• R/O
  • SSH
  • HTTPS

qrobosdk: コミット


コミットメタ情報

リビジョン1833 (tree)
日時2010-05-22 20:10:05
作者satofumi

ログメッセージ

add method

変更サマリ

差分

--- trunk/libs/gui/CanvasSurface.cpp (revision 1832)
+++ trunk/libs/gui/CanvasSurface.cpp (revision 1833)
@@ -13,6 +13,7 @@
1313 #include "CanvasSurface.h"
1414 #include "Font.h"
1515 //#include "Screen.h"
16+#include "TextSurface.h"
1617 #include <SDL_opengl.h>
1718 #include <vector>
1819 #include <cassert>
@@ -31,6 +32,9 @@
3132 GLfloat line_width;
3233 GLint stipple_factor;
3334 GLushort stipple_pattern;
35+
36+ Surface* surface;
37+ Point<long> position;
3438 } draw_t;
3539
3640 typedef vector<draw_t> Draws;
@@ -79,7 +83,11 @@
7983 void clearBuffers(void)
8084 {
8185 for (Draws::iterator it = draws_.begin(); it != draws_.end(); ++it) {
82- glDeleteBuffers(1, &it->buffer);
86+ if (it->surface) {
87+ delete it->surface;
88+ } else {
89+ glDeleteBuffers(1, &it->buffer);
90+ }
8391 }
8492 draws_.clear();
8593 }
@@ -118,8 +126,8 @@
118126 draw.stipple_pattern = line_stipple_pattern_;
119127 draw.buffer = createBuffer();
120128 draw.size = points.size();
129+ draw.surface = NULL;
121130
122-
123131 vector<GLfloat> intertwined;
124132 for (vector<Point<long> >::const_iterator it = points.begin();
125133 it != points.end(); ++it) {
@@ -139,6 +147,19 @@
139147 }
140148
141149
150+ bool registerSurface(draw_t& draw, const char* text,
151+ const Point<long>& position)
152+ {
153+ if (! font_) {
154+ return false;
155+ }
156+ draw.surface = new TextSurface(*font_, text);
157+ draw.position = position;
158+
159+ return true;
160+ }
161+
162+
142163 void drawPrimitive(const draw_t& draw)
143164 {
144165 glLineWidth(draw.line_width);
@@ -151,6 +172,16 @@
151172 }
152173
153174
175+ void drawSurface(Surface* surface, const Point<long>& position)
176+ {
177+ Rect<long> draw_rect = surface->rect();
178+ draw_rect.x = position.x;
179+ draw_rect.y = position.y;
180+
181+ surface->draw(NULL, &draw_rect);
182+ }
183+
184+
154185 void draw(const Rect<long>* src, const Rect<long>* dest)
155186 {
156187 glEnableClientState(GL_VERTEX_ARRAY);
@@ -178,7 +209,11 @@
178209
179210 for (Draws::const_iterator it = draws_.begin();
180211 it != draws_.end(); ++it) {
181- drawPrimitive(*it);
212+ if (it->surface) {
213+ drawSurface(it->surface, it->position);
214+ } else {
215+ drawPrimitive(*it);
216+ }
182217 }
183218
184219 glPopMatrix();
@@ -246,6 +281,12 @@
246281 }
247282
248283
284+Font* CanvasSurface::font(void) const
285+{
286+ return pimpl->font_;
287+}
288+
289+
249290 void CanvasSurface::setClearColor(const qrk::Color& color)
250291 {
251292 pimpl->setClearColor(color);
@@ -321,10 +362,12 @@
321362
322363 void CanvasSurface::drawText(const char* text, const Point<long>& position)
323364 {
324- (void)text;
325- (void)position;
326- // !!!
365+ if (strlen(text) == 0) {
366+ return;
367+ }
327368
328- // !!! text のサーフェスを作って描画させる
329- // !!! 描画する順番をどうやって保証するかは、未検討
369+ draw_t draw;
370+ if (pimpl->registerSurface(draw, text, position)) {
371+ pimpl->draws_.push_back(draw);
372+ }
330373 }
--- trunk/libs/gui/CanvasSurface.h (revision 1832)
+++ trunk/libs/gui/CanvasSurface.h (revision 1833)
@@ -37,6 +37,7 @@
3737 void draw(const Rect<long>* src, const Rect<long>* dest);
3838
3939 void setFont(qrk::Font& font);
40+ Font* font(void) const;
4041 void setClearColor(const qrk::Color& color);
4142 void clear(void);
4243 void setColor(const qrk::Color& color);
旧リポジトリブラウザで表示