Skip to content

Commit

Permalink
AWT: Fix Screen Rotation.
Browse files Browse the repository at this point in the history
The new way scaling is being handled brought up an issue where
the display's coordinates were being updated on the canvas as well
before being rotated. This should not be the case now.
  • Loading branch information
AShiningRay committed Nov 22, 2024
1 parent 00a4963 commit db76456
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 24 deletions.
60 changes: 36 additions & 24 deletions src/org/recompile/freej2me/FreeJ2ME.java
Original file line number Diff line number Diff line change
Expand Up @@ -353,6 +353,7 @@ private void settingsChanged()
{
int w = Integer.parseInt(config.settings.get("width"));
int h = Integer.parseInt(config.settings.get("height"));
boolean hasRotated = false;

Mobile.limitFPS = Integer.parseInt(config.settings.get("fps"));

Expand Down Expand Up @@ -381,8 +382,16 @@ private void settingsChanged()
if(phone.equals("SiemensOld")) { Mobile.siemensold = true;}

String rotate = config.settings.get("rotate");
if(rotate.equals("on")) { rotateDisplay = true; }
if(rotate.equals("off")) { rotateDisplay = false; }
if(rotate.equals("on") && rotateDisplay != true)
{
rotateDisplay = true;
hasRotated = true;
}
if(rotate.equals("off") && rotateDisplay != false)
{
rotateDisplay = false;
hasRotated = true;
}

String midiSoundfont = config.settings.get("soundfont");
if(midiSoundfont.equals("Custom")) { Manager.useCustomMidi = true; }
Expand All @@ -393,30 +402,33 @@ private void settingsChanged()
else if (speedHackNoAlpha.equals("off")) { Mobile.noAlphaOnBlankImages = false; };

// Create a standard size LCD if not rotated, else invert window's width and height.
if(w != lcdWidth || h != lcdHeight)
if(w != lcdWidth || h != lcdHeight || hasRotated)
{
if(!rotateDisplay)
{
lcdWidth = w;
lcdHeight = h;

Mobile.getPlatform().resizeLCD(w, h);

resize();
main.setSize(lcdWidth*scaleFactor+xborder , lcdHeight*scaleFactor+yborder);
}
else
{
lcdWidth = h;
lcdHeight = w;

Mobile.getPlatform().resizeLCD(w, h);

resize();
main.setSize(lcdWidth*scaleFactor+xborder , lcdHeight*scaleFactor+yborder);
}
if(!rotateDisplay)
{
lcdWidth = w;
lcdHeight = h;

Mobile.getPlatform().resizeLCD(w, h);

resize();
main.setSize(lcdWidth*scaleFactor+xborder , lcdHeight*scaleFactor+yborder);
}
else
{
lcdWidth = w;
lcdHeight = h;

Mobile.getPlatform().resizeLCD(w, h);

lcdWidth = h;
lcdHeight = w;

resize();
main.setSize(lcdWidth*scaleFactor+xborder , lcdHeight*scaleFactor+yborder);
}
}


}

private int getMobileKey(int keycode)
Expand Down
3 changes: 3 additions & 0 deletions src/org/recompile/mobile/MobilePlatform.java
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,9 @@ public void run()

public void resizeLCD(int width, int height)
{
// No need to waste time here if the screen dimensions haven't changed (screen was just rotated for example)
if(lcdWidth == width && lcdHeight == height) { return; }

lcdWidth = width;
lcdHeight = height;
Font.setScreenSize(width, height);
Expand Down

0 comments on commit db76456

Please sign in to comment.