beginning of vector background layers. And a whole load of other stuff too
[potlatch2.git] / net / systemeD / halcyon / MapPaint.as
1 package net.systemeD.halcyon {
2
3         import flash.display.Sprite;
4         import flash.display.DisplayObject;
5         import net.systemeD.halcyon.NodeUI;
6         import net.systemeD.halcyon.WayUI;
7         import net.systemeD.halcyon.connection.Node;
8         import net.systemeD.halcyon.connection.Way;
9         import net.systemeD.halcyon.styleparser.RuleSet;
10         import net.systemeD.halcyon.Globals;
11
12     public class MapPaint extends Sprite {
13
14                 public var map:Map;
15                 public var minlayer:int;
16                 public var maxlayer:int;
17                 public var ruleset:RuleSet;                                             // rules
18                 public var wayuis:Object=new Object();                  // sprites for ways and (POI/tagged) nodes
19                 public var nodeuis:Object=new Object();                 //  |
20
21                 // Set up layering
22                 // [layer][3]                   - names
23                 // [layer][2][sublayer] - stroke
24                 // [layer][1]                   - casing
25                 // [layer][0]                   - fill
26
27                 public function MapPaint(map:Map,minlayer:int,maxlayer:int) {
28                         this.map=map;
29                         this.minlayer=minlayer;
30                         this.maxlayer=maxlayer;
31
32                         for (var l:int=minlayer; l<=maxlayer; l++) {    // each layer (10 is +5, 0 is -5)
33                                 var s:Sprite = getHitSprite();                  //  |
34                                 s.addChild(getPaintSprite());                           //      | 0 fill
35                                 s.addChild(getPaintSprite());                           //      | 1 casing
36                                 var t:Sprite = getPaintSprite();                        //  | 2 stroke
37                                 for (var j:int=0; j<11; j++) {                          //      |  | ten sublayers
38                                         t.addChild(getPaintSprite());                   //  |  |  |
39                                 }                                                                                       //  |  |  |
40                                 s.addChild(t);                                                          //  |  |
41                                 s.addChild(getPaintSprite());                           //      | 3 names
42                                 s.addChild(getPaintSprite());                           //      | 4 nodes
43                                 s.addChild(getHitSprite());                                 //  | 5 entity hit tests
44                                 addChild(s);                                                            //  |
45                         }
46                         addChild(getPaintSprite());                                     // name sprite
47                 }
48                 
49                 public function get ready():Boolean {
50                         if (!ruleset) { return false; }
51                         if (!ruleset.loaded) { return false; }
52                         return true;
53                 }
54
55 /*              public function addToLayer(s:DisplayObject, layer:int, t:uint, sublayer:int=-1) {
56                         var l:DisplayObject=getChildAt(layer-minlayer);
57                         var o:DisplayObject=Sprite(l).getChildAt(t);
58                         if (sublayer!=-1) { o=Sprite(o).getChildAt(sublayer); }
59                         Sprite(o).addChild(s);
60                         sprites.push(s);
61             if ( s is Sprite ) {
62                 Sprite(s).mouseEnabled = false;
63                 Sprite(s).mouseChildren = false;
64             }
65                 }
66 */
67
68                 public function createWayUI(way:Way):WayUI {
69                         wayuis[way.id]=new WayUI(way,this,false);
70                         return wayuis[way.id];
71                 }
72
73                 public function createNodeUI(node:Node):NodeUI {
74                         nodeuis[node.id]=new NodeUI(node,this,0,false);
75                         return nodeuis[node.id];
76                 }
77
78                 public function deleteWayUI(way:Way):void {
79                         wayuis[way.id].removeSprites();
80                         delete wayuis[way.id];
81                 }
82
83                 public function deleteNodeUI(node:Node):void {
84                         nodeuis[node.id].removeSprites();
85                         delete nodeuis[node.id];
86                 }
87
88         private function getPaintSprite():Sprite {
89             var s:Sprite = new Sprite();
90             s.mouseEnabled = false;
91             s.mouseChildren = false;
92             return s;
93         }
94
95         private function getHitSprite():Sprite {
96             var s:Sprite = new Sprite();
97             return s;
98         }
99
100                 public function redraw():void {
101                         for each (var w:WayUI in wayuis) { w.recalculate(); w.redraw(); }
102                         for each (var p:NodeUI in nodeuis) { p.redraw(); }
103                 }
104
105                 public function redrawPOIs():void {
106                         for each (var p:NodeUI in nodeuis) { p.redraw(); }
107                 }
108
109         }
110 }