From c371d9f26b062b5a9e000fe628c1a740edde808d Mon Sep 17 00:00:00 2001 From: Glenn Maynard Date: Thu, 1 Mar 2007 04:29:05 +0000 Subject: [PATCH] Previously, alignment had to be implemented by each actor, so it was only ever supported by Sprite and BitmapText. Handle it globally, using m_size. This way, an actor only needs to set m_size to support alignment. This means alignment can be set for non-drawing ActorFrames, if a size is set explicitly. This allows stretching from the border of a frame without playing games with extra nested frames. "setsize,100,100;valign,4;zoomx,.5" This adds an extra matrix multiply. This will only happen for actors actually set to non-centered alignment, which is the exception. BitmapText still overrides this behavior a bit. Alignment for text does two things: changes the alignment of the bounding box vs. the X/Y position (the generic behavior), and changes the alignment of the text within the bounding box. --- stepmania/src/Actor.cpp | 22 ++++++++++++++++++---- stepmania/src/Actor.h | 8 ++++---- stepmania/src/ActorMultiTexture.cpp | 12 ++++-------- stepmania/src/BitmapText.cpp | 12 ++++-------- stepmania/src/Sprite.cpp | 12 ++++-------- 5 files changed, 34 insertions(+), 32 deletions(-) diff --git a/stepmania/src/Actor.cpp b/stepmania/src/Actor.cpp index 48784e165c..ad547acf93 100644 --- a/stepmania/src/Actor.cpp +++ b/stepmania/src/Actor.cpp @@ -72,8 +72,8 @@ void Actor::InitState() m_start.Init(); m_current.Init(); - m_fHorizAlign = 0.0f; - m_fVertAlign = 0.0f; + m_fHorizAlign = 0.5f; + m_fVertAlign = 0.5f; m_Effect = no_effect; m_fSecsIntoEffect = 0; @@ -467,6 +467,20 @@ void Actor::BeginDraw() // set the world matrix and calculate actor properties } } + if( unlikely(m_fHorizAlign != 0.5f || m_fVertAlign != 0.5f) ) + { + float fX = SCALE( m_fHorizAlign, 0.0f, 1.0f, +m_size.x/2.0f, -m_size.x/2.0f ); + float fY = SCALE( m_fVertAlign, 0.0f, 1.0f, +m_size.y/2.0f, -m_size.y/2.0f ); + RageMatrix m; + RageMatrixTranslate( + &m, + fX, + fY, + 0 + ); + DISPLAY->PreMultMatrix( m ); + } + if( m_pTempState->quat.x != 0 || m_pTempState->quat.y != 0 || m_pTempState->quat.z != 0 || m_pTempState->quat.w != 1 ) { RageMatrix mat; @@ -730,8 +744,8 @@ void Actor::ScaleTo( const RectF &rect, StretchType st ) break; } - SetX( rect.left + rect_width * SCALE( m_fHorizAlign, -1.0f, +1.0f, 0.0f, 1.0f ) ); - SetY( rect.top + rect_height * SCALE( m_fVertAlign, -1.0f, +1.0f, 0.0f, 1.0f ) ); + SetX( rect.left + rect_width * m_fHorizAlign ); + SetY( rect.top + rect_height * m_fVertAlign ); SetZoom( fNewZoom ); } diff --git a/stepmania/src/Actor.h b/stepmania/src/Actor.h index 1c87494ad8..5c784dd168 100644 --- a/stepmania/src/Actor.h +++ b/stepmania/src/Actor.h @@ -251,8 +251,8 @@ public: // // Alignment settings. These need to be virtual for BitmapText // - virtual void SetHorizAlign( HorizAlign ha ) { m_fHorizAlign = (ha == HorizAlign_Left)? -1.0f: (ha == HorizAlign_Center)? 0.0f: +1.0f; } - virtual void SetVertAlign( VertAlign va ) { m_fVertAlign = (va == VertAlign_Top)? -1.0f: (va == VertAlign_Middle)? 0.0f: +1.0f; } + virtual void SetHorizAlign( HorizAlign ha ) { m_fHorizAlign = (ha == HorizAlign_Left)? 0.0f: (ha == HorizAlign_Center)? 0.5f: +1.0f; } + virtual void SetVertAlign( VertAlign va ) { m_fVertAlign = (va == VertAlign_Top)? 0.0f: (va == VertAlign_Middle)? 0.5f: +1.0f; } // @@ -423,8 +423,8 @@ protected: // // Stuff for alignment // - float m_fHorizAlign; /* -1 left 0 center +1 right */ - float m_fVertAlign; /* -1 top 0 center +1 bottom */ + float m_fHorizAlign; /* 0.0 left 0.5 center 1.0 right */ + float m_fVertAlign; /* 0.0 top 0.5 center 1.0 bottom */ // diff --git a/stepmania/src/ActorMultiTexture.cpp b/stepmania/src/ActorMultiTexture.cpp index 75e1179bea..097b3843e8 100644 --- a/stepmania/src/ActorMultiTexture.cpp +++ b/stepmania/src/ActorMultiTexture.cpp @@ -83,15 +83,11 @@ void ActorMultiTexture::DrawPrimitives() { Actor::SetGlobalRenderStates(); // set Actor-specified render states - RageVector2 center = m_size; - center.x *= m_fHorizAlign * -0.5f; - center.y *= m_fVertAlign * -0.5f; - RectF quadVerticies; - quadVerticies.left = center.x - m_size.x/2.0f; - quadVerticies.right = center.x + m_size.x/2.0f; - quadVerticies.top = center.y - m_size.y/2.0f; - quadVerticies.bottom = center.y + m_size.y/2.0f; + quadVerticies.left = -m_size.x/2.0f; + quadVerticies.right = +m_size.x/2.0f; + quadVerticies.top = -m_size.y/2.0f; + quadVerticies.bottom = +m_size.y/2.0f; DISPLAY->ClearAllTextures(); for( size_t i = 0; i < m_aTextureUnits.size(); ++i ) diff --git a/stepmania/src/BitmapText.cpp b/stepmania/src/BitmapText.cpp index 55ec5927e2..980db4e067 100644 --- a/stepmania/src/BitmapText.cpp +++ b/stepmania/src/BitmapText.cpp @@ -188,12 +188,8 @@ void BitmapText::BuildChars() /* There's padding between every line: */ m_size.y += iPadding * int(m_wTextLines.size()-1); - RageVector2 center = m_size; -// center.x *= m_fHorizAlign*-0.5f; - center.y *= m_fVertAlign*-0.5f; - // the top position of the first row of characters - int iY = lrintf(center.y - m_size.y/2.0f); + int iY = lrintf(-m_size.y/2.0f); for( unsigned i=0; iIsRightToLeft() ) reverse( sLine.begin(), sLine.end() ); const int iLineWidth = m_iLineWidths[i]; - - float fCenterX = iLineWidth * m_fHorizAlign * -0.5f; - int iX = lrintf(fCenterX - iLineWidth/2.0f); + + float fX = SCALE( m_fHorizAlign, 0.0f, 1.0f, -m_size.x/2.0f, +m_size.x/2.0f - iLineWidth ); + int iX = lrintf( fX ); for( unsigned i = 0; i < sLine.size(); ++i ) { diff --git a/stepmania/src/Sprite.cpp b/stepmania/src/Sprite.cpp index ac70572f3f..ce9b3b6cd8 100644 --- a/stepmania/src/Sprite.cpp +++ b/stepmania/src/Sprite.cpp @@ -426,15 +426,11 @@ void Sprite::DrawTexture( const TweenState *state ) return; // use m_temp_* variables to draw the object - RageVector2 center = m_size; - center.x *= m_fHorizAlign * -0.5f; - center.y *= m_fVertAlign * -0.5f; - RectF quadVerticies; - quadVerticies.left = center.x - m_size.x/2.0f; - quadVerticies.right = center.x + m_size.x/2.0f; - quadVerticies.top = center.y - m_size.y/2.0f; - quadVerticies.bottom = center.y + m_size.y/2.0f; + quadVerticies.left = -m_size.x/2.0f; + quadVerticies.right = +m_size.x/2.0f; + quadVerticies.top = -m_size.y/2.0f; + quadVerticies.bottom = +m_size.y/2.0f; /* Don't draw anything outside of the texture's image area. Texels outside