Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: Add and manage a layer over a canvas using SurfaceView

  1. #1
    Member
    Join Date
    Oct 2011
    Posts
    53
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Default Add and manage a layer over a canvas using SurfaceView

    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.


  2. #2
    Member
    Join Date
    Oct 2011
    Posts
    53
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Default Re: Add and manage a layer over a canvas using SurfaceView

    I manage to fix the text. Now the issue is the size of the bitmaps :/

Similar Threads

  1. How to get scores from user in Canvas J2ME?
    By elenora in forum Java ME (Mobile Edition)
    Replies: 0
    Last Post: April 4th, 2011, 04:10 AM
  2. Replies: 2
    Last Post: February 14th, 2011, 01:32 AM
  3. Java layer over a page?
    By millhugz in forum Java Theory & Questions
    Replies: 7
    Last Post: July 1st, 2010, 01:23 PM
  4. [ASK] Make Object as a layer
    By bocahTuaNakalzz in forum AWT / Java Swing
    Replies: 2
    Last Post: October 24th, 2009, 01:07 PM
  5. make textbox in canvas
    By mahdi in forum Java ME (Mobile Edition)
    Replies: 2
    Last Post: October 6th, 2009, 07:10 AM