I want to say that maybe (probably) the word 'layer' is not the correct one, but I believe it gives the correct idea of what I want to do.
I am using a SurfaceView wich implements SurfaceHolder.Callback.
I am working on a canvas. I am drawing a quite complex set of points. I have the canvas translated, rotated and scaled (translateX and translateY are variable that changes when the user interacts with the canvas):
canvas.translate(0, 0);
canvas.rotate(-90);
canvas.translate(translateX, translateY);
canvas.scale(scaleX, scaleY);
My next step is to add text and images on top of this canvas. Both the text and the images should not be scaled nor rotated, only translated (they should follow the canvas).
For this reason I was thinking about having some sort of 'layer' or something similar transparent which only follows the canvas movements and does not change on zoom in or zoom out or on rotation [think them as some sort of UI which stay over the whole canvas].
Here is a snippet:
@Override public void onDraw(Canvas canvas) { try{ pt.setColor(Color.BLACK); canvas.drawColor(Color.WHITE); canvas.drawText("HELLOOOOOOOOOOOOOOOO", x, y, pt); pt.setAntiAlias(true); canvas.save(); canvas.rotate(-90, 0, 0); canvas.drawText("HELLOOOOOOOOOOOOOOOO", x1, y1, pt); canvas.restore(); } catch(Exception e) {} }
I have been wasting a lot of time here lately.
I could fix this by finding the way of converting my cartesian-like points into pixel coordinates. I have figure out that it should be like this:
Cartesian points: X, Y
Pixel Points: X, MaxValueGraph - Y
The problem is that I cant find the way to get the maxValue. I tried to use getHeight() but nothing.
I find it ridiculous that it is not possible to rotate a text/image directly. The only way I found so far is to rotate the whole canvas; seems legit...
Thanks in advance.
N.