• R/O
  • SSH
  • HTTPS

qrobosdk: コミット


コミットメタ情報

リビジョン1942 (tree)
日時2011-01-31 07:41:36
作者satofumi

ログメッセージ

adjusted Menu Component class

変更サマリ

差分

--- trunk/libs/lua/luabindGui.cpp (revision 1941)
+++ trunk/libs/lua/luabindGui.cpp (revision 1942)
@@ -203,7 +203,12 @@
203203 value("Middle", Menu::Middle),
204204 value("Bottom", Menu::Bottom)
205205 ]
206- .def(constructor<const Rect<long>&, Menu::Align>())
206+ .enum_("Axis")
207+ [
208+ value("Verbatim", Menu::Verbatim),
209+ value("Horizontal", Menu::Horizontal)
210+ ]
211+ .def(constructor<const Rect<long>&, int, Menu::Axis>())
207212 .def("setEventAcceptable", &Menu::setEventAcceptable)
208213 .def("setAlpha", &Menu::setAlpha)
209214 .def("alpha", &Menu::alpha)
--- trunk/libs/gui/Menu.h (revision 1941)
+++ trunk/libs/gui/Menu.h (revision 1942)
@@ -39,7 +39,19 @@
3939 Bottom = 0x40,
4040 } Align;
4141
42- Menu(const Rect<long>& rect, Align align = Left);
42+
43+ typedef enum {
44+ Verbatim,
45+ Horizontal,
46+ } Axis;
47+
48+
49+ /*!
50+ \brief コンストラクタ
51+
52+ \bug Middle と Center を同時に指定したときの位置がおかしい。
53+ */
54+ Menu(const Rect<long>& rect, int align = Left, Axis axis = Verbatim);
4355 ~Menu(void);
4456
4557 Rect<long> rect(void) const;
--- trunk/libs/gui/Menu.cpp (revision 1941)
+++ trunk/libs/gui/Menu.cpp (revision 1942)
@@ -34,7 +34,8 @@
3434 LayerManager layer_manager_;
3535 Items items_;
3636 Rect<long> rect_;
37- Align align_;
37+ Rect<long> draw_rect_;
38+ int align_;
3839 float alpha_;
3940 ButtonOrder button_order_;
4041 set<size_t> disabled_buttons_;
@@ -64,7 +65,7 @@
6465 Point<long> icon_offset_;
6566
6667
67- pImpl(const Rect<long>& rect, Align align)
68+ pImpl(const Rect<long>& rect, int align, Axis axis)
6869 : rect_(rect), align_(align), alpha_(1.0), default_index_(InvalidIndex),
6970 clicked_index_(default_index_), previous_index_(default_index_),
7071 index_(default_index_), decided_press_index_(InvalidIndex),
@@ -73,7 +74,7 @@
7374 enable_no_select_(false), enable_rotate_(false),
7475 event_acceptable_(true), icon_label_(NULL), icon_draw_front_(true)
7576 {
76- setAilgnBase(align);
77+ setAlignBase(align);
7778
7879 // リターンキーで決定
7980 decide_press_event_.setEventAcceptable(false);
@@ -81,8 +82,13 @@
8182 decide_release_event_.key(SDLK_RETURN, SDL_KEYUP, KMOD_NONE);
8283
8384 // カーソルキーで選択項目の移動
84- up_event_.key(SDLK_UP, SDL_KEYDOWN, KMOD_NONE);
85- down_event_.key(SDLK_DOWN, SDL_KEYDOWN, KMOD_NONE);
85+ if (axis == Verbatim) {
86+ up_event_.key(SDLK_UP, SDL_KEYDOWN, KMOD_NONE);
87+ down_event_.key(SDLK_DOWN, SDL_KEYDOWN, KMOD_NONE);
88+ } else {
89+ up_event_.key(SDLK_LEFT, SDL_KEYDOWN, KMOD_NONE);
90+ down_event_.key(SDLK_RIGHT, SDL_KEYDOWN, KMOD_NONE);
91+ }
8692
8793 layer_manager_.insertEvent(&decide_press_event_);
8894 layer_manager_.insertEvent(&decide_release_event_);
@@ -102,30 +108,30 @@
102108 }
103109
104110
105- void setAilgnBase(Align align)
111+ void setAlignBase(int align)
106112 {
107- switch (align) {
108- case Left:
109- case Top:
113+ base_point_.x = 0;
114+ base_point_.y = 0;
115+
116+ if ((align & Left) || (align & Top)) {
110117 // base_point_ は (0, 0) のまま
111- break;
112118
113- case Center:
114- base_point_ = Point<long>(rect_.w / 2, 0);
115- break;
119+ }
120+ if (align & Center) {
121+ base_point_ += Point<long>(rect_.w / 2, 0);
116122
117- case Right:
118- base_point_ = Point<long>(rect_.w - 1, 0);
119- break;
123+ }
124+ if (align & Right) {
125+ base_point_ += Point<long>(rect_.w - 1, 0);
120126
121- case Middle:
122- base_point_ = Point<long>(0, rect_.h / 2);
123- break;
127+ }
128+ if (align & Middle) {
129+ base_point_ += Point<long>(0, rect_.h / 2);
124130
125- case Bottom:
126- base_point_ = Point<long>(0, rect_.h - 1);
127- break;
128131 }
132+ if (align & Bottom) {
133+ base_point_ += Point<long>(0, rect_.h - 1);
134+ }
129135 }
130136
131137
@@ -200,27 +206,24 @@
200206 {
201207 Point<long> offset;
202208
203- switch (align_) {
204- case Left:
205- case Top:
209+ if (align_ & Left) {
206210 // そのままの位置を用いる
207- break;
208211
209- case Center:
212+ } else if (align_ & Center) {
210213 offset.x = center(*component, 0);
211- break;
212214
213- case Right:
215+ } else if (align_ & Right) {
214216 offset.x = right(*component, 0);
215- break;
217+ }
216218
217- case Middle:
219+ if (align_ & Top) {
220+ // そのままの位置を用いる
221+
222+ } else if (align_ & Middle) {
218223 offset.y = middle(*component, 0);
219- break;
220224
221- case Bottom:
225+ } else if (align_ & Bottom) {
222226 offset.y = bottom(*component, 0);
223- break;
224227 }
225228 return offset;
226229 }
@@ -230,18 +233,12 @@
230233 {
231234 // step が指定されたことがなければ align に応じてステップを更新する
232235 if (! step_specified_) {
233- switch (align_) {
234- case Left:
235- case Center:
236- case Right:
236+ if ((align_ & Left) || (align_ & Center) || (align_ & Right)) {
237237 step_.y = max(button->rect().h, step_.y);
238- break;
239238
240- case Top:
241- case Middle:
242- case Bottom:
239+ } else if ((align_ & Top) || (align_ & Middle) ||
240+ (align_ & Bottom)) {
243241 step_.x = max(button->rect().w, step_.x);
244- break;
245242 }
246243 }
247244 items_[id] = button;
@@ -525,8 +522,8 @@
525522 };
526523
527524
528-Menu::Menu(const Rect<long>& rect, Align align)
529- : pimpl(new pImpl(rect, align))
525+Menu::Menu(const Rect<long>& rect, int align, Axis axis)
526+ : pimpl(new pImpl(rect, align, axis))
530527 {
531528 }
532529
Cannot display: file marked as a binary type.
svn:mime-type = application/octet-stream
--- trunk/libs/gui/samples/horizontalMenu.cpp (nonexistent)
+++ trunk/libs/gui/samples/horizontalMenu.cpp (revision 1942)
@@ -0,0 +1,118 @@
1+/*!
2+ \example horizontalMenu.cpp 水平方向のメニューサンプル
3+
4+ \author Satofumi KAMIMURA
5+
6+ $Id$
7+*/
8+
9+#include "Menu.h"
10+#include "Screen.h"
11+#include "LayerManager.h"
12+#include "Layer.h"
13+#include "Font.h"
14+#include "TextSurface.h"
15+#include "Button.h"
16+#include "CallbackEvent.h"
17+#include "EventUtils.h"
18+#include "delay.h"
19+#include <iostream>
20+
21+using namespace qrk;
22+using namespace std;
23+
24+
25+int main(int argc, char *argv[])
26+{
27+ string font_file = "font.ttf";
28+ if (argc >= 2) {
29+ font_file = argv[1];
30+ }
31+
32+ Screen screen;
33+ screen.show(SDL_OPENGL);
34+
35+ LayerManager layer_manager;
36+ Layer layer;
37+ layer_manager.push_back(&layer);
38+
39+ // フォントの初期化
40+ enum {
41+ FontSize = 40,
42+ };
43+ Font font(font_file.c_str(), FontSize, false);
44+ Font focused_font = font;
45+ focused_font.setBackgroundColor(Color(0.5f, 0.5f, 1.0f));
46+ Font clicked_font = focused_font;
47+ clicked_font.setForegroundColor(Color(0.0f, 0.0f, 0.0f));
48+
49+ // メニューの作成
50+ Menu menu(Rect<long>(0, 0, 640, 480), Menu::Middle, Menu::Horizontal);
51+ Point<long> buttons_step(200, 0);
52+ menu.setButtonStep(buttons_step);
53+
54+ // ボタンの作成と登録
55+ vector<TextSurface*> text_surfaces;
56+ vector<Button*> buttons;
57+ const char* buttons_text[] = {
58+ " Alpha ", " Beta ", " Gamma ",
59+ };
60+ size_t n = sizeof(buttons_text) / sizeof(buttons_text[0]);
61+ for (size_t i = 0; i < n; ++i) {
62+ const char* text = buttons_text[i];
63+ TextSurface* surface = new TextSurface(font, text);
64+ TextSurface* focused_surface = new TextSurface(focused_font, text);
65+ TextSurface* clicked_surface = new TextSurface(clicked_font, text);
66+ Button* button =
67+ new Button(*surface, *focused_surface, *clicked_surface);
68+
69+
70+ menu.addButton(*button, i);
71+
72+ text_surfaces.push_back(clicked_surface);
73+ text_surfaces.push_back(focused_surface);
74+ text_surfaces.push_back(surface);
75+ buttons.push_back(button);
76+ }
77+
78+ layer.push_front(&menu);
79+
80+ CallbackEvent quit_event;
81+ setQuitEvent(&quit_event);
82+ layer_manager.insertEvent(&quit_event);
83+
84+ int clicked_count = 0;
85+ while (! quit_event.isActive()) {
86+
87+ layer_manager.updateEvent();
88+
89+ if (menu.isClicked()) {
90+
91+ if (clicked_count == 0) {
92+ cout << "clicked: " << menu.clickedId() << endl;
93+ }
94+ ++clicked_count;
95+ }
96+
97+ if (clicked_count > 100) {
98+ clicked_count = 0;
99+ menu.release();
100+ }
101+
102+ screen.clear();
103+ layer_manager.draw();
104+ layer_manager.swap();
105+ delay(10);
106+ }
107+
108+ for (vector<TextSurface*>::iterator it = text_surfaces.begin();
109+ it != text_surfaces.end(); ++it) {
110+ delete *it;
111+ }
112+ for (vector<Button*>::iterator it = buttons.begin();
113+ it != buttons.end(); ++it) {
114+ delete *it;
115+ }
116+
117+ return 0;
118+}
Added: svn:keywords
## -0,0 +1 ##
+Id
\ No newline at end of property
--- trunk/libs/gui/samples/Makefile (revision 1941)
+++ trunk/libs/gui/samples/Makefile (revision 1942)
@@ -31,6 +31,7 @@
3131 drawColorSurface \
3232 slideSelect \
3333 changeSelect \
34+ horizontalMenu \
3435
3536 all : $(TARGET)
3637
@@ -47,7 +48,7 @@
4748 $(REQUIRE_LIBS) :
4849 cd $(@D)/ && $(MAKE) $(@F)
4950
50-PROGRAMS = drawText handleEvent inputDraw chatMessageSample rectMove buttonSample menuSample drawColorSurface fadeText canvasDraw rubiDraw checkBoxSample
51+PROGRAMS = drawText handleEvent inputDraw chatMessageSample rectMove buttonSample menuSample drawColorSurface fadeText canvasDraw rubiDraw checkBoxSample horizontalMenu
5152 $(PROGRAMS) : $(REQUIRE_LIBS)
5253
5354 # DO NOT DELETE
旧リポジトリブラウザで表示