diff --git a/bin/assets/ui/uitheme.png b/bin/assets/ui/uitheme.png index daae29e7d..bd9d4fa19 100644 Binary files a/bin/assets/ui/uitheme.png and b/bin/assets/ui/uitheme.png differ diff --git a/bin/assets/ui/uitheme/uitheme_hscrollbar_button_menter.png b/bin/assets/ui/uitheme/uitheme_hscrollbar_button_menter.png index 0ec90f05c..46a203eab 100644 Binary files a/bin/assets/ui/uitheme/uitheme_hscrollbar_button_menter.png and b/bin/assets/ui/uitheme/uitheme_hscrollbar_button_menter.png differ diff --git a/bin/assets/ui/uitheme/uitheme_hscrollbar_button_normal.png b/bin/assets/ui/uitheme/uitheme_hscrollbar_button_normal.png index a9999992d..e5517c1a4 100644 Binary files a/bin/assets/ui/uitheme/uitheme_hscrollbar_button_normal.png and b/bin/assets/ui/uitheme/uitheme_hscrollbar_button_normal.png differ diff --git a/bin/assets/ui/uitheme/uitheme_vscrollbar_button_menter.png b/bin/assets/ui/uitheme/uitheme_vscrollbar_button_menter.png index f3cd4966d..5bbbebff4 100644 Binary files a/bin/assets/ui/uitheme/uitheme_vscrollbar_button_menter.png and b/bin/assets/ui/uitheme/uitheme_vscrollbar_button_menter.png differ diff --git a/bin/assets/ui/uitheme/uitheme_vscrollbar_button_normal.png b/bin/assets/ui/uitheme/uitheme_vscrollbar_button_normal.png index 80da06bf6..616b76b6f 100644 Binary files a/bin/assets/ui/uitheme/uitheme_vscrollbar_button_normal.png and b/bin/assets/ui/uitheme/uitheme_vscrollbar_button_normal.png differ diff --git a/include/eepp/math/rect.hpp b/include/eepp/math/rect.hpp index a57c1702c..ccb84c54f 100755 --- a/include/eepp/math/rect.hpp +++ b/include/eepp/math/rect.hpp @@ -106,31 +106,49 @@ tRECT& operator -=(tRECT& R, T X) { return R; } -template -tRECT operator *(const tRECT& R, T X) { - return tRECT(R.Left * X, R.Top * X, R.Right * X, R.Bottom * X); +template +tRECT operator *(const tRECT& R, Y X) { + return tRECT((T)((Y)R.Left * X), (T)((Y)R.Top * X), (T)((Y)R.Right * X), (T)((Y)R.Bottom * X)); } -template -tRECT& operator *=(tRECT& R, T X) { - R.Left *= X; - R.Top *= X; - R.Right *= X; - R.Bottom *= X; +template +tRECT& operator *=(tRECT& R, Y X) { + R.Left = (T)((Y)R.Left * X ); + R.Top = (T)((Y)R.Top * X ); + R.Right = (T)((Y)R.Right * X ); + R.Bottom = (T)((Y)R.Bottom * X ); return R; } -template -tRECT operator /(const tRECT& R, T X) { - return tRECT(R.Left / X, R.Top / X, R.Right / X, R.Bottom / X); +template +tRECT& operator *(tRECT& R, Y X) { + R.Left = (T)((Y)R.Left * X ); + R.Top = (T)((Y)R.Top * X ); + R.Right = (T)((Y)R.Right * X ); + R.Bottom = (T)((Y)R.Bottom * X ); + return R; } -template -tRECT& operator /=(tRECT& R, T X) { - R.Left /= X; - R.Top /= X; - R.Right /= X; - R.Bottom /= X; +template +tRECT operator /(const tRECT& R, Y X) { + return tRECT((T)((Y)R.Left / X), (T)((Y)R.Top / X), (T)((Y)R.Right / X), (T)((Y)R.Bottom / X)); +} + +template +tRECT& operator /=(tRECT& R, Y X) { + R.Left = (T)((Y)R.Left / X ); + R.Top = (T)((Y)R.Top / X ); + R.Right = (T)((Y)R.Right / X ); + R.Bottom = (T)((Y)R.Bottom / X ); + return R; +} + +template +tRECT& operator /(tRECT& R, Y X) { + R.Left = (T)((Y)R.Left / X ); + R.Top = (T)((Y)R.Top / X ); + R.Right = (T)((Y)R.Right / X ); + R.Bottom = (T)((Y)R.Bottom / X ); return R; } diff --git a/include/eepp/ui/uicheckbox.hpp b/include/eepp/ui/uicheckbox.hpp index 639c088d4..d4dac9a17 100644 --- a/include/eepp/ui/uicheckbox.hpp +++ b/include/eepp/ui/uicheckbox.hpp @@ -10,6 +10,8 @@ class EE_API UICheckBox : public UITextBox { public: UICheckBox( const UITextBox::CreateParams& Params ); + UICheckBox(); + virtual ~UICheckBox(); virtual Uint32 getType() const; @@ -27,11 +29,16 @@ class EE_API UICheckBox : public UITextBox { UIControlAnim * getActiveButton() const; UIControlAnim * getInactiveButton() const; + + Int32 getTextSeparation() const; + + void setTextSeparation(const Int32 & textSeparation); protected: UIControlAnim * mActiveButton; UIControlAnim * mInactiveButton; bool mActive; Uint32 mLastTick; + Int32 mTextSeparation; virtual void onSizeChange(); diff --git a/include/eepp/ui/uicomplexcontrol.hpp b/include/eepp/ui/uicomplexcontrol.hpp index b5d445779..05b730e05 100644 --- a/include/eepp/ui/uicomplexcontrol.hpp +++ b/include/eepp/ui/uicomplexcontrol.hpp @@ -39,6 +39,8 @@ class EE_API UIComplexControl : public UIControlAnim { UIComplexControl( const UIComplexControl::CreateParams& Params ); + UIComplexControl(); + virtual ~UIComplexControl(); virtual Uint32 getType() const; diff --git a/include/eepp/ui/uicontrol.hpp b/include/eepp/ui/uicontrol.hpp index f2102df49..62c1d1acd 100644 --- a/include/eepp/ui/uicontrol.hpp +++ b/include/eepp/ui/uicontrol.hpp @@ -22,6 +22,8 @@ class UIManager; class EE_API UIControl { public: + static Float PixelDensity; + typedef cb::Callback1 UIEventCallback; class CreateParams { @@ -72,6 +74,8 @@ class EE_API UIControl { UIControl( const CreateParams& Params ); + UIControl(); + virtual ~UIControl(); void screenToControl( Vector2i& position ) const; @@ -96,12 +100,16 @@ class EE_API UIControl { const Vector2i& getPosition() const; + const Vector2i& getRealPosition() const; + virtual void setSize( const Sizei& size ); void setSize( const Int32& Width, const Int32& Height ); const Sizei& getSize(); + const Sizei& getRealSize(); + Recti getRect() const; void setVisible( const bool& visible ); @@ -140,9 +148,9 @@ class EE_API UIControl { void setVerticalAlign( Uint32 valign ); - void setBackgroundFillEnabled( bool enabled ); + UIBackground * setBackgroundFillEnabled( bool enabled ); - void setBorderEnabled( bool enabled ); + UIBorder * setBorderEnabled( bool enabled ); UIControl * getNextControl() const; @@ -246,17 +254,19 @@ class EE_API UIControl { friend class UIWindow; Vector2i mPos; + Vector2i mRealPos; Vector2i mScreenPos; Vector2f mScreenPosf; Sizei mSize; + Sizei mRealSize; Uint32 mFlags; UintPtr mData; - UIControl * mParentCtrl; - UIControl * mChild; //! Pointer to the first child of the control + UIControl * mParentCtrl; + UIControl * mChild; //! Pointer to the first child of the control UIControl * mChildLast; //! Pointer to the last child added - UIControl * mNext; //! Pointer to the next child of the father + UIControl * mNext; //! Pointer to the next child of the father UIControl * mPrev; //! Pointer to the prev child of the father UISkinState * mSkinState; @@ -267,7 +277,7 @@ class EE_API UIControl { Uint16 mBlend; Uint16 mNumCallBacks; - Polygon2f mPoly; + Polygon2f mPoly; Vector2f mCenter; UIEventsMap mEvents; @@ -386,6 +396,42 @@ class EE_API UIControl { Sizei getSkinSize( UISkin * Skin, const Uint32& State = UISkinState::StateNormal ); Rectf getRectf(); + + void setInternalPosition( const Vector2i& Pos ); + + void setInternalSize( const Sizei& size ); + + void setInternalWidth( const Int32& width ); + + void setInternalHeight( const Int32& height ); + + void setInternalPosX( const Int32& x ); + + void setInternalPosY( const Int32& y ); + + Float pxToDp( Float px ); + + Int32 pxToDpI( Float px ); + + Float dpToPx( Float dp ); + + Int32 dpToPxI( Float dp ); + + Sizei dpToPxI(Sizei size); + + Sizei pxToDpI( Sizei size ); + + Recti dpToPxI( Recti size); + + Recti pxToDpI( Recti size ); + + Sizef dpToPx( Sizef size); + + Sizef pxToDp( Sizef size ); + + Sizei dpToPxI( Sizef size); + + Sizei pxToDpI( Sizef size ); }; }} diff --git a/include/eepp/ui/uicontrolanim.hpp b/include/eepp/ui/uicontrolanim.hpp index e025a978e..6cbacd3eb 100644 --- a/include/eepp/ui/uicontrolanim.hpp +++ b/include/eepp/ui/uicontrolanim.hpp @@ -11,6 +11,8 @@ class EE_API UIControlAnim : public UIDragable { public: UIControlAnim( const CreateParams& Params ); + UIControlAnim(); + virtual ~UIControlAnim(); virtual Uint32 getType() const; diff --git a/include/eepp/ui/uidragable.hpp b/include/eepp/ui/uidragable.hpp index 0bdea0858..f3c4d6ba8 100644 --- a/include/eepp/ui/uidragable.hpp +++ b/include/eepp/ui/uidragable.hpp @@ -9,6 +9,8 @@ class EE_API UIDragable : public UIControl { public: UIDragable( const UIControl::CreateParams& Params ); + UIDragable(); + virtual Uint32 getType() const; virtual bool isType( const Uint32& type ) const; diff --git a/include/eepp/ui/uigfx.hpp b/include/eepp/ui/uigfx.hpp index 9f38089cd..b1545b805 100644 --- a/include/eepp/ui/uigfx.hpp +++ b/include/eepp/ui/uigfx.hpp @@ -26,6 +26,8 @@ class EE_API UIGfx : public UIComplexControl { UIGfx( const UIGfx::CreateParams& Params ); + UIGfx(); + virtual ~UIGfx(); virtual Uint32 getType() const; @@ -42,7 +44,7 @@ class EE_API UIGfx : public UIComplexControl { const ColorA& getColor() const; - void serColor( const ColorA& col ); + void setColor( const ColorA& col ); const EE_RENDER_MODE& getRenderMode() const; diff --git a/include/eepp/ui/uiradiobutton.hpp b/include/eepp/ui/uiradiobutton.hpp index 268090f1c..da70c509c 100644 --- a/include/eepp/ui/uiradiobutton.hpp +++ b/include/eepp/ui/uiradiobutton.hpp @@ -10,6 +10,8 @@ class EE_API UIRadioButton : public UITextBox { public: UIRadioButton( const UITextBox::CreateParams& Params ); + UIRadioButton(); + virtual ~UIRadioButton(); virtual Uint32 getType() const; @@ -27,11 +29,16 @@ class EE_API UIRadioButton : public UITextBox { UIControlAnim * getActiveButton() const; UIControlAnim * getInactiveButton() const; + + Int32 getTextSeparation() const; + + void setTextSeparation(const Int32 & textSeparation); protected: UIControlAnim * mActiveButton; UIControlAnim * mInactiveButton; bool mActive; Uint32 mLastTick; + Int32 mTextSeparation; virtual void onSizeChange(); diff --git a/include/eepp/ui/uislider.hpp b/include/eepp/ui/uislider.hpp index ae230411c..d3d05cfbe 100644 --- a/include/eepp/ui/uislider.hpp +++ b/include/eepp/ui/uislider.hpp @@ -27,6 +27,8 @@ class EE_API UISlider : public UIComplexControl { UISlider( const UISlider::CreateParams& Params ); + UISlider(); + virtual ~UISlider(); virtual Uint32 getType() const; @@ -73,7 +75,7 @@ class EE_API UISlider : public UIComplexControl { bool mAllowHalfSliderOut; bool mExpandBackground; UIControlAnim * mBackSlider; - UIControlAnim * mSlider; + Private::UISliderButton * mSlider; Float mMinValue; Float mMaxValue; Float mValue; diff --git a/include/eepp/ui/uisliderbutton.hpp b/include/eepp/ui/uisliderbutton.hpp index dec9180aa..d869bebfb 100644 --- a/include/eepp/ui/uisliderbutton.hpp +++ b/include/eepp/ui/uisliderbutton.hpp @@ -9,6 +9,8 @@ class EE_API UISliderButton : public UIControlAnim { public: UISliderButton( const UIControlAnim::CreateParams& Params ); + UISliderButton(); + virtual ~UISliderButton(); protected: virtual void onPositionChange(); diff --git a/include/eepp/ui/uitextbox.hpp b/include/eepp/ui/uitextbox.hpp index da464aabc..c34fcdc2e 100644 --- a/include/eepp/ui/uitextbox.hpp +++ b/include/eepp/ui/uitextbox.hpp @@ -38,6 +38,8 @@ class EE_API UITextBox : public UIComplexControl { UITextBox( const UITextBox::CreateParams& Params ); + UITextBox(); + virtual ~UITextBox(); virtual Uint32 getType() const; @@ -56,13 +58,13 @@ class EE_API UITextBox : public UIComplexControl { virtual void setText( const String& text ); - const ColorA& getColor() const; + const ColorA& getFontColor() const; - void setColor( const ColorA& color ); + void setFontColor( const ColorA& color ); - const ColorA& getShadowColor() const; + const ColorA& getFontShadowColor() const; - void setShadowColor( const ColorA& color ); + void setFontShadowColor( const ColorA& color ); const ColorA& getSelectionBackColor() const; @@ -95,6 +97,7 @@ class EE_API UITextBox : public UIComplexControl { ColorA mFontSelectionBackColor; Vector2f mAlignOffset; Recti mPadding; + Recti mRealPadding; Int32 mSelCurInit; Int32 mSelCurEnd; diff --git a/include/eepp/ui/uitextinput.hpp b/include/eepp/ui/uitextinput.hpp index a8da8dca3..d97a4be46 100644 --- a/include/eepp/ui/uitextinput.hpp +++ b/include/eepp/ui/uitextinput.hpp @@ -28,6 +28,8 @@ class EE_API UITextInput : public UITextBox { UITextInput( const UITextInput::CreateParams& Params ); + UITextInput(); + virtual ~UITextInput(); virtual Uint32 getType() const; diff --git a/include/eepp/ui/uitheme.hpp b/include/eepp/ui/uitheme.hpp index be5cd9702..9a16e60f7 100644 --- a/include/eepp/ui/uitheme.hpp +++ b/include/eepp/ui/uitheme.hpp @@ -60,7 +60,7 @@ class EE_API UITheme : protected ResourceManager { void addThemeIcon( const std::string& Icon ); - UITheme( const std::string& getName, const std::string& abbr, Graphics::Font * defaultFont = NULL ); + UITheme( const std::string& name, const std::string& abbr, Graphics::Font * defaultFont = NULL ); virtual ~UITheme(); diff --git a/src/eepp/ui/uicheckbox.cpp b/src/eepp/ui/uicheckbox.cpp index b5fd8f2cc..1f422b61c 100644 --- a/src/eepp/ui/uicheckbox.cpp +++ b/src/eepp/ui/uicheckbox.cpp @@ -7,7 +7,8 @@ namespace EE { namespace UI { UICheckBox::UICheckBox( const UITextBox::CreateParams& Params ) : UITextBox( Params ), - mActive( false ) + mActive( false ), + mTextSeparation( 4 ) { UIControlAnim::CreateParams ButtonParams( Params ); @@ -28,6 +29,31 @@ UICheckBox::UICheckBox( const UITextBox::CreateParams& Params ) : applyDefaultTheme(); } +UICheckBox::UICheckBox() : + UITextBox(), + mActive( false ), + mTextSeparation( dpToPxI( 4 ) ) +{ + mActiveButton = eeNew( UIControlAnim, () ); + mActiveButton->setVisible( false ); + mActiveButton->setEnabled( true ); + mActiveButton->setParent( this ); + mActiveButton->setPosition( 0, 0 ); + mActiveButton->setSize( dpToPxI( 16 ), dpToPxI( 16 ) ); + + mInactiveButton = eeNew( UIControlAnim, () ); + mInactiveButton->setVisible( true ); + mInactiveButton->setEnabled( true ); + mInactiveButton->setParent( this ); + mInactiveButton->setPosition( 0, 0 ); + mInactiveButton->setSize( dpToPxI( 16 ), dpToPxI( 16 ) ); + + setPadding( Recti(0,0,0,0) ); + + applyDefaultTheme(); +} + + UICheckBox::~UICheckBox() { } @@ -56,7 +82,7 @@ void UICheckBox::doAftersetTheme() { tSubTexture = tSkin->getSubTexture( UISkinState::StateNormal ); if ( NULL != tSubTexture ) { - mActiveButton->setSize( tSubTexture->getRealSize() ); + mActiveButton->setSize( dpToPxI( tSubTexture->getRealSize() ) ); mActiveButton->centerVertical(); } } @@ -67,7 +93,7 @@ void UICheckBox::doAftersetTheme() { tSubTexture = tSkin->getSubTexture( UISkinState::StateNormal ); if ( NULL != tSubTexture ) { - mInactiveButton->setSize( tSubTexture->getRealSize() ); + mInactiveButton->setSize( dpToPxI( tSubTexture->getRealSize() ) ); mInactiveButton->centerVertical(); } } @@ -82,7 +108,7 @@ void UICheckBox::autoSize() { mActiveButton->centerVertical(); mInactiveButton->centerVertical(); - mSize.setWidth( (int)mTextCache->getTextWidth() + mActiveButton->getSize().getWidth() ); + setInternalWidth( (int)mTextCache->getTextWidth() + mActiveButton->getSize().getWidth() ); } } @@ -136,8 +162,12 @@ const bool& UICheckBox::isActive() const { } void UICheckBox::setPadding( const Recti& padding ) { - mPadding = padding; - mPadding.Left = mPadding.Left + mActiveButton->getSize().getWidth(); + UITextBox::setPadding( padding ); + + mActiveButton->setPosition( mPadding.Left, mActiveButton->getPosition().y ); + mInactiveButton->setPosition( mPadding.Left, mInactiveButton->getPosition().y ); + + mRealPadding.Left = mActiveButton->getPosition().x + mActiveButton->getSize().getWidth() + dpToPxI( mTextSeparation ); } UIControlAnim * UICheckBox::getActiveButton() const { @@ -148,6 +178,16 @@ UIControlAnim * UICheckBox::getInactiveButton() const { return mInactiveButton; } +Int32 UICheckBox::getTextSeparation() const { + return mTextSeparation; +} + +void UICheckBox::setTextSeparation(const Int32 & textSeparation) { + mTextSeparation = textSeparation; + + setPadding( getPadding() ); +} + Uint32 UICheckBox::onKeyDown( const UIEventKey& Event ) { UITextBox::onKeyDown( Event ); diff --git a/src/eepp/ui/uicomplexcontrol.cpp b/src/eepp/ui/uicomplexcontrol.cpp index 454cc57c3..e1d55b35b 100644 --- a/src/eepp/ui/uicomplexcontrol.cpp +++ b/src/eepp/ui/uicomplexcontrol.cpp @@ -15,6 +15,16 @@ UIComplexControl::UIComplexControl( const UIComplexControl::CreateParams& Params setTooltipText( Params.TooltipText ); } +UIComplexControl::UIComplexControl() : + UIControlAnim(), + mTooltip( NULL ), + mMinControlSize() +{ + mControlFlags |= UI_CTRL_FLAG_COMPLEX; + + updateAnchorsDistances(); +} + UIComplexControl::~UIComplexControl() { eeSAFE_DELETE( mTooltip ); } @@ -29,7 +39,7 @@ bool UIComplexControl::isType( const Uint32& type ) const { void UIComplexControl::updateAnchorsDistances() { if ( NULL != mParentCtrl ) { - mDistToBorder = Recti( mPos.x, mPos.y, mParentCtrl->getSize().x - ( mPos.x + mSize.x ), mParentCtrl->getSize().y - ( mPos.y + mSize.y ) ); + mDistToBorder = Recti( mPos.x, mPos.y, mParentCtrl->getRealSize().x - ( mPos.x + mSize.x ), mParentCtrl->getRealSize().y - ( mPos.y + mSize.y ) ); } } diff --git a/src/eepp/ui/uicontrol.cpp b/src/eepp/ui/uicontrol.cpp index b83180ad3..8ff17ea8e 100644 --- a/src/eepp/ui/uicontrol.cpp +++ b/src/eepp/ui/uicontrol.cpp @@ -7,6 +7,8 @@ namespace EE { namespace UI { +Float UIControl::PixelDensity = 1; + UIControl::UIControl( const CreateParams& Params ) : mPos( Params.Pos ), mSize( Params.Size ), @@ -43,6 +45,33 @@ UIControl::UIControl( const CreateParams& Params ) : updateQuad(); } +UIControl::UIControl() : + mPos(), + mSize(), + mFlags( UI_CONTROL_DEFAULT_FLAGS ), + mData( 0 ), + mParentCtrl( NULL ), + mChild( NULL ), + mChildLast( NULL ), + mNext( NULL ), + mPrev( NULL ), + mSkinState( NULL ), + mBackground( NULL ), + mBorder( NULL ), + mControlFlags( 0 ), + mBlend( ALPHA_NORMAL ), + mNumCallBacks( 0 ), + mVisible( false ), + mEnabled( false ) +{ + if ( NULL == mParentCtrl && NULL != UIManager::instance()->getMainControl() ) { + mParentCtrl = UIManager::instance()->getMainControl(); + } + + if ( NULL != mParentCtrl ) + mParentCtrl->childAdd( this ); +} + UIControl::~UIControl() { safeDeleteSkinState(); eeSAFE_DELETE( mBackground ); @@ -118,27 +147,38 @@ bool UIControl::isInside( const Vector2i& Pos ) const { return ( Pos.x >= 0 && Pos.y >= 0 && Pos.x < mSize.getWidth() && Pos.y < mSize.getHeight() ); } -void UIControl::setPosition( const Vector2i& Pos ) { +void UIControl::setInternalPosition( const Vector2i& Pos ) { mPos = Pos; + mRealPos = Vector2i( Pos.x * PixelDensity, Pos.y * PixelDensity ); +} +void UIControl::setPosition( const Vector2i& Pos ) { + setInternalPosition( Pos ); onPositionChange(); } void UIControl::setPosition( const Int32& x, const Int32& y ) { - mPos = Vector2i( x, y ); - - onPositionChange(); + setPosition( Vector2i( x, y ) ); } const Vector2i& UIControl::getPosition() const { return mPos; } +const Vector2i &UIControl::getRealPosition() const { + return mRealPos; +} + +void UIControl::setInternalSize( const Sizei& size ) { + mSize = size; + mRealSize = Sizei( size.x * PixelDensity, size.y * PixelDensity ); +} + void UIControl::setSize( const Sizei& Size ) { if ( Size != mSize ) { Vector2i sizeChange( Size.x - mSize.x, Size.y - mSize.y ); - mSize = Size; + setInternalSize( Size ); onSizeChange(); @@ -160,6 +200,26 @@ const Sizei& UIControl::getSize() { return mSize; } +const Sizei& UIControl::getRealSize() { + return mRealSize; +} + +void UIControl::setInternalWidth( const Int32& width ) { + setInternalSize( Sizei( width, mSize.y ) ); +} + +void UIControl::setInternalHeight( const Int32& height ) { + setInternalSize( Sizei( mSize.x, height ) ); +} + +void UIControl::setInternalPosX( const Int32& x ) { + setInternalPosition( Vector2i( x, mPos.y ) ); +} + +void UIControl::setInternalPosY( const Int32& y ) { + setInternalPosition( Vector2i( mPos.x, y ) ); +} + void UIControl::setVisible( const bool& visible ) { mVisible = visible; onVisibleChange(); @@ -415,15 +475,17 @@ void UIControl::setVerticalAlign( Uint32 valign ) { mFlags |= valign & UI_VALIGN_MASK; } -void UIControl::setBackgroundFillEnabled( bool enabled ) { +UIBackground * UIControl::setBackgroundFillEnabled( bool enabled ) { writeFlag( UI_FILL_BACKGROUND, enabled ? 1 : 0 ); if ( enabled && NULL == mBackground ) { mBackground = eeNew( UIBackground, () ); } + + return mBackground; } -void UIControl::setBorderEnabled( bool enabled ) { +UIBorder * UIControl::setBorderEnabled( bool enabled ) { writeFlag( UI_BORDER, enabled ? 1 : 0 ); if ( enabled && NULL == mBorder ) { @@ -433,6 +495,8 @@ void UIControl::setBorderEnabled( bool enabled ) { mBackground = eeNew( UIBackground, () ); } } + + return mBorder; } UIControl * UIControl::getNextControl() const { @@ -464,6 +528,13 @@ const Uint32& UIControl::getFlags() const { void UIControl::setFlags( const Uint32& flags ) { mFlags |= flags; + + + if ( NULL == mBackground && ( mFlags & UI_FILL_BACKGROUND ) ) + mBackground = eeNew( UIBackground, () ); + + if ( NULL == mBorder && ( mFlags & UI_BORDER ) ) + mBorder = eeNew( UIBorder, () ); } void UIControl::setBlendMode( const EE_BLEND_MODE& blend ) { @@ -525,6 +596,54 @@ Rectf UIControl::getRectf() { return Rectf( mScreenPosf, Sizef( (Float)mSize.getWidth(), (Float)mSize.getHeight() ) ); } +Float UIControl::dpToPx( Float dp ) { + return dp * 1; +} + +Int32 UIControl::dpToPxI( Float dp ) { + return (Int32)dpToPx( dp ); +} + +Float UIControl::pxToDp( Float px ) { + return px / 1; +} + +Int32 UIControl::pxToDpI( Float px ) { + return (Int32)pxToDp( px ); +} + +Sizei UIControl::dpToPxI( Sizei size ) { + return Sizei( dpToPxI( size.x ), dpToPxI( size.y ) ); +} + +Sizei UIControl::pxToDpI( Sizei size ) { + return Sizei( pxToDpI( size.x ), pxToDpI( size.y ) ); +} + +Recti UIControl::dpToPxI( Recti rect ) { + return rect * 1; +} + +Recti UIControl::pxToDpI( Recti rect ) { + return rect / 1; +} + +Sizef UIControl::dpToPx( Sizef size ) { + return size * 1.f; +} + +Sizef UIControl::pxToDp( Sizef size ) { + return size * 1.f; +} + +Sizei UIControl::dpToPxI( Sizef size ) { + return Sizei( dpToPxI( size.x ), dpToPxI( size.y ) ); +} + +Sizei UIControl::pxToDpI( Sizef size ) { + return Sizei( pxToDpI( size.x ), pxToDpI( size.y ) ); +} + void UIControl::backgroundDraw() { Primitives P; Rectf R = getRectf(); diff --git a/src/eepp/ui/uicontrolanim.cpp b/src/eepp/ui/uicontrolanim.cpp index c243f4fd4..6ad26b01b 100644 --- a/src/eepp/ui/uicontrolanim.cpp +++ b/src/eepp/ui/uicontrolanim.cpp @@ -21,6 +21,21 @@ UIControlAnim::UIControlAnim( const CreateParams& Params ) : updateOriginPoint(); } +UIControlAnim::UIControlAnim() : + UIDragable(), + mAngle(0.f), + mScale(1.f,1.f), + mAlpha(255.f), + mAngleAnim(NULL), + mScaleAnim(NULL), + mAlphaAnim(NULL), + mMoveAnim(NULL) +{ + mControlFlags |= UI_CTRL_FLAG_ANIM; + + updateOriginPoint(); +} + UIControlAnim::~UIControlAnim() { eeSAFE_DELETE( mAlphaAnim ); eeSAFE_DELETE( mAngleAnim ); diff --git a/src/eepp/ui/uidragable.cpp b/src/eepp/ui/uidragable.cpp index 17465ceee..68bd634ae 100644 --- a/src/eepp/ui/uidragable.cpp +++ b/src/eepp/ui/uidragable.cpp @@ -11,6 +11,13 @@ UIDragable::UIDragable( const UIControl::CreateParams& Params ) : mControlFlags |= UI_CTRL_FLAG_DRAGABLE; } +UIDragable::UIDragable() : + UIControl(), + mDragButton( EE_BUTTON_LMASK ) +{ + mControlFlags |= UI_CTRL_FLAG_DRAGABLE; +} + UIDragable::~UIDragable() { } diff --git a/src/eepp/ui/uigfx.cpp b/src/eepp/ui/uigfx.cpp index 626b47b14..d5a488c1f 100644 --- a/src/eepp/ui/uigfx.cpp +++ b/src/eepp/ui/uigfx.cpp @@ -18,6 +18,16 @@ UIGfx::UIGfx( const UIGfx::CreateParams& Params ) : autoSize(); } +UIGfx::UIGfx() : + UIComplexControl(), + mSubTexture( NULL ), + mColor(), + mRender( RN_NORMAL ), + mAlignOffset(0,0) +{ + mFlags |= UI_FIT_TO_CONTROL; +} + UIGfx::~UIGfx() { } @@ -33,6 +43,11 @@ void UIGfx::setSubTexture( Graphics::SubTexture * subTexture ) { mSubTexture = subTexture; autoSize(); + + if ( NULL != mSubTexture && mSize.x == 0 && mSize.y == 0 ) { + setSize( dpToPxI( mSubTexture->getDestSize() ) ); + } + autoAlign(); } @@ -112,7 +127,7 @@ const ColorA& UIGfx::getColor() const { return mColor; } -void UIGfx::serColor( const ColorA& col ) { +void UIGfx::setColor( const ColorA& col ) { mColor = col; setAlpha( col.a() ); } @@ -130,17 +145,17 @@ void UIGfx::autoAlign() { return; if ( HAlignGet( mFlags ) == UI_HALIGN_CENTER ) { - mAlignOffset.x = mSize.getWidth() / 2 - mSubTexture->getDestSize().x / 2; + mAlignOffset.x = mSize.getWidth() / 2 - dpToPxI( mSubTexture->getDestSize().x ) / 2; } else if ( fontHAlignGet( mFlags ) == UI_HALIGN_RIGHT ) { - mAlignOffset.x = mSize.getWidth() - mSubTexture->getDestSize().x; + mAlignOffset.x = mSize.getWidth() - dpToPxI( mSubTexture->getDestSize().x ); } else { mAlignOffset.x = 0; } if ( VAlignGet( mFlags ) == UI_VALIGN_CENTER ) { - mAlignOffset.y = mSize.getHeight() / 2 - mSubTexture->getDestSize().y / 2; + mAlignOffset.y = mSize.getHeight() / 2 - dpToPxI( mSubTexture->getDestSize().y ) / 2; } else if ( fontVAlignGet( mFlags ) == UI_VALIGN_BOTTOM ) { - mAlignOffset.y = mSize.getHeight() - mSubTexture->getDestSize().y; + mAlignOffset.y = mSize.getHeight() - dpToPxI( mSubTexture->getDestSize().y ); } else { mAlignOffset.y = 0; } diff --git a/src/eepp/ui/uilistbox.cpp b/src/eepp/ui/uilistbox.cpp index 43470dbb1..c5151acf0 100644 --- a/src/eepp/ui/uilistbox.cpp +++ b/src/eepp/ui/uilistbox.cpp @@ -673,7 +673,7 @@ void UIListBox::setFontColor( const ColorA& Color ) { mFontColor = Color; for ( Uint32 i = 0; i < mItems.size(); i++ ) - mItems[i]->setColor( mFontColor ); + mItems[i]->setFontColor( mFontColor ); } const ColorA& UIListBox::getFontColor() const { diff --git a/src/eepp/ui/uilistboxitem.cpp b/src/eepp/ui/uilistboxitem.cpp index 709832c28..532b05d2e 100644 --- a/src/eepp/ui/uilistboxitem.cpp +++ b/src/eepp/ui/uilistboxitem.cpp @@ -116,11 +116,11 @@ void UIListBoxItem::onStateChange() { } if ( mSkinState->getState() == UISkinState::StateSelected ) { - setColor( LBParent->getFontSelectedColor() ); + setFontColor( LBParent->getFontSelectedColor() ); } else if ( mSkinState->getState() == UISkinState::StateMouseEnter ) { - setColor( LBParent->getFontOverColor() ); + setFontColor( LBParent->getFontOverColor() ); } else { - setColor( LBParent->getFontColor() ); + setFontColor( LBParent->getFontColor() ); } } diff --git a/src/eepp/ui/uimenuitem.cpp b/src/eepp/ui/uimenuitem.cpp index 15d3f003f..a9b05f155 100644 --- a/src/eepp/ui/uimenuitem.cpp +++ b/src/eepp/ui/uimenuitem.cpp @@ -37,11 +37,11 @@ void UIMenuItem::onStateChange() { UIMenu * tMenu = reinterpret_cast ( getParent() ); if ( mSkinState->getState() == UISkinState::StateSelected ) { - mTextBox->setColor( tMenu->mFontSelectedColor ); + mTextBox->setFontColor( tMenu->mFontSelectedColor ); } else if ( mSkinState->getState() == UISkinState::StateMouseEnter ) { - mTextBox->setColor( tMenu->mFontOverColor ); + mTextBox->setFontColor( tMenu->mFontOverColor ); } else { - mTextBox->setColor( tMenu->mFontColor ); + mTextBox->setFontColor( tMenu->mFontColor ); } } diff --git a/src/eepp/ui/uipushbutton.cpp b/src/eepp/ui/uipushbutton.cpp index a76aa5ff3..8b0a2df59 100644 --- a/src/eepp/ui/uipushbutton.cpp +++ b/src/eepp/ui/uipushbutton.cpp @@ -100,17 +100,17 @@ void UIPushButton::onSizeChange() { if ( NULL != mTextBox ) { Recti P = makePadding(); - mSize.setHeight( mIcon->getSize().getHeight() + P.Top + P.Bottom ); + setInternalHeight( mIcon->getSize().getHeight() + P.Top + P.Bottom ); if ( 0 == mTextBox->getText().size() ) { - mSize.setWidth ( mIcon->getSize().getWidth() + P.Left + P.Right ); + setInternalWidth( mIcon->getSize().getWidth() + P.Left + P.Right ); mIcon->center(); } else { - mSize.setWidth( mIconSpace + mIcon->setPosition(.x + mIcon->getSize().getWidth() + mTextBox->getSize().getWidth() ); + setInternalWidth( mIconSpace + mIcon->setPosition(.x + mIcon->getSize().getWidth() + mTextBox->getSize().getWidth() ); if ( mSize.getHeight() < P.Top + P.Bottom + mTextBox->getTextHeight() ) - mSize.setHeight( P.Top + P.Bottom + mTextBox->getTextHeight() ); + setInternalHeight( P.Top + P.Bottom + mTextBox->getTextHeight() ); } } } else { @@ -137,7 +137,7 @@ void UIPushButton::doAftersetTheme() { } if ( mFlags & UI_AUTO_SIZE ) { - mSize.setHeight( getSkinSize().getHeight() ); + setInternalHeight( getSkinSize().getHeight() ); } autoPadding(); @@ -199,9 +199,9 @@ void UIPushButton::onAlphaChange() { void UIPushButton::onStateChange() { if ( mSkinState->getState() == UISkinState::StateMouseEnter ) { - mTextBox->setColor( mFontOverColor ); + mTextBox->setFontColor( mFontOverColor ); } else { - mTextBox->setColor( mFontColor ); + mTextBox->setFontColor( mFontColor ); } mTextBox->setAlpha( mAlpha ); diff --git a/src/eepp/ui/uiradiobutton.cpp b/src/eepp/ui/uiradiobutton.cpp index fa0701bae..f9943a4b3 100644 --- a/src/eepp/ui/uiradiobutton.cpp +++ b/src/eepp/ui/uiradiobutton.cpp @@ -9,7 +9,8 @@ UIRadioButton::UIRadioButton( const UITextBox::CreateParams& Params ) : UITextBox( Params ), mActiveButton(NULL), mInactiveButton(NULL), - mActive( false ) + mActive( false ), + mTextSeparation( 4 ) { UIControlAnim::CreateParams ButtonParams( Params ); @@ -32,6 +33,32 @@ UIRadioButton::UIRadioButton( const UITextBox::CreateParams& Params ) : applyDefaultTheme(); } +UIRadioButton::UIRadioButton() : + UITextBox(), + mActiveButton(NULL), + mInactiveButton(NULL), + mActive( false ), + mTextSeparation( dpToPxI( 4 ) ) +{ + mActiveButton = eeNew( UIControlAnim, () ); + mActiveButton->setVisible( false ); + mActiveButton->setEnabled( true ); + mActiveButton->setParent( this ); + mActiveButton->setPosition( 0, 0 ); + mActiveButton->setSize( dpToPxI( 16 ), dpToPxI( 16 ) ); + + mInactiveButton = eeNew( UIControlAnim, () ); + mInactiveButton->setVisible( true ); + mInactiveButton->setEnabled( true ); + mInactiveButton->setParent( this ); + mInactiveButton->setPosition( 0, 0 ); + mInactiveButton->setSize( dpToPxI( 16 ), dpToPxI( 16 ) ); + + setPadding( Recti(0,0,0,0) ); + + applyDefaultTheme(); +} + UIRadioButton::~UIRadioButton() { } @@ -56,7 +83,7 @@ void UIRadioButton::setTheme( UITheme * Theme ) { tSubTexture = tSkin->getSubTexture( UISkinState::StateNormal ); if ( NULL != tSubTexture ) { - mActiveButton->setSize( tSubTexture->getRealSize() ); + mActiveButton->setSize( dpToPxI( tSubTexture->getRealSize() ) ); mActiveButton->centerVertical(); } } @@ -67,7 +94,7 @@ void UIRadioButton::setTheme( UITheme * Theme ) { tSubTexture = tSkin->getSubTexture( UISkinState::StateNormal ); if ( NULL != tSubTexture ) { - mInactiveButton->setSize( tSubTexture->getRealSize() ); + mInactiveButton->setSize( dpToPxI( tSubTexture->getRealSize() ) ); mInactiveButton->centerVertical(); } } @@ -82,7 +109,7 @@ void UIRadioButton::autoSize() { mActiveButton->centerVertical(); mInactiveButton->centerVertical(); - mSize.setWidth( (int)mTextCache->getTextWidth() + mActiveButton->getSize().getWidth() ); + setInternalWidth( (int)mTextCache->getTextWidth() + mActiveButton->getSize().getWidth() ); } } @@ -202,8 +229,12 @@ const bool& UIRadioButton::isActive() const { } void UIRadioButton::setPadding( const Recti& padding ) { - mPadding = padding; - mPadding.Left = mPadding.Left + mActiveButton->getSize().getWidth(); + UITextBox::setPadding( padding ); + + mActiveButton->setPosition( mPadding.Left, mActiveButton->getPosition().y ); + mInactiveButton->setPosition( mPadding.Left, mInactiveButton->getPosition().y ); + + mRealPadding.Left = mActiveButton->getPosition().x + mActiveButton->getSize().getWidth() + dpToPxI( mTextSeparation ); } UIControlAnim * UIRadioButton::getActiveButton() const { @@ -214,6 +245,16 @@ UIControlAnim * UIRadioButton::getInactiveButton() const { return mInactiveButton; } +Int32 UIRadioButton::getTextSeparation() const { + return mTextSeparation; +} + +void UIRadioButton::setTextSeparation(const Int32 & textSeparation) { + mTextSeparation = textSeparation; + + setPadding( getPadding() ); +} + Uint32 UIRadioButton::onKeyDown( const UIEventKey& Event ) { if ( Event.getKeyCode() == KEY_SPACE ) { if ( Sys::getTicks() - mLastTick > 250 ) { diff --git a/src/eepp/ui/uiselectbutton.cpp b/src/eepp/ui/uiselectbutton.cpp index ac7788620..2c377d977 100644 --- a/src/eepp/ui/uiselectbutton.cpp +++ b/src/eepp/ui/uiselectbutton.cpp @@ -54,11 +54,11 @@ void UISelectButton::onStateChange() { UIWinMenu * Menu = reinterpret_cast ( getParent() ); if ( mSkinState->getState() == UISkinState::StateSelected ) { - getTextBox()->setColor( Menu->getFontSelectedColor() ); + getTextBox()->setFontColor( Menu->getFontSelectedColor() ); } else if ( mSkinState->getState() == UISkinState::StateMouseEnter ) { - getTextBox()->setColor( Menu->getFontOverColor() ); + getTextBox()->setFontColor( Menu->getFontOverColor() ); } else { - getTextBox()->setColor( Menu->getFontColor() ); + getTextBox()->setFontColor( Menu->getFontColor() ); } } } diff --git a/src/eepp/ui/uislider.cpp b/src/eepp/ui/uislider.cpp index 63d7f65fb..d519d637e 100644 --- a/src/eepp/ui/uislider.cpp +++ b/src/eepp/ui/uislider.cpp @@ -48,6 +48,49 @@ UISlider::UISlider( const UISlider::CreateParams& Params ) : applyDefaultTheme(); } +UISlider::UISlider() : + UIComplexControl(), + mVertical( true ), + mAllowHalfSliderOut( false ), + mExpandBackground( false ), + mBackSlider( NULL ), + mSlider( NULL ), + mMinValue( 0.f ), + mMaxValue( 1.f ), + mValue( 0.f ), + mClickStep( 0.1f ), + mOnPosChange( false ) +{ + Sizei bgSize; + + if ( !mVertical ) + bgSize = dpToPxI( Sizei( mSize.getWidth() - 16, 8 ) ); + else + bgSize = dpToPxI( Sizei( 8, mSize.getWidth() - 16 ) ); + + mBackSlider = eeNew( UIControlAnim, () ); + mBackSlider->setParent( this ); + mBackSlider->setVisible( true ); + mBackSlider->setEnabled( true ); + mBackSlider->setSize( bgSize ); + mBackSlider->center(); + + mSlider = eeNew( Private::UISliderButton, () ); + mSlider->setParent( this ); + mSlider->setEnabled( true ); + mSlider->setVisible( true ); + mSlider->setDragEnabled( true ); + mSlider->setSize( dpToPxI( 16 ), dpToPxI( 16 ) ); + mSlider->setPosition( 0, 0 ); + + if ( !mVertical ) + mSlider->centerVertical(); + else + mSlider->centerHorizontal(); + + applyDefaultTheme(); +} + UISlider::~UISlider() { } @@ -134,6 +177,8 @@ void UISlider::adjustChilds() { } mBackSlider->center(); + + fixSliderPos(); } } } @@ -172,8 +217,9 @@ void UISlider::fixSliderPos() { if ( mSlider->getPosition().y > mBackSlider->getSize().getHeight() ) mSlider->setPosition( 0, mBackSlider->getSize().getHeight() ); } else { - if ( mSlider->getPosition().y > mBackSlider->getSize().getHeight() - mSlider->getSize().getHeight() ) + if ( mSlider->getPosition().y > mBackSlider->getSize().getHeight() - mSlider->getSize().getHeight() ) { mSlider->setPosition( 0, mBackSlider->getSize().getHeight() - mSlider->getSize().getHeight() ); + } } mSlider->centerHorizontal(); diff --git a/src/eepp/ui/uisliderbutton.cpp b/src/eepp/ui/uisliderbutton.cpp index 858ce347a..3e1621794 100644 --- a/src/eepp/ui/uisliderbutton.cpp +++ b/src/eepp/ui/uisliderbutton.cpp @@ -9,6 +9,12 @@ UISliderButton::UISliderButton( const UIControlAnim::CreateParams& Params ) : applyDefaultTheme(); } +UISliderButton::UISliderButton() : + UIControlAnim() +{ + applyDefaultTheme(); +} + UISliderButton::~UISliderButton() { } diff --git a/src/eepp/ui/uispinbox.cpp b/src/eepp/ui/uispinbox.cpp index 016c48804..0ccfb9b2a 100644 --- a/src/eepp/ui/uispinbox.cpp +++ b/src/eepp/ui/uispinbox.cpp @@ -92,7 +92,7 @@ void UISpinBox::setTheme( UITheme * Theme ) { } if ( mFlags & UI_AUTO_SIZE ) { - mSize.setHeight( mInput->getSkinSize().getHeight() ); + setInternalHeight( mInput->getSkinSize().getHeight() ); } adjustChilds(); diff --git a/src/eepp/ui/uitab.cpp b/src/eepp/ui/uitab.cpp index 9c42bfc9f..ff49f63a4 100644 --- a/src/eepp/ui/uitab.cpp +++ b/src/eepp/ui/uitab.cpp @@ -73,11 +73,11 @@ void UITab::onStateChange() { setSize( mSize.getWidth(), getSkinSize( getSkin(), mSkinState->getState() ).getHeight() ); if ( mSkinState->getState() == UISkinState::StateSelected ) { - mTextBox->setColor( tTabW->mFontSelectedColor ); + mTextBox->setFontColor( tTabW->mFontSelectedColor ); } else if ( mSkinState->getState() == UISkinState::StateMouseEnter ) { - mTextBox->setColor( tTabW->mFontOverColor ); + mTextBox->setFontColor( tTabW->mFontOverColor ); } else { - mTextBox->setColor( tTabW->mFontColor ); + mTextBox->setFontColor( tTabW->mFontColor ); } } } diff --git a/src/eepp/ui/uitextbox.cpp b/src/eepp/ui/uitextbox.cpp index 6c41d9513..98a0d33c7 100644 --- a/src/eepp/ui/uitextbox.cpp +++ b/src/eepp/ui/uitextbox.cpp @@ -32,6 +32,31 @@ UITextBox::UITextBox( const UITextBox::CreateParams& Params ) : autoAlign(); } +UITextBox::UITextBox() : + UIComplexControl(), + mFontColor(), + mFontShadowColor(), + mFontSelectionBackColor(), + mAlignOffset( 0.f, 0.f ), + mSelCurInit( -1 ), + mSelCurEnd( -1 ) +{ + mTextCache = eeNew( TextCache, () ); + + if ( NULL != UIThemeManager::instance()->getDefaultFont() ) { + mTextCache->setFont( UIThemeManager::instance()->getDefaultFont() ); + } else { + eePRINTL( "UITextBox::UITextBox : Created a UI TextBox without a defined font." ); + } + + if ( NULL != UIThemeManager::instance()->getDefaultTheme() ) { + mTextCache->setColor( UIThemeManager::instance()->getDefaultTheme()->getFontColor() ); + mTextCache->setShadowColor( UIThemeManager::instance()->getDefaultTheme()->getFontShadowColor() ); + } + + autoAlign(); +} + UITextBox::~UITextBox() { eeSAFE_DELETE( mTextCache ); } @@ -53,15 +78,15 @@ void UITextBox::draw() { if ( mTextCache->getTextWidth() ) { if ( mFlags & UI_CLIP_ENABLE ) { UIManager::instance()->clipEnable( - mScreenPos.x + mPadding.Left, - mScreenPos.y + mPadding.Top, - mSize.getWidth() - mPadding.Left - mPadding.Right, - mSize.getHeight() - mPadding.Top - mPadding.Bottom + mScreenPos.x + mRealPadding.Left, + mScreenPos.y + mRealPadding.Top, + mSize.getWidth() - mRealPadding.Left - mRealPadding.Right, + mSize.getHeight() - mRealPadding.Top - mRealPadding.Bottom ); } mTextCache->setFlags( getFlags() ); - mTextCache->draw( (Float)mScreenPos.x + mAlignOffset.x + (Float)mPadding.Left, (Float)mScreenPos.y + mAlignOffset.y + (Float)mPadding.Top, Vector2f::One, 0.f, getBlendMode() ); + mTextCache->draw( (Float)mScreenPos.x + mAlignOffset.x + (Float)mRealPadding.Left, (Float)mScreenPos.y + mAlignOffset.y + (Float)mRealPadding.Top, Vector2f::One, 0.f, getBlendMode() ); if ( mFlags & UI_CLIP_ENABLE ) { UIManager::instance()->clipDisable(); @@ -105,22 +130,22 @@ void UITextBox::setText( const String& text ) { onTextChanged(); } -const ColorA& UITextBox::getColor() const { +const ColorA& UITextBox::getFontColor() const { return mFontColor; } -void UITextBox::setColor( const ColorA& color ) { +void UITextBox::setFontColor( const ColorA& color ) { mFontColor = color; mTextCache->setColor( color ); setAlpha( color.a() ); } -const ColorA& UITextBox::getShadowColor() const { +const ColorA& UITextBox::getFontShadowColor() const { return mFontShadowColor; } -void UITextBox::setShadowColor( const ColorA& color ) { +void UITextBox::setFontShadowColor( const ColorA& color ) { mFontShadowColor = color; mTextCache->setShadowColor( mFontColor ); } @@ -157,8 +182,8 @@ void UITextBox::shrinkText( const Uint32& MaxWidth ) { void UITextBox::autoSize() { if ( mFlags & UI_AUTO_SIZE ) { - mSize.setWidth( (int)mTextCache->getTextWidth() ); - mSize.setHeight( (int)mTextCache->getTextHeight() ); + setInternalWidth( (int)mTextCache->getTextWidth() ); + setInternalHeight( (int)mTextCache->getTextHeight() ); } } @@ -215,6 +240,7 @@ void UITextBox::onFontChanged() { void UITextBox::setPadding( const Recti& padding ) { mPadding = padding; + mRealPadding = dpToPxI( padding ); } const Recti& UITextBox::getPadding() const { @@ -333,10 +359,10 @@ void UITextBox::drawSelection() { lastEnd = end; } - P.drawRectangle( Rectf( mScreenPos.x + initPos.x + mAlignOffset.x + mPadding.Left, - mScreenPos.y + initPos.y - mTextCache->getFont()->getFontHeight() + mAlignOffset.y + mPadding.Top, - mScreenPos.x + endPos.x + mAlignOffset.x + mPadding.Left, - mScreenPos.y + endPos.y + mAlignOffset.y + mPadding.Top ) + P.drawRectangle( Rectf( mScreenPos.x + initPos.x + mAlignOffset.x + mRealPadding.Left, + mScreenPos.y + initPos.y - mTextCache->getFont()->getFontHeight() + mAlignOffset.y + mRealPadding.Top, + mScreenPos.x + endPos.x + mAlignOffset.x + mRealPadding.Left, + mScreenPos.y + endPos.y + mAlignOffset.y + mRealPadding.Top ) ); } while ( end != lastEnd ); } diff --git a/src/eepp/ui/uitextinput.cpp b/src/eepp/ui/uitextinput.cpp index fc1eb178d..039097e15 100644 --- a/src/eepp/ui/uitextinput.cpp +++ b/src/eepp/ui/uitextinput.cpp @@ -24,6 +24,21 @@ UITextInput::UITextInput( const UITextInput::CreateParams& Params ) : applyDefaultTheme(); } +UITextInput::UITextInput() : + UITextBox(), + mCursorPos(0), + mAllowEditing( true ), + mShowingWait( true ) +{ + mTextBuffer.start(); + mTextBuffer.setActive( false ); + mTextBuffer.setFreeEditing( true ); + mTextBuffer.setTextSelectionEnabled( isTextSelectionEnabled() ); + mTextBuffer.setReturnCallback( cb::Make0( this, &UITextInput::privOnPressEnter ) ); + + applyDefaultTheme(); +} + UITextInput::~UITextInput() { } diff --git a/src/eepp/ui/uitheme.cpp b/src/eepp/ui/uitheme.cpp index bc308f27a..f334e4ff9 100644 --- a/src/eepp/ui/uitheme.cpp +++ b/src/eepp/ui/uitheme.cpp @@ -319,9 +319,9 @@ bool UITheme::searchFilesOfElement( Graphics::TextureAtlas * SG, const std::stri return Found; } -UITheme::UITheme( const std::string& Name, const std::string& Abbr, Graphics::Font * defaultFont ) : +UITheme::UITheme(const std::string& name, const std::string& Abbr, Graphics::Font * defaultFont ) : ResourceManager ( false ), - mName( Name ), + mName( name ), mNameHash( String::hash( mName ) ), mAbbr( Abbr ), mTextureAtlas( NULL ), diff --git a/src/eepp/ui/uitooltip.cpp b/src/eepp/ui/uitooltip.cpp index 544de2959..2f0e97e2e 100644 --- a/src/eepp/ui/uitooltip.cpp +++ b/src/eepp/ui/uitooltip.cpp @@ -154,8 +154,8 @@ void UITooltip::setAlpha( const Float& alpha ) { void UITooltip::autoSize() { if ( mFlags & UI_AUTO_SIZE ) { - mSize.setWidth( (int)mTextCache->getTextWidth() + mPadding.Left + mPadding.Right ); - mSize.setHeight( (int)mTextCache->getTextHeight() + mPadding.Top + mPadding.Bottom ); + setInternalWidth( (int)mTextCache->getTextWidth() + mPadding.Left + mPadding.Right ); + setInternalHeight( (int)mTextCache->getTextHeight() + mPadding.Top + mPadding.Bottom ); } } diff --git a/src/eepp/ui/uiwinmenu.cpp b/src/eepp/ui/uiwinmenu.cpp index 1ea94e48c..622c3338f 100644 --- a/src/eepp/ui/uiwinmenu.cpp +++ b/src/eepp/ui/uiwinmenu.cpp @@ -58,7 +58,9 @@ void UIWinMenu::addMenuButton( const String& ButtonText, UIPopUpMenu * Menu ) { Button->setText( ButtonText ); Button->setVisible( true ); Button->setEnabled( true ); - Button->setThemeControl( mSkinState->getSkin()->getTheme(), "winmenubutton" ); + + if ( NULL != mSkinState && NULL != mSkinState->getSkin() ) + Button->setThemeControl( mSkinState->getSkin()->getTheme(), "winmenubutton" ); Menu->setVisible( false ); Menu->setEnabled( false ); diff --git a/src/test/eetest.cpp b/src/test/eetest.cpp index 15ab9911a..2881eb186 100644 --- a/src/test/eetest.cpp +++ b/src/test/eetest.cpp @@ -254,6 +254,8 @@ void EETest::createUI() { eePRINTL( "Texture Atlas Loading Time: %4.3f ms.", TE.getElapsed().asMilliseconds() ); + UIControl::PixelDensity = 1; + UIManager::instance()->init(); //UI_MANAGER_HIGHLIGHT_FOCUS | UI_MANAGER_HIGHLIGHT_OVER //mTheme = UITheme::LoadFromPath( eeNew( UIdefaultTheme, ( "uitheme", "uitheme" ) ), MyPath + "uitheme/" ); @@ -266,7 +268,7 @@ void EETest::createUI() { UIThemeManager::instance()->setDefaultEffectsEnabled( true ); UIThemeManager::instance()->setDefaultFont( TTF ); UIThemeManager::instance()->setDefaultTheme( "uitheme" ); - + /**/ UIControl::CreateParams Params( UIManager::instance()->getMainControl(), Vector2i(0,0), Sizei( 530, 380 ), UI_FILL_BACKGROUND | UI_CLIP_ENABLE | UI_BORDER ); Params.Border.setWidth( 2 ); @@ -574,6 +576,30 @@ void EETest::createUI() { C = reinterpret_cast ( C->getParent() ); eePRINTL( "CreateUI time: %4.3f ms.", TE.getElapsed().asMilliseconds() ); + /**/ + + UIRadioButton * ctrl = eeNew( UIRadioButton, () ); + ctrl->setPosition( 100, 100 ); + ctrl->setSize( 320, 32 ); + ctrl->setBackgroundFillEnabled( true )->setColor( 0x33333333 ); + ctrl->setBorderEnabled( true )->setColor( 0x66666666 ); + ctrl->setVisible( true ); + ctrl->setEnabled( true ); + ctrl->setText( "Happy TextBox :)" ); + ctrl->setFontColor( 0x000000FF ); + + UIGfx * gfx = eeNew( UIGfx, () ); + gfx->setPosition( 100, 132 ); + gfx->setBackgroundFillEnabled( true )->setColor( 0x33333333 ); + gfx->setSubTexture( mTheme->getIconByName( "ok" ) ); + gfx->setVisible( true ); + gfx->setEnabled( true ); + + UISlider * slider = eeNew( UISlider, () ); + slider->setPosition( 50, 100 ); + slider->setSize( 32, 100 ); + slider->setVisible( true ); + slider->setEnabled( true ); } void EETest::createMapEditor() {