Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Fixes #16 Scenes can specify their size

  • Loading branch information...
commit 80668224ed87240c5da866c717caf5ff5b27c9a3 1 parent 932f1c2
@avh4 authored
View
36 uilayer-core/src/main/java/net/avh4/framework/uilayer/SceneBase.java
@@ -0,0 +1,36 @@
+package net.avh4.framework.uilayer;
+
+import net.avh4.framework.uilayer.scene.Scene;
+
+public abstract class SceneBase implements Scene {
+
+ protected final String title;
+ private int width = 800;
+ private int height = 600;
+
+ public SceneBase(final String title) {
+ this.title = title;
+ }
+
+ @Override
+ public int getWidth() {
+ return width;
+ }
+
+ @Override
+ public int getHeight() {
+ return height;
+ }
+
+ @Override
+ public String getTitle() {
+ return title;
+ }
+
+ @Override
+ public void setSize(final int width, final int height) {
+ this.width = width;
+ this.height = height;
+ }
+
+}
View
2  uilayer-core/src/main/java/net/avh4/framework/uilayer/scene/Scene.java
@@ -21,4 +21,6 @@ SceneImage addImage(final int x, final int y, final int width,
SceneImage addImage(final int x, final int y, final int width,
final int height, final String imageName);
+ void setSize(int width, int height);
+
}
View
22 uilayer-ios-xmlvm/src/main/java/net/avh4/framework/uilayer/ios/IOSScene.java
@@ -3,19 +3,20 @@
import java.util.ArrayList;
import java.util.Iterator;
+import net.avh4.framework.uilayer.SceneBase;
import net.avh4.framework.uilayer.scene.Scene;
import net.avh4.framework.uilayer.scene.SceneImage;
import net.avh4.framework.uilayer.scene.SceneObject;
import org.xmlvm.iphone.CGRect;
-public class IOSScene implements Scene, Iterable<SceneObject<CGRect>> {
+public class IOSScene extends SceneBase implements Scene,
+ Iterable<SceneObject<CGRect>> {
private final ArrayList<SceneObject<CGRect>> children = new ArrayList<SceneObject<CGRect>>();
- private final String title;
public IOSScene(final String title) {
- this.title = title;
+ super(title);
}
@Override
@@ -24,21 +25,6 @@ public IOSScene(final String title) {
}
@Override
- public String getTitle() {
- return title;
- }
-
- @Override
- public int getWidth() {
- return 640;
- }
-
- @Override
- public int getHeight() {
- return 960;
- }
-
- @Override
public void addText(final String text, final int x, final int y,
final int width, final String customFontResource, final int fontSize) {
addPlaceholder(text, x, y, width, 10);
View
4 uilayer-swing/pom.xml
@@ -8,7 +8,7 @@
<groupId>net.avh4.framework</groupId>
<artifactId>uilayer-swing</artifactId>
- <version>0.0.3</version>
+ <version>0.0.4-SNAPSHOT</version>
<packaging>jar</packaging>
<name>uilayer-swing</name>
@@ -52,7 +52,7 @@
<dependency>
<groupId>net.avh4.framework</groupId>
<artifactId>uilayer-core</artifactId>
- <version>0.0.3</version>
+ <version>0.0.4-SNAPSHOT</version>
</dependency>
</dependencies>
</project>
View
2  uilayer-swing/src/main/java/net/avh4/framework/uilayer/swing/SwingUILayerService.java
@@ -14,7 +14,7 @@
public class SwingUILayerService implements UILayerService {
@Override
- public void main(final SceneCreator game, final ClickReceiver receiver,
+ public void run(final SceneCreator game, final ClickReceiver receiver,
final KeyReceiver keyReceiver) {
final Scene scene = game.getScene();
View
22 uilayer-swing/src/main/java/net/avh4/framework/uilayer/swing/scene/SwingScene.java
@@ -5,17 +5,18 @@
import java.util.ArrayList;
import java.util.Iterator;
+import net.avh4.framework.uilayer.SceneBase;
import net.avh4.framework.uilayer.scene.Scene;
import net.avh4.framework.uilayer.scene.SceneImage;
import net.avh4.framework.uilayer.scene.SceneObject;
-public class SwingScene implements Iterable<SceneObject<Graphics>>, Scene {
+public class SwingScene extends SceneBase implements
+ Iterable<SceneObject<Graphics>>, Scene {
private final ArrayList<SceneObject<Graphics>> children = new ArrayList<SceneObject<Graphics>>();
- private final String title;
public SwingScene(final String title) {
- this.title = title;
+ super(title);
}
public SwingScene() {
@@ -23,16 +24,6 @@ public SwingScene() {
}
@Override
- public int getWidth() {
- return 800;
- }
-
- @Override
- public int getHeight() {
- return 600;
- }
-
- @Override
public SceneImage addImage(final int x, final int y, final int width,
final int height, final String imageName) {
final SwingImage image = new SwingImage(x, y, width, height, imageName);
@@ -71,11 +62,6 @@ public SceneImage addImage(final int x, final int y, final int width,
}
@Override
- public String getTitle() {
- return title;
- }
-
- @Override
public void addPlaceholder(final String name, final int x, final int y,
final int width, final int height) {
children.add(new SwingPlaceholder(name, x, y, width, height));
View
49 uilayer-swing/src/test/java/net/avh4/framework/uilayer/swing/scene/SceneTest.java
@@ -0,0 +1,49 @@
+package net.avh4.framework.uilayer.swing.scene;
+
+import static net.avh4.util.imagecomparison.Matchers.isApproved;
+import static org.junit.Assert.assertThat;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.reset;
+import static org.mockito.Mockito.stub;
+import net.avh4.framework.uilayer.SceneCreator;
+import net.avh4.framework.uilayer.scene.Scene;
+
+import org.junit.Before;
+import org.junit.Test;
+
+public class SceneTest {
+
+ private SceneCreator mockCreator;
+ private SwingSceneRenderer subject;
+ private Scene scene;
+
+ @Before
+ public void setUp() {
+ scene = new SwingScene();
+ mockCreator = mock(SceneCreator.class);
+ stub(mockCreator.getScene()).toReturn(scene);
+ subject = new SwingSceneRenderer(mockCreator);
+ }
+
+ @Test
+ public void testRenderEmptyScene() throws Exception {
+ assertThat(subject, isApproved());
+ }
+
+ /**
+ * If the SceneCreator returns null, we must render something and not throw
+ * an exception.
+ */
+ @Test
+ public void testRenderNullScene() throws Exception {
+ reset(mockCreator);
+ stub(mockCreator.getScene()).toReturn(null);
+ assertThat(subject, isApproved());
+ }
+
+ @Test
+ public void testRenderSizedScene() throws Exception {
+ scene.setSize(640, 960);
+ assertThat(subject, isApproved());
+ }
+}
View
17 ...er-swing/src/test/java/net/avh4/framework/uilayer/swing/scene/SwingSceneRendererTest.java
@@ -3,7 +3,6 @@
import static net.avh4.util.imagecomparison.Matchers.isApproved;
import static org.junit.Assert.assertThat;
import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.reset;
import static org.mockito.Mockito.stub;
import java.awt.Color;
@@ -32,11 +31,6 @@ public void setUp() {
}
@Test
- public void testRenderEmptyScene() throws Exception {
- assertThat(subject, isApproved());
- }
-
- @Test
public void testRenderResourceImage() throws Exception {
scene.addImage(100, 100, 50, 50, "tile1.png");
assertThat(subject, isApproved());
@@ -86,17 +80,6 @@ public void testRenderReclippedClippedImage() throws Exception {
assertThat(subject, isApproved());
}
- /**
- * If the SceneCreator returns null, we must render something and not throw
- * an exception.
- */
- @Test
- public void testRenderNullScene() throws Exception {
- reset(mockCreator);
- stub(mockCreator.getScene()).toReturn(null);
- assertThat(subject, isApproved());
- }
-
@Test
public void testRenderPlaceholders() throws Exception {
scene.addPlaceholder("Background", 0, 0, 800, 600);
View
0  ...ceneRendererTest.testRenderEmptyScene.png → .../scene/SceneTest.testRenderEmptyScene.png
File renamed without changes
View
0  ...SceneRendererTest.testRenderNullScene.png → ...g/scene/SceneTest.testRenderNullScene.png
File renamed without changes
View
BIN  .../test/resources/net/avh4/framework/uilayer/swing/scene/SceneTest.testRenderSizedScene.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Please sign in to comment.
Something went wrong with that request. Please try again.