Implement text shade outline

--HG--
branch : develop
This commit is contained in:
kaetemi 2014-10-08 23:20:34 +02:00
parent dc3238b111
commit 3edfd56c75
5 changed files with 88 additions and 27 deletions

View file

@ -82,6 +82,8 @@ public:
void setShaded (bool b) { _Shaded = b; }
void setShadeOutline (bool b) { _ShadeOutline = b; }
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)
@ -107,6 +109,8 @@ public:
bool getShaded() const { return _Shaded; }
bool getShadeOutline() const { return _ShadeOutline; }
bool getKeep800x600Ratio() const {return _Keep800x600Ratio;}
NLMISC::CRGBA getShadeColor () const { return _ShadeColor; }
@ -138,15 +142,21 @@ public:
{
nlassert (index < _CacheStrings.size());
CComputedString &rCS = _CacheStrings[index];
if(_Shaded)
if (_Shaded)
{
CRGBA bkup = rCS.Color;
CRGBA bkup = rCS.Color;
rCS.Color = _ShadeColor;
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.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)
@ -162,6 +172,12 @@ public:
rCS.Color= _ShadeColor;
rCS.Color.A = (uint8)((uint(bkup.A) * uint(_ShadeColor.A)+1)>>8);
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.render2DClip (*_Driver, rdrBuffer, x, z, xmin, ymin, xmax, ymax);
@ -174,12 +190,18 @@ public:
{
nlassert (index < _CacheStrings.size());
CComputedString &rCS = _CacheStrings[index];
if(_Shaded)
if (_Shaded)
{
CRGBA bkup = rCS.Color;
rCS.Color= _ShadeColor;
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);
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.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);
// draw shaded
if(_Shaded)
if (_Shaded)
{
CRGBA bkup = _TempString.Color;
_TempString.Color= _ShadeColor;
_TempString.Color = _ShadeColor;
_TempString.Color.A = (uint8)((uint(bkup.A) * uint(_ShadeColor.A)+1)>>8);
_TempString.render2D (*_Driver,x+_ShadeExtent,z-_ShadeExtent,_HotSpot,_ScaleX,_ScaleZ);
_TempString.Color= bkup;
_TempString.render2D(*_Driver,x+_ShadeExtent,z-_ShadeExtent,_HotSpot,_ScaleX,_ScaleZ);
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
_TempString.render2D (*_Driver, x, z, _HotSpot, _ScaleX, _ScaleZ);
_TempString.render2D(*_Driver, x, z, _HotSpot, _ScaleX, _ScaleZ);
}
/// Directly print a string
@ -218,17 +246,23 @@ public:
_FontManager->computeString (str, _FontGen, _Color, _FontSize, _Driver, _TempString, _Keep800x600Ratio);
// draw shaded
if(_Shaded)
if (_Shaded)
{
CRGBA bkup = _TempString.Color;
_TempString.Color = _ShadeColor;
_TempString.Color.A = (uint8)((uint(bkup.A) * uint(_ShadeColor.A)+1)>>8);
_TempString.render2D (*_Driver,x+_ShadeExtent,z-_ShadeExtent,_HotSpot,_ScaleX,_ScaleZ);
_TempString.Color= bkup;
_TempString.render2D(*_Driver,x+_ShadeExtent,z-_ShadeExtent,_HotSpot,_ScaleX,_ScaleZ);
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
_TempString.render2D (*_Driver, x, z, _HotSpot, _ScaleX, _ScaleZ);
_TempString.render2D(*_Driver, x, z, _HotSpot, _ScaleX, _ScaleZ);
}
/// Get computed string from index
@ -317,6 +351,9 @@ private:
/// true if text is shaded
bool _Shaded;
/// true if shade appears as an outline
bool _ShadeOutline;
/// shade's extent (shadow size)
float _ShadeExtent;

View file

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

View file

@ -174,6 +174,15 @@ public:
* \return the shade state
*/
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
* \param the shade extent

View file

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

View file

@ -148,6 +148,18 @@ bool CTextContextUser::getShaded() const
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)
{
H_AUTO2;