Use (smoother) native cursors
authorRichard Fairhurst <richard@systemeD.net>
Wed, 28 Dec 2011 13:19:27 +0000 (13:19 +0000)
committerRichard Fairhurst <richard@systemeD.net>
Wed, 28 Dec 2011 13:19:27 +0000 (13:19 +0000)
net/systemeD/potlatch2/EditController.as
net/systemeD/potlatch2/controller/DrawWay.as

index 184f70a..f70cc21 100644 (file)
@@ -11,7 +11,10 @@ package net.systemeD.potlatch2 {
     import flash.external.ExternalInterface;
     import flash.events.*;
        import flash.geom.*;
+       import flash.display.*;
        import flash.ui.Keyboard;
+       import flash.ui.Mouse;
+       import flash.ui.MouseCursorData;
        import flash.text.TextField;
     import mx.controls.TextArea;
 
@@ -64,6 +67,12 @@ package net.systemeD.potlatch2 {
             if (this.moveFunction) {
                 map.addEventListener(MapEvent.MOVE, moveHandler);
             }
+
+                       createBitmapCursor("pen"     ,new pen());
+                       createBitmapCursor("pen_x"   ,new pen_x());
+                       createBitmapCursor("pen_o"   ,new pen_o());
+                       createBitmapCursor("pen_so"  ,new pen_so());
+                       createBitmapCursor("pen_plus",new pen_plus());
         }
 
         public function setActive():void {
@@ -178,9 +187,18 @@ package net.systemeD.potlatch2 {
                }
 
                /** Set a mouse pointer. */
-               public function setCursor(cursor:Class):void {
-                       CursorManager.removeAllCursors();
-                       if (cursor && cursorsEnabled) { CursorManager.setCursor(cursor,2,-4,0); }
+               public function setCursor(name:String=""):void {
+                       if (name && cursorsEnabled) { Mouse.cursor=name; }
+                       else { Mouse.cursor=flash.ui.MouseCursor.AUTO; }
+               }
+
+               private function createBitmapCursor(name:String, source:Bitmap, hotX:int=4, hotY:int=0):void {
+                       var bitmapVector:Vector.<BitmapData> = new Vector.<BitmapData>(1, true);
+                       bitmapVector[0] = source.bitmapData;
+                       var cursorData:MouseCursorData = new MouseCursorData();
+                       cursorData.hotSpot = new Point(hotX,hotY);
+                       cursorData.data = bitmapVector;
+                       Mouse.registerCursor(name, cursorData);
                }
 
         private function toggleSize():void {
index 08b11d0..0101db3 100644 (file)
@@ -130,12 +130,12 @@ package net.systemeD.potlatch2.controller {
                                // set cursor depending on whether we're floating over the start of this way, 
                                // another random node, a possible junction...
                                if (entity is Node && focus is Way && Way(focus).endsWith(Node(entity))) {
-                                       if (focus==firstSelected) { controller.setCursor(controller.pen_so); }
-                                                            else { controller.setCursor(controller.pen_o); }
+                                       if (focus==firstSelected) { controller.setCursor("pen_so"); }
+                                                            else { controller.setCursor("pen_o"); }
                                } else if (entity is Node) {
-                                       controller.setCursor(controller.pen_x);
+                                       controller.setCursor("pen_x");
                                } else {
-                                       controller.setCursor(controller.pen_plus);
+                                       controller.setCursor("pen_plus");
                                }
                        } else if ( event.type == MouseEvent.MOUSE_OUT && !isBackground ) {
                                if (focus is Way && entity!=firstSelected) {
@@ -144,7 +144,7 @@ package net.systemeD.potlatch2.controller {
                                        // ** We could do with an optional way of calling WayUI.redraw to only do the nodes, which would be a
                                        // useful optimisation.
                                }
-                               controller.setCursor(controller.pen);
+                               controller.setCursor("pen");
                        }
 
                        return this;
@@ -341,14 +341,14 @@ package net.systemeD.potlatch2.controller {
                        var node:Node = Way(firstSelected).getNode(editEnd ? Way(firstSelected).length-1 : 0);
                        var start:Point = new Point(node.lon, node.latp);
                        elastic = new Elastic(controller.map, start, start);
-                       controller.setCursor(controller.pen);
+                       controller.setCursor("pen");
                }
                override public function exitState(newState:ControllerState):void {
             Way(firstSelected).removeEventListener(Connection.WAY_NODE_REMOVED, fixElastic);
             Way(firstSelected).removeEventListener(Connection.WAY_NODE_ADDED, fixElastic);
 
                        super.exitState(newState);
-                       controller.setCursor(null);
+                       controller.setCursor();
                        elastic.removeSprites();
                        elastic = null;
                }