Skip to content

Commit

Permalink
Adds resolution independence support for iPad normal/retina
Browse files Browse the repository at this point in the history
  • Loading branch information
Alec McEachran committed Mar 26, 2013
1 parent d9e8fc1 commit 724b454
Show file tree
Hide file tree
Showing 15 changed files with 227 additions and 60 deletions.
99 changes: 99 additions & 0 deletions assets/helvetica-20-white.fnt
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
info face="Helvetica Neue" size=20 bold=0 italic=0 charset="" unicode=0 stretchH=100 smooth=1 aa=1 padding=0,0,0,0 spacing=0,0
common lineHeight=24 base=20 scaleW=256 scaleH=128 pages=1 packed=0
page id=0 file="helvetica-20-white.png"
chars count=95
char id=32 x=22 y=42 width=0 height=0 xoffset=-2 yoffset=20 xadvance=6 page=0 chnl=0
char id=33 x=194 y=76 width=6 height=18 xoffset=0 yoffset=4 xadvance=6 page=0 chnl=0
char id=34 x=244 y=38 width=8 height=10 xoffset=0 yoffset=4 xadvance=10 page=0 chnl=0
char id=35 x=162 y=38 width=12 height=16 xoffset=-1 yoffset=6 xadvance=12 page=0 chnl=0
char id=36 x=26 y=2 width=14 height=22 xoffset=-2 yoffset=2 xadvance=12 page=0 chnl=0
char id=37 x=2 y=22 width=20 height=18 xoffset=0 yoffset=4 xadvance=20 page=0 chnl=0
char id=38 x=78 y=42 width=16 height=18 xoffset=-1 yoffset=4 xadvance=14 page=0 chnl=0
char id=39 x=194 y=108 width=6 height=10 xoffset=0 yoffset=4 xadvance=6 page=0 chnl=0
char id=40 x=176 y=62 width=8 height=22 xoffset=0 yoffset=3 xadvance=6 page=0 chnl=0
char id=41 x=176 y=38 width=8 height=22 xoffset=-2 yoffset=3 xadvance=6 page=0 chnl=0
char id=42 x=224 y=38 width=10 height=10 xoffset=-1 yoffset=4 xadvance=9 page=0 chnl=0
char id=43 x=178 y=22 width=14 height=14 xoffset=-1 yoffset=8 xadvance=12 page=0 chnl=0
char id=44 x=194 y=96 width=6 height=10 xoffset=0 yoffset=15 xadvance=6 page=0 chnl=0
char id=45 x=202 y=56 width=10 height=6 xoffset=0 yoffset=11 xadvance=9 page=0 chnl=0
char id=46 x=224 y=56 width=6 height=6 xoffset=0 yoffset=16 xadvance=6 page=0 chnl=0
char id=47 x=162 y=56 width=10 height=18 xoffset=-2 yoffset=4 xadvance=8 page=0 chnl=0
char id=48 x=134 y=2 width=14 height=18 xoffset=-1 yoffset=4 xadvance=12 page=0 chnl=0
char id=49 x=198 y=38 width=10 height=16 xoffset=0 yoffset=6 xadvance=12 page=0 chnl=0
char id=50 x=118 y=102 width=14 height=18 xoffset=-1 yoffset=4 xadvance=12 page=0 chnl=0
char id=51 x=118 y=82 width=14 height=18 xoffset=-1 yoffset=4 xadvance=12 page=0 chnl=0
char id=52 x=166 y=2 width=14 height=16 xoffset=-1 yoffset=6 xadvance=12 page=0 chnl=0
char id=53 x=118 y=62 width=14 height=18 xoffset=-1 yoffset=4 xadvance=12 page=0 chnl=0
char id=54 x=118 y=42 width=14 height=18 xoffset=-1 yoffset=4 xadvance=12 page=0 chnl=0
char id=55 x=240 y=2 width=12 height=16 xoffset=-1 yoffset=6 xadvance=12 page=0 chnl=0
char id=56 x=118 y=22 width=14 height=18 xoffset=-1 yoffset=4 xadvance=12 page=0 chnl=0
char id=57 x=118 y=2 width=14 height=18 xoffset=-1 yoffset=4 xadvance=12 page=0 chnl=0
char id=58 x=236 y=38 width=6 height=14 xoffset=0 yoffset=8 xadvance=6 page=0 chnl=0
char id=59 x=176 y=108 width=6 height=16 xoffset=0 yoffset=9 xadvance=6 page=0 chnl=0
char id=60 x=162 y=22 width=14 height=14 xoffset=-1 yoffset=8 xadvance=12 page=0 chnl=0
char id=61 x=96 y=114 width=14 height=10 xoffset=-1 yoffset=10 xadvance=12 page=0 chnl=0
char id=62 x=146 y=102 width=14 height=14 xoffset=-1 yoffset=8 xadvance=12 page=0 chnl=0
char id=63 x=210 y=2 width=12 height=18 xoffset=-1 yoffset=4 xadvance=12 page=0 chnl=0
char id=64 x=2 y=102 width=18 height=18 xoffset=-1 yoffset=4 xadvance=16 page=0 chnl=0
char id=65 x=78 y=22 width=16 height=18 xoffset=-2 yoffset=4 xadvance=14 page=0 chnl=0
char id=66 x=96 y=94 width=14 height=18 xoffset=0 yoffset=4 xadvance=15 page=0 chnl=0
char id=67 x=78 y=2 width=16 height=18 xoffset=-1 yoffset=4 xadvance=15 page=0 chnl=0
char id=68 x=60 y=102 width=16 height=18 xoffset=0 yoffset=4 xadvance=15 page=0 chnl=0
char id=69 x=96 y=74 width=14 height=18 xoffset=0 yoffset=4 xadvance=13 page=0 chnl=0
char id=70 x=96 y=54 width=14 height=18 xoffset=0 yoffset=4 xadvance=12 page=0 chnl=0
char id=71 x=60 y=82 width=16 height=18 xoffset=-1 yoffset=4 xadvance=16 page=0 chnl=0
char id=72 x=60 y=62 width=16 height=18 xoffset=0 yoffset=4 xadvance=15 page=0 chnl=0
char id=73 x=194 y=56 width=6 height=18 xoffset=0 yoffset=4 xadvance=6 page=0 chnl=0
char id=74 x=196 y=2 width=12 height=18 xoffset=-1 yoffset=4 xadvance=12 page=0 chnl=0
char id=75 x=60 y=42 width=16 height=18 xoffset=0 yoffset=4 xadvance=15 page=0 chnl=0
char id=76 x=96 y=34 width=14 height=18 xoffset=0 yoffset=4 xadvance=12 page=0 chnl=0
char id=77 x=2 y=82 width=18 height=18 xoffset=0 yoffset=4 xadvance=19 page=0 chnl=0
char id=78 x=60 y=22 width=16 height=18 xoffset=0 yoffset=4 xadvance=15 page=0 chnl=0
char id=79 x=2 y=62 width=18 height=18 xoffset=-1 yoffset=4 xadvance=16 page=0 chnl=0
char id=80 x=78 y=102 width=14 height=18 xoffset=0 yoffset=4 xadvance=14 page=0 chnl=0
char id=81 x=2 y=42 width=18 height=18 xoffset=-1 yoffset=5 xadvance=16 page=0 chnl=0
char id=82 x=60 y=2 width=16 height=18 xoffset=0 yoffset=4 xadvance=15 page=0 chnl=0
char id=83 x=42 y=102 width=16 height=18 xoffset=-1 yoffset=4 xadvance=13 page=0 chnl=0
char id=84 x=78 y=82 width=14 height=18 xoffset=-1 yoffset=4 xadvance=13 page=0 chnl=0
char id=85 x=42 y=82 width=16 height=18 xoffset=0 yoffset=4 xadvance=15 page=0 chnl=0
char id=86 x=42 y=62 width=16 height=18 xoffset=-2 yoffset=4 xadvance=13 page=0 chnl=0
char id=87 x=2 y=2 width=22 height=18 xoffset=-1 yoffset=4 xadvance=19 page=0 chnl=0
char id=88 x=42 y=42 width=16 height=18 xoffset=-2 yoffset=4 xadvance=14 page=0 chnl=0
char id=89 x=42 y=22 width=16 height=18 xoffset=-2 yoffset=4 xadvance=14 page=0 chnl=0
char id=90 x=42 y=2 width=16 height=18 xoffset=-1 yoffset=4 xadvance=13 page=0 chnl=0
char id=91 x=162 y=100 width=8 height=22 xoffset=0 yoffset=3 xadvance=7 page=0 chnl=0
char id=92 x=134 y=90 width=10 height=18 xoffset=-2 yoffset=4 xadvance=8 page=0 chnl=0
char id=93 x=162 y=76 width=8 height=22 xoffset=-1 yoffset=3 xadvance=7 page=0 chnl=0
char id=94 x=210 y=38 width=12 height=10 xoffset=0 yoffset=5 xadvance=12 page=0 chnl=0
char id=95 x=210 y=50 width=12 height=4 xoffset=-2 yoffset=20 xadvance=10 page=0 chnl=0
char id=96 x=214 y=56 width=8 height=6 xoffset=-2 yoffset=4 xadvance=6 page=0 chnl=0
char id=97 x=146 y=86 width=14 height=14 xoffset=-1 yoffset=8 xadvance=12 page=0 chnl=0
char id=98 x=78 y=62 width=14 height=18 xoffset=0 yoffset=4 xadvance=13 page=0 chnl=0
char id=99 x=146 y=70 width=14 height=14 xoffset=-1 yoffset=8 xadvance=12 page=0 chnl=0
char id=100 x=26 y=106 width=14 height=18 xoffset=-1 yoffset=4 xadvance=13 page=0 chnl=0
char id=101 x=146 y=54 width=14 height=14 xoffset=-1 yoffset=8 xadvance=12 page=0 chnl=0
char id=102 x=134 y=70 width=10 height=18 xoffset=-2 yoffset=4 xadvance=7 page=0 chnl=0
char id=103 x=26 y=86 width=14 height=18 xoffset=-1 yoffset=7 xadvance=13 page=0 chnl=0
char id=104 x=182 y=2 width=12 height=18 xoffset=0 yoffset=4 xadvance=12 page=0 chnl=0
char id=105 x=186 y=100 width=6 height=18 xoffset=0 yoffset=4 xadvance=6 page=0 chnl=0
char id=106 x=176 y=86 width=8 height=20 xoffset=-2 yoffset=5 xadvance=6 page=0 chnl=0
char id=107 x=26 y=66 width=14 height=18 xoffset=0 yoffset=4 xadvance=12 page=0 chnl=0
char id=108 x=186 y=80 width=6 height=18 xoffset=0 yoffset=4 xadvance=6 page=0 chnl=0
char id=109 x=96 y=18 width=18 height=14 xoffset=0 yoffset=8 xadvance=19 page=0 chnl=0
char id=110 x=236 y=22 width=12 height=14 xoffset=0 yoffset=8 xadvance=12 page=0 chnl=0
char id=111 x=146 y=38 width=14 height=14 xoffset=-1 yoffset=8 xadvance=13 page=0 chnl=0
char id=112 x=26 y=46 width=14 height=18 xoffset=0 yoffset=7 xadvance=13 page=0 chnl=0
char id=113 x=26 y=26 width=14 height=18 xoffset=-1 yoffset=7 xadvance=13 page=0 chnl=0
char id=114 x=134 y=110 width=10 height=14 xoffset=0 yoffset=8 xadvance=8 page=0 chnl=0
char id=115 x=222 y=22 width=12 height=14 xoffset=-1 yoffset=8 xadvance=11 page=0 chnl=0
char id=116 x=186 y=38 width=10 height=16 xoffset=-1 yoffset=6 xadvance=8 page=0 chnl=0
char id=117 x=208 y=22 width=12 height=14 xoffset=0 yoffset=8 xadvance=12 page=0 chnl=0
char id=118 x=146 y=22 width=14 height=14 xoffset=-1 yoffset=8 xadvance=11 page=0 chnl=0
char id=119 x=96 y=2 width=20 height=14 xoffset=-1 yoffset=8 xadvance=17 page=0 chnl=0
char id=120 x=224 y=2 width=14 height=14 xoffset=-2 yoffset=8 xadvance=11 page=0 chnl=0
char id=121 x=150 y=2 width=14 height=16 xoffset=-2 yoffset=9 xadvance=11 page=0 chnl=0
char id=122 x=194 y=22 width=12 height=14 xoffset=-1 yoffset=8 xadvance=11 page=0 chnl=0
char id=123 x=134 y=46 width=10 height=22 xoffset=-2 yoffset=3 xadvance=7 page=0 chnl=0
char id=124 x=186 y=56 width=6 height=22 xoffset=0 yoffset=4 xadvance=5 page=0 chnl=0
char id=125 x=134 y=22 width=10 height=22 xoffset=-2 yoffset=3 xadvance=7 page=0 chnl=0
char id=126 x=146 y=118 width=12 height=6 xoffset=0 yoffset=12 xadvance=12 page=0 chnl=0
Binary file added assets/helvetica-20-white.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/Helvetica-20-white.bmglyph
Binary file not shown.
23 changes: 20 additions & 3 deletions src/dust/app/AppConfig.hx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package dust.app;

