Quad Pang
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
Public Member Functions | Protected Member Functions | Protected Attributes
Stroke Class Reference

Stroke can be used to draw letters and words. More...

#include <Stroke.h>

List of all members.

Public Member Functions

 Stroke (int fontSize)
 Stroke of specific font size.
virtual ~Stroke ()
bool Init ()
 Error prone initialization.
void DrawChar (char c)
void DrawString (const char *s)
void SetFontSize (int fsize)
int FontWidth () const
 Stroke (int fontSize)
 Stroke of specific font size.
virtual ~Stroke ()
bool Init ()
 Error prone initialization.
void DrawChar (char c)
void DrawString (const char *s)
void SetFontSize (int fsize)
int FontWidth () const

Protected Member Functions

void DrawLetter (CP *l)
 Draw charpoint array that represents the letter.
void DrawLetter (CP *l)
 Draw charpoint array that represents the letter.

Protected Attributes

int mFontSize
 Size of the font as speciried by constructor.
GLuint mBase
 ID of display list.
bool mbInitialized
 To ensure that object will be initialized only once.
double mProportion

Static Protected Attributes

Stroke cashe variables

Letters for each font size are loaded and compiled only once. and letter accessed trough class variables bellow

static const int FONT_SIZE_MAX = 5
static GLuint mFontBases [FONT_SIZE_MAX+1] = { 0, 0, 0, 0, 0, 0}

Detailed Description

Stroke can be used to draw letters and words.

Letters are drawn as polygons.

Definition at line 36 of file Stroke.h.


Constructor & Destructor Documentation

Stroke::Stroke ( int  fontSize)

Stroke of specific font size.

Definition at line 217 of file Stroke.cpp.

References SetFontSize().

    : mbInitialized(false) 
{
    SetFontSize(fsize);
}
virtual Stroke::~Stroke ( ) [inline, virtual]

Definition at line 41 of file Stroke.h.

{}
Stroke::Stroke ( int  fontSize)

Stroke of specific font size.

virtual Stroke::~Stroke ( ) [inline, virtual]

Definition at line 41 of file Stroke.h.

{}

Member Function Documentation

void Stroke::DrawChar ( char  c)

Definition at line 322 of file Stroke.cpp.

References mBase.

{
    glLineWidth(2.0);
    glCallList(mBase + c);
    glLineWidth(1.0);
}
void Stroke::DrawChar ( char  c)
void Stroke::DrawLetter ( CP l) [protected]

Draw charpoint array that represents the letter.

drawLetter() interprets the instructions from the array for that letter and renders the letter with line segments.

Definition at line 236 of file Stroke.cpp.

References END, mProportion, PT, STROKE, CharPoint::type, CharPoint::x, and CharPoint::y.

Referenced by Init().

{
   glBegin(GL_LINE_STRIP);
   while (1) {
      switch (l->type) {
         case PT:
            glVertex2f(l->x * mProportion, l->y * mProportion);
            break;
         case STROKE:
            glVertex2f(l->x * mProportion, l->y * mProportion);
            glEnd();
            glBegin(GL_LINE_STRIP);
            break;
         case END:
            glVertex2f(l->x * mProportion, l->y * mProportion);
            glEnd();
            glTranslatef(8.0 * mProportion, 0.0, 0.0);
            return;
      }
      l++;
   }
}
void Stroke::DrawLetter ( CP l) [protected]

Draw charpoint array that represents the letter.

void Stroke::DrawString ( const char *  s)

Definition at line 329 of file Stroke.cpp.

References mBase.

Referenced by StrokeDisplay::Display().

{
   GLsizei len = (GLsizei)strlen(s);
   glLineWidth(2.0);
   glListBase(mBase);
   glCallLists(len, GL_BYTE, (GLbyte *)s);
   glLineWidth(1.0);
}
void Stroke::DrawString ( const char *  s)
int Stroke::FontWidth ( ) const

Definition at line 229 of file Stroke.cpp.

References mProportion.

Referenced by StrokeDisplay::Display(), and StrokeDisplay::Print().

{ 
    return (int)(mProportion * 8); 
}
int Stroke::FontWidth ( ) const
bool Stroke::Init ( )

Error prone initialization.

bool Stroke::Init ( )

Error prone initialization.

Definition at line 259 of file Stroke.cpp.

References DrawLetter(), mBase, mbInitialized, mFontBases, mFontSize, and mProportion.

Referenced by StrokeDisplay::Display().

