From 036a4a902d99e932386292e0024e54844bf30455 Mon Sep 17 00:00:00 2001 From: Stephanie Gawroriski Date: Thu, 16 Feb 2023 21:07:19 +0000 Subject: [PATCH] Add PencilGraphics forwards for drawRect() and fillTriangle(). --- .../cc/squirreljme/vm/springcoat/MLEPencil.java | 53 +++++++++++++++++++++- .../java/cc/squirreljme/jvm/mle/PencilShelf.java | 41 +++++++++++++++++ .../runtime/lcdui/gfx/AdvancedGraphics.java | 11 +++++ .../runtime/lcdui/mle/PencilGraphics.java | 7 ++- .../java/javax/microedition/lcdui/Graphics.java | 25 ++++++++++ 5 files changed, 134 insertions(+), 3 deletions(-) diff --git a/emulators/springcoat-vm/src/main/java/cc/squirreljme/vm/springcoat/MLEPencil.java b/emulators/springcoat-vm/src/main/java/cc/squirreljme/vm/springcoat/MLEPencil.java index 75ea989356..247391f64e 100644 --- a/emulators/springcoat-vm/src/main/java/cc/squirreljme/vm/springcoat/MLEPencil.java +++ b/emulators/springcoat-vm/src/main/java/cc/squirreljme/vm/springcoat/MLEPencil.java @@ -51,7 +51,9 @@ public enum MLEPencil return PencilCapabilities.MINIMUM | PencilCapabilities.FILL_RECT | + PencilCapabilities.FILL_TRIANGLE | PencilCapabilities.DRAW_LINE | + PencilCapabilities.DRAW_RECT | PencilCapabilities.DRAW_XRGB32_REGION; } }, @@ -80,6 +82,29 @@ public enum MLEPencil }, /** + * {@link PencilShelf#hardwareDrawRect(PencilBracket, int, int, int, int)}. + */ + HARDWARE_DRAW_RECT("hardwareDrawRect:" + + "(Lcc/squirreljme/jvm/mle/brackets/PencilBracket;IIII)V") + { + /** + * {@inheritDoc} + * @since 2021/12/05 + */ + @Override + public Object handle(SpringThreadWorker __thread, Object... __args) + { + MLEPencil.__graphics(__args[0]) + .drawRect((Integer)__args[1], + (Integer)__args[2], + (Integer)__args[3], + (Integer)__args[4]); + + return null; + } + }, + + /** * {@link PencilShelf#hardwareDrawXRGB32Region(PencilBracket, int[], int, * int, boolean, int, int, int, int, int, int, int, int, int, int, int, * int)}. @@ -193,7 +218,33 @@ public enum MLEPencil return null; } - }, + }, + + /** + * {@link PencilShelf#hardwareFillTriangle(PencilBracket, int, int, int, + * int, int, int)}. + */ + HARDWARE_FILL_TRIANGLE("hardwareFillTriangle:" + + "(Lcc/squirreljme/jvm/mle/brackets/PencilBracket;IIIIII)V") + { + /** + * {@inheritDoc} + * @since 2023/02/16 + */ + @Override + public Object handle(SpringThreadWorker __thread, Object... __args) + { + MLEPencil.__graphics(__args[0]) + .fillTriangle((Integer)__args[1], + (Integer)__args[2], + (Integer)__args[3], + (Integer)__args[4], + (Integer)__args[5], + (Integer)__args[6]); + + return null; + } + }, /** * {@link PencilShelf#hardwareGraphics(int, int, int, Object, int, int[], diff --git a/modules/cldc-compact/src/main/java/cc/squirreljme/jvm/mle/PencilShelf.java b/modules/cldc-compact/src/main/java/cc/squirreljme/jvm/mle/PencilShelf.java index a57dffe308..ef5430dd4c 100644 --- a/modules/cldc-compact/src/main/java/cc/squirreljme/jvm/mle/PencilShelf.java +++ b/modules/cldc-compact/src/main/java/cc/squirreljme/jvm/mle/PencilShelf.java @@ -69,6 +69,27 @@ public final class PencilShelf throws MLECallError; /** + * Draws the outline of the given rectangle using the current color and + * stroke style. The rectangle will cover an area that is + * {@code [width + 1, height + 1]}. + * + * Nothing is drawn if the width and/or height are zero. + * + * @param __g The hardware graphics to draw with. + * @param __x The X coordinate. + * @param __y The Y coordinate. + * @param __w The width. + * @param __h The height. + * @throws MLECallError If the graphics is not valid or does not support + * the given operation. + * @since 2023/02/16 + */ + @SquirrelJMEVendorApi + public static native void hardwareDrawRect(PencilBracket __g, + int __x, int __y, int __w, int __h) + throws MLECallError; + + /** * Draws a region of 32-bit RGB data into the target. * * @param __data The source buffer. @@ -116,6 +137,26 @@ public final class PencilShelf throws MLECallError; /** + * Draws a filled triangle using the current color, the lines which make + * up the triangle are included in the filled area. + * + * @param __g The graphics to use for drawing. + * @param __x1 First X coordinate. + * @param __y1 First Y coordinate. + * @param __x2 Second X coordinate. + * @param __y2 Second Y coordinate. + * @param __x3 Third X coordinate. + * @param __y3 Third Y coordinate. + * @throws MLECallError If no graphics were specified or the graphics does + * not actually support the given operation. + * @since 2023/02/16 + */ + @SquirrelJMEVendorApi + public static native void hardwareFillTriangle(PencilBracket __g, + int __x1, int __y1, int __x2, int __y2, int __x3, int __y3) + throws MLECallError; + + /** * Creates a hardware reference bracket to the native hardware graphics. * * @param __pf The {@link UIPixelFormat} used for the draw. diff --git a/modules/midp-lcdui/src/main/java/cc/squirreljme/runtime/lcdui/gfx/AdvancedGraphics.java b/modules/midp-lcdui/src/main/java/cc/squirreljme/runtime/lcdui/gfx/AdvancedGraphics.java index db92aa2453..b0c540a6f5 100644 --- a/modules/midp-lcdui/src/main/java/cc/squirreljme/runtime/lcdui/gfx/AdvancedGraphics.java +++ b/modules/midp-lcdui/src/main/java/cc/squirreljme/runtime/lcdui/gfx/AdvancedGraphics.java @@ -631,6 +631,10 @@ public class AdvancedGraphics @Override public void drawRect(int __x, int __y, int __w, int __h) { + // Do nothing if less than zero + if (__w < 0 || __h < 0) + return; + // The width and height are increased by a single pixel __w += 1; __h += 1; @@ -751,6 +755,10 @@ public class AdvancedGraphics @Override public void fillRect(int __x, int __y, int __w, int __h) { + // Do nothing if less than zero + if (__w < 0 || __h < 0) + return; + // Get actual end points int ex = __x + __w, ey = __y + __h; @@ -827,6 +835,9 @@ public class AdvancedGraphics int __x3, int __y3) { this.__unimplemented(__x1, __y1, "fillTriangle"); + this.drawLine(__x1, __y1, __x2, __y2); + this.drawLine(__x2, __y2, __x3, __y3); + this.drawLine(__x3, __y3, __x1, __y1); } /** diff --git a/modules/midp-lcdui/src/main/java/cc/squirreljme/runtime/lcdui/mle/PencilGraphics.java b/modules/midp-lcdui/src/main/java/cc/squirreljme/runtime/lcdui/mle/PencilGraphics.java index fcd4808c2a..182a24601e 100644 --- a/modules/midp-lcdui/src/main/java/cc/squirreljme/runtime/lcdui/mle/PencilGraphics.java +++ b/modules/midp-lcdui/src/main/java/cc/squirreljme/runtime/lcdui/mle/PencilGraphics.java @@ -327,7 +327,8 @@ public final class PencilGraphics return; } - throw Debugging.todo(); + // Forward to hardware + PencilShelf.hardwareDrawRect(this.hardware, __x, __y, __w, __h); } /** @@ -532,7 +533,9 @@ public final class PencilGraphics return; } - throw Debugging.todo(); + // Forward to hardware + PencilShelf.hardwareFillTriangle(this.hardware, __x1, __y1, __x2, __y2, + __x3, __y3); } /** diff --git a/modules/midp-lcdui/src/main/java/javax/microedition/lcdui/Graphics.java b/modules/midp-lcdui/src/main/java/javax/microedition/lcdui/Graphics.java index 03be8dc1e4..c3bf8ea8ae 100644 --- a/modules/midp-lcdui/src/main/java/javax/microedition/lcdui/Graphics.java +++ b/modules/midp-lcdui/src/main/java/javax/microedition/lcdui/Graphics.java @@ -245,6 +245,19 @@ public abstract class Graphics int __x, int __y, int __w, int __h) throws NullPointerException; + /** + * Draws the outline of the given rectangle using the current color and + * stroke style. The rectangle will cover an area that is + * {@code [width + 1, height + 1]}. + * + * Nothing is drawn if the width and/or height are zero. + * + * @param __x The X coordinate. + * @param __y The Y coordinate. + * @param __w The width. + * @param __h The height. + * @since 2023/02/16 + */ @Api public abstract void drawRect(int __x, int __y, int __w, int __h); @@ -358,6 +371,18 @@ public abstract class Graphics public abstract void fillRoundRect(int __x, int __y, int __w, int __h, int __aw, int __ah); + /** + * Draws a filled triangle using the current color, the lines which make + * up the triangle are included in the filled area. + * + * @param __x1 First X coordinate. + * @param __y1 First Y coordinate. + * @param __x2 Second X coordinate. + * @param __y2 Second Y coordinate. + * @param __x3 Third X coordinate. + * @param __y3 Third Y coordinate. + * @since 2023/02/16 + */ @Api public abstract void fillTriangle(int __x1, int __y1, int __x2, int __y2, int __x3, int __y3); -- 2.11.4.GIT