import dust.app.data.AppTarget;
import nme.Vector;
import nme.ui.Multitouch;
import dust.app.data.AppData;
Expand All @@ -15,15 +16,31 @@ class AppConfig implements Config

function makeApp():AppData
{
var width = nme.Lib.current.stage.stageWidth;
var height = nme.Lib.current.stage.stageHeight;
var isMultiTouch = nme.ui.Multitouch.supportsTouchEvents;

var app = new AppData();
app.deviceWidth = Std.int(nme.system.Capabilities.screenResolutionX);
app.deviceHeight = Std.int(nme.system.Capabilities.screenResolutionY);
app.isMultiTouch = nme.ui.Multitouch.supportsTouchEvents;
app.stageWidth = Std.int(width);
app.stageHeight = Std.int(height);
app.target = getTarget(width, height, isMultiTouch);
app.hasGestures = nme.ui.Multitouch.supportsGestureEvents;
app.supportedGestures = toArray(nme.ui.Multitouch.supportedGestures);

return app;
}

function getTarget(width:Int, height:Int, isMultiTouch:Bool):AppTarget
{
var max = width > height ? width : height;
return if (max == 2048 && isMultiTouch)
AppTarget.IPAD_RETINA;
else if (max == 1024 && isMultiTouch)
AppTarget.IPAD_NORMAL;
else
AppTarget.WEB;
}

