Drag&Drop of Drawables and Centered Zooming.

Problems with Canvas, OpenGL, etc...

Drag&Drop of Drawables and Centered Zooming.

Postby m4tt » Thu Mar 24, 2011 6:23 pm

Hi!

I started with a simple tutorial on the google developer blog to implement a zoom gesture. (http://android-developers.blogspot.com/ ... touch.html)
Currently I draw several Elements on a canvas and I am able to move the whole canvas via canvas.translate(dx,dy) and I can select single elements and move them without moving unselected elements. To do this I compare the touch-coordinates with the drawn elements and look if an element contains this coordinates withing its bounds.

So I take the canvas offset used for canvas.translate +/- the touch coordinates and check if I have touched an element or the plain canvas. This also works if the pivot point for the zoom gesture is the upper left corner, I simply have to divide with the scaleFactor:

Code: Select all
private int canvasY(int y) {
      return (int)((yTouch-mOffsetY)/mScaleFactor);
   }


This is not working if I center the zoom on the gesture, because now the canvas.scale operation also moves the canvas and I cannot simply use the offset values to calculate my coordinates.

I use ScaleGestureDetector.getFocusX() and getFocusY() to get the pivot point for the zooming.

Code: Select all
   canvas.translate(mOffsetX, mOffsetY);
       //canvas.scale(mScaleFactor, mScaleFactor); <- zoom center on left corner
   canvas.scale(mScaleFactor, mScaleFactor, mScalePivotX, mScalePivotY);


So my questions are:
* is there a way to get the canvas offset after using the 4 parameter scale method? eg calculating the canvas offset with the gesture focus point and the current scale factor, or does any other way to get these values?
* is there a better way to detect element-touch-events instead of comparing the coordinates? is it possible to let the element handle touchevents itself?


thx for your help, I tried to find examples/apps to look into, but didn't find anything that would help me :)
m4tt
Once Poster
Once Poster
 
Posts: 1
Joined: Thu Mar 24, 2011 5:48 pm

Top

Return to Android 2D/3D Graphics - OpenGL Problems

Who is online

Users browsing this forum: No registered users and 3 guests