There is something that I am missing, so I hope you can share a little light with it.
I draw text inside the canvas. For this, I have a Word class
public class Word { private int x; private int y; private String text; }
The application allows the user to rotate the text, and I handle the rotation using onDraw
protected void onDraw(Canvas canvas) { canvas.save(Canvas.MATRIX_SAVE_FLAG); canvas.rotate(angle, centerX, centerY) ... canvas.drawText(word.getText(), word.getX(), word.getY()) .... canvas.restore(); }
The problem I get is when the user drags the canvas and the rotation set appears. When angle = 0, the movement is as expected.
@Override public boolean onTouchEvent(MotionEvent event) { case MotionEvent.ACTION_DOWN: initialX = (int) event.getX(); initialY = (int) event.getY(); break; case MotionEvent.ACTION_MOVE: int currentX = (int) event.getX(); int currentY = (int) event.getY(); int xMovement = currentX - initialX; int yMovement = currentY - initialY; dragWords(xMovement, yMovement); .....
and dragWords for every word I make:
private void dragText(int xMovement, int yMovement){ for (Word word : words) { word.setX(word.getX() + xMovement); word.setY(word.getY() + yMovement); } invalidate();
}
When the rotation angle is 0, moving up / down / left / right causes the words to move the same distance. As the angle becomes larger, the words begin to move in different modes, for example, at 60, he begins to go diagonally upwards, when he only moves up / down, and not left / right.
It seems to me that I need to calculate some difference based on the angle and add it to xMovement / yMovement ... but how do I do this?
LE: Here is an image of how he behaves:
The blue lines are the way the text moves when dragging, and the orange is the dragging of the finger on the screen. When the angle is 0, it works well enough, when the angle increases, it starts moving diagonally left / right, and when the angle is even larger, it only moves up and down and does not respond to left / right