diff --git a/CodenameOne/src/com/codename1/ui/Display.java b/CodenameOne/src/com/codename1/ui/Display.java index 38c43af63f..7819459c59 100644 --- a/CodenameOne/src/com/codename1/ui/Display.java +++ b/CodenameOne/src/com/codename1/ui/Display.java @@ -2698,8 +2698,6 @@ public int convertToPixels(float value, byte unitType) { * @since 8.0 */ public int convertToPixels(float value, byte unitType, boolean horizontal) { - - switch (unitType) { case Style.UNIT_TYPE_REM: return Math.round(value * Font.getDefaultFont().getHeight()); diff --git a/CodenameOne/src/com/codename1/ui/Graphics.java b/CodenameOne/src/com/codename1/ui/Graphics.java index 4fff76a7d1..a1aa461869 100644 --- a/CodenameOne/src/com/codename1/ui/Graphics.java +++ b/CodenameOne/src/com/codename1/ui/Graphics.java @@ -636,6 +636,7 @@ public void drawString(String str, int x, int y) { * @param character - the character to be drawn * @param x the x coordinate of the baseline of the text * @param y the y coordinate of the baseline of the text + * @deprecated use drawString instead, this method is inefficient */ public void drawChar(char character, int x, int y) { drawString("" + character, x, y); @@ -650,6 +651,7 @@ public void drawChar(char character, int x, int y) { * @param length the number of characters to be drawn * @param x the x coordinate of the baseline of the text * @param y the y coordinate of the baseline of the text + * @deprecated use drawString instead, this method is inefficient */ public void drawChars(char[] data, int offset, int length, int x, int y) { if (!(current instanceof CustomFont)) { @@ -1089,9 +1091,9 @@ void drawImageArea(Image img, int x, int y, int imageX, int imageY, int imageWid * Draws a closed polygon defined by arrays of x and y coordinates. * Each pair of (x, y) coordinates defines a point. * - * @param xPoints - a an array of x coordinates. - * @param yPoints - a an array of y coordinates. - * @param nPoints - a the total number of points. + * @param xPoints - an array of x coordinates. + * @param yPoints - an array of y coordinates. + * @param nPoints - the total number of points. */ public void drawPolygon(int[] xPoints, int[] yPoints, int nPoints) { int[] cX = xPoints; @@ -1149,7 +1151,7 @@ public int concatenateAlpha(int a) { } /** - * Returnes the alpha as a value between 0-255 (0 - 0xff) where 255 is completely opaque + * Returns the alpha as a value between 0-255 (0 - 0xff) where 255 is completely opaque * and 0 is completely transparent * * @return the alpha value @@ -1169,20 +1171,20 @@ public void setAlpha(int a) { } /** - * Returns true if anti-aliasing for standard rendering operations is supported, - * notice that text anti-aliasing is a separate attribute. + * Returns true if antialiasing for standard rendering operations is supported, + * notice that text antialiasing is a separate attribute. * - * @return true if anti aliasing is supported + * @return true if antialiasing is supported */ public boolean isAntiAliasingSupported() { return impl.isAntiAliasingSupported(nativeGraphics); } /** - * Returns true if anti-aliasing for text is supported, - * notice that text anti-aliasing is a separate attribute from standard anti-alisaing. + * Returns true if antialiasing for text is supported, + * notice that text antialiasing is a separate attribute from standard anti-alisaing. * - * @return true if text anti aliasing is supported + * @return true if text antialiasing is supported */ public boolean isAntiAliasedTextSupported() { return impl.isAntiAliasedTextSupported(nativeGraphics); @@ -1190,38 +1192,38 @@ public boolean isAntiAliasedTextSupported() { /** - * Returns true if anti-aliasing for standard rendering operations is turned on. + * Returns true if antialiasing for standard rendering operations is turned on. * - * @return true if anti aliasing is active + * @return true if antialiasing is active */ public boolean isAntiAliased() { return impl.isAntiAliased(nativeGraphics); } /** - * Set whether anti-aliasing for standard rendering operations is turned on. + * Set whether antialiasing for standard rendering operations is turned on. * - * @param a true if anti aliasing is active + * @param a true if antialiasing is active */ public void setAntiAliased(boolean a) { impl.setAntiAliased(nativeGraphics, a); } /** - * Indicates whether anti-aliasing for text is active, - * notice that text anti-aliasing is a separate attribute from standard anti-alisaing. + * Indicates whether antialiasing for text is active, + * notice that text antialiasing is a separate attribute from standard anti-alisaing. * - * @return true if text anti aliasing is supported + * @return true if text antialiasing is supported */ public boolean isAntiAliasedText() { return impl.isAntiAliasedText(nativeGraphics); } /** - * Set whether anti-aliasing for text is active, - * notice that text anti-aliasing is a separate attribute from standard anti-alisaing. + * Set whether antialiasing for text is active, + * notice that text antialiasing is a separate attribute from standard anti-alisaing. * - * @param a true if text anti aliasing is supported + * @param a true if text antialiasing is supported */ public void setAntiAliasedText(boolean a) { impl.setAntiAliasedText(nativeGraphics, a); diff --git a/CodenameOne/src/com/codename1/ui/Image.java b/CodenameOne/src/com/codename1/ui/Image.java index 744205244a..00198dd5a7 100644 --- a/CodenameOne/src/com/codename1/ui/Image.java +++ b/CodenameOne/src/com/codename1/ui/Image.java @@ -392,7 +392,7 @@ public static Image exifRotation(String capturedImage, String rotatedImage, int boolean isJpeg = isJPEG(fss.openInputStream(capturedImage)); boolean isPNG = isPNG(fss.openInputStream(capturedImage)); String format; - // IMPORTANT: we cannot relies on the file extension of the capturedImage path, + // IMPORTANT: we cannot rely on the file extension of the capturedImage path, // because some Android devices return images from the gallery without extension! if (!isJpeg && !isPNG) { // Only jpeg and png images are supported, but some devices can return also different formats from the gallery (like gif). @@ -472,7 +472,7 @@ public static Image exifRotation(String capturedImage, String rotatedImage, int /** *

- * Gets the EXIF orientation tag of an image, if it's available.

+ * Gets the EXIF orientation tag of an image if it's available.

*

* The Exif Orientation Tag is a number from 0 to 8, for the explanation of * each value see the diff --git a/Ports/JavaSE/src/com/codename1/impl/javase/JavaSEPort.java b/Ports/JavaSE/src/com/codename1/impl/javase/JavaSEPort.java index 2a1bda2f9b..5400f1198f 100644 --- a/Ports/JavaSE/src/com/codename1/impl/javase/JavaSEPort.java +++ b/Ports/JavaSE/src/com/codename1/impl/javase/JavaSEPort.java @@ -6831,7 +6831,7 @@ public Object createMutableImage(int width, int height, int fillColor) { BufferedImage b = createTrackableBufferedImage(width, height); if (a != 0) { Graphics2D g = b.createGraphics(); - g.setColor(new Color(fillColor)); + g.setColor(new Color(fillColor, true)); g.fillRect(0, 0, width, height); g.dispose(); } diff --git a/maven/core-unittests/src/test/java/com/codename1/analytics/AnalyticsServiceTest.java b/maven/core-unittests/src/test/java/com/codename1/analytics/AnalyticsServiceTest.java index c5a1f228fd..eac3d8f4fa 100644 --- a/maven/core-unittests/src/test/java/com/codename1/analytics/AnalyticsServiceTest.java +++ b/maven/core-unittests/src/test/java/com/codename1/analytics/AnalyticsServiceTest.java @@ -2,6 +2,7 @@ import com.codename1.io.ConnectionRequest; import com.codename1.junit.FormTest; +import com.codename1.junit.TestLogger; import com.codename1.junit.UITestBase; import java.util.List; @@ -27,6 +28,7 @@ void testVisitQueuesAnalyticsRequest() { @FormTest void testCrashReportQueued() { + TestLogger.install(); implementation.clearQueuedRequests(); AnalyticsService.init("UA-2", "app.example.com"); AnalyticsService.setAppsMode(true); @@ -35,5 +37,6 @@ void testCrashReportQueued() { List requests = implementation.getQueuedRequests(); assertEquals(1, requests.size()); assertTrue(requests.get(0).getUrl().contains("google-analytics")); + TestLogger.remove(); } } diff --git a/scripts/android/tests/ProcessScreenshots.java b/scripts/android/tests/ProcessScreenshots.java index c7cd8e2ab4..fc91793131 100644 --- a/scripts/android/tests/ProcessScreenshots.java +++ b/scripts/android/tests/ProcessScreenshots.java @@ -335,7 +335,7 @@ private static PNGImage loadPng(Path path) throws IOException { byte[] data = Files.readAllBytes(path); for (int i = 0; i < PNG_SIGNATURE.length; i++) { if (data[i] != PNG_SIGNATURE[i]) { - throw new IOException(path + " is not a PNG file (missing signature)"); + throw new IOException(path + " is not a PNG file (missing signature) on " + path); } } int offset = PNG_SIGNATURE.length; @@ -350,7 +350,7 @@ private static PNGImage loadPng(Path path) throws IOException { byte[] type = java.util.Arrays.copyOfRange(data, offset + 4, offset + 8); offset += 8; if (offset + length + 4 > data.length) { - throw new IOException("PNG chunk truncated before CRC"); + throw new IOException("PNG chunk truncated before CRC while processing: " + path); } byte[] chunkData = java.util.Arrays.copyOfRange(data, offset, offset + length); offset += length + 4; // skip data + CRC @@ -364,7 +364,7 @@ private static PNGImage loadPng(Path path) throws IOException { int filter = chunkData[11] & 0xFF; interlace = chunkData[12] & 0xFF; if (compression != 0 || filter != 0) { - throw new IOException("Unsupported PNG compression or filter method"); + throw new IOException("Unsupported PNG compression or filter method on " + path); } } else if ("IDAT".equals(chunkType)) { idatChunks.add(chunkData); @@ -373,10 +373,10 @@ private static PNGImage loadPng(Path path) throws IOException { } } if (width <= 0 || height <= 0) { - throw new IOException("Missing IHDR chunk"); + throw new IOException("Missing IHDR chunk on " + path); } if (interlace != 0) { - throw new IOException("Interlaced PNGs are not supported"); + throw new IOException("Interlaced PNGs are not supported " + path); } int bytesPerPixel = bytesPerPixel(bitDepth, colorType); byte[] combined = concat(idatChunks); diff --git a/scripts/hellocodenameone/common/src/main/css/theme.css b/scripts/hellocodenameone/common/src/main/css/theme.css index 1b645201b0..f6f2aa1dfd 100644 --- a/scripts/hellocodenameone/common/src/main/css/theme.css +++ b/scripts/hellocodenameone/common/src/main/css/theme.css @@ -52,3 +52,12 @@ SideCommand { font-size: 4mm; border-bottom: 2px solid #cccccc; } + +GraphicsForm { + background: #cccccc; +} + +GraphicsComponent { + padding: 0px; + margin: 1mm; +} \ No newline at end of file diff --git a/scripts/hellocodenameone/common/src/main/java/com/codenameone/examples/hellocodenameone/HelloCodenameOne.java b/scripts/hellocodenameone/common/src/main/java/com/codenameone/examples/hellocodenameone/HelloCodenameOne.java index 82cf0b004e..9f1175fca4 100644 --- a/scripts/hellocodenameone/common/src/main/java/com/codenameone/examples/hellocodenameone/HelloCodenameOne.java +++ b/scripts/hellocodenameone/common/src/main/java/com/codenameone/examples/hellocodenameone/HelloCodenameOne.java @@ -1,5 +1,6 @@ package com.codenameone.examples.hellocodenameone; +import com.codename1.system.Lifecycle; import com.codename1.testing.TestReporting; import com.codename1.ui.Button; import com.codename1.ui.BrowserComponent; @@ -15,33 +16,15 @@ import com.codenameone.examples.hellocodenameone.tests.Cn1ssDeviceRunner; import com.codenameone.examples.hellocodenameone.tests.Cn1ssDeviceRunnerReporter; -public class HelloCodenameOne { - private Form current; - private static boolean deviceRunnerExecuted; - +public class HelloCodenameOne extends Lifecycle { + @Override public void init(Object context) { + super.init(context); TestReporting.setInstance(new Cn1ssDeviceRunnerReporter()); } - public void start() { - if (current != null) { - current.show(); - return; - } - Form c = CN.getCurrentForm(); - if (!deviceRunnerExecuted || c == null) { - deviceRunnerExecuted = true; - new Thread(() -> new Cn1ssDeviceRunner().runSuite()).start(); - return; - } - c.show(); - } - - public void stop() { - current = Display.getInstance().getCurrent(); - } - - public void destroy() { - // Nothing to clean up for this sample + @Override + public void runApp() { + new Thread(() -> new Cn1ssDeviceRunner().runSuite()).start(); } } diff --git a/scripts/hellocodenameone/common/src/main/java/com/codenameone/examples/hellocodenameone/tests/AbstractGraphicsScreenshotTest.java b/scripts/hellocodenameone/common/src/main/java/com/codenameone/examples/hellocodenameone/tests/AbstractGraphicsScreenshotTest.java index 24fd13c419..4c0f5f5cee 100644 --- a/scripts/hellocodenameone/common/src/main/java/com/codenameone/examples/hellocodenameone/tests/AbstractGraphicsScreenshotTest.java +++ b/scripts/hellocodenameone/common/src/main/java/com/codenameone/examples/hellocodenameone/tests/AbstractGraphicsScreenshotTest.java @@ -1,18 +1,118 @@ package com.codenameone.examples.hellocodenameone.tests; +import com.codename1.ui.CN; import com.codename1.ui.Component; +import com.codename1.ui.Font; import com.codename1.ui.Form; +import com.codename1.ui.Graphics; +import com.codename1.ui.Image; +import com.codename1.ui.geom.Rectangle; import com.codename1.ui.layouts.BorderLayout; +import com.codename1.ui.layouts.GridLayout; -abstract class AbstractGraphicsScreenshotTest extends BaseTest { - protected abstract Component createContent(); +public abstract class AbstractGraphicsScreenshotTest extends BaseTest { + private final int[] colorSet = {0xff0000, 0xff00, 0xff, 0xffffff}; + private int currentColor = -1; + private int factor = 0; + + protected void nextColor(Graphics g) { + if(factor == 0) { + factor = CN.getDisplayWidth() < 400 ? 5 : 1; + } + if(currentColor == -1) { + currentColor = 0; + g.setColor(colorSet[0]); + } + g.darkerColor(1); + if(g.getColor() == 0) { + currentColor++; + if (currentColor == colorSet.length) { + currentColor = 0; + } + g.setColor(colorSet[currentColor]); + } + } + + protected abstract void drawContent(Graphics g, Rectangle bounds); protected abstract String screenshotName(); + static abstract class CleanPaintComponent extends Component { + CleanPaintComponent() { + setUIID("GraphicsComponent"); + } + + @Override + public void paint(Graphics g) { + int alpha = g.getAlpha(); + int color = g.getColor(); + Font font = g.getFont(); + g.pushClip(); + cleanPaint(g); + g.popClip(); + g.setFont(font); + g.setColor(color); + g.setAlpha(alpha); + } + + protected abstract void cleanPaint(Graphics g); + } + @Override public boolean runTest() { - Form form = createForm("Graphics", new BorderLayout(), screenshotName()); - form.add(BorderLayout.CENTER, createContent()); + Form form = createForm(screenshotName(), new GridLayout(2, 2), screenshotName()); + form.setUIID("GraphicsForm"); + form.add(new CleanPaintComponent() { + @Override + public void cleanPaint(Graphics g) { + currentColor = -1; + g.setAntiAliased(false); + g.setAntiAliasedText(false); + g.fillRect(getX(), getY(), getWidth(), getHeight()); + drawContent(g, getBounds()); + } + }); + form.add(new CleanPaintComponent() { + @Override + public void cleanPaint(Graphics g) { + currentColor = -1; + g.setAntiAliased(true); + g.setAntiAliasedText(true); + g.fillRect(getX(), getY(), getWidth(), getHeight()); + drawContent(g, getBounds()); + } + }); + form.add(new CleanPaintComponent() { + private Image img; + @Override + public void cleanPaint(Graphics g) { + if (img == null || img.getWidth() != getWidth() || img.getHeight() != getHeight()) { + currentColor = -1; + img = Image.createImage(getWidth(), getHeight()); + Graphics imgGraphics = img.getGraphics(); + imgGraphics.setAntiAliased(false); + imgGraphics.setAntiAliasedText(false); + drawContent(imgGraphics, new Rectangle(0, 0, img.getWidth(), img.getHeight())); + } + g.drawImage(img, getX(), getY()); + } + }); + form.add(new CleanPaintComponent() { + private Image img; + @Override + public void cleanPaint(Graphics g) { + if (img == null || img.getWidth() != getWidth() || img.getHeight() != getHeight()) { + currentColor = -1; + img = Image.createImage(getWidth(), getHeight()); + Graphics imgGraphics = img.getGraphics(); + imgGraphics.setAntiAliased(true); + imgGraphics.setAntiAliasedText(true); + drawContent(imgGraphics, new Rectangle(0, 0, img.getWidth(), img.getHeight())); + } + g.drawImage(img, getX(), getY()); + } + }); + form.show(); return true; } diff --git a/scripts/hellocodenameone/common/src/main/java/com/codenameone/examples/hellocodenameone/tests/BrowserComponentScreenshotTest.java b/scripts/hellocodenameone/common/src/main/java/com/codenameone/examples/hellocodenameone/tests/BrowserComponentScreenshotTest.java index cacb198197..76a69b7c0e 100644 --- a/scripts/hellocodenameone/common/src/main/java/com/codenameone/examples/hellocodenameone/tests/BrowserComponentScreenshotTest.java +++ b/scripts/hellocodenameone/common/src/main/java/com/codenameone/examples/hellocodenameone/tests/BrowserComponentScreenshotTest.java @@ -2,7 +2,6 @@ import com.codename1.ui.BrowserComponent; import com.codename1.ui.Form; -import com.codename1.ui.CN; import com.codename1.ui.layouts.BorderLayout; import com.codename1.ui.util.UITimer; diff --git a/scripts/hellocodenameone/common/src/main/java/com/codenameone/examples/hellocodenameone/tests/Cn1ssDeviceRunner.java b/scripts/hellocodenameone/common/src/main/java/com/codenameone/examples/hellocodenameone/tests/Cn1ssDeviceRunner.java index 05971ef04c..98febbba7d 100644 --- a/scripts/hellocodenameone/common/src/main/java/com/codenameone/examples/hellocodenameone/tests/Cn1ssDeviceRunner.java +++ b/scripts/hellocodenameone/common/src/main/java/com/codenameone/examples/hellocodenameone/tests/Cn1ssDeviceRunner.java @@ -1,25 +1,44 @@ package com.codenameone.examples.hellocodenameone.tests; -import com.codename1.impl.CodenameOneThread; -import com.codename1.io.Log; import com.codename1.io.Util; import com.codename1.testing.DeviceRunner; import com.codename1.testing.TestReporting; import com.codename1.ui.CN; import com.codename1.ui.Display; import com.codename1.ui.Form; -import com.codename1.testing.AbstractTest; import com.codename1.util.StringUtil; - -import java.util.List; +import com.codenameone.examples.hellocodenameone.tests.graphics.AffineScale; +import com.codenameone.examples.hellocodenameone.tests.graphics.DrawArc; +import com.codenameone.examples.hellocodenameone.tests.graphics.DrawGradient; +import com.codenameone.examples.hellocodenameone.tests.graphics.DrawImage; +import com.codenameone.examples.hellocodenameone.tests.graphics.DrawLine; +import com.codenameone.examples.hellocodenameone.tests.graphics.DrawRect; +import com.codenameone.examples.hellocodenameone.tests.graphics.DrawRoundRect; +import com.codenameone.examples.hellocodenameone.tests.graphics.DrawString; +import com.codenameone.examples.hellocodenameone.tests.graphics.DrawStringDecorated; +import com.codenameone.examples.hellocodenameone.tests.graphics.FillArc; +import com.codenameone.examples.hellocodenameone.tests.graphics.FillPolygon; +import com.codenameone.examples.hellocodenameone.tests.graphics.FillRect; +import com.codenameone.examples.hellocodenameone.tests.graphics.FillRoundRect; +import com.codenameone.examples.hellocodenameone.tests.graphics.Scale; public final class Cn1ssDeviceRunner extends DeviceRunner { private static final BaseTest[] TEST_CLASSES = new BaseTest[] { new MainScreenScreenshotTest(), - new GraphicsPipelineScreenshotTest(), - new GraphicsShapesAndGradientsScreenshotTest(), - new GraphicsStateAndTextScreenshotTest(), - new GraphicsTransformationsScreenshotTest(), + new DrawLine(), + new FillRect(), + new DrawRect(), + new FillRoundRect(), + new DrawRoundRect(), + new FillArc(), + new DrawArc(), + new DrawString(), + new DrawImage(), + new DrawStringDecorated(), + new DrawGradient(), + new FillPolygon(), + new AffineScale(), + new Scale(), new BrowserComponentScreenshotTest(), new MediaPlaybackScreenshotTest() }; @@ -62,6 +81,9 @@ public void runSuite() { } log("CN1SS:SUITE:FINISHED"); TestReporting.getInstance().testExecutionFinished(getClass().getName()); + if (CN.isSimulator()) { + Display.getInstance().exitApplication(); + } } private static void log(String msg) { diff --git a/scripts/hellocodenameone/common/src/main/java/com/codenameone/examples/hellocodenameone/tests/Cn1ssDeviceRunnerHelper.java b/scripts/hellocodenameone/common/src/main/java/com/codenameone/examples/hellocodenameone/tests/Cn1ssDeviceRunnerHelper.java index 54b570843e..936f29931c 100644 --- a/scripts/hellocodenameone/common/src/main/java/com/codenameone/examples/hellocodenameone/tests/Cn1ssDeviceRunnerHelper.java +++ b/scripts/hellocodenameone/common/src/main/java/com/codenameone/examples/hellocodenameone/tests/Cn1ssDeviceRunnerHelper.java @@ -1,5 +1,6 @@ package com.codenameone.examples.hellocodenameone.tests; +import com.codename1.io.Storage; import com.codename1.io.Util; import com.codename1.io.Log; import com.codename1.ui.Display; @@ -61,6 +62,9 @@ static void emitCurrentFormScreenshot(String testName) { println("CN1SS:ERR:test=" + safeName + " message=PNG encoding unavailable"); println("CN1SS:END:" + safeName); } + if(Display.getInstance().isSimulator()) { + io.save(screenshot, Storage.getInstance().createOutputStream(safeName + ".png"), ImageIO.FORMAT_PNG, 1); + } ByteArrayOutputStream pngOut = new ByteArrayOutputStream(Math.max(1024, width * height / 2)); io.save(screenshot, pngOut, ImageIO.FORMAT_PNG, 1f); byte[] pngBytes = pngOut.toByteArray(); diff --git a/scripts/hellocodenameone/common/src/main/java/com/codenameone/examples/hellocodenameone/tests/GraphicsPipelineScreenshotTest.java b/scripts/hellocodenameone/common/src/main/java/com/codenameone/examples/hellocodenameone/tests/GraphicsPipelineScreenshotTest.java deleted file mode 100644 index aedc948376..0000000000 --- a/scripts/hellocodenameone/common/src/main/java/com/codenameone/examples/hellocodenameone/tests/GraphicsPipelineScreenshotTest.java +++ /dev/null @@ -1,155 +0,0 @@ -package com.codenameone.examples.hellocodenameone.tests; - -import com.codename1.testing.AbstractTest; -import com.codename1.ui.Component; -import com.codename1.ui.Display; -import com.codename1.ui.Form; -import com.codename1.ui.Graphics; -import com.codename1.ui.geom.Dimension; -import com.codename1.ui.layouts.BorderLayout; - -public class GraphicsPipelineScreenshotTest extends BaseTest { - @Override - public boolean runTest() throws Exception { - Form form = createForm("Graphics Pipeline", new BorderLayout(), "GraphicsPipeline"); - form.add(BorderLayout.CENTER, new GraphicsShowcase()); - form.show(); - return true; - } - - private static final class GraphicsShowcase extends Component { - @Override - protected Dimension calcPreferredSize() { - int w = Math.max(Display.getInstance().getDisplayWidth(), 420); - int h = Math.max(Display.getInstance().getDisplayHeight(), 720); - return new Dimension(w, h); - } - - @Override - public void paint(Graphics g) { - super.paint(g); - int w = getWidth(); - int h = getHeight(); - g.setColor(0x0b1220); - g.fillRect(0, 0, w, h); - - int margin = 16; - int columnWidth = (w - margin * 3) / 2; - int rowHeight = (h - margin * 3) / 2; - - drawBasicPrimitives(g, margin, margin, columnWidth, rowHeight); - drawTransforms(g, margin * 2 + columnWidth, margin, columnWidth, rowHeight); - drawClipAndAlpha(g, margin, margin * 2 + rowHeight, columnWidth, rowHeight); - drawGradients(g, margin * 2 + columnWidth, margin * 2 + rowHeight, columnWidth, rowHeight); - } - - private void drawBasicPrimitives(Graphics g, int x, int y, int w, int h) { - g.setColor(0x111827); - g.fillRect(x, y, w, h); - g.setColor(0x475569); - g.drawRect(x, y, w - 1, h - 1); - - g.setColor(0xfacc15); - g.drawLine(x + 8, y + 8, x + w - 8, y + 8); - - g.setColor(0x22c55e); - g.fillRect(x + 8, y + 18, w / 3, 36); - g.setColor(0xf97316); - g.drawRect(x + w / 3 + 16, y + 18, w / 3, 36); - - g.setColor(0x38bdf8); - g.fillRoundRect(x + 8, y + 62, w / 3, 40, 14, 14); - g.setColor(0xec4899); - g.drawRoundRect(x + w / 3 + 16, y + 62, w / 3, 40, 18, 18); - - g.setColor(0xa855f7); - g.fillArc(x + 8, y + 108, 70, 70, 30, 210); - g.setColor(0x6366f1); - g.drawArc(x + w / 3 + 16, y + 108, 70, 70, 200, 300); - - int[] px = new int[] {x + w - 78, x + w - 34, x + w - 58}; - int[] py = new int[] {y + 24, y + 24, y + 70}; - g.setColor(0x7dd3fc); - g.fillPolygon(px, py, px.length); - g.setColor(0x0ea5e9); - g.drawPolygon(px, py, px.length); - - g.setColor(0xe5e7eb); - g.drawString("basic primitives", x + 10, y + h - 28); - } - - private void drawTransforms(Graphics g, int x, int y, int w, int h) { - g.setColor(0x0f172a); - g.fillRect(x, y, w, h); - g.setColor(0x334155); - g.drawRect(x, y, w - 1, h - 1); - - int cx = x + w / 2; - int cy = y + h / 2; - - g.translate(cx, cy); - g.setColor(0x22c55e); - g.fillRect(-50, -22, 100, 44); - - if (g.isAffineSupported()) { - g.rotateRadians((float) Math.toRadians(18)); - g.scale(0.85f, 0.85f); - g.setColor(0xf97316); - g.fillRoundRect(-64, -30, 128, 60, 16, 16); - g.shear(0.25f, 0); - g.setColor(0x38bdf8); - g.drawRect(-70, -36, 140, 72); - g.resetAffine(); - } - - g.setColor(0xf8fafc); - g.drawString("translate + affine", -58, 4); - g.translate(-cx, -cy); - - g.setColor(0x14b8a6); - g.drawArc(x + 10, y + h - 70, 54, 54, 30, 280); - g.setColor(0xf43f5e); - g.fillArc(x + w - 78, y + h - 78, 64, 64, 200, 140); - } - - private void drawClipAndAlpha(Graphics g, int x, int y, int w, int h) { - g.setColor(0x0f172a); - g.fillRect(x, y, w, h); - g.setColor(0x475569); - g.drawRect(x, y, w - 1, h - 1); - - int oldClipX = g.getClipX(); - int oldClipY = g.getClipY(); - int oldClipW = g.getClipWidth(); - int oldClipH = g.getClipHeight(); - - g.setClip(x + 10, y + 10, w - 20, h - 60); - g.fillLinearGradient(0x22d3ee, 0x2563eb, x + 10, y + 10, w - 20, h - 60, false); - - g.setAlpha(150); - g.setColor(0xfbbf24); - g.fillRect(x + 24, y + 24, w / 2, 54); - g.setColor(0x10b981); - g.fillRect(x + w / 3, y + 40, w / 2, 54); - g.setAlpha(255); - - g.setClip(oldClipX, oldClipY, oldClipW, oldClipH); - g.setColor(0xe5e7eb); - g.drawString("clip + alpha", x + 10, y + h - 28); - } - - private void drawGradients(Graphics g, int x, int y, int w, int h) { - g.setColor(0x0f172a); - g.fillRect(x, y, w, h); - g.setColor(0x334155); - g.drawRect(x, y, w - 1, h - 1); - - g.fillLinearGradient(0xf472b6, 0xc084fc, x + 8, y + 12, w - 16, 72, true); - g.fillRadialGradient(0x22c55e, 0x0ea5e9, x + 12, y + 96, w / 2 - 18, h - 112); - g.fillRectRadialGradient(0xf43f5e, 0xf59e0b, x + w / 2, y + 96, w / 2 - 12, h - 112, 0.3f, 0.5f, 0.8f); - - g.setColor(0xe5e7eb); - g.drawString("linear + radial gradients", x + 10, y + h - 28); - } - } -} diff --git a/scripts/hellocodenameone/common/src/main/java/com/codenameone/examples/hellocodenameone/tests/GraphicsShapesAndGradientsScreenshotTest.java b/scripts/hellocodenameone/common/src/main/java/com/codenameone/examples/hellocodenameone/tests/GraphicsShapesAndGradientsScreenshotTest.java deleted file mode 100644 index 5f9d963971..0000000000 --- a/scripts/hellocodenameone/common/src/main/java/com/codenameone/examples/hellocodenameone/tests/GraphicsShapesAndGradientsScreenshotTest.java +++ /dev/null @@ -1,164 +0,0 @@ -package com.codenameone.examples.hellocodenameone.tests; - -import com.codename1.ui.Component; -import com.codename1.ui.Display; -import com.codename1.ui.Graphics; -import com.codename1.ui.Image; -import com.codename1.ui.Stroke; -import com.codename1.ui.geom.Dimension; -import com.codename1.ui.geom.GeneralPath; - -public class GraphicsShapesAndGradientsScreenshotTest extends AbstractGraphicsScreenshotTest { - @Override - protected Component createContent() { - return new ShapesAndGradientsCanvas(); - } - - @Override - protected String screenshotName() { - return "GraphicsShapesAndGradients"; - } - - private static final class ShapesAndGradientsCanvas extends Component { - private Image patternedImage; - - @Override - protected Dimension calcPreferredSize() { - int w = Math.max(Display.getInstance().getDisplayWidth(), 520); - int h = Math.max(Display.getInstance().getDisplayHeight(), 760); - return new Dimension(w, h); - } - - @Override - public void paint(Graphics g) { - super.paint(g); - int w = getWidth(); - int h = getHeight(); - g.setColor(0x0b1220); - g.fillRect(0, 0, w, h); - - int margin = 12; - int columnWidth = (w - margin * 3) / 2; - int rowHeight = (h - margin * 3) / 2; - - paintRectanglesAndLines(g, margin, margin, columnWidth, rowHeight); - paintPolygonsAndGradients(g, margin * 2 + columnWidth, margin, columnWidth, rowHeight); - paintImagesAndShadows(g, margin, margin * 2 + rowHeight, columnWidth, rowHeight); - paintShapesAndTriangles(g, margin * 2 + columnWidth, margin * 2 + rowHeight, columnWidth, rowHeight); - } - - private void paintRectanglesAndLines(Graphics g, int x, int y, int w, int h) { - g.setColor(0x111827); - g.fillRect(x, y, w, h); - g.setColor(0x334155); - g.drawRect(x, y, w - 1, h - 1, 2); - - g.setColor(0xf97316); - g.drawLine(x + 8, y + 12, x + w - 8, y + 12); - g.setColor(0x22c55e); - g.fillRect(x + 8, y + 20, w / 2, 36); - g.setColor(0xf59e0b); - g.fillRect(x + w / 2 + 12, y + 20, w / 2 - 20, 36, (byte) 120); - - g.setColor(0x38bdf8); - g.drawRect(x + 8, y + 64, w / 3, 40); - g.setColor(0x8b5cf6); - g.drawRect(x + w / 3 + 16, y + 64, w / 3, 40, 4); - - g.setColor(0x16a34a); - g.fillRoundRect(x + 8, y + 112, w / 3, 46, 16, 16); - g.setColor(0xec4899); - g.drawRoundRect(x + w / 3 + 16, y + 112, w / 3, 46, 12, 12); - - g.setColor(0xf43f5e); - g.fillArc(x + 8, y + 168, 70, 70, 30, 240); - g.setColor(0x0ea5e9); - g.drawArc(x + w / 3 + 16, y + 168, 70, 70, 200, 140); - - g.setColor(0xf8fafc); - g.drawString("rects + arcs", x + 10, y + h - 24); - } - - private void paintPolygonsAndGradients(Graphics g, int x, int y, int w, int h) { - g.setColor(0x0f172a); - g.fillRect(x, y, w, h); - g.setColor(0x475569); - g.drawRect(x, y, w - 1, h - 1); - - int[] px = new int[] {x + 16, x + 60, x + 32, x + 68, x + 22}; - int[] py = new int[] {y + 16, y + 20, y + 44, y + 64, y + 60}; - g.setColor(0xf87171); - g.fillPolygon(px, py, px.length); - g.setColor(0x10b981); - g.drawPolygon(px, py, px.length); - - g.setColor(0x22d3ee); - g.fillTriangle(x + w - 110, y + 16, x + w - 40, y + 20, x + w - 60, y + 74); - - g.fillLinearGradient(0x22d3ee, 0x2563eb, x + 10, y + 90, w - 20, 60, true); - g.fillLinearGradient(0xf472b6, 0xf59e0b, x + 10, y + 154, w - 20, 60, false); - - g.fillRadialGradient(0x34d399, 0x0ea5e9, x + 12, y + 220, w / 2 - 16, h - 232); - g.fillRadialGradient(0xf43f5e, 0xc084fc, x + w / 2, y + 220, w / 2 - 16, h - 232, 30, 220); - g.fillRectRadialGradient(0x2563eb, 0x22d3ee, x + 20, y + h - 80, w - 40, 64, 0.4f, 0.5f, 0.8f); - - g.setColor(0xe2e8f0); - g.drawString("polygons + gradients", x + 10, y + h - 24); - } - - private void paintImagesAndShadows(Graphics g, int x, int y, int w, int h) { - g.setColor(0x111827); - g.fillRect(x, y, w, h); - g.setColor(0x475569); - g.drawRect(x, y, w - 1, h - 1); - - if (patternedImage == null) { - patternedImage = Image.createImage(72, 72, 0xfff1f5f9); - Graphics imgG = patternedImage.getGraphics(); - imgG.setColor(0x1d4ed8); - imgG.fillRect(6, 6, 60, 60); - imgG.setColor(0xf97316); - imgG.fillRect(18, 18, 18, 18); - imgG.setColor(0x0ea5e9); - imgG.drawRect(0, 0, 71, 71); - } - - g.drawImage(patternedImage, x + 12, y + 12); - g.drawImage(patternedImage, x + 120, y + 16, 60, 60); - g.tileImage(patternedImage, x + 12, y + 86, w - 24, 60); - - g.drawShadow(patternedImage, x + w / 2, y + 12, 6, 12, 8, 4, 0xcc0f172a, 0.45f); - g.clearRect(x + w / 2 + 12, y + 90, w / 2 - 24, 28); - - g.setColor(0xf8fafc); - g.drawString("images + shadow", x + 10, y + h - 24); - } - - private void paintShapesAndTriangles(Graphics g, int x, int y, int w, int h) { - g.setColor(0x0f172a); - g.fillRect(x, y, w, h); - g.setColor(0x334155); - g.drawRect(x, y, w - 1, h - 1); - - GeneralPath shape = new GeneralPath(); - shape.moveTo(x + 12, y + 12); - shape.lineTo(x + w / 2f, y + 60); - shape.lineTo(x + 18, y + 108); - shape.closePath(); - if (g.isShapeSupported()) { - g.setColor(0x22c55e); - g.fillShape(shape); - g.setColor(0xf97316); - g.drawShape(shape, new Stroke(3, Stroke.CAP_ROUND, Stroke.JOIN_ROUND, 1f)); - } - - g.setColor(0x38bdf8); - g.fillTriangle(x + w - 120, y + 14, x + w - 24, y + 48, x + w - 96, y + 104); - g.setColor(0xf43f5e); - g.drawLine(x + w - 110, y + h - 68, x + w - 24, y + h - 68); - - g.setColor(0xe2e8f0); - g.drawString("shapes + stroke", x + 10, y + h - 24); - } - } -} diff --git a/scripts/hellocodenameone/common/src/main/java/com/codenameone/examples/hellocodenameone/tests/GraphicsStateAndTextScreenshotTest.java b/scripts/hellocodenameone/common/src/main/java/com/codenameone/examples/hellocodenameone/tests/GraphicsStateAndTextScreenshotTest.java deleted file mode 100644 index 6c599c8de3..0000000000 --- a/scripts/hellocodenameone/common/src/main/java/com/codenameone/examples/hellocodenameone/tests/GraphicsStateAndTextScreenshotTest.java +++ /dev/null @@ -1,188 +0,0 @@ -package com.codenameone.examples.hellocodenameone.tests; - -import com.codename1.ui.Component; -import com.codename1.ui.Display; -import com.codename1.ui.Font; -import com.codename1.ui.Graphics; -import com.codename1.ui.Image; -import com.codename1.ui.geom.Dimension; -import com.codename1.ui.geom.GeneralPath; -import com.codename1.ui.geom.Rectangle; -import com.codename1.ui.plaf.Style; -import com.codename1.ui.LinearGradientPaint; -import com.codename1.ui.MultipleGradientPaint; - -public class GraphicsStateAndTextScreenshotTest extends AbstractGraphicsScreenshotTest { - @Override - protected Component createContent() { - return new StateAndTextCanvas(); - } - - @Override - protected String screenshotName() { - return "GraphicsStateAndText"; - } - - private static final class StateAndTextCanvas extends Component { - @Override - protected Dimension calcPreferredSize() { - int w = Math.max(Display.getInstance().getDisplayWidth(), 480); - int h = Math.max(Display.getInstance().getDisplayHeight(), 720); - return new Dimension(w, h); - } - - @Override - public void paint(Graphics g) { - super.paint(g); - int w = getWidth(); - int h = getHeight(); - g.setColor(0x0f172a); - g.fillRect(0, 0, w, h); - - int margin = 12; - int columnWidth = (w - margin * 3) / 2; - int rowHeight = (h - margin * 3) / 2; - - paintColorAndClips(g, margin, margin, columnWidth, rowHeight); - paintAlphaAndRendering(g, margin * 2 + columnWidth, margin, columnWidth, rowHeight); - paintTextAndFonts(g, margin, margin * 2 + rowHeight, columnWidth * 2 + margin, rowHeight); - } - - private void paintColorAndClips(Graphics g, int x, int y, int w, int h) { - int originalColor = g.setAndGetColor(0x1d4ed8); - g.fillRect(x, y, w, h); - g.setColor(0x334155); - g.drawRect(x, y, w - 1, h - 1); - - g.lighterColor(40); - g.fillRect(x + 8, y + 8, w / 3, 24); - g.darkerColor(80); - g.fillRect(x + 8, y + 40, w / 3, 24); - - LinearGradientPaint paint = new LinearGradientPaint( - 0f, - 0f, - (float) w, - 0f, - new float[] {0f, 1f}, - new int[] {0xff22d3ee, 0xff6366f1}, - MultipleGradientPaint.CycleMethod.NO_CYCLE, - MultipleGradientPaint.ColorSpaceType.SRGB, - null); - g.setColor(paint); - GeneralPath shape = new GeneralPath(); - shape.moveTo(x + w - 12, y + 12); - shape.lineTo(x + w / 2f, y + h / 2f); - shape.lineTo(x + w - 12, y + h - 12); - shape.lineTo(x + w - 12, y + 12); - g.fillShape(shape); - g.setColor(g.getColor()); - g.drawString("paint fillShape", x + w / 2 - 40, y + h - 24); - - int[] clipArray = new int[] {x + w / 6, y + h / 4, w / 2, h / 3}; - g.setClip(clipArray); - int[] fullClip = g.getClip(); - int clipX = g.getClipX(); - int clipY = g.getClipY(); - int clipW = g.getClipWidth(); - int clipH = g.getClipHeight(); - g.pushClip(); - g.clipRect(x + w / 4, y + h / 3, w / 2, h / 2); - g.setColor(0xfbbf24); - g.fillRect(x, y, w, h); - g.popClip(); - GeneralPath clipShape = new GeneralPath(); - clipShape.moveTo(x + 20, y + 20); - clipShape.lineTo(x + 50, y + 20); - clipShape.lineTo(x + 20, y + 60); - clipShape.closePath(); - if (g.isShapeClipSupported()) { - g.setClip(clipShape); - g.setColor(0x10b981); - g.fillRect(x, y, w, h); - } - g.setClip(new Rectangle(clipX, clipY, clipW, clipH)); - g.setClip(x, y, w, h); - g.setColor(0xe2e8f0); - g.drawString("clip info: " + clipX + "," + clipY + " " + clipW + "x" + clipH, x + 10, y + 14); - g.drawString("clip array=" + fullClip[0] + "," + fullClip[1], x + 10, y + 34); - g.setColor(originalColor); - } - - private void paintAlphaAndRendering(Graphics g, int x, int y, int w, int h) { - g.setColor(0x0f766e); - g.fillRect(x, y, w, h); - g.setColor(0x14b8a6); - g.drawRect(x, y, w - 1, h - 1); - - boolean alphaSupported = g.isAlphaSupported(); - boolean aaSupported = g.isAntiAliasingSupported(); - boolean aaTextSupported = g.isAntiAliasedTextSupported(); - int oldAlpha = g.getAlpha(); - int previousAlpha = g.setAndGetAlpha(180); - g.setColor(0xf43f5e); - g.fillRect(x + 8, y + 8, w / 2, 40); - int concatenatedAlpha = g.concatenateAlpha(200); - g.setColor(0xfcd34d); - g.fillRect(x + 16, y + 28, w / 2, 40); - g.setAlpha(previousAlpha); - g.setAlpha(oldAlpha); - - g.setRenderingHints(Graphics.RENDERING_HINT_FAST); - int hints = g.getRenderingHints(); - g.setRenderingHints(0); - - g.setColor(0x0ea5e9); - g.fillRect(x + w / 2 + 8, y + 12, w / 3, 28); - g.fillRect(x + w / 2 + 8, y + 48, w / 3, 28, (byte) 120); - g.clearRect(x + w / 2 + 8, y + 84, w / 3, 18); - - g.setAntiAliased(true); - g.setAntiAliasedText(true); - boolean aa = g.isAntiAliased(); - boolean aaText = g.isAntiAliasedText(); - g.setColor(0xf8fafc); - g.drawString("alpha supported=" + alphaSupported + " aa sup=" + aaSupported + " text sup=" + aaTextSupported, x + 8, y + h - 56); - g.drawString("aa=" + aa + " text=" + aaText + " hints=" + hints + " concat=" + concatenatedAlpha, x + 8, y + h - 36); - g.setAntiAliased(false); - g.setAntiAliasedText(false); - } - - private void paintTextAndFonts(Graphics g, int x, int y, int w, int h) { - g.setClip(x, y, w, h); - g.setColor(0x111827); - g.fillRect(x, y, w, h); - g.setColor(0x475569); - g.drawRect(x, y, w - 1, h - 1); - - Font nativeFont = Font.createTrueTypeFont("native:MainLight"); - g.setFont(nativeFont.derive(Font.STYLE_BOLD, Font.getDefaultFont().getHeight() + 2)); - g.setColor(0x22c55e); - g.drawString("drawString", x + 10, y + 10, Style.TEXT_DECORATION_UNDERLINE); - g.setFont(nativeFont); - - g.setColor(0xf97316); - g.drawStringBaseline("baseline", x + 10, y + 42); - g.setColor(0x38bdf8); - g.drawStringBaseline("decorated", x + 120, y + 42, Style.TEXT_DECORATION_STRIKETHRU); - - g.setColor(0xf43f5e); - g.drawChar('G', x + 10, y + 72); - char[] chars = new char[] {'r', 'a', 'p', 'h', 'i', 'c', 's'}; - g.setColor(0xa855f7); - g.drawChars(chars, 0, chars.length, x + 32, y + 72); - - Image img = Image.createImage(60, 60, 0xffe0f2fe); - Graphics imgG = img.getGraphics(); - imgG.setColor(0x1d4ed8); - imgG.fillRect(4, 4, 52, 52); - g.drawImage(img, x + 10, y + 104); - g.drawImage(img, x + 84, y + 104, 48, 48); - - g.setColor(0xe5e7eb); - g.drawString("translate=" + g.getTranslateX() + "," + g.getTranslateY(), x + 10, y + h - 38); - g.drawString("paint? " + (g.getPaint() != null), x + 10, y + h - 20); - g.setClip(0, 0, getWidth(), getHeight()); - } - } -} diff --git a/scripts/hellocodenameone/common/src/main/java/com/codenameone/examples/hellocodenameone/tests/GraphicsTransformationsScreenshotTest.java b/scripts/hellocodenameone/common/src/main/java/com/codenameone/examples/hellocodenameone/tests/GraphicsTransformationsScreenshotTest.java deleted file mode 100644 index 48c8229164..0000000000 --- a/scripts/hellocodenameone/common/src/main/java/com/codenameone/examples/hellocodenameone/tests/GraphicsTransformationsScreenshotTest.java +++ /dev/null @@ -1,169 +0,0 @@ -package com.codenameone.examples.hellocodenameone.tests; - -import com.codename1.ui.Component; -import com.codename1.ui.Display; -import com.codename1.ui.Graphics; -import com.codename1.ui.Image; -import com.codename1.ui.Transform; -import com.codename1.ui.geom.Dimension; -import com.codename1.ui.geom.GeneralPath; -import com.codename1.ui.geom.Rectangle; - -public class GraphicsTransformationsScreenshotTest extends AbstractGraphicsScreenshotTest { - @Override - protected Component createContent() { - return new TransformCanvas(); - } - - @Override - protected String screenshotName() { - return "GraphicsTransformations"; - } - - private static final class TransformCanvas extends Component { - private Image marker; - - @Override - protected Dimension calcPreferredSize() { - int w = Math.max(Display.getInstance().getDisplayWidth(), 520); - int h = Math.max(Display.getInstance().getDisplayHeight(), 760); - return new Dimension(w, h); - } - - @Override - public void paint(Graphics g) { - super.paint(g); - int w = getWidth(); - int h = getHeight(); - g.setColor(0x0b1220); - g.fillRect(0, 0, w, h); - - int margin = 12; - int columnWidth = (w - margin * 3) / 2; - int rowHeight = (h - margin * 3) / 2; - - paintTransforms(g, margin, margin, columnWidth, rowHeight); - paintAffineOperations(g, margin * 2 + columnWidth, margin, columnWidth, rowHeight); - paintShapeAndClipSupport(g, margin, margin * 2 + rowHeight, columnWidth, rowHeight); - paintNativeAndScale(g, margin * 2 + columnWidth, margin * 2 + rowHeight, columnWidth, rowHeight); - } - - private void paintTransforms(Graphics g, int x, int y, int w, int h) { - g.setColor(0x111827); - g.fillRect(x, y, w, h); - g.setColor(0x334155); - g.drawRect(x, y, w - 1, h - 1); - - Transform original = Transform.makeIdentity(); - g.getTransform(original); - Transform legacy = g.getTransform(); - boolean transformSupported = g.isTransformSupported(); - boolean perspectiveSupported = g.isPerspectiveTransformSupported(); - - Transform translate = Transform.makeTranslation(40, 30); - Transform rotation = Transform.makeRotation((float) Math.toRadians(20), 0, 0); - translate.concatenate(rotation); - if (transformSupported) { - g.transform(translate); - } - g.setColor(0x22c55e); - g.fillRect(x + 10, y + 10, 120, 50); - g.setColor(0xf97316); - g.drawRect(x + 6, y + 6, 128, 58); - g.setTransform(original); - - g.setColor(0xe2e8f0); - g.drawString("transform ok=" + transformSupported + " persp=" + perspectiveSupported, x + 10, y + h - 24); - g.drawString( - "legacy tx=" + legacy.getTranslateX() + " ty=" + legacy.getTranslateY() + " sx=" + legacy.getScaleX() - + " sy=" + legacy.getScaleY(), - x + 10, - y + h - 44); - } - - private void paintAffineOperations(Graphics g, int x, int y, int w, int h) { - g.setColor(0x0f172a); - g.fillRect(x, y, w, h); - g.setColor(0x475569); - g.drawRect(x, y, w - 1, h - 1); - - int cx = x + w / 2; - int cy = y + h / 2; - g.translate(cx, cy); - if (marker == null) { - marker = Image.createImage(60, 60, 0xfff8fafc); - Graphics mg = marker.getGraphics(); - mg.setColor(0x2563eb); - mg.fillRect(8, 8, 44, 44); - } - - if (g.isAffineSupported()) { - g.scale(1.1f, 0.8f); - g.rotate((float) Math.toRadians(12)); - g.drawImage(marker, -30, -30); - g.rotateRadians((float) Math.toRadians(14)); - g.shear(0.2f, 0.1f); - g.drawImage(marker, 10, 8, 48, 48); - g.resetAffine(); - g.rotate((float) Math.toRadians(8), 0, 0); - g.rotateRadians((float) Math.toRadians(-12), 0, 0); - g.scale(0.9f, 0.9f); - g.rotate((float) Math.toRadians(18), 12, 12); - g.rotateRadians((float) Math.toRadians(-10), -8, -8); - g.shear(-0.15f, 0); - g.drawImage(marker, -12, 26); - g.resetAffine(); - } - g.translate(-cx, -cy); - g.setColor(0xf8fafc); - g.drawString("affine scaleX=" + g.getScaleX() + " scaleY=" + g.getScaleY(), x + 10, y + h - 24); - } - - private void paintShapeAndClipSupport(Graphics g, int x, int y, int w, int h) { - g.setColor(0x0f172a); - g.fillRect(x, y, w, h); - g.setColor(0x334155); - g.drawRect(x, y, w - 1, h - 1); - - boolean shapeSupported = g.isShapeSupported(); - boolean shapeClipSupported = g.isShapeClipSupported(); - GeneralPath path = new GeneralPath(); - path.moveTo(x + 16, y + 16); - path.lineTo(x + w - 16, y + 28); - path.lineTo(x + 24, y + h - 20); - path.closePath(); - if (shapeSupported) { - g.setColor(0xa855f7); - g.fillShape(path); - } - - Rectangle rectClip = new Rectangle(x + w / 3, y + h / 3, w / 2, h / 3); - if (shapeClipSupported) { - g.setClip(path); - } else { - g.setClip(rectClip.getX(), rectClip.getY(), rectClip.getSize().getWidth(), rectClip.getSize().getHeight()); - } - g.setColor(0x22d3ee); - g.fillRect(x, y, w, h); - g.setClip(0, 0, getWidth(), getHeight()); - g.setColor(0xe2e8f0); - g.drawString("shape?=" + shapeSupported + " clip?=" + shapeClipSupported, x + 10, y + h - 24); - } - - private void paintNativeAndScale(Graphics g, int x, int y, int w, int h) { - g.setColor(0x111827); - g.fillRect(x, y, w, h); - g.setColor(0x475569); - g.drawRect(x, y, w - 1, h - 1); - - Object nativeHandle = g.beginNativeGraphicsAccess(); - g.setColor(0x22c55e); - g.fillRect(x + 12, y + 12, w / 3, 48); - g.endNativeGraphicsAccess(); - - g.setColor(0xf97316); - g.drawString("native handle=" + (nativeHandle != null), x + 10, y + h - 48); - g.drawString("render hints=" + g.getRenderingHints(), x + 10, y + h - 28); - } - } -} diff --git a/scripts/hellocodenameone/common/src/main/java/com/codenameone/examples/hellocodenameone/tests/graphics/AffineScale.java b/scripts/hellocodenameone/common/src/main/java/com/codenameone/examples/hellocodenameone/tests/graphics/AffineScale.java new file mode 100644 index 0000000000..9d85c963a1 --- /dev/null +++ b/scripts/hellocodenameone/common/src/main/java/com/codenameone/examples/hellocodenameone/tests/graphics/AffineScale.java @@ -0,0 +1,38 @@ +package com.codenameone.examples.hellocodenameone.tests.graphics; + +import com.codename1.ui.Graphics; +import com.codename1.ui.Transform; +import com.codename1.ui.geom.AffineTransform; +import com.codename1.ui.geom.Rectangle; +import com.codenameone.examples.hellocodenameone.tests.AbstractGraphicsScreenshotTest; + +public class AffineScale extends AbstractGraphicsScreenshotTest { + + @Override + protected void drawContent(Graphics g, Rectangle bounds) { + if(!g.isAffineSupported()) { + g.drawString("Affine unsupported", 0, 0); + return; + } + + float xScale = 0.01f * ((float)bounds.getHeight()); + float yScale = 0.01f * ((float)bounds.getWidth()); + AffineTransform affine = new AffineTransform(); + affine.setToScale(xScale, yScale); + Transform transform = affine.toTransform(); + int translateX = (int)(bounds.getX() / xScale); + int translateY = (int)(bounds.getY() / yScale); + transform.translate(translateX, translateY); + g.setTransform(transform); + g.fillLinearGradient(0xff0000, 0xff, 0, 0, 100, 100, true); + + transform.scale(-1, 1); + g.fillLinearGradient(0xff0000, 0xff, 0, 100, 100, 100, true); + g.resetAffine(); + } + + @Override + protected String screenshotName() { + return "graphics-affine-scale"; + } +} diff --git a/scripts/hellocodenameone/common/src/main/java/com/codenameone/examples/hellocodenameone/tests/graphics/DrawArc.java b/scripts/hellocodenameone/common/src/main/java/com/codenameone/examples/hellocodenameone/tests/graphics/DrawArc.java new file mode 100644 index 0000000000..6f6088b0b0 --- /dev/null +++ b/scripts/hellocodenameone/common/src/main/java/com/codenameone/examples/hellocodenameone/tests/graphics/DrawArc.java @@ -0,0 +1,21 @@ +package com.codenameone.examples.hellocodenameone.tests.graphics; + +import com.codename1.ui.Graphics; +import com.codename1.ui.geom.Rectangle; +import com.codenameone.examples.hellocodenameone.tests.AbstractGraphicsScreenshotTest; + +public class DrawArc extends AbstractGraphicsScreenshotTest { + @Override + protected void drawContent(Graphics g, Rectangle bounds) { + g.setColor(0xffffff); + for (int iter = 0 ; iter < bounds.getWidth() / 2 ; iter++) { + nextColor(g); + g.drawArc(bounds.getX() + iter, bounds.getY() + iter, bounds.getX() + bounds.getWidth() - iter, bounds.getY() + bounds.getHeight() + iter, iter, 180); + } + } + + @Override + protected String screenshotName() { + return "graphics-draw-arc"; + } +} diff --git a/scripts/hellocodenameone/common/src/main/java/com/codenameone/examples/hellocodenameone/tests/graphics/DrawGradient.java b/scripts/hellocodenameone/common/src/main/java/com/codenameone/examples/hellocodenameone/tests/graphics/DrawGradient.java new file mode 100644 index 0000000000..db6a9ea069 --- /dev/null +++ b/scripts/hellocodenameone/common/src/main/java/com/codenameone/examples/hellocodenameone/tests/graphics/DrawGradient.java @@ -0,0 +1,33 @@ +package com.codenameone.examples.hellocodenameone.tests.graphics; + +import com.codename1.ui.EncodedImage; +import com.codename1.ui.FontImage; +import com.codename1.ui.Graphics; +import com.codename1.ui.Image; +import com.codename1.ui.RGBImage; +import com.codename1.ui.geom.Rectangle; +import com.codenameone.examples.hellocodenameone.tests.AbstractGraphicsScreenshotTest; + +public class DrawGradient extends AbstractGraphicsScreenshotTest { + + @Override + protected void drawContent(Graphics g, Rectangle bounds) { + int height = bounds.getHeight() / 3; + int width = bounds.getWidth() / 2; + int y = bounds.getY(); + g.fillRadialGradient(0xff, 0xff00, bounds.getX(), y, width, height); + g.fillRadialGradient(0xff, 0xff00, bounds.getX() + width, y, width, height,20, 200); + y += height; + + g.fillRectRadialGradient(0xff0000, 0xcccccc, bounds.getX() + width, y, width, height,0.5f, 0.5f, 2); + g.fillLinearGradient(0xff, 0x999999, bounds.getX(), y, width, height, true); + y += height; + + g.fillLinearGradient(0xff, 0x999999, bounds.getX(), y, width, height, false); + } + + @Override + protected String screenshotName() { + return "graphics-draw-gradient"; + } +} diff --git a/scripts/hellocodenameone/common/src/main/java/com/codenameone/examples/hellocodenameone/tests/graphics/DrawImage.java b/scripts/hellocodenameone/common/src/main/java/com/codenameone/examples/hellocodenameone/tests/graphics/DrawImage.java new file mode 100644 index 0000000000..3a351f9a97 --- /dev/null +++ b/scripts/hellocodenameone/common/src/main/java/com/codenameone/examples/hellocodenameone/tests/graphics/DrawImage.java @@ -0,0 +1,93 @@ +package com.codenameone.examples.hellocodenameone.tests.graphics; + +import com.codename1.ui.EncodedImage; +import com.codename1.ui.FontImage; +import com.codename1.ui.Graphics; +import com.codename1.ui.Image; +import com.codename1.ui.RGBImage; +import com.codename1.ui.geom.Rectangle; +import com.codenameone.examples.hellocodenameone.tests.AbstractGraphicsScreenshotTest; + +public class DrawImage extends AbstractGraphicsScreenshotTest { + private Image mutable; + private Image mutableWithAlpha; + private EncodedImage encoded; + private RGBImage rgbImage; + private Image fromRgba; + private Image fromBytes; + private FontImage fontImage; + private Image scaled; + + @Override + protected void drawContent(Graphics g, Rectangle bounds) { + int size = bounds.getWidth() / 4; + if(mutable == null) { + mutable = Image.createImage(size, size); + Graphics mg = mutable.getGraphics(); + mg.fillRadialGradient(0xff0000, 0xff, 0, 0, size, size); + mutableWithAlpha = Image.createImage(size, size, 0x2000ff00); + mg = mutableWithAlpha.getGraphics(); + mg.setColor(0xff0000); + mg.fillRect(30, 30, size - 60, size - 60); + encoded = EncodedImage.createFromImage(mutable, false); + rgbImage = new RGBImage(mutable); + fromRgba = Image.createImage(rgbImage.getRGB(), size, size); + fromBytes = Image.createImage(encoded.getImageData(), 0, encoded.getImageData().length); + fontImage = FontImage.createFixed("" + FontImage.MATERIAL_ALARM_ON, FontImage.getMaterialDesignFont(), 0xff0000, size, size, 2); + scaled = mutable.scaled(size * 2, size * 2).scaled(size, size); + } + int yBound = bounds.getY(); + g.drawImage(mutable, bounds.getX(), yBound); + + g.setColor(0xff); + g.drawArc(bounds.getX() + size, yBound, size, size, 0, 360); + g.drawImage(mutableWithAlpha, bounds.getX() + size, yBound); + + g.drawImage(encoded, bounds.getX() + size * 2, yBound); + g.drawImage(fontImage, bounds.getX() + size * 3, yBound); + + yBound = bounds.getY() + size; + g.drawImage(rgbImage, bounds.getX(), yBound); + g.drawImage(fromRgba, bounds.getX() + size, yBound); + g.drawImage(fromBytes, bounds.getX() + size * 2, yBound); + g.drawImage(scaled, bounds.getX() + size * 3, yBound); + + int smallSize = size / 2; + yBound = bounds.getY() + size * 2; + g.drawImage(mutable, bounds.getX(), yBound, smallSize, smallSize); + + g.drawArc(bounds.getX() + smallSize, yBound, smallSize, smallSize, 0, 360); + g.drawImage(mutableWithAlpha, bounds.getX() + smallSize, yBound, smallSize, smallSize); + + g.drawImage(encoded, bounds.getX() + smallSize * 2, yBound, smallSize, smallSize); + g.drawImage(rgbImage, bounds.getX() + smallSize * 3, yBound, smallSize, smallSize); + g.drawImage(fromRgba, bounds.getX() + smallSize * 4, yBound, smallSize, smallSize); + g.drawImage(fromBytes, bounds.getX() + smallSize * 5, yBound, smallSize, smallSize); + g.drawImage(fontImage, bounds.getX() + smallSize * 6, yBound, smallSize, smallSize); + g.drawImage(scaled, bounds.getX() + smallSize * 7, yBound, smallSize, smallSize); + yBound += smallSize; + + int larger = bounds.getWidth() / 2; + g.drawImage(mutable, bounds.getX(), yBound, larger, larger); + + g.drawArc(bounds.getX() + larger, yBound, larger, larger, 0, 360); + g.drawImage(mutableWithAlpha, bounds.getX() + larger, yBound, larger, larger); + + yBound += larger; + g.drawImage(encoded, bounds.getX(), yBound, larger, larger); + g.drawImage(rgbImage, bounds.getX() + larger, yBound, larger, larger); + + yBound += larger; + g.drawImage(fromRgba, bounds.getX(), yBound, larger, larger); + g.drawImage(fromBytes, bounds.getX() + larger, yBound, larger, larger); + + yBound += larger; + g.drawImage(fontImage, bounds.getX(), yBound, larger, larger); + g.drawImage(scaled, bounds.getX() + larger, yBound, larger, larger); + } + + @Override + protected String screenshotName() { + return "graphics-draw-image-rect"; + } +} diff --git a/scripts/hellocodenameone/common/src/main/java/com/codenameone/examples/hellocodenameone/tests/graphics/DrawLine.java b/scripts/hellocodenameone/common/src/main/java/com/codenameone/examples/hellocodenameone/tests/graphics/DrawLine.java new file mode 100644 index 0000000000..3517c2001b --- /dev/null +++ b/scripts/hellocodenameone/common/src/main/java/com/codenameone/examples/hellocodenameone/tests/graphics/DrawLine.java @@ -0,0 +1,43 @@ +package com.codenameone.examples.hellocodenameone.tests.graphics; + +import com.codename1.ui.Graphics; +import com.codename1.ui.geom.Rectangle; +import com.codenameone.examples.hellocodenameone.tests.AbstractGraphicsScreenshotTest; + +public class DrawLine extends AbstractGraphicsScreenshotTest { + @Override + protected void drawContent(Graphics g, Rectangle bounds) { + g.setColor(0xffffff); + // horizontal lines + for (int iter = 0 ; iter < bounds.getHeight() ; iter++) { + nextColor(g); + g.drawLine(bounds.getX(), bounds.getY() + iter, bounds.getX() + bounds.getWidth(), bounds.getY() + iter); + } + + g.setColor(0); + // vertical lines gapped by 5 + for (int iter = 0 ; iter < bounds.getWidth() ; iter += 5) { + nextColor(g); + g.drawLine(bounds.getX() + iter, bounds.getY(), bounds.getX() + iter, bounds.getY() + bounds.getHeight()); + } + + // diagonal lines down slope with alpha + g.setColor(0xfffff); + g.setAlpha(128); + for (int iter = 0 ; iter < bounds.getWidth() ; iter += 20) { + g.drawLine(bounds.getX(), bounds.getY(), bounds.getX() + iter, bounds.getY() + bounds.getHeight()); + } + + // diagonal lines up slope with alpha + g.setColor(0); + g.setAlpha(128); + for (int iter = 0 ; iter < bounds.getWidth() ; iter += 20) { + g.drawLine(bounds.getX() + bounds.getWidth(), bounds.getY() + bounds.getHeight(), bounds.getX() + iter, bounds.getY()); + } + } + + @Override + protected String screenshotName() { + return "graphics-draw-line"; + } +} diff --git a/scripts/hellocodenameone/common/src/main/java/com/codenameone/examples/hellocodenameone/tests/graphics/DrawRect.java b/scripts/hellocodenameone/common/src/main/java/com/codenameone/examples/hellocodenameone/tests/graphics/DrawRect.java new file mode 100644 index 0000000000..e0b5547bc1 --- /dev/null +++ b/scripts/hellocodenameone/common/src/main/java/com/codenameone/examples/hellocodenameone/tests/graphics/DrawRect.java @@ -0,0 +1,28 @@ +package com.codenameone.examples.hellocodenameone.tests.graphics; + +import com.codename1.ui.Graphics; +import com.codename1.ui.geom.Rectangle; +import com.codenameone.examples.hellocodenameone.tests.AbstractGraphicsScreenshotTest; + +public class DrawRect extends AbstractGraphicsScreenshotTest { + @Override + protected void drawContent(Graphics g, Rectangle bounds) { + g.setColor(0xffffff); + for (int iter = 0 ; iter < bounds.getWidth() / 2 ; iter++) { + nextColor(g); + g.drawRect(bounds.getX() + iter, bounds.getY() + iter, bounds.getX() + bounds.getWidth() - iter, bounds.getY() + bounds.getHeight() + iter); + } + + g.setColor(0); + g.setAlpha(80); + for (int iter = 0 ; iter < bounds.getWidth() / 2 ; iter += 20) { + nextColor(g); + g.drawRect(bounds.getX() + iter, bounds.getY() + iter, bounds.getX() + bounds.getWidth() - iter, bounds.getY() + bounds.getHeight() + iter, 4); + } + } + + @Override + protected String screenshotName() { + return "graphics-draw-rect"; + } +} diff --git a/scripts/hellocodenameone/common/src/main/java/com/codenameone/examples/hellocodenameone/tests/graphics/DrawRoundRect.java b/scripts/hellocodenameone/common/src/main/java/com/codenameone/examples/hellocodenameone/tests/graphics/DrawRoundRect.java new file mode 100644 index 0000000000..53c0ff5d6a --- /dev/null +++ b/scripts/hellocodenameone/common/src/main/java/com/codenameone/examples/hellocodenameone/tests/graphics/DrawRoundRect.java @@ -0,0 +1,21 @@ +package com.codenameone.examples.hellocodenameone.tests.graphics; + +import com.codename1.ui.Graphics; +import com.codename1.ui.geom.Rectangle; +import com.codenameone.examples.hellocodenameone.tests.AbstractGraphicsScreenshotTest; + +public class DrawRoundRect extends AbstractGraphicsScreenshotTest { + @Override + protected void drawContent(Graphics g, Rectangle bounds) { + g.setColor(0xffffff); + for (int iter = 0 ; iter < bounds.getWidth() / 2 ; iter++) { + nextColor(g); + g.drawRoundRect(bounds.getX() + iter, bounds.getY() + iter, bounds.getX() + bounds.getWidth() - iter, bounds.getY() + bounds.getHeight() + iter, iter % 20, iter % 20); + } + } + + @Override + protected String screenshotName() { + return "graphics-draw-round-rect"; + } +} diff --git a/scripts/hellocodenameone/common/src/main/java/com/codenameone/examples/hellocodenameone/tests/graphics/DrawString.java b/scripts/hellocodenameone/common/src/main/java/com/codenameone/examples/hellocodenameone/tests/graphics/DrawString.java new file mode 100644 index 0000000000..1829b98c1d --- /dev/null +++ b/scripts/hellocodenameone/common/src/main/java/com/codenameone/examples/hellocodenameone/tests/graphics/DrawString.java @@ -0,0 +1,37 @@ +package com.codenameone.examples.hellocodenameone.tests.graphics; + +import com.codename1.ui.Font; +import com.codename1.ui.Graphics; +import com.codename1.ui.geom.Rectangle; +import com.codenameone.examples.hellocodenameone.tests.AbstractGraphicsScreenshotTest; + +public class DrawString extends AbstractGraphicsScreenshotTest { + @Override + protected void drawContent(Graphics g, Rectangle bounds) { + g.setColor(0); + g.fillRect(bounds.getX(), bounds.getY(), bounds.getWidth(), bounds.getHeight()); + g.setColor(0xffffff); + int y = bounds.getY(); + g.drawString("Default Font", bounds.getX(), y); + y += g.getFont().getHeight(); + g.setFont(Font.createSystemFont(Font.FACE_MONOSPACE, Font.STYLE_BOLD, Font.SIZE_SMALL)); + g.drawString("Small Bold Monospace", bounds.getX(), y); + y += g.getFont().getHeight(); + String[] ttfFonts = {"native:MainThin", "native:MainLight", "native:MainRegular", + "native:MainBold", "native:MainBlack", "native:ItalicThin", "native:ItalicLight", + "native:ItalicRegular", "native:ItalicBold", "native:ItalicBlack"}; + for(String name : ttfFonts) { + g.setFont(Font.createTrueTypeFont(name, 4)); + g.drawString(name, bounds.getX(), y); + y += g.getFont().getHeight(); + } + + g.setColor(0xff0000); + g.drawStringBaseline("Baseline and עברית", bounds.getX(), bounds.getY() + bounds.getHeight()); + } + + @Override + protected String screenshotName() { + return "graphics-draw-string"; + } +} diff --git a/scripts/hellocodenameone/common/src/main/java/com/codenameone/examples/hellocodenameone/tests/graphics/DrawStringDecorated.java b/scripts/hellocodenameone/common/src/main/java/com/codenameone/examples/hellocodenameone/tests/graphics/DrawStringDecorated.java new file mode 100644 index 0000000000..85ee56be9f --- /dev/null +++ b/scripts/hellocodenameone/common/src/main/java/com/codenameone/examples/hellocodenameone/tests/graphics/DrawStringDecorated.java @@ -0,0 +1,35 @@ +package com.codenameone.examples.hellocodenameone.tests.graphics; + +import com.codename1.ui.Font; +import com.codename1.ui.Graphics; +import com.codename1.ui.geom.Rectangle; +import com.codename1.ui.plaf.Style; +import com.codenameone.examples.hellocodenameone.tests.AbstractGraphicsScreenshotTest; + +public class DrawStringDecorated extends AbstractGraphicsScreenshotTest { + @Override + protected void drawContent(Graphics g, Rectangle bounds) { + g.setColor(0xffffff); + g.fillRect(bounds.getX(), bounds.getY(), bounds.getWidth(), bounds.getHeight()); + g.setColor(0); + int y = bounds.getY(); + g.drawString("No Decoration", bounds.getX(), y, Style.TEXT_DECORATION_NONE); + y += g.getFont().getHeight(); + g.drawString("3D Decoration", bounds.getX(), y, Style.TEXT_DECORATION_3D); + y += g.getFont().getHeight(); + g.drawString("3D Lowered Decoration", bounds.getX(), y, Style.TEXT_DECORATION_3D_LOWERED); + y += g.getFont().getHeight(); + g.drawString("Overline Decoration", bounds.getX(), y, Style.TEXT_DECORATION_OVERLINE); + y += g.getFont().getHeight(); + g.drawString("Strikethru Decoration", bounds.getX(), y, Style.TEXT_DECORATION_STRIKETHRU); + y += g.getFont().getHeight(); + g.drawString("3D Shadow North Decoration", bounds.getX(), y, Style.TEXT_DECORATION_3D_SHADOW_NORTH); + y += g.getFont().getHeight(); + g.drawString("Underline Decoration", bounds.getX(), y, Style.TEXT_DECORATION_UNDERLINE); + } + + @Override + protected String screenshotName() { + return "graphics-draw-string-decorated"; + } +} diff --git a/scripts/hellocodenameone/common/src/main/java/com/codenameone/examples/hellocodenameone/tests/graphics/FillArc.java b/scripts/hellocodenameone/common/src/main/java/com/codenameone/examples/hellocodenameone/tests/graphics/FillArc.java new file mode 100644 index 0000000000..829f372812 --- /dev/null +++ b/scripts/hellocodenameone/common/src/main/java/com/codenameone/examples/hellocodenameone/tests/graphics/FillArc.java @@ -0,0 +1,21 @@ +package com.codenameone.examples.hellocodenameone.tests.graphics; + +import com.codename1.ui.Graphics; +import com.codename1.ui.geom.Rectangle; +import com.codenameone.examples.hellocodenameone.tests.AbstractGraphicsScreenshotTest; + +public class FillArc extends AbstractGraphicsScreenshotTest { + @Override + protected void drawContent(Graphics g, Rectangle bounds) { + g.setColor(0xffffff); + for (int iter = 0 ; iter < bounds.getWidth() / 2 ; iter++) { + nextColor(g); + g.fillArc(bounds.getX() + iter, bounds.getY() + iter, bounds.getX() + bounds.getWidth() - iter, bounds.getY() + bounds.getHeight() + iter, iter, 180); + } + } + + @Override + protected String screenshotName() { + return "graphics-fill-arc"; + } +} diff --git a/scripts/hellocodenameone/common/src/main/java/com/codenameone/examples/hellocodenameone/tests/graphics/FillPolygon.java b/scripts/hellocodenameone/common/src/main/java/com/codenameone/examples/hellocodenameone/tests/graphics/FillPolygon.java new file mode 100644 index 0000000000..1534c2c735 --- /dev/null +++ b/scripts/hellocodenameone/common/src/main/java/com/codenameone/examples/hellocodenameone/tests/graphics/FillPolygon.java @@ -0,0 +1,36 @@ +package com.codenameone.examples.hellocodenameone.tests.graphics; + +import com.codename1.ui.Graphics; +import com.codename1.ui.geom.Rectangle; +import com.codenameone.examples.hellocodenameone.tests.AbstractGraphicsScreenshotTest; + +public class FillPolygon extends AbstractGraphicsScreenshotTest { + + @Override + protected void drawContent(Graphics g, Rectangle bounds) { + int[] xPoints = new int[360]; + int[] yPoints = new int[360]; + int centerX = bounds.getX() + bounds.getWidth() / 2; + int centerY = bounds.getY() + bounds.getHeight() / 2; + int radius = bounds.getWidth() / 3; + for(int i = 0; i < 360 ; i++) { + double angle = 2 * Math.PI * i / 360.0; + xPoints[i] = centerX + (int) Math.round(radius * Math.cos(angle)); + yPoints[i] = centerY + (int) Math.round(radius * Math.sin(angle)); + } + + g.setColor(0xffffff); + g.fillRect(bounds.getX(), bounds.getY(), bounds.getWidth(), bounds.getHeight()); + + g.setColor(0); + g.fillPolygon(xPoints, yPoints, 360); + + g.setColor(0xff); + g.drawPolygon(xPoints, yPoints, 360); + } + + @Override + protected String screenshotName() { + return "graphics-fill-polygon"; + } +} diff --git a/scripts/hellocodenameone/common/src/main/java/com/codenameone/examples/hellocodenameone/tests/graphics/FillRect.java b/scripts/hellocodenameone/common/src/main/java/com/codenameone/examples/hellocodenameone/tests/graphics/FillRect.java new file mode 100644 index 0000000000..89dcdf294b --- /dev/null +++ b/scripts/hellocodenameone/common/src/main/java/com/codenameone/examples/hellocodenameone/tests/graphics/FillRect.java @@ -0,0 +1,21 @@ +package com.codenameone.examples.hellocodenameone.tests.graphics; + +import com.codename1.ui.Graphics; +import com.codename1.ui.geom.Rectangle; +import com.codenameone.examples.hellocodenameone.tests.AbstractGraphicsScreenshotTest; + +public class FillRect extends AbstractGraphicsScreenshotTest { + @Override + protected void drawContent(Graphics g, Rectangle bounds) { + g.setColor(0xffffff); + for (int iter = 0 ; iter < bounds.getWidth() / 2 ; iter++) { + nextColor(g); + g.fillRect(bounds.getX() + iter, bounds.getY() + iter, bounds.getX() + bounds.getWidth() - iter, bounds.getY() + bounds.getHeight() + iter); + } + } + + @Override + protected String screenshotName() { + return "graphics-fill-rect"; + } +} diff --git a/scripts/hellocodenameone/common/src/main/java/com/codenameone/examples/hellocodenameone/tests/graphics/FillRoundRect.java b/scripts/hellocodenameone/common/src/main/java/com/codenameone/examples/hellocodenameone/tests/graphics/FillRoundRect.java new file mode 100644 index 0000000000..e1746c592b --- /dev/null +++ b/scripts/hellocodenameone/common/src/main/java/com/codenameone/examples/hellocodenameone/tests/graphics/FillRoundRect.java @@ -0,0 +1,21 @@ +package com.codenameone.examples.hellocodenameone.tests.graphics; + +import com.codename1.ui.Graphics; +import com.codename1.ui.geom.Rectangle; +import com.codenameone.examples.hellocodenameone.tests.AbstractGraphicsScreenshotTest; + +public class FillRoundRect extends AbstractGraphicsScreenshotTest { + @Override + protected void drawContent(Graphics g, Rectangle bounds) { + g.setColor(0xffffff); + for (int iter = 0 ; iter < bounds.getWidth() / 2 ; iter++) { + nextColor(g); + g.fillRoundRect(bounds.getX() + iter, bounds.getY() + iter, bounds.getX() + bounds.getWidth() - iter, bounds.getY() + bounds.getHeight() + iter, iter % 20, iter % 20); + } + } + + @Override + protected String screenshotName() { + return "graphics-fill-round-rect"; + } +} diff --git a/scripts/hellocodenameone/common/src/main/java/com/codenameone/examples/hellocodenameone/tests/graphics/Scale.java b/scripts/hellocodenameone/common/src/main/java/com/codenameone/examples/hellocodenameone/tests/graphics/Scale.java new file mode 100644 index 0000000000..907da5dc9a --- /dev/null +++ b/scripts/hellocodenameone/common/src/main/java/com/codenameone/examples/hellocodenameone/tests/graphics/Scale.java @@ -0,0 +1,34 @@ +package com.codenameone.examples.hellocodenameone.tests.graphics; + +import com.codename1.ui.Graphics; +import com.codename1.ui.geom.Rectangle; +import com.codenameone.examples.hellocodenameone.tests.AbstractGraphicsScreenshotTest; + +public class Scale extends AbstractGraphicsScreenshotTest { + + @Override + protected void drawContent(Graphics g, Rectangle bounds) { + if(!g.isAffineSupported()) { + g.drawString("Affine unsupported", 0, 0); + return; + } + + float xScale = 0.01f * ((float)bounds.getHeight()); + float yScale = 0.01f * ((float)bounds.getWidth()); + g.scale(xScale, yScale); + int translateX = (int)(bounds.getX() / xScale); + int translateY = (int)(bounds.getY() / yScale); + g.translate(translateX, translateY); + g.fillLinearGradient(0xff0000, 0xff, 0, 0, 100, 100, true); + g.scale(-1, 1); + g.fillLinearGradient(0xff0000, 0xff, 0, 100, 100, 100, true); + + g.translate(-translateX, -translateY); + g.resetAffine(); + } + + @Override + protected String screenshotName() { + return "graphics-scale"; + } +}