Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035 #include "dialog-draw.h"
00036
00037 #include "common/wave_ex.h"
00038 #include "glut-font/glut-font.h"
00039 #include "perf/perf.h"
00040 #include "wave-glut/glut_2d.h"
00041 #include "wave-glut/wave-glut.h"
00042
00043
00044 namespace dialog {
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060 class OGLDrawer : public Drawer {
00061 public:
00062 ~OGLDrawer(void) throw() { }
00063
00064
00065 void initialize(IN ogl_dialog_draw_t& odd);
00066
00067
00068 font_size_t getFontSizing(IN eElementType type,
00069 IN const char * text);
00070 border_size_t getBorderSizing(IN eElementType type);
00071 void drawString(IN eElementType type,
00072 IN const point_t& pos,
00073 IN const char * text);
00074 void drawRectWithBorder(IN eElementType type,
00075 IN const rect_t& r);
00076 void drawCircle(IN const point_t& pos,
00077 IN float radius);
00078
00079 private:
00080
00081 glut::Font * getFont(IN eElementType type) { return m_font; }
00082
00083
00084 smart_ptr<glut::Font> m_font;
00085 };
00086
00087
00088
00089 void
00090 OGLDrawer::initialize
00091 (
00092 IN ogl_dialog_draw_t& odd
00093 )
00094 {
00095 ASSERT(odd.isValid(), "invalid OpenGL dialog drawer data");
00096
00097 ASSERT(odd.font, "null font");
00098 m_font = odd.font;
00099 }
00100
00101
00102
00103
00104
00105
00106
00107
00108
00109 font_size_t
00110 OGLDrawer::getFontSizing
00111 (
00112 IN eElementType type,
00113 IN const char * text
00114 )
00115 {
00116 ASSERT(text, "null");
00117
00118 font_size_t fs;
00119
00120 glut::font_rect_t fr = this->getFont(type)->getBoundingRect(text);
00121
00122 fs.lead = fr.lead;
00123 fs.trail = fr.trail;
00124 fs.rise = fr.rise;
00125 fs.drop = fr.drop;
00126
00127 return fs;
00128 }
00129
00130
00131
00132 border_size_t
00133 OGLDrawer::getBorderSizing
00134 (
00135 IN eElementType type
00136 )
00137 {
00138 border_size_t bs;
00139 bs.size = 4;
00140 return bs;
00141 }
00142
00143
00144
00145 void
00146 OGLDrawer::drawString
00147 (
00148 IN eElementType type,
00149 IN const point_t& pos,
00150 IN const char * text
00151 )
00152 {
00153 float z = 0;
00154 glut::Font * font = this->getFont(type);
00155 ASSERT(font, "null");
00156 glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
00157
00158
00159
00160
00161
00162
00163
00164
00165 glColor3f(1.0, 1.0, 1.0);
00166 font->display(pos.x, pos.y, z, text);
00167 }
00168
00169
00170
00171 void
00172 OGLDrawer::drawRectWithBorder
00173 (
00174 IN eElementType type,
00175 IN const rect_t& r
00176 )
00177 {
00178
00179
00180
00181
00182
00183
00184
00185
00186
00187 glEnable(GL_BLEND);
00188 glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
00189 glColor4f(0.0, 0.0, 0.0, 0.5);
00190 glRecti(r.left + 1, r.top + 1, r.right - 1, r.bottom - 1);
00191 glDisable(GL_BLEND);
00192
00193
00194
00195
00196
00197
00198
00199
00200 glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
00201 glColor3f(1.0, 1.0, 1.0);
00202 glRecti(r.left, r.top, r.right, r.bottom);
00203
00204
00205 }
00206
00207
00208
00209 void
00210 OGLDrawer::drawCircle
00211 (
00212 IN const point_t& pos,
00213 IN float radius
00214 )
00215 {
00216 ASSERT_THROW(radius >= 0, "Bad radius " << radius);
00217
00218 DPRINTF("Circle: %f", radius);
00219 }
00220
00221
00222
00223
00224
00225
00226
00227
00228
00229
00230
00231
00232
00233
00234
00235 smart_ptr<Drawer>
00236 createOpenGLDrawer
00237 (
00238 IN ogl_dialog_draw_t& odd
00239 )
00240 {
00241 ASSERT(odd.isValid(), "Invalid OpenGL drawer data");
00242
00243 smart_ptr<OGLDrawer> local = new OGLDrawer;
00244 ASSERT(local, "out of memory");
00245
00246 local->initialize(odd);
00247
00248 return local;
00249 }
00250
00251
00252
00253 };
00254