function toArray(list:Vector<String>):Array<String>
{
var output = new Array<String>();
Expand Down
6 changes: 3 additions & 3 deletions src/dust/app/data/AppData.hx
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ package dust.app.data;

class AppData
{
public var deviceWidth:Int;
public var deviceHeight:Int;
public var isMultiTouch:Bool;
public var stageWidth:Int;
public var stageHeight:Int;
public var target:AppTarget;
public var hasGestures:Bool;
public var supportedGestures:Array<String>;

Expand Down
8 changes: 8 additions & 0 deletions src/dust/app/data/AppTarget.hx
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package dust.app.data;

enum AppTarget
{
WEB;
IPAD_NORMAL;
IPAD_RETINA;
}
16 changes: 11 additions & 5 deletions src/dust/camera/CameraConfig.hx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package dust.camera;

import dust.app.data.AppTarget;
import dust.app.data.AppData;
import dust.app.AppConfig;
import dust.collections.CollectionsConfig;
Expand Down Expand Up @@ -37,10 +38,15 @@ class CameraConfig implements DependentConfig

function makeCamera():Camera
{
var stage = nme.Lib.current.stage;
screenCenterX = Std.int(app.deviceWidth * 0.5);
screenCenterY = Std.int(app.deviceHeight * 0.5);

return new Camera(screenCenterX, screenCenterY);
screenCenterX = Std.int(app.stageWidth * 0.5);
screenCenterY = Std.int(app.stageHeight * 0.5);

return switch (app.target)
{
case AppTarget.IPAD_RETINA:
new Camera(screenCenterX, screenCenterY, 2);
default:
new Camera(screenCenterX, screenCenterY, 1);
}
}
}
5 changes: 3 additions & 2 deletions src/dust/camera/data/Camera.hx
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,14 @@ class Camera extends Component
public var worldY:Float;
public var scalar:Float;

public function new(screenCenterX:Int, screenCenterY:Int)
public function new(screenCenterX:Int, screenCenterY:Int, scalar:Float = 1)
{
this.screenCenterX = screenCenterX;
this.screenCenterY = screenCenterY;
this.scalar = scalar;

worldX = 0;
worldY = 0;
scalar = 1;
}

public function set(worldX:Float, worldY:Float)
Expand Down
5 changes: 5 additions & 0 deletions src/dust/console/impl/Console.hx
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,11 @@ class Console extends Sprite
input.command.bind(onCommand);
}