{
    if (mbInitialized)
        return true;

    if (mFontBases[mFontSize])
    {
        mBase = mFontBases[mFontSize];
    }
    else
    {
        mBase = glGenLists (128);
        if (mBase == 0) 
            return false;

        mFontBases[mFontSize] = mBase;
        glListBase(mBase);
        glNewList(mBase+'A', GL_COMPILE); DrawLetter(Adata); glEndList();
        glNewList(mBase+'B', GL_COMPILE); DrawLetter(Bdata); glEndList();      
        glNewList(mBase+'C', GL_COMPILE); DrawLetter(Cdata); glEndList();   
        glNewList(mBase+'D', GL_COMPILE); DrawLetter(Ddata); glEndList();    
        glNewList(mBase+'E', GL_COMPILE); DrawLetter(Edata); glEndList();
        glNewList(mBase+'F', GL_COMPILE); DrawLetter(Fdata); glEndList();
        glNewList(mBase+'G', GL_COMPILE); DrawLetter(Gdata); glEndList();
        glNewList(mBase+'H', GL_COMPILE); DrawLetter(Hdata); glEndList();
        glNewList(mBase+'I', GL_COMPILE); DrawLetter(Idata); glEndList();
        glNewList(mBase+'J', GL_COMPILE); DrawLetter(Jdata); glEndList();
        glNewList(mBase+'K', GL_COMPILE); DrawLetter(Kdata); glEndList();
        glNewList(mBase+'M', GL_COMPILE); DrawLetter(Mdata); glEndList();
        glNewList(mBase+'N', GL_COMPILE); DrawLetter(Ndata); glEndList();
        glNewList(mBase+'L', GL_COMPILE); DrawLetter(Ldata); glEndList();
        glNewList(mBase+'O', GL_COMPILE); DrawLetter(Odata); glEndList();    
        glNewList(mBase+'P', GL_COMPILE); DrawLetter(Pdata); glEndList();
        glNewList(mBase+'Q', GL_COMPILE); DrawLetter(Qdata); glEndList();    
        glNewList(mBase+'R', GL_COMPILE); DrawLetter(Rdata); glEndList();
        glNewList(mBase+'S', GL_COMPILE); DrawLetter(Sdata); glEndList();
        glNewList(mBase+'T', GL_COMPILE); DrawLetter(Tdata); glEndList();
        glNewList(mBase+'U', GL_COMPILE); DrawLetter(Udata); glEndList();
        glNewList(mBase+'V', GL_COMPILE); DrawLetter(Vdata); glEndList();
        glNewList(mBase+'W', GL_COMPILE); DrawLetter(Wdata); glEndList();
        glNewList(mBase+'X', GL_COMPILE); DrawLetter(Xdata); glEndList();
        glNewList(mBase+'Y', GL_COMPILE); DrawLetter(Ydata); glEndList();
        glNewList(mBase+'Z', GL_COMPILE); DrawLetter(Zdata); glEndList();
      
        glNewList(mBase+'.', GL_COMPILE); DrawLetter(DOTdata); glEndList();
        glNewList(mBase+':', GL_COMPILE); DrawLetter(DOT2data); glEndList();
        glNewList(mBase+' ', GL_COMPILE); glTranslatef(8.0 * mProportion, 0.0, 0.0); glEndList();
        glNewList(mBase+'0', GL_COMPILE); DrawLetter(N0data); glEndList();   
        glNewList(mBase+'1', GL_COMPILE); DrawLetter(N1data); glEndList();
        glNewList(mBase+'2', GL_COMPILE); DrawLetter(N2data); glEndList();
        glNewList(mBase+'3', GL_COMPILE); DrawLetter(N3data); glEndList();
        glNewList(mBase+'4', GL_COMPILE); DrawLetter(N4data); glEndList();      
        glNewList(mBase+'5', GL_COMPILE); DrawLetter(N5data); glEndList();
        glNewList(mBase+'6', GL_COMPILE); DrawLetter(N6data); glEndList();
        glNewList(mBase+'7', GL_COMPILE); DrawLetter(N7data); glEndList();  
        glNewList(mBase+'8', GL_COMPILE); DrawLetter(N8data); glEndList();
        glNewList(mBase+'9', GL_COMPILE); DrawLetter(N9data); glEndList();
        glNewList(mBase+'^', GL_COMPILE); DrawLetter(KAPAdata); glEndList();
    }

    return mbInitialized = true;
}
void Stroke::SetFontSize ( int  fsize)

Definition at line 223 of file Stroke.cpp.

References mFontSize, and mProportion.

Referenced by Stroke().

{ 
    mFontSize = fsize; 
    mProportion = (double)fsize / 10; 
}
void Stroke::SetFontSize ( int  fsize)

Member Data Documentation

static const int Stroke::FONT_SIZE_MAX = 5 [static, protected]

Definition at line 64 of file Stroke.h.

GLuint Stroke::mBase [protected]

ID of display list.

Definition at line 72 of file Stroke.h.

Referenced by DrawChar(), DrawString(), and Init().

bool Stroke::mbInitialized [protected]

To ensure that object will be initialized only once.

Definition at line 75 of file Stroke.h.

Referenced by Init().

static GLuint Stroke::mFontBases = { 0, 0, 0, 0, 0, 0} [static, protected]

Definition at line 65 of file Stroke.h.

Referenced by Init().

int Stroke::mFontSize [protected]

Size of the font as speciried by constructor.

Definition at line 69 of file Stroke.h.

Referenced by Init(), and SetFontSize().

double Stroke::mProportion [protected]

Definition at line 77 of file Stroke.h.

Referenced by DrawLetter(), FontWidth(), Init(), and SetFontSize().


The documentation for this class was generated from the following files: