width can be defined based on maximum width so far
[potlatch2.git] / net / systemeD / halcyon / EntityUI.as
1 package net.systemeD.halcyon {
2
3         import flash.display.*;
4         import flash.events.MouseEvent;
5         import flash.text.AntiAliasType;
6         import flash.text.GridFitType;
7         import net.systemeD.halcyon.Globals;
8         import net.systemeD.halcyon.styleparser.StyleList;
9
10         public class EntityUI {
11
12                 protected var sprites:Array=new Array();                // instances in display list
13         protected var listenSprite:Sprite;                              // clickable sprite to receive events
14                 protected var stateClasses:Object=new Object(); // special context-sensitive classes, e.g. :hover
15                 protected var layer:int=0;                                              // map layer
16                 public var map:Map;                                                             // reference to parent map
17
18                 protected const FILLSPRITE:uint=0;
19                 protected const CASINGSPRITE:uint=1;
20                 protected const STROKESPRITE:uint=2;
21                 protected const NAMESPRITE:uint=3;
22                 protected const NODESPRITE:uint=4;
23                 protected const CLICKSPRITE:uint=5;
24
25                 public static const DEFAULT_TEXTFIELD_PARAMS:Object = {
26                         embedFonts: true,
27                         antiAliasType: AntiAliasType.ADVANCED,
28                         gridFitType: GridFitType.NONE
29                 };
30
31                 public function EntityUI() {
32                 }
33
34                 // Add object (stroke/fill/roadname) to layer sprite
35                 
36                 protected function addToLayer(s:DisplayObject,t:uint,sublayer:int=-1):void {
37                         var l:DisplayObject=Map(map).getChildAt(map.WAYSPRITE+layer);
38                         var o:DisplayObject=Sprite(l).getChildAt(t);
39                         if (sublayer!=-1) { o=Sprite(o).getChildAt(sublayer); }
40                         Sprite(o).addChild(s);
41                         sprites.push(s);
42             if ( s is Sprite ) {
43                 Sprite(s).mouseEnabled = false;
44                 Sprite(s).mouseChildren = false;
45             }
46                 }
47                 
48                 public function removeSprites():void {
49                         while (sprites.length>0) {
50                                 var d:DisplayObject=sprites.pop();
51                                 if (d.parent) { d.parent.removeChild(d); }
52                         }
53                         listenSprite=null;
54                 }
55
56                 protected function createListenSprite(hitzone:Sprite):void {
57             if ( listenSprite == null ) {
58                 listenSprite = new Sprite();
59                 listenSprite.addEventListener(MouseEvent.CLICK, mouseEvent);
60                 listenSprite.addEventListener(MouseEvent.DOUBLE_CLICK, mouseEvent);
61                 listenSprite.addEventListener(MouseEvent.MOUSE_OVER, mouseEvent);
62                 listenSprite.addEventListener(MouseEvent.MOUSE_OUT, mouseEvent);
63                 listenSprite.addEventListener(MouseEvent.MOUSE_DOWN, mouseEvent);
64                 listenSprite.addEventListener(MouseEvent.MOUSE_UP, mouseEvent);
65                 listenSprite.addEventListener(MouseEvent.MOUSE_MOVE, mouseEvent);
66             }
67             listenSprite.hitArea = hitzone;
68             addToLayer(listenSprite, CLICKSPRITE);
69             listenSprite.buttonMode = true;
70             listenSprite.mouseEnabled = true;
71                 }
72
73         protected function mouseEvent(event:MouseEvent):void {
74         }
75
76         public function setHighlight(stateType:String, isOn:*):void {
77             if ( isOn && stateClasses[stateType] == null ) {
78                 stateClasses[stateType] = isOn;
79             } else if ( !isOn && stateClasses[stateType] != null ) {
80                 delete stateClasses[stateType];
81             }
82         }
83
84                 protected function applyStateClasses(tags:Object):Object {
85             for (var stateKey:String in stateClasses) {
86                 tags[":"+stateKey] = 'yes';
87             }
88                         return tags;
89                 }
90                 
91                 public function redraw(sl:StyleList=null):Boolean {
92                         return false;
93                 }
94
95         }
96
97 }