Merge pull request #48 from kyzentun/text_distortion

Added distort function to BitmapText.
This commit is contained in:
Colby Klein
2014-02-19 10:36:05 -08:00
4 changed files with 51 additions and 0 deletions
+2
View File
@@ -550,6 +550,7 @@
<Function name='NoStroke'/>
<Function name='PixelFont'/>
<Function name='Stroke'/>
<Function name='distort'/>
<Function name='jitter'/>
<Function name='maxheight'/>
<Function name='maxwidth'/>
@@ -558,6 +559,7 @@
<Function name='settextf'/>
<Function name='strokecolor'/>
<Function name='textglowmode'/>
<Function name='undistort'/>
<Function name='uppercase'/>
<Function name='vertspacing'/>
<Function name='wrapwidthpixels'/>
+8
View File
@@ -1611,6 +1611,14 @@ save yourself some time, copy this for undocumented things:
<Function name='GetText' return='string' arguments=''>
Returns the text that is currently set.
</Function>
<Function name='distort' return='void' arguments='float distortion_percentage'>
Causes each character of text to be randomly distorted by
distortion_percentage of its size when the text is set. The distortion
only changes when the text changes.
</Function>
<Function name='undistort' return='void' arguments=''>
Turns off distortion.
</Function>
<Function name='jitter' return='void' arguments='bool bJitter'>
If <code>bJitter</code> is <code>true</code>, move each character of the string around by a small random amount.
</Function>
+37
View File
@@ -47,6 +47,8 @@ BitmapText::BitmapText()
m_bRainbowScroll = false;
m_bJitter = false;
m_fDistortion= 0.0f;
m_bUsingDistortion= false;
m_iWrapWidthPixels = -1;
m_fMaxWidth = 0;
@@ -84,6 +86,8 @@ BitmapText & BitmapText::operator=(const BitmapText &cpy)
CPY( m_fMaxHeight );
CPY( m_bRainbowScroll );
CPY( m_bJitter );
CPY( m_fDistortion );
CPY( m_bUsingDistortion );
CPY( m_iVertSpacing );
CPY( m_aVertices );
CPY( m_vpFontPageTextures );
@@ -252,6 +256,22 @@ void BitmapText::BuildChars()
// The amount of padding a line needs:
iY += iPadding;
}
if( m_bUsingDistortion )
{
int iSeed = lrintf( RageTimer::GetTimeSinceStartFast()*500000.0f );
RandomGen rnd( iSeed );
for(unsigned int i= 0; i < m_aVertices.size(); i+=4)
{
float w= m_aVertices[i+2].p.x - m_aVertices[i].p.x;
float h= m_aVertices[i+2].p.y - m_aVertices[i].p.y;
for(unsigned int ioff= 0; ioff < 4; ++ioff)
{
m_aVertices[i+ioff].p.x += ((rnd()%9) / 8.0f - .5f) * m_fDistortion * w;
m_aVertices[i+ioff].p.y += ((rnd()%9) / 8.0f - .5f) * m_fDistortion * h;
}
}
}
}
void BitmapText::DrawChars( bool bUseStrokeTexture )
@@ -470,6 +490,19 @@ void BitmapText::SetUppercase( bool b )
BuildChars();
}
void BitmapText::SetDistortion( float f )
{
m_fDistortion= f;
m_bUsingDistortion= true;
BuildChars();
}
void BitmapText::UnSetDistortion()
{
m_bUsingDistortion= false;
BuildChars();
}
void BitmapText::UpdateBaseZoom()
{
if( m_fMaxWidth == 0 )
@@ -827,6 +860,8 @@ public:
}
static int rainbowscroll( T* p, lua_State *L ) { p->SetRainbowScroll( BArg(1) ); return 0; }
static int jitter( T* p, lua_State *L ) { p->SetJitter( BArg(1) ); return 0; }
static int distort( T* p, lua_State *L) { p->SetDistortion( FArg(1) ); return 0; }
static int undistort( T* p, lua_State *L) { p->UnSetDistortion(); return 0; }
static int GetText( T* p, lua_State *L ) { lua_pushstring( L, p->GetText() ); return 1; }
static int AddAttribute( T* p, lua_State *L )
{
@@ -851,6 +886,8 @@ public:
ADD_METHOD( settext );
ADD_METHOD( rainbowscroll );
ADD_METHOD( jitter );
ADD_METHOD( distort );
ADD_METHOD( undistort );
ADD_METHOD( GetText );
ADD_METHOD( AddAttribute );
ADD_METHOD( ClearAttributes );
+4
View File
@@ -34,6 +34,8 @@ public:
void SetUppercase( bool b );
void SetRainbowScroll( bool b ) { m_bRainbowScroll = b; }
void SetJitter( bool b ) { m_bJitter = b; }
void SetDistortion( float f );
void UnSetDistortion();
void SetHorizAlign( float f );
@@ -77,6 +79,8 @@ protected:
float m_fMaxHeight; // 0 = no max
bool m_bRainbowScroll;
bool m_bJitter;
bool m_bUsingDistortion;
float m_fDistortion;
int m_iVertSpacing;
vector<RageSpriteVertex> m_aVertices;