From cad843f58dbee30b5cd1a52dab9518ddfa8ea08b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mart=C3=ADn=20Lucas=20Golini?= Date: Sat, 10 Jun 2017 04:20:18 -0300 Subject: [PATCH] Some minor fixes. --HG-- branch : dev --- include/eepp/math/polygon2.hpp | 20 ++++++++++---------- include/eepp/math/rect.hpp | 2 +- include/eepp/math/vector2.hpp | 32 +++++++++++++++++++++++--------- src/eepp/ui/uicombobox.cpp | 8 ++++---- src/eepp/ui/uimenu.cpp | 2 +- src/eepp/ui/uimenuitem.cpp | 3 +++ src/eepp/ui/uimenuseparator.cpp | 2 +- src/eepp/ui/uiprogressbar.cpp | 3 +++ src/eepp/ui/uipushbutton.cpp | 2 +- src/eepp/ui/uiscrollview.cpp | 16 ++++++++++------ src/eepp/ui/uiselectbutton.cpp | 3 +++ src/eepp/ui/uiskincomplex.cpp | 3 ++- src/eepp/ui/uislider.cpp | 2 +- src/eepp/ui/uitab.cpp | 6 +++--- src/eepp/ui/uitextedit.cpp | 3 ++- src/eepp/ui/uiwinmenu.cpp | 4 ++-- src/test/eetest.cpp | 9 ++++++--- 17 files changed, 76 insertions(+), 44 deletions(-) diff --git a/include/eepp/math/polygon2.hpp b/include/eepp/math/polygon2.hpp index f0cee0a51..96f2b010a 100755 --- a/include/eepp/math/polygon2.hpp +++ b/include/eepp/math/polygon2.hpp @@ -308,23 +308,23 @@ bool Polygon2::intersect( const Polygon2& p1 ) { vAxis = Line2( Vector[i], Vector[n] ).getNormal(); - min0 = vAxis.Dot( Vector[0] ); + min0 = vAxis.dot( Vector[0] ); max0 = min0; for (j = 1; j < this->getSize(); j++) { - t = vAxis.Dot( Vector[j] ); + t = vAxis.dot( Vector[j] ); if (t < min0) min0 = t; if (t > max0) max0 = t; } - min1 = vAxis.Dot( p1[0] ); + min1 = vAxis.dot( p1[0] ); max1 = min1; for (j = 1; j < p1.getSize(); j++) { - t = vAxis.Dot( p1[j] ); + t = vAxis.dot( p1[j] ); if (t < min1) min1 = t; if (t > max1) max1 = t; } - sOffset = vAxis.Dot( vOffset ); + sOffset = vAxis.dot( vOffset ); min0 += sOffset; max0 += sOffset; @@ -339,23 +339,23 @@ bool Polygon2::intersect( const Polygon2& p1 ) { vAxis = Line2( p1[i], p1[n] ).getNormal(); - min0 = vAxis.Dot( Vector[0] ); + min0 = vAxis.dot( Vector[0] ); max0 = min0; for (j = 1; j < this->getSize(); j++) { - t = vAxis.Dot( Vector[j] ); + t = vAxis.dot( Vector[j] ); if (t < min0) min0 = t; if (t > max0) max0 = t; } - min1 = vAxis.Dot( p1[0] ); + min1 = vAxis.dot( p1[0] ); max1 = min1; for (j = 1; j < p1.getSize(); j++) { - t = vAxis.Dot( p1[j] ); + t = vAxis.dot( p1[j] ); if (t < min1) min1 = t; if (t > max1) max1 = t; } - sOffset = vAxis.Dot( vOffset ); + sOffset = vAxis.dot( vOffset ); min0 += sOffset; max0 += sOffset; diff --git a/include/eepp/math/rect.hpp b/include/eepp/math/rect.hpp index b94b978a7..6059ad2cd 100755 --- a/include/eepp/math/rect.hpp +++ b/include/eepp/math/rect.hpp @@ -258,7 +258,7 @@ bool tRECT::intersectsSegment( const Vector2& a, const Vector2& b ) { Vector2 offset( ( a.x + b.x - Right - Left ), ( a.y + b.y - Bottom - Top ) ); Vector2 extents( Right - Left, Bottom - Top ); - return ( eeabs( axis.Dot( offset ) ) < eeabs( axis.x * extents.x ) + eeabs( axis.y * extents.y ) ); + return ( eeabs( axis.dot( offset ) ) < eeabs( axis.x * extents.x ) + eeabs( axis.y * extents.y ) ); } return false; diff --git a/include/eepp/math/vector2.hpp b/include/eepp/math/vector2.hpp index 997c4d664..7d9958753 100755 --- a/include/eepp/math/vector2.hpp +++ b/include/eepp/math/vector2.hpp @@ -24,10 +24,10 @@ class Vector2 { Vector2 copy(); /** @return The Dot product of the 2D vectors. */ - T Dot( const Vector2& V2 ); + T dot( const Vector2& V2 ); /** @return The Cross product of the 2D vectors. */ - T Cross( const Vector2& V2 ); + T cross( const Vector2& V2 ); /** @return The perpendicular vector */ Vector2 perp(); @@ -92,6 +92,10 @@ class Vector2 { /** Scales the vector position against another vector */ void scale( const T& scale, const Vector2& Center ); + Vector2 ceil(); + + Vector2 floor(); + T x; T y; private: @@ -119,7 +123,7 @@ Vector2 Vector2::lerpConst( const Vector2& Vec, T Dist ) { template Vector2 Vector2::sphericalLerp( const Vector2& Vec, T Time ) { - T omega = eeacos( Dot( Vec ) ); + T omega = eeacos( dot( Vec ) ); if( omega ) { T denom = 1 / eesin( omega ); @@ -132,7 +136,7 @@ Vector2 Vector2::sphericalLerp( const Vector2& Vec, T Time ) { template Vector2 Vector2::sphericalLerpConst( const Vector2& Vec, T Angle ) { - T angle = eeacos( Dot( Vec ) ); + T angle = eeacos( dot( Vec ) ); return lerp( Vec, ( ( Angle < angle ) ? Angle : angle ) / angle ); } @@ -334,12 +338,12 @@ void Vector2::scale( const T& scale, const Vector2& Center ) { template -T Vector2::Dot( const Vector2& V2 ) { +T Vector2::dot( const Vector2& V2 ) { return x * V2.x + y * V2.y; } template -T Vector2::Cross( const Vector2& V2 ) { +T Vector2::cross( const Vector2& V2 ) { return x * V2.x - y * V2.y; } @@ -365,12 +369,12 @@ Vector2 Vector2::unrotate( const Vector2& V2 ) { template T Vector2::length() { - return eesqrt( Dot( Vector2( x , y ) ) ); + return eesqrt( dot( Vector2( x , y ) ) ); } template T Vector2::lengthSq() { - return Dot( Vector2( x , y ) ); + return dot( Vector2( x , y ) ); } template @@ -407,7 +411,7 @@ T Vector2::distanceSq( const Vector2& Vec ) { template void Vector2::clamp( T len ) { - if ( Dot( Vector2( x, y ) ) > len * len ) { + if ( dot( Vector2( x, y ) ) > len * len ) { normalize(); x *= len; @@ -415,6 +419,16 @@ void Vector2::clamp( T len ) { } } +template +Vector2 Vector2::ceil() { + return Vector2( eeceil( x ), eeceil( y ) ); +} + +template +Vector2 Vector2::floor() { + return Vector2( eefloor( x ), eefloor( y ) ); +} + template bool Vector2::nearDist( const Vector2& Vec, T Dist ) { return 0 != ( distanceSq( Vec ) < Dist * Dist ); diff --git a/src/eepp/ui/uicombobox.cpp b/src/eepp/ui/uicombobox.cpp index 955cf2f1b..49cb89d81 100644 --- a/src/eepp/ui/uicombobox.cpp +++ b/src/eepp/ui/uicombobox.cpp @@ -53,11 +53,11 @@ void UIComboBox::setTheme( UITheme * Theme ) { mButton->setThemeSkin( Theme, "combobox_button" ); if ( NULL != mDropDownList->getSkin() ) { - setInternalHeight( mDropDownList->getSkin()->getSize().getHeight() ); + setInternalHeight( mDropDownList->getSkinSize().getHeight() ); } if ( NULL != mButton->getSkin() ) { - mButton->setSize( mButton->getSkin()->getSize() ); + mButton->setSize( mButton->getSkinSize() ); } updateControls(); @@ -80,7 +80,7 @@ void UIComboBox::loadFromXmlNode(const pugi::xml_node& node) { } void UIComboBox::updateControls() { - if ( ( mFlags & UI_AUTO_SIZE ) || mSize.getHeight() < mDropDownList->getSkin()->getSize().getHeight() ) { + if ( ( mFlags & UI_AUTO_SIZE ) || mSize.getHeight() < mDropDownList->getSkinSize().getHeight() ) { onAutoSize(); } @@ -114,7 +114,7 @@ void UIComboBox::onPositionChange() { } void UIComboBox::onAutoSize() { - setInternalHeight( mDropDownList->getSkin()->getSize().getHeight() ); + setInternalHeight( mDropDownList->getSkinSize().getHeight() ); } }} diff --git a/src/eepp/ui/uimenu.cpp b/src/eepp/ui/uimenu.cpp index 35a3e630c..9f8855db2 100644 --- a/src/eepp/ui/uimenu.cpp +++ b/src/eepp/ui/uimenu.cpp @@ -186,7 +186,7 @@ Uint32 UIMenu::addSeparator() { UIMenuSeparator * Control = UIMenuSeparator::New(); Control->setParent( this ); Control->setPosition( mStyleConfig.Padding.Left, mStyleConfig.Padding.Top + mNextPosY ); - Control->setSize( mSize.getWidth() - mStyleConfig.Padding.Left - mStyleConfig.Padding.Right, 3 ); + Control->setSize( mSize.getWidth() - mStyleConfig.Padding.Left - mStyleConfig.Padding.Right, Control->getSkinSize().getHeight() ); mNextPosY += Control->getSize().getHeight(); diff --git a/src/eepp/ui/uimenuitem.cpp b/src/eepp/ui/uimenuitem.cpp index 66649744c..fa61084b2 100644 --- a/src/eepp/ui/uimenuitem.cpp +++ b/src/eepp/ui/uimenuitem.cpp @@ -41,6 +41,9 @@ Uint32 UIMenuItem::onMouseEnter( const Vector2i &Pos, const Uint32 Flags ) { void UIMenuItem::onStateChange() { UIMenu * tMenu = reinterpret_cast ( getParent() ); + if ( NULL == mSkinState ) + return; + if ( mSkinState->getState() == UISkinState::StateSelected ) { mTextBox->setFontColor( tMenu->getFontStyleConfig().getFontSelectedColor() ); } else if ( mSkinState->getState() == UISkinState::StateMouseEnter ) { diff --git a/src/eepp/ui/uimenuseparator.cpp b/src/eepp/ui/uimenuseparator.cpp index eab9c211f..363ba82e2 100644 --- a/src/eepp/ui/uimenuseparator.cpp +++ b/src/eepp/ui/uimenuseparator.cpp @@ -29,7 +29,7 @@ void UIMenuSeparator::setTheme( UITheme * Theme ) { setThemeSkin( Theme, "separator" ); if ( NULL != getSkin() ) { - setSize( Sizei( mSize.getWidth(), getSkin()->getSize().getHeight() ) ); + setSize( Sizei( mSize.getWidth(), getSkinSize().getHeight() ) ); } } diff --git a/src/eepp/ui/uiprogressbar.cpp b/src/eepp/ui/uiprogressbar.cpp index dd76ff918..6ac0eb28d 100644 --- a/src/eepp/ui/uiprogressbar.cpp +++ b/src/eepp/ui/uiprogressbar.cpp @@ -80,6 +80,9 @@ void UIProgressBar::draw() { void UIProgressBar::update() { UIControlAnim::update(); + if ( NULL == mFillerSkin ) + return; + mOffset += mStyleConfig.MovementSpeed * (Float)( getElapsed().asSeconds() ); Sizei rSize( PixelDensity::dpToPxI( mFillerSkin->getSize() ) ); diff --git a/src/eepp/ui/uipushbutton.cpp b/src/eepp/ui/uipushbutton.cpp index 828b67130..47c73c162 100644 --- a/src/eepp/ui/uipushbutton.cpp +++ b/src/eepp/ui/uipushbutton.cpp @@ -138,7 +138,7 @@ void UIPushButton::onThemeLoaded() { } if ( ( mFlags & UI_AUTO_SIZE ) && NULL != getSkin() ) { - setInternalHeight( getSkin()->getSize().getHeight() ); + setInternalHeight( getSkinSize().getHeight() ); } autoPadding(); diff --git a/src/eepp/ui/uiscrollview.cpp b/src/eepp/ui/uiscrollview.cpp index d01b83bef..25fd18c75 100644 --- a/src/eepp/ui/uiscrollview.cpp +++ b/src/eepp/ui/uiscrollview.cpp @@ -177,16 +177,20 @@ void UIScrollView::containerUpdate() { mVScroll->setSize( mVScroll->getSize().getWidth(), mSize.getHeight() ); mHScroll->setSize( mSize.getWidth() - ( mVScroll->isVisible() ? mVScroll->getSize().getWidth() : 0 ), mHScroll->getSize().getHeight() ); - mVScroll->setPageStep( (Float)mContainer->getSize().getHeight() / (Float)mScrollView->getSize().getHeight()); - mHScroll->setPageStep( (Float)mContainer->getSize().getWidth() / (Float)mScrollView->getSize().getWidth() ); + if ( mVScroll->isVisible() && 0 != mScrollView->getSize().getHeight() ) + mVScroll->setPageStep( (Float)mContainer->getSize().getHeight() / (Float)mScrollView->getSize().getHeight() ); + + if ( mHScroll->isVisible() && 0 != mScrollView->getSize().getWidth() ) { + mHScroll->setPageStep( (Float)mContainer->getSize().getWidth() / (Float)mScrollView->getSize().getWidth() ); + } updateScroll(); } void UIScrollView::updateScroll() { mScrollView->setPosition( - -( mHScroll->getSlider()->getValue() * ( mScrollView->getSize().getWidth() - mSize.getWidth() ) ), - -( mVScroll->getSlider()->getValue() * ( mScrollView->getSize().getHeight() - mSize.getHeight() ) ) + mHScroll->isVisible() ? -( mHScroll->getSlider()->getValue() * eemax( 0, mScrollView->getSize().getWidth() - mSize.getWidth() ) ) : 0 , + mVScroll->isVisible() ? -( mVScroll->getSlider()->getValue() * eemax( 0, mScrollView->getSize().getHeight() - mSize.getHeight() ) ) : 0 ); } @@ -199,10 +203,10 @@ void UIScrollView::onScrollViewSizeChange(const UIEvent * Event) { } void UIScrollView::onTouchDragValueChange( Vector2f diff ) { - if ( mVScroll->isEnabled() ) + if ( mVScroll->isEnabled() && 0 != mScrollView->getSize().getHeight() ) mVScroll->setValue( mVScroll->getValue() + ( -diff.y / (Float)( mScrollView->getSize().getHeight() ) ) ); - if ( mHScroll->isEnabled() ) + if ( mHScroll->isEnabled() && 0 != mScrollView->getSize().getWidth() ) mHScroll->setValue( mHScroll->getValue() + ( -diff.x / (Float)( mScrollView->getSize().getWidth() ) ) ); } diff --git a/src/eepp/ui/uiselectbutton.cpp b/src/eepp/ui/uiselectbutton.cpp index 20930039d..967a7e876 100644 --- a/src/eepp/ui/uiselectbutton.cpp +++ b/src/eepp/ui/uiselectbutton.cpp @@ -49,6 +49,9 @@ bool UISelectButton::selected() const { } void UISelectButton::onStateChange() { + if ( NULL == mSkinState ) + return; + if ( mSkinState->getState() != UISkinState::StateSelected && selected() ) { if ( mSkinState->stateExists( UISkinState::StateSelected ) ) { setSkinState( UISkinState::StateSelected ); diff --git a/src/eepp/ui/uiskincomplex.cpp b/src/eepp/ui/uiskincomplex.cpp index bf82a440b..01539a3b5 100644 --- a/src/eepp/ui/uiskincomplex.cpp +++ b/src/eepp/ui/uiskincomplex.cpp @@ -33,7 +33,8 @@ UISkinComplex::~UISkinComplex() { } -#define DRAWABLE_PX_SIZE PixelDensity::dpToPx( tDrawable->getSize() ) +#define DRAWABLE_PX_SIZE PixelDensity::dpToPx( tDrawable->getSize() ).ceil() + void UISkinComplex::draw( const Float& X, const Float& Y, const Float& Width, const Float& Height, const Uint32& Alpha, const Uint32& State ) { if ( 0 == Alpha ) diff --git a/src/eepp/ui/uislider.cpp b/src/eepp/ui/uislider.cpp index 2aaed0f8a..1092795be 100644 --- a/src/eepp/ui/uislider.cpp +++ b/src/eepp/ui/uislider.cpp @@ -18,7 +18,7 @@ UISlider::UISlider( const UI_ORIENTATION& orientation ) : mMaxValue( 1.f ), mValue( 0.f ), mClickStep( 0.1f ), - mPageStep(0), + mPageStep( 0 ), mOnPosChange( false ) { UITheme * theme = UIThemeManager::instance()->getDefaultTheme(); diff --git a/src/eepp/ui/uitab.cpp b/src/eepp/ui/uitab.cpp index 1c2010f76..f61715c58 100644 --- a/src/eepp/ui/uitab.cpp +++ b/src/eepp/ui/uitab.cpp @@ -80,11 +80,11 @@ void UITab::onStateChange() { UITabWidget * tTabW = getTabWidget(); - if ( NULL != tTabW ) { - Int32 skinSize = getSkin()->getSize( mSkinState->getState() ).getHeight(); + if ( NULL != tTabW && NULL != mSkinState ) { + Int32 skinSize = getSkinSize( getSkin(), mSkinState->getState() ).getHeight(); if ( 0 == skinSize ) { - skinSize = getSkin()->getSize().getHeight(); + skinSize = getSkinSize().getHeight(); } setSize( mSize.getWidth(), skinSize ); diff --git a/src/eepp/ui/uitextedit.cpp b/src/eepp/ui/uitextedit.cpp index 6009ae6e7..c5ea5614f 100644 --- a/src/eepp/ui/uitextedit.cpp +++ b/src/eepp/ui/uitextedit.cpp @@ -225,10 +225,11 @@ void UITextEdit::scrollbarsSet() { if ( mHScrollBar->isVisible() ) { Int32 totW = mRealSize.getWidth() - mContainerPadding.Left - mContainerPadding.Right - mVScrollBar->getRealSize().getWidth(); - if ( mTextInput->getTextWidth() > totW ) { + if ( mTextInput->getTextWidth() > totW && 0 != mTextInput->getTextWidth() ) { mHScrollBar->setPageStep( (Float)totW / (Float)mTextInput->getTextWidth() ); } } + mSkipValueChange = false; } diff --git a/src/eepp/ui/uiwinmenu.cpp b/src/eepp/ui/uiwinmenu.cpp index 07b22c4a8..1f08cf221 100644 --- a/src/eepp/ui/uiwinmenu.cpp +++ b/src/eepp/ui/uiwinmenu.cpp @@ -71,8 +71,8 @@ void UIWinMenu::setTheme( UITheme * Theme ) { it->first->setThemeSkin( Theme, "winmenubutton" ); } - if ( 0 == mStyleConfig.MenuHeight && NULL != getSkin() && NULL != getSkin() ) { - mStyleConfig.MenuHeight = getSkin()->getSize().getHeight(); + if ( 0 == mStyleConfig.MenuHeight && NULL != getSkin() ) { + mStyleConfig.MenuHeight = getSkinSize().getHeight(); setSize( getParent()->getSize().getWidth(), mStyleConfig.MenuHeight ); diff --git a/src/test/eetest.cpp b/src/test/eetest.cpp index 038efb50d..fefa57271 100644 --- a/src/test/eetest.cpp +++ b/src/test/eetest.cpp @@ -167,7 +167,7 @@ void EETest::createUIThemeTextureAtlas() { std::string Path( MyPath + "ui/" + mThemeName ); if ( !FileSystem::fileExists( tgpath + EE_TEXTURE_ATLAS_EXTENSION ) ) { - TexturePacker tp( 512, 512, mThemeName.find_first_of( "2x" ) != std::string::npos ? PD_XHDPI : PD_MDPI, true, 2 ); + TexturePacker tp( 512, 512, mThemeName.find_first_of( "2x" ) != std::string::npos ? PD_XHDPI : ( mThemeName.find_first_of( "1.5x" ) != std::string::npos ? PD_HDPI : PD_MDPI ), true, 2 ); tp.addTexturesPath( Path ); tp.packTextures(); tp.save( tgpath + ".png", SAVE_TYPE_PNG ); @@ -278,6 +278,8 @@ void EETest::createUI() { if ( PixelDensity::getPixelDensity() >= 2 ) { mThemeName += "2x"; + } else if ( PixelDensity::getPixelDensity() >= 1.1 ) { + mThemeName += "1.5x"; } createUIThemeTextureAtlas(); @@ -754,7 +756,7 @@ void EETest::createNewUI() { "" " " " " - " " + " " " " " " "" @@ -768,7 +770,8 @@ void EETest::createNewUI() { if ( textures.size() > 0 ) { for ( std::size_t i = 0; i < textures.size(); i++ ) { - UIImage::New()->setDrawable( textures[i] ) + UIImage::New() + ->setDrawable( textures[i] ) ->setScaleType( UIScaleType::FitInside ) ->setGravity( UI_HALIGN_CENTER | UI_VALIGN_CENTER ) ->setEnabled( false )