Display text usins Stroke-es. More...
#include <TextDisplay.h>
Public Member Functions | |
| StrokeDisplay (int numOfColumns, int numOfRows, int fontSize, bool drawBackground, bool isCentered) | |
| ~StrokeDisplay () | |
| void | SetFocus (bool focus) |
| StrokeDisplay (int numOfColumns, int numOfRows, int fontSize, bool drawBackground, bool isCentered) | |
| ~StrokeDisplay () | |
| void | SetFocus (bool focus) |
Methods from TextDisplay | |
| bool | Display () |
| Display text (OPEN GL methods) | |
| void | Clear () |
| Clear all text. | |
| bool | Print (const char *msg) |
| Add more text. ' ' is accepted as well. | |
| bool | Display () |
| Display text (OPEN GL methods) | |
| void | Clear () |
| Clear all text. | |
| bool | Print (const char *msg) |
| Add more text. ' ' is accepted as well. | |
Protected Attributes | |
| int | mbBackground |
| int | mbCentered |
| int | mFontSize |
| int | mCols |
| int | mRows |
| int | mColsPos |
| int | mRowsPos |
| double | mFontColor [3] |
| double | mBgColor [4] |
| char ** | mpText |
| An array of lines (text) | |
| double * | mLinePadding |
| int * | mLineWidth |
| Stroke * | mpStroke |
Display text usins Stroke-es.
Definition at line 29 of file TextDisplay.h.
| StrokeDisplay::StrokeDisplay | ( | int | numOfColumns, |
| int | numOfRows, | ||
| int | fontSize, | ||
| bool | drawBackground, | ||
| bool | isCentered | ||
| ) |
Definition at line 14 of file TextDisplay.cpp.
References Clear(), mBgColor, mFontColor, mLinePadding, mLineWidth, mpText, and STROKEBG_TRANSP.
: mCols(cols), mRows(rows) , mFontSize(fontSize), mpStroke(0) , mbBackground(bg), mbCentered(centered) { memset(mBgColor, 0, sizeof(mBgColor) ); mBgColor[3] = STROKEBG_TRANSP; memset(mFontColor, 0, sizeof(mFontColor) ); mpText = new PCHAR[rows]; mLineWidth = new int[rows]; mLinePadding = new double[rows]; for (int i=0; i<rows; i++) { mpText[i] = new char[cols+1]; } Clear(); }
Definition at line 47 of file TextDisplay.cpp.
References mLinePadding, mLineWidth, and mpText.
{
delete mpText;
delete mLineWidth;
delete mLinePadding;
}
| StrokeDisplay::StrokeDisplay | ( | int | numOfColumns, |
| int | numOfRows, | ||
| int | fontSize, | ||
| bool | drawBackground, | ||
| bool | isCentered | ||
| ) |
| void StrokeDisplay::Clear | ( | ) | [virtual] |
Clear all text.
Implements TextDisplay.
Definition at line 36 of file TextDisplay.cpp.
References mColsPos, mLinePadding, mLineWidth, mpText, mRows, and mRowsPos.
Referenced by StrokeDisplay().
{
for (int i=0; i <mRows; i++)
{
*mpText[i] = '\0';
}
mColsPos = mRowsPos = 0;
memset(mLinePadding, 0, sizeof(double) * mRows);
memset(mLineWidth, 0, sizeof(int) * mRows);
}
| void StrokeDisplay::Clear | ( | ) | [virtual] |
Clear all text.
Implements TextDisplay.
| bool StrokeDisplay::Display | ( | ) | [virtual] |
Display text (OPEN GL methods)
Implements TextDisplay.
Definition at line 113 of file TextDisplay.cpp.
References Stroke::DrawString(), Stroke::FontWidth(), Stroke::Init(), mbBackground, mbCentered, mBgColor, mCols, mColsPos, mFontColor, mFontSize, mLinePadding, mLineWidth, mpStroke, mpText, mRows, and mRowsPos.
{
// If there is no text, don't display anything
if (mColsPos == 0 && mRowsPos == 0)
{
return true;
}
// create stroke on first draw
if (!mpStroke)
{
mpStroke = new Stroke(mFontSize);
if (mLineWidth[mRowsPos] > 0 && mLineWidth[mRowsPos] < mCols)
mLinePadding[mRowsPos] = ( (mCols - mLineWidth[mRowsPos]) - 0.3) * mpStroke->FontWidth() / 2;
else
mLinePadding[mRowsPos] = 0.0;
if (!mpStroke->Init() )
{
delete mpStroke;
mpStroke = 0;
return false;
}
for (int i=0; i<mRows; i++)
{
if (mLineWidth[i] > 0 && mLineWidth[i] < mCols)
mLinePadding[i] = ( (mCols - mLineWidth[i]) - 0.3) * mpStroke->FontWidth() / 2;
else
mLinePadding[i] = 0.0;
}
}
// draw background
if (mbBackground)
{
double offset = 0.4;
glEnable (GL_BLEND);
glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glColor4f(0.2, 0.5, 0.65, mBgColor[3]);
glBegin(GL_POLYGON);
glVertex3f(0.0-2*offset, 0.0-2*offset, 0.0);
glVertex3f(mCols * mpStroke->FontWidth() + 5 * offset, 0.0 - 2*offset, 0.0);
glVertex3f( mCols * mpStroke->FontWidth() + 5 * offset, mRows * mFontSize * 1.5 - offset, 0.0);
glVertex3f(0.0 - 2*offset, mRows * mFontSize * 1.5 - offset, 0.0);
glEnd();
}
int rows = mRows;
int curr_row = (mRowsPos + 1) % mRows;
glColor3f(mFontColor[0], mFontColor[1], mFontColor[2]);
glDisable (GL_BLEND);
// draw stroke text
glTranslatef(0.0, (mRows - 1) * 1.5 * mFontSize, 0.0);
while (rows)
{
if (mpText[curr_row] != '\0')
{
glPushMatrix();
if (mbCentered)
{
glTranslatef(mLinePadding[curr_row], 0.0, 0.0);
}
mpStroke->DrawString(mpText[curr_row]);
glPopMatrix();
glTranslatef(0.0, -1.5 * mFontSize, 0.0);
}
curr_row = (curr_row + 1) % mRows;
rows--;
}
return true;
}
| bool StrokeDisplay::Display | ( | ) | [virtual] |
Display text (OPEN GL methods)
Implements TextDisplay.
| bool StrokeDisplay::Print | ( | const char * | msg | ) | [virtual] |
Add more text. '
' is accepted as well.
Implements TextDisplay.
Definition at line 54 of file TextDisplay.cpp.
References Stroke::FontWidth(), mCols, mColsPos, mLinePadding, mLineWidth, mpStroke, mpText, mRows, and mRowsPos.
Referenced by MenuDisplay::Add(), and CollisionMaster::Collision().
{
char* pom = (char*)msg;
while (*pom)
{
if (mColsPos == mCols || *pom == '\n')
{
mpText[mRowsPos][mColsPos] = '\0';
if (*pom == '\n')
{
pom++;
}
mColsPos = 0;
// Calcualte padding for mRowsPos Row
if (mpStroke)
{
if (mLineWidth[mRowsPos] > 0 && mLineWidth[mRowsPos] < mCols)
mLinePadding[mRowsPos] = ( (mCols - mLineWidth[mRowsPos]) - 0.3) * mpStroke->FontWidth() / 2;
else
mLinePadding[mRowsPos] = 0.0;
}
mRowsPos = (mRowsPos + 1) % mRows;
mLineWidth[mRowsPos] = 0;
}
else
{
mpText[mRowsPos][mColsPos] = toupper(*pom);
mColsPos++;
pom++;
mLineWidth[mRowsPos]++;
}
}
mpText[mRowsPos][mColsPos] = '\0';
// Calcualte padding for mRowsPos Row
if (mpStroke)
{
if (mLineWidth[mRowsPos] > 0 && mLineWidth[mRowsPos] < mCols)
mLinePadding[mRowsPos] = ( (mCols - mLineWidth[mRowsPos]) - 0.3) * mpStroke->FontWidth() / 2;
else
mLinePadding[mRowsPos] = 0.0;
}
return true;
}
| bool StrokeDisplay::Print | ( | const char * | msg | ) | [virtual] |
Add more text. '
' is accepted as well.
Implements TextDisplay.
| void StrokeDisplay::SetFocus | ( | bool | focus | ) |
We will draw non-focused elements with different ransparency level.
Definition at line 105 of file TextDisplay.cpp.
References mBgColor, STROKEBG_FOCUS, and STROKEBG_TRANSP.
{
if (focus)
mBgColor[3] = STROKEBG_FOCUS;
else
mBgColor[3] = STROKEBG_TRANSP;
}
| void StrokeDisplay::SetFocus | ( | bool | focus | ) |
int StrokeDisplay::mbBackground [protected] |
Definition at line 52 of file TextDisplay.h.
Referenced by Display().
int StrokeDisplay::mbCentered [protected] |
Definition at line 53 of file TextDisplay.h.
Referenced by Display().
double StrokeDisplay::mBgColor [protected] |
Definition at line 60 of file TextDisplay.h.
Referenced by Display(), SetFocus(), and StrokeDisplay().
int StrokeDisplay::mCols [protected] |
Definition at line 55 of file TextDisplay.h.
int StrokeDisplay::mColsPos [protected] |
Definition at line 57 of file TextDisplay.h.
double StrokeDisplay::mFontColor [protected] |
Definition at line 59 of file TextDisplay.h.
Referenced by Display(), and StrokeDisplay().
int StrokeDisplay::mFontSize [protected] |
Definition at line 54 of file TextDisplay.h.
Referenced by Display().
double * StrokeDisplay::mLinePadding [protected] |
Definition at line 64 of file TextDisplay.h.
Referenced by Clear(), Display(), Print(), StrokeDisplay(), and ~StrokeDisplay().
int * StrokeDisplay::mLineWidth [protected] |
Definition at line 65 of file TextDisplay.h.
Referenced by Clear(), Display(), Print(), StrokeDisplay(), and ~StrokeDisplay().
Stroke * StrokeDisplay::mpStroke [protected] |
Definition at line 67 of file TextDisplay.h.
char ** StrokeDisplay::mpText [protected] |
An array of lines (text)
Definition at line 63 of file TextDisplay.h.
Referenced by Clear(), Display(), Print(), StrokeDisplay(), and ~StrokeDisplay().
int StrokeDisplay::mRows [protected] |
Definition at line 56 of file TextDisplay.h.
int StrokeDisplay::mRowsPos [protected] |
Definition at line 58 of file TextDisplay.h.
1.8.0