×

Discussion Board

Page 1 of 2 12 LastLast
Results 1 to 15 of 21
  1. #1
    Regular Contributor
    Join Date
    Sep 2009
    Posts
    353

    does Canvas support layering?

    Does the Canvas class support layering or Depth?
    For instance, if I draw a Box on the canvas and then overlap it with a Circle partially, is it possible to get the original box back, or is the overlapping Area overwritten by the Circle?

    Are there any third party UI libraries that support layering?

  2. #2
    Super Contributor
    Join Date
    Apr 2009
    Posts
    572

    Re: does Canvas support layering?

    No canvas doesnt support layering however you can acheive what U want by intelligent paintaing

    Regarding 3rd party there are numerous LWUIT j2me Polish are name to few
    Regards,
    Saurabh

  3. #3
    Super Contributor
    Join Date
    Apr 2007
    Posts
    2,708

    Re: does Canvas support layering?

    well the GameCanvas does have something called a LayerManager which is to be used in combination with Layers (and Sprites)...
    You might want to have a look at that ?

  4. #4
    Regular Contributor
    Join Date
    Sep 2009
    Posts
    353

    Re: does Canvas support layering?

    @ingsaurabh: what is intelligent painting?

    @Tiger: More than sprites, I would like to have the ability to place custom components on the Canvas is it possible to do that.
    For example can I create a CustomItem and place it on the canvas, or is there some way where I can place components on Canvas.

  5. #5
    Nokia Developer Expert
    Join Date
    May 2007
    Location
    Mexico D.F
    Posts
    351

    Re: does Canvas support layering?

    Quoting you:

    For instance, if I draw a Box on the canvas and then overlap it with a Circle partially, is it possible to get the original box back, or is the overlapping Area overwritten by the Circle?
    I would say that as Tiger mentions you need to use a LayerManager. This class allows you to put different items (Layers) pile them, and paint them according to your needs. Every Layer is independient and won't affect the other ones.

    A Sprite it's just a kind of Layer, if you want to create your own, just inherit the Layer class and overwrite the paint() method.

    Please check the GameCanvas documentation.
    :Ruben

  6. #6
    Regular Contributor
    Join Date
    Sep 2009
    Posts
    353

    Re: does Canvas support layering?

    @rdrincon

    The Sprite Class usually uses a image input either single or in the form of a film strip.

    Is it possible for instance, If I was to make a custom button, then I inherit Layer without an image, and create a button by drawing a rectangular box and filling it with a pre-defined color and then I could use this on the canvas?

  7. #7
    Nokia Developer Expert
    Join Date
    May 2007
    Location
    Mexico D.F
    Posts
    351

    Re: does Canvas support layering?

    Yes, just inherit the Layer class and paint your box inside the paint method that you have to overwrite.


    Code:
    public class MyOwnLayer extends Layer{
    
    public void paint(Graphics g){
    //Paint your box with g
    }
    
    }
    Now you will be able to add an instance of MyOwnLayer to any LayerManager.
    And please, don't forget to make the MyOwnLayer instance visible


    Code:
    myOwnLayerInstance.setVisible(true);
    :Ruben

  8. #8
    Regular Contributor
    Join Date
    Sep 2009
    Posts
    353

    Re: does Canvas support layering?

    @Ruben
    Does that mean, this Layer instance is now a custom component and I can play with it and move, render and modify it at will on the canvas.

  9. #9
    Super Contributor
    Join Date
    Apr 2009
    Posts
    572

    Lightbulb Re: does Canvas support layering?

    @ingsaurabh: what is intelligent painting?
    its what every developer had to do while working on canvas because canvas most of the times developers k I talk bot myself at least I feel uncomfortable while working with canvas and all I have to create an illusion by customization

    BTW if you use search functionality of forum most of post are related to canvas only

    Nd of course Game Canvas support layering but U asked for canvas I replied for that only
    Regards,
    Saurabh

  10. #10
    Super Contributor
    Join Date
    Apr 2007
    Posts
    2,708

    Re: does Canvas support layering?

    well a layer in the GameCanvas is a Layer enveloping the whole screen area...
    but fortunately within that screen-covering layer you can place your own items wherever you want...

  11. #11
    Nokia Developer Expert
    Join Date
    May 2007
    Location
    Mexico D.F
    Posts
    351

    Re: does Canvas support layering?

    Yes,
    but then I'd rather recommend to use a sprite.
    If you want to create your own component, then do the following.

    1. Create an empty image
    Code:
    Image img = Image.createImage(100x100);
    2. Get the Graphics of that Image
    Code:
    Graphics g= img.getGraphics();
    3. Paint whatever you want in that graphics

    4. Create a Sprite using the image img.

    The good thing is that you can always modify the image getting the Graphics. Just add that Sprite to a LayerManager and you will be able to move it all over the screen, make it visible, overlap it with some other Sprite, whatever you want.
    :Ruben

  12. #12
    Super Contributor
    Join Date
    Jun 2003
    Location
    Cheshire, UK
    Posts
    7,395

    Re: does Canvas support layering?

    Or... you can just draw the objects you want, in the paint() method. Draw them in order, from back to front. You can create a simple framework for this... something like:

    PHP Code:
    public abstract class Component {
        private 
    int xywh;

        protected abstract 
    void paint(Graphics g);

        
    void parentPaint(Graphics g) {
            
    // record current state
            
    int cx g.getClipX();
            
    int cy g.getClipY();
            
    int cw g.getClipWidth();
            
    int ch g.getClipHeight();
            
    int tx g.getTranslateX();
            
    int ty g.getTranslateY();
            
    // set up for component paint
            
    g.translate(xy);
            
    g.setClip(00wh);

            
    paint(g);

            
    // put everything back how it was
            
    g.translate(tx g.getTranslateX(), ty g.getTranslateY());
            
    g.setClip(cxcycwch);
        }

    PHP Code:
    public class Container extends Canvas {
        private 
    Vector components = new Vector();
        private 
    int backgroundColor;

        public 
    void paint(Graphics g) {
            
    // paint background
            
    g.setColor(backgroundColor);
            
    g.fillRect(00getWidth(), getHeight());

            
    // paint components
            
    synchronized (components) {
                
    int size components.size();
                for (
    int i 0sizei++) {
                    
    Component c = (Componentcomponents.elementAt(i);
                    
    c.parentPaint(g);
                }
            }
        }


  13. #13
    Regular Contributor
    Join Date
    Sep 2009
    Posts
    353

    Re: does Canvas support layering?

    @ Graham, Ruben, ingSaurabh, Tiger

    Wow! Fantastic pieces of advise,
    The codes that you have been dishing out has got me thinking, I will have to get used to the tips and tricks of J2ME programming.
    Of course nothing can beat experience, but How do I pull up my socks, any good reference on J2ME programming, that teach your the caveats, the nuances...

    Thanks!

  14. #14
    Regular Contributor
    Join Date
    Jan 2008
    Posts
    387

    Re: does Canvas support layering?

    Hi, there is no foreground or background in J2ME what is available is your logic, just paint some thing first and other later, it will give you a layering effect, as stated by GH.
    Thanks and Regards,
    Manjul.

  15. #15
    Regular Contributor
    Join Date
    Sep 2009
    Posts
    353

    Re: does Canvas support layering?

    @Graham

    PHP Code:
    // set up for component paint 
            
    g.translate(xy); 
            
    g.setClip(00wh); 

            
    paint(g); 

            
    // put everything back how it was 
            
    g.translate(tx g.getTranslateX(), ty g.getTranslateY()); 
            
    g.setClip(cxcycwch); 
    I did not understand the following code snippet, why do you translate back after painting?

Page 1 of 2 12 LastLast

Similar Threads

  1. Clarifications/Information required about Technical Support case
    By mevasudeva in forum Feedback - Nokia Developer Services & Infrastructure
    Replies: 4
    Last Post: 2008-01-10, 13:39
  2. Technical Support Engineer, Mobile, London
    By mobile2004 in forum Symbian C++
    Replies: 0
    Last Post: 2004-11-05, 09:40
  3. Technical Support Engineer, Mobile, London
    By mobile2004 in forum Symbian C++
    Replies: 0
    Last Post: 2004-11-05, 09:38
  4. Technical Support Engineer, Mobile, London
    By mobile2004 in forum Symbian C++
    Replies: 0
    Last Post: 2004-11-05, 09:33
  5. Replies: 0
    Last Post: 2004-08-25, 11:42

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •