Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members

Console Class Reference

#include <console.h>

Collaboration diagram for Console:

Collaboration graph
List of all members.

Public Member Functions

void begin ()
 Console (int _nRows, int _nColumns)
void end ()
int getColumn () const
int getHeight () const
int getRow () const
int getWidth () const
int getWindowRow () const
void newline ()
void print (char *)
void print (wchar_t)
void render (int rowHeight)
void setFont (TextureFont *)
void setScale (int, int)
void setWindowHeight (int)
void setWindowRow (int)
 ~Console ()

Private Attributes

bool autoScroll
int column
TextureFontfont
int nColumns
int nRows
int row
ConsoleStreamBuf sbuf
wchar_t * text
int windowHeight
int windowRow
int xscale
int yscale

Constructor & Destructor Documentation

Console::Console int  _nRows,
int  _nColumns
 

Definition at line 27 of file console.cpp.

References nColumns, nRows, sbuf, ConsoleStreamBuf::setConsole(), and text.

00027                                           :
00028     ostream(&sbuf),
00029     text(NULL),
00030     nRows(_nRows),
00031     nColumns(_nColumns),
00032     row(0),
00033     column(0),
00034     windowRow(0),
00035     windowHeight(10),
00036     xscale(1),
00037     yscale(1),
00038     font(NULL),
00039     autoScroll(true)
00040 {
00041     sbuf.setConsole(this);
00042     text = new wchar_t[(nColumns + 1) * nRows];
00043     for (int i = 0; i < nRows; i++)
00044         text[(nColumns + 1) * i] = '\0';
00045 }

Console::~Console  ) 
 

Definition at line 48 of file console.cpp.

References text.

00049 {
00050     if (text != NULL)
00051         delete[] text;
00052 }


Member Function Documentation

void Console::begin  ) 
 

Definition at line 55 of file console.cpp.

References xscale, and yscale.

Referenced by CelestiaCore::draw().

00056 {
00057     glMatrixMode(GL_PROJECTION);
00058     glPushMatrix();
00059     glLoadIdentity();
00060     gluOrtho2D(0, xscale, 0, yscale);
00061     glMatrixMode(GL_MODELVIEW);
00062     glPushMatrix();
00063     glLoadIdentity();
00064     glTranslatef(0.125f, 0.125f, 0);
00065 
00066     glDisable(GL_LIGHTING);
00067     glDisable(GL_TEXTURE_2D);
00068     glEnable(GL_BLEND);
00069     glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
00070 }

void Console::end  ) 
 

Definition at line 73 of file console.cpp.

Referenced by CelestiaCore::draw().

00074 {
00075     glMatrixMode(GL_PROJECTION);
00076     glPopMatrix();
00077     glMatrixMode(GL_MODELVIEW);
00078     glPopMatrix();
00079 }

int Console::getColumn  )  const
 

Definition at line 194 of file console.cpp.

References column.

00195 {
00196     return column;
00197 }

int Console::getHeight  )  const
 

Definition at line 224 of file console.cpp.

References nRows.

00225 {
00226     return nRows;
00227 }

int Console::getRow  )  const
 

Definition at line 188 of file console.cpp.

References row.

00189 {
00190     return row;
00191 }

int Console::getWidth  )  const
 

Definition at line 218 of file console.cpp.

References nColumns.

00219 {
00220     return nColumns;
00221 }

int Console::getWindowRow  )  const
 

Definition at line 200 of file console.cpp.

References windowRow.

00201 {
00202     return windowRow;
00203 }

void Console::newline  ) 
 

Definition at line 127 of file console.cpp.

References autoScroll, column, nColumns, nRows, row, text, windowHeight, and windowRow.

Referenced by print().

00128 {
00129     assert(column <= nColumns);
00130     assert(row < nRows);
00131 
00132     text[row * (nColumns + 1) + column] = '\0';
00133     row = (row + 1) % nRows;
00134     column = 0;
00135 
00136     if (autoScroll)
00137         windowRow = -windowHeight;
00138 }

void Console::print char *   ) 
 

Definition at line 157 of file console.cpp.

References print(), UTF8Decode(), and UTF8EncodedSize().

