×

Discussion Board

Results 1 to 3 of 3
  1. #1
    Registered User
    Join Date
    Nov 2007
    Posts
    8

    drawRGB problem in landscape mode in S60 3rd edition FP1 emulator

    Hi,

    I have encountered a strange problem with the Graphics drawRGB() when switching from portrait to landscape while running my application (a game) in S60 3rd edition FP1 emulator. Specifically, I use drawRGB to draw two
    semitransparent areas on GameCanvas:
    Area 1 is a white rectangle with 50% opacity. Its width is 190px and its height is 230px.
    Area 2 is a gray rectangle with 50% opacity. Its width is equal to screenWidth and its height is 40px. screenWidth is requested by getWidth() of Displayable once every drawing cycle.

    When I switch from portrait to landscape, Area1 should retain its width of 190px. However it does NOT! (This is easy to figure out by counting the letters which can be shown on top of Area1. Their number is different between portait and landscape).

    Area2 width is wrong as well. Its width is not as screenWidth. (it should be width=screenWidth=320px when in landscape)

    What happens is that both Area1 and Area2 have the their rightmost pixels at the same x coordinate (which seems to be pixel 240)

    I guess the problem is that drawRGB() refuses to draw beyond pixel 240 although this IS possible when in landscape mode.

    The funny thing is that if you select landscape view before showing the canvas then both Areas are drawn as they should. However, in this case, when a change to portait is done, then the HEIGHT of Area1 is wrong!!!

    Actually it is less than it should be, and it seems to me that its lowermost pixels are at y=240!

    You can reproduce this behaviour by using the 2 source files I include in this post.

    Could anybody figure out if I am doing something wrong here?

    Any help would be appreciated.

    Thanks


    -----------------------------------
    PortraitLandscape.java
    -----------------------------------
    Code:
    import javax.microedition.lcdui.Display;
    import javax.microedition.midlet.MIDlet;
    
    public class PortraitLandscape extends MIDlet
    {
        public PortraitLandscape(){}
    
        public void startApp()
        {
            Display display=Display.getDisplay(this);
            GameView gameView = new GameView();
            display.setCurrent(gameView);
            gameView.startTheThread();
        }
    
        public void pauseApp(){}
        public void destroyApp(boolean unconditional) {}
    }
    -----------------------------------
    GameView.java
    -----------------------------------
    Code:
    import javax.microedition.lcdui.Font;
    import javax.microedition.lcdui.Graphics;
    import javax.microedition.lcdui.game.GameCanvas;
    
    public class GameView extends GameCanvas implements Runnable
    {
        protected Thread   m_Thread;
        protected Graphics m_Graphics;
        private int m_Area1TransparentArray [];
        private int m_Area2TransparentArray [];
    
        public GameView()
        {
            super(false);
            setFullScreenMode(true);
        }
    
        public void run()
        {
            m_Graphics = getGraphics();
            m_Graphics.setFont(Font.getFont(Font.FACE_SYSTEM,
    Font.STYLE_BOLD, Font.SIZE_MEDIUM));
    
            m_Area1TransparentArray = new int [190 * 230];
            for(int i=0;i<m_Area1TransparentArray.length;i++)
                m_Area1TransparentArray[i] = 0x80FFFFFF; //50% opacity white
    
            m_Area2TransparentArray = new int
    [Math.max(getWidth(),getHeight()) * 40];
            for(int i=0;i<m_Area2TransparentArray.length;i++)
                m_Area2TransparentArray[i] = 0x80AFAFAF; //50% opacity gray
    
            while(true)
            {
                //draw the background color (blue)
                m_Graphics.setColor(0,0,150);
                m_Graphics.fillRect(0, 0, getWidth(), getHeight());
    
                //draw area 1
                m_Graphics.drawRGB(m_Area1TransparentArray,0,190,
                  (getWidth() - 190)/2,
                  (getHeight() - 230)/2,
                  190,230,true);
                m_Graphics.setColor(0x000000); // black
                m_Graphics.drawString("abcdefghijklmnopqrstuvwxyz",
                  (getWidth() - 190)/2,
                  (getHeight())/2, m_Graphics.LEFT | m_Graphics.BOTTOM);
    
                //draw area 2
                m_Graphics.drawRGB(m_Area2TransparentArray,0,getWidth(),0,0,
                  getWidth(),40,true);
    
                flushGraphics();
                try
                {
                    Thread.sleep(500);
                }
                catch (InterruptedException ex)
                {}
            }
        }
    
        public void startTheThread()
        {
            m_Thread = new Thread(this);
            m_Thread.start();
        }
    
        protected void showNotify()
        {
            setFullScreenMode(true);
        }
    
        protected void hideNotify()
        {
            setFullScreenMode(false);
        }
    }

  2. #2
    Nokia Developer Champion
    Join Date
    Mar 2005
    Location
    Paris
    Posts
    814

    Re: drawRGB problem in landscape mode in S60 3rd edition FP1 emulator

    i think it may be due to the fact you fetch the graphics only once at start.
    it may change when you switch one view to another.
    try fetch the graphics at each loop

  3. #3
    Registered User
    Join Date
    Nov 2007
    Posts
    8

    Re: drawRGB problem in landscape mode in S60 3rd edition FP1 emulator

    It really worked!

    I had only followed the instructions in the GameCanvas javadoc that say: "A new Graphics object is created and returned each time this method is called; therefore, the needed Graphics object(s) should be obtained before the game starts then re-used while the game is running."

    I guess I didn't understand that this instruction didin't cover the case of portrait / landscape switching.

    Thanks a lot!

Similar Threads

  1. S60 3rd edition emulator crash with <select>
    By johalareewi in forum Mobile Web Site Development
    Replies: 4
    Last Post: 2010-05-18, 15:33
  2. S60 SDK 3rd edition FP1 Emulator problem
    By justteam in forum Symbian Tools & SDKs
    Replies: 14
    Last Post: 2010-03-23, 08:47
  3. Replies: 35
    Last Post: 2009-04-11, 14:36
  4. S60 3rd Edition FP1 SDK - Emulator 無法開啟
    By charlestsai13 in forum Symbian
    Replies: 2
    Last Post: 2007-03-19, 01:08
  5. CFTPSesson problem in S60 3rd edition
    By dubey_hbti27 in forum Symbian Networking & Messaging (Closed)
    Replies: 1
    Last Post: 2006-12-13, 10:00

Posting Permissions

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