Permalink
Browse files

Added Toolbar

  • Loading branch information...
1 parent 77b0e8f commit 4847bc1dca57a9a0b405e6abd4b9d2bd20246aad @destroytoday destroytoday committed Jan 27, 2010
View
BIN libs/DestroyFramework.swc
Binary file not shown.
View
BIN libs/GTween_V2_01.swc
Binary file not shown.
View
7 src/Dwarf-app.xml
@@ -3,11 +3,16 @@
<id>com.destroytoday.dwarf</id>
<filename>Dwarf</filename>
<name>Dwarf</name>
- <version>1.0.0 Build 20100126.0</version>
+ <version>1.0.0 Build 20100127.1</version>
<description>Dwarf is a screen toolbox.</description>
<copyright>Copyright © 2010 Jonnie Hallman</copyright>
<initialWindow>
<content>[This value will be overwritten by Flash Builder in the output app.xml]</content>
+ <systemChrome>none</systemChrome>
+ <transparent>true</transparent>
+ <title>Dwarf</title>
+ <maximizable>false</maximizable>
+ <minimizable>false</minimizable>
</initialWindow>
<icon>
<image16x16>icons/16.png</image16x16>
View
37 src/Dwarf.as
@@ -1,28 +1,61 @@
package {
+ import com.destroytoday.display.Group;
import com.destroytoday.dwarf.contexts.ApplicationContext;
import com.destroytoday.dwarf.views.ruler.RulerView;
+ import com.destroytoday.dwarf.views.toolbar.ToolbarView;
+ import com.gskinner.motion.GTween;
import flash.display.Sprite;
+ import flash.display.StageAlign;
+ import flash.display.StageScaleMode;
+ import flash.geom.Point;
import flash.ui.Multitouch;
import flash.ui.MultitouchInputMode;
+ import mx.effects.easing.Quartic;
+
+ [SWF(backgroundColor="#222222")]
+
/**
* The Dwarf class is the application class.
* @author Jonnie Hallman
*/
- public class Dwarf extends Sprite {
+ public class Dwarf extends Group {
/**
* The context of the application.
*/
public var context:ApplicationContext;
/**
+ * The toolbar for managing tools.
+ */
+ public var toolbarView:ToolbarView;
+
+ /**
* Constructs the Dwarf instance.
*/
public function Dwarf() {
- context = new ApplicationContext(this);
+ GTween.defaultEase = Quartic.easeInOut;
+
+ stage.scaleMode = StageScaleMode.NO_SCALE;
+ stage.align = StageAlign.TOP_LEFT;
+ stage.nativeWindow.minSize = new Point(0, 0);
stage.frameRate = 50.0; //TODO - integrate framerate throttler
+
+ context = new ApplicationContext(this);
+
+ toolbarView = addChild(new ToolbarView()) as ToolbarView;
+
+ measureChildren = false;
+
+ left = 0.0;
+ top = 0.0;
+ right = 0.0;
+ bottom = 0.0;
+
+ updateListeners();
+ stage.nativeWindow.activate();
}
}
}
View
7 src/com/destroytoday/dwarf/assets/Assets.as
@@ -19,8 +19,11 @@ package com.destroytoday.dwarf.assets {
*/
public static const INTERSTATE_REGULAR_FONT:String = "Interstate-Regular";
- [Embed(source="icons/16.png", mimeType="image/png")]
- public static const ICON_16X16:Class;
+ /**
+ * The System Tray icon (PC only)
+ */
+ [Embed(source="icons/32.png", mimeType="image/png")]
+ public static const ICON_32X32:Class;
/**
* @private
View
9 src/com/destroytoday/dwarf/assets/Color.as
@@ -1,5 +1,14 @@
package com.destroytoday.dwarf.assets {
public class Color {
+ // interface colors
+ public static const GREY_2:uint = 0x222222;
+ public static const GREY_2B:uint = 0x2B2B2B;
+ public static const GREY_3:uint = 0x333333;
+ public static const GREY_42:uint = 0x424242;
+ public static const GREY_A:uint = 0xAAAAAA;
+ public static const GREY_C3C6C8:uint = 0xC3C6C8;
+
+ // tool colors
public static const WHITE:uint = 0xFFFFFF;
public static const BLACK:uint = 0x000000;
public static const RED:uint = 0xCA3430;
View
11 src/com/destroytoday/dwarf/constants/ToolbarState.as
@@ -0,0 +1,11 @@
+package com.destroytoday.dwarf.constants {
+ public class ToolbarState {
+ public static const NORMAL:String = "ToolbarState:normal";
+
+ public static const RULER:String = "ToolbarState:ruler";
+
+ public function ToolbarState() {
+ throw Error("The ToolbarState class cannot be instantiated.");
+ }
+ }
+}
View
9 src/com/destroytoday/dwarf/contexts/ApplicationContext.as
@@ -2,12 +2,14 @@ package com.destroytoday.dwarf.contexts {
import com.destroytoday.dwarf.controllers.AddRulerCommand;
import com.destroytoday.dwarf.controllers.ToolController;
import com.destroytoday.dwarf.desktop.IconMenu;
+ import com.destroytoday.dwarf.desktop.MacToolbar;
import com.destroytoday.dwarf.desktop.RulerMenu;
- import com.destroytoday.dwarf.desktop.Toolbar;
import com.destroytoday.dwarf.mediators.RulerMediator;
+ import com.destroytoday.dwarf.mediators.ToolbarMediator;
import com.destroytoday.dwarf.models.ToolModel;
import com.destroytoday.dwarf.signals.AddRulerSignal;
import com.destroytoday.dwarf.views.ruler.RulerView;
+ import com.destroytoday.dwarf.views.toolbar.ToolbarView;
import com.destroytoday.util.ApplicationUtil;
import flash.display.DisplayObjectContainer;
@@ -35,14 +37,14 @@ package com.destroytoday.dwarf.contexts {
override public function startup():void {
injector.mapSingleton(ToolController);
injector.mapSingleton(ToolModel);
- injector.mapSingleton(Toolbar);
+ injector.mapSingleton(MacToolbar);
injector.mapSingleton(IconMenu);
injector.mapSingleton(RulerMenu);
injector.mapValue(AddRulerSignal, signalCommandMap.mapSignalClass(AddRulerSignal, AddRulerCommand));
if (ApplicationUtil.mac) {
- var toolbar:Toolbar = new Toolbar();
+ var toolbar:MacToolbar = new MacToolbar();
injector.injectInto(toolbar);
@@ -53,6 +55,7 @@ package com.destroytoday.dwarf.contexts {
injector.injectInto(iconMenu);
iconMenu.setup();
+ mediatorMap.mapView(ToolbarView, ToolbarMediator);
mediatorMap.mapView(RulerView, RulerMediator);
}
}
View
4 src/com/destroytoday/dwarf/core/ITool.as
@@ -1,4 +1,6 @@
package com.destroytoday.dwarf.core {
+ import flash.display.NativeWindow;
+
import org.osflash.signals.Signal;
public interface ITool {
@@ -11,6 +13,8 @@ package com.destroytoday.dwarf.core {
function get colorChangeSignal():Signal;
function get alphaChangeSignal():Signal;
+ function get window():NativeWindow;
+
function open():void;
function close():void;
function maximize():void;
View
31 src/com/destroytoday/dwarf/desktop/IconMenu.as
@@ -2,13 +2,16 @@ package com.destroytoday.dwarf.desktop {
import com.destroytoday.desktop.NativeMenuPlus;
import com.destroytoday.dwarf.assets.Assets;
import com.destroytoday.dwarf.controllers.ToolController;
+ import com.destroytoday.dwarf.models.ToolModel;
import com.destroytoday.util.ApplicationUtil;
+ import com.destroytoday.util.WindowUtil;
import flash.desktop.DockIcon;
import flash.desktop.Icon;
import flash.desktop.NativeApplication;
import flash.desktop.SystemTrayIcon;
import flash.display.NativeMenuItem;
+ import flash.events.ScreenMouseEvent;
import flash.net.URLRequest;
import flash.net.navigateToURL;
import flash.ui.Keyboard;
@@ -17,6 +20,9 @@ package com.destroytoday.dwarf.desktop {
[Inject]
public var toolController:ToolController;
+ [Inject]
+ public var toolModel:ToolModel;
+
public function IconMenu() {
}
@@ -31,19 +37,23 @@ package com.destroytoday.dwarf.desktop {
<item name="newRuler" label="New Ruler" />
<separator />
<item name="closeTool" label="Close Tool" />
+ <item name="quit" label="Quit" />
</menu>;
} else {
var icon:SystemTrayIcon = NativeApplication.nativeApplication.icon as SystemTrayIcon;
- icon.bitmaps = [new Assets.ICON_16X16()];
+ icon.bitmaps = [new Assets.ICON_32X32()];
icon.menu = this;
data =
<menu>
- <item name="newRuler" keyEquivalentModifiers="control" keyEquivalent="r" label="New Ruler" />
+ <item name="newRuler" label="New Ruler" />
<separator />
- <item name="closeTool" keyEquivalentModifiers="control" keyEquivalent="w" label="Close Tool" />
+ <item name="closeTool" label="Close Tool" />
+ <item name="quit" label="Quit" />
</menu>;
+
+ icon.addEventListener(ScreenMouseEvent.CLICK, iconClickHandler, false, 0, true);
}
//add listeners
@@ -66,6 +76,21 @@ package com.destroytoday.dwarf.desktop {
case "closeTool":
toolController.removeCurrentTool();
break;
+ case "quit":
+ WindowUtil.closeAll(true);
+ break;
+ }
+ }
+
+ /**
+ * @private
+ * @param event
+ */
+ protected function iconClickHandler(event:ScreenMouseEvent):void {
+ if (toolModel.currentTool.window) {
+ NativeApplication.nativeApplication.activate(toolModel.currentTool.window);
+ } else {
+ NativeApplication.nativeApplication.activate(NativeApplication.nativeApplication.openedWindows[0]);
}
}
}
View
4 ...com/destroytoday/dwarf/desktop/Toolbar.as → .../destroytoday/dwarf/desktop/MacToolbar.as
@@ -17,7 +17,7 @@ package com.destroytoday.dwarf.desktop {
* The Toolbar class represents the desktop toolbar on Mac.
* @author Jonnie Hallman
*/
- public class Toolbar extends Actor {
+ public class MacToolbar {
[Inject]
public var toolController:ToolController;
@@ -57,7 +57,7 @@ package com.destroytoday.dwarf.desktop {
/**
* Constructs the Toolbar instance.
*/
- public function Toolbar() {
+ public function MacToolbar() {
}
/**
View
62 src/com/destroytoday/dwarf/desktop/RulerMenu.as
@@ -0,0 +1,62 @@
+package com.destroytoday.dwarf.desktop {
+ import com.destroytoday.desktop.NativeMenuPlus;
+ import com.destroytoday.dwarf.assets.Color;
+ import com.destroytoday.dwarf.models.ToolModel;
+ import com.destroytoday.dwarf.views.ruler.RulerView;
+
+ import flash.display.NativeMenuItem;
+ import flash.display.Stage;
+ import flash.events.Event;
+
+ public class RulerMenu extends NativeMenuPlus {
+ [Inject]
+ public var toolModel:ToolModel;
+
+ public function RulerMenu() {
+ setup();
+ }
+
+ public function setup():void {
+ data =
+ <menu>
+ <item name="800x600" label="800x600" />
+ <item name="1024x768" label="1024x768" />
+ <separator />
+ <item name="red" label="Red" />
+ <item name="orange" label="Orange" />
+ <item name="yellow" label="Yellow" />
+ <item name="green" label="Green" />
+ <item name="blue" label="Blue" />
+ <item name="black" label="Black" />
+ </menu>;
+ }
+
+ override public function display(stage:Stage, stageX:Number, stageY:Number):void {
+ var ruler:RulerView = toolModel.currentTool as RulerView;
+
+ for each(var color:String in Color.names) {
+ getItemByName(color).checked = ruler.platform.fillColor == Color[color.toUpperCase()];
+ }
+
+ super.display(stage, stageX, stageY);
+ }
+
+ override protected function itemSelectHandler(event:Event):void {
+ var ruler:RulerView = toolModel.currentTool as RulerView;
+ var item:NativeMenuItem = event.currentTarget as NativeMenuItem;
+
+ switch(item.name) {
+ case "800x600":
+ ruler.stage.nativeWindow.width = 800.0;
+ ruler.stage.nativeWindow.height = 600.0;
+ break;
+ case "1024x768":
+ ruler.stage.nativeWindow.width = 1024.0;
+ ruler.stage.nativeWindow.height = 768.0;
+ break;
+ default:
+ ruler.platform.fillColor = Color[item.name.toUpperCase()];
+ }
+ }
+ }
+}
View
34 src/com/destroytoday/dwarf/mediators/ToolbarMediator.as
@@ -0,0 +1,34 @@
+package com.destroytoday.dwarf.mediators {
+ import com.destroytoday.dwarf.controllers.ToolController;
+ import com.destroytoday.dwarf.views.toolbar.ToolbarView;
+
+ import flash.events.MouseEvent;
+ import flash.net.URLRequest;
+ import flash.net.navigateToURL;
+
+ import org.robotlegs.mvcs.Mediator;
+
+ public class ToolbarMediator extends Mediator {
+ [Inject]
+ public var toolController:ToolController;
+
+ [Inject]
+ public var view:ToolbarView;
+
+ public function ToolbarMediator() {
+ }
+
+ override public function onRegister():void {
+ eventMap.mapListener(view.applicationButton, MouseEvent.CLICK, applicationButtonClickHandler, MouseEvent);
+ eventMap.mapListener(view.rulerButton, MouseEvent.CLICK, rulerButtonClickHandler, MouseEvent);
+ }
+
+ protected function applicationButtonClickHandler(event:MouseEvent):void {
+ navigateToURL(new URLRequest("http://github.com/destroytoday/Dwarf"));
+ }
+
+ protected function rulerButtonClickHandler(event:MouseEvent):void {
+ toolController.addRuler();
+ }
+ }
+}
View
6 src/com/destroytoday/dwarf/views/ruler/RulerSizeText.as
@@ -1,8 +1,10 @@
package com.destroytoday.dwarf.views.ruler {
import com.destroytoday.display.Group;
import com.destroytoday.dwarf.assets.Assets;
+ import com.destroytoday.dwarf.assets.Color;
import com.destroytoday.text.TextFieldPlus;
+ import flash.text.AntiAliasType;
import flash.text.TextFieldAutoSize;
import flash.text.TextFormat;
@@ -30,9 +32,11 @@ package com.destroytoday.dwarf.views.ruler {
// set components' properties
textfield.embedFonts = true;
- textfield.defaultTextFormat = new TextFormat(Assets.INTERSTATE_REGULAR_FONT, 11, 0xFFFFFF);
+ textfield.defaultTextFormat = new TextFormat(Assets.INTERSTATE_REGULAR_FONT, 11, Color.WHITE);
textfield.selectable = false;
textfield.autoSize = TextFieldAutoSize.LEFT;
+ textfield.antiAliasType = AntiAliasType.ADVANCED;
+ textfield.thickness = -100.0;
// set instance's properties
measureChildren = false;
View
8 src/com/destroytoday/dwarf/views/ruler/RulerView.as
@@ -134,6 +134,14 @@ package com.destroytoday.dwarf.views.ruler {
}
/**
+ * Returns the Ruler's native window.
+ * @return
+ */
+ public function get window():NativeWindow {
+ return stage.nativeWindow;
+ }
+
+ /**
* The color of the Ruler's platform.
* @return
*/
View
101 src/com/destroytoday/dwarf/views/toolbar/TextButton.as
@@ -0,0 +1,101 @@
+package com.destroytoday.dwarf.views.toolbar {
+ import com.destroytoday.display.Group;
+ import com.destroytoday.dwarf.assets.Assets;
+ import com.destroytoday.dwarf.assets.Color;
+ import com.destroytoday.text.TextFieldPlus;
+
+ import flash.display.CapsStyle;
+ import flash.display.Sprite;
+ import flash.events.MouseEvent;
+ import flash.text.AntiAliasType;
+ import flash.text.TextFieldAutoSize;
+ import flash.text.TextFormat;
+
+ import org.osmf.display.ScaleMode;
+
+ public class TextButton extends Group {
+ public var textfield:TextFieldPlus;
+
+ protected var _maxWidth:Number = Number.MAX_VALUE;
+
+ protected var _fillColor:uint = Color.GREY_3;
+
+ public function TextButton() {
+ textfield = addChild(new TextFieldPlus()) as TextFieldPlus;
+
+ textfield.embedFonts = true;
+ textfield.defaultTextFormat = new TextFormat(Assets.INTERSTATE_REGULAR_FONT, 11, Color.GREY_C3C6C8);
+ textfield.selectable = false;
+ textfield.autoSize = TextFieldAutoSize.LEFT;
+ textfield.antiAliasType = AntiAliasType.ADVANCED;
+
+ textfield.x = 4.0;
+ textfield.y = 5.0;
+
+ measureChildren = false;
+ buttonMode = true;
+ mouseChildren = false;
+
+ height = 25.0;
+
+ draw();
+
+ addEventListener(MouseEvent.MOUSE_OVER, mouseOverHandler);
+ addEventListener(MouseEvent.MOUSE_OUT, mouseOutHandler);
+ }
+
+ public function get maxWidth():Number {
+ return _maxWidth;
+ }
+
+ public function set maxWidth(value:Number):void {
+ _maxWidth = value;
+
+ width = Math.min(_maxWidth, width);
+
+ draw();
+ }
+
+ public function get text():String {
+ return textfield.text;
+ }
+
+ public function set text(value:String):void {
+ textfield.text = value;
+
+ width = Math.min(_maxWidth, Math.round(textfield.width + 9.0));
+
+ draw();
+ }
+
+ public function get fillColor():uint {
+ return _fillColor;
+ }
+
+ public function set fillColor(value:uint):void {
+ _fillColor = value;
+
+ draw();
+ }
+
+ public function draw():void {
+ graphics.clear();
+ graphics.beginFill(fillColor);
+ graphics.drawRect(0.0, 0.0, width, height);
+ graphics.endFill();
+ graphics.lineStyle(0.0, Color.GREY_2, 1.0, false, ScaleMode.NONE, CapsStyle.SQUARE);
+ graphics.moveTo(0.0, 0.0);
+ graphics.lineTo(0.0, height - 1.0);
+ graphics.moveTo(width - 1.0, 0.0);
+ graphics.lineTo(width - 1.0, height - 1.0);
+ }
+
+ protected function mouseOverHandler(event:MouseEvent):void {
+ fillColor = Color.GREY_42;
+ }
+
+ protected function mouseOutHandler(event:MouseEvent):void {
+ fillColor = Color.GREY_3;
+ }
+ }
+}
View
133 src/com/destroytoday/dwarf/views/toolbar/ToolbarView.as
@@ -0,0 +1,133 @@
+package com.destroytoday.dwarf.views.toolbar {
+ import com.destroytoday.display.Group;
+ import com.destroytoday.display.GroupAlignType;
+ import com.destroytoday.dwarf.assets.Color;
+ import com.destroytoday.dwarf.constants.ToolbarState;
+ import com.gskinner.motion.GTween;
+
+ import flash.desktop.NativeApplication;
+ import flash.display.NativeWindow;
+ import flash.display.NativeWindowInitOptions;
+ import flash.display.NativeWindowSystemChrome;
+ import flash.display.Screen;
+ import flash.display.Stage;
+ import flash.events.Event;
+ import flash.events.NativeWindowBoundsEvent;
+ import flash.geom.Rectangle;
+
+ public class ToolbarView extends Group {
+ public var applicationButton:TextButton;
+ public var rulerButton:TextButton;
+
+ protected var positionTween:GTween;
+
+ protected var bounds:Rectangle;
+
+ protected var _state:String = ToolbarState.NORMAL;
+
+ public function ToolbarView() {
+ applicationButton = addChild(new TextButton()) as TextButton;
+ rulerButton = addChild(new TextButton()) as TextButton;
+
+ applicationButton.paddingRight = 2.0;
+ applicationButton.maxWidth = 27.0;
+ applicationButton.text = "Dw";
+ applicationButton.textfield.x = 2.0;
+ applicationButton.textfield.textColor = Color.RED;
+
+ rulerButton.text = "Ruler";
+
+ positionTween = new GTween(this, 0.75);
+
+ measureChildren = false;
+ align = GroupAlignType.LEFT;
+ gap = 1.0;
+
+ left = 0.0;
+ right = 0.0;
+ height = 25.0;
+
+ scrollRect = bounds = new Rectangle(0.0, height, 0.0, height);
+
+ positionTween.onInit = positionTweenInitHandler;
+ positionTween.onComplete = positionTweenCompleteHandler;
+ }
+
+ override public function get y():Number {
+ return (bounds) ? bounds.y : 0.0;
+ }
+
+ override public function set y(value:Number):void {
+ if (bounds) {
+ bounds.y = value;
+
+ scrollRect = bounds;
+ }
+ }
+
+ public function resize():void {
+ var screen:Rectangle = Screen.mainScreen.visibleBounds;
+
+ stage.nativeWindow.x = screen.x;
+ stage.nativeWindow.y = screen.y;
+ stage.nativeWindow.width = Screen.mainScreen.bounds.width;
+ stage.nativeWindow.height = height;
+ }
+
+ public function get state():String {
+ return _state;
+ }
+
+ public function set state(value:String):void {
+ _state = value;
+ }
+
+ override protected function updateBounds():void {
+ super.updateBounds();
+
+ if (bounds) {
+ bounds.width = width;
+
+ scrollRect = bounds;
+ }
+
+ graphics.clear();
+ graphics.beginFill(Color.GREY_2B);
+ graphics.drawRect(0.0, 0.0, width, height);
+ graphics.endFill();
+ }
+
+ override protected function addedToStageHandler(event:Event):void {
+ super.addedToStageHandler(event);
+
+ resize();
+
+ if (stage.nativeWindow.active) {
+ positionTween.setValue('y', 0.0);
+ }
+
+ NativeApplication.nativeApplication.addEventListener(Event.ACTIVATE, applicationActivateHandler, false, 0, true);
+ NativeApplication.nativeApplication.addEventListener(Event.DEACTIVATE, applicationDeactivateHandler, false, 0, true);
+ }
+
+ protected function applicationActivateHandler(event:Event):void {
+ positionTween.setValue('y', 0.0);
+ }
+
+ protected function applicationDeactivateHandler(event:Event):void {
+ positionTween.setValue('y', height);
+ }
+
+ protected function positionTweenInitHandler(tween:GTween):void {
+ if (y == height) {
+ stage.nativeWindow.visible = true;
+ }
+ }
+
+ protected function positionTweenCompleteHandler(tween:GTween):void {
+ if (y == height) {
+ stage.nativeWindow.visible = false;
+ }
+ }
+ }
+}

0 comments on commit 4847bc1

Please sign in to comment.