From aaef8b1716cf46d4cd589972ffa01b46589e2c4b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mart=C3=AD=C2=ADn=20Lucas=20Golini?= Date: Sat, 25 Feb 2017 03:42:24 -0300 Subject: [PATCH] Padding fixes. --HG-- branch : dev --- include/eepp/graphics/pixeldensity.hpp | 4 ++++ include/eepp/graphics/subtexture.hpp | 6 ++++-- include/eepp/ui/uitextbox.hpp | 2 -- include/eepp/ui/uitooltip.hpp | 9 ++++---- src/eepp/graphics/pixeldensity.cpp | 8 +++++++ src/eepp/graphics/subtexture.cpp | 6 ++++++ src/eepp/ui/uicontrol.cpp | 8 +++---- src/eepp/ui/uilistbox.cpp | 2 +- src/eepp/ui/uimenu.cpp | 2 +- src/eepp/ui/uipushbutton.cpp | 28 +----------------------- src/eepp/ui/uitextbox.cpp | 5 ----- src/eepp/ui/uitextedit.cpp | 2 +- src/eepp/ui/uitextinput.cpp | 2 +- src/eepp/ui/uitooltip.cpp | 30 +++++++++++++++----------- src/test/eetest.cpp | 4 ++-- 15 files changed, 55 insertions(+), 63 deletions(-) diff --git a/include/eepp/graphics/pixeldensity.hpp b/include/eepp/graphics/pixeldensity.hpp index 116be3d16..42c9907be 100644 --- a/include/eepp/graphics/pixeldensity.hpp +++ b/include/eepp/graphics/pixeldensity.hpp @@ -73,6 +73,10 @@ class EE_API PixelDensity { static Vector2i dpToPxI( Vector2i pos ); static Vector2i pxToDpI( Vector2i pos ); + + static Vector2f dpToPx( Vector2f pos ); + + static Vector2f pxToDp( Vector2f pos ); protected: static Float sPixelDensity; }; diff --git a/include/eepp/graphics/subtexture.hpp b/include/eepp/graphics/subtexture.hpp index 3b3776504..7ad84eb36 100644 --- a/include/eepp/graphics/subtexture.hpp +++ b/include/eepp/graphics/subtexture.hpp @@ -71,7 +71,7 @@ class EE_API SubTexture { /** Sets the Destination Size of the SubTexture. * The size can be different from the original size of the SubTexture. - * For example if the SubTexture width is 32 pixels, by default the destination width is 32 pixels, but it can be changed to anything wanted. */ + * For example if the SubTexture width is 32 pixels, by default the destination width is 32 pixels, but it can be changed to anything want. */ void setDestSize( const Sizef& destSize ); /** @return The SubTexture default offset. The offset is added to the position passed when is drawed. */ @@ -141,12 +141,14 @@ class EE_API SubTexture { * This will get the Texture from VRAM ( it will not work with OpenGL ES ) */ bool saveToFile( const std::string& filepath, const EE_SAVE_TYPE& Format ); - /** Sets the Destination Size as the Source Rect Size ( the real size of the SubTexture ). */ + /** Sets the Destination Size as the Source Rect Size ( the real size of the SubTexture ) multiplied by the pixel density. */ void resetDestSize(); Float getPixelDensity() const; void setPixelDensity( const Float & pixelDensity ); + + Sizei getDpSize(); protected: Uint8 * mPixels; Uint8 * mAlpha; diff --git a/include/eepp/ui/uitextbox.hpp b/include/eepp/ui/uitextbox.hpp index abb3e4d0a..c34fcdc2e 100644 --- a/include/eepp/ui/uitextbox.hpp +++ b/include/eepp/ui/uitextbox.hpp @@ -72,8 +72,6 @@ class EE_API UITextBox : public UIComplexControl { virtual void setPadding( const Recti& padding ); - virtual void setPixelsPadding( const Recti& padding ); - const Recti& getPadding() const; virtual void setTheme( UITheme * Theme ); diff --git a/include/eepp/ui/uitooltip.hpp b/include/eepp/ui/uitooltip.hpp index 4c897e33f..738058f51 100644 --- a/include/eepp/ui/uitooltip.hpp +++ b/include/eepp/ui/uitooltip.hpp @@ -89,7 +89,7 @@ class EE_API UITooltip : public UIControlAnim { const int& getNumLines() const; - const Vector2f& getAlignOffset() const; + Vector2f getAlignOffset(); void setTooltipTime( const Time& Time ); @@ -100,9 +100,10 @@ class EE_API UITooltip : public UIControlAnim { TextCache * mTextCache; ColorA mFontColor; ColorA mFontShadowColor; - Vector2f mAlignOffset; - Recti mPadding; - Time mTooltipTime; + Vector2f mAlignOffset; + Recti mPadding; + Recti mRealPadding; + Time mTooltipTime; UIControl * mTooltipOf; virtual void onSizeChange(); diff --git a/src/eepp/graphics/pixeldensity.cpp b/src/eepp/graphics/pixeldensity.cpp index 37de0165a..679ec62db 100644 --- a/src/eepp/graphics/pixeldensity.cpp +++ b/src/eepp/graphics/pixeldensity.cpp @@ -80,4 +80,12 @@ Vector2i PixelDensity::pxToDpI( Vector2i pos ) { return Sizei( pxToDpI( pos.x ), pxToDpI( pos.y ) ); } +Vector2f PixelDensity::dpToPx( Vector2f pos ) { + return Vector2f( dpToPx( pos.x ), dpToPx( pos.y ) ); +} + +Vector2f PixelDensity::pxToDp( Vector2f pos ) { + return Vector2f( pxToDp( pos.x ), pxToDp( pos.y ) ); +} + }} diff --git a/src/eepp/graphics/subtexture.cpp b/src/eepp/graphics/subtexture.cpp index 609d48591..1b9867fbd 100644 --- a/src/eepp/graphics/subtexture.cpp +++ b/src/eepp/graphics/subtexture.cpp @@ -388,4 +388,10 @@ void SubTexture::setPixelDensity( const Float & pixelDensity ) { resetDestSize(); } +Sizei SubTexture::getDpSize() { + Sizei Size = mSrcRect.getSize(); + + return Sizei( (Int32)( (Float)Size.getWidth() / mPixelDensity ), (Int32)( (Float)Size.getHeight() / mPixelDensity ) ); +} + }} diff --git a/src/eepp/ui/uicontrol.cpp b/src/eepp/ui/uicontrol.cpp index 6c74c0957..92fc2f681 100644 --- a/src/eepp/ui/uicontrol.cpp +++ b/src/eepp/ui/uicontrol.cpp @@ -1279,28 +1279,28 @@ Recti UIControl::makePadding( bool PadLeft, bool PadRight, bool PadTop, bool Pad tSubTexture = tComplex->getSubTextureSide( UISkinState::StateNormal, UISkinComplex::Left ); if ( NULL != tSubTexture ) - tPadding.Left = tSubTexture->getSize().getWidth(); + tPadding.Left = tSubTexture->getDpSize().getWidth(); } if ( PadRight ) { tSubTexture = tComplex->getSubTextureSide( UISkinState::StateNormal, UISkinComplex::Right ); if ( NULL != tSubTexture ) - tPadding.Right = tSubTexture->getSize().getWidth(); + tPadding.Right = tSubTexture->getDpSize().getWidth(); } if ( PadTop ) { tSubTexture = tComplex->getSubTextureSide( UISkinState::StateNormal, UISkinComplex::Up ); if ( NULL != tSubTexture ) - tPadding.Top = tSubTexture->getSize().getHeight(); + tPadding.Top = tSubTexture->getDpSize().getHeight(); } if ( PadBottom ) { tSubTexture = tComplex->getSubTextureSide( UISkinState::StateNormal, UISkinComplex::Down ); if ( NULL != tSubTexture ) - tPadding.Bottom = tSubTexture->getSize().getHeight(); + tPadding.Bottom = tSubTexture->getDpSize().getHeight(); } } } diff --git a/src/eepp/ui/uilistbox.cpp b/src/eepp/ui/uilistbox.cpp index 28e63089d..0f2c948f5 100644 --- a/src/eepp/ui/uilistbox.cpp +++ b/src/eepp/ui/uilistbox.cpp @@ -174,7 +174,7 @@ void UIListBox::setTheme( UITheme * Theme ) { void UIListBox::autoPadding() { if ( mFlags & UI_AUTO_PADDING ) { - mPaddingContainer = PixelDensity::pxToDpI( makePadding() ); + mPaddingContainer = makePadding(); } } diff --git a/src/eepp/ui/uimenu.cpp b/src/eepp/ui/uimenu.cpp index 3e8f7c082..4679fe531 100644 --- a/src/eepp/ui/uimenu.cpp +++ b/src/eepp/ui/uimenu.cpp @@ -346,7 +346,7 @@ void UIMenu::onSizeChange() { void UIMenu::autoPadding() { if ( mFlags & UI_AUTO_PADDING ) { - mPadding = PixelDensity::pxToDpI( makePadding() ); + mPadding = makePadding(); } } diff --git a/src/eepp/ui/uipushbutton.cpp b/src/eepp/ui/uipushbutton.cpp index 23d0456df..5515c7005 100644 --- a/src/eepp/ui/uipushbutton.cpp +++ b/src/eepp/ui/uipushbutton.cpp @@ -70,7 +70,7 @@ void UIPushButton::onSizeChange() { mTextBox->setPosition( 0, 0 ); } - mIcon->setPosition( PixelDensity::pxToDpI( mIconSpace ), 0 ); + mIcon->setPosition( mIconSpace, 0 ); mIcon->centerVertical(); if ( NULL != mTextBox ) { @@ -93,32 +93,6 @@ void UIPushButton::onSizeChange() { if ( NULL != mTextBox && 0 == mTextBox->getText().size() ) { mIcon->center(); } - - /** Auto Size only for height? May be set another flag to this... */ - /** - if ( mFlags & UI_AUTO_SIZE ) { - if ( NULL != mTextBox ) { - Recti P = makePadding(); - - setInternalHeight( mIcon->getSize().getHeight() + P.Top + P.Bottom ); - - if ( 0 == mTextBox->getText().size() ) { - setInternalWidth( mIcon->getSize().getWidth() + P.Left + P.Right ); - - mIcon->center(); - } else { - setInternalWidth( mIconSpace + mIcon->setPosition(.x + mIcon->getSize().getWidth() + mTextBox->getSize().getWidth() ); - - if ( mSize.getHeight() < P.Top + P.Bottom + mTextBox->getTextHeight() ) - setInternalHeight( P.Top + P.Bottom + mTextBox->getTextHeight() ); - } - } - } else { - if ( NULL != mTextBox && 0 == mTextBox->getText().size() ) { - mIcon->center(); - } - } - */ } void UIPushButton::setTheme( UITheme * Theme ) { diff --git a/src/eepp/ui/uitextbox.cpp b/src/eepp/ui/uitextbox.cpp index 72e2448d9..64f85d581 100644 --- a/src/eepp/ui/uitextbox.cpp +++ b/src/eepp/ui/uitextbox.cpp @@ -243,11 +243,6 @@ void UITextBox::setPadding( const Recti& padding ) { mRealPadding = PixelDensity::dpToPxI( padding ); } -void UITextBox::setPixelsPadding( const Recti& padding ) { - mPadding = PixelDensity::pxToDpI( padding ); - mRealPadding = padding; -} - const Recti& UITextBox::getPadding() const { return mPadding; } diff --git a/src/eepp/ui/uitextedit.cpp b/src/eepp/ui/uitextedit.cpp index 94e4a84ca..7ddd5b239 100644 --- a/src/eepp/ui/uitextedit.cpp +++ b/src/eepp/ui/uitextedit.cpp @@ -230,7 +230,7 @@ void UITextEdit::scrollbarsSet() { void UITextEdit::autoPadding() { if ( mFlags & UI_AUTO_PADDING ) { - mPadding = makePadding(); + mPadding = PixelDensity::dpToPxI( makePadding() ); } } diff --git a/src/eepp/ui/uitextinput.cpp b/src/eepp/ui/uitextinput.cpp index 576ded3ed..47128dfc4 100644 --- a/src/eepp/ui/uitextinput.cpp +++ b/src/eepp/ui/uitextinput.cpp @@ -202,7 +202,7 @@ void UITextInput::autoSize() { void UITextInput::autoPadding() { if ( mFlags & UI_AUTO_PADDING ) { - setPixelsPadding( makePadding( true, true, false, false ) ); + setPadding( makePadding( true, true, false, false ) ); } } diff --git a/src/eepp/ui/uitooltip.cpp b/src/eepp/ui/uitooltip.cpp index 4f6c677fd..92d004a10 100644 --- a/src/eepp/ui/uitooltip.cpp +++ b/src/eepp/ui/uitooltip.cpp @@ -14,6 +14,8 @@ UITooltip::UITooltip( UITooltip::CreateParams& Params, UIControl * TooltipOf ) : mTooltipTime( Time::Zero ), mTooltipOf( TooltipOf ) { + setPadding( mPadding ); + mTextCache = eeNew( TextCache, () ); mTextCache->setFont( Params.Font ); mTextCache->setColor( mFontColor ); @@ -62,7 +64,7 @@ void UITooltip::setTheme( UITheme * Theme ) { void UITooltip::autoPadding() { if ( mFlags & UI_AUTO_PADDING ) { - mPadding = makePadding( true, true, true, true ); + setPadding( makePadding( true, true, true, true ) ); } } @@ -155,37 +157,37 @@ void UITooltip::setAlpha( const Float& alpha ) { void UITooltip::autoSize() { if ( mFlags & UI_AUTO_SIZE ) { setPixelsSize( - (int)mTextCache->getTextWidth() + mPadding.Left + mPadding.Right, - (int)mTextCache->getTextHeight() + mPadding.Top + mPadding.Bottom + (int)mTextCache->getTextWidth() + mRealPadding.Left + mRealPadding.Right, + (int)mTextCache->getTextHeight() + mRealPadding.Top + mRealPadding.Bottom ); } } void UITooltip::autoAlign() { - Uint32 Width = mRealSize.getWidth() - mPadding.Left - mPadding.Right; - Uint32 Height = mRealSize.getHeight() - mPadding.Top - mPadding.Bottom; + Uint32 Width = mRealSize.getWidth() - mRealPadding.Left - mRealPadding.Right; + Uint32 Height = mRealSize.getHeight() - mRealPadding.Top - mRealPadding.Bottom; switch ( fontHAlignGet( getFlags() ) ) { case UI_HALIGN_CENTER: - mAlignOffset.x = mPadding.Left + (Float)( (Int32)( Width - mTextCache->getTextWidth() ) / 2 ); + mAlignOffset.x = mRealPadding.Left + (Float)( (Int32)( Width - mTextCache->getTextWidth() ) / 2 ); break; case UI_HALIGN_RIGHT: - mAlignOffset.x = ( (Float)Width - (Float)mTextCache->getTextWidth() ) - mPadding.Right; + mAlignOffset.x = ( (Float)Width - (Float)mTextCache->getTextWidth() ) - mRealPadding.Right; break; case UI_HALIGN_LEFT: - mAlignOffset.x = mPadding.Left; + mAlignOffset.x = mRealPadding.Left; break; } switch ( fontVAlignGet( getFlags() ) ) { case UI_VALIGN_CENTER: - mAlignOffset.y = mPadding.Top + (Float)( ( (Int32)( Height - mTextCache->getTextHeight() ) ) / 2 ); + mAlignOffset.y = mRealPadding.Top + (Float)( ( (Int32)( Height - mTextCache->getTextHeight() ) ) / 2 ); break; case UI_VALIGN_BOTTOM: - mAlignOffset.y = ( (Float)Height - (Float)mTextCache->getTextHeight() ) - mPadding.Bottom; + mAlignOffset.y = ( (Float)Height - (Float)mTextCache->getTextHeight() ) - mRealPadding.Bottom; break; case UI_VALIGN_TOP: - mAlignOffset.y = mPadding.Top; + mAlignOffset.y = mRealPadding.Top; break; } } @@ -210,6 +212,8 @@ void UITooltip::onFontChanged() { void UITooltip::setPadding( const Recti& padding ) { mPadding = padding; + mRealPadding = PixelDensity::dpToPxI( mPadding ); + } const Recti& UITooltip::getPadding() const { @@ -232,8 +236,8 @@ const int& UITooltip::getNumLines() const { return mTextCache->getNumLines(); } -const Vector2f& UITooltip::getAlignOffset() const { - return mAlignOffset; +Vector2f UITooltip::getAlignOffset() { + return PixelDensity::pxToDp( mAlignOffset ); } void UITooltip::setTooltipTime( const Time& Time ) { diff --git a/src/test/eetest.cpp b/src/test/eetest.cpp index ef2cbf4d9..c80e07eff 100644 --- a/src/test/eetest.cpp +++ b/src/test/eetest.cpp @@ -256,11 +256,11 @@ void EETest::createUI() { Clock TE; mThemeName = "uitheme"; -/* + if ( PixelDensity::getPixelDensity() == 2 ) { mThemeName += "2x"; } -*/ + createUIThemeTextureAtlas(); eePRINTL( "Texture Atlas Loading Time: %4.3f ms.", TE.getElapsed().asMilliseconds() );