00158 {
00159     int length = strlen(s);
00160     bool validChar = true;
00161     int i = 0;
00162 
00163     while (i < length && validChar)
00164     {
00165         wchar_t ch = 0;
00166         validChar = UTF8Decode(s, i, length, ch);
00167         i += UTF8EncodedSize(ch);
00168         print(ch);
00169     }
00170 }

void Console::print wchar_t   ) 
 

Definition at line 140 of file console.cpp.

References column, nColumns, newline(), row, and text.

Referenced by ConsoleStreamBuf::overflow(), and print().

00141 {
00142     switch (c)
00143     {
00144     case '\n':
00145         newline();
00146         break;
00147     default:
00148         if (column == nColumns)
00149             newline();
00150         text[row * (nColumns + 1) + column] = c;
00151         column++;
00152         break;
00153     }
00154 }

void Console::render int  rowHeight  ) 
 

Definition at line 82 of file console.cpp.

References TextureFont::bind(), font, TextureFont::getHeight(), nColumns, nRows, pmod(), TextureFont::render(), row, text, and windowRow.

Referenced by CelestiaCore::draw().

00083 {
00084     if (font == NULL)
00085         return;
00086 
00087     glEnable(GL_TEXTURE_2D);
00088     font->bind();
00089     glPushMatrix();
00090     for (int i = 0; i < rowHeight; i++)
00091     {
00092         //int r = (nRows - rowHeight + 1 + windowRow + i) % nRows;
00093         int r = pmod(row + windowRow + i, nRows);
00094         for (int j = 0; j < nColumns; j++)
00095         {
00096             wchar_t ch = text[r * (nColumns + 1) + j];
00097             if (ch == '\0')
00098                 break;
00099             font->render(ch);
00100         }
00101 
00102         // advance to the next line
00103         glPopMatrix();
00104         glTranslatef(0.0f, -(1.0f + font->getHeight()), 0.0f);
00105         glPushMatrix();
00106     }
00107     glPopMatrix();
00108 }

void Console::setFont TextureFont  ) 
 

Definition at line 118 of file console.cpp.

References font.

Referenced by CelestiaCore::draw().

00119 {
00120     if (f != font)
00121     {
00122         font = f;
00123     }
00124 }

void Console::setScale int  ,
int 
 

Definition at line 111 of file console.cpp.

References xscale, and yscale.

Referenced by CelestiaCore::resize().

00112 {
00113     xscale = w;
00114     yscale = h;
00115 }

void Console::setWindowHeight int   ) 
 

Definition at line 212 of file console.cpp.

References windowHeight.

Referenced by CelestiaCore::CelestiaCore().

00213 {
00214     windowHeight = _height;
00215 }

void Console::setWindowRow int   ) 
 

Definition at line 206 of file console.cpp.

References windowRow.

Referenced by scrollConsole().

00207 {
00208     windowRow = _row;
00209 }


Member Data Documentation

bool Console::autoScroll [private]
 

Definition at line 90 of file console.h.

Referenced by newline().

int Console::column [private]
 

Definition at line 78 of file console.h.

Referenced by getColumn(), newline(), and print().

TextureFont* Console::font [private]
 

Definition at line 86 of file console.h.

Referenced by render(), and setFont().

int Console::nColumns [private]
 

Definition at line 76 of file console.h.

Referenced by Console(), getWidth(), newline(), print(), and render().

int Console::nRows [private]
 

Definition at line 75 of file console.h.

Referenced by Console(), getHeight(), newline(), and render().

int Console::row [private]
 

Definition at line 77 of file console.h.

Referenced by getRow(), newline(), print(), and render().

ConsoleStreamBuf Console::sbuf [private]
 

Definition at line 88 of file console.h.

Referenced by Console().

wchar_t* Console::text [private]
 

Definition at line 74 of file console.h.

Referenced by Console(), newline(), print(), render(), and ~Console().

int Console::windowHeight [private]
 

Definition at line 82 of file console.h.

Referenced by newline(), and setWindowHeight().

int Console::windowRow [private]
 

Definition at line 80 of file console.h.

Referenced by getWindowRow(), newline(), render(), and setWindowRow().

int Console::xscale [private]
 

Definition at line 84 of file console.h.

Referenced by begin(), and setScale().

int Console::yscale [private]
 

Definition at line 85 of file console.h.

Referenced by begin(), and setScale().


The documentation for this class was generated from the following files:
Generated on Sat Jan 14 22:33:16 2006 for Celestia by  doxygen 1.4.1