Padding fixes.

--HG--
branch : dev
This commit is contained in:
Martí­n Lucas Golini
2017-02-25 03:42:24 -03:00
parent dce42a05d4
commit aaef8b1716
15 changed files with 55 additions and 63 deletions

View File

@@ -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;
};

View File

@@ -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;

View File

@@ -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 );

View File

@@ -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();

View File

@@ -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 ) );
}
}}

View File

@@ -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 ) );
}
}}

View File

@@ -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();
}
}
}

View File

@@ -174,7 +174,7 @@ void UIListBox::setTheme( UITheme * Theme ) {
void UIListBox::autoPadding() {
if ( mFlags & UI_AUTO_PADDING ) {
mPaddingContainer = PixelDensity::pxToDpI( makePadding() );
mPaddingContainer = makePadding();
}
}

View File

@@ -346,7 +346,7 @@ void UIMenu::onSizeChange() {
void UIMenu::autoPadding() {
if ( mFlags & UI_AUTO_PADDING ) {
mPadding = PixelDensity::pxToDpI( makePadding() );
mPadding = makePadding();
}
}

View File

@@ -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 ) {

View File

@@ -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;
}

View File

@@ -230,7 +230,7 @@ void UITextEdit::scrollbarsSet() {
void UITextEdit::autoPadding() {
if ( mFlags & UI_AUTO_PADDING ) {
mPadding = makePadding();
mPadding = PixelDensity::dpToPxI( makePadding() );
}
}

View File

@@ -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 ) );
}
}

View File

@@ -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 ) {

View File

@@ -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() );