public function write(value:String, ?color:Int = 0xFFFFFF)
{
output.write(value, color);
}

public function enable()
{
if (!isEnabled)
Expand Down
4 changes: 2 additions & 2 deletions src/dust/console/ui/ConsoleInput.hx
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ class ConsoleInput extends Sprite
function makeInput(app:AppData)
{
var input = new TextField();
input.y = app.deviceHeight - 20;
input.width = app.deviceWidth;
input.y = app.stageHeight - 20;
input.width = app.stageWidth;
input.height = 20;
input.background = true;
input.backgroundColor = 0x006600;
Expand Down
6 changes: 3 additions & 3 deletions src/dust/console/ui/ConsoleOutput.hx
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class ConsoleOutput extends Sprite
{
var shape = new Shape();
shape.graphics.beginFill(0x006600, 0.8);
shape.graphics.drawRect(0, 0, app.deviceWidth, app.deviceHeight);
shape.graphics.drawRect(0, 0, app.stageWidth, app.stageHeight);
shape.graphics.endFill();
addChild(shape);
return shape;
Expand All @@ -41,8 +41,8 @@ class ConsoleOutput extends Sprite
function makeTextfield(app:AppData):TextField
{
var textfield = new TextField();
textfield.width = app.deviceWidth;
textfield.height = app.deviceHeight - 20;
textfield.width = app.stageWidth;
textfield.height = app.stageHeight - 20;
textfield.background = false;
textfield.defaultTextFormat = format;
textfield.multiline = true;
Expand Down
15 changes: 11 additions & 4 deletions src/dust/mainmenu/MainMenuConfig.hx
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
package dust.mainmenu;

import dust.app.data.AppTarget;
import nme.display.DisplayObjectContainer;
import dust.app.data.AppData;
import dust.app.AppConfig;
import dust.text.Helvetica10WhiteFontConfig;
import dust.text.HelveticaSmallWhiteFontConfig;
import dust.mainmenu.control.MainMenuButtonFactory;
import dust.graphics.data.Paint;
import dust.text.Michroma24WhiteFontConfig;
Expand All @@ -27,7 +28,7 @@ class MainMenuConfig implements DependentConfig
@inject public var root:DisplayObjectContainer;

public function dependencies():Array<Class<Config>>
return [AppConfig, SignalMapConfig, Helvetica10WhiteFontConfig]
return [AppConfig, SignalMapConfig, HelveticaSmallWhiteFontConfig]

public function configure()
{
Expand All @@ -40,11 +41,17 @@ class MainMenuConfig implements DependentConfig

function makeConfig():MainMenuButtonConfig
{
var font = fonts.get(Helvetica10WhiteFontConfig.HELVETICA_10_WHITE);
var font = fonts.get(HelveticaSmallWhiteFontConfig.FONT);
var paint = new Paint()
.setFill(0x1E90FF)
.setLine(1, 0xFFFFFF);

return new MainMenuButtonConfig(app, font, paint, 160, 40, 20);
return switch (app.target)
{
case AppTarget.IPAD_RETINA:
new MainMenuButtonConfig(app, font, paint, 320, 80, 40);
default:
new MainMenuButtonConfig(app, font, paint, 160, 40, 20);
}
}
}
2 changes: 1 addition & 1 deletion src/dust/mainmenu/data/MainMenuButtonConfig.hx
Original file line number Diff line number Diff line change
Expand Up @@ -40,5 +40,5 @@ class MainMenuButtonConfig
}

public function rows():Int
return Std.int((app.deviceHeight - padding) / (height + padding))
return Std.int((app.stageHeight - padding) / (height + padding))
}
37 changes: 0 additions & 37 deletions src/dust/text/Helvetica10WhiteFontConfig.hx

This file was deleted.

Loading

0 comments on commit 724b454

Please sign in to comment.