00001 #include "cursor.h"
00002
00015 #include <glt/font.h>
00016 #include <glt/viewport.h>
00017 #include <glt/error.h>
00018
00019 using namespace std;
00020
00021 GltCursor::GltCursor(const GltFont &font,const GltViewport &area)
00022 : _font(font), _area(area)
00023 {
00024 GLERROR
00025
00026 glMatrixMode(GL_PROJECTION);
00027 glPushMatrix();
00028 glMatrixMode(GL_MODELVIEW);
00029 glPushMatrix();
00030 glPushAttrib(GL_VIEWPORT_BIT);
00031
00032 GLERROR
00033
00034 _area.set();
00035
00036 glMatrixMode(GL_PROJECTION);
00037 glLoadIdentity();
00038 glOrtho(0.0,GLdouble(area.width()),GLdouble(area.height()-1),-1.0,-1.0,1.0);
00039
00040 GLERROR
00041
00042 glMatrixMode(GL_MODELVIEW);
00043 glLoadIdentity();
00044
00045 GLERROR
00046
00047
00048 glRasterPos2i(0,0);
00049
00050 GLERROR
00051 }
00052
00053 GltCursor::~GltCursor()
00054 {
00055 GLERROR
00056
00057 glPopAttrib();
00058 glPopMatrix();
00059 glMatrixMode(GL_PROJECTION);
00060 glPopMatrix();
00061 glMatrixMode(GL_MODELVIEW);
00062
00063 GLERROR
00064 }
00065
00066 void
00067 GltCursor::print(const string &str)
00068 {
00069 wstring s;
00070 string2wstring(s,str);
00071 print(s);
00072 }
00073
00074 void
00075 GltCursor::print(const wstring &str)
00076 {
00077 wstring s;
00078 dos2unix(s,str);
00079
00080 wstring::size_type i=0;
00081 wstring::size_type j=0;
00082
00083 do
00084 {
00085 j = s.find('\n',i);
00086 if (j==wstring::npos)
00087 {
00088 printLine(s.substr(i));
00089 return;
00090 }
00091
00092 printLine(s.substr(i,j-i));
00093 i = j+1;
00094
00095 } while (j!=wstring::npos);
00096 }
00097
00098 void
00099 GltCursor::printLine(const wstring &str)
00100 {
00101 GLERROR
00102
00103
00104
00105
00106
00107
00108 _font.print(str);
00109
00110
00111
00112
00113
00114
00115
00116 GLERROR
00117 }
00118