Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Comparing changes

Choose two branches to see what's changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
base fork: napthats/Board_Note
base: 23bd12d28f
...
head fork: napthats/Board_Note
compare: 921c75e153
Checking mergeability… Don't worry, you can still create the pull request.
  • 2 commits
  • 1 file changed
  • 0 commit comments
  • 1 contributor
Showing with 68 additions and 20 deletions.
  1. +68 −20 src/main/scala/BoardView.scala
View
88 src/main/scala/BoardView.scala
@@ -17,19 +17,56 @@ import _root_.org.metalev.multitouch.controller.MultiTouchController.PointInfo;
import _root_.org.metalev.multitouch.controller.MultiTouchController.PositionAndScale;
-class Page(var x: Int, var y: Int, var size: Int, val color: Int, title: String) {
-}
+class Page(var x: Double, var y: Double, var size: Double, val color: Int, title: String) {
+ def winX = BoardView.world2WindowPosition(x, y).x
+ def winY = BoardView.world2WindowPosition(x, y).y
+ def scale = size / 100.0
+
+ def dragAndPinch(pos_scale: PositionAndScale) {
+ val pos = BoardView.window2WorldPosition(pos_scale.getXOff, pos_scale.getYOff)
+ this.x = pos.x
+ this.y = pos.y
+ this.size = pos_scale.getScale * 100
+ }
+}
+
-class BoardView(context: Context, attrs:AttributeSet) extends View(context, attrs) with MultiTouchObjectCanvas[Page]{
-/*
- var prev_touch_x = 0
- var prev_touch_y = 0
-*/
- var page = new Page(200, 100, 100, Color.RED, "test")
- var page_alt = new Page(400, 400, 100, Color.BLUE, "test_alt")
+object BoardView {
+ var base_x = 0.0
+ var base_y = 0.0
+ var base_scale = 1.0
+ def window2WorldPosition(x_orig: Double, y_orig: Double): {val x: Double; val y: Double} = {
+ new {val x = (x_orig / base_scale) + base_x; val y = (y_orig / base_scale) + base_y}
+ }
+
+ def world2WindowPosition(x_orig: Double, y_orig: Double): {val x: Double; val y: Double} = {
+ new {val x = (x_orig - base_x) * base_scale; val y = (y_orig - base_y) * base_scale}
+ }
+}
+
+
+class BoardView(context: Context, attrs:AttributeSet) extends View(context, attrs) with MultiTouchObjectCanvas[Page]{
val multiTouchController = new MultiTouchController[Page](this)
+ var page = new Page(200.0, 100.0, 100.0, Color.RED, "test")
+ var page_alt = new Page(400.0, 400.0, 100.0, Color.BLUE, "test_alt")
+ var page_dummy = new Page(0.0, 0.0, 0.0, 0, "") {
+ override def scale = BoardView.base_scale
+ override def dragAndPinch(pos_scale: PositionAndScale) {
+ super.dragAndPinch(pos_scale)
+ val pos = BoardView.window2WorldPosition(pos_scale.getXOff, pos_scale.getYOff)
+ BoardView.base_x -= pos.x
+ BoardView.base_y -= pos.y
+ BoardView.base_scale = pos_scale.getScale
+ }
+ }
+
+
+
+ //for Canvas#drawRect
+ private implicit def double2Float(x: Double): Float = x.toFloat
+
override def onDraw(canvas: Canvas) {
super.onDraw(canvas)
@@ -37,10 +74,22 @@ class BoardView(context: Context, attrs:AttributeSet) extends View(context, attr
val paint = new Paint()
paint.setColor(page.color)
- canvas.drawRect(page.x, page.y, page.x + page.size, page.y + page.size, paint)
+ canvas.drawRect(
+ (page.x - BoardView.base_x) * BoardView.base_scale,
+ (page.y - BoardView.base_y) * BoardView.base_scale,
+ (page.x + page.size - BoardView.base_x) * BoardView.base_scale,
+ (page.y + page.size - BoardView.base_y) * BoardView.base_scale,
+ paint
+ )
paint.setColor(page_alt.color)
- canvas.drawRect(page_alt.x, page_alt.y, page_alt.x + page_alt.size, page_alt.y + page_alt.size, paint)
+ canvas.drawRect(
+ (page_alt.x - BoardView.base_x) * BoardView.base_scale,
+ (page_alt.y - BoardView.base_y) * BoardView.base_scale,
+ (page_alt.x + page_alt.size - BoardView.base_x) * BoardView.base_scale,
+ (page_alt.y + page_alt.size - BoardView.base_y) * BoardView.base_scale,
+ paint
+ )
}
override def selectObject(page: Page, point: PointInfo) {
@@ -48,23 +97,22 @@ class BoardView(context: Context, attrs:AttributeSet) extends View(context, attr
}
override def setPositionAndScale(page: Page, pos_scale: PositionAndScale, point: PointInfo): Boolean = {
- page.x = pos_scale.getXOff.toInt
- page.y = pos_scale.getYOff.toInt
- page.size = (pos_scale.getScale * 100).toInt
+ page.dragAndPinch(pos_scale)
invalidate()
return true
}
override def getPositionAndScale(page: Page, pos_scale: PositionAndScale) {
- pos_scale.set(page.x, page.y, true, page.size/100, false, page.size/100, page.size/100, false, 0)
+ pos_scale.set(page.winX, page.winY, true, page.scale, false, page.scale, page.scale, false, 0)
}
override def getDraggableObjectAtPoint(point: PointInfo): Page = {
- if (point.getX >= page.x && point.getX <= page.x + page.size &&
- point.getY >= page.y && point.getY <= page.y + page.size) return page
- else if (point.getX >= page_alt.x && point.getX <= page_alt.x + page_alt.size &&
- point.getY >= page_alt.y && point.getY <= page_alt.y + page_alt.size) return page_alt
- return null
+ val pos = BoardView.window2WorldPosition(point.getX, point.getY)
+ if (pos.x >= page.x && pos.x <= page.x + page.size &&
+ pos.y >= page.y && pos.y <= page.y + page.size) return page
+ else if (pos.x >= page_alt.x && pos.x <= page_alt.x + page_alt.size &&
+ pos.y >= page_alt.y && pos.y <= page_alt.y + page_alt.size) return page_alt
+ return page_dummy
}
override def onTouchEvent(event: MotionEvent): Boolean = multiTouchController.onTouchEvent(event)

No commit comments for this range

Something went wrong with that request. Please try again.