Permalink
Browse files

Fix strange zoom in/out behavior

  • Loading branch information...
1 parent 0f07164 commit 921c75e153a0869dc6ba1b9dbb5423c1ca1fa091 @napthats committed Nov 11, 2012
Showing with 13 additions and 7 deletions.
  1. +13 −7 src/main/scala/BoardView.scala
@@ -18,14 +18,18 @@ import _root_.org.metalev.multitouch.controller.MultiTouchController.PositionAnd
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
}
}
-
+
object BoardView {
var base_x = 0.0
@@ -47,15 +51,18 @@ class BoardView(context: Context, attrs:AttributeSet) extends View(context, attr
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,100.0,Color.RED,"") {
+ 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 = -x
- BoardView.base_y = -y
- BoardView.base_scale = size / 100.0
+ 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
@@ -96,8 +103,7 @@ class BoardView(context: Context, attrs:AttributeSet) extends View(context, attr
}
override def getPositionAndScale(page: Page, pos_scale: PositionAndScale) {
- val pos = BoardView.world2WindowPosition(page.x, page.y)
- pos_scale.set(pos.x, pos.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 = {

0 comments on commit 921c75e

Please sign in to comment.