diff --git a/include/eepp/math/vector2.hpp b/include/eepp/math/vector2.hpp index 8914477cf..e3a2b1098 100644 --- a/include/eepp/math/vector2.hpp +++ b/include/eepp/math/vector2.hpp @@ -94,6 +94,8 @@ template class Vector2 { /** Scales the vector position against another vector */ void scale( const T& scale, const Vector2& Center ); + Vector2 trunc() const; + Vector2 ceil() const; Vector2 floor() const; @@ -384,6 +386,10 @@ template void Vector2::clamp( T len ) { } } +template Vector2 Vector2::trunc() const { + return Vector2( std::trunc( x ), std::trunc( y ) ); +} + template Vector2 Vector2::ceil() const { return Vector2( eeceil( x ), eeceil( y ) ); } diff --git a/include/eepp/scene/node.hpp b/include/eepp/scene/node.hpp index 6bc161938..97aa9ffb8 100644 --- a/include/eepp/scene/node.hpp +++ b/include/eepp/scene/node.hpp @@ -481,7 +481,6 @@ class EE_API Node : public Transformable { std::string mId; String::HashType mIdHash{ 0 }; Vector2f mScreenPos; - Vector2i mScreenPosi; Sizef mSize; Float mAlpha{ 255.f }; UintPtr mData{ 0 }; diff --git a/src/eepp/scene/node.cpp b/src/eepp/scene/node.cpp index 35b6336ac..8a4dc859b 100644 --- a/src/eepp/scene/node.cpp +++ b/src/eepp/scene/node.cpp @@ -513,8 +513,8 @@ void Node::onSizeChange() { } Rectf Node::getScreenBounds() const { - return Rectf( Vector2f( mScreenPosi.x, mScreenPosi.y ), - Sizef( (Float)(int)mSize.getWidth(), (Float)(int)mSize.getHeight() ) ); + return Rectf( mScreenPos.trunc(), + Sizef( std::trunc( mSize.getWidth() ), std::trunc( mSize.getHeight() ) ) ); } Rectf Node::getLocalBounds() const { @@ -1259,7 +1259,6 @@ void Node::updateScreenPos() { nodeToWorldTranslation( Pos ); mScreenPos = Pos; - mScreenPosi = Vector2i( Pos.x, Pos.y ); updateCenter(); diff --git a/src/eepp/scene/scenenode.cpp b/src/eepp/scene/scenenode.cpp index 2120c27b8..06080df9b 100644 --- a/src/eepp/scene/scenenode.cpp +++ b/src/eepp/scene/scenenode.cpp @@ -284,8 +284,8 @@ void SceneNode::drawFrameBuffer() { } else { Rect r = Rect( 0, 0, mSize.getWidth(), mSize.getHeight() ); TextureRegion textureRegion( mFrameBuffer->getTexture(), r, r.getSize().asFloat() ); - textureRegion.draw( mScreenPosi.x, mScreenPosi.y, Color::White, getRotation(), - getScale() ); + Vector2f pos( mScreenPos.trunc() ); + textureRegion.draw( pos.x, pos.y, Color::White, getRotation(), getScale() ); } } } diff --git a/src/eepp/ui/uiimage.cpp b/src/eepp/ui/uiimage.cpp index b14fa8de4..3b973cd44 100644 --- a/src/eepp/ui/uiimage.cpp +++ b/src/eepp/ui/uiimage.cpp @@ -142,8 +142,8 @@ void UIImage::draw() { calcDestSize(); mDrawable->setColor( mColor ); - mDrawable->draw( Vector2f( (Float)mScreenPosi.x + (int)mAlignOffset.x, - (Float)mScreenPosi.y + (int)mAlignOffset.y ), + mDrawable->draw( Vector2f( std::trunc( mScreenPos.x ) + std::trunc( mAlignOffset.x ), + std::trunc( mScreenPos.y ) + std::trunc( mAlignOffset.y ) ), mDestSize ); mDrawable->clearColor(); } diff --git a/src/eepp/ui/uiloader.cpp b/src/eepp/ui/uiloader.cpp index 3226e999d..7a2bc875a 100644 --- a/src/eepp/ui/uiloader.cpp +++ b/src/eepp/ui/uiloader.cpp @@ -41,7 +41,7 @@ bool UILoader::isType( const Uint32& type ) const { void UILoader::draw() { UIWidget::draw(); - Rectf rect( Vector2f( mScreenPosi.x, mScreenPosi.y ), Sizef( (int)mSize.x, (int)mSize.y ) ); + Rectf rect( mScreenPos.trunc(), Sizef( (int)mSize.x, (int)mSize.y ) ); mArc.setPosition( rect.getCenter() ); mCircle.setPosition( rect.getCenter() ); diff --git a/src/eepp/ui/uinode.cpp b/src/eepp/ui/uinode.cpp index 5e536b668..9c9c9551e 100644 --- a/src/eepp/ui/uinode.cpp +++ b/src/eepp/ui/uinode.cpp @@ -633,12 +633,14 @@ void UINode::drawSkin() { PixelDensity::dpToPx( getSkinSize( getSkin(), mSkinState->getCurrentState() ) ); Sizef diff = ( mSize - rSize ) * 0.5f; - mSkinState->draw( mScreenPosi.x + eefloor( diff.x ), mScreenPosi.y + eefloor( diff.y ), + mSkinState->draw( std::trunc( mScreenPos.x ) + eefloor( diff.x ), + std::trunc( mScreenPos.y ) + eefloor( diff.y ), eefloor( rSize.getWidth() ), eefloor( rSize.getHeight() ), (Uint32)mAlpha ); } else { - mSkinState->draw( mScreenPosi.x, mScreenPosi.y, eefloor( mSize.getWidth() ), - eefloor( mSize.getHeight() ), (Uint32)mAlpha ); + mSkinState->draw( std::trunc( mScreenPos.x ), std::trunc( mScreenPos.y ), + eefloor( mSize.getWidth() ), eefloor( mSize.getHeight() ), + (Uint32)mAlpha ); } } } @@ -974,20 +976,20 @@ UINode* UINode::resetFlags( Uint32 newFlags ) { void UINode::drawBackground() { if ( ( mFlags & UI_FILL_BACKGROUND ) && NULL != mBackground ) { - mBackground->draw( mScreenPosi.asFloat(), mSize.floor(), mAlpha ); + mBackground->draw( mScreenPos.trunc(), mSize.floor(), mAlpha ); } } void UINode::drawForeground() { if ( ( mFlags & UI_FILL_FOREGROUND ) && NULL != mForeground ) { - mForeground->draw( mScreenPosi.asFloat(), mSize.floor(), (Uint32)mAlpha ); + mForeground->draw( mScreenPos.trunc(), mSize.floor(), (Uint32)mAlpha ); } } void UINode::drawBorder() { if ( ( mFlags & UI_BORDER ) && NULL != mBorder ) { mBorder->setAlpha( mAlpha ); - mBorder->draw( mScreenPosi.asFloat(), mSize.floor() ); + mBorder->draw( mScreenPos.trunc(), mSize.floor() ); } } diff --git a/src/eepp/ui/uiprogressbar.cpp b/src/eepp/ui/uiprogressbar.cpp index 76ff74c32..e4a848fb2 100644 --- a/src/eepp/ui/uiprogressbar.cpp +++ b/src/eepp/ui/uiprogressbar.cpp @@ -40,9 +40,10 @@ void UIProgressBarFiller::draw() { for ( int y = -1; y < numTiles.y; y++ ) { for ( int x = -1; x < numTiles.x; x++ ) { - mFillerSkin->draw( Vector2f( (Int32)offset.x + mScreenPosi.x + x * rSize.getWidth(), - offset.y + mScreenPosi.y + y * rSize.getHeight() ), - Sizef( rSize.getWidth(), rSize.getHeight() ) ); + mFillerSkin->draw( + Vector2f( (Int32)offset.x + std::trunc( mScreenPos.x ) + x * rSize.getWidth(), + offset.y + std::trunc( mScreenPos.y ) + y * rSize.getHeight() ), + Sizef( rSize.getWidth(), rSize.getHeight() ) ); } } diff --git a/src/eepp/ui/uisprite.cpp b/src/eepp/ui/uisprite.cpp index f0328d339..593a5b7e3 100644 --- a/src/eepp/ui/uisprite.cpp +++ b/src/eepp/ui/uisprite.cpp @@ -55,8 +55,9 @@ void UISprite::draw() { if ( NULL != mSprite && 0.f != mAlpha ) { checkTextureRegionUpdate(); - mSprite->setPosition( Vector2f( (Float)( mScreenPosi.x + (int)mAlignOffset.x ), - (Float)( mScreenPosi.y + (int)mAlignOffset.y ) ) ); + mSprite->setPosition( + Vector2f( (Float)( std::trunc( mScreenPos.x ) + (int)mAlignOffset.x ), + (Float)( std::trunc( mScreenPos.y ) + (int)mAlignOffset.y ) ) ); TextureRegion* textureRegion = mSprite->getCurrentTextureRegion(); diff --git a/src/eepp/ui/uitextinput.cpp b/src/eepp/ui/uitextinput.cpp index 3e19f6c5b..25898bf37 100644 --- a/src/eepp/ui/uitextinput.cpp +++ b/src/eepp/ui/uitextinput.cpp @@ -135,14 +135,16 @@ void UITextInput::draw() { if ( mTextCache->getTextWidth() ) { drawSelection( mTextCache ); mTextCache->setAlign( getFlags() ); - mTextCache->draw( (Float)mScreenPosi.x + (int)mRealAlignOffset.x + (int)mPaddingPx.Left, - (Float)mScreenPosi.y + (int)mRealAlignOffset.y + (int)mPaddingPx.Top, - Vector2f::One, 0.f, getBlendMode() ); + mTextCache->draw( + std::trunc( mScreenPos.x ) + (int)mRealAlignOffset.x + (int)mPaddingPx.Left, + std::trunc( mScreenPos.y ) + (int)mRealAlignOffset.y + (int)mPaddingPx.Top, + Vector2f::One, 0.f, getBlendMode() ); } else if ( !mHintCache->getString().empty() && ( mHintDisplay == HintDisplay::Always || hasFocus() ) ) { - mHintCache->draw( (Float)mScreenPosi.x + (int)mRealAlignOffset.x + (int)mPaddingPx.Left, - (Float)mScreenPosi.y + (int)mRealAlignOffset.y + (int)mPaddingPx.Top, - Vector2f::One, 0.f, getBlendMode() ); + mHintCache->draw( + std::trunc( mScreenPos.x ) + (int)mRealAlignOffset.x + (int)mPaddingPx.Left, + std::trunc( mScreenPos.y ) + (int)mRealAlignOffset.y + (int)mPaddingPx.Top, + Vector2f::One, 0.f, getBlendMode() ); } } diff --git a/src/eepp/ui/uitextinputpassword.cpp b/src/eepp/ui/uitextinputpassword.cpp index 9189605db..71704e2ce 100644 --- a/src/eepp/ui/uitextinputpassword.cpp +++ b/src/eepp/ui/uitextinputpassword.cpp @@ -35,9 +35,10 @@ void UITextInputPassword::draw() { } mPassCache->setAlign( getFlags() ); - mPassCache->draw( (Float)mScreenPosi.x + (int)mRealAlignOffset.x + (int)mPaddingPx.Left, - (Float)mScreenPosi.y + (int)mRealAlignOffset.y + (int)mPaddingPx.Top, - Vector2f::One, 0.f, getBlendMode() ); + mPassCache->draw( + std::trunc( mScreenPos.x ) + (int)mRealAlignOffset.x + (int)mPaddingPx.Left, + std::trunc( mScreenPos.y ) + (int)mRealAlignOffset.y + (int)mPaddingPx.Top, + Vector2f::One, 0.f, getBlendMode() ); if ( isClipped() ) { clipSmartDisable(); @@ -49,9 +50,10 @@ void UITextInputPassword::draw() { mSize.getHeight() - mPaddingPx.Top - mPaddingPx.Bottom ); } - mHintCache->draw( (Float)mScreenPosi.x + (int)mHintAlignOffset.x + (int)mPaddingPx.Left, - (Float)mScreenPosi.y + (int)mHintAlignOffset.y + (int)mPaddingPx.Top, - Vector2f::One, 0.f, getBlendMode() ); + mHintCache->draw( + std::trunc( mScreenPos.x ) + (int)mHintAlignOffset.x + (int)mPaddingPx.Left, + std::trunc( mScreenPos.y ) + (int)mHintAlignOffset.y + (int)mPaddingPx.Top, + Vector2f::One, 0.f, getBlendMode() ); if ( isClipped() ) { clipSmartDisable(); diff --git a/src/eepp/ui/uitextureregion.cpp b/src/eepp/ui/uitextureregion.cpp index e23c86745..aa4b481f6 100644 --- a/src/eepp/ui/uitextureregion.cpp +++ b/src/eepp/ui/uitextureregion.cpp @@ -134,9 +134,9 @@ void UITextureRegion::draw() { } void UITextureRegion::drawTextureRegion() { - mTextureRegion->draw( (Float)mScreenPosi.x + (int)mAlignOffset.x, - (Float)mScreenPosi.y + (int)mAlignOffset.y, mColor, 0.f, Vector2f::One, - getBlendMode(), mRender ); + mTextureRegion->draw( std::trunc( mScreenPos.x ) + (int)mAlignOffset.x, + std::trunc( mScreenPos.y ) + (int)mAlignOffset.y, mColor, 0.f, + Vector2f::One, getBlendMode(), mRender ); } void UITextureRegion::setAlpha( const Float& alpha ) { diff --git a/src/eepp/ui/uitextview.cpp b/src/eepp/ui/uitextview.cpp index ad508cd86..ef8f70fb8 100644 --- a/src/eepp/ui/uitextview.cpp +++ b/src/eepp/ui/uitextview.cpp @@ -90,9 +90,10 @@ void UITextView::draw() { } mTextCache->setAlign( Font::getHorizontalAlign( getFlags() ) ); - mTextCache->draw( (Float)mScreenPosi.x + (int)mRealAlignOffset.x + (int)mPaddingPx.Left, - (Float)mScreenPosi.y + (int)mRealAlignOffset.y + (int)mPaddingPx.Top, - Vector2f::One, 0.f, getBlendMode() ); + mTextCache->draw( + std::trunc( mScreenPos.x ) + (int)mRealAlignOffset.x + (int)mPaddingPx.Left, + std::trunc( mScreenPos.y ) + (int)mRealAlignOffset.y + (int)mPaddingPx.Top, + Vector2f::One, 0.f, getBlendMode() ); if ( isClipped() ) clipSmartDisable(); diff --git a/src/eepp/ui/uitooltip.cpp b/src/eepp/ui/uitooltip.cpp index 4e7050616..9b1197d55 100644 --- a/src/eepp/ui/uitooltip.cpp +++ b/src/eepp/ui/uitooltip.cpp @@ -160,8 +160,8 @@ void UITooltip::draw() { if ( mTextCache->getTextWidth() ) { mTextCache->setAlign( getFlags() ); - mTextCache->draw( (Float)mScreenPosi.x + (int)mAlignOffset.x, - (Float)mScreenPosi.y + (int)mAlignOffset.y, Vector2f::One, 0.f, + mTextCache->draw( std::trunc( mScreenPos.x ) + (int)mAlignOffset.x, + std::trunc( mScreenPos.y ) + (int)mAlignOffset.y, Vector2f::One, 0.f, getBlendMode() ); } } diff --git a/src/eepp/ui/uiwindow.cpp b/src/eepp/ui/uiwindow.cpp index 908390e6a..b1b27a56f 100644 --- a/src/eepp/ui/uiwindow.cpp +++ b/src/eepp/ui/uiwindow.cpp @@ -353,8 +353,8 @@ void UIWindow::drawFrameBuffer() { } else { Rect r( 0, 0, mSize.getWidth(), mSize.getHeight() ); TextureRegion textureRegion( mFrameBuffer->getTexture(), r, r.getSize().asFloat() ); - textureRegion.draw( mScreenPosi.x, mScreenPosi.y, Color::White, getRotation(), - getScale() ); + textureRegion.draw( std::trunc( mScreenPos.x ), std::trunc( mScreenPos.y ), + Color::White, getRotation(), getScale() ); } } } @@ -1329,9 +1329,9 @@ void UIWindow::matrixSet() { mFrameBuffer->clear(); } - if ( 0 != mScreenPosi ) { + if ( Vector2f::Zero != mScreenPos ) { GLi->pushMatrix(); - GLi->translatef( -mScreenPosi.x, -mScreenPosi.y, 0.f ); + GLi->translatef( std::trunc( -mScreenPos.x ), std::trunc( -mScreenPos.y ), 0.f ); } } } else { @@ -1343,7 +1343,7 @@ void UIWindow::matrixUnset() { if ( ownsFrameBuffer() ) { GlobalBatchRenderer::instance()->draw(); - if ( 0 != mScreenPosi ) + if ( Vector2f::Zero != mScreenPos ) GLi->popMatrix(); if ( mFrameBufferBound ) { diff --git a/src/modules/eterm/src/eterm/ui/uiterminal.cpp b/src/modules/eterm/src/eterm/ui/uiterminal.cpp index cb9bc08d4..597866665 100644 --- a/src/modules/eterm/src/eterm/ui/uiterminal.cpp +++ b/src/modules/eterm/src/eterm/ui/uiterminal.cpp @@ -42,7 +42,7 @@ bool UITerminal::isType( const Uint32& type ) const { void UITerminal::draw() { if ( mTerm ) { - mTerm->setPosition( mScreenPosi.asFloat() ); + mTerm->setPosition( mScreenPos.trunc() ); mTerm->draw(); } } @@ -499,7 +499,7 @@ Uint32 UITerminal::onMouseUp( const Vector2i& position, const Uint32& flags ) { } void UITerminal::onPositionChange() { - mTerm->setPosition( mScreenPosi.asFloat() ); + mTerm->setPosition( mScreenPos.trunc() ); UIWidget::onPositionChange(); } @@ -517,7 +517,7 @@ void UITerminal::onSizeChange() { Uint32 UITerminal::onFocus( NodeFocusReason reason ) { getUISceneNode()->getWindow()->startTextInput(); updateScreenPos(); - mTerm->setPosition( mScreenPosi.asFloat() ); + mTerm->setPosition( mScreenPos.trunc() ); mTerm->setFocus( true ); invalidateDraw(); return UIWidget::onFocus( reason );