PageRenderTime 57ms CodeModel.GetById 24ms RepoModel.GetById 0ms app.codeStats 1ms

/src/homponex/core/Style.hx

http://homponex.googlecode.com/
Haxe | 208 lines | 174 code | 30 blank | 4 comment | 19 complexity | fe05ffda4a258d9d9a87d30c84e03321 MD5 | raw file
  1. /**
  2. * ...
  3. * @author alijaya
  4. */
  5. package homponex.core;
  6. #if flash9
  7. import flash.display.BitmapData;
  8. import flash.display.Bitmap;
  9. import flash.display.Sprite;
  10. import flash.utils.ByteArray;
  11. import heox.Rectangle;
  12. #end
  13. import homponex.utils.DynamicUtils;
  14. class Style
  15. {
  16. private static var _defaultStyle:Style;
  17. public static var defaultStyle(get_defaultStyle, null):Style;
  18. private static function get_defaultStyle() : Style
  19. {
  20. if (_defaultStyle == null) _defaultStyle = new DefaultStyle();
  21. return _defaultStyle;
  22. }
  23. public static var curStyle(default, null):Style;
  24. private static var _skinWhite:BitmapS9G;
  25. public static var skinWhite(get_skinWhite, null):BitmapS9G;
  26. private static function get_skinWhite() : BitmapS9G
  27. {
  28. if (_skinWhite == null) _skinWhite = new BitmapS9G(SW, new Rectangle(1, 1, 1, 1));
  29. return _skinWhite;
  30. }
  31. private var style:Hash<Hash<Dynamic>>;
  32. public function new()
  33. {
  34. style = new Hash<Hash<Dynamic>>();
  35. }
  36. public function setStyle(value:Dynamic, component:String, ?group:String = "default")
  37. {
  38. if (!style.exists(component)) style.set(component, new Hash<Dynamic>());
  39. var cStyle:Hash<Dynamic> = style.get(component);
  40. if (!cStyle.exists(group)) cStyle.set(group, { } );
  41. var s:Dynamic = cStyle.get(group);
  42. DynamicUtils.mergeDynamic(s, value);
  43. }
  44. public function getStyle(component:String, ?group:String = "default") : Dynamic
  45. {
  46. var value:Dynamic = { };
  47. var a:Array<String> = component.split(".");
  48. var curS:String = a.pop();
  49. if (a.length != 0)
  50. {
  51. var inheritS:String = a.join(".");
  52. DynamicUtils.mergeDynamic(value, getStyle(inheritS, group));
  53. }
  54. var cStyle:Hash<Dynamic> = style.get(component);
  55. if (cStyle == null) return null;
  56. if (!cStyle.exists(group))
  57. {
  58. if (group != "default")
  59. {
  60. group = "default";
  61. if (!cStyle.exists(group)) return null;
  62. }
  63. }
  64. var s:Dynamic = cStyle.get(group);
  65. DynamicUtils.mergeDynamic(value, s);
  66. return value;
  67. }
  68. }
  69. class DefaultStyle extends Style
  70. {
  71. public function new()
  72. {
  73. super();
  74. var component:Dynamic = { };
  75. setStyle(component, DynamicUtils.getClassTree(Component));
  76. var panel:Dynamic = { };
  77. #if flash9
  78. panel.background = new BitmapS9G(SP, new Rectangle(2, 2, 12, 12));
  79. #end
  80. panel.padTop = 2;
  81. panel.padBottom = 2;
  82. panel.padLeft = 2;
  83. panel.padRight = 2;
  84. setStyle(panel, DynamicUtils.getClassTree(Panel));
  85. var button:Dynamic = { };
  86. #if flash9
  87. button.up = new BitmapS9G(SBU, new Rectangle(2, 2, 12, 12));
  88. button.over = new BitmapS9G(SBO, new Rectangle(2, 2, 12, 12));
  89. button.down = new BitmapS9G(SBDn, new Rectangle(2, 2, 12, 12));
  90. button.disabled = new BitmapS9G(SBDs, new Rectangle(2, 2, 12, 12));
  91. #end
  92. setStyle(button, DynamicUtils.getClassTree(Button));
  93. }
  94. }
  95. #if flash9
  96. class SP extends Bitmap
  97. {
  98. public function new()
  99. {
  100. super(new BitmapData(16, 16, true, 0x00000000));
  101. var b:ByteArray = new ByteArray();
  102. var a:Array<Int> = [ -16249848, -16249848, -16249848, -16249848, -16249848, -16249848, -16249848, -16249848, -16249848, -16249848, -16249848, -16249848, -16249848, -16249848, -16249848, -16249848, -16249848, -13553615, -13553615, -13553615, -13553615, -13553615, -13553615, -13553615, -13553615, -13553615, -13553615, -13553615, -13553615, -13553615, -13553615, -16249848, -16249848, -13553615, -1086241727, -1086241727, -1086241727, -1086241727, -1086241727, -1086241727, -1086241727, -1086241727, -1086241727, -1086241727, -1086241727, -1086241727, -13553615, -16249848, -16249848, -13553615, -1086241727, -1086241727, -1086241727, -1086241727, -1086241727, -1086241727, -1086241727, -1086241727, -1086241727, -1086241727, -1086241727, -1086241727, -13553615, -16249848, -16249848, -13553615, -1086241727, -1086241727, -1086241727, -1086241727, -1086241727, -1086241727, -1086241727, -1086241727, -1086241727, -1086241727, -1086241727, -1086241727, -13553615, -16249848, -16249848, -13553615, -1086241727, -1086241727, -1086241727, -1086241727, -1086241727, -1086241727, -1086241727, -1086241727, -1086241727, -1086241727, -1086241727, -1086241727, -13553615, -16249848, -16249848, -13553615, -1086241727, -1086241727, -1086241727, -1086241727, -1086241727, -1086241727, -1086241727, -1086241727, -1086241727, -1086241727, -1086241727, -1086241727, -13553615, -16249848, -16249848, -13553615, -1086241727, -1086241727, -1086241727, -1086241727, -1086241727, -1086241727, -1086241727, -1086241727, -1086241727, -1086241727, -1086241727, -1086241727, -13553615, -16249848, -16249848, -13553615, -1086241727, -1086241727, -1086241727, -1086241727, -1086241727, -1086241727, -1086241727, -1086241727, -1086241727, -1086241727, -1086241727, -1086241727, -13553615, -16249848, -16249848, -13553615, -1086241727, -1086241727, -1086241727, -1086241727, -1086241727, -1086241727, -1086241727, -1086241727, -1086241727, -1086241727, -1086241727, -1086241727, -13553615, -16249848, -16249848, -13553615, -1086241727, -1086241727, -1086241727, -1086241727, -1086241727, -1086241727, -1086241727, -1086241727, -1086241727, -1086241727, -1086241727, -1086241727, -13553615, -16249848, -16249848, -13553615, -1086241727, -1086241727, -1086241727, -1086241727, -1086241727, -1086241727, -1086241727, -1086241727, -1086241727, -1086241727, -1086241727, -1086241727, -13553615, -16249848, -16249848, -13553615, -1086241727, -1086241727, -1086241727, -1086241727, -1086241727, -1086241727, -1086241727, -1086241727, -1086241727, -1086241727, -1086241727, -1086241727, -13553615, -16249848, -16249848, -13553615, -1086241727, -1086241727, -1086241727, -1086241727, -1086241727, -1086241727, -1086241727, -1086241727, -1086241727, -1086241727, -1086241727, -1086241727, -13553615, -16249848, -16249848, -13553615, -13553615, -13553615, -13553615, -13553615, -13553615, -13553615, -13553615, -13553615, -13553615, -13553615, -13553615, -13553615, -13553615, -16249848, -16249848, -16249848, -16249848, -16249848, -16249848, -16249848, -16249848, -16249848, -16249848, -16249848, -16249848, -16249848, -16249848, -16249848, -16249848, -16249848, ];
  103. for (n in a)
  104. {
  105. b.writeInt(n);
  106. }
  107. b.position = 0;
  108. bitmapData.setPixels(bitmapData.rect, b);
  109. }
  110. }
  111. class SBU extends Bitmap
  112. {
  113. public function new()
  114. {
  115. super(new BitmapData(16, 16, true, 0x00000000));
  116. var b:ByteArray = new ByteArray();
  117. var a:Array<Int> = [ -16249848, -16249848, -16249848, -16249848, -16249848, -16249848, -16249848, -16249848, -16249848, -16249848, -16249848, -16249848, -16249848, -16249848, -16249848, -16249848, -16249848, -13553615, -13553615, -13553615, -13553615, -13553615, -13553615, -13553615, -13553615, -13553615, -13553615, -13553615, -13553615, -13553615, -13553615, -16249848, -16249848, -13553615, -1080846957, -1080846957, -1080846957, -1080846957, -1080846957, -1080846957, -1080846957, -1080846957, -1080846957, -1080846957, -1080846957, -1080846957, -13553615, -16249848, -16249848, -13553615, -1081899645, -1081899645, -1081899645, -1081899645, -1081899645, -1081899645, -1081899645, -1081899645, -1081899645, -1081899645, -1081899645, -1081899645, -13553615, -16249848, -16249848, -13553615, -1082427269, -1082427269, -1082427269, -1082427269, -1082427269, -1082427269, -1082427269, -1082427269, -1082427269, -1082427269, -1082427269, -1082427269, -13553615, -16249848, -16249848, -13553615, -1083478933, -1083478933, -1083478933, -1083478933, -1083478933, -1083478933, -1083478933, -1083478933, -1083478933, -1083478933, -1083478933, -1083478933, -13553615, -16249848, -16249848, -13553615, -1084006301, -1084006301, -1084006301, -1084006301, -1084006301, -1084006301, -1084006301, -1084006301, -1084006301, -1084006301, -1084006301, -1084006301, -13553615, -16249848, -16249848, -13553615, -1085189039, -1085189039, -1085189039, -1085189039, -1085189039, -1085189039, -1085189039, -1085189039, -1085189039, -1085189039, -1085189039, -1085189039, -13553615, -16249848, -16249848, -13553615, -1086241727, -1086241727, -1086241727, -1086241727, -1086241727, -1086241727, -1086241727, -1086241727, -1086241727, -1086241727, -1086241727, -1086241727, -13553615, -16249848, -16249848, -13553615, -1086834888, -1086834888, -1086834888, -1086834888, -1086834888, -1086834888, -1086834888, -1086834888, -1086834888, -1086834888, -1086834888, -1086834888, -13553615, -16249848, -16249848, -13553615, -1087886552, -1087886552, -1087886552, -1087886552, -1087886552, -1087886552, -1087886552, -1087886552, -1087886552, -1087886552, -1087886552, -1087886552, -13553615, -16249848, -16249848, -13553615, -1088413920, -1088413920, -1088413920, -1088413920, -1088413920, -1088413920, -1088413920, -1088413920, -1088413920, -1088413920, -1088413920, -1088413920, -13553615, -16249848, -16249848, -13553615, -1089531121, -1089531121, -1089531121, -1089531121, -1089531121, -1089531121, -1089531121, -1089531121, -1089531121, -1089531121, -1089531121, -1089531121, -13553615, -16249848, -16249848, -13553615, -1090058489, -1090058489, -1090058489, -1090058489, -1090058489, -1090058489, -1090058489, -1090058489, -1090058489, -1090058489, -1090058489, -1090058489, -13553615, -16249848, -16249848, -13553615, -13553615, -13553615, -13553615, -13553615, -13553615, -13553615, -13553615, -13553615, -13553615, -13553615, -13553615, -13553615, -13553615, -16249848, -16249848, -16249848, -16249848, -16249848, -16249848, -16249848, -16249848, -16249848, -16249848, -16249848, -16249848, -16249848, -16249848, -16249848, -16249848, -16249848, ];
  118. for (n in a)
  119. {
  120. b.writeInt(n);
  121. }
  122. b.position = 0;
  123. bitmapData.setPixels(bitmapData.rect, b);
  124. }
  125. }
  126. class SBO extends Bitmap
  127. {
  128. public function new()
  129. {
  130. super(new BitmapData(16, 16, true, 0x00000000));
  131. var b:ByteArray = new ByteArray();
  132. var a:Array<Int> = [ -16249848, -16249848, -16249848, -16249848, -16249848, -16249848, -16249848, -16249848, -16249848, -16249848, -16249848, -16249848, -16249848, -16249848, -16249848, -16249848, -16249848, -13553615, -13553615, -13553615, -13553615, -13553615, -13553615, -13553615, -13553615, -13553615, -13553615, -13553615, -13553615, -13553615, -13553615, -16249848, -16249848, -13553615, -1077557563, -1077557563, -1077557563, -1077557563, -1077557563, -1077557563, -1077557563, -1077557563, -1077557563, -1077557563, -1077557563, -1077557563, -13553615, -16249848, -16249848, -13553615, -1078150724, -1078150724, -1078150724, -1078150724, -1078150724, -1078150724, -1078150724, -1078150724, -1078150724, -1078150724, -1078150724, -1078150724, -13553615, -16249848, -16249848, -13553615, -1079202388, -1079202388, -1079202388, -1079202388, -1079202388, -1079202388, -1079202388, -1079202388, -1079202388, -1079202388, -1079202388, -1079202388, -13553615, -16249848, -16249848, -13553615, -1079729756, -1079729756, -1079729756, -1079729756, -1079729756, -1079729756, -1079729756, -1079729756, -1079729756, -1079729756, -1079729756, -1079729756, -13553615, -16249848, -16249848, -13553615, -1080846957, -1080846957, -1080846957, -1080846957, -1080846957, -1080846957, -1080846957, -1080846957, -1080846957, -1080846957, -1080846957, -1080846957, -13553615, -16249848, -16249848, -13553615, -1081899645, -1081899645, -1081899645, -1081899645, -1081899645, -1081899645, -1081899645, -1081899645, -1081899645, -1081899645, -1081899645, -1081899645, -13553615, -16249848, -16249848, -13553615, -1082427269, -1082427269, -1082427269, -1082427269, -1082427269, -1082427269, -1082427269, -1082427269, -1082427269, -1082427269, -1082427269, -1082427269, -13553615, -16249848, -16249848, -13553615, -1083478933, -1083478933, -1083478933, -1083478933, -1083478933, -1083478933, -1083478933, -1083478933, -1083478933, -1083478933, -1083478933, -1083478933, -13553615, -16249848, -16249848, -13553615, -1084006301, -1084006301, -1084006301, -1084006301, -1084006301, -1084006301, -1084006301, -1084006301, -1084006301, -1084006301, -1084006301, -1084006301, -13553615, -16249848, -16249848, -13553615, -1085189039, -1085189039, -1085189039, -1085189039, -1085189039, -1085189039, -1085189039, -1085189039, -1085189039, -1085189039, -1085189039, -1085189039, -13553615, -16249848, -16249848, -13553615, -1086241727, -1086241727, -1086241727, -1086241727, -1086241727, -1086241727, -1086241727, -1086241727, -1086241727, -1086241727, -1086241727, -1086241727, -13553615, -16249848, -16249848, -13553615, -1086834888, -1086834888, -1086834888, -1086834888, -1086834888, -1086834888, -1086834888, -1086834888, -1086834888, -1086834888, -1086834888, -1086834888, -13553615, -16249848, -16249848, -13553615, -13553615, -13553615, -13553615, -13553615, -13553615, -13553615, -13553615, -13553615, -13553615, -13553615, -13553615, -13553615, -13553615, -16249848, -16249848, -16249848, -16249848, -16249848, -16249848, -16249848, -16249848, -16249848, -16249848, -16249848, -16249848, -16249848, -16249848, -16249848, -16249848, -16249848, ];
  133. for (n in a)
  134. {
  135. b.writeInt(n);
  136. }
  137. b.position = 0;
  138. bitmapData.setPixels(bitmapData.rect, b);
  139. }
  140. }
  141. class SBDn extends Bitmap
  142. {
  143. public function new()
  144. {
  145. super(new BitmapData(16, 16, true, 0x00000000));
  146. var b:ByteArray = new ByteArray();
  147. var a:Array<Int> = [ -16249848, -16249848, -16249848, -16249848, -16249848, -16249848, -16249848, -16249848, -16249848, -16249848, -16249848, -16249848, -16249848, -16249848, -16249848, -16249848, -16249848, -1594847, -1594847, -1594847, -1594847, -1594847, -1594847, -1594847, -1594847, -1594847, -1594847, -1594847, -1594847, -1594847, -1594847, -16249848, -16249848, -1594847, -1090058489, -1090058489, -1090058489, -1090058489, -1090058489, -1090058489, -1090058489, -1090058489, -1090058489, -1090058489, -1090058489, -1090058489, -1594847, -16249848, -16249848, -1594847, -1089531121, -1089531121, -1089531121, -1089531121, -1089531121, -1089531121, -1089531121, -1089531121, -1089531121, -1089531121, -1089531121, -1089531121, -1594847, -16249848, -16249848, -1594847, -1088413920, -1088413920, -1088413920, -1088413920, -1088413920, -1088413920, -1088413920, -1088413920, -1088413920, -1088413920, -1088413920, -1088413920, -1594847, -16249848, -16249848, -1594847, -1087886552, -1087886552, -1087886552, -1087886552, -1087886552, -1087886552, -1087886552, -1087886552, -1087886552, -1087886552, -1087886552, -1087886552, -1594847, -16249848, -16249848, -1594847, -1086834888, -1086834888, -1086834888, -1086834888, -1086834888, -1086834888, -1086834888, -1086834888, -1086834888, -1086834888, -1086834888, -1086834888, -1594847, -16249848, -16249848, -1594847, -1086241727, -1086241727, -1086241727, -1086241727, -1086241727, -1086241727, -1086241727, -1086241727, -1086241727, -1086241727, -1086241727, -1086241727, -1594847, -16249848, -16249848, -1594847, -1085189039, -1085189039, -1085189039, -1085189039, -1085189039, -1085189039, -1085189039, -1085189039, -1085189039, -1085189039, -1085189039, -1085189039, -1594847, -16249848, -16249848, -1594847, -1084006301, -1084006301, -1084006301, -1084006301, -1084006301, -1084006301, -1084006301, -1084006301, -1084006301, -1084006301, -1084006301, -1084006301, -1594847, -16249848, -16249848, -1594847, -1083478933, -1083478933, -1083478933, -1083478933, -1083478933, -1083478933, -1083478933, -1083478933, -1083478933, -1083478933, -1083478933, -1083478933, -1594847, -16249848, -16249848, -1594847, -1082427269, -1082427269, -1082427269, -1082427269, -1082427269, -1082427269, -1082427269, -1082427269, -1082427269, -1082427269, -1082427269, -1082427269, -1594847, -16249848, -16249848, -1594847, -1081899645, -1081899645, -1081899645, -1081899645, -1081899645, -1081899645, -1081899645, -1081899645, -1081899645, -1081899645, -1081899645, -1081899645, -1594847, -16249848, -16249848, -1594847, -1080846957, -1080846957, -1080846957, -1080846957, -1080846957, -1080846957, -1080846957, -1080846957, -1080846957, -1080846957, -1080846957, -1080846957, -1594847, -16249848, -16249848, -1594847, -1594847, -1594847, -1594847, -1594847, -1594847, -1594847, -1594847, -1594847, -1594847, -1594847, -1594847, -1594847, -1594847, -16249848, -16249848, -16249848, -16249848, -16249848, -16249848, -16249848, -16249848, -16249848, -16249848, -16249848, -16249848, -16249848, -16249848, -16249848, -16249848, -16249848, ];
  148. for (n in a)
  149. {
  150. b.writeInt(n);
  151. }
  152. b.position = 0;
  153. bitmapData.setPixels(bitmapData.rect, b);
  154. }
  155. }
  156. class SBDs extends Bitmap
  157. {
  158. public function new()
  159. {
  160. super(new BitmapData(16, 16, true, 0x00000000));
  161. var b:ByteArray = new ByteArray();
  162. var a:Array<Int> = [ -16249848, -16249848, -16249848, -16249848, -16249848, -16249848, -16249848, -16249848, -16249848, -16249848, -16249848, -16249848, -16249848, -16249848, -16249848, -16249848, -16249848, -13553615, -13553615, -13553615, -13553615, -13553615, -13553615, -13553615, -13553615, -13553615, -13553615, -13553615, -13553615, -13553615, -13553615, -16249848, -16249848, -13553615, -1080846957, -1080846957, -1080846957, -1080846957, -1080846957, -1080846957, -1080846957, -1080846957, -1080846957, -1080846957, -1080846957, -1080846957, -13553615, -16249848, -16249848, -13553615, -1080846957, -1080846957, -1080846957, -1080846957, -1080846957, -1080846957, -1080846957, -1080846957, -1080846957, -1080846957, -1080846957, -1080846957, -13553615, -16249848, -16249848, -13553615, -1080846957, -1080846957, -1080846957, -1080846957, -1080846957, -1080846957, -1080846957, -1080846957, -1080846957, -1080846957, -1080846957, -1080846957, -13553615, -16249848, -16249848, -13553615, -1080846957, -1080846957, -1080846957, -1080846957, -1080846957, -1080846957, -1080846957, -1080846957, -1080846957, -1080846957, -1080846957, -1080846957, -13553615, -16249848, -16249848, -13553615, -1080846957, -1080846957, -1080846957, -1080846957, -1080846957, -1080846957, -1080846957, -1080846957, -1080846957, -1080846957, -1080846957, -1080846957, -13553615, -16249848, -16249848, -13553615, -1080846957, -1080846957, -1080846957, -1080846957, -1080846957, -1080846957, -1080846957, -1080846957, -1080846957, -1080846957, -1080846957, -1080846957, -13553615, -16249848, -16249848, -13553615, -1080846957, -1080846957, -1080846957, -1080846957, -1080846957, -1080846957, -1080846957, -1080846957, -1080846957, -1080846957, -1080846957, -1080846957, -13553615, -16249848, -16249848, -13553615, -1080846957, -1080846957, -1080846957, -1080846957, -1080846957, -1080846957, -1080846957, -1080846957, -1080846957, -1080846957, -1080846957, -1080846957, -13553615, -16249848, -16249848, -13553615, -1080846957, -1080846957, -1080846957, -1080846957, -1080846957, -1080846957, -1080846957, -1080846957, -1080846957, -1080846957, -1080846957, -1080846957, -13553615, -16249848, -16249848, -13553615, -1080846957, -1080846957, -1080846957, -1080846957, -1080846957, -1080846957, -1080846957, -1080846957, -1080846957, -1080846957, -1080846957, -1080846957, -13553615, -16249848, -16249848, -13553615, -1080846957, -1080846957, -1080846957, -1080846957, -1080846957, -1080846957, -1080846957, -1080846957, -1080846957, -1080846957, -1080846957, -1080846957, -13553615, -16249848, -16249848, -13553615, -1080846957, -1080846957, -1080846957, -1080846957, -1080846957, -1080846957, -1080846957, -1080846957, -1080846957, -1080846957, -1080846957, -1080846957, -13553615, -16249848, -16249848, -13553615, -13553615, -13553615, -13553615, -13553615, -13553615, -13553615, -13553615, -13553615, -13553615, -13553615, -13553615, -13553615, -13553615, -16249848, -16249848, -16249848, -16249848, -16249848, -16249848, -16249848, -16249848, -16249848, -16249848, -16249848, -16249848, -16249848, -16249848, -16249848, -16249848, -16249848, ];
  163. for (n in a)
  164. {
  165. b.writeInt(n);
  166. }
  167. b.position = 0;
  168. bitmapData.setPixels(bitmapData.rect, b);
  169. }
  170. }
  171. class SW extends Bitmap
  172. {
  173. public function new()
  174. {
  175. super(new BitmapData(3,3,true,0xffffffff));
  176. }
  177. }
  178. #end