Merge branch 'master' of github.com:systemed/potlatch2
[potlatch2.git] / net / systemeD / potlatch2 / controller / DragBackground.as
1 package net.systemeD.potlatch2.controller {
2         import flash.events.*;
3     import net.systemeD.potlatch2.EditController;
4     import net.systemeD.halcyon.connection.*;
5     import net.systemeD.halcyon.MapEvent;
6
7     /** The state of realigning the background imagery by holding down a key and moving the mouse. This moves the background, but 
8     * doesn't move the map, thereby adjusting the offset between the background and the map. */
9     public class DragBackground extends ControllerState {
10
11         private var downX:Number;
12         private var downY:Number;
13         protected var previousState:ControllerState;
14         
15         /** Start the drag by recording the location of the mouse. */
16         public function DragBackground(event:MouseEvent, previousState:ControllerState) {
17             downX = event.localX;
18             downY = event.localY;
19             this.previousState = previousState;
20         }
21  
22        /** Respond to dragging and end drag. */
23        override public function processMouseEvent(event:MouseEvent, entity:Entity):ControllerState {
24
25             if (event.type==MouseEvent.MOUSE_UP) {
26                 return previousState;
27
28                         } else if ( event.type == MouseEvent.MOUSE_MOVE) {
29                                 // dragging
30                                 controller.map.nudgeBackground(event.localX-downX, event.localY-downY);
31                     downX = event.localX;
32                     downY = event.localY;
33                                 return this;
34
35                         } else {
36                                 // event not handled
37                 return this;
38                         }
39         }
40
41         /** Prevent map panning while background is being dragged. */
42         override public function enterState():void {
43                         controller.map.draggable=false;
44         }
45         
46         /** Re-allow map panning. */
47         override public function exitState(newState:ControllerState):void {
48                         controller.map.draggable=true;
49         }
50         
51         /** "DragBackground" */
52         override public function toString():String {
53             return "DragBackground";
54         }
55     }
56 }