Skip to content

Commit ea30219

Browse files
committed
Initial refactor of the graphics pipeline
1 parent 7fa99f9 commit ea30219

18 files changed

+378
-685
lines changed

scripts/hellocodenameone/common/src/main/css/theme.css

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,3 +52,12 @@ SideCommand {
5252
font-size: 4mm;
5353
border-bottom: 2px solid #cccccc;
5454
}
55+
56+
GraphicsForm {
57+
background: #cccccc;
58+
}
59+
60+
GraphicsComponent {
61+
padding: 0px;
62+
margin: 1mm;
63+
}

scripts/hellocodenameone/common/src/main/java/com/codenameone/examples/hellocodenameone/tests/AbstractGraphicsScreenshotTest.java

Lines changed: 99 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,113 @@
11
package com.codenameone.examples.hellocodenameone.tests;
22

33
import com.codename1.ui.Component;
4+
import com.codename1.ui.Font;
45
import com.codename1.ui.Form;
6+
import com.codename1.ui.Graphics;
7+
import com.codename1.ui.Image;
8+
import com.codename1.ui.geom.Rectangle;
59
import com.codename1.ui.layouts.BorderLayout;
10+
import com.codename1.ui.layouts.GridLayout;
611

7-
abstract class AbstractGraphicsScreenshotTest extends BaseTest {
8-
protected abstract Component createContent();
12+
public abstract class AbstractGraphicsScreenshotTest extends BaseTest {
13+
private final int[] colorSet = {0xff0000, 0xff00, 0xff, 0xffffff};
14+
private int currentColor = -1;
15+
16+
protected void nextColor(Graphics g) {
17+
if (currentColor == -1) {
18+
currentColor = 0;
19+
g.setColor(colorSet[0]);
20+
}
21+
g.darkerColor(1);
22+
if (g.getColor() == 0) {
23+
currentColor++;
24+
if (currentColor == colorSet.length) {
25+
currentColor = 0;
26+
}
27+
g.setColor(colorSet[currentColor]);
28+
}
29+
}
30+
31+
protected abstract void drawContent(Graphics g, Rectangle bounds);
932

1033
protected abstract String screenshotName();
1134

35+
static abstract class CleanPaintComponent extends Component {
36+
CleanPaintComponent() {
37+
setUIID("GraphicsComponent");
38+
}
39+
40+
@Override
41+
public void paint(Graphics g) {
42+
int alpha = g.getAlpha();
43+
int color = g.getColor();
44+
Font font = g.getFont();
45+
g.pushClip();
46+
cleanPaint(g);
47+
g.popClip();
48+
g.setFont(font);
49+
g.setColor(color);
50+
g.setAlpha(alpha);
51+
}
52+
53+
protected abstract void cleanPaint(Graphics g);
54+
}
55+
1256
@Override
1357
public boolean runTest() {
14-
Form form = createForm("Graphics", new BorderLayout(), screenshotName());
15-
form.add(BorderLayout.CENTER, createContent());
58+
Form form = createForm(screenshotName(), new GridLayout(2, 2), screenshotName());
59+
form.setUIID("GraphicsForm");
60+
form.add(new CleanPaintComponent() {
61+
@Override
62+
public void cleanPaint(Graphics g) {
63+
currentColor = -1;
64+
g.setAntiAliased(false);
65+
g.setAntiAliasedText(false);
66+
g.fillRect(getX(), getY(), getWidth(), getHeight());
67+
drawContent(g, getBounds());
68+
}
69+
});
70+
form.add(new CleanPaintComponent() {
71+
@Override
72+
public void cleanPaint(Graphics g) {
73+
currentColor = -1;
74+
g.setAntiAliased(true);
75+
g.setAntiAliasedText(true);
76+
g.fillRect(getX(), getY(), getWidth(), getHeight());
77+
drawContent(g, getBounds());
78+
}
79+
});
80+
form.add(new CleanPaintComponent() {
81+
private Image img;
82+
@Override
83+
public void cleanPaint(Graphics g) {
84+
if (img == null || img.getWidth() != getWidth() || img.getHeight() != getHeight()) {
85+
currentColor = -1;
86+
img = Image.createImage(getWidth(), getHeight());
87+
Graphics imgGraphics = img.getGraphics();
88+
imgGraphics.setAntiAliased(false);
89+
imgGraphics.setAntiAliasedText(false);
90+
drawContent(imgGraphics, new Rectangle(0, 0, img.getWidth(), img.getHeight()));
91+
}
92+
g.drawImage(img, getX(), getY());
93+
}
94+
});
95+
form.add(new CleanPaintComponent() {
96+
private Image img;
97+
@Override
98+
public void cleanPaint(Graphics g) {
99+
if (img == null || img.getWidth() != getWidth() || img.getHeight() != getHeight()) {
100+
currentColor = -1;
101+
img = Image.createImage(getWidth(), getHeight());
102+
Graphics imgGraphics = img.getGraphics();
103+
imgGraphics.setAntiAliased(true);
104+
imgGraphics.setAntiAliasedText(true);
105+
drawContent(imgGraphics, new Rectangle(0, 0, img.getWidth(), img.getHeight()));
106+
}
107+
g.drawImage(img, getX(), getY());
108+
}
109+
});
110+
16111
form.show();
17112
return true;
18113
}

scripts/hellocodenameone/common/src/main/java/com/codenameone/examples/hellocodenameone/tests/BrowserComponentScreenshotTest.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
import com.codename1.ui.BrowserComponent;
44
import com.codename1.ui.Form;
5-
import com.codename1.ui.CN;
65
import com.codename1.ui.layouts.BorderLayout;
76
import com.codename1.ui.util.UITimer;
87

scripts/hellocodenameone/common/src/main/java/com/codenameone/examples/hellocodenameone/tests/Cn1ssDeviceRunner.java

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,30 @@
1010
import com.codename1.ui.Form;
1111
import com.codename1.testing.AbstractTest;
1212
import com.codename1.util.StringUtil;
13+
import com.codenameone.examples.hellocodenameone.tests.graphics.DrawArc;
14+
import com.codenameone.examples.hellocodenameone.tests.graphics.DrawLine;
15+
import com.codenameone.examples.hellocodenameone.tests.graphics.DrawRect;
16+
import com.codenameone.examples.hellocodenameone.tests.graphics.DrawRoundRect;
17+
import com.codenameone.examples.hellocodenameone.tests.graphics.DrawString;
18+
import com.codenameone.examples.hellocodenameone.tests.graphics.DrawStringDecorated;
19+
import com.codenameone.examples.hellocodenameone.tests.graphics.FillArc;
20+
import com.codenameone.examples.hellocodenameone.tests.graphics.FillRect;
21+
import com.codenameone.examples.hellocodenameone.tests.graphics.FillRoundRect;
1322

1423
import java.util.List;
1524

1625
public final class Cn1ssDeviceRunner extends DeviceRunner {
1726
private static final BaseTest[] TEST_CLASSES = new BaseTest[] {
1827
new MainScreenScreenshotTest(),
19-
new GraphicsPipelineScreenshotTest(),
20-
new GraphicsShapesAndGradientsScreenshotTest(),
21-
new GraphicsStateAndTextScreenshotTest(),
22-
new GraphicsTransformationsScreenshotTest(),
28+
new DrawLine(),
29+
new FillRect(),
30+
new DrawRect(),
31+
new FillRoundRect(),
32+
new DrawRoundRect(),
33+
new FillArc(),
34+
new DrawArc(),
35+
new DrawString(),
36+
new DrawStringDecorated(),
2337
new BrowserComponentScreenshotTest(),
2438
new MediaPlaybackScreenshotTest()
2539
};
@@ -62,6 +76,9 @@ public void runSuite() {
6276
}
6377
log("CN1SS:SUITE:FINISHED");
6478
TestReporting.getInstance().testExecutionFinished(getClass().getName());
79+
if (CN.isSimulator()) {
80+
Display.getInstance().exitApplication();
81+
}
6582
}
6683

6784
private static void log(String msg) {

scripts/hellocodenameone/common/src/main/java/com/codenameone/examples/hellocodenameone/tests/Cn1ssDeviceRunnerHelper.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package com.codenameone.examples.hellocodenameone.tests;
22

3+
import com.codename1.io.Storage;
34
import com.codename1.io.Util;
45
import com.codename1.io.Log;
56
import com.codename1.ui.Display;
@@ -61,6 +62,9 @@ static void emitCurrentFormScreenshot(String testName) {
6162
println("CN1SS:ERR:test=" + safeName + " message=PNG encoding unavailable");
6263
println("CN1SS:END:" + safeName);
6364
}
65+
if(Display.getInstance().isSimulator()) {
66+
io.save(screenshot, Storage.getInstance().createOutputStream(safeName + ".png"), ImageIO.FORMAT_PNG, 1);
67+
}
6468
ByteArrayOutputStream pngOut = new ByteArrayOutputStream(Math.max(1024, width * height / 2));
6569
io.save(screenshot, pngOut, ImageIO.FORMAT_PNG, 1f);
6670
byte[] pngBytes = pngOut.toByteArray();

scripts/hellocodenameone/common/src/main/java/com/codenameone/examples/hellocodenameone/tests/GraphicsPipelineScreenshotTest.java

Lines changed: 0 additions & 155 deletions
This file was deleted.

0 commit comments

Comments
 (0)