mirror of
https://github.com/SpartanJ/eepp.git
synced 2026-06-02 11:36:30 +03:00
Allow text to set originpoint for rotation and scale.
Also some minor changes. --HG-- branch : dev
This commit is contained in:
@@ -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;
|
||||
|
||||
@@ -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 );
|
||||
|
||||
@@ -602,6 +602,8 @@ UIBackground * UIControl::setBackgroundFillEnabled( bool enabled ) {
|
||||
mBackground = UIBackground::New( this );
|
||||
}
|
||||
|
||||
invalidateDraw();
|
||||
|
||||
return mBackground;
|
||||
}
|
||||
|
||||
|
||||
@@ -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 );
|
||||
|
||||
@@ -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() ) );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user