Main Page   Modules   Class Hierarchy   Compound List   File List   Compound Members   File Members   Related Pages   Examples  

node/text.cpp

Go to the documentation of this file.
00001 #include "text.h"
00002 
00007 #include <node/fade.h>
00008 
00009 #include <glt/cursor.h>
00010 #include <glt/font.h>
00011 #include <glt/error.h>
00012 #include <glt/glu.h>
00013 #include <glt/rgb.h>
00014 
00015 #include <algorithm>
00016 using namespace std;
00017 
00018 GltTextOverlay::GltTextOverlay(const GltFont &font,const GltViewport &window)
00019 : 
00020   _font(font),
00021   _window(window),
00022   _textShadow(true),
00023   _textShadowColor(black),
00024   _textAlignHorizontal(GLT_ALIGN_LEFT),
00025   _textAlignVertical(GLT_ALIGN_TOP),
00026   _spacing(4), 
00027   _margin(4)
00028 {
00029     color() = white;
00030     _textFade.color() = black;
00031     _textFade.color().alpha() = 0.3;
00032 
00033     _textFade.border() = true;
00034     _textFade.borderColor() = black;
00035 }
00036 
00037 GltTextOverlay::GltTextOverlay(const GltTextOverlay &overlay)
00038 : 
00039   _font(overlay._font),
00040   _window(overlay._window), 
00041   _textShadow(overlay._textShadow),
00042   _textShadowColor(overlay._textShadowColor),
00043   _textAlignHorizontal(overlay._textAlignHorizontal),
00044   _textAlignVertical(overlay._textAlignVertical),
00045   _spacing(overlay._spacing),
00046   _margin(overlay._margin)
00047 {
00048 }
00049 
00050 GltTextOverlay::~GltTextOverlay()
00051 {
00052 }
00053 
00054 bool      &GltTextOverlay::shadow()      { return _textShadow;      }
00055 GltColor  &GltTextOverlay::shadowColor() { return _textShadowColor; }
00056 
00057 bool      &GltTextOverlay::border()       { return _textFade.border(); }
00058 GltColor  &GltTextOverlay::borderColor()  { return _textFade.borderColor(); }
00059 
00060 GltHorizontalAlignment &GltTextOverlay::alignHorizontal() { return _textAlignHorizontal; }
00061 GltVerticalAlignment   &GltTextOverlay::alignVertical()   { return _textAlignVertical;   }
00062 
00063 GltColor  &GltTextOverlay::fadeColor()  { return _textFade.color(); }
00064 
00065 int       &GltTextOverlay::spacing() { return _spacing; }
00066 int       &GltTextOverlay::margin()  { return _margin;  }
00067 
00068 /*
00069 void 
00070 GltTextOverlay::stringDimensions(const std::wstring &str,int &width,int &height)
00071 {
00072     height = 0;
00073     width = 0;
00074 
00075     // Get the first line of text
00076 
00077     int i = 0;
00078     int j = str.find('\n',i);
00079 
00080     // Process each line of text
00081 
00082     while (i!=string::npos)
00083     {
00084         height++;
00085 
00086         if (j==string::npos)
00087         {
00088             width = MAX(width,int(str.length()-i));
00089             break;
00090         }
00091         else
00092             width = MAX(width,j-i);
00093 
00094         i = j+1;
00095         j = str.find('\n',i);
00096     }
00097 }
00098 */
00099 
00100 void 
00101 GltTextOverlay::draw() const
00102 {
00103     if (_text.length()==0)
00104         return;
00105 
00106     // Window viewport
00107 
00108     GltViewport window = _window;
00109     window.shrink(_spacing);
00110 
00111 
00112     // Get text dimensions
00113 
00114     int width;
00115     int height;
00116 //  stringDimensions(_text,width,height);
00117     _font.size(width,height,_text);
00118 
00119     //
00120 
00121     GltViewport viewport = _window;
00122 
00123     // Make viewport big enough to fit text
00124 
00125     viewport.width()  = width;
00126     viewport.height() = height;
00127 
00128     // Include margin
00129 
00130     viewport.shrink(-_margin);
00131     viewport.align(_textAlignHorizontal,window);
00132     viewport.align(_textAlignVertical,window);
00133 
00134     GLERROR
00135 
00136     glPushAttrib(GL_ENABLE_BIT);
00137 
00138         glDisable(GL_LIGHTING);
00139         glDisable(GL_DEPTH_TEST);
00140 
00141         GLERROR
00142 
00143         glPushAttrib(GL_VIEWPORT_BIT);
00144             viewport.set();
00145             _textFade.draw();
00146         glPopAttrib();
00147 
00148         viewport.shrink(_margin);
00149 
00150         if (_textShadow)
00151         {
00152             viewport.x()++;
00153             viewport.y()--;
00154             _textShadowColor.glColor();
00155             GltCursor cursor(_font,viewport);
00156             cursor.print(_text);
00157             viewport.x()--;
00158             viewport.y()++;
00159         }
00160 
00161         GLERROR
00162 
00163         {
00164             glColor();
00165             GltCursor cursor(_font,viewport);
00166             cursor.print(_text);
00167         }
00168 
00169     glPopAttrib();
00170 }
00171 
00172       std::wstring &GltTextOverlay::text()       { return _text; }
00173 const std::wstring &GltTextOverlay::text() const { return _text; }
00174 
00175 

Generated on Tue Nov 5 11:11:05 2002 for GLT by doxygen1.2.18