select and move POI nodes, and a handful of smaller fixes too
authorRichard Fairhurst <richard@systemed.net>
Mon, 30 Nov 2009 00:42:53 +0000 (00:42 +0000)
committerRichard Fairhurst <richard@systemed.net>
Mon, 30 Nov 2009 00:42:53 +0000 (00:42 +0000)
net/systemeD/halcyon/EntityUI.as
net/systemeD/halcyon/Map.as
net/systemeD/halcyon/NodeUI.as
net/systemeD/halcyon/WayUI.as
net/systemeD/potlatch2/controller/DrawWay.as
net/systemeD/potlatch2/controller/NoSelection.as
net/systemeD/potlatch2/controller/SelectedPOINode.as
net/systemeD/potlatch2/controller/SelectedWay.as
net/systemeD/potlatch2/controller/SelectedWayNode.as

index bf4cb76..ca7cc1f 100644 (file)
@@ -5,6 +5,7 @@ package net.systemeD.halcyon {
        import flash.text.AntiAliasType;
        import flash.text.GridFitType;
        import net.systemeD.halcyon.Globals;
+       import net.systemeD.halcyon.styleparser.StyleList;
 
        public class EntityUI {
 
@@ -79,6 +80,17 @@ package net.systemeD.halcyon {
             }
         }
 
+               protected function applyStateClasses(tags:Object):Object {
+            for (var stateKey:String in stateClasses) {
+                tags[":"+stateKey] = 'yes';
+            }
+                       return tags;
+               }
+               
+               public function redraw(sl:StyleList=null):Boolean {
+                       return false;
+               }
+
        }
 
 }
