highlight nodes in mouseover
authorRichard Fairhurst <richard@systemed.net>
Sun, 29 Nov 2009 20:34:07 +0000 (20:34 +0000)
committerRichard Fairhurst <richard@systemed.net>
Sun, 29 Nov 2009 20:34:07 +0000 (20:34 +0000)
net/systemeD/halcyon/Elastic.as
net/systemeD/halcyon/WayUI.as
net/systemeD/potlatch2/controller/CreateWay.as [deleted file]
net/systemeD/potlatch2/controller/DragWayNode.as
net/systemeD/potlatch2/controller/DrawWay.as
net/systemeD/potlatch2/controller/NoSelection.as
net/systemeD/potlatch2/controller/SelectedWay.as
net/systemeD/potlatch2/controller/SelectedWayNode.as

index 134ea6dd76c75c5d94c5612cf932eedaf15c2a07..bfaa05769221973f60ddc56edddc2669deb46b9b 100755 (executable)
@@ -63,30 +63,11 @@ package net.systemeD.halcyon {
             stroke.graphics.lineStyle(1, 0xff0000, 1, false, "normal", CapsStyle.ROUND, JointStyle.ROUND);
                        addToLayer(stroke,3);
                        dashedLine(stroke.graphics, [2,2]);
-                       
-                       var nodes:Sprite = new Sprite();
-            drawNodes(nodes.graphics);
-            addToLayer(nodes, 3);
-
                }
                
                // ------------------------------------------------------------------------------------------
                // Drawing support functions
 
