Skip to content

Commit

Permalink
exposing Starling viewPort (closes #19)
Browse files Browse the repository at this point in the history
  • Loading branch information
PrimaryFeather committed Aug 18, 2011
1 parent 6323a99 commit 735007a
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 13 deletions.
2 changes: 2 additions & 0 deletions samples/demo/src/Startup.as
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package
{
import flash.display.Sprite;
import flash.display.StageScaleMode;

import starling.core.Starling;

Expand All @@ -11,6 +12,7 @@ package

public function Startup()
{
stage.scaleMode = StageScaleMode.NO_SCALE;
Starling.multitouchEnabled = true;

mStarling = new Starling(Game, stage);
Expand Down
33 changes: 20 additions & 13 deletions starling/src/starling/core/Starling.as
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,6 @@ package starling.core
stage.addEventListener(touchEventType, onTouch, false, 0, true);

// register other event handlers
stage.addEventListener(Event.RESIZE, onResize, false, 0, true);
stage.addEventListener(Event.ENTER_FRAME, onEnterFrame, false, 0, true);
stage.addEventListener(KeyboardEvent.KEY_DOWN, onKey, false, 0, true);
stage.addEventListener(KeyboardEvent.KEY_UP, onKey, false, 0, true);
Expand All @@ -115,10 +114,8 @@ package starling.core
if (mContext) return;

mContext = mStage3D.context3D;
mStage3D.x = mViewPort.x;
mStage3D.y = mViewPort.y;
mContext.enableErrorChecking = mEnableErrorChecking;
mContext.configureBackBuffer(mViewPort.width, mViewPort.height, mAntiAliasing, false);
updateViewPort();

trace("[Starling] Initialization complete.");
trace("[Starling] Display Driver:" + mContext.driverInfo);
Expand All @@ -139,6 +136,15 @@ package starling.core
mStage.addChild(rootObject);
}

private function updateViewPort():void
{
if (mContext)
mContext.configureBackBuffer(mViewPort.width, mViewPort.height, mAntiAliasing, false);

mStage3D.x = mViewPort.x;
mStage3D.y = mViewPort.y;
}

public function makeCurrent():void
{
sCurrent = this;
Expand Down Expand Up @@ -171,11 +177,6 @@ package starling.core

// event handlers

private function onResize(event:Event):void
{
// TODO
}

private function onContextCreated(event:Event):void
{
initializeGraphicsAPI();
Expand Down Expand Up @@ -223,8 +224,8 @@ package starling.core
function convertPosition(globalPos:Point):Point
{
return new Point(
(globalPos.x - mViewPort.x) * (mViewPort.width / mStage.stageWidth),
(globalPos.y - mViewPort.y) * (mViewPort.height / mStage.stageHeight));
(globalPos.x - mViewPort.x) + (mViewPort.width / mStage.stageWidth),
(globalPos.y - mViewPort.y) + (mViewPort.height / mStage.stageHeight));
}

function getPhaseFromMouseEvent(event:MouseEvent):String
Expand Down Expand Up @@ -304,8 +305,14 @@ package starling.core
public function set antiAliasing(value:int):void
{
mAntiAliasing = value;
if (mContext)
mContext.configureBackBuffer(mViewPort.width, mViewPort.height, value, false);
updateViewPort();
}

public function get viewPort():Rectangle { return mViewPort.clone(); }
public function set viewPort(value:Rectangle):void
{
mViewPort = value.clone();
updateViewPort();
}

// static properties
Expand Down

0 comments on commit 735007a

Please sign in to comment.