Skip to content

Commit

Permalink
Fix LCD paint logic - use the repaint method
Browse files Browse the repository at this point in the history
On mac, updates might not be performed when calling paint directly,
and the Graphics class shouldn't be retrieved directly.

Also on this TASEmulators fork, optimize FreeJ2ME's
lcd paint() method to only copy the 'Graphics g' argument into
a Graphics2D if screen rotation is enabled, which
should save us some time in the render path.
  • Loading branch information
zb3 authored and AShiningRay committed Sep 19, 2024
1 parent 18fcc5a commit c8c25c3
Showing 1 changed file with 12 additions and 15 deletions.
27 changes: 12 additions & 15 deletions src/org/recompile/freej2me/FreeJ2ME.java
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,8 @@ public void run()
/* Whenever AWT GUI notifies that its menu options were changed, update settings */
if(awtGUI.hasChanged()) { settingsChanged(); awtGUI.clearChanged(); }

lcd.paint(lcd.getGraphics());
lcd.repaint();
//lcd.paint(lcd.getGraphics());
}
});

Expand Down Expand Up @@ -547,12 +548,16 @@ public void updateScale(int vw, int vh)
scaley = (double)lcdHeight/(double)vh;
}

@Override
public void update(Graphics g) {
// Use paint method directly to avoid flicker
paint(g);
}

public void paint(Graphics g)
{
try
{
Graphics2D cgc = (Graphics2D)this.getGraphics();

if(limitFPS>0)
{
requiredFrametime = 1000 / limitFPS;
Expand All @@ -564,10 +569,7 @@ public void paint(Graphics g)

if (config.isRunning)
{
if(!rotateDisplay)
{
g.drawImage(config.getLCD(), cx, cy, cw, ch, null);
}
if(!rotateDisplay) { g.drawImage(config.getLCD(), cx, cy, cw, ch, null); }
else
{
// If rotated, simply redraw the config menu with different width and height
Expand All @@ -576,12 +578,10 @@ public void paint(Graphics g)
}
else
{
if(!rotateDisplay)
{
g.drawImage(Mobile.getPlatform().getLCD(), cx, cy, cw, ch, null);
}
if(!rotateDisplay) { g.drawImage(Mobile.getPlatform().getLCD(), cx, cy, cw, ch, null); }
else
{
final Graphics2D cgc = (Graphics2D)this.getGraphics();
// Rotate the FB 90 degrees counterclockwise with an adjusted pivot
cgc.rotate(Math.toRadians(-90), ch/2, ch/2);
// Draw the rotated FB with adjusted cy and cx values
Expand All @@ -590,10 +590,7 @@ public void paint(Graphics g)
}
lastRenderTime = System.currentTimeMillis();
}
catch (Exception e)
{
System.out.println(e.getMessage());
}
catch (Exception e) { System.out.println(e.getMessage()); }
}
}
}

0 comments on commit c8c25c3

Please sign in to comment.