Skip to content

Commit

Permalink
Use Smoothing on the FPS counter so it can be more readable
Browse files Browse the repository at this point in the history
Especially useful in lower screen resolutions, so much so that
it now gets a bit smaller on the lowest available resolutions like
96x65 pixels to not cover as much of the screen.

Also document the correct location to implement Java 2D RenderingHints
for when configurable screen AA, font AA, among others when deemed
the right time to do so (platformImage's graphics instance).
  • Loading branch information
AShiningRay committed Nov 20, 2024
1 parent c937432 commit 67bb770
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/org/recompile/mobile/MobilePlatform.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@

import java.awt.Color;
import java.awt.Graphics2D;
import java.awt.RenderingHints;
import java.awt.event.KeyEvent;

import javax.microedition.lcdui.Canvas;
Expand Down Expand Up @@ -424,6 +425,10 @@ private final void showFPS() {

BufferedImage overlayImage = new BufferedImage(OVERLAY_WIDTH, OVERLAY_HEIGHT, BufferedImage.TYPE_INT_ARGB);
Graphics2D overlayGraphics = overlayImage.createGraphics();

// Enable font AA for better text quality (GASP uses font resource information to apply AA when appropriate)
gc.getGraphics2D().setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
gc.getGraphics2D().setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR);

// Set the overlay background
overlayGraphics.setColor(new Color(0, 0, 105, 150)); // BG is a semi-transparent dark blue
Expand All @@ -444,7 +449,7 @@ private final void showFPS() {
double scale = Math.min(lcdWidth, lcdHeight);

int scaledWidth = 0;
if(scale < 100) { scaledWidth = (int) (lcdWidth / 2);}
if(scale < 100) { scaledWidth = (int) (lcdWidth / 2.5);}
if(scale > 100) { scaledWidth = (int) (lcdWidth / 3);}
if(scale > 200) { scaledWidth = (int) (lcdWidth / 4);}
if(scale > 300) { scaledWidth = (int) (lcdWidth / 5);}
Expand Down
8 changes: 8 additions & 0 deletions src/org/recompile/mobile/PlatformImage.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@

import javax.imageio.ImageIO;
import java.awt.Graphics2D;
import java.awt.RenderingHints;
import java.awt.image.BufferedImage;
import java.awt.image.WritableRaster;

Expand All @@ -51,6 +52,13 @@ public class PlatformImage extends javax.microedition.lcdui.Image
protected void createGraphics()
{
gc = new PlatformGraphics(this);


// Assuming we ever decide to implement configurable Java Graphics rendering options (2D smoothing, AA, etc), they should be applied here

// Example: Enable font AA (GASP uses font resource information to apply AA when appropriate)
//gc.getGraphics2D().setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_GASP);

gc.setColor(0x000000);
}

Expand Down

0 comments on commit 67bb770

Please sign in to comment.