@@ -15,44 +15,41 @@ import haxe.ui.styles.Style;
1515import haxe .ui .util .Rectangle ;
1616import hxd .Cursor ;
1717
18- class ComponentBase {
19- public var sprite (default , null ): UISprite ;
18+ class ComponentBase extends UISprite {
2019 private var _eventMap : Map <String , UIEvent -> Void >;
2120
2221 public function new () {
22+ super (null );
2323 _eventMap = new Map <String , UIEvent -> Void >();
2424 }
2525
2626 public function handleCreate (native : Bool ) {
27- sprite = new UISprite (null );
2827 }
2928
3029 private function handlePosition (left : Null <Float >, top : Null <Float >, style : Style ) {
3130 if (left != null ) {
32- sprite . x = left ;
31+ x = left ;
3332 }
3433
3534 if (top != null ) {
36- sprite . y = top ;
35+ y = top ;
3736 }
3837 }
3938
40- private function handleSize (width : Null <Float >, height : Null <Float >, style : Style ) {
41- if (width == null || height == null || width <= 0 || height <= 0 ) {
39+ private function handleSize (w : Null <Float >, h : Null <Float >, style : Style ) {
40+ if (h == null || w == null || w <= 0 || h <= 0 ) {
4241 return ;
4342 }
4443
45- sprite .width = width ;
46- sprite .height = height ;
47-
48- StyleHelper .apply (sprite , style , sprite .x , sprite .y , width , height );
44+ setSize (w , h );
45+ StyleHelper .apply (this , style , x , y , __width , __height );
4946 }
5047
5148 private function handleReady () {
5249 }
5350
5451 private function handleClipRect (value : Rectangle ) {
55- sprite . clipRect = value ;
52+ clipRect = value ;
5653 }
5754
5855 public function handlePreReposition () {
@@ -62,7 +59,7 @@ class ComponentBase {
6259 }
6360
6461 private function handleVisibility (show : Bool ) {
65- sprite . visible = show ;
62+ visible = show ;
6663 }
6764
6865 // ***********************************************************************************************************
@@ -73,7 +70,7 @@ class ComponentBase {
7370 if (_textDisplay == null ) {
7471 _textDisplay = new TextDisplay ();
7572 _textDisplay .parentComponent = cast (this , Component );
76- sprite . addChild (_textDisplay .sprite );
73+ addChild (_textDisplay .sprite );
7774 }
7875 if (text != null ) {
7976 _textDisplay .text = text ;
@@ -94,7 +91,7 @@ class ComponentBase {
9491 if (_textInput == null ) {
9592 _textInput = new TextInput ();
9693 _textInput .parentComponent = cast (this , Component );
97- sprite . addChild (_textInput .sprite );
94+ addChild (_textInput .sprite );
9895 }
9996 if (text != null ) {
10097 _textInput .text = text ;
@@ -117,7 +114,7 @@ class ComponentBase {
117114 public function createImageDisplay (): ImageDisplay {
118115 if (_imageDisplay == null ) {
119116 _imageDisplay = new ImageDisplay ();
120- sprite . addChild (_imageDisplay .sprite );
117+ addChild (_imageDisplay .sprite );
121118 }
122119 return _imageDisplay ;
123120 }
@@ -140,29 +137,29 @@ class ComponentBase {
140137 // Display tree
141138 // ***********************************************************************************************************
142139 private function handleSetComponentIndex (child : Component , index : Int ) {
143- sprite . addChildAt (child . sprite , index );
140+ addChildAt (child , index );
144141 }
145142
146143 private function handleAddComponent (child : Component ): Component {
147- sprite . addChild (child . sprite );
144+ addChild (child );
148145 return child ;
149146 }
150147
151148 private function handleAddComponentAt (child : Component , index : Int ): Component {
152- sprite . addChildAt (child . sprite , index );
149+ addChildAt (child , index );
153150 return child ;
154151 }
155152
156153 private function handleRemoveComponent (child : Component , dispose : Bool = true ): Component {
157- sprite . removeChild (child . sprite );
154+ removeChild (child );
158155 // TODO - dispose
159156 return child ;
160157 }
161158
162159 private function handleRemoveComponentAt (index : Int , dispose : Bool = true ): Component {
163160 var child = cast (this , Component )._children [index ];
164161 if (child != null ) {
165- sprite . removeChild (child . sprite );
162+ removeChild (child );
166163
167164 // TODO - dispose
168165 }
@@ -171,23 +168,23 @@ class ComponentBase {
171168
172169 private function applyStyle (style : Style ) {
173170 if (style .cursor != null && style .cursor == " pointer" ) {
174- sprite . cursor = Cursor . Button ;
175- } else if (sprite . cursor != hxd. Cursor . Default ) {
176- sprite . cursor = Cursor . Default ;
171+ cursor = Cursor . Button ;
172+ } else if (cursor != hxd. Cursor . Default ) {
173+ cursor = Cursor . Default ;
177174 }
178175
179176 if (style .filter != null ) {
180177 // TODO
181178 } else {
182- sprite . filter = null ;
179+ filter = null ;
183180 }
184181
185182 if (style .hidden != null ) {
186- sprite . visible = ! style .hidden ;
183+ visible = ! style .hidden ;
187184 }
188185
189186 if (style .opacity != null ) {
190- sprite . alpha = style .opacity ;
187+ alpha = style .opacity ;
191188 }
192189 }
193190
@@ -200,9 +197,9 @@ class ComponentBase {
200197 | MouseEvent .MOUSE_DOWN | MouseEvent .MOUSE_UP | MouseEvent .MOUSE_WHEEL
201198 | MouseEvent .CLICK :
202199 if (! _eventMap .exists (type )) {
203- sprite . interactive = true ;
200+ interactive = true ;
204201 _eventMap .set (type , listener );
205- Reflect .setProperty (sprite . interactiveObj , EventMapper .HAXEUI_TO_HEAPS .get (type ), __onMouseEvent .bind (_ , type ));
202+ Reflect .setProperty (interactiveObj , EventMapper .HAXEUI_TO_HEAPS .get (type ), __onMouseEvent .bind (_ , type ));
206203 }
207204 }
208205 }
@@ -213,11 +210,11 @@ class ComponentBase {
213210 | MouseEvent .MOUSE_DOWN | MouseEvent .MOUSE_UP | MouseEvent .MOUSE_WHEEL
214211 | MouseEvent .CLICK :
215212 _eventMap .remove (type );
216- Reflect .setProperty (sprite . interactiveObj , EventMapper .HAXEUI_TO_HEAPS .get (type ), null );
213+ Reflect .setProperty (interactiveObj , EventMapper .HAXEUI_TO_HEAPS .get (type ), null );
217214 }
218215
219216 if (Lambda .empty (_eventMap )) {
220- sprite . interactive = false ;
217+ interactive = false ;
221218 }
222219 }
223220
0 commit comments