1 package net.systemeD.potlatch2.controller {
3 import flash.geom.Point;
4 import flash.ui.Keyboard;
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;
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
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) {
30 private function updateSelectionUI(e:Event):void {
31 controller.updateSelectionUIWithoutTagChange();
34 /** Tidy up UI as we transition to a new state without the current selection. */
35 protected function clearSelection(newState:ControllerState):void {
37 editableLayer.setHighlight(firstSelected, { selected: false, hover: false });
38 editableLayer.setHighlightOnNodes(firstSelected as Way, { selectedway: false });
40 if (!newState.isSelectionState()) { controller.updateSelectionUI(); }
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;
52 /** TODO - key press for "completing" a way */
53 override public function processKeyboardEvent(event:KeyboardEvent):ControllerState {
54 switch (event.keyCode) {
58 var cs:ControllerState = sharedKeyboardEvents(event);
59 return cs ? cs : this;
62 /** Officially enter this state by marking the previously nominated way as selected. */
63 override public function enterState():void {
64 if (firstSelected!=initWay) {
66 editableLayer.setHighlight(initWay, { selected: true, hover: false });
67 editableLayer.setHighlightOnNodes(initWay, { selectedway: true });
68 selection = [initWay];
69 controller.updateSelectionUI();
71 editableLayer.setPurgable(selection,false);
74 /** Officially leave the state */
75 override public function exitState(newState:ControllerState):void {
76 editableLayer.setPurgable(selection,true);
77 clearSelection(newState);
80 /** @return "SelectedWay" */
81 override public function toString():String {
82 return "SelectedBackgroundWay";