don't bother redrawing EntityUIs that are offscreen
[potlatch2.git] / net / systemeD / potlatch2 / controller / SelectedParallelWay.as
1 package net.systemeD.potlatch2.controller {
2         import flash.events.*;
3         import flash.display.Stage;
4     import net.systemeD.halcyon.connection.*;
5     import net.systemeD.halcyon.Map;
6         import net.systemeD.potlatch2.tools.Parallelise;
7         import net.systemeD.halcyon.Globals;
8
9     public class SelectedParallelWay extends SelectedWay {
10                 private var startlon:Number;
11                 private var startlatp:Number;
12                 private var parallelise:Parallelise;
13
14         public function SelectedParallelWay(originalWay:Way) {
15                         parallelise = new Parallelise(originalWay);
16                         selectedWay=parallelise.parallelWay;
17                         super (selectedWay);
18         }
19
20         override public function processMouseEvent(event:MouseEvent, entity:Entity):ControllerState {
21                         if (event.type==MouseEvent.MOUSE_MOVE) {
22                                 var lon:Number =controller.map.coord2lon(controller.map.mouseX);
23                                 var latp:Number=controller.map.coord2latp(controller.map.mouseY);
24                                 var offset:Number=Math.sqrt(Math.pow(lon-startlon,2)+
25                                                             Math.pow(latp-startlatp,2));
26                                 if (lon<startlon) { offset=-offset; }   // ** this should be smarter than just lon<startlon
27                                 parallelise.draw(offset);
28                         } else if (event.type==MouseEvent.MOUSE_UP) {
29                                 return new SelectedWay(selectedWay);
30                         }
31                         return this;
32         }
33
34                 private function sgn(a:Number):Number {
35                         if (a==0) return 0;
36                         if (a<0) return -1;
37                         return 1;
38                 }
39
40                 override public function enterState():void {
41                         controller.map.paint.createWayUI(selectedWay);
42                         startlon =controller.map.coord2lon(controller.map.mouseX);
43                         startlatp=controller.map.coord2latp(controller.map.mouseY);
44                         Globals.vars.root.addDebug("**** -> "+this);
45         }
46                 override public function exitState():void {
47             clearSelection();
48                         Globals.vars.root.addDebug("**** <- "+this);
49         }
50
51         override public function toString():String {
52             return "SelectedParallelWay";
53         }
54     }
55 }