diff --git a/include/eepp/ui/uinode.hpp b/include/eepp/ui/uinode.hpp index c77b3e455..e936a22ce 100644 --- a/include/eepp/ui/uinode.hpp +++ b/include/eepp/ui/uinode.hpp @@ -14,6 +14,8 @@ #include #include #include +#include + namespace EE { namespace UI { class UITheme; @@ -22,7 +24,7 @@ class UIManager; class UIAction; class UIActionManager; -class EE_API UINode { +class EE_API UINode : public Transformable { public: static UINode * New(); @@ -36,9 +38,9 @@ class EE_API UINode { void nodeToScreen( Vector2i& position ) const; - void worldToNode( Vector2i& pos ) const; + void worldToNode( Vector2i& pos ); - void nodeToWorld( Vector2i& pos ) const; + void nodeToWorld( Vector2i& pos ); virtual Uint32 getType() const; @@ -284,9 +286,7 @@ class EE_API UINode { const Uint32& getDragButton() const; - const Float& getRotation() const; - - void setRotation( const Float& angle ); + void setRotation( float angle ); void setRotation( const Float& angle, const OriginPoint& center ); @@ -296,8 +296,6 @@ class EE_API UINode { Vector2f getRotationCenter(); - const Vector2f& getScale() const; - void setScale( const Vector2f& scale ); void setScale( const Vector2f& scale, const OriginPoint& center ); @@ -310,6 +308,14 @@ class EE_API UINode { Vector2f getScaleCenter(); + virtual void setPosition(float x, float y); + + virtual void setScale(float factorX, float factorY); + + virtual void setScaleOrigin(float x, float y); + + virtual void setRotationOrigin(float x, float y); + const Float& getAlpha() const; virtual void setAlpha( const Float& alpha ); @@ -351,6 +357,18 @@ class EE_API UINode { UIActionManager * getActionManager(); void runAction( UIAction * action ); + + Transform getLocalTransform(); + + Transform getGlobalTransform(); + + Transform getNodeToWorldTransform(); + + Transform getWorldToNodeTransform(); + + Vector2f convertToNodeSpace(const Vector2f& worldPoint); + + Vector2f convertToWorldSpace(const Vector2f& nodePoint); protected: typedef std::map< Uint32, std::map > UIEventsMap; friend class UIManager; @@ -394,9 +412,7 @@ class EE_API UINode { Vector2i mDragPoint; Uint32 mDragButton; - Float mRotation; OriginPoint mRotationOriginPoint; - Vector2f mScale; OriginPoint mScaleOriginPoint; Float mAlpha; diff --git a/src/eepp/maps/mapeditor/mapeditor.cpp b/src/eepp/maps/mapeditor/mapeditor.cpp index 88cfb315c..ac295c7c5 100644 --- a/src/eepp/maps/mapeditor/mapeditor.cpp +++ b/src/eepp/maps/mapeditor/mapeditor.cpp @@ -483,8 +483,8 @@ void MapEditor::createUIMap() { UISkin * HScrollSkin = mTheme->getSkin( "hscrollbar_bg" ); UISkin * VScrollSkin = mTheme->getSkin( "vscrollbar_bg" ); - Float ScrollH = 16; - Float ScrollV = 16; + Int32 ScrollH = 16; + Int32 ScrollV = 16; if ( NULL != HScrollSkin ) { ScrollH = HScrollSkin->getSize().getHeight(); diff --git a/src/eepp/math/transformable.cpp b/src/eepp/math/transformable.cpp index c1ddf5bb6..a6098e346 100644 --- a/src/eepp/math/transformable.cpp +++ b/src/eepp/math/transformable.cpp @@ -114,7 +114,7 @@ void Transformable::scale(const Vector2f& factor) { const Transform& Transformable::getTransform() const { // Recompute the combined transform if needed if (mTransformNeedUpdate) { - Transform t; + /*Transform t; if ( 1.f != mScale ) { t.translate( mScaleOrigin ); @@ -123,14 +123,26 @@ const Transform& Transformable::getTransform() const { } if ( 0.f != mRotation ) { - t.translate( mRotationOrigin ); + t.translate( mRotationOrigin ); t.rotate( mRotation ); t.translate( -mRotationOrigin ); } t.translate( mPosition ); - mTransform = t; + mTransform = t;*/ + + float angle = -mRotation * EE_PI_180; + float cosine = eecos(angle); + float sine = eesin(angle); + float sxc = mScale.x * cosine; + float syc = mScale.y * cosine; + float sxs = mScale.x * sine; + float sys = mScale.y * sine; + float tx = -mRotationOrigin.x * sxc - mRotationOrigin.y * sys + mPosition.x; + float ty = mRotationOrigin.x * sxs - mRotationOrigin.y * syc + mPosition.y; + + mTransform = Transform( sxc, sys, tx, -sxs, syc, ty, 0.f, 0.f, 1.f ); } return mTransform; diff --git a/src/eepp/ui/uinode.cpp b/src/eepp/ui/uinode.cpp index 0b04b09a2..ea676ce3b 100644 --- a/src/eepp/ui/uinode.cpp +++ b/src/eepp/ui/uinode.cpp @@ -45,8 +45,6 @@ UINode::UINode() : mVisible( true ), mEnabled( true ), mDragButton( EE_BUTTON_LMASK ), - mRotation(0.f), - mScale(1.f,1.f), mAlpha(255.f), mActionManager(NULL) { @@ -134,6 +132,7 @@ Uint32 UINode::onMessage( const UIMessage * Msg ) { void UINode::setInternalPosition( const Vector2i& Pos ) { mPos = Pos; mRealPos = Vector2i( Pos.x * PixelDensity::getPixelDensity(), Pos.y * PixelDensity::getPixelDensity() ); + Transformable::setPosition( mRealPos.x, mRealPos.y ); setDirty(); } @@ -872,25 +871,27 @@ void UINode::clipDisable() { } void UINode::matrixSet() { - if ( mScale != 1.f || mRotation != 0.f ) { + if ( getScale() != 1.f || getRotation() != 0.f ) { GlobalBatchRenderer::instance()->draw(); GLi->pushMatrix(); Vector2f scaleCenter = getScaleCenter(); GLi->translatef( scaleCenter.x , scaleCenter.y, 0.f ); - GLi->scalef( mScale.x, mScale.y, 1.0f ); + GLi->scalef( getScale().x, getScale().y, 1.0f ); GLi->translatef( -scaleCenter.x, -scaleCenter.y, 0.f ); Vector2f rotationCenter = getRotationCenter(); GLi->translatef( rotationCenter.x , rotationCenter.y, 0.f ); - GLi->rotatef( mRotation, 0.0f, 0.0f, 1.0f ); + GLi->rotatef( getRotation(), 0.0f, 0.0f, 1.0f ); GLi->translatef( -rotationCenter.x, -rotationCenter.y, 0.f ); + + //GLi->loadMatrixf( getGlobalTransform().getMatrix() ); } } void UINode::matrixUnset() { - if ( mScale != 1.f || mRotation != 0.f ) { + if ( getScale() != 1.f || getRotation() != 0.f ) { GlobalBatchRenderer::instance()->draw(); GLi->popMatrix(); @@ -1279,8 +1280,8 @@ void UINode::updateWorldPolygon() { mPoly = Polygon2f( Rectf( mScreenPosf.x, mScreenPosf.y, mScreenPosf.x + mRealSize.getWidth(), mScreenPosf.y + mRealSize.getHeight() ) ); - mPoly.rotate( mRotation, getRotationCenter() ); - mPoly.scale( mScale, getScaleCenter() ); + mPoly.rotate( getRotation(), getRotationCenter() ); + mPoly.scale( getScale(), getScaleCenter() ); UINode * tParent = getParent(); @@ -1478,6 +1479,8 @@ void UINode::updateScreenPos() { updateCenter(); + Transformable::setPosition( mScreenPosf.x, mScreenPosf.y ); + mNodeFlags &= ~NODE_FLAG_POSITION_DIRTY; } @@ -1626,7 +1629,9 @@ void UINode::onChildCountChange() { invalidateDraw(); } -void UINode::worldToNode( Vector2i& pos ) const { +void UINode::worldToNode( Vector2i& pos ) { + Vector2f PosTest( convertToNodeSpace( Vector2f( pos.x, pos.y ) ) ); + Vector2f Pos( pos.x, pos.y ); std::list parents; @@ -1666,7 +1671,7 @@ void UINode::worldToNode( Vector2i& pos ) const { pos = Vector2i( Pos.x / PixelDensity::getPixelDensity(), Pos.y / PixelDensity::getPixelDensity() ); } -void UINode::nodeToWorld( Vector2i& pos ) const { +void UINode::nodeToWorld( Vector2i& pos ) { Vector2f Pos( (Float)pos.x * PixelDensity::getPixelDensity(), (Float)pos.y * PixelDensity::getPixelDensity() ); std::list parents; @@ -1956,11 +1961,11 @@ Interpolation1d * UINode::startAlphaAnim(const Float & To, const Time & TotalTim } Interpolation2d * UINode::startScaleAnim(const Vector2f & To, const Time & TotalTime, const Ease::Interpolation & type, Interpolation2d::OnPathEndCallback PathEndCallback) { - return startScaleAnim( mScale, To, TotalTime, type, PathEndCallback ); + return startScaleAnim( getScale(), To, TotalTime, type, PathEndCallback ); } Interpolation2d * UINode::startScaleAnim(const Float & To, const Time & TotalTime, const Ease::Interpolation & type, Interpolation2d::OnPathEndCallback PathEndCallback) { - return startScaleAnim( mScale, Vector2f(To,To), TotalTime, type, PathEndCallback ); + return startScaleAnim( getScale(), Vector2f(To,To), TotalTime, type, PathEndCallback ); } Interpolation2d * UINode::startTranslation(const Vector2i & To, const Time & TotalTime, const Ease::Interpolation & type, Interpolation2d::OnPathEndCallback PathEndCallback) { @@ -1968,7 +1973,7 @@ Interpolation2d * UINode::startTranslation(const Vector2i & To, const Time & Tot } Interpolation1d * UINode::startRotation(const Float & To, const Time & TotalTime, const Ease::Interpolation & type, Interpolation1d::OnPathEndCallback PathEndCallback) { - return startRotation( mRotation, To, TotalTime, type, PathEndCallback ); + return startRotation( getRotation(), To, TotalTime, type, PathEndCallback ); } Interpolation1d * UINode::createFadeIn( const Time& time, const bool& AlphaChilds, const Ease::Interpolation& Type ) { @@ -1993,10 +1998,6 @@ Interpolation1d * UINode::disableFadeOut( const Time& time, const bool& AlphaChi return startAlphaAnim( mAlpha, 0.f, time, AlphaChilds, Type ); } -const Float& UINode::getRotation() const { - return mRotation; -} - const OriginPoint& UINode::getRotationOriginPoint() const { return mRotationOriginPoint; } @@ -2004,6 +2005,7 @@ const OriginPoint& UINode::getRotationOriginPoint() const { void UINode::setRotationOriginPoint( const OriginPoint & center ) { mRotationOriginPoint = PixelDensity::dpToPx( center ); updateOriginPoint(); + Transformable::setRotationOrigin( getRotationCenter().x, getRotationCenter().y ); } Vector2f UINode::getRotationCenter() { @@ -2014,10 +2016,13 @@ Vector2f UINode::getRotationCenter() { } } -void UINode::setRotation( const Float& angle ) { - mRotation = angle; +void UINode::setRotation( float angle ) { + Transformable::setRotation( angle ); - if ( mRotation != 0.f ) { + updateOriginPoint(); + Transformable::setRotationOrigin( getRotationCenter().x, getRotationCenter().y ); + + if ( getRotation() != 0.f ) { mNodeFlags |= NODE_FLAG_ROTATED; } else { if ( mNodeFlags & NODE_FLAG_ROTATED ) @@ -2030,19 +2035,18 @@ void UINode::setRotation( const Float& angle ) { } void UINode::setRotation( const Float& angle , const OriginPoint & center ) { - mRotationOriginPoint = center; + mRotationOriginPoint = PixelDensity::dpToPx( center ); updateOriginPoint(); setRotation( angle ); } -const Vector2f& UINode::getScale() const { - return mScale; -} - void UINode::setScale( const Vector2f & scale ) { - mScale = scale; + Transformable::setScale( scale.x, scale.y ); - if ( mScale != 1.f ) { + updateOriginPoint(); + Transformable::setScaleOrigin( getScaleCenter().x, getScaleCenter().y ); + + if ( getScale() != 1.f ) { mNodeFlags |= NODE_FLAG_SCALED; } else { if ( mNodeFlags & NODE_FLAG_SCALED ) @@ -2061,6 +2065,7 @@ const OriginPoint& UINode::getScaleOriginPoint() const { void UINode::setScaleOriginPoint( const OriginPoint & center ) { mScaleOriginPoint = PixelDensity::dpToPx( center ); updateOriginPoint(); + Transformable::setScaleOrigin( getScaleCenter().x, getScaleCenter().y ); } Vector2f UINode::getScaleCenter() { @@ -2072,9 +2077,10 @@ Vector2f UINode::getScaleCenter() { } void UINode::setScale( const Vector2f& scale, const OriginPoint& center ) { - mScaleOriginPoint = center; + mScaleOriginPoint = PixelDensity::dpToPx( center ); updateOriginPoint(); - setScale( scale ); + Transformable::setScale( scale.x, scale.y ); + Transformable::setScaleOrigin( getScaleCenter().x, getScaleCenter().y ); } void UINode::setScale( const Float& scale, const OriginPoint& center ) { @@ -2117,4 +2123,45 @@ void UINode::runAction( UIAction * action ) { } } +Transform UINode::getLocalTransform() { + return getTransform(); +} + +Transform UINode::getGlobalTransform() { + return NULL != mParentCtrl ? mParentCtrl->getGlobalTransform() * getTransform() : getTransform(); +} + +Transform UINode::getNodeToWorldTransform() { + return getGlobalTransform(); +} + +Transform UINode::getWorldToNodeTransform() { + return getNodeToWorldTransform().getInverse(); +} + +Vector2f UINode::convertToNodeSpace(const Vector2f& worldPoint) { + return getWorldToNodeTransform().transformPoint(worldPoint.x, worldPoint.y); +} + +Vector2f UINode::convertToWorldSpace(const Vector2f& nodePoint) { + return getNodeToWorldTransform().transformPoint(nodePoint.x, nodePoint.y); +} + +void UINode::setPosition(float x, float y) { + setPosition( Vector2f( x, y ) ); +} + +void UINode::setScale(float factorX, float factorY) { + setScale( Vector2f( factorX, factorY ) ); +} + +void UINode::setScaleOrigin(float x, float y) { + setScaleOriginPoint( OriginPoint( x, y ) ); +} + +void UINode::setRotationOrigin(float x, float y) { + setRotationOriginPoint( OriginPoint( x, y ) ); +} + + }} diff --git a/src/eepp/ui/uitabwidget.cpp b/src/eepp/ui/uitabwidget.cpp index 21381d48c..fb5c78fd8 100644 --- a/src/eepp/ui/uitabwidget.cpp +++ b/src/eepp/ui/uitabwidget.cpp @@ -458,8 +458,8 @@ void UITabWidget::setTabContainerSize() { void UITabWidget::posTabs() { Uint32 w = 0; - Uint32 h = 0; - Uint32 VA = VAlignGet( mFlags ); + Int32 h = 0; + Int32 VA = VAlignGet( mFlags ); for ( Uint32 i = 0; i < mTabs.size(); i++ ) { switch ( VA ) diff --git a/src/eepp/ui/uiwindow.cpp b/src/eepp/ui/uiwindow.cpp index 83df7d061..166137319 100644 --- a/src/eepp/ui/uiwindow.cpp +++ b/src/eepp/ui/uiwindow.cpp @@ -282,7 +282,7 @@ void UIWindow::drawFrameBuffer() { mFrameBuffer->draw( Rect( 0, 0, mRealSize.getWidth(), mRealSize.getHeight() ), Rect( mScreenPos.x, mScreenPos.y, mScreenPos.x + mRealSize.getWidth(), mScreenPos.y + mRealSize.getHeight() ) ); } else { TextureRegion textureRegion( mFrameBuffer->getTexture()->getId(), Rect( 0, 0, mRealSize.getWidth(), mRealSize.getHeight() ) ); - textureRegion.draw( mScreenPos.x, mScreenPos.y, Color::White, mRotation, mScale ); + textureRegion.draw( mScreenPos.x, mScreenPos.y, Color::White, getRotation(), getScale() ); } } } diff --git a/src/test/eetest.cpp b/src/test/eetest.cpp index 7402492a5..c133af5be 100644 --- a/src/test/eetest.cpp +++ b/src/test/eetest.cpp @@ -390,7 +390,7 @@ void EETest::createUI() { UIWindow * tWin = UIWindow::New(); tWin->setSize( 530, 405 )->setPosition( 320, 240 ); UIWindowStyleConfig windowStyleConfig = tWin->getStyleConfig(); - windowStyleConfig.WinFlags = UI_WIN_DRAGABLE_CONTAINER | UI_WIN_SHADOW | UI_WIN_FRAME_BUFFER; + windowStyleConfig.WinFlags = UI_WIN_DRAGABLE_CONTAINER | UI_WIN_SHADOW /*| UI_WIN_FRAME_BUFFER*/; windowStyleConfig.MinWindowSize = Sizei( 530, 405 ); windowStyleConfig.BaseAlpha = 200; tWin->setStyleConfig( windowStyleConfig );