Added Text::setFillColor to substrings from the text string.

Renamed Text::setFlags and Text::getFlags to Text::setAlign and Text::getAlign.
A couple of random fixes.

--HG--
branch : dev
This commit is contained in:
Martí­n Lucas Golini
2017-03-24 02:10:39 -03:00
parent 2a0005a8d2
commit b29b8bcd69
14 changed files with 437 additions and 321 deletions

View File

@@ -262,7 +262,7 @@ class EE_API BatchRenderer {
void rotate( const Vector2f& center, Vector2f* point, const Float& angle );
void setBlendMode( EE_DRAW_MODE Mode, const bool& Force );
void setDrawMode( const EE_DRAW_MODE & Mode, const bool& Force );
};
}}

View File

@@ -9,28 +9,28 @@ enum EE_FONT_TYPE {
};
enum EE_FONT_HALIGN {
FONT_DRAW_LEFT = (0 << 0),
FONT_DRAW_RIGHT = (1 << 0),
FONT_DRAW_CENTER = (2 << 0),
FONT_DRAW_HALIGN_MASK = (3 << 0)
TEXT_ALIGN_LEFT = (0 << 0),
TEXT_ALIGN_RIGHT = (1 << 0),
TEXT_ALIGN_CENTER = (2 << 0),
TEXT_HALIGN_MASK = (3 << 0)
};
enum EE_FONT_VALIGN {
FONT_DRAW_TOP = (0 << 2),
FONT_DRAW_BOTTOM = (1 << 2),
FONT_DRAW_MIDDLE = (2 << 2),
FONT_DRAW_VALIGN_MASK = (3 << 2)
TEXT_ALIGN_TOP = (0 << 2),
TEXT_ALIGN_BOTTOM = (1 << 2),
TEXT_ALIGN_MIDDLE = (2 << 2),
TEXT_VALIGN_MASK = (3 << 2)
};
inline Uint32 fontHAlignGet( Uint32 Flags ) {
return Flags & FONT_DRAW_HALIGN_MASK;
return Flags & TEXT_HALIGN_MASK;
}
inline Uint32 fontVAlignGet( Uint32 Flags ) {
return Flags & FONT_DRAW_VALIGN_MASK;
return Flags & TEXT_VALIGN_MASK;
}
#define FONT_DRAW_ALIGN_MASK ( FONT_DRAW_VALIGN_MASK | FONT_DRAW_HALIGN_MASK )
#define TEXT_ALIGN_MASK ( TEXT_VALIGN_MASK | TEXT_HALIGN_MASK )
#define EE_TTF_FONT_MAGIC ( ( 'E' << 0 ) | ( 'E' << 8 ) | ( 'F' << 16 ) | ( 'N' << 24 ) )

View File

