Commenting for ASDoc
[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         import net.systemeD.halcyon.Globals;
7
8     /** The state of realigning the background imagery by holding down a key and moving the mouse. This moves the background, but 
9     * doesn't move the map, thereby adjusting the offset between the background and the map. */
10     public class DragBackground extends ControllerState {
11
12         private var downX:Number;
13         private var downY:Number;
14         
15         /** Start the drag by recording the location of the mouse. */
16         public function DragBackground(event:MouseEvent) {
17             downX = event.localX;
18             downY = event.localY;
19         }
20  
21        /** Respond to dragging and end drag. */
22        override public function processMouseEvent(event:MouseEvent, entity:Entity):ControllerState {
23
24             if (event.type==MouseEvent.MOUSE_UP) {
25                 return previousState;
26
27                         } else if ( event.type == MouseEvent.MOUSE_MOVE) {
28                                 // dragging
29                                 controller.map.nudgeBackground(event.localX-downX, event.localY-downY);
30                     downX = event.localX;
31                     downY = event.localY;
32                                 return this;
33
34                         } else {
35                                 // event not handled
36                 return this;
37                         }
38         }
39
40         /** Prevent map panning while background is being dragged. */
41         override public function enterState():void {
42                         controller.map.draggable=false;
43                         Globals.vars.root.addDebug("**** -> "+this);
44         }
45         
46         /** Re-allow map panning. */
47         override public function exitState(newState:ControllerState):void {
48                         controller.map.draggable=true;
49                         Globals.vars.root.addDebug("**** <- "+this);
50         }
51         
52         /** "DragBackground" */
53         override public function toString():String {
54             return "DragBackground";
55         }
56     }
57 }