-               private function drawNodes(g:Graphics):void {
-            g.lineStyle(1, 0xff0000, 1, false, "normal", CapsStyle.ROUND, JointStyle.ROUND);
-                       for (var i:uint = 0; i < 1; i++) {
-                var p:Point = i == 0 ? start : end;
-                var x:Number = map.lon2coord(p.x);
-                var y:Number = map.latp2coord(p.y);
-                g.moveTo(x-2, y-2);
-                g.lineTo(x+2, y-2);
-                g.lineTo(x+2, y+2);
-                g.lineTo(x-2, y+2);
-                g.lineTo(x-2, y-2);
-                       }
-               }
-
                // Draw dashed polyline
                
                private function dashedLine(g:Graphics,dashes:Array):void {
index e27a7c5e70e92c1d0dca61b1e8836f6338b52813..1c35f058c7fe9b647a9185ad4954ef8cbfa6424e 100755 (executable)
@@ -193,14 +193,14 @@ package net.systemeD.halcyon {
                        //    running getStyles for every node in the way on every redraw
                        var r:Number;
                        var nodetags:Object;
-                       var highlight:Boolean=stateClasses["showNodes"]; // !=null
                        var nodeSelected:int=stateClasses["nodeSelected"];
                        for (var i:uint = 0; i < way.length; i++) {
                 var node:Node = way.getNode(i);
                                nodetags=node.getTagsCopy();
                                if (i==0) { nodetags['_heading']= heading[i]; }
                                     else { nodetags['_heading']=(heading[i]+heading[i-1])/2; }
-                               if (highlight) { nodetags[':selectedway']='yes'; }
+                               if (stateClasses["showNodes"]) { nodetags[':selectedway']='yes'; }
+                               if (stateClasses["showNodesHover"]) { nodetags[':hoverway']='yes'; }
                                if (node.id==nodeSelected) { nodetags[':selected']='yes'; }
                                sl=map.ruleset.getStyles(node,nodetags);
                                if (sl.hasStyles()) {
@@ -228,22 +228,6 @@ package net.systemeD.halcyon {
                // ------------------------------------------------------------------------------------------
                // Drawing support functions
 
-               private function drawNodes(g:Graphics):void {
-// ***** these should be discreet anchorpoints (NodeUI?), not just sprites
-//          g.lineStyle(1, 0xff0000, 1, false, "normal", CapsStyle.ROUND, JointStyle.ROUND);
-                       g.beginFill(0xFF0000);
-                       for (var i:uint = 0; i < way.length; i++) {
-                var node:Node = way.getNode(i);
-                var x:Number = map.lon2coord(node.lon);
-                var y:Number = map.latp2coord(node.latp);
-                g.moveTo(x-NODESIZE, y-NODESIZE);
-                g.lineTo(x+NODESIZE, y-NODESIZE);
-                g.lineTo(x+NODESIZE, y+NODESIZE);
-                g.lineTo(x-NODESIZE, y+NODESIZE);
-                g.lineTo(x-NODESIZE, y-NODESIZE);
-                       }
-               }
-
                // Draw solid polyline
                
                public function solidLine(g:Graphics):void {
@@ -401,11 +385,7 @@ package net.systemeD.halcyon {
                }
 
         override protected function mouseEvent(event:MouseEvent):void {
-//            var node:Node = getNodeAt(event.localX, event.localY);
-//            if ( node == null )
-                map.entityMouseEvent(event, way);
-//            else
-//                map.entityMouseEvent(event, node);
+                       map.entityMouseEvent(event, way);
         }
 
        }
diff --git a/net/systemeD/potlatch2/controller/CreateWay.as b/net/systemeD/potlatch2/controller/CreateWay.as
deleted file mode 100644 (file)
index d8878bb..0000000
+++ /dev/null
@@ -1,71 +0,0 @@
-package net.systemeD.potlatch2.controller {
-       import flash.events.*;
-       import flash.geom.*;
-    import net.systemeD.potlatch2.EditController;
-    import net.systemeD.halcyon.connection.*;
-    import net.systemeD.halcyon.Elastic;
-       import net.systemeD.halcyon.Globals;
-
-    public class CreateWay extends ControllerState {
-        private var start:Point;
-        private var mouse:Point;
-        private var elastic:Elastic;
-        
-        public function CreateWay(event:MouseEvent) {
-            start = new Point(event.localX, event.localY);
-            mouse = new Point(event.localX, event.localY);
-        }
-        
-        override public function processMouseEvent(event:MouseEvent, entity:Entity):ControllerState {
-            var focus:Entity = NoSelection.getTopLevelFocusEntity(entity);
-            if ( event.type == MouseEvent.MOUSE_UP ) {
-                if ( focus == null ) {
-                    var lat:Number = controller.map.coord2lat(event.localY);
-                    var lon:Number = controller.map.coord2lon(event.localX);
-                    var endNode:Node = controller.connection.createNode({}, lat, lon);
-                    
-                    lat = Node.latp2lat(start.y);
-                    lon = start.x;
-                    var startNode:Node = controller.connection.createNode({}, lat, lon);
-                    
-                    var way:Way = controller.connection.createWay({}, [startNode, endNode]);
-                    return new DrawWay(way, true);
-                }
-            } else if ( event.type == MouseEvent.MOUSE_MOVE ) {
-                mouse = new Point(
-                          controller.map.coord2lon(event.localX),
-                          controller.map.coord2latp(event.localY));
-                elastic.end = mouse;
-            }
-
-            return this;
-        }
-
-        override public function processKeyboardEvent(event:KeyboardEvent):ControllerState {
-            if ( event.keyCode == 27 )
-                return new NoSelection();
-            return this;
-        }
-
-        override public function enterState():void {
-            // transform points
-            start.x = controller.map.coord2lon(start.x);
-            start.y = controller.map.coord2latp(start.y);
-            mouse.x = controller.map.coord2lon(mouse.x);
-            mouse.y = controller.map.coord2latp(mouse.y);
-            
-            elastic = new Elastic(controller.map, start, mouse);
-                       Globals.vars.root.addDebug("**** -> "+this);
-        }
-        
-        override public function exitState():void {
-            elastic.removeSprites();
-            elastic = null;
-                       Globals.vars.root.addDebug("**** <- "+this);
-        }
-
-        override public function toString():String {
-            return "CreateWay";
-        }
-    }
-}
index abf22e8e076a4ad24dac7ab0db007024c68b6624..30387b8e0e41677d1c5b65e9d69fe713da4c0049 100644 (file)
@@ -34,7 +34,7 @@ package net.systemeD.potlatch2.controller {
 //                     return endDrag();
                                } else if (event.shiftKey && !isNew) {
                                        // start new way
-                                       var way:Way = controller.connection.createWay({}, [entity, entity]);
+                                       var way:Way = controller.connection.createWay({}, [entity]);
                                        return new DrawWay(way, true);
                                } else if (event.shiftKey && isNew) {
                        return new SelectedWayNode(selectedWay,draggingNode);
index 9932cfb3f286c1c15f21e556c8b418b2b8db2d8c..6026d099644b83396693bc6bd5923ef4f94f7240 100644 (file)
@@ -18,6 +18,7 @@ package net.systemeD.potlatch2.controller {
                override public function processMouseEvent(event:MouseEvent, entity:Entity):ControllerState {
                        var mouse:Point;
                        var node:Node;
+                       var focus:Entity = NoSelection.getTopLevelFocusEntity(entity);
 
                        if ( event.type == MouseEvent.MOUSE_UP ) {
                                if ( entity == null ) {
@@ -25,6 +26,8 @@ package net.systemeD.potlatch2.controller {
                                        resetElastic(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);
                                } else if ( entity is Way ) {
                                        node = createAndAddNode(event);
@@ -36,6 +39,18 @@ package net.systemeD.potlatch2.controller {
                                                  controller.map.coord2lon(event.localX),
                                                  controller.map.coord2latp(event.localY));
                                elastic.end = mouse;
+                       } else if ( event.type == MouseEvent.MOUSE_OVER && focus!=selectedWay) {
+                               controller.map.setHighlight(focus, { showNodesHover: true });
+                       } else if ( event.type == MouseEvent.MOUSE_OUT  && focus!=selectedWay) {
+                               controller.map.setHighlight(focus, { showNodesHover: false });
+                               controller.map.setHighlight(selectedWay, { showNodes: true });
+                               // ** this call to setHighlight(selectedWay) is necessary in case the hovered way (blue nodes)
+                               // shares any nodes with the selected way (red nodes): if they do, they'll be wiped out by the
+                               // first call.
+                               // Ultimately we should fix this by referring to 'way :selected nodes' instead of 'nodes :selectedway'.
+                               // But this will do for now.
+                               // We could do with an optional way of calling WayUI.redraw to only do the nodes, which would be a
+                               // useful optimisation.
                        }
 
                        return this;
index b10e4920568ce8fa7a59c333094b0ad367821b47..d55103b8fcfe7b8589102025dc78566e0213cff5 100644 (file)
@@ -18,11 +18,16 @@ package net.systemeD.potlatch2.controller {
                                        return new SelectedWay(focus as Way);
                                } else if ( focus is Node ) {
                                        // *** select node
-                                       Globals.vars.root.addDebug("- selected POI");
+                                       Globals.vars.root.addDebug("- selected POI from NoSelection");
                                }
                        } else if (event.type==MouseEvent.MOUSE_UP && focus==null && map.dragstate!=map.DRAGGING) {
                                map.dragstate=map.NOT_DRAGGING;
-                               return new CreateWay(event);
+                               var startNode:Node = controller.connection.createNode(
+                                       {}, 
+                                       controller.map.coord2lat(event.localY),
+                                       controller.map.coord2lon(event.localX));
+                               var way:Way = controller.connection.createWay({}, [startNode]);
+                               return new DrawWay(way, true);
                        } else if ( event.type == MouseEvent.MOUSE_OVER ) {
                                controller.map.setHighlight(focus, { hover: true });
                        } else if ( event.type == MouseEvent.MOUSE_OUT ) {
index aeb0fb0db4f51d1cdb39213edbd353afe20c842d..cd533231e053e4f9f50fadb504ef6f424c1bc6fd 100644 (file)
@@ -38,14 +38,14 @@ package net.systemeD.potlatch2.controller {
             if ( event.type == MouseEvent.MOUSE_UP ) {
                                if ( entity is Node && event.shiftKey ) {
                                        // start new way
-                    var way:Way = controller.connection.createWay({}, [entity, entity]);
+                    var way:Way = controller.connection.createWay({}, [entity]);
                     return new DrawWay(way, true);
                                } else if ( entity is Way ) {
                                        // select way
                     selectWay(entity as Way);
                 } else if ( entity is Node ) {
                                        // *** select node
-                                       Globals.vars.root.addDebug("- selected POI");
+                                       Globals.vars.root.addDebug("- selected POI from SelectedWay");
                     trace("select poi");
                 } else if ( focus == null && map.dragstate!=map.DRAGGING ) {
                     return new NoSelection();
index 17be1e8ef4ef359736839c818853700fc7d3c1a7..114c913be52b359bc262f1b9e1e4c353cfe50527 100644 (file)
@@ -40,14 +40,14 @@ package net.systemeD.potlatch2.controller {
             if ( event.type == MouseEvent.MOUSE_UP ) {
                                if ( entity is Node && event.shiftKey ) {
                                        // start new way
-                    var way:Way = controller.connection.createWay({}, [entity, entity]);
+                    var way:Way = controller.connection.createWay({}, [entity]);
                     return new DrawWay(way, true);
                                } else if ( entity is Node ) {
                                        // select node within way
                                        return new SelectedWayNode(selectedWay,Node(entity));
                 } else if ( entity is Way ) {
                                        // select way
-                                       return new SelectedWay(selectedWay);
+                                       return new SelectedWay(Way(entity));
                 } else if ( focus == null && map.dragstate!=map.DRAGGING ) {
                     return new NoSelection();
                                }