• R/O
  • SSH
  • HTTPS

qrobosdk: コミット


コミットメタ情報

リビジョン1828 (tree)
日時2010-05-20 06:47:54
作者satofumi

ログメッセージ

add lib/gui/CheckBox.cpp

変更サマリ

差分

--- trunk/libs/gui/Canvas.cpp (revision 1827)
+++ trunk/libs/gui/Canvas.cpp (revision 1828)
@@ -5,47 +5,59 @@
55 \author Satofumi KAMIMURA
66
77 $Id$
8+
9+ \todo setAlpha() を実行する
10+ \todo 適切にクリッピングを行う
811 */
912
13+#define GL_GLEXT_PROTOTYPES
1014 #include "Canvas.h"
11-#define GL_GLEXT_PROTOTYPES
15+#include "Font.h"
1216 #include <SDL_opengl.h>
1317 #include <vector>
18+#include <cassert>
1419
1520 using namespace qrk;
1621 using namespace std;
1722
1823
19-struct Canvas::pImpl
24+namespace
2025 {
21- // !!! 使わない要素は削除する
22- typedef struct {
26+ typedef struct
27+ {
28+ GLuint buffer;
2329 GLenum mode;
24- GLuint start;
25- GLuint end;
26- GLsizei count;
27- GLenum type;
28- } primitive_t;
30+ size_t size;
31+ GLfloat line_width;
32+ } draw_t;
2933
34+ typedef vector<draw_t> Draws;
35+}
3036
37+struct Canvas::pImpl
38+{
3139 Rect<long> rect_;
3240 float alpha_;
3341 Color clear_color_;
3442 Color draw_color_;
35- vector<GLuint> buffers_;
36- vector<primitive_t> primitives_;
43+ GLfloat line_width_;
44+ Font* font_;
45+ vector<draw_t> draws_;
46+ vector<GLubyte> indices_;
47+ GLuint indices_buffer_;
3748
3849
3950 pImpl(const Rect<long>& rect)
4051 : rect_(rect), alpha_(1.0),
4152 clear_color_(Color(0.0, 0.0, 0.0, 1.0)),
42- draw_color_(Color(1.0, 1.0, 1.0, 1.0))
53+ draw_color_(Color(1.0, 1.0, 1.0, 1.0)),
54+ line_width_(1.0f), font_(NULL), indices_buffer_(createBuffer())
4355 {
4456 clearBuffers();
4557 }
4658
4759
48- GLuint addBuffer(void)
60+ GLuint createBuffer(void)
4961 {
5062 GLuint id;
5163 glGenBuffers(1, &id);
@@ -56,53 +68,58 @@
5668
5769 void clearBuffers(void)
5870 {
59- // buffers_ を順に削除する
60- glDeleteBuffers(buffers_.size(), &buffers_[0]);
61- buffers_.clear();
71+ for (Draws::iterator it = draws_.begin(); it != draws_.end(); ++it) {
72+ glDeleteBuffers(1, &it->buffer);
73+ }
74+ draws_.clear();
75+ indices_.clear();
76+ }
6277
63- // 塗りつぶし用の矩形を描画する
64- // !!!
78+
79+ void setColor(vector<GLfloat>& intertwined)
80+ {
81+ intertwined.push_back(draw_color_.r);
82+ intertwined.push_back(draw_color_.g);
83+ intertwined.push_back(draw_color_.b);
6584 }
6685
6786
87+ void expandIndices(size_t n)
88+ {
89+ if (n < indices_.size()) {
90+ return;
91+ }
92+ assert(n <= 255);
93+
94+ for (size_t i = indices_.size(); i < n; ++i) {
95+ indices_.push_back(i);
96+ }
97+ }
98+
6899 void draw(const Rect<long>* src, const Rect<long>* dest)
69100 {
70101 (void)src;
71102 (void)dest;
72103
104+ // !!!
105+
73106 glEnableClientState(GL_VERTEX_ARRAY);
74107
75- GLfloat vertices[2 * 2];
76- vertices[0] = 0.0f;
77- vertices[1] = 0.0f;
78- vertices[2] = 100.0f;
79- vertices[3] = 100.0f;
108+ for (Draws::const_iterator it = draws_.begin();
109+ it != draws_.end(); ++it) {
80110
81- //GLuint id = addBuffer();
82- //glBindBuffer(GL_ARRAY_BUFFER, id);
83- glVertexPointer(2, GL_FLOAT, 0, vertices);
84- GLubyte indices[] = { 0, 1 };
85- glDrawElements(GL_LINES, 2, GL_UNSIGNED_BYTE, indices);
111+ glLineWidth(it->line_width);
112+ glBindBuffer(GL_ARRAY_BUFFER, it->buffer);
86113
87- glDisableClientState(GL_VERTEX_ARRAY);
88-#if 0
89- // !!! 効率が気になるならば foreach, bind を用いる
90- GLubyte indices[] = { 0, 1 };
91- size_t index = 0;
92- for (vector<GLuint>::iterator it = buffers_.begin();
93- it != buffers_.end(); ++it, ++index) {
114+ glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, indices_buffer_);
115+ glBufferData(GL_ELEMENT_ARRAY_BUFFER,
116+ it->size * sizeof(indices_[0]),
117+ &indices_[0], GL_STATIC_DRAW);
94118
95- //glBindBuffer(GL_ARRAY_BUFFER, *it);
96- //glVertexPointer(2, GL_FLOAT, 0, 0);
97- //glDrawElements(GL_LINES, 3 * 3, GL_UNSIGNED_INT, BUFFER_OFFSET(0));
98- //glDrawRangeElement(GL_LINES, 0, 4,
99-
100- glDrawElements(GL_LINES, 2, GL_UNSIGNED_BYTE, &indices);
101- // !!!
119+ glDrawElements(it->mode, it->size, GL_UNSIGNED_BYTE, NULL);
102120 }
103121
104122 glDisableClientState(GL_VERTEX_ARRAY);
105-#endif
106123 }
107124 };
108125
@@ -154,6 +171,12 @@
154171 }
155172
156173
174+void Canvas::setFont(Font& font)
175+{
176+ pimpl->font_ = &font;
177+}
178+
179+
157180 void Canvas::setClearColor(const qrk::Color& color)
158181 {
159182 pimpl->clear_color_ = color;
@@ -174,33 +197,38 @@
174197
175198 void Canvas::setLineWidth(float width)
176199 {
177- (void)width;
178- // !!!
200+ pimpl->line_width_ = width;
179201 }
180202
181203
182-void Canvas::drawLine(const qrk::Point<long>& p0, const qrk::Point<long>& p1)
204+void Canvas::drawLines(const std::vector<qrk::Point<long> >& points)
183205 {
184- (void)p0;
185- (void)p1;
206+ if (points.empty()) {
207+ return;
208+ }
186209
187-#if 0
188- GLfloat vertices[2 * 2];
189- vertices[0] = p0.x;
190- vertices[1] = p0.y;
191- vertices[2] = p1.x;
192- vertices[3] = p1.y;
210+ draw_t draw;
211+ draw.mode = GL_LINE_STRIP;
212+ draw.line_width = pimpl->line_width_;
213+ draw.buffer = pimpl->createBuffer();
214+ draw.size = points.size();
193215
194- GLuint id = pimpl->addBuffer();
195- glBindBuffer(GL_ARRAY_BUFFER, id);
196- glVertexPointer(2, GL_FLOAT, 0, vertices);
197- //glBufferData(GL_ARRAY_BUFFER,
198- //2 * 2 * sizeof(GLfloat), vertices, GL_STATIC_DRAW);
216+ vector<GLfloat> intertwined;
217+ for (vector<Point<long> >::const_iterator it = points.begin();
218+ it != points.end(); ++it) {
219+ pimpl->setColor(intertwined);
220+ intertwined.push_back(it->x);
221+ intertwined.push_back(it->y);
222+ intertwined.push_back(0.0f);
223+ }
224+ pimpl->expandIndices(draw.size);
199225
200- pimpl->buffers_.push_back(id);
201- // !!! GL_LINES
202- //pimpl->primitives_.push_back();
203-#endif
226+ glBindBuffer(GL_ARRAY_BUFFER, draw.buffer);
227+ size_t array_size = intertwined.size() * sizeof(intertwined[0]);
228+ glBufferData(GL_ARRAY_BUFFER, array_size, &intertwined[0], GL_STATIC_DRAW);
229+ glInterleavedArrays(GL_C3F_V3F, 0, NULL);
230+
231+ pimpl->draws_.push_back(draw);
204232 }
205233
206234
@@ -212,16 +240,18 @@
212240 }
213241
214242
215-void Canvas::drawQuads(const qrk::Point<long>& p0,
216- const qrk::Point<long>& p1,
217- const qrk::Point<long>& p2,
218- const qrk::Point<long>& p3)
243+void Canvas::drawPolygons(const std::vector<qrk::Point<long> >& points)
219244 {
220- (void)p0;
221- (void)p1;
222- (void)p2;
223- (void)p3;
245+ (void)points;
224246 // !!!
225247
226248 // !!! GL_QUADS
227249 }
250+
251+
252+void Canvas::drawText(const char* text, const Point<long>& position)
253+{
254+ (void)text;
255+ (void)position;
256+ // !!!
257+}
--- trunk/libs/gui/CheckBox.h (nonexistent)
+++ trunk/libs/gui/CheckBox.h (revision 1828)
@@ -0,0 +1,48 @@
1+#ifndef QRK_CHECK_BOX_H
2+#define QRK_CHECK_BOX_H
3+
4+/*!
5+ \file
6+ \brief コンボボックス
7+
8+ \author Satofumi KAMIMURA
9+
10+ $Id$
11+*/
12+
13+#include "Component.h"
14+#include <memory>
15+
16+
17+namespace qrk
18+{
19+ class Surface;
20+ class Color;
21+
22+
23+ class CheckBox : public Component
24+ {
25+ public:
26+ explicit CheckBox(const Rect<long>& rect, Surface& text,
27+ Surface& check_image, Surface& no_check_image);
28+ ~CheckBox(void);
29+
30+ Rect<long> rect(void) const;
31+ void setEventAcceptable(bool acceptable);
32+ void setAlpha(float alpha);
33+ float alpha(void);
34+ void setRotateAngle(const Angle& angle);
35+ void draw(const Rect<long>& area);
36+
37+ void setFocusedColor(const Color& color);
38+
39+ private:
40+ CheckBox(const CheckBox& rhs);
41+ CheckBox& operator = (CheckBox& rhs);
42+
43+ struct pImpl;
44+ std::auto_ptr<pImpl> pimpl;
45+ };
46+}
47+
48+#endif /* !QRK_CHECK_BOX_H */
Added: svn:keywords
## -0,0 +1 ##
+Id
\ No newline at end of property
--- trunk/libs/gui/Makefile (revision 1827)
+++ trunk/libs/gui/Makefile (revision 1828)
@@ -47,6 +47,7 @@
4747 $(GUI_LIB)(ChatMessage.o) \
4848 $(GUI_LIB)(AlignUtils.o) \
4949 $(GUI_LIB)(Canvas.o) \
50+ $(GUI_LIB)(CheckBox.o) \
5051
5152 # DO NOT DELETE
5253
@@ -54,6 +55,7 @@
5455 CallbackEvent.o: Event.h ../geometry/Point.h ../geometry/Rect.h
5556 Canvas.o: Surface.h ../geometry/Rect.h ../geometry/Point.h ../common/Color.h
5657 ChatMessage.o: Component.h ../geometry/Rect.h ../geometry/Point.h
58+CheckBox.o: Component.h ../geometry/Rect.h ../geometry/Point.h
5759 ColorSurface.o: Surface.h ../geometry/Rect.h
5860 Component.o: ../geometry/Rect.h ../geometry/Point.h
5961 Event.o: ../geometry/Point.h
@@ -86,6 +88,8 @@
8688 ChatMessage.o: ChatMessage.h Component.h ../geometry/Rect.h
8789 ChatMessage.o: ../geometry/Point.h Font.h ../common/Color.h TextSurface.h
8890 ChatMessage.o: Surface.h ../system/StopWatch.h
91+CheckBox.o: CheckBox.h Component.h ../geometry/Rect.h ../geometry/Point.h
92+CheckBox.o: ../common/Color.h
8993 ColorSurface.o: ColorSurface.h Surface.h ../geometry/Rect.h ../common/Color.h
9094 ColorSurface.o: ../system/log_printf.h ../system/DetectOS.h
9195 EventManager.o: EventManager.h ../geometry/Point.h Event.h
--- trunk/libs/gui/Canvas.h (revision 1827)
+++ trunk/libs/gui/Canvas.h (revision 1828)
@@ -14,11 +14,15 @@
1414 #include "Rect.h"
1515 #include "Point.h"
1616 #include "Color.h"
17+#include <vector>
1718 #include <memory>
1819
1920
2021 namespace qrk
2122 {
23+ class Font;
24+
25+
2226 class Canvas : public Surface
2327 {
2428 public:
@@ -32,17 +36,16 @@
3236 void setRotateAngle(const Angle& angle);
3337 void draw(const Rect<long>* src, const Rect<long>* dest);
3438
39+ void setFont(qrk::Font& font);
3540 void setClearColor(const qrk::Color& color);
3641 void clear(void);
3742 void setColor(const qrk::Color& color);
3843 void setLineWidth(float width);
3944
40- void drawLine(const qrk::Point<long>& p0, const qrk::Point<long>& p1);
45+ void drawLines(const std::vector<qrk::Point<long> >& points);
4146 void drawCircle(const qrk::Point<long>& center, float radius);
42- void drawQuads(const qrk::Point<long>& p0,
43- const qrk::Point<long>& p1,
44- const qrk::Point<long>& p2,
45- const qrk::Point<long>& p3);
47+ void drawPolygons(const std::vector<qrk::Point<long> >& points);
48+ void drawText(const char* text, const Point<long>& position);
4649
4750 private:
4851 Canvas(const Canvas& rhs);
--- trunk/libs/gui/samples/menuSample.cpp (revision 1827)
+++ trunk/libs/gui/samples/menuSample.cpp (revision 1828)
@@ -1,6 +1,5 @@
11 /*!
2- \example menuSample.cpp
3- \brief Menu の動作サンプル
2+ \example menuSample.cpp Menu の動作サンプル
43
54 \author Satofumi KAMIMURA
65
--- trunk/libs/gui/samples/checkBoxSample.cpp (nonexistent)
+++ trunk/libs/gui/samples/checkBoxSample.cpp (revision 1828)
@@ -0,0 +1,26 @@
1+/*!
2+ \example checkBoxSample.cpp チェックボックスの動作サンプル
3+
4+ \author Satofumi KAMIMURA
5+
6+ $Id$
7+*/
8+
9+#include "Screen.h"
10+#include "CheckBox.h"
11+
12+using namespace qrk;
13+
14+
15+int main(int argc, char *argv[])
16+{
17+ (void)argc;
18+ (void)argv;
19+
20+ Screen screen;
21+ screen.show(Screen::OpenGL);
22+
23+ // !!!
24+
25+ return 0;
26+}
Added: svn:keywords
## -0,0 +1 ##
+Id
\ No newline at end of property
--- trunk/libs/gui/samples/canvasDraw.cpp (revision 1827)
+++ trunk/libs/gui/samples/canvasDraw.cpp (revision 1828)
@@ -13,6 +13,7 @@
1313 #include "Label.h"
1414
1515 using namespace qrk;
16+using namespace std;
1617
1718
1819 int main(int argc, char *argv[])
@@ -28,8 +29,16 @@
2829 screen.clear();
2930 Rect<long> dest_rect = canvas.rect();
3031
31- canvas.drawLine(Point<long>(0, 0), Point<long>(100, 100));
32+ canvas.setColor(Color(0.0, 0.0, 1.0));
33+ canvas.setLineWidth(4.0);
3234
35+ vector<Point<long> > points;
36+ points.push_back(Point<long>(0, 1));
37+ points.push_back(Point<long>(50, 1));
38+ points.push_back(Point<long>(50, 100));
39+ points.push_back(Point<long>(100, 100));
40+ canvas.drawLines(points);
41+
3342 canvas.draw(NULL, &dest_rect);
3443
3544 SDL_GL_SwapBuffers();
--- trunk/libs/gui/samples/Makefile (revision 1827)
+++ trunk/libs/gui/samples/Makefile (revision 1828)
@@ -12,6 +12,7 @@
1212
1313 # Target
1414 TARGET = \
15+ checkBoxSample \
1516 rubiDraw \
1617 canvasDraw \
1718 fadeText \
@@ -44,7 +45,7 @@
4445 $(REQUIRE_LIBS) :
4546 cd $(@D)/ && $(MAKE) $(@F)
4647
47-PROGRAMS = drawText handleEvent inputDraw chatMessageSample rectMove buttonSample menuSample drawColorSurface fadeText canvasDraw rubiDraw
48+PROGRAMS = drawText handleEvent inputDraw chatMessageSample rectMove buttonSample menuSample drawColorSurface fadeText canvasDraw rubiDraw checkBoxSample
4849 $(PROGRAMS) : $(REQUIRE_LIBS)
4950
5051 # DO NOT DELETE
--- trunk/libs/gui/CheckBox.cpp (nonexistent)
+++ trunk/libs/gui/CheckBox.cpp (revision 1828)
@@ -0,0 +1,90 @@
1+/*!
2+ \file
3+ \brief コンボボックス
4+
5+ \author Satofumi KAMIMURA
6+
7+ $Id$
8+*/
9+
10+#include "CheckBox.h"
11+#include "Color.h"
12+
13+using namespace qrk;
14+
15+
16+struct CheckBox::pImpl
17+{
18+ Rect<long> rect_;
19+ Surface& text_;
20+ Surface& check_image_;
21+ Surface& no_check_image_;
22+ Color focused_color_;
23+ float alpha_;
24+
25+
26+ pImpl(const Rect<long>& rect, Surface& text,
27+ Surface& check_image, Surface& no_check_image)
28+ : rect_(rect), text_(text), check_image_(check_image),
29+ no_check_image_(no_check_image),
30+ focused_color_(Color(0.0, 0.0, 0.0, 0.0)), alpha_(1.0f)
31+ {
32+ }
33+};
34+
35+
36+CheckBox::CheckBox(const Rect<long>& rect, Surface& text,
37+ Surface& check_image, Surface& no_check_image)
38+ : pimpl(new pImpl(rect, text, check_image, no_check_image))
39+{
40+}
41+
42+
43+CheckBox::~CheckBox(void)
44+{
45+}
46+
47+
48+Rect<long> CheckBox::rect(void) const
49+{
50+ return pimpl->rect_;
51+}
52+
53+
54+void CheckBox::setEventAcceptable(bool acceptable)
55+{
56+ (void)acceptable;
57+ // !!!
58+}
59+
60+
61+void CheckBox::setAlpha(float alpha)
62+{
63+ pimpl->alpha_ = alpha;
64+}
65+
66+
67+float CheckBox::alpha(void)
68+{
69+ return pimpl->alpha_;
70+}
71+
72+
73+void CheckBox::setRotateAngle(const Angle& angle)
74+{
75+ (void)angle;
76+ // !!!
77+}
78+
79+
80+void CheckBox::draw(const Rect<long>& area)
81+{
82+ (void)area;
83+ // !!!
84+}
85+
86+
87+void CheckBox::setFocusedColor(const Color& color)
88+{
89+ pimpl->focused_color_ = color;
90+}
Added: svn:keywords
## -0,0 +1 ##
+Id
\ No newline at end of property
旧リポジトリブラウザで表示