1
8
9 import com.sekati.display.BaseClip;
10 import com.sekati.draw.Rectangle;
11 import com.sekati.draw.Triangle;
12 import com.sekati.geom.Point;
13 import com.sekati.utils.ClassUtils;
14 import com.sekati.utils.TextUtils;
15
16
19 class com.sekati.log.ConsoleStyle {
20
21 private static var _instance:ConsoleStyle;
22 public var CW:Number = 900;
23
24 public var CH:Number = 500;
25
26 public var IW:Number = 889;
27
28 public var IH:Number = 12;
29
30 public var TH:Number = 14;
31
32
33
34 public var CSS:Object = {
35 console:{
36 n:"___Console", x:0, y:0, w:CW, h:CH, minW:450, minH:150, maxW:Stage.width, maxH:Stage.height, bg:{n:"bgMc", x:0, y:0, w:CW, h:CH, c:0x1D1D1D, a:95}, head:{
37 n:"headMc", x:0, y:0, w:CW, h:IH, isDraggable:false, bg:{n:"bcMc", x:0, y:0, w:CW, h:IH, c:0xFFFFFF, a:100}, textfields:{
38 head:{n:"headTf", t:"com.sekati.log.Console", url:"http://sasapi.googlecode.com/", x:5, y:-1, w:500, h:TH, c:0x6C8297, a:100}
39 }, fps:{n:"fpsMc", x:CW - 120, y:0, w:110, h:TH, updateRate:10, bg:{n:"bgMc", x:0, y:0, w:110, h:TH - 2, c:0xFFFFFF, a:0}, textfields:{
40 trend_colors:{up:"#009900", down:"#CC0000"}, current_label:{n:"currentLabelTf", t:"current", x:0, y:-1, w:42, h:TH, c:0x6C8297, a:100}, current_fps:{n:"currentFpsTf", t:"00", html:true, x:32, y:-1, w:25, h:TH, c:0x6C8297, a:100}, average_label:{n:"averageLabelTf", t:"average", x:55, y:-1, w:42, h:TH, c:0x6C8297, a:100}, average_fps:{n:"averageFpsTf", t:"00", html:true, x:91, y:-1, w:25, h:TH, c:0x6C8297, a:100}
41 }
42 }
43 }, holder:{
44 n:"holderMc", x:0, y:IH, w:0, h:0, list:{n:"listMc", x:0, y:0, w:0, h:0}, mask:{n:"maskMc", x:0, y:0, w:IW, h:CH - IH, c:0x00ffff, a:100}, gutter:{n:"gutterMc", x:CW - 10, y:0, w:10, h:CH - IH, c:0x000000, a:100}, bar:{n:"barMc", x:CW - 10, y:0, w:10, h:165, c:0x6C8297, a:100}
45 }, resizer:{n:"resizerMc", x:CW - 10, y:CH - 10, w:10, h:10, c:0xFFFFFF, a:100}
46 }, item:{
47 n:"itemMc", x:0, y:0, w:IW, h:IH, bg:{n:"bgMc", x:0, y:0, w:IW, h:IH, c:[ 0x202020, 0x000000 ], cindex:1, a:50}, line:{n:"lineMc", x:0, y:0, w:IW, h:1, c:0xFFFFFF, a:50}, textfields:{
48 id:{n:"idTf", t:"id", x:5, y:0, w:30, h:TH, c:0x999999, a:100}, type:{n:"typeTf", t:"type", x:40, y:0, w:40, h:TH, a:100, c:{
49 trace:0xFF00FF, info:0x00FFFF, status:0x99FF00, warn:0xFFFF00, error:0xFF9900, fatal:0xFF0000, object:0x9900FF, custom:0x0066FF}
50 }, origin:{n:"originTf", t:"origin", selectable:false, x:85, y:0, w:90, h:TH, c:0x6C8297, a:100}, message:{n:"messageTf", t:"message", selectable:true, x:180, y:0, w:650, h:TH, c:0xF7F7F7, a:100}, benchmark:{n:"benchmarkTf", t:"benchmark", x:835, y:0, w:51, h:TH, c:0x999999, a:100}
51 }
52 }, meta_item:{
53 n:"metaItemMc", x:0, y:0, w:IW, h:IH, bg:{n:"bgMc", x:0, y:0, w:IW, h:IH, c:0x000000, a:95}, line:{n:"lineMc", x:0, y:0, w:IW, h:1, c:0xFFFFFF, a:50}, textfields:{
54 id:{n:"idTf", t:"id", x:5, y:0, w:30, h:TH, c:0x666666, a:100}, type:{n:"typeTf", t:"type", x:40, y:0, w:40, h:TH, c:0x666666, a:100}, origin:{n:"originTf", t:"origin", x:85, y:0, w:90, h:TH, c:0x666666, a:100}, message:{n:"messageTf", t:"message", x:180, y:0, w:650, h:TH, c:0x666666, a:100}, benchmark:{n:"benchmarkTf", t:"benchmark", x:835, y:0, w:51, h:TH, c:0x666666, a:100}
55 }
56 }
57 };
58
59
62 private function ConsoleStyle() {
63 }
64
65
69 public static function getInstance():ConsoleStyle {
70 if (!_instance) _instance = new ConsoleStyle( );
71 return _instance;
72 }
73
74
77 public static function get $():ConsoleStyle {
78 return ConsoleStyle.getInstance( );
79 }
80
81
90 public function createClip(target:MovieClip, style:Object):MovieClip {
91 return ClassUtils.createEmptyMovieClip( com.sekati.display.BaseClip, target, style.n );
92 }
93
94
103 public function createPositionClip(target:MovieClip, style:Object):MovieClip {
104 return ClassUtils.createEmptyMovieClip( com.sekati.display.BaseClip, target, style.n, {_x:style.x, _y:style.y, _alpha:style.a} );
105 }
106
107
116 public function createStyledRectangle(target:MovieClip, style:Object):MovieClip {
117
118 var r:MovieClip = createClip( target, style );
119
120 var c:Number = (style.c instanceof Array) ? alternateItemBgColor( ) : style.c;
121
122 Rectangle.draw( r, new Point( 0, 0 ), new Point( style.w, style.h ), c, style.a );
123 r._x = style.x;
124 r._y = style.y;
125 return r;
126 }
127
128
134 public function createStyledTriangle(target:MovieClip, style:Object):MovieClip {
135 var t:MovieClip = createClip( target, style );
136 Triangle.draw( t, new Point( style.w, style.h ), new Point( 0, style.h ), new Point( style.w, 0 ), style.c, style.a, 0 );
137 t._x = style.x;
138 t._y = style.y;
139 return t;
140 }
141
142
146 private function alternateItemBgColor():Number {
147 CSS.item.bg.cindex = (CSS.item.bg.cindex == 1) ? 0 : 1;
148
149 return CSS.item.bg.c[CSS.item.bg.cindex];
150 }
151
152
162 public function createStyledTextField(target:MovieClip, style:Object, str:String):TextField {
163
164 var s:String = (str != undefined) ? str : style.t;
165
166 var c:Number = (!isNaN( style.c )) ? style.c : resolveTypeColor( str );
167
168 var isSizable:Boolean = (style.n == CSS.item.textfields.message.n || style.n == CSS.item.textfields.origin.n);
169
170 var isHtml:Boolean = (style.html == true) ? true : false;
171
172 var isSelectable:Boolean = (style.selectable == true) ? true : false;
173
174 var props:Object = {type:"dynamic", html:isHtml, autoSize:isSizable, wordWrap:isSizable, multiline:isSizable, selectable:isSelectable, mouseWheelEnabled:false, embedFonts:false, _alpha:style.a, htmlText:s};
175 var format:Object = {font:"Arial", size:9, color:c};
176
177 var t:TextField = TextUtils.create( target, style.n, style.x, style.y, style.w, style.h, props, format );
178 return t;
179 }
180
181
191 private function resolveTypeColor(type:String):Number {
192 var t:String = type.toLowerCase( );
193 var c:Number = (!CSS.item.textfields.type.c[t]) ? CSS.item.textfields.type.c.custom : CSS.item.textfields.type.c[t];
194
195 return c;
196 }
197 }