Implement text shade outline

This commit is contained in:
kaetemi 2014-10-08 23:20:34 +02:00
parent da982ab0ca
commit 523761d7b7
5 changed files with 88 additions and 27 deletions

View file

@ -82,6 +82,8 @@ public:
void setShaded (bool b) { _Shaded = b; } void setShaded (bool b) { _Shaded = b; }
void setShadeOutline (bool b) { _ShadeOutline = b; }
void setShadeExtent (float shext) { _ShadeExtent = shext; } void setShadeExtent (float shext) { _ShadeExtent = shext; }
/// The alpha of the shade is multiplied at each draw with the alpha of the color. Default: (0,0,0,255) /// The alpha of the shade is multiplied at each draw with the alpha of the color. Default: (0,0,0,255)
@ -107,6 +109,8 @@ public:
bool getShaded() const { return _Shaded; } bool getShaded() const { return _Shaded; }
bool getShadeOutline() const { return _ShadeOutline; }
bool getKeep800x600Ratio() const {return _Keep800x600Ratio;} bool getKeep800x600Ratio() const {return _Keep800x600Ratio;}
NLMISC::CRGBA getShadeColor () const { return _ShadeColor; } NLMISC::CRGBA getShadeColor () const { return _ShadeColor; }
@ -138,15 +142,21 @@ public:
{ {
nlassert (index < _CacheStrings.size()); nlassert (index < _CacheStrings.size());
CComputedString &rCS = _CacheStrings[index]; CComputedString &rCS = _CacheStrings[index];
if(_Shaded) if (_Shaded)
{ {
CRGBA bkup = rCS.Color; CRGBA bkup = rCS.Color;
rCS.Color = _ShadeColor; rCS.Color = _ShadeColor;
rCS.Color.A = (uint8)((uint(bkup.A) * uint(_ShadeColor.A)+1)>>8); rCS.Color.A = (uint8)((uint(bkup.A) * uint(_ShadeColor.A)+1)>>8);
rCS.render2D (*_Driver, x+_ShadeExtent, z-_ShadeExtent, _HotSpot, _ScaleX, _ScaleZ); rCS.render2D(*_Driver, x+_ShadeExtent, z-_ShadeExtent, _HotSpot, _ScaleX, _ScaleZ);
if (_ShadeOutline)
{
rCS.render2D(*_Driver, x-_ShadeExtent, z-_ShadeExtent, _HotSpot, _ScaleX, _ScaleZ);
rCS.render2D(*_Driver, x-_ShadeExtent, z+_ShadeExtent, _HotSpot, _ScaleX, _ScaleZ);
rCS.render2D(*_Driver, x+_ShadeExtent, z+_ShadeExtent, _HotSpot, _ScaleX, _ScaleZ);
}
rCS.Color= bkup; rCS.Color= bkup;
} }
rCS.render2D (*_Driver, x, z, _HotSpot, _ScaleX, _ScaleZ); rCS.render2D(*_Driver, x, z, _HotSpot, _ScaleX, _ScaleZ);
} }
/** Clip and print a string that is in the cache (it leaves the string in the cache) /** Clip and print a string that is in the cache (it leaves the string in the cache)
@ -162,6 +172,12 @@ public:
rCS.Color= _ShadeColor; rCS.Color= _ShadeColor;
rCS.Color.A = (uint8)((uint(bkup.A) * uint(_ShadeColor.A)+1)>>8); rCS.Color.A = (uint8)((uint(bkup.A) * uint(_ShadeColor.A)+1)>>8);
rCS.render2DClip(*_Driver, rdrBuffer, x+_ShadeExtent, z-_ShadeExtent, xmin, ymin, xmax, ymax); rCS.render2DClip(*_Driver, rdrBuffer, x+_ShadeExtent, z-_ShadeExtent, xmin, ymin, xmax, ymax);
if (_ShadeOutline)
{
rCS.render2DClip(*_Driver, rdrBuffer, x-_ShadeExtent, z-_ShadeExtent, xmin, ymin, xmax, ymax);
rCS.render2DClip(*_Driver, rdrBuffer, x-_ShadeExtent, z+_ShadeExtent, xmin, ymin, xmax, ymax);
rCS.render2DClip(*_Driver, rdrBuffer, x+_ShadeExtent, z+_ShadeExtent, xmin, ymin, xmax, ymax);
}
rCS.Color= bkup; rCS.Color= bkup;
} }
rCS.render2DClip (*_Driver, rdrBuffer, x, z, xmin, ymin, xmax, ymax); rCS.render2DClip (*_Driver, rdrBuffer, x, z, xmin, ymin, xmax, ymax);
@ -174,12 +190,18 @@ public:
{ {
nlassert (index < _CacheStrings.size()); nlassert (index < _CacheStrings.size());
CComputedString &rCS = _CacheStrings[index]; CComputedString &rCS = _CacheStrings[index];
if(_Shaded) if (_Shaded)
{ {
CRGBA bkup = rCS.Color; CRGBA bkup = rCS.Color;
rCS.Color= _ShadeColor; rCS.Color= _ShadeColor;
rCS.Color.A = (uint8)((uint(bkup.A) * uint(_ShadeColor.A)+1)>>8); rCS.Color.A = (uint8)((uint(bkup.A) * uint(_ShadeColor.A)+1)>>8);
rCS.render2DUnProjected (*_Driver, renderBuffer, frustum, scaleMatrix, x+_ShadeExtent, y-_ShadeExtent, depth, xmin, ymin, xmax, ymax); rCS.render2DUnProjected (*_Driver, renderBuffer, frustum, scaleMatrix, x+_ShadeExtent, y-_ShadeExtent, depth, xmin, ymin, xmax, ymax);
if (_ShadeOutline)
{
rCS.render2DUnProjected (*_Driver, renderBuffer, frustum, scaleMatrix, x-_ShadeExtent, y-_ShadeExtent, depth, xmin, ymin, xmax, ymax);
rCS.render2DUnProjected (*_Driver, renderBuffer, frustum, scaleMatrix, x-_ShadeExtent, y+_ShadeExtent, depth, xmin, ymin, xmax, ymax);
rCS.render2DUnProjected (*_Driver, renderBuffer, frustum, scaleMatrix, x+_ShadeExtent, y+_ShadeExtent, depth, xmin, ymin, xmax, ymax);
}
rCS.Color= bkup; rCS.Color= bkup;
} }
rCS.render2DUnProjected (*_Driver, renderBuffer, frustum, scaleMatrix, x, y, depth, xmin, ymin, xmax, ymax); rCS.render2DUnProjected (*_Driver, renderBuffer, frustum, scaleMatrix, x, y, depth, xmin, ymin, xmax, ymax);
@ -194,17 +216,23 @@ public:
_FontManager->computeString (ucstr, _FontGen, _Color, _FontSize, _Driver, _TempString, _Keep800x600Ratio); _FontManager->computeString (ucstr, _FontGen, _Color, _FontSize, _Driver, _TempString, _Keep800x600Ratio);
// draw shaded // draw shaded
if(_Shaded) if (_Shaded)
{ {
CRGBA bkup = _TempString.Color; CRGBA bkup = _TempString.Color;
_TempString.Color= _ShadeColor; _TempString.Color = _ShadeColor;
_TempString.Color.A = (uint8)((uint(bkup.A) * uint(_ShadeColor.A)+1)>>8); _TempString.Color.A = (uint8)((uint(bkup.A) * uint(_ShadeColor.A)+1)>>8);
_TempString.render2D (*_Driver,x+_ShadeExtent,z-_ShadeExtent,_HotSpot,_ScaleX,_ScaleZ); _TempString.render2D(*_Driver,x+_ShadeExtent,z-_ShadeExtent,_HotSpot,_ScaleX,_ScaleZ);
_TempString.Color= bkup; if (_ShadeOutline)
{
_TempString.render2D(*_Driver,x-_ShadeExtent,z-_ShadeExtent,_HotSpot,_ScaleX,_ScaleZ);
_TempString.render2D(*_Driver,x-_ShadeExtent,z+_ShadeExtent,_HotSpot,_ScaleX,_ScaleZ);
_TempString.render2D(*_Driver,x+_ShadeExtent,z+_ShadeExtent,_HotSpot,_ScaleX,_ScaleZ);
}
_TempString.Color = bkup;
} }
// draw // draw
_TempString.render2D (*_Driver, x, z, _HotSpot, _ScaleX, _ScaleZ); _TempString.render2D(*_Driver, x, z, _HotSpot, _ScaleX, _ScaleZ);
} }
/// Directly print a string /// Directly print a string
@ -218,17 +246,23 @@ public:
_FontManager->computeString (str, _FontGen, _Color, _FontSize, _Driver, _TempString, _Keep800x600Ratio); _FontManager->computeString (str, _FontGen, _Color, _FontSize, _Driver, _TempString, _Keep800x600Ratio);
// draw shaded // draw shaded
if(_Shaded) if (_Shaded)
{ {
CRGBA bkup = _TempString.Color; CRGBA bkup = _TempString.Color;
_TempString.Color = _ShadeColor; _TempString.Color = _ShadeColor;
_TempString.Color.A = (uint8)((uint(bkup.A) * uint(_ShadeColor.A)+1)>>8); _TempString.Color.A = (uint8)((uint(bkup.A) * uint(_ShadeColor.A)+1)>>8);
_TempString.render2D (*_Driver,x+_ShadeExtent,z-_ShadeExtent,_HotSpot,_ScaleX,_ScaleZ); _TempString.render2D(*_Driver,x+_ShadeExtent,z-_ShadeExtent,_HotSpot,_ScaleX,_ScaleZ);
_TempString.Color= bkup; if (_ShadeOutline)
{
_TempString.render2D(*_Driver,x-_ShadeExtent,z-_ShadeExtent,_HotSpot,_ScaleX,_ScaleZ);
_TempString.render2D(*_Driver,x-_ShadeExtent,z+_ShadeExtent,_HotSpot,_ScaleX,_ScaleZ);
_TempString.render2D(*_Driver,x+_ShadeExtent,z+_ShadeExtent,_HotSpot,_ScaleX,_ScaleZ);
}
_TempString.Color = bkup;
} }
// draw // draw
_TempString.render2D (*_Driver, x, z, _HotSpot, _ScaleX, _ScaleZ); _TempString.render2D(*_Driver, x, z, _HotSpot, _ScaleX, _ScaleZ);
} }
/// Get computed string from index /// Get computed string from index
@ -317,6 +351,9 @@ private:
/// true if text is shaded /// true if text is shaded
bool _Shaded; bool _Shaded;
/// true if shade appears as an outline
bool _ShadeOutline;
/// shade's extent (shadow size) /// shade's extent (shadow size)
float _ShadeExtent; float _ShadeExtent;

View file

@ -64,16 +64,18 @@ public:
/// \name Text look. /// \name Text look.
// @{ // @{
void setColor(NLMISC::CRGBA color); void setColor(NLMISC::CRGBA color);
void setFontSize(uint32 fontSize) ; void setFontSize(uint32 fontSize);
uint32 getFontSize() const ; uint32 getFontSize() const;
void setHotSpot(THotSpot hotSpot) ; void setHotSpot(THotSpot hotSpot);
THotSpot getHotSpot() const ; THotSpot getHotSpot() const;
void setScaleX(float scaleX) ; void setScaleX(float scaleX);
void setScaleY(float scaleY) ; void setScaleY(float scaleY);
float getScaleX() const ; float getScaleX() const;
float getScaleY() const ; float getScaleY() const;
void setShaded(bool b) ; void setShaded(bool b);
bool getShaded() const ; bool getShaded() const;
void setShadeOutline(bool b);
bool getShadeOutline() const;
void setShadeExtent(float shext) ; void setShadeExtent(float shext) ;
void setShadeColor (NLMISC::CRGBA sc); void setShadeColor (NLMISC::CRGBA sc);
NLMISC::CRGBA getShadeColor () const; NLMISC::CRGBA getShadeColor () const;

View file

@ -174,6 +174,15 @@ public:
* \return the shade state * \return the shade state
*/ */
virtual bool getShaded () const = 0; virtual bool getShaded () const = 0;
/**
* set the shade states
* \param the shade state
*/
virtual void setShadeOutline (bool b) = 0;
/**
* \return the shade state
*/
virtual bool getShadeOutline () const = 0;
/** /**
* set the shadow's size * set the shadow's size
* \param the shade extent * \param the shade extent

View file

@ -40,6 +40,7 @@ CTextContext::CTextContext()
_ScaleZ = 1.0f; _ScaleZ = 1.0f;
_Shaded = false; _Shaded = false;
_ShadeOutline = false;
_ShadeExtent = 0.001f; _ShadeExtent = 0.001f;
_ShadeColor = NLMISC::CRGBA(0,0,0); _ShadeColor = NLMISC::CRGBA(0,0,0);

View file

@ -148,6 +148,18 @@ bool CTextContextUser::getShaded() const
return _TextContext.getShaded(); return _TextContext.getShaded();
} }
void CTextContextUser::setShadeOutline(bool b)
{
H_AUTO2;
_TextContext.setShadeOutline(b);
}
bool CTextContextUser::getShadeOutline() const
{
H_AUTO2;
return _TextContext.getShadeOutline();
}
void CTextContextUser::setShadeExtent(float shext) void CTextContextUser::setShadeExtent(float shext)
{ {
H_AUTO2; H_AUTO2;