From 310813ccaa037472da7233f78ec5c4e38d0e704a Mon Sep 17 00:00:00 2001 From: Liam Routt Date: Mon, 3 Mar 2014 14:34:56 +1100 Subject: [PATCH 01/11] Added adjustable registration point to Widget - can only set to "left,top", "center,middle", etc. --- src/ru/stablex/ui/widgets/Widget.hx | 93 ++++++++++++++++++++++++++++- 1 file changed, 92 insertions(+), 1 deletion(-) diff --git a/src/ru/stablex/ui/widgets/Widget.hx b/src/ru/stablex/ui/widgets/Widget.hx index 99d41f8..6eacb86 100644 --- a/src/ru/stablex/ui/widgets/Widget.hx +++ b/src/ru/stablex/ui/widgets/Widget.hx @@ -30,7 +30,15 @@ class Widget extends TweenSprite{ @:noCompletion static private inline var _Y_USE_BOTTOM = 7; @:noCompletion static private inline var _Y_USE_BOTTOM_PERCENT = 8; + @:noCompletion static private inline var _X_REG_LEFT = 9; + @:noCompletion static private inline var _X_REG_CENTER = 10; + @:noCompletion static private inline var _X_REG_RIGHT = 11; + @:noCompletion static private inline var _Y_REG_TOP = 12; + @:noCompletion static private inline var _Y_REG_MIDDLE = 13; + @:noCompletion static private inline var _Y_REG_BOTTOM = 14; + + //Name of section in default settings for this type of widgets public var defaults : String = 'Default'; @@ -83,6 +91,18 @@ class Widget extends TweenSprite{ @:noCompletion private var _xUse : Int = _X_USE_LEFT; @:noCompletion private var _yUse : Int = _Y_USE_TOP; + // registration of widget + /** + * This should be like 'left,top' or 'bottom' or 'center,middle' etc. + * Vertical: left, right, center. Horizontal: top, bottom, middle. + * Default is 'left,top' and any unrecognized string reverts to this. + */ + public var registration (default, set_registration): String = 'left,top'; + + //Wich one to use: left, right, center, etc. + @:noCompletion private var _xReg : Int = _X_USE_LEFT; + @:noCompletion private var _yReg : Int = _Y_USE_TOP; + //Get parent if it is widget, returns null otherwise public var wparent (get_wparent,never) : Widget; @@ -270,6 +290,12 @@ class Widget extends TweenSprite{ //by left percent case _X_USE_LEFT_PERCENT: this.x = newParent._width * this._leftPercent / 100; }//switch() + switch( this._xReg ) { + //from right + case _X_REG_RIGHT: this.x -= this._width; + // from center + case _X_REG_CENTER: this.x -= (this._width / 2); + }//switch() switch ( this._yUse ) { //by bottom border @@ -279,6 +305,12 @@ class Widget extends TweenSprite{ //by top percent case _Y_USE_TOP_PERCENT: this.y = newParent._height * this._topPercent / 100; }//switch() + switch( this._yReg ) { + //from bottom + case _Y_REG_BOTTOM: this.y -= this._height; + // from middle + case _Y_REG_MIDDLE: this.y -= (this._height / 2); + }//switch() //} //notify @@ -311,6 +343,12 @@ class Widget extends TweenSprite{ //by left percent case _X_USE_LEFT_PERCENT: this.x = parent._width * this._leftPercent / 100; }//switch() + switch( this._xReg ) { + //from right + case _X_REG_RIGHT: this.x -= this._width; + // from center + case _X_REG_CENTER: this.x -= (this._width / 2); + }//switch() switch ( this._yUse ) { //by bottom border @@ -320,6 +358,12 @@ class Widget extends TweenSprite{ //by top percent case _Y_USE_TOP_PERCENT: this.y = parent._height * this._topPercent / 100; }//switch() + switch( this._yReg ) { + //from bottom + case _Y_REG_BOTTOM: this.y -= this._height; + // from middle + case _Y_REG_MIDDLE: this.y -= (this._height / 2); + }//switch() //} }//function _onParentResize() @@ -359,6 +403,12 @@ class Widget extends TweenSprite{ //by right percent case _X_USE_RIGHT_PERCENT: this.x = this.wparent._width - this.wparent._width * this._rightPercent / 100 - this._width; }//switch() + switch( this._xReg ) { + //from right + case _X_REG_RIGHT: this.x -= this._width; + // from center + case _X_REG_CENTER: this.x -= (this._width / 2); + }//switch() switch ( this._yUse ) { //by bottom border @@ -366,6 +416,12 @@ class Widget extends TweenSprite{ //by bottom percent case _Y_USE_BOTTOM_PERCENT: this.y = this.wparent._height - this.wparent._height * this._bottomPercent / 100 - this._height; }//switch() + switch( this._yReg ) { + //from bottom + case _Y_REG_BOTTOM: this.y -= this._height; + // from middle + case _Y_REG_MIDDLE: this.y -= (this._height / 2); + }//switch() }//if() //handle overflow visibility @@ -975,5 +1031,40 @@ class Widget extends TweenSprite{ tip.bindTo(this); return this.tip = tip; }//function set_tip() - + + /** + * Registration setter + * + */ + @:final @:noCompletion private function set_registration (regs:String) : String { + var registrations : Array = regs.split(','); + + this._yReg = _Y_REG_TOP; + this._xReg = _X_REG_LEFT; + + for(reg in registrations){ + switch(reg){ + case 'top' : this._yReg = _Y_REG_TOP; + case 'middle' : this._yReg = _Y_REG_MIDDLE; + case 'bottom' : this._yReg = _Y_REG_BOTTOM; + case 'left' : this._xReg = _X_REG_LEFT; + case 'center' : this._xReg = _X_REG_CENTER; + case 'right' : this._xReg = _X_REG_RIGHT; + } + } + + registration = (switch(this._xReg) { + case _X_REG_LEFT : 'left'; + case _X_REG_CENTER : 'center'; + case _X_REG_RIGHT : 'right'; + default : 'left'; + }) + ',' + (switch(this._yReg) { + case _Y_REG_TOP : 'top'; + case _Y_REG_MIDDLE : 'middle'; + case _Y_REG_BOTTOM : 'bottom'; + default : 'top'; + }); + + return registration; + } }//class Widget \ No newline at end of file From 6b33361240ac5f256cbf29a5da2d12ef67e13bac Mon Sep 17 00:00:00 2001 From: Liam Routt Date: Mon, 24 Mar 2014 17:28:55 +1100 Subject: [PATCH 02/11] Allow registration of already registered class --- src/ru/stablex/ui/UIBuilder.hx | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/ru/stablex/ui/UIBuilder.hx b/src/ru/stablex/ui/UIBuilder.hx index 27e594a..fa03cdd 100644 --- a/src/ru/stablex/ui/UIBuilder.hx +++ b/src/ru/stablex/ui/UIBuilder.hx @@ -605,9 +605,9 @@ class UIBuilder { } if( cls != null ){ - if( UIBuilder._imports.exists(cls) ) Err.trigger('Class is already imported: ' + cls); - UIBuilder._imports.set(cls, fullyQualifiedName); - + if( !UIBuilder._imports.exists(cls) ){ // Err.trigger('Class is already imported: ' + cls); + UIBuilder._imports.set(cls, fullyQualifiedName); + } }else{ Err.trigger('Wrong class name: ' + fullyQualifiedName); } From b6a9108a1290ff7d4c664b3036211700c82656e9 Mon Sep 17 00:00:00 2001 From: Liam Routt Date: Thu, 12 Jun 2014 20:02:54 +1000 Subject: [PATCH 03/11] Speculative changes for rotation around center and update on resize --- src/ru/stablex/ui/widgets/Box.hx | 36 ++++- src/ru/stablex/ui/widgets/Widget.hx | 222 +++++++++++++++++----------- 2 files changed, 164 insertions(+), 94 deletions(-) diff --git a/src/ru/stablex/ui/widgets/Box.hx b/src/ru/stablex/ui/widgets/Box.hx index fb86e70..1840d22 100644 --- a/src/ru/stablex/ui/widgets/Box.hx +++ b/src/ru/stablex/ui/widgets/Box.hx @@ -57,8 +57,11 @@ class Box extends Widget{ * get object width * */ - @:noCompletion static private inline function _objWidth (obj:DisplayObject) : Float { + @:noCompletion static private function _objWidth (obj:DisplayObject, ignoreRot:Bool=false) : Float { // #if html5 + if ( !ignoreRot && (obj.rotation % 90 == 0) && (obj.rotation % 180 != 0) ) { + return Box._objHeight(obj, true); + } if( Std.is(obj, Widget) ){ return cast(obj, Widget).w; }else if( Std.is(obj, flash.text.TextField) ){ @@ -76,8 +79,11 @@ class Box extends Widget{ * get object height * */ - @:noCompletion static private inline function _objHeight (obj:DisplayObject) : Float { + @:noCompletion static private function _objHeight (obj:DisplayObject, ignoreRot:Bool=false) : Float { // #if html5 + if ( !ignoreRot && (obj.rotation % 90 == 0) && (obj.rotation % 180 != 0) ) { + return Box._objWidth(obj, true); + } if( Std.is(obj, Widget) ){ return cast(obj, Widget).h; }else if( Std.is(obj, flash.text.TextField) ){ @@ -126,29 +132,38 @@ class Box extends Widget{ *******************************************************************************/ + override public function onCreate() : Void { + super.onCreate(); + //trace("onCreate Box - " + name); + alignElements(); + } + /** * Refresh widgets. Re-apply skin box and realigns children * */ override public function refresh() : Void { + //trace("Box starting refresh - " + name); if( this.autoWidth || this.autoHeight ){ var w : Float = (this.autoWidth ? this._calcWidth() : this._width); var h : Float = (this.autoHeight ? this._calcHeight() : this._height); if( this._width != w || this._height != h ){ - this._width = w; this._height = h; - this.dispatchEvent(new WidgetEvent(WidgetEvent.RESIZE)); + _onResize(); + //this.dispatchEvent(new WidgetEvent(WidgetEvent.RESIZE)); } }//if( autoSize ) super.refresh(); - if( this.layout == null ){ + if ( this.layout == null ) { + //trace(" Box align in refresh"); this.alignElements(); } + //trace("Box ending refresh"); }//function refresh() @@ -244,6 +259,7 @@ class Box extends Widget{ * */ public function alignElements () : Void { + //trace(" in align - " + name); if( this.unifyChildren ){ this._unifyChildren(); } @@ -317,6 +333,7 @@ class Box extends Widget{ * */ @:noCompletion private function _vAlignTop () : Void { + //trace(" align top - " + name); //vertical box if( this.vertical ){ var lastY : Float = this.paddingTop; @@ -343,6 +360,7 @@ class Box extends Widget{ * */ @:noCompletion private function _vAlignMiddle () : Void { + //trace(" align middle - " + name); //vertical box if(this.vertical){ //count sum children height @@ -386,6 +404,7 @@ class Box extends Widget{ * */ @:noCompletion private function _vAlignBottom () : Void { + //trace(" align bottom - " + name); //vertical box if( this.vertical ){ var lastY : Float = this.h - this.paddingBottom; @@ -414,6 +433,7 @@ class Box extends Widget{ * */ @:noCompletion private function _hAlignLeft () : Void { + //trace(" align left - " + name); //vertical box if(this.vertical){ for(i in 0...this.numChildren){ @@ -440,6 +460,7 @@ class Box extends Widget{ * */ @:noCompletion private function _hAlignRight () : Void { + //trace(" align right - " + name); //vertical box if(this.vertical){ var child : DisplayObject; @@ -468,6 +489,7 @@ class Box extends Widget{ * */ @:noCompletion private function _hAlignCenter () : Void { + //trace(" align center - " + name); //vertical box if(this.vertical){ var child : DisplayObject; @@ -567,6 +589,7 @@ class Box extends Widget{ * */ @:noCompletion private function _onChildResize (e:WidgetEvent = null) : Void { + //trace("resized child of " + name); if( this.created ){ if( this.autoWidth || this.autoHeight ){ if( e != null ){ @@ -575,7 +598,8 @@ class Box extends Widget{ child != null && child.visible != false && !(this.autoWidth && child._widthUsePercent) && !(this.autoHeight && child._heightUsePercent) - ){ + ) { + //trace(" child is " + child.name); this.refresh(); } }else{ diff --git a/src/ru/stablex/ui/widgets/Widget.hx b/src/ru/stablex/ui/widgets/Widget.hx index 6eacb86..ddca11f 100644 --- a/src/ru/stablex/ui/widgets/Widget.hx +++ b/src/ru/stablex/ui/widgets/Widget.hx @@ -3,6 +3,7 @@ package ru.stablex.ui.widgets; import flash.display.DisplayObject; import flash.display.DisplayObjectContainer; +import flash.geom.Matrix; import flash.geom.Rectangle; import ru.stablex.TweenSprite; import ru.stablex.ui.events.WidgetEvent; @@ -99,6 +100,10 @@ class Widget extends TweenSprite{ */ public var registration (default, set_registration): String = 'left,top'; + // rotation + public var rot_center (default, set_rot_center): Float = 0; + private var _initialTransformMatrix:Matrix; + //Wich one to use: left, right, center, etc. @:noCompletion private var _xReg : Int = _X_USE_LEFT; @:noCompletion private var _yReg : Int = _Y_USE_TOP; @@ -157,6 +162,7 @@ class Widget extends TweenSprite{ super(); this.id = UIBuilder.createId(); + this._initialTransformMatrix = this.transform.matrix.clone(); }//function new() @@ -281,37 +287,7 @@ class Widget extends TweenSprite{ ); } - //positioning { - switch ( this._xUse ) { - //by right border - case _X_USE_RIGHT: this.x = newParent._width - this._right - this._width; - //by right percent - case _X_USE_RIGHT_PERCENT: this.x = newParent._width - newParent._width * this._rightPercent / 100 - this._width; - //by left percent - case _X_USE_LEFT_PERCENT: this.x = newParent._width * this._leftPercent / 100; - }//switch() - switch( this._xReg ) { - //from right - case _X_REG_RIGHT: this.x -= this._width; - // from center - case _X_REG_CENTER: this.x -= (this._width / 2); - }//switch() - - switch ( this._yUse ) { - //by bottom border - case _Y_USE_BOTTOM: this.y = newParent._height - this._bottom - this._height; - //by bottom percent - case _Y_USE_BOTTOM_PERCENT: this.y = newParent._height - newParent._height * this._bottomPercent / 100 - this._height; - //by top percent - case _Y_USE_TOP_PERCENT: this.y = newParent._height * this._topPercent / 100; - }//switch() - switch( this._yReg ) { - //from bottom - case _Y_REG_BOTTOM: this.y -= this._height; - // from middle - case _Y_REG_MIDDLE: this.y -= (this._height / 2); - }//switch() - //} + _do_positioning(newParent); //notify UIBuilder.dispatcher.dispatchEvent(new WidgetEvent( WidgetEvent.ADDED, this )); @@ -334,37 +310,7 @@ class Widget extends TweenSprite{ ); } - //positioning { - switch ( this._xUse ) { - //by right border - case _X_USE_RIGHT: this.x = parent._width - this._right - this._width; - //by right percent - case _X_USE_RIGHT_PERCENT: this.x = parent._width - parent._width * this._rightPercent / 100 - this.w; - //by left percent - case _X_USE_LEFT_PERCENT: this.x = parent._width * this._leftPercent / 100; - }//switch() - switch( this._xReg ) { - //from right - case _X_REG_RIGHT: this.x -= this._width; - // from center - case _X_REG_CENTER: this.x -= (this._width / 2); - }//switch() - - switch ( this._yUse ) { - //by bottom border - case _Y_USE_BOTTOM: this.y = parent._height - this._bottom - this._height; - //by bottom percent - case _Y_USE_BOTTOM_PERCENT: this.y = parent._height - parent._height * this._bottomPercent / 100 - this._height; - //by top percent - case _Y_USE_TOP_PERCENT: this.y = parent._height * this._topPercent / 100; - }//switch() - switch( this._yReg ) { - //from bottom - case _Y_REG_BOTTOM: this.y -= this._height; - // from middle - case _Y_REG_MIDDLE: this.y -= (this._height / 2); - }//switch() - //} + _do_positioning(parent); }//function _onParentResize() @@ -386,6 +332,78 @@ class Widget extends TweenSprite{ this._onResize(); }//function resize() + @:final @:noCompletion private function _do_positioning( myParent:Widget ) : Void { + switch( this._xUse ) { + //by left border + case _X_USE_LEFT: this.x = this._left + _xRegCorrection(_X_USE_LEFT); + //by left percent + case _X_USE_LEFT_PERCENT: this.x = (myParent._width * this._leftPercent / 100) + _xRegCorrection(_X_USE_LEFT); + //by right border + case _X_USE_RIGHT: this.x = (myParent._width - this._right - this.get_rotated_w()) + _xRegCorrection(_X_USE_RIGHT); + //by right percent + case _X_USE_RIGHT_PERCENT: this.x = ((myParent._width * ((100 - this._rightPercent) / 100)) - this.get_rotated_w()) + _xRegCorrection(_X_USE_RIGHT); + }//switch() + + switch ( this._yUse ) { + //by top border + case _Y_USE_TOP: this.y = this._top + _yRegCorrection(_Y_USE_TOP); + //by top percent + case _Y_USE_TOP_PERCENT: this.y = (myParent._height * this._topPercent / 100) + _yRegCorrection(_Y_USE_TOP); + //by bottom border + case _Y_USE_BOTTOM: this.y = (myParent._height - this._bottom - this.get_rotated_h()) + _yRegCorrection(_Y_USE_BOTTOM); + //by bottom percent + case _Y_USE_BOTTOM_PERCENT: this.y = ((myParent._height * ((100 - this._bottomPercent) / 100)) - this.get_rotated_h()) + _yRegCorrection(_Y_USE_BOTTOM); + }//switch() + } + + @:final @:noCompletion private function _xRegCorrection ( xUse:Int ) : Float + { + if ( (xUse == _X_USE_RIGHT) || (xUse == _X_USE_RIGHT_PERCENT) ) + { + switch ( this._xReg ) + { + case _X_REG_LEFT: return this.get_rotated_w(); + //case _X_REG_RIGHT: return 0; + case _X_REG_CENTER: return (this.get_rotated_w() / 2); + } + } + else // assume LEFT + { + switch ( this._xReg ) + { + //case _X_REG_LEFT: return 0; + case _X_REG_RIGHT: return -this.get_rotated_w(); + case _X_REG_CENTER: return -(this.get_rotated_w() / 2); + } + } + + return 0; + } + + @:final @:noCompletion private function _yRegCorrection ( yUse:Int ) : Float + { + if ( (yUse == _Y_USE_BOTTOM) || (yUse == _Y_USE_BOTTOM_PERCENT) ) + { + switch ( this._yReg ) + { + case _Y_REG_TOP: return this.get_rotated_h(); + //case _Y_REG_BOTTOM: return 0; + case _Y_REG_MIDDLE: return (this.get_rotated_h() / 2); + } + } + else // assume TOP + { + switch ( this._yReg ) + { + //case _Y_REG_TOP: return 0; + case _Y_REG_BOTTOM: return -this.get_rotated_h(); + case _Y_REG_MIDDLE: return -(this.get_rotated_h() / 2); + } + } + + return 0; + } + /** * Called every time this object is resized. This methods calls `.refresh()` and `.onResize()` wich @@ -396,32 +414,8 @@ class Widget extends TweenSprite{ */ @:final @:noCompletion private function _onResize() : Void { //positioning - if( this.wparent != null ){ - switch( this._xUse ){ - //by right border - case _X_USE_RIGHT: this.x = this.wparent._width - this._right - this._width; - //by right percent - case _X_USE_RIGHT_PERCENT: this.x = this.wparent._width - this.wparent._width * this._rightPercent / 100 - this._width; - }//switch() - switch( this._xReg ) { - //from right - case _X_REG_RIGHT: this.x -= this._width; - // from center - case _X_REG_CENTER: this.x -= (this._width / 2); - }//switch() - - switch ( this._yUse ) { - //by bottom border - case _Y_USE_BOTTOM: this.y = this.wparent._height - this._bottom - this._height; - //by bottom percent - case _Y_USE_BOTTOM_PERCENT: this.y = this.wparent._height - this.wparent._height * this._bottomPercent / 100 - this._height; - }//switch() - switch( this._yReg ) { - //from bottom - case _Y_REG_BOTTOM: this.y -= this._height; - // from middle - case _Y_REG_MIDDLE: this.y -= (this._height / 2); - }//switch() + if ( this.wparent != null ) { + _do_positioning(this.wparent); }//if() //handle overflow visibility @@ -902,6 +896,23 @@ class Widget extends TweenSprite{ }//function get_w() + /** + * Rotated Width getter + * + */ + @:noCompletion private function get_rotated_w() : Float { + var rads:Float = Math.PI / 180 * this.rot_center; + return Math.abs((Math.sin(rads) * this._height)) + Math.abs((Math.cos(rads) * this._width)); + + //if ( (this.rotation % 90 == 0) && (this.rotation % 180 != 0) ) + //{ + //return this._height; + //} + // + //return this._width; + }//function get_w() + + /** * Height setter * @@ -925,6 +936,22 @@ class Widget extends TweenSprite{ }//function get_h() + /** + * Rotated Height getter + * + */ + @:noCompletion private function get_rotated_h() : Float { + var rads:Float = Math.PI / 180 * this.rot_center; + return Math.abs((Math.sin(rads) * this._width)) + Math.abs((Math.cos(rads) * this._height)); + //if ( (this.rotation % 90 == 0) && (this.rotation % 180 != 0) ) + //{ + //return this._width; + //} + // + //return this._height; + }//function get_h() + + /** * Width percent setter * @@ -1067,4 +1094,23 @@ class Widget extends TweenSprite{ return registration; } + + @:final @:noCompletion private function set_rot_center ( rot: Float ) : Float + { + var centerX:Float = x + (w / 2); + var centerY:Float = y + (h / 2); + var mat:Matrix = _initialTransformMatrix.clone(); + + rot_center = rot; + + mat.translate( -centerX, -centerY); + mat.rotate (rot_center * (Math.PI / 180)); + mat.translate(centerX, centerY); + + transform.matrix = mat; + + trace("set rotation around center, rot:" + rot + ", x:" + x + ", y:" + y + ", w:" + w + ", h:" + h); + + return rot_center; + } }//class Widget \ No newline at end of file From 50359cb379c9aad61845cc5d5f5ed15986285260 Mon Sep 17 00:00:00 2001 From: Liam Routt Date: Mon, 16 Jun 2014 13:19:31 +1000 Subject: [PATCH 04/11] Fixes to rotation - now using rot --- src/ru/stablex/ui/widgets/Widget.hx | 55 ++++++++++------------------- 1 file changed, 19 insertions(+), 36 deletions(-) diff --git a/src/ru/stablex/ui/widgets/Widget.hx b/src/ru/stablex/ui/widgets/Widget.hx index ddca11f..8cb2191 100644 --- a/src/ru/stablex/ui/widgets/Widget.hx +++ b/src/ru/stablex/ui/widgets/Widget.hx @@ -101,8 +101,7 @@ class Widget extends TweenSprite{ public var registration (default, set_registration): String = 'left,top'; // rotation - public var rot_center (default, set_rot_center): Float = 0; - private var _initialTransformMatrix:Matrix; + public var rot (get_rot, set_rot): Float = 0; //Wich one to use: left, right, center, etc. @:noCompletion private var _xReg : Int = _X_USE_LEFT; @@ -162,7 +161,6 @@ class Widget extends TweenSprite{ super(); this.id = UIBuilder.createId(); - this._initialTransformMatrix = this.transform.matrix.clone(); }//function new() @@ -901,16 +899,9 @@ class Widget extends TweenSprite{ * */ @:noCompletion private function get_rotated_w() : Float { - var rads:Float = Math.PI / 180 * this.rot_center; - return Math.abs((Math.sin(rads) * this._height)) + Math.abs((Math.cos(rads) * this._width)); - - //if ( (this.rotation % 90 == 0) && (this.rotation % 180 != 0) ) - //{ - //return this._height; - //} - // - //return this._width; - }//function get_w() + var rads:Float = Math.PI / 180 * this.rotation; + return (Math.sin(rads) * -this._height) + (Math.cos(rads) * this._width); + }//function get_rotated_w() /** @@ -941,15 +932,9 @@ class Widget extends TweenSprite{ * */ @:noCompletion private function get_rotated_h() : Float { - var rads:Float = Math.PI / 180 * this.rot_center; - return Math.abs((Math.sin(rads) * this._width)) + Math.abs((Math.cos(rads) * this._height)); - //if ( (this.rotation % 90 == 0) && (this.rotation % 180 != 0) ) - //{ - //return this._width; - //} - // - //return this._height; - }//function get_h() + var rads:Float = Math.PI / 180 * this.rotation; + return (Math.sin(rads) * this._width) + (Math.cos(rads) * this._height); + }//function get_rotated_h() /** @@ -1095,22 +1080,20 @@ class Widget extends TweenSprite{ return registration; } - @:final @:noCompletion private function set_rot_center ( rot: Float ) : Float + @:final @:noCompletion private function set_rot ( rot: Float ) : Float { - var centerX:Float = x + (w / 2); - var centerY:Float = y + (h / 2); - var mat:Matrix = _initialTransformMatrix.clone(); - - rot_center = rot; - - mat.translate( -centerX, -centerY); - mat.rotate (rot_center * (Math.PI / 180)); - mat.translate(centerX, centerY); - - transform.matrix = mat; + this.rotation = rot; - trace("set rotation around center, rot:" + rot + ", x:" + x + ", y:" + y + ", w:" + w + ", h:" + h); + if ( this.wparent != null ) + { + _do_positioning(this.wparent); + } - return rot_center; + return this.rotation; } + + @:final @:noCompletion private function get_rot ( ) : Float + { + return this.rotation; + } }//class Widget \ No newline at end of file From 8cd7e06bc8e2c05d677f2c2e2239380762ae9438 Mon Sep 17 00:00:00 2001 From: Liam Routt Date: Mon, 16 Jun 2014 13:35:17 +1000 Subject: [PATCH 05/11] Changed rot to rotate --- src/ru/stablex/ui/widgets/Widget.hx | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/ru/stablex/ui/widgets/Widget.hx b/src/ru/stablex/ui/widgets/Widget.hx index 8cb2191..6a78271 100644 --- a/src/ru/stablex/ui/widgets/Widget.hx +++ b/src/ru/stablex/ui/widgets/Widget.hx @@ -101,7 +101,7 @@ class Widget extends TweenSprite{ public var registration (default, set_registration): String = 'left,top'; // rotation - public var rot (get_rot, set_rot): Float = 0; + public var rotate (get_rotate, set_rotate): Float = 0; //Wich one to use: left, right, center, etc. @:noCompletion private var _xReg : Int = _X_USE_LEFT; @@ -1080,7 +1080,7 @@ class Widget extends TweenSprite{ return registration; } - @:final @:noCompletion private function set_rot ( rot: Float ) : Float + @:final @:noCompletion private function set_rotate ( rot: Float ) : Float { this.rotation = rot; @@ -1092,7 +1092,7 @@ class Widget extends TweenSprite{ return this.rotation; } - @:final @:noCompletion private function get_rot ( ) : Float + @:final @:noCompletion private function get_rotate ( ) : Float { return this.rotation; } From 38c30369d6864e765ef4875d9636778e47368042 Mon Sep 17 00:00:00 2001 From: Liam Routt Date: Mon, 16 Jun 2014 13:38:47 +1000 Subject: [PATCH 06/11] Fixed finally --- src/ru/stablex/ui/widgets/Widget.hx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ru/stablex/ui/widgets/Widget.hx b/src/ru/stablex/ui/widgets/Widget.hx index 6a78271..28d9970 100644 --- a/src/ru/stablex/ui/widgets/Widget.hx +++ b/src/ru/stablex/ui/widgets/Widget.hx @@ -101,7 +101,7 @@ class Widget extends TweenSprite{ public var registration (default, set_registration): String = 'left,top'; // rotation - public var rotate (get_rotate, set_rotate): Float = 0; + public var rotate (get_rotate, set_rotate): Float; //Wich one to use: left, right, center, etc. @:noCompletion private var _xReg : Int = _X_USE_LEFT; From b45366856eef36c3f6ded5050214553df9475865 Mon Sep 17 00:00:00 2001 From: Liam Routt Date: Tue, 17 Jun 2014 12:25:13 +1000 Subject: [PATCH 07/11] correct position for registration --- src/ru/stablex/ui/widgets/Widget.hx | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/ru/stablex/ui/widgets/Widget.hx b/src/ru/stablex/ui/widgets/Widget.hx index 28d9970..9fadfe7 100644 --- a/src/ru/stablex/ui/widgets/Widget.hx +++ b/src/ru/stablex/ui/widgets/Widget.hx @@ -649,7 +649,7 @@ class Widget extends TweenSprite{ */ @:noCompletion private function set_left(l:Float) : Float { this._xUse = _X_USE_LEFT; - this.x = l; + this.x = l + _xRegCorrection(this._xUse); return this._left = l; }//function set_left() @@ -670,7 +670,7 @@ class Widget extends TweenSprite{ @:noCompletion private function set_right(r:Float) : Float { this._xUse = _X_USE_RIGHT; if( this.wparent != null ){ - this.x = this.wparent._width - r - this.w; + this.x = this.wparent._width - r - this.w + _xRegCorrection(this._xUse); } return this._right = r; }//function set_right() @@ -701,7 +701,7 @@ class Widget extends TweenSprite{ this._xUse = _X_USE_LEFT_PERCENT; if( this.wparent != null ){ - this.x = this.wparent._width * lp / 100; + this.x = (this.wparent._width * lp / 100) + _xRegCorrection(this._xUse); } return this._leftPercent = lp; @@ -733,7 +733,7 @@ class Widget extends TweenSprite{ this._xUse = _X_USE_RIGHT_PERCENT; if( this.wparent != null ){ - this.x = this.wparent._width - this.wparent._width * rp / 100 - this.w; + this.x = (this.wparent._width - this.wparent._width * rp / 100 - this.w) + _xRegCorrection(this._xUse); } return this._rightPercent = rp; @@ -763,7 +763,7 @@ class Widget extends TweenSprite{ */ @:noCompletion private function set_top(t:Float) : Float { this._yUse = _Y_USE_TOP; - this.y = t; + this.y = t + _yRegCorrection(this._yUse); return this._top = t; }//function set_top() @@ -784,7 +784,7 @@ class Widget extends TweenSprite{ @:noCompletion private function set_bottom(b:Float) : Float { this._yUse = _Y_USE_BOTTOM; if( this.wparent != null ){ - this.y = this.wparent._height - b - this.h; + this.y = (this.wparent._height - b - this.h) + _yRegCorrection(this._yUse); } return this._bottom = b; }//function set_bottom() @@ -815,7 +815,7 @@ class Widget extends TweenSprite{ this._yUse = _Y_USE_TOP_PERCENT; if( this.wparent != null ){ - this.y = this.wparent._height * tp / 100; + this.y = (this.wparent._height * tp / 100) + _yRegCorrection(this._yUse); } return this._topPercent = tp; @@ -847,7 +847,7 @@ class Widget extends TweenSprite{ this._yUse = _Y_USE_BOTTOM_PERCENT; if( this.wparent != null ){ - this.y = this.wparent._height - this.wparent._height * bp / 100 - this.h; + this.y = (this.wparent._height - this.wparent._height * bp / 100 - this.h) + _yRegCorrection(this._yUse); } return this._bottomPercent = bp; From 3606756b18b4719fba292c481ac9398c5035965b Mon Sep 17 00:00:00 2001 From: Liam Routt Date: Wed, 18 Jun 2014 18:18:46 +1000 Subject: [PATCH 08/11] Added scale to registration calculations --- src/ru/stablex/ui/widgets/Widget.hx | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/ru/stablex/ui/widgets/Widget.hx b/src/ru/stablex/ui/widgets/Widget.hx index 9fadfe7..80474a7 100644 --- a/src/ru/stablex/ui/widgets/Widget.hx +++ b/src/ru/stablex/ui/widgets/Widget.hx @@ -360,9 +360,9 @@ class Widget extends TweenSprite{ { switch ( this._xReg ) { - case _X_REG_LEFT: return this.get_rotated_w(); + case _X_REG_LEFT: return this.get_rotated_w() * this.scaleX; //case _X_REG_RIGHT: return 0; - case _X_REG_CENTER: return (this.get_rotated_w() / 2); + case _X_REG_CENTER: return (this.get_rotated_w() / 2) * this.scaleX; } } else // assume LEFT @@ -370,8 +370,8 @@ class Widget extends TweenSprite{ switch ( this._xReg ) { //case _X_REG_LEFT: return 0; - case _X_REG_RIGHT: return -this.get_rotated_w(); - case _X_REG_CENTER: return -(this.get_rotated_w() / 2); + case _X_REG_RIGHT: return -this.get_rotated_w() * this.scaleX; + case _X_REG_CENTER: return -(this.get_rotated_w() / 2) * this.scaleX; } } @@ -384,9 +384,9 @@ class Widget extends TweenSprite{ { switch ( this._yReg ) { - case _Y_REG_TOP: return this.get_rotated_h(); + case _Y_REG_TOP: return this.get_rotated_h() * this.scaleY; //case _Y_REG_BOTTOM: return 0; - case _Y_REG_MIDDLE: return (this.get_rotated_h() / 2); + case _Y_REG_MIDDLE: return (this.get_rotated_h() / 2) * this.scaleY; } } else // assume TOP @@ -394,8 +394,8 @@ class Widget extends TweenSprite{ switch ( this._yReg ) { //case _Y_REG_TOP: return 0; - case _Y_REG_BOTTOM: return -this.get_rotated_h(); - case _Y_REG_MIDDLE: return -(this.get_rotated_h() / 2); + case _Y_REG_BOTTOM: return -this.get_rotated_h() * this.scaleY; + case _Y_REG_MIDDLE: return -(this.get_rotated_h() / 2) * this.scaleY; } } From dde5b7d5f9f5c390e3219c6cfe2bb1f1eb35ec38 Mon Sep 17 00:00:00 2001 From: Liam Routt Date: Fri, 20 Jun 2014 19:12:55 +1000 Subject: [PATCH 09/11] Box children alignment takes into account rotation --- src/ru/stablex/ui/widgets/Box.hx | 11 ++--------- src/ru/stablex/ui/widgets/Widget.hx | 2 +- 2 files changed, 3 insertions(+), 10 deletions(-) diff --git a/src/ru/stablex/ui/widgets/Box.hx b/src/ru/stablex/ui/widgets/Box.hx index 1840d22..c34b4fb 100644 --- a/src/ru/stablex/ui/widgets/Box.hx +++ b/src/ru/stablex/ui/widgets/Box.hx @@ -59,11 +59,8 @@ class Box extends Widget{ */ @:noCompletion static private function _objWidth (obj:DisplayObject, ignoreRot:Bool=false) : Float { // #if html5 - if ( !ignoreRot && (obj.rotation % 90 == 0) && (obj.rotation % 180 != 0) ) { - return Box._objHeight(obj, true); - } if( Std.is(obj, Widget) ){ - return cast(obj, Widget).w; + return cast(obj, Widget).get_rotated_w() * cast(obj, Widget).scaleX; }else if( Std.is(obj, flash.text.TextField) ){ return cast(obj, flash.text.TextField).textWidth + 4; }else{ @@ -81,11 +78,8 @@ class Box extends Widget{ */ @:noCompletion static private function _objHeight (obj:DisplayObject, ignoreRot:Bool=false) : Float { // #if html5 - if ( !ignoreRot && (obj.rotation % 90 == 0) && (obj.rotation % 180 != 0) ) { - return Box._objWidth(obj, true); - } if( Std.is(obj, Widget) ){ - return cast(obj, Widget).h; + return cast(obj, Widget).get_rotated_h() * cast(obj, Widget).scaleY; }else if( Std.is(obj, flash.text.TextField) ){ return cast(obj, flash.text.TextField).textHeight + 4; }else{ @@ -180,7 +174,6 @@ class Box extends Widget{ var childW : Float = 0; for(i in 0...this.numChildren){ - child = this.getChildAt(i); child = this.getChildAt(i); if( child.visible ){ childW = Box._objWidth(child); diff --git a/src/ru/stablex/ui/widgets/Widget.hx b/src/ru/stablex/ui/widgets/Widget.hx index 80474a7..bd21b0c 100644 --- a/src/ru/stablex/ui/widgets/Widget.hx +++ b/src/ru/stablex/ui/widgets/Widget.hx @@ -1053,7 +1053,7 @@ class Widget extends TweenSprite{ this._yReg = _Y_REG_TOP; this._xReg = _X_REG_LEFT; - + for(reg in registrations){ switch(reg){ case 'top' : this._yReg = _Y_REG_TOP; From 5eb02b93c42209e339f557a005e5d29ce48a5404 Mon Sep 17 00:00:00 2001 From: Liam Routt Date: Wed, 25 Jun 2014 17:21:53 +1000 Subject: [PATCH 10/11] added relative x, y, and rotation --- src/ru/stablex/ui/widgets/Widget.hx | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/src/ru/stablex/ui/widgets/Widget.hx b/src/ru/stablex/ui/widgets/Widget.hx index bd21b0c..5cd09e3 100644 --- a/src/ru/stablex/ui/widgets/Widget.hx +++ b/src/ru/stablex/ui/widgets/Widget.hx @@ -1095,5 +1095,23 @@ class Widget extends TweenSprite{ @:final @:noCompletion private function get_rotate ( ) : Float { return this.rotation; - } + } + + public function x_relativeTo ( p_widget:Widget ) : Float + { + return this.x + ( ( (this.wparent != null) && (this.wparent != p_widget) ) ? + this.wparent.x_relativeTo(p_widget) : 0 ); + } + + public function y_relativeTo ( p_widget:Widget ) : Float + { + return this.y + ( ( (this.wparent != null) && (this.wparent != p_widget) ) ? + this.wparent.y_relativeTo(p_widget) : 0 ); + } + + public function rotation_relativeTo ( p_widget:Widget ) : Float + { + return this.rotate + ( ( (this.wparent != null) && (this.wparent != p_widget) ) ? + this.wparent.rotation_relativeTo(p_widget) : 0 ); + } }//class Widget \ No newline at end of file From c484ac55635c242dc32e5e66cdc3d0300cd321c8 Mon Sep 17 00:00:00 2001 From: Liam Routt Date: Wed, 13 Aug 2014 12:15:18 +1000 Subject: [PATCH 11/11] Need to be able to override set_src --- src/ru/stablex/ui/widgets/Bmp.hx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ru/stablex/ui/widgets/Bmp.hx b/src/ru/stablex/ui/widgets/Bmp.hx index b568f22..b853a13 100644 --- a/src/ru/stablex/ui/widgets/Bmp.hx +++ b/src/ru/stablex/ui/widgets/Bmp.hx @@ -163,7 +163,7 @@ class Bmp extends Widget{ * Setter src * */ - private inline function set_src(src:String) : String { + private function set_src(src:String) : String { if( src != null ){ this._bitmapData = null; }