• R/O
  • SSH
  • HTTPS

qrobosdk: コミット


コミットメタ情報

リビジョン1830 (tree)
日時2010-05-20 18:22:27
作者satofumi

ログメッセージ

rename CanvasSurface.h

変更サマリ

差分

--- trunk/widgets/UrgDrawWidget/UrgDrawWidget.cpp (revision 1829)
+++ trunk/widgets/UrgDrawWidget/UrgDrawWidget.cpp (revision 1830)
@@ -30,368 +30,371 @@
3030
3131 namespace
3232 {
33- const double DefaultPixelPerMm = 20.0;
33+ const double DefaultPixelPerMm = 20.0;
3434
3535
36- struct DrawData
37- {
38- vector<Point<long> > point_data;
39- long timestamp;
40- Color line_color;
36+ struct DrawData
37+ {
38+ vector<Point<long> > point_data;
39+ long timestamp;
40+ Color line_color;
4141
4242
43- DrawData(vector<Point<long> >& point_data_,
44- long timestamp_, const Color& line_color_)
45- : timestamp(timestamp_), line_color(line_color_)
46- {
47- swap(point_data, point_data_);
48- }
49- };
43+ DrawData(vector<Point<long> >& point_data_,
44+ long timestamp_, const Color& line_color_)
45+ : timestamp(timestamp_), line_color(line_color_)
46+ {
47+ swap(point_data, point_data_);
48+ }
49+ };
5050 }
5151
5252
5353 struct UrgDrawWidget::pImpl
5454 {
55- enum {
56- MinimumWidth = 100,
57- MinimumHeight = 100,
55+ enum {
56+ MinimumWidth = 100,
57+ MinimumHeight = 100,
5858
59- PointLength = 30 * 1000, // [mm]
60- };
59+ PointLength = 30 * 1000, // [mm]
60+ };
6161
62- UrgDrawWidget* widget_;
62+ UrgDrawWidget* widget_;
6363
64- Point<double> view_center_;
65- double pixel_per_mm_;
66- DrawMode draw_mode_;
67- long draw_period_;
68- long last_redraw_;
69- long last_timestamp_;
64+ Point<double> view_center_;
65+ double pixel_per_mm_;
66+ DrawMode draw_mode_;
67+ long draw_period_;
68+ long last_redraw_;
69+ long last_timestamp_;
7070
71- typedef deque<DrawData> DataArray;
72- DataArray draw_data_;
73- size_t width_;
74- size_t height_;
71+ typedef deque<DrawData> DataArray;
72+ DataArray draw_data_;
73+ size_t width_;
74+ size_t height_;
7575
76- QColor clear_color_;
77- Position<long> rotate_offset_;
78- QPoint clicked_position_;
79- bool now_pressed_;
76+ QColor clear_color_;
77+ Position<long> rotate_offset_;
78+ QPoint clicked_position_;
79+ bool now_pressed_;
8080
81- Color line_color_;
81+ Color line_color_;
8282
8383
84- pImpl(UrgDrawWidget* widget)
85- : widget_(widget),
86- pixel_per_mm_(DefaultPixelPerMm), draw_mode_(Lines), draw_period_(100),
87- last_redraw_(0), last_timestamp_(0), width_(MinimumWidth),
88- height_(MinimumHeight), clear_color_(Qt::white),
89- rotate_offset_(Position<long>(0, 0, deg(90))), now_pressed_(false),
90- line_color_(0.2f, 0.2f, 1.0f, 0.6f)
91- {
92- }
84+ pImpl(UrgDrawWidget* widget)
85+ : widget_(widget),
86+ pixel_per_mm_(DefaultPixelPerMm), draw_mode_(Lines),
87+ draw_period_(100), last_redraw_(0), last_timestamp_(0),
88+ width_(MinimumWidth), height_(MinimumHeight), clear_color_(Qt::white),
89+ rotate_offset_(Position<long>(0, 0, deg(90))), now_pressed_(false),
90+ line_color_(0.2f, 0.2f, 1.0f, 0.6f)
91+ {
92+ }
9393
9494
95- void initializeForm(void)
96- {
97- widget_->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
98- widget_->setMinimumSize(MinimumWidth, MinimumHeight);
95+ void initializeForm(void)
96+ {
97+ widget_->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
98+ widget_->setMinimumSize(MinimumWidth, MinimumHeight);
9999
100- widget_->setMouseTracking(true);
101- }
100+ widget_->setMouseTracking(true);
101+ }
102102
103103
104- void removeOldData(long timestamp)
105- {
106- if (draw_data_.empty()) {
107- return;
108- }
104+ void removeOldData(long timestamp)
105+ {
106+ if (draw_data_.empty()) {
107+ return;
108+ }
109109
110- // タイムスタンプが異常な場合、全てのデータをクリアする
111- if (draw_data_.back().timestamp > timestamp) {
112- draw_data_.clear();
113- return;
114- }
110+ // タイムスタンプが異常な場合、全てのデータをクリアする
111+ if (draw_data_.back().timestamp > timestamp) {
112+ draw_data_.clear();
113+ return;
114+ }
115115
116- int index = 0;
117- for (DataArray::iterator it = draw_data_.begin();
118- it != draw_data_.end(); ++it, ++index) {
119- long difference = timestamp - it->timestamp;
120- if (difference < draw_period_) {
121- break;
122- }
123- }
116+ int index = 0;
117+ for (DataArray::iterator it = draw_data_.begin();
118+ it != draw_data_.end(); ++it, ++index) {
119+ long difference = timestamp - it->timestamp;
120+ if (difference < draw_period_) {
121+ break;
122+ }
123+ }
124124
125- if (index > 0) {
126- DataArray::iterator it = draw_data_.begin();
127- draw_data_.erase(it, it + index);
125+ if (index > 0) {
126+ DataArray::iterator it = draw_data_.begin();
127+ draw_data_.erase(it, it + index);
128+ }
128129 }
129- }
130130
131131
132- void initializeGL(void)
133- {
134- widget_->qglClearColor(clear_color_);
135- glEnable(GL_CULL_FACE);
136- glEnable(GL_TEXTURE_2D);
137- glEnable(GL_BLEND);
138- glDisable(GL_DEPTH_TEST);
132+ void initializeGL(void)
133+ {
134+ widget_->qglClearColor(clear_color_);
135+ glEnable(GL_CULL_FACE);
136+ glEnable(GL_TEXTURE_2D);
137+ glEnable(GL_BLEND);
138+ glDisable(GL_DEPTH_TEST);
139139
140- glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
141- }
140+ glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
141+ }
142142
143143
144- void resizeGL(int width, int height)
145- {
146- glViewport(0, 0, width, height);
144+ void resizeGL(int width, int height)
145+ {
146+ glViewport(0, 0, width, height);
147147
148- glMatrixMode(GL_PROJECTION);
149- glLoadIdentity();
148+ glMatrixMode(GL_PROJECTION);
149+ glLoadIdentity();
150150
151- double aspect = 1.0 * width / height;
152- glOrtho(-1.0 * aspect, +1.0 * aspect, -1.0, +1.0,
153- numeric_limits<int>::min(), numeric_limits<int>::max());
151+ double aspect = 1.0 * width / height;
152+ glOrtho(-1.0 * aspect, +1.0 * aspect, -1.0, +1.0,
153+ numeric_limits<int>::min(), numeric_limits<int>::max());
154154
155- glMatrixMode(GL_MODELVIEW);
156- width_ = width;
157- height_ = height;
158- }
155+ glMatrixMode(GL_MODELVIEW);
156+ width_ = width;
157+ height_ = height;
158+ }
159159
160160
161- void paintGL(void)
162- {
163- widget_->qglClearColor(clear_color_);
164- glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
165- glLoadIdentity();
161+ void paintGL(void)
162+ {
163+ widget_->qglClearColor(clear_color_);
164+ glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
165+ glLoadIdentity();
166166
167- // 軸の描画
168- drawAxis();
167+ // 軸の描画
168+ drawAxis();
169169
170- // データの描画
171- drawData();
172- }
170+ // データの描画
171+ drawData();
172+ }
173173
174174
175- void drawAxis(void)
176- {
177- double zoom_ratio = zoomRatio();
178- Point<double> offset = drawOffset(zoom_ratio);
175+ void drawAxis(void)
176+ {
177+ double zoom_ratio = zoomRatio();
178+ Point<double> offset = drawOffset(zoom_ratio);
179179
180- // 補助線の描画
181- drawSubAxis(offset);
180+ // 補助線の描画
181+ drawSubAxis(offset);
182182
183- glColor3d(0.3, 0.3, 0.3);
184- glBegin(GL_LINES);
183+ glColor3d(0.3, 0.3, 0.3);
184+ glBegin(GL_LINES);
185185
186- // Y 軸
187- glVertex2d(-offset.x, -1.0);
188- glVertex2d(-offset.x, +1.0);
186+ // Y 軸
187+ glVertex2d(-offset.x, -1.0);
188+ glVertex2d(-offset.x, +1.0);
189189
190- // X 軸
191- double aspect = 1.0 * width_ / height_;
192- glVertex2d(-aspect, -offset.y);
193- glVertex2d(+aspect, -offset.y);
190+ // X 軸
191+ double aspect = 1.0 * width_ / height_;
192+ glVertex2d(-aspect, -offset.y);
193+ glVertex2d(+aspect, -offset.y);
194194
195- // 背後 45 [deg] の補助線
196- glVertex2d(-offset.x, -offset.y);
197- glVertex2d((-PointLength * zoom_ratio) - offset.x,
198- (-PointLength * zoom_ratio) - offset.y);
199- glVertex2d(-offset.x, -offset.y);
200- glVertex2d((+PointLength * zoom_ratio) - offset.x,
201- (-PointLength * zoom_ratio) - offset.y);
202- glEnd();
195+ // 背後 45 [deg] の補助線
196+ glVertex2d(-offset.x, -offset.y);
197+ glVertex2d((-PointLength * zoom_ratio) - offset.x,
198+ (-PointLength * zoom_ratio) - offset.y);
199+ glVertex2d(-offset.x, -offset.y);
200+ glVertex2d((+PointLength * zoom_ratio) - offset.x,
201+ (-PointLength * zoom_ratio) - offset.y);
202+ glEnd();
203203
204- // 円の補助線を描画
205- for (int i = 0; i <= PointLength; i += 1000) {
206- drawSubCircle(i, offset);
204+ // 円の補助線を描画
205+ for (int i = 0; i <= PointLength; i += 1000) {
206+ drawSubCircle(i, offset);
207+ }
208+
209+ // 単位の表示
210+ // !!!
207211 }
208212
209- // 単位の表示
210- // !!!
211- }
212213
214+ void drawSubCircle(int radius, const Point<double>& offset)
215+ {
216+ double pixel_radius = (radius / pixel_per_mm_) / (height_ / 2.0);
213217
214- void drawSubCircle(int radius, const Point<double>& offset)
215- {
216- double pixel_radius = (radius / pixel_per_mm_) / (height_ / 2.0);
218+ glBegin(GL_LINE_STRIP);
219+ for (int theta = -45; theta <= (180 + 45); theta += 2) {
217220
218- glBegin(GL_LINE_STRIP);
219- for (int theta = -45; theta <= (180 + 45); theta += 2) {
220-
221- double radian = M_PI * theta / 180.0;
222- double x = pixel_radius * cos(radian);
223- double y = pixel_radius * sin(radian);
224- glVertex2d(x - offset.x, y - offset.y);
221+ double radian = M_PI * theta / 180.0;
222+ double x = pixel_radius * cos(radian);
223+ double y = pixel_radius * sin(radian);
224+ glVertex2d(x - offset.x, y - offset.y);
225+ }
226+ glEnd();
225227 }
226- glEnd();
227- }
228228
229229
230- void drawSubAxis(const Point<double>& offset)
231- {
232- Point<int> center(width_ / 2, height_ / 2);
233- Point<long> first(static_cast<int>((-center.x * pixel_per_mm_)
234- - view_center_.x),
235- static_cast<int>((-center.y * pixel_per_mm_)
236- - view_center_.y));
237- Point<long> last(static_cast<int>((+center.x * pixel_per_mm_)
238- - view_center_.x),
239- static_cast<int>((+center.y * pixel_per_mm_)
240- - view_center_.y));
230+ void drawSubAxis(const Point<double>& offset)
231+ {
232+ Point<int> center(width_ / 2, height_ / 2);
233+ Point<long> first(static_cast<int>((-center.x * pixel_per_mm_)
234+ - view_center_.x),
235+ static_cast<int>((-center.y * pixel_per_mm_)
236+ - view_center_.y));
237+ Point<long> last(static_cast<int>((+center.x * pixel_per_mm_)
238+ - view_center_.x),
239+ static_cast<int>((+center.y * pixel_per_mm_)
240+ - view_center_.y));
241241
242- const double threshold[] = { 4.0, 16.0, 32.0 };
243- const int interval[] = { 10, 100, 1000 };
244- const double color[] = { 0.8, 0.6, 0.3 };
245- size_t n = sizeof(threshold) / sizeof(threshold[0]);
246- for (size_t i = 0; i < n; ++i) {
247- const double draw_threshold = threshold[i];
248- if (pixel_per_mm_ > draw_threshold) {
249- continue;
250- }
251- double alpha = 1.0 - (pixel_per_mm_ / draw_threshold);
252- glColor4d(color[i], color[i], color[i], alpha);
253- drawSubPointLine(interval[i], offset, first, last);
242+ const double threshold[] = { 4.0, 16.0, 32.0 };
243+ const int interval[] = { 10, 100, 1000 };
244+ const double color[] = { 0.8, 0.6, 0.3 };
245+ size_t n = sizeof(threshold) / sizeof(threshold[0]);
246+ for (size_t i = 0; i < n; ++i) {
247+ const double draw_threshold = threshold[i];
248+ if (pixel_per_mm_ > draw_threshold) {
249+ continue;
250+ }
251+ double alpha = 1.0 - (pixel_per_mm_ / draw_threshold);
252+ glColor4d(color[i], color[i], color[i], alpha);
253+ drawSubPointLine(interval[i], offset, first, last);
254+ }
254255 }
255- }
256256
257257
258- void drawSubPointLine(int interval, const Point<double>& offset,
259- const Point<long>& first, const Point<long>& last)
260- {
261- glBegin(GL_LINES);
262- for (int x = (first.x / interval) - 1; x < ((last.x / interval) + 1); ++x) {
263- double draw_x = (interval * x / pixel_per_mm_) / (height_ / 2.0);
264- glVertex2d(draw_x - offset.x, -1.0);
265- glVertex2d(draw_x - offset.x, +1.0);
266- }
258+ void drawSubPointLine(int interval, const Point<double>& offset,
259+ const Point<long>& first, const Point<long>& last)
260+ {
261+ glBegin(GL_LINES);
262+ for (int x = (first.x / interval) - 1;
263+ x < ((last.x / interval) + 1); ++x) {
264+ double draw_x = (interval * x / pixel_per_mm_) / (height_ / 2.0);
265+ glVertex2d(draw_x - offset.x, -1.0);
266+ glVertex2d(draw_x - offset.x, +1.0);
267+ }
267268
268- double aspect = 1.0 * width_ / height_;
269- for (int y = (first.y / interval) - 1; y < ((last.y / interval) + 1); ++y) {
270- double draw_y = (interval * y / pixel_per_mm_) / (height_ / 2.0);
271- glVertex2d(-aspect, draw_y - offset.y);
272- glVertex2d(+aspect, draw_y - offset.y);
269+ double aspect = 1.0 * width_ / height_;
270+ for (int y = (first.y / interval) - 1;
271+ y < ((last.y / interval) + 1); ++y) {
272+ double draw_y = (interval * y / pixel_per_mm_) / (height_ / 2.0);
273+ glVertex2d(-aspect, draw_y - offset.y);
274+ glVertex2d(+aspect, draw_y - offset.y);
275+ }
276+ glEnd();
273277 }
274- glEnd();
275- }
276278
277279
278- void drawData(void)
279- {
280- // !!! 時間が経過するほど、薄い色で表示するようにする
280+ void drawData(void)
281+ {
282+ // !!! 時間が経過するほど、薄い色で表示するようにする
281283
282- double zoom_ratio = zoomRatio();
283- Point<double> offset = drawOffset(zoom_ratio);
284+ double zoom_ratio = zoomRatio();
285+ Point<double> offset = drawOffset(zoom_ratio);
284286
285- if (draw_mode_ == Lines) {
286- // 中心から測定点への直線を描画
287- glBegin(GL_LINES);
288- for (DataArray::iterator line_it = draw_data_.begin();
289- line_it != draw_data_.end(); ++line_it) {
287+ if (draw_mode_ == Lines) {
288+ // 中心から測定点への直線を描画
289+ glBegin(GL_LINES);
290+ for (DataArray::iterator line_it = draw_data_.begin();
291+ line_it != draw_data_.end(); ++line_it) {
290292
291- Color& line_color = line_it->line_color;
292- double diff = last_timestamp_ - line_it->timestamp;
293- double alpha = 1.0 - (diff / draw_period_);
294- glColor4d(line_color.r, line_color.g, line_color.b, alpha);
293+ Color& line_color = line_it->line_color;
294+ double diff = last_timestamp_ - line_it->timestamp;
295+ double alpha = 1.0 - (diff / draw_period_);
296+ glColor4d(line_color.r, line_color.g, line_color.b, alpha);
295297
296- vector<Point<long> >& line_data = line_it->point_data;;
297- vector<Point<long> >::iterator end_it = line_data.end();
298- for (vector<Point<long> >::iterator it = line_data.begin();
299- it != end_it; ++it) {
298+ vector<Point<long> >& line_data = line_it->point_data;;
299+ vector<Point<long> >::iterator end_it = line_data.end();
300+ for (vector<Point<long> >::iterator it = line_data.begin();
301+ it != end_it; ++it) {
300302
301- double x = it->x * zoom_ratio;
302- double y = it->y * zoom_ratio;
303- glVertex2d(-offset.x, -offset.y);
304- glVertex2d(x - offset.x, y - offset.y);
303+ double x = it->x * zoom_ratio;
304+ double y = it->y * zoom_ratio;
305+ glVertex2d(-offset.x, -offset.y);
306+ glVertex2d(x - offset.x, y - offset.y);
307+ }
308+ }
309+ glEnd();
310+
311+ } else if (draw_mode_ == Polygon) {
312+ // !!! これを実現するには、convert2d 時に捨ててしまった情報が必要
313+ // !!! 実装方法を見直すべき
305314 }
306- }
307- glEnd();
308315
309- } else if (draw_mode_ == Polygon) {
310- // !!! これを実現するには、convert2d 時に捨ててしまった情報が必要
311- // !!! 実装方法を見直すべき
312- }
316+ // 測定点の描画
317+ double base_size = 1.4;
318+ double mm_pixel = max(base_size / pixel_per_mm_, base_size);
319+ glPointSize(mm_pixel);
313320
314- // 測定点の描画
315- double base_size = 1.4;
316- double mm_pixel = max(base_size / pixel_per_mm_, base_size);
317- glPointSize(mm_pixel);
321+ glBegin(GL_POINTS);
322+ for (DataArray::iterator line_it = draw_data_.begin();
323+ line_it != draw_data_.end(); ++line_it) {
318324
319- glBegin(GL_POINTS);
320- for (DataArray::iterator line_it = draw_data_.begin();
321- line_it != draw_data_.end(); ++line_it) {
325+ // !!! 関数にする
326+ double diff = last_timestamp_ - line_it->timestamp;
327+ double alpha = 1.0 - (diff / draw_period_);
328+ glColor4d(1.0, 0.0, 0.0, alpha);
322329
323- // !!! 関数にする
324- double diff = last_timestamp_ - line_it->timestamp;
325- double alpha = 1.0 - (diff / draw_period_);
326- glColor4d(1.0, 0.0, 0.0, alpha);
330+ vector<Point<long> >::iterator end_it = line_it->point_data.end();
331+ for (vector<Point<long> >::iterator it =
332+ line_it->point_data.begin();
333+ it != end_it; ++it) {
327334
328- vector<Point<long> >::iterator end_it = line_it->point_data.end();
329- for (vector<Point<long> >::iterator it = line_it->point_data.begin();
330- it != end_it; ++it) {
331-
332- double x = it->x * zoom_ratio;
333- double y = it->y * zoom_ratio;
334- glVertex2d(x - offset.x, y - offset.y);
335- }
335+ double x = it->x * zoom_ratio;
336+ double y = it->y * zoom_ratio;
337+ glVertex2d(x - offset.x, y - offset.y);
338+ }
339+ }
340+ glEnd();
336341 }
337- glEnd();
338- }
339342
340343
341- // [mm] -> [pixel]
342- double zoomRatio(void)
343- {
344- return (1.0 / pixel_per_mm_ / (height_ / 2.0));
345- }
344+ // [mm] -> [pixel]
345+ double zoomRatio(void)
346+ {
347+ return (1.0 / pixel_per_mm_ / (height_ / 2.0));
348+ }
346349
347350
348- Point<double> drawOffset(double zoom_ratio)
349- {
350- return Point<double>(-view_center_.x * zoom_ratio,
351- -view_center_.y * zoom_ratio);
352- }
351+ Point<double> drawOffset(double zoom_ratio)
352+ {
353+ return Point<double>(-view_center_.x * zoom_ratio,
354+ -view_center_.y * zoom_ratio);
355+ }
353356
354357
355- void setClickedPosition(QMouseEvent* event)
356- {
357- clicked_position_ = event->pos();
358- }
358+ void setClickedPosition(QMouseEvent* event)
359+ {
360+ clicked_position_ = event->pos();
361+ }
359362
360363
361- void updateZoomRatio(int steps)
362- {
363- double zoom = widget_->zoomRatio();
364- zoom *= pow(1.1, steps);
364+ void updateZoomRatio(int steps)
365+ {
366+ double zoom = widget_->zoomRatio();
367+ zoom *= pow(1.1, steps);
365368
366- if (zoom > 500.0) {
367- zoom = 500.0;
368- } else if (zoom < 0.05) {
369- zoom = 0.05;
369+ if (zoom > 500.0) {
370+ zoom = 500.0;
371+ } else if (zoom < 0.05) {
372+ zoom = 0.05;
373+ }
374+ widget_->setZoomRatio(zoom);
370375 }
371- widget_->setZoomRatio(zoom);
372- }
373376
374377
375- bool storeUrgData(int timestamp, vector<Point<long> >& point_data,
376- vector<Point<long> >* intensity_point_data = NULL)
377- {
378- removeOldData(timestamp);
379- draw_data_.push_back(DrawData(point_data, timestamp, line_color_));
380- if (intensity_point_data) {
381- draw_data_.push_back(DrawData(*intensity_point_data, timestamp,
382- Color(1.0f, 0.0f, 1.0f, 0.7f)));
378+ bool storeUrgData(int timestamp, vector<Point<long> >& point_data,
379+ vector<Point<long> >* intensity_point_data = NULL)
380+ {
381+ removeOldData(timestamp);
382+ draw_data_.push_back(DrawData(point_data, timestamp, line_color_));
383+ if (intensity_point_data) {
384+ draw_data_.push_back(DrawData(*intensity_point_data, timestamp,
385+ Color(1.0f, 0.0f, 1.0f, 0.7f)));
386+ }
387+ last_timestamp_ = timestamp;
388+
389+ return true;
383390 }
384- last_timestamp_ = timestamp;
385-
386- return true;
387- }
388391 };
389392
390393
391394 UrgDrawWidget::UrgDrawWidget(QWidget* parent)
392- : QGLWidget(parent), pimpl(new pImpl(this))
395+ : QGLWidget(parent), pimpl(new pImpl(this))
393396 {
394- pimpl->initializeForm();
397+ pimpl->initializeForm();
395398 }
396399
397400
@@ -402,53 +405,53 @@
402405
403406 void UrgDrawWidget::clear(void)
404407 {
405- pimpl->draw_data_.clear();
406- //redraw();
408+ pimpl->draw_data_.clear();
409+ //redraw();
407410 }
408411
409412
410413 void UrgDrawWidget::initializeView(void)
411414 {
412- pimpl->pixel_per_mm_ = DefaultPixelPerMm;
413- pimpl->view_center_ = Point<double>(0.0, 0.0);
414- redraw();
415+ pimpl->pixel_per_mm_ = DefaultPixelPerMm;
416+ pimpl->view_center_ = Point<double>(0.0, 0.0);
417+ redraw();
415418 }
416419
417420
418421 void UrgDrawWidget::redraw(void)
419422 {
420- pimpl->last_redraw_ = ticks();
421- updateGL();
423+ pimpl->last_redraw_ = ticks();
424+ updateGL();
422425 }
423426
424427
425428 bool UrgDrawWidget::setUrgData(qrk::RangeSensor* sensor)
426429 {
427- vector<long> data;
428- vector<long> intensity_data;
429- vector<Point<long> > intensity_point_data;
430- long timestamp = 0;
430+ vector<long> data;
431+ vector<long> intensity_data;
432+ vector<Point<long> > intensity_point_data;
433+ long timestamp = 0;
431434
432- RangeCaptureMode capture_mode = sensor->captureMode();
435+ RangeCaptureMode capture_mode = sensor->captureMode();
433436
434- int n = 0;
435- if (capture_mode != IntensityCapture) {
436- n = sensor->capture(data, &timestamp);
437- } else {
438- n = sensor->captureWithIntensity(data, intensity_data, &timestamp);
439- }
440- if (n <= 0) {
441- return false;
442- }
437+ int n = 0;
438+ if (capture_mode != IntensityCapture) {
439+ n = sensor->capture(data, &timestamp);
440+ } else {
441+ n = sensor->captureWithIntensity(data, intensity_data, &timestamp);
442+ }
443+ if (n <= 0) {
444+ return false;
445+ }
443446
444- vector<Point<long> > point_data;
445- qrk::convert2d(point_data, sensor, data, pimpl->rotate_offset_);
446- if (capture_mode == IntensityCapture) {
447- qrk::convert2d(intensity_point_data, sensor, intensity_data,
448- pimpl->rotate_offset_, numeric_limits<int>::max());
449- }
447+ vector<Point<long> > point_data;
448+ qrk::convert2d(point_data, sensor, data, pimpl->rotate_offset_);
449+ if (capture_mode == IntensityCapture) {
450+ qrk::convert2d(intensity_point_data, sensor, intensity_data,
451+ pimpl->rotate_offset_, numeric_limits<int>::max());
452+ }
450453
451- return pimpl->storeUrgData(timestamp, point_data, &intensity_point_data);
454+ return pimpl->storeUrgData(timestamp, point_data, &intensity_point_data);
452455 }
453456
454457
@@ -455,10 +458,10 @@
455458 bool UrgDrawWidget::setUrgData(std::vector<long>& data,
456459 const RangeSensor* sensor, long timestamp)
457460 {
458- vector<Point<long> > point_data;
459- qrk::convert2d(point_data, sensor, data, pimpl->rotate_offset_);
461+ vector<Point<long> > point_data;
462+ qrk::convert2d(point_data, sensor, data, pimpl->rotate_offset_);
460463
461- return pimpl->storeUrgData(timestamp, point_data, NULL);
464+ return pimpl->storeUrgData(timestamp, point_data, NULL);
462465 }
463466
464467
@@ -465,7 +468,7 @@
465468 bool UrgDrawWidget::setUrgData(std::vector<qrk::Point<long> >& data,
466469 long timestamp)
467470 {
468- return pimpl->storeUrgData(timestamp, data, NULL);
471+ return pimpl->storeUrgData(timestamp, data, NULL);
469472 }
470473
471474
@@ -473,13 +476,13 @@
473476 const qrk::RangeSensor* sensor,
474477 long timestamp)
475478 {
476- vector<Point<long> > point_data;
477- qrk::convert2d(point_data, sensor, data, pimpl->rotate_offset_,
478- numeric_limits<int>::max());
479+ vector<Point<long> > point_data;
480+ qrk::convert2d(point_data, sensor, data, pimpl->rotate_offset_,
481+ numeric_limits<int>::max());
479482
480- pimpl->draw_data_.push_back(DrawData(point_data, timestamp,
481- Color(1.0f, 0.0f, 1.0f, 0.7f)));
482- return true;
483+ pimpl->draw_data_.push_back(DrawData(point_data, timestamp,
484+ Color(1.0f, 0.0f, 1.0f, 0.7f)));
485+ return true;
483486 }
484487
485488
@@ -486,140 +489,141 @@
486489 bool UrgDrawWidget::setUrgIntensityData(vector<qrk::Point<long> >& data,
487490 long timestamp)
488491 {
489- pimpl->draw_data_.push_back(DrawData(data, timestamp,
490- Color(1.0f, 0.0f, 1.0f, 0.7f)));
491- return true;
492+ pimpl->draw_data_.push_back(DrawData(data, timestamp,
493+ Color(1.0f, 0.0f, 1.0f, 0.7f)));
494+ return true;
492495 }
493496
494497
495498 void UrgDrawWidget::setDrawColor(const qrk::Color& line_color)
496499 {
497- pimpl->line_color_ = line_color;
500+ pimpl->line_color_ = line_color;
498501 }
499502
500503
501504 void UrgDrawWidget::setDrawMode(DrawMode mode)
502505 {
503- pimpl->draw_mode_ = mode;
506+ pimpl->draw_mode_ = mode;
504507 }
505508
506509
507510 void UrgDrawWidget::setDrawPeriod(size_t msec)
508511 {
509- pimpl->draw_period_ = msec;
512+ pimpl->draw_period_ = msec;
510513 }
511514
512515
513516 void UrgDrawWidget::setZoomRatio(double pixel_per_mm)
514517 {
515- pimpl->pixel_per_mm_ = pixel_per_mm;
516- redraw();
518+ pimpl->pixel_per_mm_ = pixel_per_mm;
519+ redraw();
517520 }
518521
519522
520523 double UrgDrawWidget::zoomRatio(void)
521524 {
522- return pimpl->pixel_per_mm_;
525+ return pimpl->pixel_per_mm_;
523526 }
524527
525528
526529 void UrgDrawWidget::updateZoomRatio(int steps)
527530 {
528- pimpl->updateZoomRatio(steps);
531+ pimpl->updateZoomRatio(steps);
529532 }
530533
531534
532535 void UrgDrawWidget::setViewCenter(const Point<long>& point)
533536 {
534- pimpl->view_center_.x = point.x;
535- pimpl->view_center_.y = point.y;
537+ pimpl->view_center_.x = point.x;
538+ pimpl->view_center_.y = point.y;
536539 }
537540
538541
539542 Point<long> UrgDrawWidget::viewCenter(void)
540543 {
541- return Point<long>(static_cast<long>(pimpl->view_center_.x),
542- static_cast<long>(pimpl->view_center_.y));
544+ return Point<long>(static_cast<long>(pimpl->view_center_.x),
545+ static_cast<long>(pimpl->view_center_.y));
543546 }
544547
545548
546549 void UrgDrawWidget::initializeGL(void)
547550 {
548- pimpl->initializeGL();
551+ pimpl->initializeGL();
549552 }
550553
551554
552555 void UrgDrawWidget::resizeGL(int width, int height)
553556 {
554- pimpl->resizeGL(width, height);
557+ pimpl->resizeGL(width, height);
555558 }
556559
557560
558561 void UrgDrawWidget::paintGL(void)
559562 {
560- pimpl->paintGL();
563+ pimpl->paintGL();
561564 }
562565
563566
564567 void UrgDrawWidget::mousePressEvent(QMouseEvent* event)
565568 {
566- pimpl->now_pressed_ = true;
567- pimpl->setClickedPosition(event);
569+ pimpl->now_pressed_ = true;
570+ pimpl->setClickedPosition(event);
568571 }
569572
570573
571574 void UrgDrawWidget::mouseMoveEvent(QMouseEvent* event)
572575 {
573- int x = event->x();
574- int y = event->y();
576+ int x = event->x();
577+ int y = event->y();
575578
576- if (pimpl->now_pressed_) {
577- int dx = x - pimpl->clicked_position_.x();
578- int dy = y - pimpl->clicked_position_.y();
579+ if (pimpl->now_pressed_) {
580+ int dx = x - pimpl->clicked_position_.x();
581+ int dy = y - pimpl->clicked_position_.y();
579582
580- pimpl->view_center_.x += dx * pimpl->pixel_per_mm_;
581- pimpl->view_center_.y -= dy * pimpl->pixel_per_mm_;
583+ pimpl->view_center_.x += dx * pimpl->pixel_per_mm_;
584+ pimpl->view_center_.y -= dy * pimpl->pixel_per_mm_;
582585
583- pimpl->setClickedPosition(event);
586+ pimpl->setClickedPosition(event);
584587
585- // 最後の更新が MinimumRedrawInterval [msec] 以前だったなら、再描画を行う
586- enum { MinimumRedrawInterval = 25 };
587- if ((pimpl->last_redraw_ + MinimumRedrawInterval) < ticks()) {
588- redraw();
588+ // 最後の更新が MinimumRedrawInterval [msec] 以前だったなら、
589+ // 再描画を行う
590+ enum { MinimumRedrawInterval = 25 };
591+ if ((pimpl->last_redraw_ + MinimumRedrawInterval) < ticks()) {
592+ redraw();
593+ }
589594 }
590- }
591595
592- // カーソル位置の座標をシグナルで送信する
593- if ((x < 0) || (x >= static_cast<int>(pimpl->width_)) ||
594- (y < 0) || (y >= static_cast<int>(pimpl->height_))) {
595- emit position(false, -1, -1);
596- return;
597- }
596+ // カーソル位置の座標をシグナルで送信する
597+ if ((x < 0) || (x >= static_cast<int>(pimpl->width_)) ||
598+ (y < 0) || (y >= static_cast<int>(pimpl->height_))) {
599+ emit position(false, -1, -1);
600+ return;
601+ }
598602
599- int center_x = pimpl->width_ / 2;
600- int center_y = pimpl->height_ / 2;
601- int x_mm = static_cast<int>(((x - center_x) * pimpl->pixel_per_mm_)
602- - pimpl->view_center_.x);
603- int y_mm = static_cast<int>((-(y - center_y) * pimpl->pixel_per_mm_)
604- - pimpl->view_center_.y);
605- emit position(true, x_mm, y_mm);
603+ int center_x = pimpl->width_ / 2;
604+ int center_y = pimpl->height_ / 2;
605+ int x_mm = static_cast<int>(((x - center_x) * pimpl->pixel_per_mm_)
606+ - pimpl->view_center_.x);
607+ int y_mm = static_cast<int>((-(y - center_y) * pimpl->pixel_per_mm_)
608+ - pimpl->view_center_.y);
609+ emit position(true, x_mm, y_mm);
606610 }
607611
608612
609613 void UrgDrawWidget::mouseReleaseEvent(QMouseEvent* event)
610614 {
611- static_cast<void>(event);
615+ static_cast<void>(event);
612616
613- pimpl->now_pressed_ = false;
614- redraw();
617+ pimpl->now_pressed_ = false;
618+ redraw();
615619 }
616620
617621
618622 void UrgDrawWidget::wheelEvent(QWheelEvent* event) {
619623
620- int degrees = event->delta() / 8;
621- int steps = degrees / 15;
624+ int degrees = event->delta() / 8;
625+ int steps = degrees / 15;
622626
623- event->accept();
624- updateZoomRatio(steps);
627+ event->accept();
628+ updateZoomRatio(steps);
625629 }
--- trunk/widgets/UrgDrawWidget/UrgDrawWidget.h (revision 1829)
+++ trunk/widgets/UrgDrawWidget/UrgDrawWidget.h (revision 1830)
@@ -18,7 +18,7 @@
1818
1919 namespace qrk
2020 {
21- class RangeSensor;
21+ class RangeSensor;
2222 }
2323
2424
@@ -27,65 +27,65 @@
2727 */
2828 class UrgDrawWidget : public QGLWidget
2929 {
30- Q_OBJECT;
30+ Q_OBJECT;
3131
3232 public:
33- typedef enum {
34- Points,
35- Lines,
36- Polygon,
37- } DrawMode;
33+ typedef enum {
34+ Points,
35+ Lines,
36+ Polygon,
37+ } DrawMode;
3838
3939
40- UrgDrawWidget(QWidget* parent = 0);
41- ~UrgDrawWidget(void);
40+ UrgDrawWidget(QWidget* parent = 0);
41+ ~UrgDrawWidget(void);
4242
43- void clear(void);
44- void initializeView(void);
43+ void clear(void);
44+ void initializeView(void);
4545
46- void redraw(void);
46+ void redraw(void);
4747
48- bool setUrgData(qrk::RangeSensor* sensor);
49- bool setUrgData(std::vector<long>& data,
50- const qrk::RangeSensor* sensor, long timestamp);
51- bool setUrgData(std::vector<qrk::Point<long> >& data, long timestamp);
48+ bool setUrgData(qrk::RangeSensor* sensor);
49+ bool setUrgData(std::vector<long>& data,
50+ const qrk::RangeSensor* sensor, long timestamp);
51+ bool setUrgData(std::vector<qrk::Point<long> >& data, long timestamp);
5252
53- bool setUrgIntensityData(std::vector<long>& data,
54- const qrk::RangeSensor* sensor, long timestamp);
55- bool setUrgIntensityData(std::vector<qrk::Point<long> >& data,
56- long timestamp);
53+ bool setUrgIntensityData(std::vector<long>& data,
54+ const qrk::RangeSensor* sensor, long timestamp);
55+ bool setUrgIntensityData(std::vector<qrk::Point<long> >& data,
56+ long timestamp);
5757
58- void setDrawColor(const qrk::Color& line_color);
58+ void setDrawColor(const qrk::Color& line_color);
5959
60- void setDrawMode(DrawMode mode);
60+ void setDrawMode(DrawMode mode);
6161
62- void setDrawPeriod(size_t msec);
62+ void setDrawPeriod(size_t msec);
6363
64- void setZoomRatio(double pixel_per_mm);
65- double zoomRatio(void);
66- void updateZoomRatio(int steps);
64+ void setZoomRatio(double pixel_per_mm);
65+ double zoomRatio(void);
66+ void updateZoomRatio(int steps);
6767
68- void setViewCenter(const qrk::Point<long>& point);
69- qrk::Point<long> viewCenter(void);
68+ void setViewCenter(const qrk::Point<long>& point);
69+ qrk::Point<long> viewCenter(void);
7070
7171 signals:
72- void position(bool active, long x_mm, long y_mm);
72+ void position(bool active, long x_mm, long y_mm);
7373
7474 protected:
75- void initializeGL(void);
76- void resizeGL(int width, int height);
77- void paintGL(void);
78- void mousePressEvent(QMouseEvent* event);
79- void mouseMoveEvent(QMouseEvent* event);
80- void mouseReleaseEvent(QMouseEvent* event);
81- void wheelEvent(QWheelEvent* event);
75+ void initializeGL(void);
76+ void resizeGL(int width, int height);
77+ void paintGL(void);
78+ void mousePressEvent(QMouseEvent* event);
79+ void mouseMoveEvent(QMouseEvent* event);
80+ void mouseReleaseEvent(QMouseEvent* event);
81+ void wheelEvent(QWheelEvent* event);
8282
8383 private:
84- UrgDrawWidget(const UrgDrawWidget& rhs);
85- UrgDrawWidget& operator = (const UrgDrawWidget& rhs);
84+ UrgDrawWidget(const UrgDrawWidget& rhs);
85+ UrgDrawWidget& operator = (const UrgDrawWidget& rhs);
8686
87- struct pImpl;
88- std::auto_ptr<pImpl> pimpl;
87+ struct pImpl;
88+ std::auto_ptr<pImpl> pimpl;
8989 };
9090
9191 #endif /* !QRK_URG_DRAW_WIDGET_H */
--- trunk/libs/lua/luabindGui.cpp (revision 1829)
+++ trunk/libs/lua/luabindGui.cpp (revision 1830)
@@ -21,6 +21,7 @@
2121 #include "ColorSurface.h"
2222 #include "FillSurface.h"
2323 #include "ImageSurface.h"
24+#include "CanvasSurface.h"
2425 #include "MultiSurface.h"
2526 #include "Label.h"
2627 #include "Button.h"
@@ -156,6 +157,22 @@
156157 .def("setAlpha", &ImageSurface::setAlpha)
157158 .def("draw", &ImageSurface::draw),
158159
160+ class_<CanvasSurface, Surface>("CanvasSurface")
161+ .def(constructor<const Rect<long>&>())
162+ .def("isValid", &CanvasSurface::isValid)
163+ .def("rect", &CanvasSurface::rect)
164+ .def("setAlpha", &CanvasSurface::setAlpha)
165+ .def("draw", &CanvasSurface::draw)
166+ .def("setFont", &CanvasSurface::setFont)
167+ .def("setClearColor", &CanvasSurface::setClearColor)
168+ .def("clear", &CanvasSurface::clear)
169+ .def("setColor", &CanvasSurface::setColor)
170+ .def("setLineWidth", &CanvasSurface::setLineWidth)
171+ .def("drawLineStrip", &CanvasSurface::drawLineStrip)
172+ .def("drawCircle", &CanvasSurface::drawCircle)
173+ .def("drawQuadStrip", &CanvasSurface::drawQuadStrip)
174+ .def("drawText", &CanvasSurface::drawText),
175+
159176 class_<MultiSurface, Surface>("MultiSurface")
160177 .def(constructor<Surface&>())
161178 .def("rect", &MultiSurface::rect)
--- trunk/libs/lua/Makefile (revision 1829)
+++ trunk/libs/lua/Makefile (revision 1830)
@@ -87,9 +87,10 @@
8787 luabindGui.o: ../common/Color.h ../gui/TextSurface.h ../gui/Surface.h
8888 luabindGui.o: ../gui/TextFadeSurface.h ../gui/TextRubiFadeSurface.h
8989 luabindGui.o: ../gui/ColorSurface.h ../gui/FillSurface.h
90-luabindGui.o: ../gui/ImageSurface.h ../gui/MultiSurface.h ../gui/Label.h
91-luabindGui.o: ../gui/Component.h ../gui/Button.h ../gui/Menu.h
92-luabindGui.o: ../gui/ChatMessage.h ../gui/CallbackEvent.h ../gui/AlignUtils.h
90+luabindGui.o: ../gui/ImageSurface.h ../gui/CanvasSurface.h
91+luabindGui.o: ../gui/MultiSurface.h ../gui/Label.h ../gui/Component.h
92+luabindGui.o: ../gui/Button.h ../gui/Menu.h ../gui/ChatMessage.h
93+luabindGui.o: ../gui/CallbackEvent.h ../gui/AlignUtils.h
9394 luabindInit.o: luabindInit.h LuaHandler.h ../system/log_printf.h
9495 luabindInput.o: luabindInput.h ../input/convertToRoman.h
9596 luabindInput.o: ../input/convertToJp.h ../input/Utf8.h ../input/utf8_string.h
--- trunk/libs/gui/Canvas.cpp (revision 1829)
+++ trunk/libs/gui/Canvas.cpp (nonexistent)
@@ -1,297 +0,0 @@
1-/*!
2- \file
3- \brief 描画コンポーネント
4-
5- \author Satofumi KAMIMURA
6-
7- $Id$
8-
9- \todo setAlpha() を実行する
10- \todo 適切にクリッピングを行う
11-*/
12-
13-#define GL_GLEXT_PROTOTYPES
14-#include "Canvas.h"
15-#include "Font.h"
16-#include <SDL_opengl.h>
17-#include <vector>
18-#include <cassert>
19-
20-using namespace qrk;
21-using namespace std;
22-
23-
24-namespace
25-{
26- typedef struct
27- {
28- GLuint buffer;
29- GLenum mode;
30- size_t size;
31- GLfloat line_width;
32- //vector<GLfloat> intertwined;
33- } draw_t;
34-
35- typedef vector<draw_t> Draws;
36-}
37-
38-struct Canvas::pImpl
39-{
40- Rect<long> rect_;
41- float alpha_;
42- Color draw_color_;
43- GLfloat line_width_;
44- Font* font_;
45- vector<draw_t> draws_;
46- draw_t clear_draw_;
47-
48-
49- pImpl(const Rect<long>& rect)
50- : rect_(rect), alpha_(1.0), draw_color_(Color(1.0, 1.0, 1.0, 1.0)),
51- line_width_(1.0f), font_(NULL)
52- {
53- clearBuffers();
54- setClearColor(Color(0.0f, 0.0f, 0.0f));
55- }
56-
57-
58- ~pImpl(void)
59- {
60- clearBuffers();
61-
62- // !!! clear_draw_ のリソースを解放する
63- }
64-
65-
66- GLuint createBuffer(void)
67- {
68- GLuint id;
69- glGenBuffers(1, &id);
70-
71- return id;
72- }
73-
74-
75- void clearBuffers(void)
76- {
77- for (Draws::iterator it = draws_.begin(); it != draws_.end(); ++it) {
78- glDeleteBuffers(1, &it->buffer);
79- }
80- draws_.clear();
81- }
82-
83-
84- void registerColor(vector<GLfloat>& intertwined)
85- {
86- intertwined.push_back(draw_color_.r);
87- intertwined.push_back(draw_color_.g);
88- intertwined.push_back(draw_color_.b);
89- }
90-
91-
92- void setClearColor(const Color& color)
93- {
94- vector<Point<long> > points;
95- points.push_back(Point<long>(0, 0));
96- points.push_back(Point<long>(0, rect_.h));
97- points.push_back(Point<long>(rect_.w, 0));
98- points.push_back(Point<long>(rect_.w, rect_.h));
99-
100- // クリア用の矩形を作成する
101- Color stored_color = draw_color_;
102- draw_color_ = color;
103- registerPrimitive(clear_draw_, points, GL_QUAD_STRIP);
104- draw_color_ = stored_color;
105- }
106-
107-
108- void registerPrimitive(draw_t& draw,
109- const vector<Point<long> >& points, GLenum mode)
110- {
111- draw.mode = mode;
112- draw.line_width = line_width_;
113- draw.buffer = createBuffer();
114- draw.size = points.size();
115-
116- vector<GLfloat> intertwined;
117- for (vector<Point<long> >::const_iterator it = points.begin();
118- it != points.end(); ++it) {
119- registerColor(intertwined);
120- intertwined.push_back(it->x);
121- intertwined.push_back(it->y);
122- intertwined.push_back(0.0f);
123- }
124-
125- glBindBuffer(GL_ARRAY_BUFFER, draw.buffer);
126- size_t array_size =
127- intertwined.size() * sizeof(intertwined[0]);
128- glBufferData(GL_ARRAY_BUFFER, array_size,
129- &intertwined[0], GL_STATIC_DRAW);
130-
131- glBindBuffer(GL_ARRAY_BUFFER, 0);
132- }
133-
134-
135- void drawLineStrip(const vector<Point<long> >& points)
136- {
137- draw_t draw;
138- registerPrimitive(draw, points, GL_LINE_STRIP);
139- draws_.push_back(draw);
140- }
141-
142-
143- void drawQuadsStrip(const vector<Point<long> >& points)
144- {
145- draw_t draw;
146- registerPrimitive(draw, points, GL_QUAD_STRIP);
147- draws_.push_back(draw);
148- }
149-
150-
151- void drawPrimitive(const draw_t& draw)
152- {
153- glLineWidth(draw.line_width);
154- glBindBuffer(GL_ARRAY_BUFFER, draw.buffer);
155- glInterleavedArrays(GL_C3F_V3F, 0, NULL);
156- glDrawArrays(draw.mode, 0, draw.size);
157- glBindBuffer(GL_ARRAY_BUFFER, 0);
158- }
159-
160-
161- void draw(const Rect<long>* src, const Rect<long>* dest)
162- {
163- // !!! 指定されている描画範囲でクリッピングする
164- (void)src;
165- (void)dest;
166-
167- // !!! 位置にオフセットを加えて描画する
168-
169- // !!!
170-
171- glEnableClientState(GL_VERTEX_ARRAY);
172- glEnableClientState(GL_COLOR_ARRAY);
173-
174- drawPrimitive(clear_draw_);
175-
176- for (Draws::const_iterator it = draws_.begin();
177- it != draws_.end(); ++it) {
178- drawPrimitive(*it);
179- }
180-
181- glDisableClientState(GL_COLOR_ARRAY);
182- glDisableClientState(GL_VERTEX_ARRAY);
183- }
184-};
185-
186-
187-Canvas::Canvas(const qrk::Rect<long>& rect) : pimpl(new pImpl(rect))
188-{
189-}
190-
191-
192-Canvas::~Canvas(void)
193-{
194-}
195-
196-
197-bool Canvas::isValid(void) const
198-{
199- return true;
200-}
201-
202-
203-Rect<long> Canvas::rect(void) const
204-{
205- return pimpl->rect_;
206-}
207-
208-
209-void Canvas::setAlpha(float alpha)
210-{
211- pimpl->alpha_ = alpha;
212-}
213-
214-
215-float Canvas::alpha(void) const
216-{
217- return pimpl->alpha_;
218-}
219-
220-
221-void Canvas::setRotateAngle(const Angle& angle)
222-{
223- (void)angle;
224- // !!!
225-}
226-
227-
228-void Canvas::draw(const Rect<long>* src, const Rect<long>* dest)
229-{
230- pimpl->draw(src, dest);
231-}
232-
233-
234-void Canvas::setFont(Font& font)
235-{
236- pimpl->font_ = &font;
237-}
238-
239-
240-void Canvas::setClearColor(const qrk::Color& color)
241-{
242- pimpl->setClearColor(color);
243-}
244-
245-
246-void Canvas::clear(void)
247-{
248- pimpl->clearBuffers();
249-}
250-
251-
252-void Canvas::setColor(const qrk::Color& color)
253-{
254- pimpl->draw_color_ = color;
255-}
256-
257-
258-void Canvas::setLineWidth(float width)
259-{
260- pimpl->line_width_ = width;
261-}
262-
263-
264-void Canvas::drawLineStrip(const std::vector<qrk::Point<long> >& points)
265-{
266- if (points.empty()) {
267- return;
268- }
269-
270- pimpl->drawLineStrip(points);
271-}
272-
273-
274-void Canvas::drawCircle(const qrk::Point<long>& center, float radius)
275-{
276- (void)center;
277- (void)radius;
278- // !!!
279-}
280-
281-
282-void Canvas::drawQuadStrip(const std::vector<qrk::Point<long> >& points)
283-{
284- if (points.empty()) {
285- return;
286- }
287-
288- pimpl->drawQuadsStrip(points);
289-}
290-
291-
292-void Canvas::drawText(const char* text, const Point<long>& position)
293-{
294- (void)text;
295- (void)position;
296- // !!!
297-}
Deleted: svn:keywords
## -1 +0,0 ##
-Id
\ No newline at end of property
--- trunk/libs/gui/Canvas.h (revision 1829)
+++ trunk/libs/gui/Canvas.h (nonexistent)
@@ -1,59 +0,0 @@
1-#ifndef QRK_CANVAS_H
2-#define QRK_CANVAS_H
3-
4-/*!
5- \file
6- \brief 描画サーフェス
7-
8- \author Satofumi KAMIMURA
9-
10- $Id$
11-*/
12-
13-#include "Surface.h"
14-#include "Rect.h"
15-#include "Point.h"
16-#include "Color.h"
17-#include <vector>
18-#include <memory>
19-
20-
21-namespace qrk
22-{
23- class Font;
24-
25-
26- class Canvas : public Surface
27- {
28- public:
29- Canvas(const qrk::Rect<long>& rect);
30- ~Canvas(void);
31-
32- bool isValid(void) const;
33- Rect<long> rect(void) const;
34- void setAlpha(float alpha);
35- float alpha(void) const;
36- void setRotateAngle(const Angle& angle);
37- void draw(const Rect<long>* src, const Rect<long>* dest);
38-
39- void setFont(qrk::Font& font);
40- void setClearColor(const qrk::Color& color);
41- void clear(void);
42- void setColor(const qrk::Color& color);
43- void setLineWidth(float width);
44-
45- void drawLineStrip(const std::vector<qrk::Point<long> >& points);
46- void drawCircle(const qrk::Point<long>& center, float radius);
47- void drawQuadStrip(const std::vector<qrk::Point<long> >& points);
48- void drawText(const char* text, const Point<long>& position);
49-
50- private:
51- Canvas(const Canvas& rhs);
52- Canvas& operator = (Canvas& rhs);
53-
54- struct pImpl;
55- std::auto_ptr<pImpl> pimpl;
56- };
57-}
58-
59-#endif /* !QRK_CANVAS_H */
Deleted: svn:keywords
## -1 +0,0 ##
-Id
\ No newline at end of property
--- trunk/libs/gui/CanvasSurface.cpp (nonexistent)
+++ trunk/libs/gui/CanvasSurface.cpp (revision 1830)
@@ -0,0 +1,313 @@
1+/*!
2+ \file
3+ \brief 描画コンポーネント
4+
5+ \author Satofumi KAMIMURA
6+
7+ $Id$
8+
9+ \todo setAlpha() を実行する
10+ \todo 適切にクリッピングを行う
11+*/
12+
13+#define GL_GLEXT_PROTOTYPES
14+#include "CanvasSurface.h"
15+#include "Font.h"
16+#include "Screen.h"
17+#include <SDL_opengl.h>
18+#include <vector>
19+#include <cassert>
20+
21+using namespace qrk;
22+using namespace std;
23+
24+
25+namespace
26+{
27+ typedef struct
28+ {
29+ GLuint buffer;
30+ GLenum mode;
31+ size_t size;
32+ GLfloat line_width;
33+ //vector<GLfloat> intertwined;
34+ } draw_t;
35+
36+ typedef vector<draw_t> Draws;
37+}
38+
39+struct CanvasSurface::pImpl
40+{
41+ Rect<long> rect_;
42+ float alpha_;
43+ Color draw_color_;
44+ GLfloat line_width_;
45+ Font* font_;
46+ vector<draw_t> draws_;
47+ draw_t clear_draw_;
48+
49+
50+ pImpl(const Rect<long>& rect)
51+ : rect_(rect), alpha_(1.0), draw_color_(Color(1.0, 1.0, 1.0, 1.0)),
52+ line_width_(1.0f), font_(NULL)
53+ {
54+ clearBuffers();
55+ setClearColor(Color(0.0f, 0.0f, 0.0f));
56+ }
57+
58+
59+ ~pImpl(void)
60+ {
61+ clearBuffers();
62+
63+ // !!! clear_draw_ のリソースを解放する
64+ }
65+
66+
67+ GLuint createBuffer(void)
68+ {
69+ GLuint id;
70+ glGenBuffers(1, &id);
71+
72+ return id;
73+ }
74+
75+
76+ void clearBuffers(void)
77+ {
78+ for (Draws::iterator it = draws_.begin(); it != draws_.end(); ++it) {
79+ glDeleteBuffers(1, &it->buffer);
80+ }
81+ draws_.clear();
82+ }
83+
84+
85+ void registerColor(vector<GLfloat>& intertwined)
86+ {
87+ intertwined.push_back(draw_color_.r);
88+ intertwined.push_back(draw_color_.g);
89+ intertwined.push_back(draw_color_.b);
90+ }
91+
92+
93+ void setClearColor(const Color& color)
94+ {
95+ vector<Point<long> > points;
96+ points.push_back(Point<long>(0, 0));
97+ points.push_back(Point<long>(0, rect_.h));
98+ points.push_back(Point<long>(rect_.w, 0));
99+ points.push_back(Point<long>(rect_.w, rect_.h));
100+
101+ // クリア用の矩形を作成する
102+ Color stored_color = draw_color_;
103+ draw_color_ = color;
104+ registerPrimitive(clear_draw_, points, GL_QUAD_STRIP);
105+ draw_color_ = stored_color;
106+ }
107+
108+
109+ void registerPrimitive(draw_t& draw,
110+ const vector<Point<long> >& points, GLenum mode)
111+ {
112+ draw.mode = mode;
113+ draw.line_width = line_width_;
114+ draw.buffer = createBuffer();
115+ draw.size = points.size();
116+
117+ vector<GLfloat> intertwined;
118+ for (vector<Point<long> >::const_iterator it = points.begin();
119+ it != points.end(); ++it) {
120+ registerColor(intertwined);
121+ intertwined.push_back(it->x);
122+ intertwined.push_back(it->y);
123+ intertwined.push_back(0.0f);
124+ }
125+
126+ glBindBuffer(GL_ARRAY_BUFFER, draw.buffer);
127+ size_t array_size =
128+ intertwined.size() * sizeof(intertwined[0]);
129+ glBufferData(GL_ARRAY_BUFFER, array_size,
130+ &intertwined[0], GL_STATIC_DRAW);
131+
132+ glBindBuffer(GL_ARRAY_BUFFER, 0);
133+ }
134+
135+
136+ void drawLineStrip(const vector<Point<long> >& points)
137+ {
138+ draw_t draw;
139+ registerPrimitive(draw, points, GL_LINE_STRIP);
140+ draws_.push_back(draw);
141+ }
142+
143+
144+ void drawQuadsStrip(const vector<Point<long> >& points)
145+ {
146+ draw_t draw;
147+ registerPrimitive(draw, points, GL_QUAD_STRIP);
148+ draws_.push_back(draw);
149+ }
150+
151+
152+ void drawPrimitive(const draw_t& draw)
153+ {
154+ glLineWidth(draw.line_width);
155+ glBindBuffer(GL_ARRAY_BUFFER, draw.buffer);
156+ glInterleavedArrays(GL_C3F_V3F, 0, NULL);
157+ glDrawArrays(draw.mode, 0, draw.size);
158+ glBindBuffer(GL_ARRAY_BUFFER, 0);
159+ }
160+
161+
162+ void draw(const Rect<long>* src, const Rect<long>* dest)
163+ {
164+ glEnableClientState(GL_VERTEX_ARRAY);
165+ glEnableClientState(GL_COLOR_ARRAY);
166+
167+ // 位置にオフセットを加えて描画する
168+ Point<long> offset(dest->x, dest->y);
169+ if (src) {
170+ offset.x += src->x;
171+ offset.y += src->y;
172+ }
173+ glPushMatrix();
174+ glTranslatef(offset.x, offset.y, 0.0);
175+
176+ // !!! src のオフセットを加味する
177+ // !!! clip する領域の右側と下側が、場合によって狭くなるはず
178+ (void)src;
179+
180+ Screen::setClipArea(*dest);
181+
182+ drawPrimitive(clear_draw_);
183+
184+ for (Draws::const_iterator it = draws_.begin();
185+ it != draws_.end(); ++it) {
186+ drawPrimitive(*it);
187+ }
188+
189+ glPopMatrix();
190+
191+ glDisableClientState(GL_COLOR_ARRAY);
192+ glDisableClientState(GL_VERTEX_ARRAY);
193+
194+ Screen::disableClipArea();
195+ }
196+};
197+
198+
199+CanvasSurface::CanvasSurface(const qrk::Rect<long>& rect)
200+ : pimpl(new pImpl(rect))
201+{
202+}
203+
204+
205+CanvasSurface::~CanvasSurface(void)
206+{
207+}
208+
209+
210+bool CanvasSurface::isValid(void) const
211+{
212+ return true;
213+}
214+
215+
216+Rect<long> CanvasSurface::rect(void) const
217+{
218+ return pimpl->rect_;
219+}
220+
221+
222+void CanvasSurface::setAlpha(float alpha)
223+{
224+ pimpl->alpha_ = alpha;
225+}
226+
227+
228+float CanvasSurface::alpha(void) const
229+{
230+ return pimpl->alpha_;
231+}
232+
233+
234+void CanvasSurface::setRotateAngle(const Angle& angle)
235+{
236+ (void)angle;
237+ // !!!
238+}
239+
240+
241+void CanvasSurface::draw(const Rect<long>* src, const Rect<long>* dest)
242+{
243+ pimpl->draw(src, dest);
244+}
245+
246+
247+void CanvasSurface::setFont(Font& font)
248+{
249+ pimpl->font_ = &font;
250+}
251+
252+
253+void CanvasSurface::setClearColor(const qrk::Color& color)
254+{
255+ pimpl->setClearColor(color);
256+}
257+
258+
259+void CanvasSurface::clear(void)
260+{
261+ pimpl->clearBuffers();
262+}
263+
264+
265+void CanvasSurface::setColor(const qrk::Color& color)
266+{
267+ pimpl->draw_color_ = color;
268+}
269+
270+
271+void CanvasSurface::setLineWidth(float width)
272+{
273+ pimpl->line_width_ = width;
274+}
275+
276+
277+void CanvasSurface::drawLineStrip(const std::vector<qrk::Point<long> >& points)
278+{
279+ if (points.empty()) {
280+ return;
281+ }
282+
283+ pimpl->drawLineStrip(points);
284+}
285+
286+
287+void CanvasSurface::drawCircle(const qrk::Point<long>& center, float radius)
288+{
289+ (void)center;
290+ (void)radius;
291+ // !!!
292+}
293+
294+
295+void CanvasSurface::drawQuadStrip(const std::vector<qrk::Point<long> >& points)
296+{
297+ if (points.empty()) {
298+ return;
299+ }
300+
301+ pimpl->drawQuadsStrip(points);
302+}
303+
304+
305+void CanvasSurface::drawText(const char* text, const Point<long>& position)
306+{
307+ (void)text;
308+ (void)position;
309+ // !!!
310+
311+ // !!! text のサーフェスを作って描画させる
312+ // !!! 描画する順番をどうやって保証するかは、未検討
313+}
Added: svn:keywords
## -0,0 +1 ##
+Id
\ No newline at end of property
--- trunk/libs/gui/Makefile (revision 1829)
+++ trunk/libs/gui/Makefile (revision 1830)
@@ -40,6 +40,7 @@
4040 $(GUI_LIB)(SwitchSurface.o) \
4141 $(GUI_LIB)(MultiSurface.o) \
4242 $(GUI_LIB)(ImageSurface.o) \
43+ $(GUI_LIB)(CanvasSurface.o) \
4344 $(GUI_LIB)(Font.o) \
4445 $(GUI_LIB)(Label.o) \
4546 $(GUI_LIB)(Button.o) \
@@ -46,7 +47,6 @@
4647 $(GUI_LIB)(Menu.o) \
4748 $(GUI_LIB)(ChatMessage.o) \
4849 $(GUI_LIB)(AlignUtils.o) \
49- $(GUI_LIB)(Canvas.o) \
5050 $(GUI_LIB)(CheckBox.o) \
5151
5252 # DO NOT DELETE
@@ -53,7 +53,8 @@
5353
5454 Button.o: Component.h ../geometry/Rect.h ../geometry/Point.h
5555 CallbackEvent.o: Event.h ../geometry/Point.h ../geometry/Rect.h
56-Canvas.o: Surface.h ../geometry/Rect.h ../geometry/Point.h ../common/Color.h
56+CanvasSurface.o: Surface.h ../geometry/Rect.h ../geometry/Point.h
57+CanvasSurface.o: ../common/Color.h
5758 ChatMessage.o: Component.h ../geometry/Rect.h ../geometry/Point.h
5859 CheckBox.o: Component.h ../geometry/Rect.h ../geometry/Point.h
5960 ColorSurface.o: Surface.h ../geometry/Rect.h
@@ -83,8 +84,8 @@
8384 Button.o: LayerInterface.h ../geometry/RectUtils.h
8485 CallbackEvent.o: CallbackEvent.h Event.h ../geometry/Point.h
8586 CallbackEvent.o: ../geometry/Rect.h ../geometry/RectUtils.h
86-Canvas.o: Canvas.h Surface.h ../geometry/Rect.h ../geometry/Point.h
87-Canvas.o: ../common/Color.h
87+CanvasSurface.o: CanvasSurface.h Surface.h ../geometry/Rect.h
88+CanvasSurface.o: ../geometry/Point.h ../common/Color.h Font.h Screen.h
8889 ChatMessage.o: ChatMessage.h Component.h ../geometry/Rect.h
8990 ChatMessage.o: ../geometry/Point.h Font.h ../common/Color.h TextSurface.h
9091 ChatMessage.o: Surface.h ../system/StopWatch.h
--- trunk/libs/gui/samples/canvasDraw.cpp (revision 1829)
+++ trunk/libs/gui/samples/canvasDraw.cpp (revision 1830)
@@ -9,7 +9,7 @@
99 */
1010
1111 #include "Screen.h"
12-#include "Canvas.h"
12+#include "CanvasSurface.h"
1313 #include "Label.h"
1414
1515 using namespace qrk;
@@ -24,7 +24,7 @@
2424 Screen screen;
2525 screen.show(SDL_OPENGL);
2626
27- Canvas canvas(Rect<long>(0, 0, 100, 100));
27+ CanvasSurface canvas(Rect<long>(0, 0, 100, 100));
2828
2929 screen.clear();
3030 Rect<long> dest_rect = canvas.rect();
@@ -46,11 +46,17 @@
4646 points.push_back(Point<long>(100, 100));
4747 canvas.drawLineStrip(points);
4848
49- canvas.setLineWidth(4.0);
5049 points.clear();
51- points.push_back(Point<long>(100, 0));
52- points.push_back(Point<long>(0, 100));
53- canvas.drawLineStrip(points);
50+ canvas.setColor(Color(1.0, 0.0, 1.0));
51+ points.push_back(Point<long>(0, 20));
52+ points.push_back(Point<long>(0, 40));
53+ points.push_back(Point<long>(40, 60));
54+ points.push_back(Point<long>(40, 80));
55+ points.push_back(Point<long>(80, 40));
56+ points.push_back(Point<long>(80, 60));
57+ points.push_back(Point<long>(100, 80));
58+ points.push_back(Point<long>(100, 100));
59+ canvas.drawQuadStrip(points);
5460
5561 canvas.draw(NULL, &dest_rect);
5662
--- trunk/libs/gui/samples/Makefile (revision 1829)
+++ trunk/libs/gui/samples/Makefile (revision 1830)
@@ -55,9 +55,9 @@
5555 buttonSample.o: ../LayerInterface.h ../Layer.h ../Font.h ../../common/Color.h
5656 buttonSample.o: ../TextSurface.h ../Surface.h ../CallbackEvent.h ../Event.h
5757 buttonSample.o: ../EventUtils.h ../../system/delay.h
58-canvasDraw.o: ../Screen.h ../../geometry/Rect.h ../Canvas.h ../Surface.h
59-canvasDraw.o: ../../geometry/Point.h ../../common/Color.h ../Label.h
60-canvasDraw.o: ../Component.h
58+canvasDraw.o: ../Screen.h ../../geometry/Rect.h ../CanvasSurface.h
59+canvasDraw.o: ../Surface.h ../../geometry/Point.h ../../common/Color.h
60+canvasDraw.o: ../Label.h ../Component.h
6161 chatMessageSample.o: ../ChatMessage.h ../Component.h ../../geometry/Rect.h
6262 chatMessageSample.o: ../../geometry/Point.h ../Screen.h ../LayerManager.h
6363 chatMessageSample.o: ../LayerInterface.h ../Layer.h ../Font.h
@@ -64,6 +64,8 @@
6464 chatMessageSample.o: ../../common/Color.h ../ColorSurface.h ../Surface.h
6565 chatMessageSample.o: ../Label.h ../CallbackEvent.h ../Event.h ../EventUtils.h
6666 chatMessageSample.o: ../../system/delay.h
67+checkBoxSample.o: ../Screen.h ../../geometry/Rect.h ../CheckBox.h
68+checkBoxSample.o: ../Component.h ../../geometry/Point.h
6769 drawColorSurface.o: ../Screen.h ../../geometry/Rect.h ../ColorSurface.h
6870 drawColorSurface.o: ../Surface.h ../ImageSurface.h ../../common/Color.h
6971 drawText.o: ../Screen.h ../../geometry/Rect.h ../Font.h ../../common/Color.h
--- trunk/libs/gui/CanvasSurface.h (nonexistent)
+++ trunk/libs/gui/CanvasSurface.h (revision 1830)
@@ -0,0 +1,59 @@
1+#ifndef QRK_CANVAS_SURFACE_H
2+#define QRK_CANVAS_SURFACE_H
3+
4+/*!
5+ \file
6+ \brief 描画サーフェス
7+
8+ \author Satofumi KAMIMURA
9+
10+ $Id$
11+*/
12+
13+#include "Surface.h"
14+#include "Rect.h"
15+#include "Point.h"
16+#include "Color.h"
17+#include <vector>
18+#include <memory>
19+
20+
21+namespace qrk
22+{
23+ class Font;
24+
25+
26+ class CanvasSurface : public Surface
27+ {
28+ public:
29+ CanvasSurface(const qrk::Rect<long>& rect);
30+ ~CanvasSurface(void);
31+
32+ bool isValid(void) const;
33+ Rect<long> rect(void) const;
34+ void setAlpha(float alpha);
35+ float alpha(void) const;
36+ void setRotateAngle(const Angle& angle);
37+ void draw(const Rect<long>* src, const Rect<long>* dest);
38+
39+ void setFont(qrk::Font& font);
40+ void setClearColor(const qrk::Color& color);
41+ void clear(void);
42+ void setColor(const qrk::Color& color);
43+ void setLineWidth(float width);
44+
45+ void drawLineStrip(const std::vector<qrk::Point<long> >& points);
46+ void drawCircle(const qrk::Point<long>& center, float radius);
47+ void drawQuadStrip(const std::vector<qrk::Point<long> >& points);
48+ void drawText(const char* text, const Point<long>& position);
49+
50+ private:
51+ CanvasSurface(const CanvasSurface& rhs);
52+ CanvasSurface& operator = (CanvasSurface& rhs);
53+
54+ struct pImpl;
55+ std::auto_ptr<pImpl> pimpl;
56+ };
57+}
58+
59+#endif /* !QRK_CANVAS_SURFACE_H */
Added: svn:keywords
## -0,0 +1 ##
+Id
\ No newline at end of property
旧リポジトリブラウザで表示