Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixes #10 Basic framework for iOS binding
- Loading branch information
Showing
19 changed files
with
305 additions
and
63 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletions
4
uilayer-android/src/net/avh4/framework/uilayer/DemoGameActivity.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 40 additions & 0 deletions
40
uilayer-ios-xmlvm/src/main/java/net/avh4/demo/uilayer/DemoGame.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package net.avh4.demo.uilayer; | ||
|
||
import net.avh4.framework.uilayer.UI; | ||
import net.avh4.framework.uilayer.UILayer; | ||
import net.avh4.framework.uilayer.scene.Scene; | ||
|
||
public class DemoGame implements UI { | ||
|
||
public static void main(final String[] args) { | ||
final DemoGame game = new DemoGame(); | ||
UILayer.run(game); | ||
} | ||
|
||
private Scene s; | ||
|
||
public DemoGame() { | ||
s = UILayer.newScene("UILayer Demo Game"); | ||
s.addImage(0, 0, 640, 960, "background.jpg"); | ||
click(100, 100); | ||
} | ||
|
||
@Override | ||
public Scene getScene() { | ||
return s; | ||
} | ||
|
||
@Override | ||
public void click(final int x, final int y) { | ||
s.addPlaceholder("Box", x, y, 50, 50); | ||
} | ||
|
||
@Override | ||
public void key(final int keyCode) { | ||
// if (keyCode == KeyEvent.VK_SPACE) { | ||
s = UILayer.newScene("UILayer Demo Game"); | ||
s.addImage(0, 0, 640, 960, "background.jpg"); | ||
// } | ||
} | ||
|
||
} |
32 changes: 32 additions & 0 deletions
32
uilayer-ios-xmlvm/src/main/java/net/avh4/framework/uilayer/UILayer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package net.avh4.framework.uilayer; | ||
|
||
import net.avh4.framework.uilayer.ios.IOSUILayerService; | ||
import net.avh4.framework.uilayer.scene.Scene; | ||
|
||
/** | ||
* This class replaces the version in uilayer-core when compiling for xmlvm | ||
* because the uilayer-core version uses ClassLoader, which is not implemented | ||
* for iOS with xmlvm. | ||
*/ | ||
public class UILayer { | ||
|
||
public static final UILayerService service = loadService(); | ||
|
||
public static void run(final UI game) { | ||
UILayer.run(game, game, game); | ||
} | ||
|
||
private static UILayerService loadService() { | ||
return new IOSUILayerService(); | ||
} | ||
|
||
public static Scene newScene(final String title) { | ||
return service.newScene(title); | ||
} | ||
|
||
public static void run(final SceneCreator game, | ||
final ClickReceiver receiver, final KeyReceiver keyReceiver) { | ||
service.run(game, receiver, keyReceiver); | ||
} | ||
|
||
} |
36 changes: 36 additions & 0 deletions
36
uilayer-ios-xmlvm/src/main/java/net/avh4/framework/uilayer/ios/IOSPlaceholder.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package net.avh4.framework.uilayer.ios; | ||
|
||
import net.avh4.framework.uilayer.scene.SceneObject; | ||
|
||
import org.xmlvm.iphone.CGContext; | ||
import org.xmlvm.iphone.CGRect; | ||
import org.xmlvm.iphone.UIGraphics; | ||
|
||
public class IOSPlaceholder extends SceneObject<CGRect> { | ||
|
||
private static final int MARGIN = 5; | ||
private final String name; | ||
private final float[] color = new float[] { .2f, .2f, .2f, 1 }; | ||
private final float[] textColor = new float[] { 1, 1, 1, 1 }; | ||
|
||
public IOSPlaceholder(final String name, final int x, final int y, | ||
final int width, final int height) { | ||
super(x, y, width, height); | ||
this.name = name; | ||
} | ||
|
||
@Override | ||
public void draw(final CGRect rect) { | ||
final CGContext g = UIGraphics.getCurrentContext(); | ||
g.setFillColor(color); | ||
g.fillRect(new CGRect(x, y, width, height)); | ||
g.setStrokeColor(new float[] { 0, 0, 0, 1 }); | ||
g.strokeRect(new CGRect(x, y, width, height)); | ||
|
||
g.selectFont("Helvetica", 10); | ||
g.setTextDrawingMode(CGContext.kCGTextFill); | ||
g.setFillColor(textColor); | ||
g.showTextAtPoint(x + MARGIN, y + height - MARGIN, name); | ||
} | ||
|
||
} |
68 changes: 68 additions & 0 deletions
68
uilayer-ios-xmlvm/src/main/java/net/avh4/framework/uilayer/ios/IOSScene.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
package net.avh4.framework.uilayer.ios; | ||
|
||
import java.util.ArrayList; | ||
import java.util.Iterator; | ||
|
||
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>> { | ||
|
||
private final ArrayList<SceneObject<CGRect>> children = new ArrayList<SceneObject<CGRect>>(); | ||
private final String title; | ||
|
||
public IOSScene(final String title) { | ||
this.title = title; | ||
} | ||
|
||
@Override | ||
public Iterator<SceneObject<CGRect>> iterator() { | ||
return children.iterator(); | ||
} | ||
|
||
@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); | ||
} | ||
|
||
@Override | ||
public void addPlaceholder(final String name, final int x, final int y, | ||
final int width, final int height) { | ||
children.add(new IOSPlaceholder(name, x, y, width, height)); | ||
} | ||
|
||
@Override | ||
public SceneImage addImage(final int x, final int y, final int width, | ||
final int height, final String imageName, final int clipX, | ||
final int clipY, final int clipWidth, final int clipHeight) { | ||
addPlaceholder(imageName, x, y, width, height); | ||
return null; | ||
} | ||
|
||
@Override | ||
public SceneImage addImage(final int x, final int y, final int width, | ||
final int height, final String imageName) { | ||
addPlaceholder(imageName, x, y, width, height); | ||
return null; | ||
} | ||
|
||
} |
Oops, something went wrong.