Unify selection ControllerStates so they can work on either background or editable...
[potlatch2.git] / net / systemeD / potlatch2 / controller / SelectedPOINode.as
index 2e6af17cf2af889a06bb193a23fc3b8679723f40..b3279501b6e09cf4ac9a99cd131e766c81f02218 100644 (file)
@@ -1,13 +1,16 @@
 package net.systemeD.potlatch2.controller {
        import flash.events.*;
+       import flash.display.*;
        import flash.ui.Keyboard;
     import net.systemeD.potlatch2.EditController;
     import net.systemeD.halcyon.connection.*;
+    import net.systemeD.halcyon.MapPaint;
 
     public class SelectedPOINode extends ControllerState {
         protected var initNode:Node;
 
-        public function SelectedPOINode(node:Node) {
+        public function SelectedPOINode(node:Node, layer:MapPaint=null) {
+                       if (layer) this.layer=layer;
             initNode = node;
         }
  
@@ -32,11 +35,14 @@ package net.systemeD.potlatch2.controller {
         
         override public function processMouseEvent(event:MouseEvent, entity:Entity):ControllerState {
                        if (event.type==MouseEvent.MOUSE_MOVE) { return this; }
-                       if (event.type==MouseEvent.MOUSE_DOWN && event.ctrlKey && entity && entity!=firstSelected) {
-                               return new SelectedMultiple([firstSelected,entity]);
-                       }
-                       if (event.type==MouseEvent.MOUSE_DOWN && event.shiftKey && !entity) {
+                       var paint:MapPaint = getMapPaint(DisplayObject(event.target));
+
+                       if (event.type==MouseEvent.MOUSE_DOWN && event.ctrlKey && entity && entity!=firstSelected && paint==layer) {
+                               return new SelectedMultiple([firstSelected,entity],layer);
+                       } else if (event.type==MouseEvent.MOUSE_DOWN && event.shiftKey && !entity && !layer.isBackground) {
                                return new DrawQuadrilateral(firstSelected as Node);
+                       } else if ( event.type == MouseEvent.MOUSE_UP && entity==firstSelected ) {
+                               return this;
                        }
                        var cs:ControllerState = sharedMouseEvents(event, entity);
                        return cs ? cs : this;