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); } }

Reply With Quote

