Merge pull request #362 from kyzentun/StrokeTween
Tweenable stroke color for BitmapText
This commit is contained in:
+1
-1
@@ -279,7 +279,7 @@ public:
|
||||
virtual void Update( float fDeltaTime ); // this can short circuit UpdateInternal
|
||||
virtual void UpdateInternal( float fDeltaTime ); // override this
|
||||
void UpdateTweening( float fDeltaTime );
|
||||
// These next functions should all be overridden by a derived class that has its own tweening states to handl.
|
||||
// These next functions should all be overridden by a derived class that has its own tweening states to handle.
|
||||
virtual void SetCurrentTweenStart() {}
|
||||
virtual void EraseHeadTween() {}
|
||||
virtual void UpdatePercentThroughTween( float PercentThroughTween ) {}
|
||||
|
||||
+63
-8
@@ -56,9 +56,6 @@ BitmapText::BitmapText()
|
||||
m_iVertSpacing = 0;
|
||||
m_MaxDimensionUsesZoom= false;
|
||||
m_bHasGlowAttribute = false;
|
||||
// We'd be better off not adding strokes to things we can't control
|
||||
// themewise (ScreenDebugOverlay for example). -Midiman
|
||||
m_StrokeColor = RageColor(0,0,0,0);
|
||||
// Never, this way we dont have awkward settings between themes. -Midiman
|
||||
SetShadowLength( 0 );
|
||||
// SM4SVN r28328, "draw glow using stroke texture" forces the BitmapText to
|
||||
@@ -95,7 +92,9 @@ BitmapText & BitmapText::operator=(const BitmapText &cpy)
|
||||
CPY( m_vpFontPageTextures );
|
||||
CPY( m_mAttributes );
|
||||
CPY( m_bHasGlowAttribute );
|
||||
CPY( m_StrokeColor );
|
||||
CPY( BMT_Tweens );
|
||||
CPY( BMT_current );
|
||||
CPY( BMT_start );
|
||||
#undef CPY
|
||||
|
||||
if( m_pFont )
|
||||
@@ -117,6 +116,60 @@ BitmapText::BitmapText( const BitmapText &cpy ):
|
||||
*this = cpy;
|
||||
}
|
||||
|
||||
void BitmapText::SetCurrentTweenStart()
|
||||
{
|
||||
BMT_start= BMT_current;
|
||||
}
|
||||
|
||||
void BitmapText::EraseHeadTween()
|
||||
{
|
||||
BMT_current= BMT_Tweens[0];
|
||||
BMT_Tweens.erase(BMT_Tweens.begin());
|
||||
}
|
||||
|
||||
void BitmapText::UpdatePercentThroughTween(float between)
|
||||
{
|
||||
BMT_TweenState::MakeWeightedAverage(BMT_current, BMT_start, BMT_Tweens[0],
|
||||
between);
|
||||
}
|
||||
|
||||
void BitmapText::BeginTweening(float time, ITween* interp)
|
||||
{
|
||||
Actor::BeginTweening(time, interp);
|
||||
if(!BMT_Tweens.empty())
|
||||
{
|
||||
BMT_Tweens.push_back(BMT_Tweens.back());
|
||||
}
|
||||
else
|
||||
{
|
||||
BMT_Tweens.push_back(BMT_current);
|
||||
}
|
||||
}
|
||||
|
||||
void BitmapText::StopTweening()
|
||||
{
|
||||
BMT_Tweens.clear();
|
||||
Actor::StopTweening();
|
||||
}
|
||||
|
||||
void BitmapText::FinishTweening()
|
||||
{
|
||||
if(!BMT_Tweens.empty())
|
||||
{
|
||||
BMT_current= BMT_DestTweenState();
|
||||
}
|
||||
Actor::FinishTweening();
|
||||
}
|
||||
|
||||
void BitmapText::BMT_TweenState::MakeWeightedAverage(BMT_TweenState& out,
|
||||
BMT_TweenState const& from, BMT_TweenState const& to, float between)
|
||||
{
|
||||
out.m_stroke_color.b= lerp(between, from.m_stroke_color.b, to.m_stroke_color.b);
|
||||
out.m_stroke_color.g= lerp(between, from.m_stroke_color.g, to.m_stroke_color.g);
|
||||
out.m_stroke_color.r= lerp(between, from.m_stroke_color.r, to.m_stroke_color.r);
|
||||
out.m_stroke_color.a= lerp(between, from.m_stroke_color.a, to.m_stroke_color.a);
|
||||
}
|
||||
|
||||
void BitmapText::LoadFromNode( const XNode* node )
|
||||
{
|
||||
RString text;
|
||||
@@ -613,12 +666,12 @@ void BitmapText::DrawPrimitives()
|
||||
}
|
||||
|
||||
// render the stroke
|
||||
if( m_StrokeColor.a > 0 )
|
||||
RageColor stroke_color= GetCurrStrokeColor();
|
||||
if( stroke_color.a > 0 )
|
||||
{
|
||||
RageColor c = m_StrokeColor;
|
||||
c.a *= m_pTempState->diffuse[0].a;
|
||||
stroke_color.a *= m_pTempState->diffuse[0].a;
|
||||
for( unsigned i=0; i<m_aVertices.size(); i++ )
|
||||
m_aVertices[i].c = c;
|
||||
m_aVertices[i].c = stroke_color;
|
||||
DrawChars( true );
|
||||
}
|
||||
|
||||
@@ -914,6 +967,7 @@ public:
|
||||
}
|
||||
static int ClearAttributes( T* p, lua_State * ) { p->ClearAttributes(); return 0; }
|
||||
static int strokecolor( T* p, lua_State *L ) { RageColor c; c.FromStackCompat( L, 1 ); p->SetStrokeColor( c ); return 0; }
|
||||
DEFINE_METHOD(getstrokecolor, GetStrokeColor());
|
||||
static int uppercase( T* p, lua_State *L ) { p->SetUppercase( BArg(1) ); return 0; }
|
||||
static int textglowmode( T* p, lua_State *L ) { p->SetTextGlowMode( Enum::Check<TextGlowMode>(L, 1) ); return 0; }
|
||||
|
||||
@@ -933,6 +987,7 @@ public:
|
||||
ADD_METHOD( AddAttribute );
|
||||
ADD_METHOD( ClearAttributes );
|
||||
ADD_METHOD( strokecolor );
|
||||
ADD_METHOD( getstrokecolor );
|
||||
ADD_METHOD( uppercase );
|
||||
ADD_METHOD( textglowmode );
|
||||
//ADD_METHOD( LoadFromFont );
|
||||
|
||||
+42
-3
@@ -19,6 +19,41 @@ public:
|
||||
virtual void LoadFromNode( const XNode* pNode );
|
||||
virtual BitmapText *Copy() const;
|
||||
|
||||
struct BMT_TweenState
|
||||
{
|
||||
// We'd be better off not adding strokes to things we can't control
|
||||
// themewise (ScreenDebugOverlay for example). -Midiman
|
||||
BMT_TweenState(): m_stroke_color(RageColor(0,0,0,0)) {}
|
||||
static void MakeWeightedAverage(BMT_TweenState& out,
|
||||
BMT_TweenState const& from, BMT_TweenState const& to, float between);
|
||||
bool operator==(BMT_TweenState const& other) const;
|
||||
bool operator!=(BMT_TweenState const& other) const { return !operator==(other); }
|
||||
void SetStrokeColor(RageColor const& c) { m_stroke_color= c; }
|
||||
RageColor const& GetStrokeColor() { return m_stroke_color; }
|
||||
private:
|
||||
RageColor m_stroke_color;
|
||||
};
|
||||
|
||||
BMT_TweenState& BMT_DestTweenState()
|
||||
{
|
||||
if(BMT_Tweens.empty())
|
||||
{ return BMT_current; }
|
||||
else
|
||||
{ return BMT_Tweens.back(); }
|
||||
}
|
||||
BMT_TweenState const& BMT_DestTweenState() const { return const_cast<BitmapText*>(this)->BMT_DestTweenState(); }
|
||||
|
||||
virtual void SetCurrentTweenStart();
|
||||
virtual void EraseHeadTween();
|
||||
virtual void UpdatePercentThroughTween(float between);
|
||||
virtual void BeginTweening(float time, ITween* interp);
|
||||
// This function exists because the compiler tried to connect a call of
|
||||
// "BeginTweening(1.2f)" to the function above. -Kyz
|
||||
virtual void BeginTweening(float time, TweenType tt = TWEEN_LINEAR)
|
||||
{ Actor::BeginTweening(time, tt); }
|
||||
virtual void StopTweening();
|
||||
virtual void FinishTweening();
|
||||
|
||||
bool LoadFromFont( const RString& sFontName );
|
||||
bool LoadFromTextureAndChars( const RString& sTexturePath, const RString& sChars );
|
||||
virtual void SetText( const RString& sText, const RString& sAlternateText = "", int iWrapWidthPixels = -1 );
|
||||
@@ -40,8 +75,10 @@ public:
|
||||
|
||||
void SetHorizAlign( float f );
|
||||
|
||||
void SetStrokeColor( RageColor c ) { m_StrokeColor = c; }
|
||||
RageColor GetStrokeColor() { return m_StrokeColor; }
|
||||
void SetStrokeColor(RageColor c) { BMT_DestTweenState().SetStrokeColor(c); }
|
||||
RageColor const& GetStrokeColor() { return BMT_DestTweenState().GetStrokeColor(); }
|
||||
void SetCurrStrokeColor(RageColor c) { BMT_current.SetStrokeColor(c); }
|
||||
RageColor const& GetCurrStrokeColor() { return BMT_current.GetStrokeColor(); }
|
||||
|
||||
void SetTextGlowMode( TextGlowMode tgm ) { m_TextGlowMode = tgm; }
|
||||
|
||||
@@ -91,7 +128,6 @@ protected:
|
||||
map<size_t, Attribute> m_mAttributes;
|
||||
bool m_bHasGlowAttribute;
|
||||
|
||||
RageColor m_StrokeColor;
|
||||
TextGlowMode m_TextGlowMode;
|
||||
|
||||
// recalculate the items in SetText()
|
||||
@@ -101,6 +137,9 @@ protected:
|
||||
|
||||
private:
|
||||
void SetTextInternal();
|
||||
vector<BMT_TweenState> BMT_Tweens;
|
||||
BMT_TweenState BMT_current;
|
||||
BMT_TweenState BMT_start;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
@@ -32,7 +32,7 @@ void RollingNumbers::DrawPart(RageColor const* diffuse, RageColor const& stroke,
|
||||
{
|
||||
m_pTempState->diffuse[i]= diffuse[i];
|
||||
}
|
||||
SetStrokeColor(stroke);
|
||||
SetCurrStrokeColor(stroke);
|
||||
m_pTempState->crop.left= crop_left;
|
||||
m_pTempState->crop.right= crop_right;
|
||||
BitmapText::DrawPrimitives();
|
||||
@@ -42,8 +42,8 @@ void RollingNumbers::DrawPrimitives()
|
||||
{
|
||||
RageColor diffuse_orig[NUM_DIFFUSE_COLORS];
|
||||
RageColor diffuse_temp[NUM_DIFFUSE_COLORS];
|
||||
RageColor stroke_orig= GetStrokeColor();
|
||||
RageColor stroke_temp= GetStrokeColor() * LEADING_ZERO_MULTIPLY_COLOR;
|
||||
RageColor stroke_orig= GetCurrStrokeColor();
|
||||
RageColor stroke_temp= stroke_orig * LEADING_ZERO_MULTIPLY_COLOR;
|
||||
for(int i= 0; i < NUM_DIFFUSE_COLORS; ++i)
|
||||
{
|
||||
diffuse_orig[i]= m_pTempState->diffuse[i];
|
||||
|
||||
Reference in New Issue
Block a user