rename CanvasSurface.h
@@ -30,368 +30,371 @@ | ||
30 | 30 | |
31 | 31 | namespace |
32 | 32 | { |
33 | - const double DefaultPixelPerMm = 20.0; | |
33 | + const double DefaultPixelPerMm = 20.0; | |
34 | 34 | |
35 | 35 | |
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; | |
41 | 41 | |
42 | 42 | |
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 | + }; | |
50 | 50 | } |
51 | 51 | |
52 | 52 | |
53 | 53 | struct UrgDrawWidget::pImpl |
54 | 54 | { |
55 | - enum { | |
56 | - MinimumWidth = 100, | |
57 | - MinimumHeight = 100, | |
55 | + enum { | |
56 | + MinimumWidth = 100, | |
57 | + MinimumHeight = 100, | |
58 | 58 | |
59 | - PointLength = 30 * 1000, // [mm] | |
60 | - }; | |
59 | + PointLength = 30 * 1000, // [mm] | |
60 | + }; | |
61 | 61 | |
62 | - UrgDrawWidget* widget_; | |
62 | + UrgDrawWidget* widget_; | |
63 | 63 | |
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_; | |
70 | 70 | |
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_; | |
75 | 75 | |
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_; | |
80 | 80 | |
81 | - Color line_color_; | |
81 | + Color line_color_; | |
82 | 82 | |
83 | 83 | |
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 | + } | |
93 | 93 | |
94 | 94 | |
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); | |
99 | 99 | |
100 | - widget_->setMouseTracking(true); | |
101 | - } | |
100 | + widget_->setMouseTracking(true); | |
101 | + } | |
102 | 102 | |
103 | 103 | |
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 | + } | |
109 | 109 | |
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 | + } | |
115 | 115 | |
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 | + } | |
124 | 124 | |
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 | + } | |
128 | 129 | } |
129 | - } | |
130 | 130 | |
131 | 131 | |
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); | |
139 | 139 | |
140 | - glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); | |
141 | - } | |
140 | + glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); | |
141 | + } | |
142 | 142 | |
143 | 143 | |
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); | |
147 | 147 | |
148 | - glMatrixMode(GL_PROJECTION); | |
149 | - glLoadIdentity(); | |
148 | + glMatrixMode(GL_PROJECTION); | |
149 | + glLoadIdentity(); | |
150 | 150 | |
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()); | |
154 | 154 | |
155 | - glMatrixMode(GL_MODELVIEW); | |
156 | - width_ = width; | |
157 | - height_ = height; | |
158 | - } | |
155 | + glMatrixMode(GL_MODELVIEW); | |
156 | + width_ = width; | |
157 | + height_ = height; | |
158 | + } | |
159 | 159 | |
160 | 160 | |
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(); | |
166 | 166 | |
167 | - // 軸の描画 | |
168 | - drawAxis(); | |
167 | + // 軸の描画 | |
168 | + drawAxis(); | |
169 | 169 | |
170 | - // データの描画 | |
171 | - drawData(); | |
172 | - } | |
170 | + // データの描画 | |
171 | + drawData(); | |
172 | + } | |
173 | 173 | |
174 | 174 | |
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); | |
179 | 179 | |
180 | - // 補助線の描画 | |
181 | - drawSubAxis(offset); | |
180 | + // 補助線の描画 | |
181 | + drawSubAxis(offset); | |
182 | 182 | |
183 | - glColor3d(0.3, 0.3, 0.3); | |
184 | - glBegin(GL_LINES); | |
183 | + glColor3d(0.3, 0.3, 0.3); | |
184 | + glBegin(GL_LINES); | |
185 | 185 | |
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); | |
189 | 189 | |
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); | |
194 | 194 | |
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(); | |
203 | 203 | |
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 | + // !!! | |
207 | 211 | } |
208 | 212 | |
209 | - // 単位の表示 | |
210 | - // !!! | |
211 | - } | |
212 | 213 | |
214 | + void drawSubCircle(int radius, const Point<double>& offset) | |
215 | + { | |
216 | + double pixel_radius = (radius / pixel_per_mm_) / (height_ / 2.0); | |
213 | 217 | |
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) { | |
217 | 220 | |
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(); | |
225 | 227 | } |
226 | - glEnd(); | |
227 | - } | |
228 | 228 | |
229 | 229 | |
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)); | |
241 | 241 | |
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 | + } | |
254 | 255 | } |
255 | - } | |
256 | 256 | |
257 | 257 | |
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 | + } | |
267 | 268 | |
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(); | |
273 | 277 | } |
274 | - glEnd(); | |
275 | - } | |
276 | 278 | |
277 | 279 | |
278 | - void drawData(void) | |
279 | - { | |
280 | - // !!! 時間が経過するほど、薄い色で表示するようにする | |
280 | + void drawData(void) | |
281 | + { | |
282 | + // !!! 時間が経過するほど、薄い色で表示するようにする | |
281 | 283 | |
282 | - double zoom_ratio = zoomRatio(); | |
283 | - Point<double> offset = drawOffset(zoom_ratio); | |
284 | + double zoom_ratio = zoomRatio(); | |
285 | + Point<double> offset = drawOffset(zoom_ratio); | |
284 | 286 | |
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) { | |
290 | 292 | |
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); | |
295 | 297 | |
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) { | |
300 | 302 | |
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 | + // !!! 実装方法を見直すべき | |
305 | 314 | } |
306 | - } | |
307 | - glEnd(); | |
308 | 315 | |
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); | |
313 | 320 | |
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) { | |
318 | 324 | |
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); | |
322 | 329 | |
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) { | |
327 | 334 | |
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(); | |
336 | 341 | } |
337 | - glEnd(); | |
338 | - } | |
339 | 342 | |
340 | 343 | |
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 | + } | |
346 | 349 | |
347 | 350 | |
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 | + } | |
353 | 356 | |
354 | 357 | |
355 | - void setClickedPosition(QMouseEvent* event) | |
356 | - { | |
357 | - clicked_position_ = event->pos(); | |
358 | - } | |
358 | + void setClickedPosition(QMouseEvent* event) | |
359 | + { | |
360 | + clicked_position_ = event->pos(); | |
361 | + } | |
359 | 362 | |
360 | 363 | |
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); | |
365 | 368 | |
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); | |
370 | 375 | } |
371 | - widget_->setZoomRatio(zoom); | |
372 | - } | |
373 | 376 | |
374 | 377 | |
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; | |
383 | 390 | } |
384 | - last_timestamp_ = timestamp; | |
385 | - | |
386 | - return true; | |
387 | - } | |
388 | 391 | }; |
389 | 392 | |
390 | 393 | |
391 | 394 | UrgDrawWidget::UrgDrawWidget(QWidget* parent) |
392 | - : QGLWidget(parent), pimpl(new pImpl(this)) | |
395 | + : QGLWidget(parent), pimpl(new pImpl(this)) | |
393 | 396 | { |
394 | - pimpl->initializeForm(); | |
397 | + pimpl->initializeForm(); | |
395 | 398 | } |
396 | 399 | |
397 | 400 |
@@ -402,53 +405,53 @@ | ||
402 | 405 | |
403 | 406 | void UrgDrawWidget::clear(void) |
404 | 407 | { |
405 | - pimpl->draw_data_.clear(); | |
406 | - //redraw(); | |
408 | + pimpl->draw_data_.clear(); | |
409 | + //redraw(); | |
407 | 410 | } |
408 | 411 | |
409 | 412 | |
410 | 413 | void UrgDrawWidget::initializeView(void) |
411 | 414 | { |
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(); | |
415 | 418 | } |
416 | 419 | |
417 | 420 | |
418 | 421 | void UrgDrawWidget::redraw(void) |
419 | 422 | { |
420 | - pimpl->last_redraw_ = ticks(); | |
421 | - updateGL(); | |
423 | + pimpl->last_redraw_ = ticks(); | |
424 | + updateGL(); | |
422 | 425 | } |
423 | 426 | |
424 | 427 | |
425 | 428 | bool UrgDrawWidget::setUrgData(qrk::RangeSensor* sensor) |
426 | 429 | { |
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; | |
431 | 434 | |
432 | - RangeCaptureMode capture_mode = sensor->captureMode(); | |
435 | + RangeCaptureMode capture_mode = sensor->captureMode(); | |
433 | 436 | |
434 | - int n = 0; | |
435 | - if (capture_mode != IntensityCapture) { | |
436 | - n = sensor->capture(data, ×tamp); | |
437 | - } else { | |
438 | - n = sensor->captureWithIntensity(data, intensity_data, ×tamp); | |
439 | - } | |
440 | - if (n <= 0) { | |
441 | - return false; | |
442 | - } | |
437 | + int n = 0; | |
438 | + if (capture_mode != IntensityCapture) { | |
439 | + n = sensor->capture(data, ×tamp); | |
440 | + } else { | |
441 | + n = sensor->captureWithIntensity(data, intensity_data, ×tamp); | |
442 | + } | |
443 | + if (n <= 0) { | |
444 | + return false; | |
445 | + } | |
443 | 446 | |
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 | + } | |
450 | 453 | |
451 | - return pimpl->storeUrgData(timestamp, point_data, &intensity_point_data); | |
454 | + return pimpl->storeUrgData(timestamp, point_data, &intensity_point_data); | |
452 | 455 | } |
453 | 456 | |
454 | 457 |
@@ -455,10 +458,10 @@ | ||
455 | 458 | bool UrgDrawWidget::setUrgData(std::vector<long>& data, |
456 | 459 | const RangeSensor* sensor, long timestamp) |
457 | 460 | { |
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_); | |
460 | 463 | |
461 | - return pimpl->storeUrgData(timestamp, point_data, NULL); | |
464 | + return pimpl->storeUrgData(timestamp, point_data, NULL); | |
462 | 465 | } |
463 | 466 | |
464 | 467 |
@@ -465,7 +468,7 @@ | ||
465 | 468 | bool UrgDrawWidget::setUrgData(std::vector<qrk::Point<long> >& data, |
466 | 469 | long timestamp) |
467 | 470 | { |
468 | - return pimpl->storeUrgData(timestamp, data, NULL); | |
471 | + return pimpl->storeUrgData(timestamp, data, NULL); | |
469 | 472 | } |
470 | 473 | |
471 | 474 |
@@ -473,13 +476,13 @@ | ||
473 | 476 | const qrk::RangeSensor* sensor, |
474 | 477 | long timestamp) |
475 | 478 | { |
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()); | |
479 | 482 | |
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; | |
483 | 486 | } |
484 | 487 | |
485 | 488 |
@@ -486,140 +489,141 @@ | ||
486 | 489 | bool UrgDrawWidget::setUrgIntensityData(vector<qrk::Point<long> >& data, |
487 | 490 | long timestamp) |
488 | 491 | { |
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; | |
492 | 495 | } |
493 | 496 | |
494 | 497 | |
495 | 498 | void UrgDrawWidget::setDrawColor(const qrk::Color& line_color) |
496 | 499 | { |
497 | - pimpl->line_color_ = line_color; | |
500 | + pimpl->line_color_ = line_color; | |
498 | 501 | } |
499 | 502 | |
500 | 503 | |
501 | 504 | void UrgDrawWidget::setDrawMode(DrawMode mode) |
502 | 505 | { |
503 | - pimpl->draw_mode_ = mode; | |
506 | + pimpl->draw_mode_ = mode; | |
504 | 507 | } |
505 | 508 | |
506 | 509 | |
507 | 510 | void UrgDrawWidget::setDrawPeriod(size_t msec) |
508 | 511 | { |
509 | - pimpl->draw_period_ = msec; | |
512 | + pimpl->draw_period_ = msec; | |
510 | 513 | } |
511 | 514 | |
512 | 515 | |
513 | 516 | void UrgDrawWidget::setZoomRatio(double pixel_per_mm) |
514 | 517 | { |
515 | - pimpl->pixel_per_mm_ = pixel_per_mm; | |
516 | - redraw(); | |
518 | + pimpl->pixel_per_mm_ = pixel_per_mm; | |
519 | + redraw(); | |
517 | 520 | } |
518 | 521 | |
519 | 522 | |
520 | 523 | double UrgDrawWidget::zoomRatio(void) |
521 | 524 | { |
522 | - return pimpl->pixel_per_mm_; | |
525 | + return pimpl->pixel_per_mm_; | |
523 | 526 | } |
524 | 527 | |
525 | 528 | |
526 | 529 | void UrgDrawWidget::updateZoomRatio(int steps) |
527 | 530 | { |
528 | - pimpl->updateZoomRatio(steps); | |
531 | + pimpl->updateZoomRatio(steps); | |
529 | 532 | } |
530 | 533 | |
531 | 534 | |
532 | 535 | void UrgDrawWidget::setViewCenter(const Point<long>& point) |
533 | 536 | { |
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; | |
536 | 539 | } |
537 | 540 | |
538 | 541 | |
539 | 542 | Point<long> UrgDrawWidget::viewCenter(void) |
540 | 543 | { |
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)); | |
543 | 546 | } |
544 | 547 | |
545 | 548 | |
546 | 549 | void UrgDrawWidget::initializeGL(void) |
547 | 550 | { |
548 | - pimpl->initializeGL(); | |
551 | + pimpl->initializeGL(); | |
549 | 552 | } |
550 | 553 | |
551 | 554 | |
552 | 555 | void UrgDrawWidget::resizeGL(int width, int height) |
553 | 556 | { |
554 | - pimpl->resizeGL(width, height); | |
557 | + pimpl->resizeGL(width, height); | |
555 | 558 | } |
556 | 559 | |
557 | 560 | |
558 | 561 | void UrgDrawWidget::paintGL(void) |
559 | 562 | { |
560 | - pimpl->paintGL(); | |
563 | + pimpl->paintGL(); | |
561 | 564 | } |
562 | 565 | |
563 | 566 | |
564 | 567 | void UrgDrawWidget::mousePressEvent(QMouseEvent* event) |
565 | 568 | { |
566 | - pimpl->now_pressed_ = true; | |
567 | - pimpl->setClickedPosition(event); | |
569 | + pimpl->now_pressed_ = true; | |
570 | + pimpl->setClickedPosition(event); | |
568 | 571 | } |
569 | 572 | |
570 | 573 | |
571 | 574 | void UrgDrawWidget::mouseMoveEvent(QMouseEvent* event) |
572 | 575 | { |
573 | - int x = event->x(); | |
574 | - int y = event->y(); | |
576 | + int x = event->x(); | |
577 | + int y = event->y(); | |
575 | 578 | |
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(); | |
579 | 582 | |
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_; | |
582 | 585 | |
583 | - pimpl->setClickedPosition(event); | |
586 | + pimpl->setClickedPosition(event); | |
584 | 587 | |
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 | + } | |
589 | 594 | } |
590 | - } | |
591 | 595 | |
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 | + } | |
598 | 602 | |
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); | |
606 | 610 | } |
607 | 611 | |
608 | 612 | |
609 | 613 | void UrgDrawWidget::mouseReleaseEvent(QMouseEvent* event) |
610 | 614 | { |
611 | - static_cast<void>(event); | |
615 | + static_cast<void>(event); | |
612 | 616 | |
613 | - pimpl->now_pressed_ = false; | |
614 | - redraw(); | |
617 | + pimpl->now_pressed_ = false; | |
618 | + redraw(); | |
615 | 619 | } |
616 | 620 | |
617 | 621 | |
618 | 622 | void UrgDrawWidget::wheelEvent(QWheelEvent* event) { |
619 | 623 | |
620 | - int degrees = event->delta() / 8; | |
621 | - int steps = degrees / 15; | |
624 | + int degrees = event->delta() / 8; | |
625 | + int steps = degrees / 15; | |
622 | 626 | |
623 | - event->accept(); | |
624 | - updateZoomRatio(steps); | |
627 | + event->accept(); | |
628 | + updateZoomRatio(steps); | |
625 | 629 | } |
@@ -18,7 +18,7 @@ | ||
18 | 18 | |
19 | 19 | namespace qrk |
20 | 20 | { |
21 | - class RangeSensor; | |
21 | + class RangeSensor; | |
22 | 22 | } |
23 | 23 | |
24 | 24 |
@@ -27,65 +27,65 @@ | ||
27 | 27 | */ |
28 | 28 | class UrgDrawWidget : public QGLWidget |
29 | 29 | { |
30 | - Q_OBJECT; | |
30 | + Q_OBJECT; | |
31 | 31 | |
32 | 32 | public: |
33 | - typedef enum { | |
34 | - Points, | |
35 | - Lines, | |
36 | - Polygon, | |
37 | - } DrawMode; | |
33 | + typedef enum { | |
34 | + Points, | |
35 | + Lines, | |
36 | + Polygon, | |
37 | + } DrawMode; | |
38 | 38 | |
39 | 39 | |
40 | - UrgDrawWidget(QWidget* parent = 0); | |
41 | - ~UrgDrawWidget(void); | |
40 | + UrgDrawWidget(QWidget* parent = 0); | |
41 | + ~UrgDrawWidget(void); | |
42 | 42 | |
43 | - void clear(void); | |
44 | - void initializeView(void); | |
43 | + void clear(void); | |
44 | + void initializeView(void); | |
45 | 45 | |
46 | - void redraw(void); | |
46 | + void redraw(void); | |
47 | 47 | |
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); | |
52 | 52 | |
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); | |
57 | 57 | |
58 | - void setDrawColor(const qrk::Color& line_color); | |
58 | + void setDrawColor(const qrk::Color& line_color); | |
59 | 59 | |
60 | - void setDrawMode(DrawMode mode); | |
60 | + void setDrawMode(DrawMode mode); | |
61 | 61 | |
62 | - void setDrawPeriod(size_t msec); | |
62 | + void setDrawPeriod(size_t msec); | |
63 | 63 | |
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); | |
67 | 67 | |
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); | |
70 | 70 | |
71 | 71 | signals: |
72 | - void position(bool active, long x_mm, long y_mm); | |
72 | + void position(bool active, long x_mm, long y_mm); | |
73 | 73 | |
74 | 74 | 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); | |
82 | 82 | |
83 | 83 | private: |
84 | - UrgDrawWidget(const UrgDrawWidget& rhs); | |
85 | - UrgDrawWidget& operator = (const UrgDrawWidget& rhs); | |
84 | + UrgDrawWidget(const UrgDrawWidget& rhs); | |
85 | + UrgDrawWidget& operator = (const UrgDrawWidget& rhs); | |
86 | 86 | |
87 | - struct pImpl; | |
88 | - std::auto_ptr<pImpl> pimpl; | |
87 | + struct pImpl; | |
88 | + std::auto_ptr<pImpl> pimpl; | |
89 | 89 | }; |
90 | 90 | |
91 | 91 | #endif /* !QRK_URG_DRAW_WIDGET_H */ |
@@ -21,6 +21,7 @@ | ||
21 | 21 | #include "ColorSurface.h" |
22 | 22 | #include "FillSurface.h" |
23 | 23 | #include "ImageSurface.h" |
24 | +#include "CanvasSurface.h" | |
24 | 25 | #include "MultiSurface.h" |
25 | 26 | #include "Label.h" |
26 | 27 | #include "Button.h" |
@@ -156,6 +157,22 @@ | ||
156 | 157 | .def("setAlpha", &ImageSurface::setAlpha) |
157 | 158 | .def("draw", &ImageSurface::draw), |
158 | 159 | |
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 | + | |
159 | 176 | class_<MultiSurface, Surface>("MultiSurface") |
160 | 177 | .def(constructor<Surface&>()) |
161 | 178 | .def("rect", &MultiSurface::rect) |
@@ -87,9 +87,10 @@ | ||
87 | 87 | luabindGui.o: ../common/Color.h ../gui/TextSurface.h ../gui/Surface.h |
88 | 88 | luabindGui.o: ../gui/TextFadeSurface.h ../gui/TextRubiFadeSurface.h |
89 | 89 | 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 | |
93 | 94 | luabindInit.o: luabindInit.h LuaHandler.h ../system/log_printf.h |
94 | 95 | luabindInput.o: luabindInput.h ../input/convertToRoman.h |
95 | 96 | luabindInput.o: ../input/convertToJp.h ../input/Utf8.h ../input/utf8_string.h |
@@ -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 | -} |
@@ -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 */ |
@@ -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 | +} |
@@ -40,6 +40,7 @@ | ||
40 | 40 | $(GUI_LIB)(SwitchSurface.o) \ |
41 | 41 | $(GUI_LIB)(MultiSurface.o) \ |
42 | 42 | $(GUI_LIB)(ImageSurface.o) \ |
43 | + $(GUI_LIB)(CanvasSurface.o) \ | |
43 | 44 | $(GUI_LIB)(Font.o) \ |
44 | 45 | $(GUI_LIB)(Label.o) \ |
45 | 46 | $(GUI_LIB)(Button.o) \ |
@@ -46,7 +47,6 @@ | ||
46 | 47 | $(GUI_LIB)(Menu.o) \ |
47 | 48 | $(GUI_LIB)(ChatMessage.o) \ |
48 | 49 | $(GUI_LIB)(AlignUtils.o) \ |
49 | - $(GUI_LIB)(Canvas.o) \ | |
50 | 50 | $(GUI_LIB)(CheckBox.o) \ |
51 | 51 | |
52 | 52 | # DO NOT DELETE |
@@ -53,7 +53,8 @@ | ||
53 | 53 | |
54 | 54 | Button.o: Component.h ../geometry/Rect.h ../geometry/Point.h |
55 | 55 | 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 | |
57 | 58 | ChatMessage.o: Component.h ../geometry/Rect.h ../geometry/Point.h |
58 | 59 | CheckBox.o: Component.h ../geometry/Rect.h ../geometry/Point.h |
59 | 60 | ColorSurface.o: Surface.h ../geometry/Rect.h |
@@ -83,8 +84,8 @@ | ||
83 | 84 | Button.o: LayerInterface.h ../geometry/RectUtils.h |
84 | 85 | CallbackEvent.o: CallbackEvent.h Event.h ../geometry/Point.h |
85 | 86 | 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 | |
88 | 89 | ChatMessage.o: ChatMessage.h Component.h ../geometry/Rect.h |
89 | 90 | ChatMessage.o: ../geometry/Point.h Font.h ../common/Color.h TextSurface.h |
90 | 91 | ChatMessage.o: Surface.h ../system/StopWatch.h |
@@ -9,7 +9,7 @@ | ||
9 | 9 | */ |
10 | 10 | |
11 | 11 | #include "Screen.h" |
12 | -#include "Canvas.h" | |
12 | +#include "CanvasSurface.h" | |
13 | 13 | #include "Label.h" |
14 | 14 | |
15 | 15 | using namespace qrk; |
@@ -24,7 +24,7 @@ | ||
24 | 24 | Screen screen; |
25 | 25 | screen.show(SDL_OPENGL); |
26 | 26 | |
27 | - Canvas canvas(Rect<long>(0, 0, 100, 100)); | |
27 | + CanvasSurface canvas(Rect<long>(0, 0, 100, 100)); | |
28 | 28 | |
29 | 29 | screen.clear(); |
30 | 30 | Rect<long> dest_rect = canvas.rect(); |
@@ -46,11 +46,17 @@ | ||
46 | 46 | points.push_back(Point<long>(100, 100)); |
47 | 47 | canvas.drawLineStrip(points); |
48 | 48 | |
49 | - canvas.setLineWidth(4.0); | |
50 | 49 | 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); | |
54 | 60 | |
55 | 61 | canvas.draw(NULL, &dest_rect); |
56 | 62 |
@@ -55,9 +55,9 @@ | ||
55 | 55 | buttonSample.o: ../LayerInterface.h ../Layer.h ../Font.h ../../common/Color.h |
56 | 56 | buttonSample.o: ../TextSurface.h ../Surface.h ../CallbackEvent.h ../Event.h |
57 | 57 | 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 | |
61 | 61 | chatMessageSample.o: ../ChatMessage.h ../Component.h ../../geometry/Rect.h |
62 | 62 | chatMessageSample.o: ../../geometry/Point.h ../Screen.h ../LayerManager.h |
63 | 63 | chatMessageSample.o: ../LayerInterface.h ../Layer.h ../Font.h |
@@ -64,6 +64,8 @@ | ||
64 | 64 | chatMessageSample.o: ../../common/Color.h ../ColorSurface.h ../Surface.h |
65 | 65 | chatMessageSample.o: ../Label.h ../CallbackEvent.h ../Event.h ../EventUtils.h |
66 | 66 | chatMessageSample.o: ../../system/delay.h |
67 | +checkBoxSample.o: ../Screen.h ../../geometry/Rect.h ../CheckBox.h | |
68 | +checkBoxSample.o: ../Component.h ../../geometry/Point.h | |
67 | 69 | drawColorSurface.o: ../Screen.h ../../geometry/Rect.h ../ColorSurface.h |
68 | 70 | drawColorSurface.o: ../Surface.h ../ImageSurface.h ../../common/Color.h |
69 | 71 | drawText.o: ../Screen.h ../../geometry/Rect.h ../Font.h ../../common/Color.h |
@@ -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 */ |