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.
This commit is contained in:
+18
-4
@@ -72,8 +72,8 @@ void Actor::InitState()
|
|||||||
m_start.Init();
|
m_start.Init();
|
||||||
m_current.Init();
|
m_current.Init();
|
||||||
|
|
||||||
m_fHorizAlign = 0.0f;
|
m_fHorizAlign = 0.5f;
|
||||||
m_fVertAlign = 0.0f;
|
m_fVertAlign = 0.5f;
|
||||||
|
|
||||||
m_Effect = no_effect;
|
m_Effect = no_effect;
|
||||||
m_fSecsIntoEffect = 0;
|
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 )
|
if( m_pTempState->quat.x != 0 || m_pTempState->quat.y != 0 || m_pTempState->quat.z != 0 || m_pTempState->quat.w != 1 )
|
||||||
{
|
{
|
||||||
RageMatrix mat;
|
RageMatrix mat;
|
||||||
@@ -730,8 +744,8 @@ void Actor::ScaleTo( const RectF &rect, StretchType st )
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
SetX( rect.left + rect_width * SCALE( m_fHorizAlign, -1.0f, +1.0f, 0.0f, 1.0f ) );
|
SetX( rect.left + rect_width * m_fHorizAlign );
|
||||||
SetY( rect.top + rect_height * SCALE( m_fVertAlign, -1.0f, +1.0f, 0.0f, 1.0f ) );
|
SetY( rect.top + rect_height * m_fVertAlign );
|
||||||
|
|
||||||
SetZoom( fNewZoom );
|
SetZoom( fNewZoom );
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -251,8 +251,8 @@ public:
|
|||||||
//
|
//
|
||||||
// Alignment settings. These need to be virtual for BitmapText
|
// 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 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)? -1.0f: (va == VertAlign_Middle)? 0.0f: +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
|
// Stuff for alignment
|
||||||
//
|
//
|
||||||
float m_fHorizAlign; /* -1 left 0 center +1 right */
|
float m_fHorizAlign; /* 0.0 left 0.5 center 1.0 right */
|
||||||
float m_fVertAlign; /* -1 top 0 center +1 bottom */
|
float m_fVertAlign; /* 0.0 top 0.5 center 1.0 bottom */
|
||||||
|
|
||||||
|
|
||||||
//
|
//
|
||||||
|
|||||||
@@ -83,15 +83,11 @@ void ActorMultiTexture::DrawPrimitives()
|
|||||||
{
|
{
|
||||||
Actor::SetGlobalRenderStates(); // set Actor-specified render states
|
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;
|
RectF quadVerticies;
|
||||||
quadVerticies.left = center.x - m_size.x/2.0f;
|
quadVerticies.left = -m_size.x/2.0f;
|
||||||
quadVerticies.right = center.x + m_size.x/2.0f;
|
quadVerticies.right = +m_size.x/2.0f;
|
||||||
quadVerticies.top = center.y - m_size.y/2.0f;
|
quadVerticies.top = -m_size.y/2.0f;
|
||||||
quadVerticies.bottom = center.y + m_size.y/2.0f;
|
quadVerticies.bottom = +m_size.y/2.0f;
|
||||||
|
|
||||||
DISPLAY->ClearAllTextures();
|
DISPLAY->ClearAllTextures();
|
||||||
for( size_t i = 0; i < m_aTextureUnits.size(); ++i )
|
for( size_t i = 0; i < m_aTextureUnits.size(); ++i )
|
||||||
|
|||||||
@@ -188,12 +188,8 @@ void BitmapText::BuildChars()
|
|||||||
/* There's padding between every line: */
|
/* There's padding between every line: */
|
||||||
m_size.y += iPadding * int(m_wTextLines.size()-1);
|
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
|
// 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; i<m_wTextLines.size(); i++ ) // foreach line
|
for( unsigned i=0; i<m_wTextLines.size(); i++ ) // foreach line
|
||||||
{
|
{
|
||||||
@@ -204,8 +200,8 @@ void BitmapText::BuildChars()
|
|||||||
reverse( sLine.begin(), sLine.end() );
|
reverse( sLine.begin(), sLine.end() );
|
||||||
const int iLineWidth = m_iLineWidths[i];
|
const int iLineWidth = m_iLineWidths[i];
|
||||||
|
|
||||||
float fCenterX = iLineWidth * m_fHorizAlign * -0.5f;
|
float fX = SCALE( m_fHorizAlign, 0.0f, 1.0f, -m_size.x/2.0f, +m_size.x/2.0f - iLineWidth );
|
||||||
int iX = lrintf(fCenterX - iLineWidth/2.0f);
|
int iX = lrintf( fX );
|
||||||
|
|
||||||
for( unsigned i = 0; i < sLine.size(); ++i )
|
for( unsigned i = 0; i < sLine.size(); ++i )
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -426,15 +426,11 @@ void Sprite::DrawTexture( const TweenState *state )
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
// use m_temp_* variables to draw the object
|
// 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;
|
RectF quadVerticies;
|
||||||
quadVerticies.left = center.x - m_size.x/2.0f;
|
quadVerticies.left = -m_size.x/2.0f;
|
||||||
quadVerticies.right = center.x + m_size.x/2.0f;
|
quadVerticies.right = +m_size.x/2.0f;
|
||||||
quadVerticies.top = center.y - m_size.y/2.0f;
|
quadVerticies.top = -m_size.y/2.0f;
|
||||||
quadVerticies.bottom = center.y + 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
|
/* Don't draw anything outside of the texture's image area. Texels outside
|
||||||
|
|||||||
Reference in New Issue
Block a user