• Main Page
  • Namespaces
  • Classes
  • Files
  • File List

console.cpp

Go to the documentation of this file.
00001 #include "console.h"
00002 #include "application.h"
00003 #include <ogcsys.h>
00004 #include <stdio.h>
00005 #include <string.h>
00006 
00007 namespace wit {
00008 
00026 class ConsolePrivate {
00027 friend class Console;
00028 public:
00029     GXRModeObj* videoMode;
00030 };
00031 
00032 Console::Console(void* videoMode)
00033 {
00034     d = new ConsolePrivate; // for future expansion
00035     memset(d, 0, sizeof(ConsolePrivate));
00036     d->videoMode = reinterpret_cast<GXRModeObj*>(videoMode);
00037     setFramebuffer(Application::instance()->framebuffer());
00038 }
00039 
00045 Console::~Console()
00046 {
00047     delete d;
00048 }
00049 
00050 void Console::setFramebuffer(void* fb)
00051 {
00052     CON_Init(fb, 20, 20, d->videoMode->fbWidth, d->videoMode->xfbHeight, d->videoMode->fbWidth * VI_DISPLAY_PIX_SZ);
00053 }
00054 
00058 int Console::rows() const
00059 {
00060     if(!this)
00061         return 0;
00062     int r, c;
00063     CON_GetMetrics(&c, &r);
00064     return r;
00065 }
00066 
00070 int Console::columns() const
00071 {
00072     if(!this)
00073         return 0;
00074     int r, c;
00075     CON_GetMetrics(&c, &r);
00076     return c;
00077 }
00078 
00083 void Console::setCursorPosition(int x, int y)
00084 {
00085     if(!this)
00086         return;
00087     printf("\x1b[%d;%dH", y, x);
00088 }
00089 
00095 void Console::setCursorX(int x)
00096 {
00097     setCursorPosition(x, cursorY());
00098 }
00099 
00105 void Console::setCursorY(int y)
00106 {
00107     setCursorPosition(cursorX(), y);
00108 }
00109 
00113 int Console::cursorX() const
00114 {
00115     if(!this)
00116         return 0;
00117     int x, y;
00118     CON_GetPosition(&x, &y);
00119     return x;
00120 }
00121 
00125 int Console::cursorY() const
00126 {
00127     if(!this)
00128         return 0;
00129     int x, y;
00130     CON_GetPosition(&x, &y);
00131     return x;
00132 }
00133 
00139 void Console::enableGecko(int channel, bool safe)
00140 {
00141     if(!this)
00142         return;
00143     CON_EnableGecko(channel, safe ? 1 : 0);
00144 }
00145 
00149 void Console::disableGecko()
00150 {
00151     if(!this)
00152         return;
00153     CON_EnableGecko(-1, false);
00154 }
00155 
00159 void Console::write(const char* text)
00160 {
00161     if(Application::instance()->console() == 0)
00162         return;
00163     printf(text);
00164 }
00165 
00171 void Console::clear()
00172 {
00173     Console::write("\x1b[2J");
00174 }
00175 
00176 }

Generated on Sat Sep 3 2011 10:25:00 for wit by  doxygen 1.7.2