Add the ability to select, but not edit, a background way
authorAndy Allan <andy@gravitystorm.co.uk>
Thu, 2 Jun 2011 13:44:32 +0000 (14:44 +0100)
committerAndy Allan <andy@gravitystorm.co.uk>
Thu, 2 Jun 2011 13:44:32 +0000 (14:44 +0100)
net/systemeD/potlatch2/controller/ControllerState.as
net/systemeD/potlatch2/controller/SelectedBackgroundWay.as [new file with mode: 0644]

index d635e46..0aeddaa 100644 (file)
@@ -7,6 +7,7 @@ package net.systemeD.potlatch2.controller {
     import net.systemeD.potlatch2.collections.Imagery;
     import net.systemeD.potlatch2.EditController;
        import net.systemeD.potlatch2.save.SaveManager;
+       import net.systemeD.potlatch2.utils.SnapshotConnection;
        import flash.ui.Keyboard;
        import mx.controls.Alert;
        import mx.events.CloseEvent;
@@ -93,7 +94,10 @@ package net.systemeD.potlatch2.controller {
             var focus:Entity = getTopLevelFocusEntity(entity);
 
                        if ( paint && paint.isBackground ) {
-                               if ( event.type == MouseEvent.MOUSE_DOWN && ((event.shiftKey && event.ctrlKey) || event.altKey) ) {
+                if ( event.type == MouseEvent.MOUSE_DOWN && entity.connection is SnapshotConnection) {
+                    if (entity is Way) { return new SelectedBackgroundWay(entity as Way); }
+                    else if (entity is Node) { return new SelectedPOINode(entity as Node); }
+                } else if ( event.type == MouseEvent.MOUSE_DOWN && ((event.shiftKey && event.ctrlKey) || event.altKey) ) {
                                        // alt-click to pull data out of vector background layer
                                        var newEntity:Entity=paint.pullThrough(entity,editableLayer);
                                        if (entity is Way) { return new SelectedWay(newEntity as Way); }
diff --git a/net/systemeD/potlatch2/controller/SelectedBackgroundWay.as b/net/systemeD/potlatch2/controller/SelectedBackgroundWay.as
new file mode 100644 (file)
index 0000000..934010c
--- /dev/null
@@ -0,0 +1,86 @@
+package net.systemeD.potlatch2.controller {
+       import flash.events.*;
+       import flash.geom.Point;
+       import flash.ui.Keyboard;
+       
+       import net.systemeD.halcyon.WayUI;
+       import net.systemeD.halcyon.connection.*;
+       import net.systemeD.potlatch2.tools.Quadrilateralise;
+       import net.systemeD.potlatch2.tools.Simplify;
+
+    /** Behaviour that takes place while a way is selected includes: adding a node to the way, straightening/reshaping the way, dragging it. */
+    public class SelectedBackgroundWay extends ControllerState {
+        /** The selected way itself. */
+        protected var initWay:Way;
+        private var clicked:Point;             // did the user enter this state by clicking at a particular point?
+               private var wayList:Array;              // list of ways to cycle through with '/' keypress
+               private var initIndex: int;     // index of last selected node if entered from SelectedWayNode
+        
+        /** 
+        * @param way The way that is now selected.
+        * @param point The location that was clicked.
+        * @param ways An ordered list of ways sharing a node, to make "way cycling" work. */
+        public function SelectedBackgroundWay(way:Way, point:Point=null, ways:Array=null, index:int=0) {
+            initWay = way;
+                       clicked = point;
+                       wayList = ways;
+                       initIndex=index;
+        }
+
+        private function updateSelectionUI(e:Event):void {
+            controller.updateSelectionUIWithoutTagChange();
+        }
+
+        /** Tidy up UI as we transition to a new state without the current selection. */
+        protected function clearSelection(newState:ControllerState):void {
+            if ( selectCount ) {
+               editableLayer.setHighlight(firstSelected, { selected: false, hover: false });
+               editableLayer.setHighlightOnNodes(firstSelected as Way, { selectedway: false });
+                selection = [];
+                if (!newState.isSelectionState()) { controller.updateSelectionUI(); }
+            }
+        }
+        
+        /** The only things we want to do here are deselect and stay selected */
+        override public function processMouseEvent(event:MouseEvent, entity:Entity):ControllerState {
+            if (event.type==MouseEvent.MOUSE_MOVE) { return this; }
+            if (event.type==MouseEvent.MOUSE_UP) { return this; }
+            var cs:ControllerState = sharedMouseEvents(event, entity);
+            return cs ? cs : this;
+        }
+        
+               /** TODO - key press for "completing" a way */
+               override public function processKeyboardEvent(event:KeyboardEvent):ControllerState {
+                       switch (event.keyCode) {
+
+
+            }
+                       var cs:ControllerState = sharedKeyboardEvents(event);
+                       return cs ? cs : this;
+               }
+
+        /** Officially enter this state by marking the previously nominated way as selected. */
+        override public function enterState():void {
+            if (firstSelected!=initWay) {
+                clearSelection(this);
+                editableLayer.setHighlight(initWay, { selected: true, hover: false });
+                   editableLayer.setHighlightOnNodes(initWay, { selectedway: true });
+                   selection = [initWay];
+                   controller.updateSelectionUI();
+                       }
+                       editableLayer.setPurgable(selection,false);
+        }
+        
+        /** Officially leave the state */
+        override public function exitState(newState:ControllerState):void {
+            editableLayer.setPurgable(selection,true);
+            clearSelection(newState);
+        }
+
+        /** @return "SelectedWay" */
+        override public function toString():String {
+            return "SelectedBackgroundWay";
+        }
+
+    }
+}