index 1334896..4b78c3e 100755 (executable)
@@ -286,7 +286,15 @@ package net.systemeD.halcyon {
 
         public function setHighlight(entity:Entity, settings:Object):void {
                        var stateType:String;
-            if ( entity is Way ) {
+                       var ui:EntityUI=null;
+                       if      ( entity is Way  ) { ui = ways[entity.id]; }
+                       else if ( entity is Node ) { ui = pois[entity.id]; }
+                       if (ui==null) { return; }
+                       for (stateType in settings) {
+                               ui.setHighlight(stateType, settings[stateType]);
+                       }
+                       ui.redraw();
+/*            if ( entity is Way ) {
                 var wayUI:WayUI = ways[entity.id];
                 if (wayUI==null) { return; }
                                for (stateType in settings) {
@@ -294,13 +302,14 @@ package net.systemeD.halcyon {
                                }
                                wayUI.redraw();
             } else if (entity is Node) {
-                               var nodeUI:NodeUI = nodes[entity.id];
+                               var nodeUI:NodeUI = pois[entity.id];
                 if (nodeUI==null) { return; }
                                for (stateType in settings) {
                        nodeUI.setHighlight(stateType, settings[stateType]);
                                }
                                nodeUI.redraw();
                        }
+*/
         }
 
         // Handle mouse events on ways/nodes
index 8f57b8e..3656914 100644 (file)
@@ -33,16 +33,10 @@ package net.systemeD.halcyon {
                    updatePosition();
                }
                
-               public function redraw(sl:StyleList=null,forceDraw:Boolean=false):Boolean {
-                       // *** forcedraw can be removed
+               override public function redraw(sl:StyleList=null):Boolean {
                        var tags:Object = node.getTagsCopy();
-
-                       // special tags
+                       tags=applyStateClasses(tags);
                        if (!node.hasParentWays) { tags[':poi']='yes'; }
-            for (var stateKey:String in stateClasses) {
-                tags[":"+stateKey] = 'yes';
-            }
-
                        if (!sl) { sl=map.ruleset.getStyles(this.node,tags); }
 
                        var inWay:Boolean=node.hasParentWays;
index 1c35f05..9cbfa6a 100755 (executable)
@@ -112,14 +112,12 @@ package net.systemeD.halcyon {
                // ------------------------------------------------------------------------------------------
                // Redraw
 
-               public function redraw():void {
+               override public function redraw(sl:StyleList=null):Boolean {
                        removeSprites();
 
             // Copy tags object, and add states
             var tags:Object = way.getTagsCopy();
-            for (var stateKey:String in stateClasses) {
-                tags[":"+stateKey] = 'yes';
-            }
+                       tags=applyStateClasses(tags);
                        if (way.isArea()) { tags[':area']='yes'; }
 
                        // Which layer?
@@ -128,7 +126,7 @@ package net.systemeD.halcyon {
                 layer=Math.min(Math.max(tags['layer']+5,-5),5)+5;
 
                        // Iterate through each sublayer, drawing any styles on that layer
-                       var sl:StyleList=map.ruleset.getStyles(this.way, tags);
+                       if (!sl) { sl=map.ruleset.getStyles(this.way, tags); }
                        var drawn:Boolean;
                        for (var sublayer:int=10; sublayer>=0; sublayer--) {
                                if (sl.shapeStyles[sublayer]) {
@@ -213,7 +211,7 @@ package net.systemeD.halcyon {
                                        map.pois[node.id].removeSprites();
                                }
                        }
-                       if (!drawn) { return; }
+                       if (!drawn) { return false; }
                        
             // create a generic "way" hitzone sprite
             hitzone = new Sprite();
@@ -223,6 +221,7 @@ package net.systemeD.halcyon {
             hitzone.visible = false;
                        createListenSprite(hitzone);
 
+                       return true;
                }
                
                // ------------------------------------------------------------------------------------------
index 0e6ff89..de89fdc 100644 (file)
@@ -10,6 +10,8 @@ package net.systemeD.potlatch2.controller {
                private var elastic:Elastic;
                private var editEnd:Boolean;
                private var leaveNodeSelected:Boolean;
+               private var lastClick:Entity=null;
+               private var lastClickTime:Date;
                
                public function DrawWay(way:Way, editEnd:Boolean, leaveNodeSelected:Boolean) {
                        super(way);
@@ -26,16 +28,24 @@ package net.systemeD.potlatch2.controller {
                                if ( entity == null ) {
                                        node = createAndAddNode(event);
                                        resetElastic(node);
+                                       lastClick=node;
                                } else if ( entity is Node ) {
-                                       appendNode(entity as Node);
-                                       controller.map.setHighlight(focus, { showNodesHover: false });
-                                       controller.map.setHighlight(selectedWay, { showNodes: true });
-                                       resetElastic(entity as Node);
+                                       if (entity==lastClick && (new Date().getTime()-lastClickTime.getTime())<1000) {
+                                               return stopDrawing();
+                                       } else {
+                                               appendNode(entity as Node);
+                                               controller.map.setHighlight(focus, { showNodesHover: false });
+                                               controller.map.setHighlight(selectedWay, { showNodes: true });
+                                               resetElastic(entity as Node);
+                                               lastClick=entity;
+                                       }
                                } else if ( entity is Way ) {
                                        node = createAndAddNode(event);
                                        Way(entity).insertNodeAtClosestPosition(node, true);
                                        resetElastic(node);
+                                       lastClick=node;
                                }
+                               lastClickTime=new Date();
                        } else if ( event.type == MouseEvent.MOUSE_MOVE ) {
                                mouse = new Point(
                                                  controller.map.coord2lon(event.localX),
@@ -65,11 +75,20 @@ package net.systemeD.potlatch2.controller {
                }
 
                override public function processKeyboardEvent(event:KeyboardEvent):ControllerState {
-                       if ( event.keyCode == 13 || event.keyCode == 27 ) {
-                               if ( leaveNodeSelected ) 
-                                   return new SelectedWayNode(selectedWay, selectedWay.getNode(editEnd ? selectedWay.length - 1 : 0));
-                               else
-                                   return new SelectedWay(selectedWay);
+                       if ( event.keyCode == 13 || event.keyCode == 27 ) { return stopDrawing(); }
+                       return this;
+               }
+               
+               protected function stopDrawing():ControllerState {
+                       if ( selectedWay.length<2) {
+                               // ** probably needs to call a proper 'delete way' method
+                               controller.map.setHighlight(selectedWay, { showNodes: false });
+                               delete controller.map.ways[selectedWay.id];
+                               return new NoSelection();
+                       } else if ( leaveNodeSelected ) {
+                           return new SelectedWayNode(selectedWay, selectedWay.getNode(editEnd ? selectedWay.length - 1 : 0));
+                       } else {
+                           return new SelectedWay(selectedWay);
                        }
                        return this;
                }
index e2c8bca..c82c244 100644 (file)
@@ -13,12 +13,13 @@ package net.systemeD.potlatch2.controller {
                override public function processMouseEvent(event:MouseEvent, entity:Entity):ControllerState {
                        var focus:Entity = getTopLevelFocusEntity(entity);
 
-                       if ( event.type == MouseEvent.CLICK ) {
-                               if ( focus is Way ) {
+                       if ( event.type == MouseEvent.MOUSE_DOWN ) {
+                               if ( entity is Way ) {
                                        return new SelectedWay(focus as Way);
-                               } else if ( focus is Node ) {
-                                       // *** select node
-                                       Globals.vars.root.addDebug("- selected POI from NoSelection");
+                } else if ( focus is Node ) {
+                                       return new DragPOINode(entity as Node,event,false);
+                } else if ( entity is Node && focus is Way ) {
+                                       return new DragWayNode(focus as Way,entity as Node,event,false);
                                }
                        } else if (event.type==MouseEvent.MOUSE_UP && focus==null && map.dragstate!=map.DRAGGING) {
                                map.dragstate=map.NOT_DRAGGING;
index 0b3cc22..b8f4751 100644 (file)
@@ -4,8 +4,6 @@ package net.systemeD.potlatch2.controller {
     import net.systemeD.halcyon.connection.*;
        import net.systemeD.halcyon.Globals;
 
-       /* **** this is largely unfinished **** */
-
     public class SelectedPOINode extends ControllerState {
         protected var selectedNode:Node;
         protected var initNode:Node;
@@ -35,10 +33,12 @@ package net.systemeD.potlatch2.controller {
         
         override public function processMouseEvent(event:MouseEvent, entity:Entity):ControllerState {
                        if (event.type==MouseEvent.MOUSE_MOVE || event.type==MouseEvent.MOUSE_OVER || event.type==MouseEvent.MOUSE_OUT) { return this; }
+            var focus:Entity = NoSelection.getTopLevelFocusEntity(entity);
 
             if ( event.type == MouseEvent.MOUSE_UP ) {
                                if ( entity is Way ) {
-                    return new SelectedWay(Way(entity));
+                    return new SelectedWay(entity as Way);
+                               // ** do we need 'entity is Node && focus is Way' for POIs in ways?
                 } else if ( focus == null && map.dragstate!=map.DRAGGING ) {
                     return new NoSelection();
                                }
@@ -49,30 +49,16 @@ package net.systemeD.potlatch2.controller {
 //                                     d.forceDragStart();
 //                                     return d;
 //                             } else
-                               if ( entity is Node && entity.hasParent(selectedWay) ) {
-                    return new DragWayNode(selectedWay, Node(entity), event);
+                if ( focus is Node ) {
+                                       return new DragPOINode(entity as Node,event,false);
+                } else if ( entity is Node && focus is Way ) {
+                                       return new DragWayNode(focus as Way,entity as Node,event,false);
                                }
             }
 
             return this;
         }
 
-/*      public function clickOnWay(event:MouseEvent, entity:Entity):ControllerState {
-            if ( entity is Node ) {
-                if ( selectedNode == entity ) {
-                    var i:uint = selectedWay.indexOfNode(selectedNode);
-                    if ( i == 0 )
-                        return new DrawWay(selectedWay, false);
-                    else if ( i == selectedWay.length - 1 )
-                        return new DrawWay(selectedWay, true);
-                } else {
-                    selectNode(entity as Node);
-                }
-            }
-            
-            return this;
-        }
-*/      
         override public function enterState():void {
             selectNode(initNode);
                        Globals.vars.root.addDebug("**** -> "+this);
@@ -83,7 +69,7 @@ package net.systemeD.potlatch2.controller {
         }
 
         override public function toString():String {
-            return "SelectedNode";
+            return "SelectedPOINode";
         }
 
     }
index 386daf8..5a8154a 100644 (file)
@@ -18,14 +18,14 @@ package net.systemeD.potlatch2.controller {
 
             clearSelection();
             controller.setTagViewer(way);
-            controller.map.setHighlight(way, { selected: true, showNodes: true });
+            controller.map.setHighlight(way, { selected: true, showNodes: true, hover: false });
             selectedWay = way;
             initWay = way;
         }
 
         protected function clearSelection():void {
             if ( selectedWay != null ) {
-               controller.map.setHighlight(selectedWay, { selected: false, showNodes: false });
+               controller.map.setHighlight(selectedWay, { selected: false, showNodes: false, hover: false });
                 controller.setTagViewer(null);
                 selectedWay = null;
             }
@@ -43,10 +43,6 @@ package net.systemeD.potlatch2.controller {
                                } else if ( entity is Way ) {
                                        // select way
                     selectWay(entity as Way);
-                } else if ( entity is Node ) {
-                                       // *** select node
-                                       Globals.vars.root.addDebug("- selected POI from SelectedWay");
-                    trace("select poi");
                 } else if ( focus == null && map.dragstate!=map.DRAGGING ) {
                     return new NoSelection();
                                }
@@ -57,7 +53,14 @@ package net.systemeD.potlatch2.controller {
                                        d.forceDragStart();
                                        return d;
                                } else if ( entity is Node && entity.hasParent(selectedWay) ) {
+                                       // select node within this way
                     return new DragWayNode(selectedWay, Node(entity), event, false);
+                } else if ( focus is Node ) {
+                                       // select POI node
+                                       return new DragPOINode(entity as Node,event,false);
+                } else if ( entity is Node && focus is Way ) {
+                                       // select way node
+                                       return new DragWayNode(focus as Way,entity as Node,event,false);
                                }
             }
 
index 24dbe48..c21e772 100644 (file)
@@ -59,6 +59,8 @@ package net.systemeD.potlatch2.controller {
                                        return d;
                                } else if ( entity is Node && entity.hasParent(selectedWay) ) {
                     return new DragWayNode(selectedWay, Node(entity), event, false);
+                               } else if ( focus is Node ) {
+                                       return new DragPOINode(entity as Node,event,false);
                                }
             }