934010c4a203f4209b6208af5f94a9cfb53f1fe1
[potlatch2.git] / net / systemeD / potlatch2 / controller / SelectedBackgroundWay.as
1 package net.systemeD.potlatch2.controller {
2         import flash.events.*;
3         import flash.geom.Point;
4         import flash.ui.Keyboard;
5         
6         import net.systemeD.halcyon.WayUI;
7         import net.systemeD.halcyon.connection.*;
8         import net.systemeD.potlatch2.tools.Quadrilateralise;
9         import net.systemeD.potlatch2.tools.Simplify;
10
11     /** Behaviour that takes place while a way is selected includes: adding a node to the way, straightening/reshaping the way, dragging it. */
12     public class SelectedBackgroundWay extends ControllerState {
13         /** The selected way itself. */
14         protected var initWay:Way;
15         private var clicked:Point;              // did the user enter this state by clicking at a particular point?
16                 private var wayList:Array;              // list of ways to cycle through with '/' keypress
17                 private var initIndex: int;     // index of last selected node if entered from SelectedWayNode
18         
19         /** 
20         * @param way The way that is now selected.
21         * @param point The location that was clicked.
22         * @param ways An ordered list of ways sharing a node, to make "way cycling" work. */
23         public function SelectedBackgroundWay(way:Way, point:Point=null, ways:Array=null, index:int=0) {
24             initWay = way;
25                         clicked = point;
26                         wayList = ways;
27                         initIndex=index;
28         }
29
30         private function updateSelectionUI(e:Event):void {
31             controller.updateSelectionUIWithoutTagChange();
32         }
33
34         /** Tidy up UI as we transition to a new state without the current selection. */
35         protected function clearSelection(newState:ControllerState):void {
36             if ( selectCount ) {
37                 editableLayer.setHighlight(firstSelected, { selected: false, hover: false });
38                 editableLayer.setHighlightOnNodes(firstSelected as Way, { selectedway: false });
39                 selection = [];
40                 if (!newState.isSelectionState()) { controller.updateSelectionUI(); }
41             }
42         }
43         
44         /** The only things we want to do here are deselect and stay selected */
45         override public function processMouseEvent(event:MouseEvent, entity:Entity):ControllerState {
46             if (event.type==MouseEvent.MOUSE_MOVE) { return this; }
47             if (event.type==MouseEvent.MOUSE_UP) { return this; }
48             var cs:ControllerState = sharedMouseEvents(event, entity);
49             return cs ? cs : this;
50         }
51         
52                 /** TODO - key press for "completing" a way */
53                 override public function processKeyboardEvent(event:KeyboardEvent):ControllerState {
54                         switch (event.keyCode) {
55
56
57             }
58                         var cs:ControllerState = sharedKeyboardEvents(event);
59                         return cs ? cs : this;
60                 }
61
62         /** Officially enter this state by marking the previously nominated way as selected. */
63         override public function enterState():void {
64             if (firstSelected!=initWay) {
65                 clearSelection(this);
66                 editableLayer.setHighlight(initWay, { selected: true, hover: false });
67                     editableLayer.setHighlightOnNodes(initWay, { selectedway: true });
68                     selection = [initWay];
69                     controller.updateSelectionUI();
70                         }
71                         editableLayer.setPurgable(selection,false);
72         }
73         
74         /** Officially leave the state */
75         override public function exitState(newState:ControllerState):void {
76             editableLayer.setPurgable(selection,true);
77             clearSelection(newState);
78         }
79
80         /** @return "SelectedWay" */
81         override public function toString():String {
82             return "SelectedBackgroundWay";
83         }
84
85     }
86 }