From 032be3a7544dfa9755c55b3ddac6f50d4ce039b8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mart=C3=AD=C2=ADn=20Lucas=20Golini?= Date: Fri, 22 Dec 2017 02:25:30 -0300 Subject: [PATCH] Allow text to set originpoint for rotation and scale. Also some minor changes. --HG-- branch : dev --- include/eepp/graphics/text.hpp | 2 +- src/eepp/graphics/text.cpp | 27 +++++++++++++++++++-------- src/eepp/ui/uicontrol.cpp | 2 ++ src/eepp/ui/uicontrolanim.cpp | 4 ++-- src/eepp/ui/uiwidget.cpp | 17 +++++++++++++++++ 5 files changed, 41 insertions(+), 11 deletions(-) diff --git a/include/eepp/graphics/text.hpp b/include/eepp/graphics/text.hpp index b99de28af..f52c629bc 100644 --- a/include/eepp/graphics/text.hpp +++ b/include/eepp/graphics/text.hpp @@ -81,7 +81,7 @@ class EE_API Text { Float getTextHeight(); /** Draw the cached text on screen */ - void draw( const Float& X, const Float& Y, const Vector2f& Scale = Vector2f::One, const Float& Angle = 0, BlendMode Effect = BlendAlpha ); + void draw( const Float& X, const Float& Y, const Vector2f& Scale = Vector2f::One, const Float& Rotation = 0, BlendMode Effect = BlendAlpha, const OriginPoint& rotationCenter = OriginPoint::OriginCenter, const OriginPoint& scaleCenter = OriginPoint::OriginCenter ); /** @return The Shadow Font Color */ const Color& getShadowColor() const; diff --git a/src/eepp/graphics/text.cpp b/src/eepp/graphics/text.cpp index bfcad9603..d3b168d72 100644 --- a/src/eepp/graphics/text.cpp +++ b/src/eepp/graphics/text.cpp @@ -492,7 +492,7 @@ Float Text::getTextHeight() { return mFont->getLineSpacing(mRealCharacterSize) * ( 0 == mNumLines ? 1 : mNumLines ); } -void Text::draw(const Float & X, const Float & Y, const Vector2f & Scale, const Float & Angle, BlendMode Effect) { +void Text::draw(const Float & X, const Float & Y, const Vector2f & Scale, const Float & Rotation, BlendMode Effect, const OriginPoint& rotationCenter, const OriginPoint& scaleCenter) { if ( NULL != mFont ) { ensureColorUpdate(); ensureGeometryUpdate(); @@ -526,7 +526,7 @@ void Text::draw(const Float & X, const Float & Y, const Vector2f & Scale, const Float pd = PixelDensity::dpToPx(1); - draw( X + pd, Y + pd, Scale, Angle, Effect ); + draw( X + pd, Y + pd, Scale, Rotation, Effect ); mStyle = f; @@ -534,17 +534,28 @@ void Text::draw(const Float & X, const Float & Y, const Vector2f & Scale, const mColors.assign( mColors.size(), getFillColor() ); } - if ( Angle != 0.0f || Scale != 1.0f ) { + if ( Rotation != 0.0f || Scale != 1.0f ) { Float cX = (Float) ( (Int32)X ); Float cY = (Float) ( (Int32)Y ); + Vector2f Center( cX + mCachedWidth * 0.5f, cY + getTextHeight() * 0.5f ); GLi->pushMatrix(); - Vector2f Center( cX + mCachedWidth * 0.5f, cY + getTextHeight() * 0.5f ); - GLi->translatef( Center.x , Center.y, 0.f ); - GLi->rotatef( Angle, 0.0f, 0.0f, 1.0f ); + Vector2f center = Center; + if ( OriginPoint::OriginTopLeft == scaleCenter.OriginType ) center = Vector2f( cX, cY ); + else if ( OriginPoint::OriginCustom == scaleCenter.OriginType ) center = Vector2f( scaleCenter.x, scaleCenter.y ); + + GLi->translatef( center.x , center.y, 0.f ); GLi->scalef( Scale.x, Scale.y, 1.0f ); - GLi->translatef( -Center.x + X, -Center.y + Y, 0.f ); + GLi->translatef( -center.x, -center.y, 0.f ); + + center = Center; + if ( OriginPoint::OriginTopLeft == rotationCenter.OriginType ) center = Vector2f( cX, cY ); + else if ( OriginPoint::OriginCustom == rotationCenter.OriginType ) center = Vector2f( rotationCenter.x, rotationCenter.y ); + + GLi->translatef( center.x , center.y, 0.f ); + GLi->rotatef( Rotation, 0.0f, 0.0f, 1.0f ); + GLi->translatef( -center.x + cX, -center.y + cY, 0.f ); } else { GLi->translatef( X, Y, 0 ); } @@ -574,7 +585,7 @@ void Text::draw(const Float & X, const Float & Y, const Vector2f & Scale, const GLi->drawArrays( GL_TRIANGLES, 0, numvert ); } - if ( Angle != 0.0f || Scale != 1.0f ) { + if ( Rotation != 0.0f || Scale != 1.0f ) { GLi->popMatrix(); } else { GLi->translatef( -X, -Y, 0 ); diff --git a/src/eepp/ui/uicontrol.cpp b/src/eepp/ui/uicontrol.cpp index 0c56005fc..7c5b0e7e6 100644 --- a/src/eepp/ui/uicontrol.cpp +++ b/src/eepp/ui/uicontrol.cpp @@ -602,6 +602,8 @@ UIBackground * UIControl::setBackgroundFillEnabled( bool enabled ) { mBackground = UIBackground::New( this ); } + invalidateDraw(); + return mBackground; } diff --git a/src/eepp/ui/uicontrolanim.cpp b/src/eepp/ui/uicontrolanim.cpp index 53a67a742..01695edb8 100644 --- a/src/eepp/ui/uicontrolanim.cpp +++ b/src/eepp/ui/uicontrolanim.cpp @@ -186,12 +186,12 @@ void UIControlAnim::matrixSet() { GLi->pushMatrix(); - Vector2f scaleCenter = this->getScaleCenter(); + Vector2f scaleCenter = getScaleCenter(); GLi->translatef( scaleCenter.x , scaleCenter.y, 0.f ); GLi->scalef( mScale.x, mScale.y, 1.0f ); GLi->translatef( -scaleCenter.x, -scaleCenter.y, 0.f ); - Vector2f rotationCenter = this->getRotationCenter(); + Vector2f rotationCenter = getRotationCenter(); GLi->translatef( rotationCenter.x , rotationCenter.y, 0.f ); GLi->rotatef( mAngle, 0.0f, 0.0f, 1.0f ); GLi->translatef( -rotationCenter.x, -rotationCenter.y, 0.f ); diff --git a/src/eepp/ui/uiwidget.cpp b/src/eepp/ui/uiwidget.cpp index c1e195b7d..7055c741c 100644 --- a/src/eepp/ui/uiwidget.cpp +++ b/src/eepp/ui/uiwidget.cpp @@ -427,6 +427,19 @@ static OriginPoint toOriginPoint( std::string val ) { return OriginPoint::OriginCenter; } +static BlendMode toBlendMode( std::string val ) { + String::toLowerInPlace( val ); + + BlendMode blendMode; + + if ( val == "add" ) blendMode == BlendAdd; + else if ( val == "alpha" ) blendMode == BlendAlpha; + else if ( val == "multiply" ) blendMode == BlendMultiply; + else if ( val == "none" ) blendMode == BlendNone; + + return blendMode; +} + void UIWidget::loadFromXmlNode( const pugi::xml_node& node ) { beginPropertiesTransaction(); @@ -633,6 +646,10 @@ void UIWidget::loadFromXmlNode( const pugi::xml_node& node ) { setRotationOriginPoint( toOriginPoint( ait->as_string() ) ); } else if ( "scaleoriginpoint" == name ) { setScaleOriginPoint( toOriginPoint( ait->as_string() ) ); + } else if ( "blendmode" == name ) { + setBlendMode( toBlendMode( ait->as_string() ) ); + } else if ( "backgroundblendmode" == name ) { + setBackgroundFillEnabled( true )->setBlendMode( toBlendMode( ait->as_string() ) ); } }