@@ -40,6 +40,8 @@ class EE_API Text {
void setFillColor(const ColorA& color);
void setFillColor(const ColorA& color, Uint32 from, Uint32 to);
void setOutlineColor(const ColorA& color);
void setOutlineThickness(Float thickness);
@@ -90,11 +92,11 @@ class EE_API Text {
/** @return Every cached text line width */
const std::vector<Float>& getLinesWidth();
/** Set the font draw flags */
void setFlags( const Uint32& flags );
/** Set the text draw align */
void setAlign( const Uint32& align );
/** @return The font draw flags */
const Uint32& getFlags() const;
/** @return The text align */
const Uint32& getAlign() const;
/** @return The number of lines that the cached text contains */
const int& getNumLines();
@@ -119,12 +121,13 @@ class EE_API Text {
mutable Rectf mBounds; ///< Bounding rectangle of the text (in local coordinates)
mutable bool mGeometryNeedUpdate; ///< Does the geometry need to be recomputed?
mutable bool mCachedWidthNeedUpdate;
mutable bool mColorsNeedUpdate;
Float mCachedWidth;
int mNumLines;
int mLargestLineCharCount;
ColorA mFontShadowColor;
Uint32 mFlags;
Uint32 mAlign;
Uint32 mFontHeight;
std::vector<VertexCoords> mVertices;
@@ -136,12 +139,16 @@ class EE_API Text {
void ensureGeometryUpdate();
void ensureColorUpdate();
/** Force to cache the width of the current text */
void cacheWidth();
static void addLine(std::vector<VertexCoords>& vertices, std::vector<ColorA>& colors, Float lineLength, Float lineTop, const EE::System::ColorA& color, Float offset, Float thickness, Float outlineThickness, Sizei textureSize, Int32 centerDiffX);
static void addLine(std::vector<VertexCoords>& vertice, Float lineLength, Float lineTop, Float offset, Float thickness, Float outlineThickness, Sizei textureSize, Int32 centerDiffX);
static void addGlyphQuad(std::vector<VertexCoords>& vertices, std::vector<ColorA>& colors, Vector2f position, const EE::System::ColorA& color, const EE::Graphics::Glyph& glyph, Float italic, Float outlineThickness, Sizei textureSize, Int32 centerDiffX);
static void addGlyphQuad(std::vector<VertexCoords>& vertices, Vector2f position, const EE::Graphics::Glyph& glyph, Float italic, Float outlineThickness, Sizei textureSize, Int32 centerDiffX);
Uint32 getTotalVertices();
};
}}

View File

@@ -28,10 +28,10 @@ enum UI_CONTROL_FLAGS_VALUES {
UI_CTRL_FLAG_FREE_USE = (1<<31)
};
#define UI_HALIGN_LEFT FONT_DRAW_LEFT
#define UI_HALIGN_MASK FONT_DRAW_HALIGN_MASK
#define UI_VALIGN_TOP FONT_DRAW_TOP
#define UI_VALIGN_MASK FONT_DRAW_VALIGN_MASK
#define UI_HALIGN_LEFT TEXT_ALIGN_LEFT
#define UI_HALIGN_MASK TEXT_HALIGN_MASK
#define UI_VALIGN_TOP TEXT_ALIGN_TOP
#define UI_VALIGN_MASK TEXT_VALIGN_MASK
inline Uint32 HAlignGet( Uint32 Flags ) {
return Flags & UI_HALIGN_MASK;
@@ -42,10 +42,10 @@ inline Uint32 VAlignGet( Uint32 Flags ) {
}
enum UI_FLAGS {
UI_HALIGN_RIGHT = FONT_DRAW_RIGHT,
UI_HALIGN_CENTER = FONT_DRAW_CENTER,
UI_VALIGN_BOTTOM = FONT_DRAW_BOTTOM,
UI_VALIGN_CENTER = FONT_DRAW_MIDDLE,
UI_HALIGN_RIGHT = TEXT_ALIGN_RIGHT,
UI_HALIGN_CENTER = TEXT_ALIGN_CENTER,
UI_VALIGN_BOTTOM = TEXT_ALIGN_BOTTOM,
UI_VALIGN_CENTER = TEXT_ALIGN_MIDDLE,
UI_AUTO_SIZE = (1 << 4),
UI_SKIN_KEEP_SIZE_ON_DRAW = (1 << 5),
UI_FILL_BACKGROUND = (1 << 6),

View File

@@ -34,10 +34,6 @@ class EE_API UIWinMenu : public UIWidget {
void setMarginBetweenButtons(const Uint32 & marginBetweenButtons);
UITooltipStyleConfig getFontStyleConfig() const;
void setFontStyleConfig(const UITooltipStyleConfig & fontStyleConfig);
UIWinMenuStyleConfig getStyleConfig() const;
void setStyleConfig(const UIWinMenuStyleConfig & styleConfig);

View File

@@ -92,7 +92,7 @@ void BatchRenderer::addVertexs( const unsigned int& num ) {
flush();
}
void BatchRenderer::setBlendMode( EE_DRAW_MODE Mode, const bool& Force ) {
void BatchRenderer::setDrawMode( const EE_DRAW_MODE& Mode, const bool& Force ) {
if ( Force && mCurrentMode != Mode ) {
flush();
mCurrentMode = Mode;
@@ -191,7 +191,7 @@ void BatchRenderer::batchQuadEx( Float x, Float y, Float width, Float height, Fl
originPoint.x += x;
originPoint.y += y;
setBlendMode( DM_QUADS, mForceBlendMode );
setDrawMode( DM_QUADS, mForceBlendMode );
if ( GLi->quadsSupported() ) {
mTVertex = &mVertex[ mNumVertex ];
@@ -270,7 +270,7 @@ void BatchRenderer::batchQuadFree( const Float& x0, const Float& y0, const Float
if ( mNumVertex + ( GLi->quadsSupported() ? 3 : 5 ) >= mVertexSize )
return;
setBlendMode( DM_QUADS, mForceBlendMode );
setDrawMode( DM_QUADS, mForceBlendMode );
if ( GLi->quadsSupported() ) {
mTVertex = &mVertex[ mNumVertex ];
@@ -354,7 +354,7 @@ void BatchRenderer::batchQuadFreeEx( const Float& x0, const Float& y0, const Flo
mQ.scale( Scale, QCenter );
}
setBlendMode( DM_QUADS, mForceBlendMode );
setDrawMode( DM_QUADS, mForceBlendMode );
if ( GLi->quadsSupported() ) {
mTVertex = &mVertex[ mNumVertex ];
@@ -424,7 +424,7 @@ void BatchRenderer::batchQuadFreeEx( const Float& x0, const Float& y0, const Flo
}
void BatchRenderer::quadsBegin() {
setBlendMode( DM_QUADS, true );
setDrawMode( DM_QUADS, true );
quadsSetSubset( 0, 0, 1, 1 );
quadsSetColor( ColorA() );
}
@@ -465,7 +465,7 @@ void BatchRenderer::rotate( const Vector2f& center, Vector2f* point, const Float
}
void BatchRenderer::pointsBegin() {
setBlendMode( DM_POINTS, true );
setDrawMode( DM_POINTS, true );
quadsSetSubset( 0, 0, 1, 1 );
pointSetColor( ColorA() );
}
@@ -478,7 +478,7 @@ void BatchRenderer::batchPoint( const Float& x, const Float& y ) {
if ( mNumVertex + 1 >= mVertexSize )
return;
setBlendMode( DM_POINTS, mForceBlendMode );
setDrawMode( DM_POINTS, mForceBlendMode );
mTVertex = &mVertex[ mNumVertex ];
mTVertex->pos.x = x;
@@ -490,7 +490,7 @@ void BatchRenderer::batchPoint( const Float& x, const Float& y ) {
}
void BatchRenderer::linesBegin() {
setBlendMode( DM_LINES, true );
setDrawMode( DM_LINES, true );
quadsSetSubset( 0, 0, 1, 1 );
pointSetColor( ColorA() );
}
@@ -507,7 +507,7 @@ void BatchRenderer::batchLine( const Float& x0, const Float& y0, const Float& x1
if ( mNumVertex + 1 >= mVertexSize )
return;
setBlendMode( DM_LINES, mForceBlendMode );
setDrawMode( DM_LINES, mForceBlendMode );
mTVertex = &mVertex[ mNumVertex ];
mTVertex->pos.x = x0;
@@ -525,7 +525,7 @@ void BatchRenderer::batchLine( const Float& x0, const Float& y0, const Float& x1
}
void BatchRenderer::lineLoopBegin() {
setBlendMode( DM_LINE_LOOP, true );
setDrawMode( DM_LINE_LOOP, true );
quadsSetSubset( 0, 0, 1, 1 );
pointSetColor( ColorA() );
}
@@ -542,7 +542,7 @@ void BatchRenderer::batchLineLoop( const Float& x0, const Float& y0, const Float
if ( mNumVertex + 1 >= mVertexSize )
return;
setBlendMode( DM_LINE_LOOP, mForceBlendMode );
setDrawMode( DM_LINE_LOOP, mForceBlendMode );
mTVertex = &mVertex[ mNumVertex ];
mTVertex->pos.x = x0;
@@ -567,7 +567,7 @@ void BatchRenderer::batchLineLoop( const Float& x0, const Float& y0 ) {
if ( mNumVertex + 1 >= mVertexSize )
return;
setBlendMode( DM_LINE_LOOP, mForceBlendMode );
setDrawMode( DM_LINE_LOOP, mForceBlendMode );
mTVertex = &mVertex[ mNumVertex ];
mTVertex->pos.x = x0;
@@ -583,7 +583,7 @@ void BatchRenderer::batchLineLoop( const Vector2f& vector1 ) {
}
void BatchRenderer::lineStripBegin() {
setBlendMode( DM_LINE_STRIP, true );
setDrawMode( DM_LINE_STRIP, true );
quadsSetSubset( 0, 0, 1, 1 );
pointSetColor( ColorA() );
}
@@ -600,7 +600,7 @@ void BatchRenderer::batchLineStrip( const Float& x0, const Float& y0, const Floa
if ( mNumVertex + 1 >= mVertexSize )
return;
setBlendMode( DM_LINE_STRIP, mForceBlendMode );
setDrawMode( DM_LINE_STRIP, mForceBlendMode );
mTVertex = &mVertex[ mNumVertex ];
mTVertex->pos.x = x0;
@@ -625,7 +625,7 @@ void BatchRenderer::batchLineStrip( const Float& x0, const Float& y0 ) {
if ( mNumVertex + 1 >= mVertexSize )
return;
setBlendMode( DM_LINE_STRIP, mForceBlendMode );
setDrawMode( DM_LINE_STRIP, mForceBlendMode );
mTVertex = &mVertex[ mNumVertex ];
mTVertex->pos.x = x0;
@@ -641,7 +641,7 @@ void BatchRenderer::batchLineStrip( const Vector2f& vector1 ) {
}
void BatchRenderer::triangleFanBegin() {
setBlendMode( DM_TRIANGLE_FAN, true );
setDrawMode( DM_TRIANGLE_FAN, true );
triangleFanSetSubset( 0, 0, 0, 1, 1, 1 );
triangleFanSetColor( ColorA() );
}
@@ -665,7 +665,7 @@ void BatchRenderer::batchTriangleFan( const Float& x0, const Float& y0, const Fl
if ( mNumVertex + 3 >= mVertexSize )
return;
setBlendMode( DM_TRIANGLE_FAN, mForceBlendMode );
setDrawMode( DM_TRIANGLE_FAN, mForceBlendMode );
mTVertex = &mVertex[ mNumVertex ];
mTVertex->pos.x = x0;
@@ -692,7 +692,7 @@ void BatchRenderer::batchTriangleFan( const Float& x0, const Float& y0 ) {
if ( mNumVertex + 1 >= mVertexSize )
return;
setBlendMode( DM_TRIANGLE_FAN, mForceBlendMode );
setDrawMode( DM_TRIANGLE_FAN, mForceBlendMode );
mTVertex = &mVertex[ mNumVertex ];
mTVertex->pos.x = x0;
@@ -704,7 +704,7 @@ void BatchRenderer::batchTriangleFan( const Float& x0, const Float& y0 ) {
}
void BatchRenderer::trianglesBegin() {
setBlendMode( DM_TRIANGLES, true );
setDrawMode( DM_TRIANGLES, true );
trianglesSetSubset( 0, 0, 0, 1, 1, 1 );
trianglesSetColor( ColorA() );
}
@@ -728,7 +728,7 @@ void BatchRenderer::batchTriangle( const Float& x0, const Float& y0, const Float
if ( mNumVertex + 2 >= mVertexSize )
return;
setBlendMode( DM_TRIANGLES, mForceBlendMode );
setDrawMode( DM_TRIANGLES, mForceBlendMode );
mTVertex = &mVertex[ mNumVertex ];
mTVertex->pos.x = x0;
@@ -759,7 +759,7 @@ void BatchRenderer::batchPolygon( const Polygon2f& Polygon ) {
if ( Polygon.getSize() > mVertexSize )
return;
setBlendMode( DM_POLYGON, mForceBlendMode );
setDrawMode( DM_POLYGON, mForceBlendMode );
for ( Uint32 i = 0; i < Polygon.getSize(); i++ ) {
mTVertex = &mVertex[ mNumVertex ];
@@ -777,7 +777,7 @@ void BatchRenderer::batchPolygonByPoint( const Float& x, const Float& y ) {
if ( mNumVertex + 1 >= mVertexSize )
return;
setBlendMode( DM_POLYGON, mForceBlendMode );
setDrawMode( DM_POLYGON, mForceBlendMode );
mTVertex = &mVertex[ mNumVertex ];
mTVertex->pos.x = x;

View File

@@ -7,178 +7,6 @@
#include <algorithm>
#include <cmath>
namespace EE { namespace Graphics {
// Add an underline or strikethrough line to the vertex array
void Text::addLine(std::vector<VertexCoords>& vertices, std::vector<ColorA>& colors, Float lineLength, Float lineTop, const EE::System::ColorA& color, Float offset, Float thickness, Float outlineThickness, Sizei textureSize, Int32 centerDiffX) {
Float top = std::floor(lineTop + offset - (thickness / 2) + 0.5f);
Float bottom = top + std::floor(thickness + 0.5f);
Float u1 = 0;
Float v1 = 0;
Float u2 = 1 / (Float)textureSize.getWidth();
Float v2 = 1 / (Float)textureSize.getHeight();
VertexCoords vc;
if ( GLi->quadsSupported() ) {
vc.texCoords.x = u1;
vc.texCoords.y = v1;
vc.position.x = centerDiffX + -outlineThickness;
vc.position.y = top - outlineThickness;
colors.push_back( color );
vertices.push_back( vc );
vc.texCoords.x = u1;
vc.texCoords.y = v2;
vc.position.x = centerDiffX + -outlineThickness;
vc.position.y = bottom + outlineThickness;
colors.push_back( color );
vertices.push_back( vc );
vc.texCoords.x = u2;
vc.texCoords.y = v2;
vc.position.x = centerDiffX + lineLength + outlineThickness;
vc.position.y = bottom + outlineThickness;
colors.push_back( color );
vertices.push_back( vc );
vc.texCoords.x = u2;
vc.texCoords.y = v1;
vc.position.x = centerDiffX + lineLength + outlineThickness;
vc.position.y = top - outlineThickness;
colors.push_back( color );
vertices.push_back( vc );
} else {
vc.texCoords.x = u1;
vc.texCoords.y = v2;
vc.position.x = centerDiffX + -outlineThickness;
vc.position.y = bottom + outlineThickness;
colors.push_back( color );
vertices.push_back( vc );
vc.texCoords.x = u1;
vc.texCoords.y = v1;
vc.position.x = centerDiffX + -outlineThickness;
vc.position.y = top - outlineThickness;
colors.push_back( color );
vertices.push_back( vc );
vc.texCoords.x = u2;
vc.texCoords.y = v1;
vc.position.x = centerDiffX + lineLength + outlineThickness;
vc.position.y = top - outlineThickness;
colors.push_back( color );
vertices.push_back( vc );
vc.texCoords.x = u1;
vc.texCoords.y = v2;
vc.position.x = centerDiffX + -outlineThickness;
vc.position.y = bottom + outlineThickness;
colors.push_back( color );
vertices.push_back( vc );
vc.texCoords.x = u2;
vc.texCoords.y = v2;
vc.position.x = centerDiffX + lineLength + outlineThickness;
vc.position.y = bottom + outlineThickness;
colors.push_back( color );
vertices.push_back( vc );
vc.texCoords.x = u2;
vc.texCoords.y = v1;
vc.position.x = centerDiffX + lineLength + outlineThickness;
vc.position.y = top - outlineThickness;
colors.push_back( color );
vertices.push_back( vc );
}
}
// Add a glyph quad to the vertex array
void Text::addGlyphQuad(std::vector<VertexCoords>& vertices, std::vector<ColorA>& colors, Vector2f position, const EE::System::ColorA& color, const EE::Graphics::Glyph& glyph, Float italic, Float outlineThickness, Sizei textureSize, Int32 centerDiffX) {
Float left = glyph.bounds.Left;
Float top = glyph.bounds.Top;
Float right = glyph.bounds.Left + glyph.bounds.Right;
Float bottom = glyph.bounds.Top + glyph.bounds.Bottom;
Float u1 = static_cast<Float>(glyph.textureRect.Left) / (Float)textureSize.getWidth();
Float v1 = static_cast<Float>(glyph.textureRect.Top) / (Float)textureSize.getHeight();
Float u2 = static_cast<Float>(glyph.textureRect.Left + glyph.textureRect.Right) / (Float)textureSize.getWidth();
Float v2 = static_cast<Float>(glyph.textureRect.Top + glyph.textureRect.Bottom) / (Float)textureSize.getHeight();
VertexCoords vc;
if ( GLi->quadsSupported() ) {
vc.texCoords.x = u1;
vc.texCoords.y = v1;
vc.position.x = centerDiffX + position.x + left - italic * top - outlineThickness;
vc.position.y = position.y + top - outlineThickness;
colors.push_back( color );
vertices.push_back( vc );
vc.texCoords.x = u1;
vc.texCoords.y = v2;
vc.position.x = centerDiffX + position.x + left - italic * bottom - outlineThickness;
vc.position.y = position.y + bottom - outlineThickness;
colors.push_back( color );
vertices.push_back( vc );
vc.texCoords.x = u2;
vc.texCoords.y = v2;
vc.position.x = centerDiffX + position.x + right - italic * bottom - outlineThickness;
vc.position.y = position.y + bottom - outlineThickness;
colors.push_back( color );
vertices.push_back( vc );
vc.texCoords.x = u2;
vc.texCoords.y = v1;
vc.position.x = centerDiffX + position.x + right - italic * top - outlineThickness;
vc.position.y = position.y + top - outlineThickness;
colors.push_back( color );
vertices.push_back( vc );
} else {
vc.texCoords.x = u1;
vc.texCoords.y = v2;
vc.position.x = centerDiffX + position.x + left - italic * bottom - outlineThickness;
vc.position.y = position.y + bottom - outlineThickness;
colors.push_back( color );
vertices.push_back( vc );
vc.texCoords.x = u1;
vc.texCoords.y = v1;
vc.position.x = centerDiffX + position.x + left - italic * top - outlineThickness;
vc.position.y = position.y + top - outlineThickness;
colors.push_back( color );
vertices.push_back( vc );
vc.texCoords.x = u2;
vc.texCoords.y = v1;
vc.position.x = centerDiffX + position.x + right - italic * top - outlineThickness;
vc.position.y = position.y + top - outlineThickness;
colors.push_back( color );
vertices.push_back( vc );
vc.texCoords.x = u1;
vc.texCoords.y = v2;
vc.position.x = centerDiffX + position.x + left - italic * bottom - outlineThickness;
vc.position.y = position.y + bottom - outlineThickness;
colors.push_back( color );
vertices.push_back( vc );
vc.texCoords.x = u2;
vc.texCoords.y = v2;
vc.position.x = centerDiffX + position.x + right - italic * bottom - outlineThickness;
vc.position.y = position.y + bottom - outlineThickness;
colors.push_back( color );
vertices.push_back( vc );
vc.texCoords.x = u2;
vc.texCoords.y = v1;
vc.position.x = centerDiffX + position.x + right - italic * top - outlineThickness;
vc.position.y = position.y + top - outlineThickness;
colors.push_back( color );
vertices.push_back( vc );
}
}
}}
namespace EE { namespace Graphics {
Text::Text() :
@@ -192,11 +20,12 @@ Text::Text() :
mOutlineThickness (0),
mGeometryNeedUpdate(false),
mCachedWidthNeedUpdate(false),
mColorsNeedUpdate(false),
mCachedWidth(0),
mNumLines(0),
mLargestLineCharCount(0),
mFontShadowColor( ColorA( 0, 0, 0, 255 ) ),
mFlags(0),
mAlign(0),
mFontHeight(0)
{
}
@@ -212,11 +41,12 @@ Text::Text(const String& string, Font * font, unsigned int characterSize) :
mOutlineThickness(0),
mGeometryNeedUpdate(true),
mCachedWidthNeedUpdate(true),
mColorsNeedUpdate(true),
mCachedWidth(0),
mNumLines(0),
mLargestLineCharCount(0),
mFontShadowColor( ColorA( 0, 0, 0, 255 ) ),
mFlags(0),
mAlign(0),
mFontHeight( mFont->getFontHeight( mRealCharacterSize ) )
{
}
@@ -231,11 +61,12 @@ Text::Text(Font * font, unsigned int characterSize) :
mOutlineThickness(0),
mGeometryNeedUpdate(true),
mCachedWidthNeedUpdate(true),
mColorsNeedUpdate(true),
mCachedWidth(0),
mNumLines(0),
mLargestLineCharCount(0),
mFontShadowColor( ColorA( 0, 0, 0, 255 ) ),
mFlags(0),
mAlign(0),
mFontHeight( mFont->getFontHeight( mRealCharacterSize ) )
{
}
@@ -245,16 +76,18 @@ void Text::create(Font * font, const String & text, ColorA FontColor, ColorA Fon
mString = text;
mCharacterSize = characterSize;
mRealCharacterSize = PixelDensity::dpToPxI(mCharacterSize);
setColor( FontColor );
setFillColor( FontColor );
setShadowColor( FontShadowColor );
mGeometryNeedUpdate = true;
mCachedWidthNeedUpdate = true;
mColorsNeedUpdate = true;
ensureGeometryUpdate();
}
void Text::setString(const String& string) {
if (mString != string) {
mString = string;
mColorsNeedUpdate = true;
mGeometryNeedUpdate = true;
mCachedWidthNeedUpdate = true;
}
@@ -273,7 +106,7 @@ void Text::setFont(Font * font) {
}
void Text::setCharacterSize(unsigned int size) {
if (mCharacterSize != size) {
if ( NULL != mFont && mCharacterSize != size) {
mCharacterSize = size;
mRealCharacterSize = PixelDensity::dpToPxI( mCharacterSize );
@@ -287,6 +120,7 @@ void Text::setCharacterSize(unsigned int size) {
void Text::setStyle(Uint32 style) {
if (mStyle != style) {
mStyle = style;
mColorsNeedUpdate = true;
mGeometryNeedUpdate = true;
mCachedWidthNeedUpdate = true;
}
@@ -299,30 +133,21 @@ void Text::setColor(const ColorA & color) {
void Text::setFillColor(const ColorA& color) {
if (color != mFillColor) {
mFillColor = color;
// Change vertex colors directly, no need to update whole geometry
// (if geometry is updated anyway, we can skip this step)
if (!mGeometryNeedUpdate) {
mColors.assign( mVertices.size(), mFillColor );
}
mColorsNeedUpdate = true;
}
}
void Text::setOutlineColor(const ColorA& color) {
if (color != mOutlineColor) {
mOutlineColor = color;
// Change vertex colors directly, no need to update whole geometry
// (if geometry is updated anyway, we can skip this step)
if (!mGeometryNeedUpdate) {
mOutlineColors.assign( mOutlineVertices.size(), mOutlineColor );
}
mColorsNeedUpdate = true;
}
}
void Text::setOutlineThickness(Float thickness) {
if (thickness != mOutlineThickness) {
mOutlineThickness = thickness;
mColorsNeedUpdate = true;
mGeometryNeedUpdate = true;
mCachedWidthNeedUpdate = true;
}
@@ -454,7 +279,6 @@ void Text::draw(const Float & X, const Float & Y, const Vector2f & Scale, const
if ( Col.a != 255 ) {
ColorA ShadowColor = getShadowColor();
ShadowColor.a = (Uint8)( (Float)ShadowColor.a * ( (Float)Col.a / (Float)255 ) );
setFillColor( ShadowColor );
@@ -462,6 +286,8 @@ void Text::draw(const Float & X, const Float & Y, const Vector2f & Scale, const
setFillColor( getShadowColor() );
}
mColors.assign( mColors.size(), getFillColor() );
Float pd = PixelDensity::dpToPx(1);
draw( X + pd, Y + pd, Scale, Angle, Effect );
@@ -469,6 +295,7 @@ void Text::draw(const Float & X, const Float & Y, const Vector2f & Scale, const
mStyle = f;
setFillColor( Col );
mColors.assign( mColors.size(), getFillColor() );
}
if ( Angle != 0.0f || Scale != 1.0f ) {
@@ -536,9 +363,7 @@ void Text::ensureGeometryUpdate() {
// Clear the previous geometry
mVertices.clear();
mColors.clear();;
mOutlineVertices.clear();
mOutlineColors.clear();
mBounds = Rectf();
// No font or text: nothing to draw
@@ -575,14 +400,15 @@ void Text::ensureGeometryUpdate() {
Float centerDiffX = 0;
unsigned int Line = 0;
ensureColorUpdate();
cacheWidth();
switch ( fontHAlignGet( mFlags ) ) {
case FONT_DRAW_CENTER:
switch ( fontHAlignGet( mAlign ) ) {
case TEXT_ALIGN_CENTER:
centerDiffX = (Float)( (Int32)( ( mCachedWidth - mLinesWidth[ Line ] ) * 0.5f ) );
Line++;
break;
case FONT_DRAW_RIGHT:
case TEXT_ALIGN_RIGHT:
centerDiffX = mCachedWidth - mLinesWidth[ Line ];
Line++;
break;
@@ -597,26 +423,26 @@ void Text::ensureGeometryUpdate() {
// If we're using the underlined style and there's a new line, draw a line
if (underlined && (curChar == L'\n')) {
addLine(mVertices, mColors, x, y, mFillColor, underlineOffset, underlineThickness, 0, textureSize, centerDiffX);
addLine(mVertices, x, y, underlineOffset, underlineThickness, 0, textureSize, centerDiffX);
if (mOutlineThickness != 0)
addLine(mOutlineVertices, mOutlineColors, x, y, mOutlineColor, underlineOffset, underlineThickness, mOutlineThickness, textureSize, centerDiffX);
addLine(mOutlineVertices, x, y, underlineOffset, underlineThickness, mOutlineThickness, textureSize, centerDiffX);
}
// If we're using the strike through style and there's a new line, draw a line across all characters
if (strikeThrough && (curChar == L'\n')) {
addLine(mVertices, mColors, x, y, mFillColor, strikeThroughOffset, underlineThickness, 0, textureSize, centerDiffX);
addLine(mVertices, x, y, strikeThroughOffset, underlineThickness, 0, textureSize, centerDiffX);
if (mOutlineThickness != 0)
addLine(mOutlineVertices, mOutlineColors, x, y, mOutlineColor, strikeThroughOffset, underlineThickness, mOutlineThickness, textureSize, centerDiffX);
addLine(mOutlineVertices, x, y, strikeThroughOffset, underlineThickness, mOutlineThickness, textureSize, centerDiffX);
}
if ( curChar == L'\n' ) {
switch ( fontHAlignGet( mFlags ) ) {
case FONT_DRAW_CENTER:
switch ( fontHAlignGet( mAlign ) ) {
case TEXT_ALIGN_CENTER:
centerDiffX = (Float)( (Int32)( ( mCachedWidth - mLinesWidth[ Line ] ) * 0.5f ) );
break;
case FONT_DRAW_RIGHT:
case TEXT_ALIGN_RIGHT:
centerDiffX = mCachedWidth - mLinesWidth[ Line ];
break;
}
@@ -655,7 +481,7 @@ void Text::ensureGeometryUpdate() {
Float bottom = glyph.bounds.Top + glyph.bounds.Bottom;
// Add the outline glyph to the vertices
addGlyphQuad(mOutlineVertices, mOutlineColors, Vector2f(x, y), mOutlineColor, glyph, italic, mOutlineThickness, textureSize, centerDiffX);
addGlyphQuad(mOutlineVertices, Vector2f(x, y), glyph, italic, mOutlineThickness, textureSize, centerDiffX);
// Update the current bounds with the outlined glyph bounds
minX = std::min(minX, x + left - italic * bottom - mOutlineThickness);
@@ -668,7 +494,7 @@ void Text::ensureGeometryUpdate() {
const Glyph& glyph = mFont->getGlyph(curChar, mRealCharacterSize, bold);
// Add the glyph to the vertices
addGlyphQuad(mVertices, mColors, Vector2f(x, y), mFillColor, glyph, italic, 0, textureSize, centerDiffX);
addGlyphQuad(mVertices, Vector2f(x, y), glyph, italic, 0, textureSize, centerDiffX);
// Update the current bounds with the non outlined glyph bounds
if (mOutlineThickness == 0) {
@@ -689,18 +515,18 @@ void Text::ensureGeometryUpdate() {
// If we're using the underlined style, add the last line
if (underlined && (x > 0)) {
addLine(mVertices, mColors, x, y, mFillColor, underlineOffset, underlineThickness, 0, textureSize, centerDiffX);
addLine(mVertices, x, y, underlineOffset, underlineThickness, 0, textureSize, centerDiffX);
if (mOutlineThickness != 0)
addLine(mOutlineVertices, mOutlineColors, x, y, mOutlineColor, underlineOffset, underlineThickness, mOutlineThickness, textureSize, centerDiffX);
addLine(mOutlineVertices, x, y, underlineOffset, underlineThickness, mOutlineThickness, textureSize, centerDiffX);
}
// If we're using the strike through style, add the last line across all characters
if (strikeThrough && (x > 0)) {
addLine(mVertices, mColors, x, y, mFillColor, strikeThroughOffset, underlineThickness, 0, textureSize, centerDiffX);
addLine(mVertices, x, y, strikeThroughOffset, underlineThickness, 0, textureSize, centerDiffX);
if (mOutlineThickness != 0)
addLine(mOutlineVertices, mOutlineColors, x, y, mOutlineColor, strikeThroughOffset, underlineThickness, mOutlineThickness, textureSize, centerDiffX);
addLine(mOutlineVertices, x, y, strikeThroughOffset, underlineThickness, mOutlineThickness, textureSize, centerDiffX);
}
// Update the bounding rectangle
@@ -710,6 +536,22 @@ void Text::ensureGeometryUpdate() {
mBounds.Bottom = maxY - minY;
}
void Text::ensureColorUpdate() {
if ( mColorsNeedUpdate ) {
Uint32 tv = getTotalVertices();
if ( mColors.size() < tv ) {
mColors.resize( tv, mFillColor );
}
if ( 0 != mOutlineThickness && ( mOutlineColors.size() < tv ) ) {
mOutlineColors.resize( tv, mOutlineColor );
}
mColorsNeedUpdate = false;
}
}
const ColorA& Text::getShadowColor() const {
return mFontShadowColor;
}
@@ -730,15 +572,15 @@ const std::vector<Float>& Text::getLinesWidth() {
return mLinesWidth;
}
void Text::setFlags( const Uint32& flags ) {
if ( mFlags != flags ) {
mFlags = flags;
void Text::setAlign( const Uint32& align ) {
if ( mAlign != align ) {
mAlign = align;
mGeometryNeedUpdate = true;
}
}
const Uint32& Text::getFlags() const {
return mFlags;
const Uint32& Text::getAlign() const {
return mAlign;
}
void Text::cacheWidth() {
@@ -762,4 +604,287 @@ void Text::setStyleConfig( const FontStyleConfig& styleConfig ) {
setOutlineColor( styleConfig.OutlineColor );
}
void Text::setFillColor( const ColorA& color, Uint32 from, Uint32 to ) {
if ( mString.empty() )
return;
ensureColorUpdate();
bool underlined = (mStyle & Underlined) != 0;
bool strikeThrough = (mStyle & StrikeThrough) != 0;
std::vector<ColorA> colors( GLi->quadVertexs(), color );
std::size_t s = mString.size();
if ( to >= s ) {
to = s - 1;
}
if ( from <= to && from < s && to <= s ) {
size_t rto = to + 1;
Int32 rpos = from;
Int32 lpos = 0;
Uint32 i;
Uint32 qsize = sizeof(ColorA) * GLi->quadVertexs();
String::StringBaseType curChar;
// Spaces, new lines and tabs are not rendered, and not counted as a color
// We need to skip those characters as nonexistent chars
for ( i = 0; i < from; i++ ) {
curChar = mString[i];
if ( ' ' == curChar || '\n' == curChar || '\t' == curChar ) {
if ( rpos > 0 ) {
rpos--;
if ( '\n' == curChar) {
if ( underlined )
rpos++;
if ( strikeThrough )
rpos++;
}
}
}
}
for ( Uint32 i = from; i < rto; i++ ) {
curChar = mString[i];
lpos = rpos;
rpos++;
// Same here
if ( ' ' == curChar || '\n' == curChar || '\t' == curChar ) {
if ( rpos > 0 ) {
rpos--;
if ( '\n' == curChar) {
if ( underlined ) {
memcpy( &(mColors[ rpos * GLi->quadVertexs() ]), &colors[0], qsize );
rpos++;
}
if ( strikeThrough ) {
memcpy( &(mColors[ rpos * GLi->quadVertexs() ]), &colors[0], qsize );
rpos++;
}
}
}
}
memcpy( &(mColors[ lpos * GLi->quadVertexs() ]), &colors[0], qsize );
}
if ( rto == s ) {
if ( underlined ) {
lpos++;
Uint32 pos = lpos * GLi->quadVertexs();
if ( pos < mColors.size() )
memcpy( &(mColors[ lpos * GLi->quadVertexs() ]), &colors[0], qsize );
}
if ( strikeThrough ) {
lpos++;
Uint32 pos = lpos * GLi->quadVertexs();
if ( pos < mColors.size() )
memcpy( &(mColors[ lpos * GLi->quadVertexs() ]), &colors[0], qsize );
}
}
}
}
// Add an underline or strikethrough line to the vertex array
void Text::addLine(std::vector<VertexCoords>& vertices, Float lineLength, Float lineTop, Float offset, Float thickness, Float outlineThickness, Sizei textureSize, Int32 centerDiffX) {
Float top = std::floor(lineTop + offset - (thickness / 2) + 0.5f);
Float bottom = top + std::floor(thickness + 0.5f);
Float u1 = 0;
Float v1 = 0;
Float u2 = 1 / (Float)textureSize.getWidth();
Float v2 = 1 / (Float)textureSize.getHeight();
VertexCoords vc;
if ( GLi->quadsSupported() ) {
vc.texCoords.x = u1;
vc.texCoords.y = v1;
vc.position.x = centerDiffX + -outlineThickness;
vc.position.y = top - outlineThickness;
vertices.push_back( vc );
vc.texCoords.x = u1;
vc.texCoords.y = v2;
vc.position.x = centerDiffX + -outlineThickness;
vc.position.y = bottom + outlineThickness;
vertices.push_back( vc );
vc.texCoords.x = u2;
vc.texCoords.y = v2;
vc.position.x = centerDiffX + lineLength + outlineThickness;
vc.position.y = bottom + outlineThickness;
vertices.push_back( vc );
vc.texCoords.x = u2;
vc.texCoords.y = v1;
vc.position.x = centerDiffX + lineLength + outlineThickness;
vc.position.y = top - outlineThickness;
vertices.push_back( vc );
} else {
vc.texCoords.x = u1;
vc.texCoords.y = v2;
vc.position.x = centerDiffX + -outlineThickness;
vc.position.y = bottom + outlineThickness;
vertices.push_back( vc );
vc.texCoords.x = u1;
vc.texCoords.y = v1;
vc.position.x = centerDiffX + -outlineThickness;
vc.position.y = top - outlineThickness;
vertices.push_back( vc );
vc.texCoords.x = u2;
vc.texCoords.y = v1;
vc.position.x = centerDiffX + lineLength + outlineThickness;
vc.position.y = top - outlineThickness;
vertices.push_back( vc );
vc.texCoords.x = u1;
vc.texCoords.y = v2;
vc.position.x = centerDiffX + -outlineThickness;
vc.position.y = bottom + outlineThickness;
vertices.push_back( vc );
vc.texCoords.x = u2;
vc.texCoords.y = v2;
vc.position.x = centerDiffX + lineLength + outlineThickness;
vc.position.y = bottom + outlineThickness;
vertices.push_back( vc );
vc.texCoords.x = u2;
vc.texCoords.y = v1;
vc.position.x = centerDiffX + lineLength + outlineThickness;
vc.position.y = top - outlineThickness;
vertices.push_back( vc );
}
}
// Add a glyph quad to the vertex array
void Text::addGlyphQuad(std::vector<VertexCoords>& vertices, Vector2f position, const EE::Graphics::Glyph& glyph, Float italic, Float outlineThickness, Sizei textureSize, Int32 centerDiffX) {
Float left = glyph.bounds.Left;
Float top = glyph.bounds.Top;
Float right = glyph.bounds.Left + glyph.bounds.Right;
Float bottom = glyph.bounds.Top + glyph.bounds.Bottom;
Float u1 = static_cast<Float>(glyph.textureRect.Left) / (Float)textureSize.getWidth();
Float v1 = static_cast<Float>(glyph.textureRect.Top) / (Float)textureSize.getHeight();
Float u2 = static_cast<Float>(glyph.textureRect.Left + glyph.textureRect.Right) / (Float)textureSize.getWidth();
Float v2 = static_cast<Float>(glyph.textureRect.Top + glyph.textureRect.Bottom) / (Float)textureSize.getHeight();
VertexCoords vc;
if ( GLi->quadsSupported() ) {
vc.texCoords.x = u1;
vc.texCoords.y = v1;
vc.position.x = centerDiffX + position.x + left - italic * top - outlineThickness;
vc.position.y = position.y + top - outlineThickness;
vertices.push_back( vc );
vc.texCoords.x = u1;
vc.texCoords.y = v2;
vc.position.x = centerDiffX + position.x + left - italic * bottom - outlineThickness;
vc.position.y = position.y + bottom - outlineThickness;
vertices.push_back( vc );
vc.texCoords.x = u2;
vc.texCoords.y = v2;
vc.position.x = centerDiffX + position.x + right - italic * bottom - outlineThickness;
vc.position.y = position.y + bottom - outlineThickness;
vertices.push_back( vc );
vc.texCoords.x = u2;
vc.texCoords.y = v1;
vc.position.x = centerDiffX + position.x + right - italic * top - outlineThickness;
vc.position.y = position.y + top - outlineThickness;
vertices.push_back( vc );
} else {
vc.texCoords.x = u1;
vc.texCoords.y = v2;
vc.position.x = centerDiffX + position.x + left - italic * bottom - outlineThickness;
vc.position.y = position.y + bottom - outlineThickness;
vertices.push_back( vc );
vc.texCoords.x = u1;
vc.texCoords.y = v1;
vc.position.x = centerDiffX + position.x + left - italic * top - outlineThickness;
vc.position.y = position.y + top - outlineThickness;
vertices.push_back( vc );
vc.texCoords.x = u2;
vc.texCoords.y = v1;
vc.position.x = centerDiffX + position.x + right - italic * top - outlineThickness;
vc.position.y = position.y + top - outlineThickness;
vertices.push_back( vc );
vc.texCoords.x = u1;
vc.texCoords.y = v2;
vc.position.x = centerDiffX + position.x + left - italic * bottom - outlineThickness;
vc.position.y = position.y + bottom - outlineThickness;
vertices.push_back( vc );
vc.texCoords.x = u2;
vc.texCoords.y = v2;
vc.position.x = centerDiffX + position.x + right - italic * bottom - outlineThickness;
vc.position.y = position.y + bottom - outlineThickness;
vertices.push_back( vc );
vc.texCoords.x = u2;
vc.texCoords.y = v1;
vc.position.x = centerDiffX + position.x + right - italic * top - outlineThickness;
vc.position.y = position.y + top - outlineThickness;
vertices.push_back( vc );
}
}
Uint32 Text::getTotalVertices() {
bool underlined = (mStyle & Underlined) != 0;
bool strikeThrough = (mStyle & StrikeThrough) != 0;
size_t sl = mString.size();
size_t sv = sl * GLi->quadVertexs();
Uint32 * c = &mString[0];
Uint32 skiped = 0;
bool lineHasChars = false;
while ( '\0' != *c ) {
lineHasChars = true;
if ( ' ' == *c || '\n' == *c || '\t' == *c ) {
lineHasChars = false;
skiped++;
if ( '\n' == *c ) {
if ( underlined )
skiped--;
if ( strikeThrough )
skiped--;
}
}
c++;
}
if ( lineHasChars ) {
if ( underlined )
skiped--;
if ( strikeThrough )
skiped--;
}
sv -= skiped * GLi->quadVertexs();
return sv;
}
}}

View File

@@ -55,15 +55,15 @@ void UISelectButton::onStateChange() {
}
}
if ( getParent()->getType() & UI_TYPE_WINMENU ) {
if ( getParent()->isType( UI_TYPE_WINMENU ) ) {
UIWinMenu * Menu = reinterpret_cast<UIWinMenu*> ( getParent() );
if ( mSkinState->getState() == UISkinState::StateSelected ) {
getTextBox()->setFontColor( Menu->getFontStyleConfig().getFontSelectedColor() );
getTextBox()->setFontColor( Menu->getStyleConfig().getFontSelectedColor() );
} else if ( mSkinState->getState() == UISkinState::StateMouseEnter ) {
getTextBox()->setFontColor( Menu->getFontStyleConfig().getFontOverColor() );
getTextBox()->setFontColor( Menu->getStyleConfig().getFontOverColor() );
} else {
getTextBox()->setFontColor( Menu->getFontStyleConfig().getFontColor() );
getTextBox()->setFontColor( Menu->getStyleConfig().getFontColor() );
}
} else {
if ( mSkinState->getState() == UISkinState::StateSelected ) {

View File

@@ -40,7 +40,7 @@ void UITextInputPassword::draw() {
);
}
mPassCache->setFlags( getFlags() );
mPassCache->setAlign( getFlags() );
mPassCache->draw( (Float)mScreenPos.x + mRealAlignOffset.x + (Float)mRealPadding.Left, (Float)mScreenPos.y + mRealAlignOffset.y + (Float)mRealPadding.Top, Vector2f::One, 0.f, getBlendMode() );
if ( mFlags & UI_CLIP_ENABLE ) {

View File

@@ -62,7 +62,7 @@ void UITextView::draw() {
);
}
mTextCache->setFlags( getFlags() );
mTextCache->setAlign( getFlags() );
mTextCache->draw( (Float)mScreenPos.x + mRealAlignOffset.x + (Float)mRealPadding.Left, (Float)mScreenPos.y + mRealAlignOffset.y + (Float)mRealPadding.Top, Vector2f::One, 0.f, getBlendMode() );
if ( mFlags & UI_CLIP_ENABLE ) {

View File

@@ -94,7 +94,7 @@ void UITooltip::draw() {
UIControlAnim::draw();
if ( mTextCache->getTextWidth() ) {
mTextCache->setFlags( getFlags() );
mTextCache->setAlign( getFlags() );
mTextCache->draw( (Float)mScreenPos.x + mAlignOffset.x, (Float)mScreenPos.y + mAlignOffset.y, Vector2f::One, 0.f, getBlendMode() );
}
}

View File

@@ -120,15 +120,6 @@ void UIWinMenu::setMarginBetweenButtons(const Uint32 & marginBetweenButtons) {
refreshButtons();
}
UITooltipStyleConfig UIWinMenu::getFontStyleConfig() const {
return UITooltipStyleConfig(mStyleConfig);
}
void UIWinMenu::setFontStyleConfig(const UITooltipStyleConfig & fontStyleConfig) {
mStyleConfig = fontStyleConfig;
refreshButtons();
}
UIWinMenuStyleConfig UIWinMenu::getStyleConfig() const {
return mStyleConfig;
}

View File

@@ -4,12 +4,12 @@
EE::Window::Window * win = NULL;
FontTrueType * fontTest;
Uint32 nextGliph = 0;
Clock timer;
FontTrueType * fontTest2;
Text text;
Text text2;
Text text3;
void mainLoop()
{
void mainLoop() {
// Clear the screen buffer
win->clear();
@@ -22,68 +22,65 @@ void mainLoop()
win->close();
}
/*
Float YPos = 32;
text.draw( ( win->getWidth() - text.getTextWidth() ) * 0.5f, 32 );
// Draw the text on screen
TTFCache.draw( win->getWidth() * 0.5f - TTFCache.getTextWidth() * 0.5f, YPos );
TTFOCache.draw( ( win->getWidth() - TTFOCache.getTextWidth() ) * 0.5f, ( YPos += TTFCache.getTextHeight() + 24 ) );
TTF2Cache.draw( ( win->getWidth() - TTF2Cache.getTextWidth() ) * 0.5f, ( YPos += TTFOCache.getTextHeight() + 24 ) );
TexFCache.draw( ( win->getWidth() - TexFCache.getTextWidth() ) * 0.5f, ( YPos += TTF2Cache.getTextHeight() + 24 ) );
TexF2Cache.draw( ( win->getWidth() - TexF2Cache.getTextWidth() ) * 0.5f, ( YPos += TexFCache.getTextHeight() + 24 ) );
// Draw the cached text
TxtCache.draw( ( win->getWidth() - TxtCache.getTextWidth() ) * 0.5f, ( YPos += TexF2Cache.getTextHeight() + 24 ) );
text2.draw( ( win->getWidth() - text2.getTextWidth() ) * 0.5f, 300 );
// Text rotated and scaled
TTFCache.draw( ( win->getWidth() - TTFCache.getTextWidth() ) * 0.5f, 512 + 32, Vector2f( 0.75f, 0.75f ), 12.5f );
*/
/*if ( timer.getElapsedTime().asMilliseconds() > 50 ) {
fontTest.getGlyph( nextGliph, 48, false );
nextGliph++;
timer.restart();
}*/
text2.draw( ( win->getWidth() - text2.getTextWidth() ) * 0.5f, 430, Vector2f(1.1f,1.1f), 12.5f );
text.draw( ( win->getWidth() - text.getTextWidth() ) * 0.5f, 0 );
text3.draw( ( win->getWidth() - text3.getTextWidth() ) * 0.5f, 560 );
// Draw frame
win->display();
}
EE_MAIN_FUNC int main (int argc, char * argv [])
{
EE_MAIN_FUNC int main (int argc, char * argv []) {
// Create a new window
win = Engine::instance()->createWindow( WindowSettings( 960, 640, "eepp - Fonts" ), ContextSettings( true ) );
// Set window background color
win->setClearColor( RGB(255,255,255) );
win->setClearColor( Color(230,230,230) );
// Check if created
if ( win->isOpen() ) {
// Get the application path
std::string AppPath = Sys::getProcessPath();
// Save the TTF font so then it can be loaded as a TextureFont
//TTF->save( AppPath + "assets/temp/DejaVuSansMono.png", AppPath + "assets/temp/DejaVuSansMono.fnt" );
// Create a new text string
String Txt( "Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum." );
fontTest = FontTrueType::New( "DejaVuSansMono" );
fontTest->loadFromFile( AppPath + "assets/fonts/DejaVuSansMono.ttf" );
fontTest->shrinkText( Txt, 24, false, 2, win->getWidth() - 96 );
text.setFont( fontTest );
text.setCharacterSize( 24 );
text.setFillColor( 0xFFFFFFFF );
text.setOutlineThickness( 2 );
text.setFlags( FONT_DRAW_CENTER );
text.setAlign( TEXT_ALIGN_CENTER );
text.setString( Txt );
win->setClearColor( RGB(230,230,230) );
// Set the font color to a substring of the text
// Create a gradient
size_t size = Txt.size();
for ( size_t i = 0; i < size; i++ ) {
text.setFillColor( ColorA(255*i/size,0,0,255), i, i+1 );
}
fontTest2 = FontTrueType::New( "Arial" );
fontTest2->loadFromFile( AppPath + "assets/fonts/arial.ttf" );
text2.setFont( fontTest2 );
text2.setString( "Lorem ipsum dolor sit amet, consectetur adipisicing elit." );
text2.setCharacterSize( 32 );
text2.setFillColor( Color::Black );
text3.setFont( fontTest );
text3.setString( text2.getString() );
text3.setOutlineThickness( 2 );
text3.setCharacterSize( 24 );
text3.setFillColor( ColorA(255,255,255,255) );
text3.setOutlineColor( ColorA(0,0,0,255) );
// Application loop
win->runMainLoop( &mainLoop );

View File

@@ -1353,7 +1353,7 @@ void EETest::screen4() {
mVBO->draw();
mVBO->unbind();
mFBOText.setFlags( FONT_DRAW_CENTER );
mFBOText.setAlign( TEXT_ALIGN_CENTER );
mFBOText.draw( 128.f - (Float)(Int32)( mFBOText.getTextWidth() * 0.5f ), 25.f - (Float)(Int32)( mFBOText.getTextHeight() * 0.5f ) );
}
@@ -1435,7 +1435,7 @@ void EETest::render() {
ColorA ColRR2( 100, 100, 100, 220 );
ColorA ColRR3( 100, 100, 100, 220 );
mEEText.setFlags( FONT_DRAW_CENTER );
mEEText.setAlign( TEXT_ALIGN_CENTER );
PR.setColor( ColorA(150, 150, 150, 220) );
PR.setFillMode( DRAW_FILL );