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
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090
00091
00092
00093
00094
00095
00096
00097
00098
00099
00100 void
00101 GltTextOverlay::draw() const
00102 {
00103 if (_text.length()==0)
00104 return;
00105
00106
00107
00108 GltViewport window = _window;
00109 window.shrink(_spacing);
00110
00111
00112
00113
00114 int width;
00115 int height;
00116
00117 _font.size(width,height,_text);
00118
00119
00120
00121 GltViewport viewport = _window;
00122
00123
00124
00125 viewport.width() = width;
00126 viewport.height() = height;
00127
00128
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