• R/O
  • SSH
  • HTTPS

qrobosdk: コミット


コミットメタ情報

リビジョン1814 (tree)
日時2010-05-03 16:57:38
作者satofumi

ログメッセージ

adjusted indente

変更サマリ

差分

--- trunk/libs/lua/luabindGui.cpp (revision 1813)
+++ trunk/libs/lua/luabindGui.cpp (revision 1814)
@@ -48,6 +48,9 @@
4848 .def("setClearColor", &Screen::setClearColor)
4949 .def("clear", &Screen::clear),
5050
51+ def("Screen_enter2D", &Screen::enter2D),
52+ def("Screen_leave2D", &Screen::leave2D),
53+
5154 class_<Event>("Event"),
5255
5356 class_<CallbackEvent, Event>("CallbackEvent")
--- trunk/libs/gui/LayerManager.cpp (revision 1813)
+++ trunk/libs/gui/LayerManager.cpp (revision 1814)
@@ -163,13 +163,21 @@
163163
164164 void LayerManager::push_front(LayerInterface* layer)
165165 {
166- pimpl->layers_.push_back(layer);
166+ const Layers::iterator it =
167+ find(pimpl->layers_.begin(), pimpl->layers_.end(), layer);
168+ if (it == pimpl->layers_.end()) {
169+ pimpl->layers_.push_back(layer);
170+ }
167171 }
168172
169173
170174 void LayerManager::push_back(LayerInterface* layer)
171175 {
172- pimpl->layers_.push_front(layer);
176+ const Layers::iterator it =
177+ find(pimpl->layers_.begin(), pimpl->layers_.end(), layer);
178+ if (it == pimpl->layers_.end()) {
179+ pimpl->layers_.push_front(layer);
180+ }
173181 }
174182
175183
--- trunk/libs/gui/TextFadeSurface.cpp (revision 1813)
+++ trunk/libs/gui/TextFadeSurface.cpp (revision 1814)
@@ -78,7 +78,7 @@
7878 it != text_surfaces_.end(); ++it) {
7979 Surface* surface = *it;
8080
81- float alpha = 100.0;
81+ float alpha = 1.0;
8282 if (x > last) {
8383 alpha = 0.0;
8484 } else if (x <= first) {
@@ -121,7 +121,7 @@
121121
122122 void TextFadeSurface::setAlpha(float alpha)
123123 {
124- pimpl->base_alpha_ = min(alpha, 1.0f);
124+ pimpl->base_alpha_ = max(min(alpha, 1.0f), 0.0f);
125125 pimpl->setAlpha();
126126 }
127127
--- trunk/libs/gui/samples/glTextureDraw.cpp (revision 1813)
+++ trunk/libs/gui/samples/glTextureDraw.cpp (revision 1814)
@@ -19,429 +19,433 @@
1919
2020 namespace
2121 {
22- enum {
23- ScreenWidth = 640,
24- ScreenHeight = 480,
25- ScreenBpp = 32,
26- };
22+ enum {
23+ ScreenWidth = 640,
24+ ScreenHeight = 480,
25+ ScreenBpp = 32,
26+ };
2727
2828
29- void set_SdlRect(SDL_Rect* rect, int x, int y, int w, int h)
30- {
31- rect->x = x;
32- rect->y = y;
33- rect->w = w;
34- rect->h = h;
35- }
29+ void set_SdlRect(SDL_Rect* rect, int x, int y, int w, int h)
30+ {
31+ rect->x = x;
32+ rect->y = y;
33+ rect->w = w;
34+ rect->h = h;
35+ }
3636
3737
38- // Quick utility function for texture creation
39- int power_of_two(int input)
40- {
41- int value = 1;
42- while (value < input) {
43- value <<= 1;
38+ // Quick utility function for texture creation
39+ int power_of_two(int input)
40+ {
41+ int value = 1;
42+ while (value < input) {
43+ value <<= 1;
44+ }
45+ return value;
4446 }
45- return value;
46- }
4747
4848
49- // SDL のサーフェスを受け取り、OpenGL のテクスチャーとして描画を行うためのクラス
50- class GL_Texture
51- {
49+ // SDL のサーフェスを受け取り、OpenGL のテクスチャーとして
50+ // 描画を行うためのクラス
51+ class GL_Texture
52+ {
5253
53- public:
54- enum {
55- InvalidTextureId = 0,
56- };
57- GLuint texture_id_;
58- GLfloat basecoord_[4];
59- GLfloat alpha_;
60- size_t base_w_;
61- size_t base_h_;
54+ public:
55+ enum {
56+ InvalidTextureId = 0,
57+ };
58+ GLuint texture_id_;
59+ GLfloat basecoord_[4];
60+ GLfloat alpha_;
61+ size_t base_w_;
62+ size_t base_h_;
6263
63- size_t w;
64- size_t h;
64+ size_t w;
65+ size_t h;
6566
6667
67- GL_Texture(void)
68- : texture_id_(InvalidTextureId), alpha_(1.0), w(0), h(0)
69- {
70- }
68+ GL_Texture(void)
69+ : texture_id_(InvalidTextureId), alpha_(1.0), w(0), h(0)
70+ {
71+ }
7172
7273
73- ~GL_Texture(void)
74- {
75- }
74+ ~GL_Texture(void)
75+ {
76+ }
7677
7778
78- void SDL_GL_LoadTexture(SDL_Surface* surface)
79- {
80- if (surface == NULL) {
81- return;
82- }
83- texture_id_ = InvalidTextureId;
84- base_w_ = surface->w;
85- base_h_ = surface->h;
79+ void SDL_GL_LoadTexture(SDL_Surface* surface)
80+ {
81+ if (surface == NULL) {
82+ return;
83+ }
84+ texture_id_ = InvalidTextureId;
85+ base_w_ = surface->w;
86+ base_h_ = surface->h;
8687
87- // Use the surface width and height expanded to powers of 2
88- int w = power_of_two(surface->w);
89- int h = power_of_two(surface->h);
90- basecoord_[0] = 0.0f; // Min X
91- basecoord_[1] = 0.0f; // Min Y
92- basecoord_[2] = (GLfloat)surface->w / w; // Max X
93- basecoord_[3] = (GLfloat)surface->h / h; // Max Y
88+ // Use the surface width and height expanded to powers of 2
89+ int w = power_of_two(surface->w);
90+ int h = power_of_two(surface->h);
91+ basecoord_[0] = 0.0f; // Min X
92+ basecoord_[1] = 0.0f; // Min Y
93+ basecoord_[2] = (GLfloat)surface->w / w; // Max X
94+ basecoord_[3] = (GLfloat)surface->h / h; // Max Y
9495
95- SDL_Surface* image = SDL_CreateRGBSurface(SDL_SWSURFACE, w, h, 32,
96+ SDL_Surface* image = SDL_CreateRGBSurface(SDL_SWSURFACE, w, h, 32,
9697 #if SDL_BYTEORDER == SDL_LIL_ENDIAN // OpenGL RGBA masks
97- 0x000000FF,
98- 0x0000FF00,
99- 0x00FF0000,
100- 0xFF000000
98+ 0x000000FF,
99+ 0x0000FF00,
100+ 0x00FF0000,
101+ 0xFF000000
101102 #else
102- 0xFF000000,
103- 0x00FF0000,
104- 0x0000FF00,
105- 0x000000FF
103+ 0xFF000000,
104+ 0x00FF0000,
105+ 0x0000FF00,
106+ 0x000000FF
106107 #endif
107- );
108- if (image == NULL) {
109- return;
110- }
108+ );
109+ if (image == NULL) {
110+ return;
111+ }
111112
112- // Save the alpha blending attributes
113- Uint32 saved_flags = surface->flags & (SDL_SRCALPHA | SDL_RLEACCELOK);
114- Uint8 saved_alpha = surface->format->alpha;
115- if ((saved_flags & SDL_SRCALPHA) == SDL_SRCALPHA) {
116- SDL_SetAlpha(surface, 0, 0);
117- }
113+ // Save the alpha blending attributes
114+ Uint32 saved_flags =
115+ surface->flags & (SDL_SRCALPHA | SDL_RLEACCELOK);
116+ Uint8 saved_alpha = surface->format->alpha;
117+ if ((saved_flags & SDL_SRCALPHA) == SDL_SRCALPHA) {
118+ SDL_SetAlpha(surface, 0, 0);
119+ }
118120
119- // Copy the surface into the GL texture image
120- SDL_Rect area;
121- set_SdlRect(&area, 0, 0, surface->w, surface->h);
122- SDL_BlitSurface(surface, &area, image, &area);
121+ // Copy the surface into the GL texture image
122+ SDL_Rect area;
123+ set_SdlRect(&area, 0, 0, surface->w, surface->h);
124+ SDL_BlitSurface(surface, &area, image, &area);
123125
124- // Restore the alpha blending attributes
125- if ((saved_flags & SDL_SRCALPHA) == SDL_SRCALPHA) {
126- SDL_SetAlpha(surface, saved_flags, saved_alpha);
127- }
126+ // Restore the alpha blending attributes
127+ if ((saved_flags & SDL_SRCALPHA) == SDL_SRCALPHA) {
128+ SDL_SetAlpha(surface, saved_flags, saved_alpha);
129+ }
128130
129- // Create an OpenGL texture for the image
130- GLuint texture = InvalidTextureId;
131- glGenTextures(1, &texture);
132- glBindTexture(GL_TEXTURE_2D, texture);
133- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
134- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
135- glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, w, h, 0, GL_RGBA,
136- GL_UNSIGNED_BYTE, image->pixels);
137- SDL_FreeSurface(image); // No longer needed
131+ // Create an OpenGL texture for the image
132+ GLuint texture = InvalidTextureId;
133+ glGenTextures(1, &texture);
134+ glBindTexture(GL_TEXTURE_2D, texture);
135+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
136+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
137+ glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, w, h, 0, GL_RGBA,
138+ GL_UNSIGNED_BYTE, image->pixels);
139+ SDL_FreeSurface(image); // No longer needed
138140
139- texture_id_ = texture;
140- }
141- };
141+ texture_id_ = texture;
142+ }
143+ };
142144
143145
144- GL_Texture* Gui_LoadTexture(SDL_Surface* surface)
145- {
146- if (surface == NULL) {
147- return NULL;
148- }
149- GL_Texture* texture = new GL_Texture;
150- texture->w = surface->w;
151- texture->h = surface->h;
146+ GL_Texture* Gui_LoadTexture(SDL_Surface* surface)
147+ {
148+ if (surface == NULL) {
149+ return NULL;
150+ }
151+ GL_Texture* texture = new GL_Texture;
152+ texture->w = surface->w;
153+ texture->h = surface->h;
152154
153- texture->SDL_GL_LoadTexture(surface);
155+ texture->SDL_GL_LoadTexture(surface);
154156
155- return texture;
156- }
157+ return texture;
158+ }
157159
158160
159- void enter2D(void)
160- {
161- glPushAttrib(GL_ENABLE_BIT);
162- glDisable(GL_DEPTH_TEST);
163- glDisable(GL_CULL_FACE);
164- glEnable(GL_TEXTURE_2D);
165- glEnable(GL_BLEND);
166- glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
161+ void enter2D(void)
162+ {
163+ glPushAttrib(GL_ENABLE_BIT);
164+ glDisable(GL_DEPTH_TEST);
165+ glDisable(GL_CULL_FACE);
166+ glEnable(GL_TEXTURE_2D);
167+ glEnable(GL_BLEND);
168+ glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
167169
168- glViewport(0, 0, ScreenWidth - 1, ScreenHeight - 1);
170+ glViewport(0, 0, ScreenWidth - 1, ScreenHeight - 1);
169171
170- glMatrixMode(GL_PROJECTION);
171- glPushMatrix();
172- glLoadIdentity();
172+ glMatrixMode(GL_PROJECTION);
173+ glPushMatrix();
174+ glLoadIdentity();
173175
174- glOrtho(0.0, ScreenWidth - 1.0, ScreenHeight - 1.0, 0.0, 0.0, 1.0);
176+ glOrtho(0.0, ScreenWidth - 1.0, ScreenHeight - 1.0, 0.0, 0.0, 1.0);
175177
176- glMatrixMode(GL_MODELVIEW);
177- glPushMatrix();
178- glLoadIdentity();
178+ glMatrixMode(GL_MODELVIEW);
179+ glPushMatrix();
180+ glLoadIdentity();
179181
180- glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL);
181- }
182+ glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL);
183+ }
182184
183185
184- void leave2D(void)
185- {
186- glMatrixMode(GL_MODELVIEW);
187- glPopMatrix();
186+ void leave2D(void)
187+ {
188+ glMatrixMode(GL_MODELVIEW);
189+ glPopMatrix();
188190
189- glMatrixMode(GL_PROJECTION);
190- glPopMatrix();
191+ glMatrixMode(GL_PROJECTION);
192+ glPopMatrix();
191193
192- glPopAttrib();
193- }
194+ glPopAttrib();
195+ }
194196
195197
196- void Gui_FreeSurface(GL_Texture* texture)
197- {
198- if (texture->texture_id_ != GL_Texture::InvalidTextureId) {
199- glDeleteTextures(1, &texture->texture_id_);
200- texture->texture_id_ = GL_Texture::InvalidTextureId;
198+ void Gui_FreeSurface(GL_Texture* texture)
199+ {
200+ if (texture->texture_id_ != GL_Texture::InvalidTextureId) {
201+ glDeleteTextures(1, &texture->texture_id_);
202+ texture->texture_id_ = GL_Texture::InvalidTextureId;
203+ }
201204 }
202- }
203205
204206
205- void Gui_BlitTexture(GL_Texture* texture, SDL_Rect* srcrect,
206- SDL_Rect* dstrect)
207- {
208- if (texture->texture_id_ == GL_Texture::InvalidTextureId) {
209- return;
210- }
207+ void Gui_BlitTexture(GL_Texture* texture, SDL_Rect* srcrect,
208+ SDL_Rect* dstrect)
209+ {
210+ if (texture->texture_id_ == GL_Texture::InvalidTextureId) {
211+ return;
212+ }
211213
212- enter2D();
214+ enter2D();
213215
214- GLfloat texMinX = texture->basecoord_[0];
215- GLfloat texMinY = texture->basecoord_[1];
216- GLfloat texMaxX = texture->basecoord_[2];
217- GLfloat texMaxY = texture->basecoord_[3];
216+ GLfloat texMinX = texture->basecoord_[0];
217+ GLfloat texMinY = texture->basecoord_[1];
218+ GLfloat texMaxX = texture->basecoord_[2];
219+ GLfloat texMaxY = texture->basecoord_[3];
218220
219- int x = dstrect->x;
220- int y = dstrect->y;
221- int w = dstrect->w;
222- int h = dstrect->h;
221+ int x = dstrect->x;
222+ int y = dstrect->y;
223+ int w = dstrect->w;
224+ int h = dstrect->h;
223225
224- if (srcrect) {
225- texMinX = texMaxX * (1.0 * srcrect->x / texture->base_w_);
226- texMinY = texMaxY * (1.0 * srcrect->y / texture->base_h_);
227- }
226+ if (srcrect) {
227+ texMinX = texMaxX * (1.0 * srcrect->x / texture->base_w_);
228+ texMinY = texMaxY * (1.0 * srcrect->y / texture->base_h_);
229+ }
228230
229- GLfloat width_ratio = texMaxX * w / texture->base_w_;
230- GLfloat height_ratio = texMaxY * h / texture->base_h_;
231+ GLfloat width_ratio = texMaxX * w / texture->base_w_;
232+ GLfloat height_ratio = texMaxY * h / texture->base_h_;
231233
232- if (srcrect) {
233- width_ratio = texMaxX * (srcrect->x + srcrect->w) / texture->base_w_;
234- height_ratio = texMaxY * (srcrect->y + srcrect->h) / texture->base_h_;
235- }
234+ if (srcrect) {
235+ width_ratio =
236+ texMaxX * (srcrect->x + srcrect->w) / texture->base_w_;
237+ height_ratio =
238+ texMaxY * (srcrect->y + srcrect->h) / texture->base_h_;
239+ }
236240
237- // 透過処理のための記述
238- glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
239- glColor4d(1.0, 1.0, 1.0, texture->alpha_);
241+ // 透過処理のための記述
242+ glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
243+ glColor4d(1.0, 1.0, 1.0, texture->alpha_);
240244
241- GLfloat screen_x = x;
242- GLfloat screen_y = y;
243- GLfloat screen_w = w;
244- GLfloat screen_h = h;
245+ GLfloat screen_x = x;
246+ GLfloat screen_y = y;
247+ GLfloat screen_w = w;
248+ GLfloat screen_h = h;
245249
246- glBindTexture(GL_TEXTURE_2D, texture->texture_id_);
247- glBegin(GL_TRIANGLE_STRIP);
250+ glBindTexture(GL_TEXTURE_2D, texture->texture_id_);
251+ glBegin(GL_TRIANGLE_STRIP);
248252
249- glTexCoord2f(texMinX, texMinY);
250- glVertex2f(screen_x, screen_y);
253+ glTexCoord2f(texMinX, texMinY);
254+ glVertex2f(screen_x, screen_y);
251255
252- glTexCoord2f(width_ratio, texMinY);
253- glVertex2f(screen_x + screen_w, screen_y);
256+ glTexCoord2f(width_ratio, texMinY);
257+ glVertex2f(screen_x + screen_w, screen_y);
254258
255- glTexCoord2f(texMinX, height_ratio);
256- glVertex2f(screen_x, screen_y + screen_h);
259+ glTexCoord2f(texMinX, height_ratio);
260+ glVertex2f(screen_x, screen_y + screen_h);
257261
258- glTexCoord2f(width_ratio, height_ratio);
259- glVertex2f(screen_x + screen_w, screen_y + screen_h);
262+ glTexCoord2f(width_ratio, height_ratio);
263+ glVertex2f(screen_x + screen_w, screen_y + screen_h);
260264
261- glEnd();
265+ glEnd();
262266
263- leave2D();
264- }
267+ leave2D();
268+ }
265269 }
266270
267271
268272 static void errorAndExit(const char* message)
269273 {
270- printf("%s: %s\n", message, SDL_GetError());
271- exit(1);
274+ printf("%s: %s\n", message, SDL_GetError());
275+ exit(1);
272276 }
273277
274278
275279 static SDL_Surface* transparentSdlSurface(SDL_Surface* surface)
276280 {
277- SDL_Surface* scr = SDL_GetVideoSurface();
278- if ((surface == NULL) || (scr == NULL)) {
279- return NULL;
280- }
281+ SDL_Surface* scr = SDL_GetVideoSurface();
282+ if ((surface == NULL) || (scr == NULL)) {
283+ return NULL;
284+ }
281285
282- Uint32 trans_color = 0;
283- if (surface->format->BitsPerPixel == 8) {
284- // ピクセルフォーマットが 8 bit の場合
285- Uint8 index = *(Uint8 *)surface->pixels;
286- SDL_Color& color = surface->format->palette->colors[index];
287- trans_color = SDL_MapRGB(surface->format, color.r, color.g, color.b);
288- } else {
289- trans_color = *(Uint32*)surface->pixels;
290- }
286+ Uint32 trans_color = 0;
287+ if (surface->format->BitsPerPixel == 8) {
288+ // ピクセルフォーマットが 8 bit の場合
289+ Uint8 index = *(Uint8 *)surface->pixels;
290+ SDL_Color& color = surface->format->palette->colors[index];
291+ trans_color = SDL_MapRGB(surface->format, color.r, color.g, color.b);
292+ } else {
293+ trans_color = *(Uint32*)surface->pixels;
294+ }
291295
292- SDL_SetColorKey(surface, SDL_SRCCOLORKEY | SDL_RLEACCEL, trans_color);
293- SDL_Surface* transparent_surface = SDL_DisplayFormat(surface);
294- swap(surface, transparent_surface);
295- SDL_FreeSurface(transparent_surface);
296+ SDL_SetColorKey(surface, SDL_SRCCOLORKEY | SDL_RLEACCEL, trans_color);
297+ SDL_Surface* transparent_surface = SDL_DisplayFormat(surface);
298+ swap(surface, transparent_surface);
299+ SDL_FreeSurface(transparent_surface);
296300
297- return surface;
301+ return surface;
298302 }
299303
300304
301305 static void initializeOpenGl(void)
302306 {
303- int bpp = SDL_GetVideoInfo()->vfmt->BitsPerPixel;
307+ int bpp = SDL_GetVideoInfo()->vfmt->BitsPerPixel;
304308
305- // Initialize the display
306- int rgb_size[3];
307- switch (bpp) {
308- case 8:
309- rgb_size[0] = 3;
310- rgb_size[1] = 3;
311- rgb_size[2] = 2;
312- break;
309+ // Initialize the display
310+ int rgb_size[3];
311+ switch (bpp) {
312+ case 8:
313+ rgb_size[0] = 3;
314+ rgb_size[1] = 3;
315+ rgb_size[2] = 2;
316+ break;
313317
314- case 15:
315- case 16:
316- rgb_size[0] = 5;
317- rgb_size[1] = 5;
318- rgb_size[2] = 5;
319- break;
318+ case 15:
319+ case 16:
320+ rgb_size[0] = 5;
321+ rgb_size[1] = 5;
322+ rgb_size[2] = 5;
323+ break;
320324
321- default:
322- rgb_size[0] = 8;
323- rgb_size[1] = 8;
324- rgb_size[2] = 8;
325- break;
326- }
327- SDL_GL_SetAttribute(SDL_GL_RED_SIZE, rgb_size[0]);
328- SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, rgb_size[1]);
329- SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, rgb_size[2]);
330- SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 16);
331- SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
325+ default:
326+ rgb_size[0] = 8;
327+ rgb_size[1] = 8;
328+ rgb_size[2] = 8;
329+ break;
330+ }
331+ SDL_GL_SetAttribute(SDL_GL_RED_SIZE, rgb_size[0]);
332+ SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, rgb_size[1]);
333+ SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, rgb_size[2]);
334+ SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 16);
335+ SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
332336 }
333337
334338
335339 static void setupOpenGlView(void)
336340 {
337- glPushAttrib(GL_ENABLE_BIT);
338- glDisable(GL_DEPTH_TEST);
339- glDisable(GL_CULL_FACE);
340- glEnable(GL_TEXTURE_2D);
341- glEnable(GL_BLEND);
342- glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
341+ glPushAttrib(GL_ENABLE_BIT);
342+ glDisable(GL_DEPTH_TEST);
343+ glDisable(GL_CULL_FACE);
344+ glEnable(GL_TEXTURE_2D);
345+ glEnable(GL_BLEND);
346+ glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
343347
344- glViewport(-1, -1, +1, +1);
345- glMatrixMode(GL_PROJECTION);
346- glLoadIdentity();
348+ glViewport(-1, -1, +1, +1);
349+ glMatrixMode(GL_PROJECTION);
350+ glLoadIdentity();
347351
348- glOrtho(-1.0, +1.0, -1.0, +1.0, -10.0, +10.0);
352+ glOrtho(-1.0, +1.0, -1.0, +1.0, -10.0, +10.0);
349353
350- glMatrixMode(GL_MODELVIEW);
351- glLoadIdentity();
354+ glMatrixMode(GL_MODELVIEW);
355+ glLoadIdentity();
352356
353- glEnable(GL_DEPTH_TEST);
354- glDepthFunc(GL_LESS);
355- glShadeModel(GL_SMOOTH);
357+ glEnable(GL_DEPTH_TEST);
358+ glDepthFunc(GL_LESS);
359+ glShadeModel(GL_SMOOTH);
356360 }
357361
358362
359363 static SDL_Surface* initializeScreen(void)
360364 {
361- if (SDL_Init(SDL_INIT_VIDEO) < 0) {
362- errorAndExit("SDL_Init");
363- }
364- //atexit(SDL_Quit);
365+ if (SDL_Init(SDL_INIT_VIDEO) < 0) {
366+ errorAndExit("SDL_Init");
367+ }
368+ //atexit(SDL_Quit);
365369
366- Uint32 mode = SDL_OPENGL;
367- int width = ScreenWidth;
368- int height = ScreenHeight;
369- int bpp = ScreenBpp;
370+ Uint32 mode = SDL_OPENGL;
371+ int width = ScreenWidth;
372+ int height = ScreenHeight;
373+ int bpp = ScreenBpp;
370374
371- initializeOpenGl();
372- SDL_Surface* scr = SDL_SetVideoMode(width, height, bpp, mode);
373- if (scr == NULL) {
374- errorAndExit("SDL_SetVideoMode");
375- }
376- setupOpenGlView();
375+ initializeOpenGl();
376+ SDL_Surface* scr = SDL_SetVideoMode(width, height, bpp, mode);
377+ if (scr == NULL) {
378+ errorAndExit("SDL_SetVideoMode");
379+ }
380+ setupOpenGlView();
377381
378- return scr;
382+ return scr;
379383 }
380384
381385
382386 int main(int argc, char *argv[])
383387 {
384- static_cast<void>(argc);
385- static_cast<void>(argv);
388+ static_cast<void>(argc);
389+ static_cast<void>(argv);
386390
387- // 画面の初期化
388- initializeScreen();
391+ // 画面の初期化
392+ initializeScreen();
389393
390- // BMP 画像を SDL_Surface として読み出す
391- SDL_Surface* cross_surface = SDL_LoadBMP("cross_blue.bmp");
392- if (cross_surface == NULL) {
393- errorAndExit("SDL_LoadBMP");
394- }
394+ // BMP 画像を SDL_Surface として読み出す
395+ SDL_Surface* cross_surface = SDL_LoadBMP("cross_blue.bmp");
396+ if (cross_surface == NULL) {
397+ errorAndExit("SDL_LoadBMP");
398+ }
395399
396- // (0, 0) の位置の色を透明色として扱う
397- SDL_Surface* transparent_surface = SDL_LoadBMP("cross_blue.bmp");
398- if (transparent_surface == NULL) {
399- errorAndExit("SDL_LoadBMP");
400- }
401- transparent_surface = transparentSdlSurface(transparent_surface);
402- if (transparent_surface == NULL) {
403- errorAndExit("tranparentSdlSurface");
404- }
400+ // (0, 0) の位置の色を透明色として扱う
401+ SDL_Surface* transparent_surface = SDL_LoadBMP("cross_blue.bmp");
402+ if (transparent_surface == NULL) {
403+ errorAndExit("SDL_LoadBMP");
404+ }
405+ transparent_surface = transparentSdlSurface(transparent_surface);
406+ if (transparent_surface == NULL) {
407+ errorAndExit("tranparentSdlSurface");
408+ }
405409
406- // SDL_Surface を OpenGL に登録する
407- GL_Texture* cross_texture = Gui_LoadTexture(cross_surface);
408- if (cross_texture == NULL) {
409- printf("Gui_LoadTexture: %s\n", "cross_surface");
410- exit(1);
411- }
412- GL_Texture* transparent_texture = Gui_LoadTexture(transparent_surface);
413- if (transparent_texture == NULL) {
414- printf("Gui_LoadTexture: %s\n", "transparent_surface");
415- exit(1);
416- }
410+ // SDL_Surface を OpenGL に登録する
411+ GL_Texture* cross_texture = Gui_LoadTexture(cross_surface);
412+ if (cross_texture == NULL) {
413+ printf("Gui_LoadTexture: %s\n", "cross_surface");
414+ exit(1);
415+ }
416+ GL_Texture* transparent_texture = Gui_LoadTexture(transparent_surface);
417+ if (transparent_texture == NULL) {
418+ printf("Gui_LoadTexture: %s\n", "transparent_surface");
419+ exit(1);
420+ }
417421
418- // 画面へのテクスチャ描画
419- SDL_Rect pos;
420- set_SdlRect(&pos, 0, 0, 32, 32);
421- Gui_BlitTexture(cross_texture, NULL, &pos);
422+ // 画面へのテクスチャ描画
423+ SDL_Rect pos;
424+ set_SdlRect(&pos, 0, 0, 32, 32);
425+ Gui_BlitTexture(cross_texture, NULL, &pos);
422426
423- // 部分描画
424- SDL_Rect area;
425- set_SdlRect(&area, 0, 0, 16, 16);
426- set_SdlRect(&pos, 48 + 32 + 16, 0, 16, 16);
427- Gui_BlitTexture(cross_texture, &area, &pos);
427+ // 部分描画
428+ SDL_Rect area;
429+ set_SdlRect(&area, 0, 0, 16, 16);
430+ set_SdlRect(&pos, 48 + 32 + 16, 0, 16, 16);
431+ Gui_BlitTexture(cross_texture, &area, &pos);
428432
429- set_SdlRect(&area, 16, 16, 16, 16);
430- set_SdlRect(&pos, 48 + 32 + 16 + 16, 0 + 16, 16, 16);
431- Gui_BlitTexture(cross_texture, &area, &pos);
433+ set_SdlRect(&area, 16, 16, 16, 16);
434+ set_SdlRect(&pos, 48 + 32 + 16 + 16, 0 + 16, 16, 16);
435+ Gui_BlitTexture(cross_texture, &area, &pos);
432436
433- // 一部の色を透明扱いにして描画
434- set_SdlRect(&pos, 32 + 16, 0, 32, 32);
435- Gui_BlitTexture(transparent_texture, NULL, &pos);
437+ // 一部の色を透明扱いにして描画
438+ set_SdlRect(&pos, 32 + 16, 0, 32, 32);
439+ Gui_BlitTexture(transparent_texture, NULL, &pos);
436440
437441
438- // 描画の反映
439- SDL_GL_SwapBuffers();
440- SDL_Delay(1000);
442+ // 描画の反映
443+ SDL_GL_SwapBuffers();
444+ SDL_Delay(1000);
441445
442- // リソースの解放
443- Gui_FreeSurface(cross_texture);
444- SDL_FreeSurface(cross_surface);
446+ // リソースの解放
447+ Gui_FreeSurface(cross_texture);
448+ SDL_FreeSurface(cross_surface);
445449
446- return 0;
450+ return 0;
447451 }
--- trunk/libs/gui/samples/drawText.cpp (revision 1813)
+++ trunk/libs/gui/samples/drawText.cpp (revision 1814)
@@ -18,41 +18,41 @@
1818
1919 int main(int argc, char *argv[])
2020 {
21- Screen screen;
22- screen.show(SDL_OPENGL);
23- screen.clear();
21+ Screen screen;
22+ screen.show(SDL_OPENGL);
23+ screen.clear();
2424
25- // フォントの読み出し
26- const char* font_file = (argc <= 1) ? "font.ttf" : argv[1];
25+ // フォントの読み出し
26+ const char* font_file = (argc <= 1) ? "font.ttf" : argv[1];
2727
28- // サイズを変更しながらフォントを描画する
29- int font_size[] = { 16, 32, 64 };
28+ // サイズを変更しながらフォントを描画する
29+ int font_size[] = { 16, 32, 64 };
3030
31- vector<Surface*> surfaces;
32- int y = 0;
33- size_t n = sizeof(font_size) / sizeof(font_size[0]);
34- for (size_t i = 0; i < n; ++i) {
35- Font font(font_file, font_size[i]);
36- if (! font.resource()) {
37- exit(1);
31+ vector<Surface*> surfaces;
32+ int y = 0;
33+ size_t n = sizeof(font_size) / sizeof(font_size[0]);
34+ for (size_t i = 0; i < n; ++i) {
35+ Font font(font_file, font_size[i]);
36+ if (! font.resource()) {
37+ exit(1);
38+ }
39+ TextSurface* text = new TextSurface(font, "こんにちはー");
40+ surfaces.push_back(text);
41+
42+ Rect<long> dest_rect = text->rect();
43+ dest_rect.y = y;
44+ text->draw(NULL, &dest_rect);
45+ y += dest_rect.h;
3846 }
39- TextSurface* text = new TextSurface(font, "こんにちはー");
40- surfaces.push_back(text);
4147
42- Rect<long> dest_rect = text->rect();
43- dest_rect.y = y;
44- text->draw(NULL, &dest_rect);
45- y += dest_rect.h;
46- }
48+ // 描画内容を反映させる
49+ SDL_GL_SwapBuffers();
50+ SDL_Delay(1000);
4751
48- // 描画内容を反映させる
49- SDL_GL_SwapBuffers();
50- SDL_Delay(1000);
52+ for (vector<Surface*>::iterator it = surfaces.begin();
53+ it != surfaces.end(); ++it) {
54+ delete *it;
55+ }
5156
52- for (vector<Surface*>::iterator it = surfaces.begin();
53- it != surfaces.end(); ++it) {
54- delete *it;
55- }
56-
57- return 0;
57+ return 0;
5858 }
--- trunk/libs/gui/samples/glScreen.cpp (revision 1813)
+++ trunk/libs/gui/samples/glScreen.cpp (revision 1814)
@@ -20,227 +20,228 @@
2020
2121 namespace
2222 {
23- enum {
24- ScreenWidth = 640,
25- ScreenHeight = 480,
26- };
23+ enum {
24+ ScreenWidth = 640,
25+ ScreenHeight = 480,
26+ };
2727
2828
29- void exitAndError(void)
30- {
31- printf("error: %s\n", SDL_GetError());
32- exit(1);
33- }
29+ void exitAndError(void)
30+ {
31+ printf("error: %s\n", SDL_GetError());
32+ exit(1);
33+ }
3434
3535
36- bool initializeSdl(void)
37- {
38- if (SDL_Init(SDL_INIT_VIDEO) < 0) {
39- return false;
36+ bool initializeSdl(void)
37+ {
38+ if (SDL_Init(SDL_INIT_VIDEO) < 0) {
39+ return false;
40+ }
41+ atexit(SDL_Quit);
42+
43+ return true;
4044 }
41- atexit(SDL_Quit);
4245
43- return true;
44- }
4546
47+ void initializeOpenGl(void)
48+ {
49+ int bpp = SDL_GetVideoInfo()->vfmt->BitsPerPixel;
4650
47- void initializeOpenGl(void)
48- {
49- int bpp = SDL_GetVideoInfo()->vfmt->BitsPerPixel;
51+ // Initialize the display
52+ int rgb_size[3];
53+ switch (bpp) {
54+ case 8:
55+ rgb_size[0] = 3;
56+ rgb_size[1] = 3;
57+ rgb_size[2] = 2;
58+ break;
5059
51- // Initialize the display
52- int rgb_size[3];
53- switch (bpp) {
54- case 8:
55- rgb_size[0] = 3;
56- rgb_size[1] = 3;
57- rgb_size[2] = 2;
58- break;
60+ case 15:
61+ case 16:
62+ rgb_size[0] = 5;
63+ rgb_size[1] = 5;
64+ rgb_size[2] = 5;
65+ break;
5966
60- case 15:
61- case 16:
62- rgb_size[0] = 5;
63- rgb_size[1] = 5;
64- rgb_size[2] = 5;
65- break;
66-
67- default:
68- rgb_size[0] = 8;
69- rgb_size[1] = 8;
70- rgb_size[2] = 8;
71- break;
67+ default:
68+ rgb_size[0] = 8;
69+ rgb_size[1] = 8;
70+ rgb_size[2] = 8;
71+ break;
72+ }
73+ SDL_GL_SetAttribute(SDL_GL_RED_SIZE, rgb_size[0]);
74+ SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, rgb_size[1]);
75+ SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, rgb_size[2]);
76+ SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 16);
77+ SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
7278 }
73- SDL_GL_SetAttribute(SDL_GL_RED_SIZE, rgb_size[0]);
74- SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, rgb_size[1]);
75- SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, rgb_size[2]);
76- SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 16);
77- SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
78- }
7979
8080
81- void setupOpenGlView(void)
82- {
83- glPushAttrib(GL_ENABLE_BIT);
84- glDisable(GL_DEPTH_TEST);
85- glDisable(GL_CULL_FACE);
86- glEnable(GL_TEXTURE_2D);
87- glEnable(GL_BLEND);
88- glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
81+ void setupOpenGlView(void)
82+ {
83+ glPushAttrib(GL_ENABLE_BIT);
84+ glDisable(GL_DEPTH_TEST);
85+ glDisable(GL_CULL_FACE);
86+ glEnable(GL_TEXTURE_2D);
87+ glEnable(GL_BLEND);
88+ glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
8989
90- glViewport(-1, -1, +1, +1);
91- glMatrixMode(GL_PROJECTION);
92- glLoadIdentity();
90+ glViewport(-1, -1, +1, +1);
91+ glMatrixMode(GL_PROJECTION);
92+ glLoadIdentity();
9393
94- glOrtho(-1.0, +1.0, -1.0, +1.0, -10.0, +10.0);
94+ glOrtho(-1.0, +1.0, -1.0, +1.0, -10.0, +10.0);
9595
96- glMatrixMode(GL_MODELVIEW);
97- glLoadIdentity();
96+ glMatrixMode(GL_MODELVIEW);
97+ glLoadIdentity();
9898
99- glEnable(GL_DEPTH_TEST);
100- glDepthFunc(GL_LESS);
101- glShadeModel(GL_SMOOTH);
102- }
99+ glEnable(GL_DEPTH_TEST);
100+ glDepthFunc(GL_LESS);
101+ glShadeModel(GL_SMOOTH);
102+ }
103103
104104
105- // SDL と同じ座標系設定にする
106- void enter2D(void)
107- {
108- glPushAttrib(GL_ENABLE_BIT);
109- glDisable(GL_DEPTH_TEST);
110- glDisable(GL_CULL_FACE);
111- glEnable(GL_TEXTURE_2D);
112- glEnable(GL_BLEND);
113- glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
105+ // SDL と同じ座標系設定にする
106+ void enter2D(void)
107+ {
108+ glPushAttrib(GL_ENABLE_BIT);
109+ glDisable(GL_DEPTH_TEST);
110+ glDisable(GL_CULL_FACE);
111+ glEnable(GL_TEXTURE_2D);
112+ glEnable(GL_BLEND);
113+ glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
114114
115- glViewport(0, 0, ScreenWidth, ScreenHeight);
115+ glViewport(0, 0, ScreenWidth, ScreenHeight);
116116
117- glMatrixMode(GL_PROJECTION);
118- glPushMatrix();
119- glLoadIdentity();
117+ glMatrixMode(GL_PROJECTION);
118+ glPushMatrix();
119+ glLoadIdentity();
120120
121- glOrtho(0.0, ScreenWidth - 1.0, ScreenHeight - 1.0, 0.0, 0.0, 1.0);
121+ glOrtho(0.0, ScreenWidth - 1.0, ScreenHeight - 1.0, 0.0, 0.0, 1.0);
122122
123- glMatrixMode(GL_MODELVIEW);
124- glPushMatrix();
125- glLoadIdentity();
123+ glMatrixMode(GL_MODELVIEW);
124+ glPushMatrix();
125+ glLoadIdentity();
126126
127- glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL);
128- }
127+ glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL);
128+ }
129129
130130
131- // OpenGL 風の座標系設定にする
132- void leave2D(void)
133- {
134- glMatrixMode(GL_MODELVIEW);
135- glPopMatrix();
131+ // OpenGL 風の座標系設定にする
132+ void leave2D(void)
133+ {
134+ glMatrixMode(GL_MODELVIEW);
135+ glPopMatrix();
136136
137- glMatrixMode(GL_PROJECTION);
138- glPopMatrix();
137+ glMatrixMode(GL_PROJECTION);
138+ glPopMatrix();
139139
140- glPopAttrib();
141- }
140+ glPopAttrib();
141+ }
142142
143143
144- bool screen(Uint32 flags)
145- {
146- initializeOpenGl();
144+ bool screen(Uint32 flags)
145+ {
146+ initializeOpenGl();
147147
148- int bpp = 0;
149- SDL_Surface* screen =
150- SDL_SetVideoMode(ScreenWidth, ScreenHeight, bpp, flags | SDL_OPENGL);
151- if (! screen) {
152- return false;
153- }
148+ int bpp = 0;
149+ SDL_Surface* screen =
150+ SDL_SetVideoMode(ScreenWidth, ScreenHeight, bpp,
151+ flags | SDL_OPENGL);
152+ if (! screen) {
153+ return false;
154+ }
154155
155- setupOpenGlView();
156- enter2D();
156+ setupOpenGlView();
157+ enter2D();
157158
158- return true;
159- }
159+ return true;
160+ }
160161
161162
162- bool isKeyPressed(void)
163- {
164- SDL_Event event;
165- while (SDL_PollEvent(&event)) {
166- switch (event.type) {
163+ bool isKeyPressed(void)
164+ {
165+ SDL_Event event;
166+ while (SDL_PollEvent(&event)) {
167+ switch (event.type) {
167168
168- case SDL_QUIT:
169- case SDL_KEYDOWN:
170- // 終了イベントが発生しても処理を戻す
171- return true;
172- }
169+ case SDL_QUIT:
170+ case SDL_KEYDOWN:
171+ // 終了イベントが発生しても処理を戻す
172+ return true;
173+ }
174+ }
175+ return false;
173176 }
174- return false;
175- }
176177
177178
178- void clearScreen(void)
179- {
180- glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
181- }
179+ void clearScreen(void)
180+ {
181+ glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
182+ }
182183
183184
184- void drawLine(int degree)
185- {
186- // !!! この時点では、(0, 0)-(640, 480) の座標系に設定して
187- // !!! OpenGL 関数を用いた描画をしている。
188- // !!! 座標系の設定は enter2D(), leave2D() を参考のこと
185+ void drawLine(int degree)
186+ {
187+ // !!! この時点では、(0, 0)-(640, 480) の座標系に設定して
188+ // !!! OpenGL 関数を用いた描画をしている。
189+ // !!! 座標系の設定は enter2D(), leave2D() を参考のこと
189190
190- // 画面を中心に、指定角度の向きの線分を描く
191- enum { Length = 100 };
192- double base_x = ScreenWidth / 2.0;
193- double base_y = ScreenHeight / 2.0;
194- glColor3f(0.0, 1.0, 0.0);
195- glLineWidth(2.0);
191+ // 画面を中心に、指定角度の向きの線分を描く
192+ enum { Length = 100 };
193+ double base_x = ScreenWidth / 2.0;
194+ double base_y = ScreenHeight / 2.0;
195+ glColor3f(0.0, 1.0, 0.0);
196+ glLineWidth(2.0);
196197
197- glBegin(GL_LINES);
198- glVertex2d(base_x, base_y);
198+ glBegin(GL_LINES);
199+ glVertex2d(base_x, base_y);
199200
200- double radian = degree * M_PI / 180.0;
201+ double radian = degree * M_PI / 180.0;
201202
202- glVertex2d(base_x + (Length * cos(radian)),
203- base_y + (Length * sin(radian)));
204- glEnd();
205- }
203+ glVertex2d(base_x + (Length * cos(radian)),
204+ base_y + (Length * sin(radian)));
205+ glEnd();
206+ }
206207
207208
208- void swapScreenBuffers(void)
209- {
210- SDL_GL_SwapBuffers();
211- }
209+ void swapScreenBuffers(void)
210+ {
211+ SDL_GL_SwapBuffers();
212+ }
212213 }
213214
214215
215216 int main(int argc, char *argv[])
216217 {
217- Uint32 flags = 0;
218- for (int i = 1; i < argc; ++i) {
219- if (! strcmp(argv[i], "-f")) {
220- flags |= SDL_FULLSCREEN;
218+ Uint32 flags = 0;
219+ for (int i = 1; i < argc; ++i) {
220+ if (! strcmp(argv[i], "-f")) {
221+ flags |= SDL_FULLSCREEN;
222+ }
221223 }
222- }
223224
224- // 初期化
225- if (! initializeSdl()) {
226- exitAndError();
227- }
225+ // 初期化
226+ if (! initializeSdl()) {
227+ exitAndError();
228+ }
228229
229- // 画面の作成
230- if (! screen(flags)) {
231- exitAndError();
232- }
230+ // 画面の作成
231+ if (! screen(flags)) {
232+ exitAndError();
233+ }
233234
234- // メインループ
235- int angle_degree = 0;
236- while (! isKeyPressed()) {
235+ // メインループ
236+ int angle_degree = 0;
237+ while (! isKeyPressed()) {
237238
238- clearScreen();
239- drawLine(angle_degree++);
240- swapScreenBuffers();
239+ clearScreen();
240+ drawLine(angle_degree++);
241+ swapScreenBuffers();
241242
242- SDL_Delay(10);
243- }
243+ SDL_Delay(10);
244+ }
244245
245- return 0;
246+ return 0;
246247 }
--- trunk/libs/gui/samples/fadeText.cpp (revision 1813)
+++ trunk/libs/gui/samples/fadeText.cpp (revision 1814)
@@ -15,26 +15,28 @@
1515
1616 int main(int argc, char *argv[])
1717 {
18- Screen screen;
19- screen.show(SDL_OPENGL);
18+ Screen screen;
19+ screen.show(SDL_OPENGL);
2020
21- // フォントの読み出し
22- const char* font_file = (argc <= 1) ? "font.ttf" : argv[1];
23- Font font(font_file, 32);
21+ // フォントの読み出し
22+ const char* font_file = (argc <= 1) ? "font.ttf" : argv[1];
23+ Font font(font_file, 32);
2424
25- // 文字列の描画
26- TextFadeSurface surface(font, "This is sample text.");
27- Rect<long> dest_rect = surface.rect();
25+ // 文字列の描画
26+ TextFadeSurface surface(font, "This is sample text.");
27+ Rect<long> dest_rect = surface.rect();
2828
29- // 描画した文字列のをフェードさせる
30- for (size_t i = 0; i <= 100; ++i) {
31- screen.clear();
32- surface.setFadePercent(i);
33- surface.draw(NULL, &dest_rect);
34- SDL_GL_SwapBuffers();
35- SDL_Delay(10);
36- }
37- SDL_Delay(100);
29+ // 描画した文字列のをフェードさせる
30+ for (size_t j = 0; j < 1; ++j) {
31+ for (size_t i = 0; i <= 100; ++i) {
32+ screen.clear();
33+ surface.setFadePercent(i);
34+ surface.draw(NULL, &dest_rect);
35+ SDL_GL_SwapBuffers();
36+ SDL_Delay(10);
37+ }
38+ }
39+ SDL_Delay(100);
3840
39- return 0;
41+ return 0;
4042 }
--- trunk/libs/gui/samples/drawColorSurface.cpp (revision 1813)
+++ trunk/libs/gui/samples/drawColorSurface.cpp (revision 1814)
@@ -17,32 +17,32 @@
1717
1818 int main(int argc, char *argv[])
1919 {
20- static_cast<void>(argc);
21- static_cast<void>(argv);
20+ static_cast<void>(argc);
21+ static_cast<void>(argv);
2222
23- Screen screen;
24- screen.show(Screen::OpenGL);
25- screen.clear();
23+ Screen screen;
24+ screen.show(Screen::OpenGL);
25+ screen.clear();
2626
27- Surface* surface_1st =
28- new ColorSurface(Rect<long>(0, 0, 100, 100), Color(1.0, 0.0, 0.0, 1.0));
29- Rect<long> dest_1st(0, 0, 100, 100);
30- surface_1st->draw(NULL, &dest_1st);
27+ Surface* surface_1st =
28+ new ColorSurface(Rect<long>(0, 0, 100, 100), Color(1.0, 0.0, 0.0, 1.0));
29+ Rect<long> dest_1st(0, 0, 100, 100);
30+ surface_1st->draw(NULL, &dest_1st);
3131
32- Surface* surface_2nd = new ImageSurface("cross_blue.bmp");
33- Rect<long> dest_2nd = surface_2nd->rect();
34- dest_2nd.x = 125;
35- dest_2nd.y = 125;
36- surface_2nd->draw(NULL, &dest_2nd);
32+ Surface* surface_2nd = new ImageSurface("cross_blue.bmp");
33+ Rect<long> dest_2nd = surface_2nd->rect();
34+ dest_2nd.x = 125;
35+ dest_2nd.y = 125;
36+ surface_2nd->draw(NULL, &dest_2nd);
3737
38- Surface* surface_3rd =
39- new ColorSurface(Rect<long>(0, 0, 100, 100), Color(0.4, 0.4, 1.0, 0.8));
40- Rect<long> dest_3rd(50, 50, 100, 100);
41- surface_3rd->draw(NULL, &dest_3rd);
38+ Surface* surface_3rd =
39+ new ColorSurface(Rect<long>(0, 0, 100, 100), Color(0.4, 0.4, 1.0, 0.8));
40+ Rect<long> dest_3rd(50, 50, 100, 100);
41+ surface_3rd->draw(NULL, &dest_3rd);
4242
43- // 描画内容を反映させる
44- SDL_GL_SwapBuffers();
45- SDL_Delay(1000);
43+ // 描画内容を反映させる
44+ SDL_GL_SwapBuffers();
45+ SDL_Delay(1000);
4646
47- return 0;
47+ return 0;
4848 }
--- trunk/libs/gui/samples/menuSample.cpp (revision 1813)
+++ trunk/libs/gui/samples/menuSample.cpp (revision 1814)
@@ -26,92 +26,93 @@
2626
2727 int main(int argc, char *argv[])
2828 {
29- string font_file = "font.ttf";
30- if (argc >= 2) {
31- font_file = argv[1];
32- }
29+ string font_file = "font.ttf";
30+ if (argc >= 2) {
31+ font_file = argv[1];
32+ }
3333
34- Screen screen;
35- screen.show(SDL_OPENGL);
34+ Screen screen;
35+ screen.show(SDL_OPENGL);
3636
37- LayerManager layer_manager;
38- Layer layer;
39- layer_manager.push_back(&layer);
37+ LayerManager layer_manager;
38+ Layer layer;
39+ layer_manager.push_back(&layer);
4040
41- // フォントの初期化
42- enum {
43- FontSize = 40,
44- };
45- Font font(font_file.c_str(), FontSize, false);
46- Font focused_font = font;
47- focused_font.setBackgroundColor(Color(0.5f, 0.5f, 1.0f));
48- Font clicked_font = focused_font;
49- clicked_font.setForegroundColor(Color(0.0f, 0.0f, 0.0f));
41+ // フォントの初期化
42+ enum {
43+ FontSize = 40,
44+ };
45+ Font font(font_file.c_str(), FontSize, false);
46+ Font focused_font = font;
47+ focused_font.setBackgroundColor(Color(0.5f, 0.5f, 1.0f));
48+ Font clicked_font = focused_font;
49+ clicked_font.setForegroundColor(Color(0.0f, 0.0f, 0.0f));
5050
51- // メニューの作成
52- Menu menu(Rect<long>(0, 0, 640, 480), Menu::Center);
51+ // メニューの作成
52+ Menu menu(Rect<long>(0, 0, 640, 480), Menu::Center);
5353
54- // ボタンの作成と登録
55- vector<TextSurface*> text_surfaces;
56- vector<Button*> buttons;
57- const char* buttons_text[] = {
58- " New Game ", " Load Game ", " Config ", " Exit ",
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 = new Button(*surface, *focused_surface, *clicked_surface);
54+ // ボタンの作成と登録
55+ vector<TextSurface*> text_surfaces;
56+ vector<Button*> buttons;
57+ const char* buttons_text[] = {
58+ " New Game ", " Load Game ", " Config ", " Exit ",
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);
6768
6869
69- menu.addButton(*button, i);
70+ menu.addButton(*button, i);
7071
71- text_surfaces.push_back(clicked_surface);
72- text_surfaces.push_back(focused_surface);
73- text_surfaces.push_back(surface);
74- buttons.push_back(button);
75- }
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+ }
7677
77- layer.push_front(&menu);
78+ layer.push_front(&menu);
7879
79- CallbackEvent quit_event;
80- setQuitEvent(&quit_event);
81- layer_manager.insertEvent(&quit_event);
80+ CallbackEvent quit_event;
81+ setQuitEvent(&quit_event);
82+ layer_manager.insertEvent(&quit_event);
8283
83- int clicked_count = 0;
84- while (! quit_event.isActive()) {
84+ int clicked_count = 0;
85+ while (! quit_event.isActive()) {
8586
86- layer_manager.updateEvent();
87+ layer_manager.updateEvent();
8788
88- if (menu.isClicked()) {
89+ if (menu.isClicked()) {
8990
90- if (clicked_count == 0) {
91- cout << "clicked: " << menu.clickedId() << endl;
92- }
93- ++clicked_count;
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);
94106 }
95107
96- if (clicked_count > 100) {
97- clicked_count = 0;
98- menu.release();
108+ for (vector<TextSurface*>::iterator it = text_surfaces.begin();
109+ it != text_surfaces.end(); ++it) {
110+ delete *it;
99111 }
112+ for (vector<Button*>::iterator it = buttons.begin();
113+ it != buttons.end(); ++it) {
114+ delete *it;
115+ }
100116
101- screen.clear();
102- layer_manager.draw();
103- layer_manager.swap();
104- delay(10);
105- }
106-
107- for (vector<TextSurface*>::iterator it = text_surfaces.begin();
108- it != text_surfaces.end(); ++it) {
109- delete *it;
110- }
111- for (vector<Button*>::iterator it = buttons.begin();
112- it != buttons.end(); ++it) {
113- delete *it;
114- }
115-
116- return 0;
117+ return 0;
117118 }
--- trunk/libs/gui/samples/buttonSample.cpp (revision 1813)
+++ trunk/libs/gui/samples/buttonSample.cpp (revision 1814)
@@ -25,56 +25,56 @@
2525
2626 int main(int argc, char *argv[])
2727 {
28- string font_file = "font.ttf";
29- if (argc >= 2) {
30- font_file = argv[1];
31- }
28+ string font_file = "font.ttf";
29+ if (argc >= 2) {
30+ font_file = argv[1];
31+ }
3232
33- Screen screen;
34- screen.show(SDL_OPENGL);
33+ Screen screen;
34+ screen.show(SDL_OPENGL);
3535
36- LayerManager layer_manager;
37- Layer layer;
38- layer_manager.push_back(&layer);
36+ LayerManager layer_manager;
37+ Layer layer;
38+ layer_manager.push_back(&layer);
3939
40- // ボタンの作成
41- enum {
42- FontSize = 20,
43- };
44- const char text[] = " Press Me ! ";
45- Font font(font_file.c_str(), FontSize, false);
46- font.setBackgroundColor(Color(0.0f, 0.0f, 1.0f));
47- TextSurface normal_surface(font, text);
40+ // ボタンの作成
41+ enum {
42+ FontSize = 20,
43+ };
44+ const char text[] = " Press Me ! ";
45+ Font font(font_file.c_str(), FontSize, false);
46+ font.setBackgroundColor(Color(0.0f, 0.0f, 1.0f));
47+ TextSurface normal_surface(font, text);
4848
49- Font focused_font = font;
50- focused_font.setBackgroundColor(Color(0.5f, 0.5f, 1.0f));
51- TextSurface focused_surface(focused_font, text);
49+ Font focused_font = font;
50+ focused_font.setBackgroundColor(Color(0.5f, 0.5f, 1.0f));
51+ TextSurface focused_surface(focused_font, text);
5252
53- Font pressed_font = focused_font;
54- pressed_font.setForegroundColor(Color(0.0f, 0.0f, 0.0f));
55- TextSurface pressed_surface(pressed_font, text);
53+ Font pressed_font = focused_font;
54+ pressed_font.setForegroundColor(Color(0.0f, 0.0f, 0.0f));
55+ TextSurface pressed_surface(pressed_font, text);
5656
57- Button button(normal_surface, focused_surface, pressed_surface);
57+ Button button(normal_surface, focused_surface, pressed_surface);
5858
59- layer.push_front(&button);
59+ layer.push_front(&button);
6060
61- CallbackEvent quit_event;
62- setQuitEvent(&quit_event);
63- layer_manager.insertEvent(&quit_event);
61+ CallbackEvent quit_event;
62+ setQuitEvent(&quit_event);
63+ layer_manager.insertEvent(&quit_event);
6464
65- while (! quit_event.isActive()) {
65+ while (! quit_event.isActive()) {
6666
67- layer_manager.updateEvent();
67+ layer_manager.updateEvent();
6868
69- // ボタンが押されたかの判定
70- if (button.isClicked()) {
71- cout << "clicked." << endl;
69+ // ボタンが押されたかの判定
70+ if (button.isClicked()) {
71+ cout << "clicked." << endl;
72+ }
73+
74+ screen.clear();
75+ layer_manager.draw();
76+ layer_manager.swap();
77+ delay(10);
7278 }
73-
74- screen.clear();
75- layer_manager.draw();
76- layer_manager.swap();
77- delay(10);
78- }
79- return 0;
79+ return 0;
8080 }
--- trunk/libs/gui/samples/inputDraw.cpp (revision 1813)
+++ trunk/libs/gui/samples/inputDraw.cpp (revision 1814)
@@ -27,94 +27,94 @@
2727
2828 namespace
2929 {
30- void updateText(TextSurface*& text_surface, Label*& text_label,
31- Font& font, const char* text)
32- {
33- delete text_label;
34- delete text_surface;
35- text_surface = new TextSurface(font, text);
36- text_label = new Label(*text_surface);
37- }
30+ void updateText(TextSurface*& text_surface, Label*& text_label,
31+ Font& font, const char* text)
32+ {
33+ delete text_label;
34+ delete text_surface;
35+ text_surface = new TextSurface(font, text);
36+ text_label = new Label(*text_surface);
37+ }
3838 }
3939
4040
4141 int main(int argc, char *argv[])
4242 {
43- // フォントの読み出し
44- if (argc <= 1) {
45- cout << "usage:" << endl
46- << '\t' << argv[0] << " <ttf font file>" << endl;
47- exit(1);
48- }
49- const char* font_file = argv[1];
43+ // フォントの読み出し
44+ if (argc <= 1) {
45+ cout << "usage:" << endl
46+ << '\t' << argv[0] << " <ttf font file>" << endl;
47+ exit(1);
48+ }
49+ const char* font_file = argv[1];
5050
51- Font font(font_file, 32);
52- if (! font.isValid()) {
53- exit(1);
54- }
51+ Font font(font_file, 32);
52+ if (! font.isValid()) {
53+ exit(1);
54+ }
5555
56- // 画面の生成
57- Screen screen;
58- if (! screen.show(SDL_OPENGL)) {
59- cout << "Screen::show(): " << screen.what() << endl;
60- exit(1);
61- }
56+ // 画面の生成
57+ Screen screen;
58+ if (! screen.show(SDL_OPENGL)) {
59+ cout << "Screen::show(): " << screen.what() << endl;
60+ exit(1);
61+ }
6262
63- LayerManager layer_manager;
64- Layer layer;
65- layer_manager.push_back(&layer);
63+ LayerManager layer_manager;
64+ Layer layer;
65+ layer_manager.push_back(&layer);
6666
67- // 入力の取得用
68- TextInput text_input;
69- // !!! 削除イベントを登録する
70- layer_manager.insertEvent(&text_input);
67+ // 入力の取得用
68+ TextInput text_input;
69+ // !!! 削除イベントを登録する
70+ layer_manager.insertEvent(&text_input);
7171
7272
73- // イベントの初期化
74- CallbackEvent quit_event;
75- setQuitEvent(&quit_event);
76- layer_manager.insertEvent(&quit_event);
73+ // イベントの初期化
74+ CallbackEvent quit_event;
75+ setQuitEvent(&quit_event);
76+ layer_manager.insertEvent(&quit_event);
7777
78- CallbackEvent enter_event;
79- setEnterEvent(&enter_event);
80- layer_manager.insertEvent(&enter_event);
78+ CallbackEvent enter_event;
79+ setEnterEvent(&enter_event);
80+ layer_manager.insertEvent(&enter_event);
8181
8282
83- // 文字列描画
84- TextSurface* text_surface = NULL;
85- Label* text_label = NULL;
83+ // 文字列描画
84+ TextSurface* text_surface = NULL;
85+ Label* text_label = NULL;
8686
87- // 描画ループ
88- bool quit = false;
89- while (! quit) {
90- layer_manager.updateEvent();
91- quit |= quit_event.isActive();
87+ // 描画ループ
88+ bool quit = false;
89+ while (! quit) {
90+ layer_manager.updateEvent();
91+ quit |= quit_event.isActive();
9292
93- // 入力文字の取得と描画
94- if (text_input.isChanged()) {
95- // 文字列サーフェスの作り直し
96- layer.remove(text_label);
93+ // 入力文字の取得と描画
94+ if (text_input.isChanged()) {
95+ // 文字列サーフェスの作り直し
96+ layer.remove(text_label);
9797
98- if (! text_input.empty()) {
99- updateText(text_surface, text_label, font, text_input.text());
100- layer.push_front(text_label);
101- }
102- }
103- if (enter_event.isActive()) {
104- // 取得文字列の表示
105- cout << text_input.text() << endl;
106- text_input.clear();
107- }
98+ if (! text_input.empty()) {
99+ updateText(text_surface, text_label, font, text_input.text());
100+ layer.push_front(text_label);
101+ }
102+ }
103+ if (enter_event.isActive()) {
104+ // 取得文字列の表示
105+ cout << text_input.text() << endl;
106+ text_input.clear();
107+ }
108108
109- screen.clear();
110- layer_manager.draw();
111- layer_manager.swap();
109+ screen.clear();
110+ layer_manager.draw();
111+ layer_manager.swap();
112112
113- delay(10);
114- }
113+ delay(10);
114+ }
115115
116- delete text_label;
117- delete text_surface;
116+ delete text_label;
117+ delete text_surface;
118118
119- return 0;
119+ return 0;
120120 }
--- trunk/libs/gui/samples/toggleScreen.cpp (revision 1813)
+++ trunk/libs/gui/samples/toggleScreen.cpp (revision 1814)
@@ -14,49 +14,49 @@
1414
1515 namespace
1616 {
17- SDL_Surface* createScreen(Uint32 flags)
18- {
19- // 毎回、ウィンドウを作りなおす
20- return SDL_SetVideoMode(640, 480, 0, flags);
21- }
17+ SDL_Surface* createScreen(Uint32 flags)
18+ {
19+ // 毎回、ウィンドウを作りなおす
20+ return SDL_SetVideoMode(640, 480, 0, flags);
21+ }
2222 }
2323
2424
2525 int main(int argc, char *argv[])
2626 {
27- static_cast<void>(argc);
28- static_cast<void>(argv);
27+ static_cast<void>(argc);
28+ static_cast<void>(argv);
2929
30- SDL_Init(SDL_INIT_VIDEO);
31- atexit(SDL_Quit);
30+ SDL_Init(SDL_INIT_VIDEO);
31+ atexit(SDL_Quit);
3232
33- Uint32 flags = 0;
34- createScreen(flags);
33+ Uint32 flags = 0;
34+ createScreen(flags);
3535
36- SDL_Event event;
37- while (true) {
38- while (SDL_PollEvent(&event)) {
39- switch (event.type) {
40- case SDL_QUIT:
41- exit(0);
42- break;
36+ SDL_Event event;
37+ while (true) {
38+ while (SDL_PollEvent(&event)) {
39+ switch (event.type) {
40+ case SDL_QUIT:
41+ exit(0);
42+ break;
4343
44- case SDL_KEYDOWN:
45- // スペースキーが押されたら、ウィンドウモードを変更する
46- if (event.key.keysym.sym == SDLK_SPACE) {
47- flags ^= SDL_FULLSCREEN;
48- createScreen(flags);
44+ case SDL_KEYDOWN:
45+ // スペースキーが押されたら、ウィンドウモードを変更する
46+ if (event.key.keysym.sym == SDLK_SPACE) {
47+ flags ^= SDL_FULLSCREEN;
48+ createScreen(flags);
49+ }
50+ // ESC を押すと終了する
51+ if (event.key.keysym.sym == SDLK_ESCAPE) {
52+ exit(0);
53+ }
54+ break;
55+ }
56+
57+ SDL_Delay(10);
4958 }
50- // ESC を押すと終了する
51- if (event.key.keysym.sym == SDLK_ESCAPE) {
52- exit(0);
53- }
54- break;
55- }
56-
57- SDL_Delay(10);
5859 }
59- }
6060
61- return 0;
61+ return 0;
6262 }
--- trunk/libs/gui/samples/rectMove.cpp (revision 1813)
+++ trunk/libs/gui/samples/rectMove.cpp (revision 1814)
@@ -24,54 +24,54 @@
2424
2525 int main(int argc, char *argv[])
2626 {
27- static_cast<void>(argc);
28- static_cast<void>(argv);
27+ static_cast<void>(argc);
28+ static_cast<void>(argv);
2929
30- Screen screen;
31- if (! screen.show(SDL_OPENGL)) {
32- cout << "Screen::show(): " << screen.show() << endl;
33- exit(1);
34- }
30+ Screen screen;
31+ if (! screen.show(SDL_OPENGL)) {
32+ cout << "Screen::show(): " << screen.show() << endl;
33+ exit(1);
34+ }
3535
36- LayerManager layer_manager;
37- Layer layer;
38- layer_manager.push_front(&layer);
36+ LayerManager layer_manager;
37+ Layer layer;
38+ layer_manager.push_front(&layer);
3939
40- ColorSurface surface(Rect<long>(0, 0, 64, 64), Color(0.0, 0.0, 1.0));
41- Label label(surface);
42- layer.push_front(&label);
40+ ColorSurface surface(Rect<long>(0, 0, 64, 64), Color(0.0, 0.0, 1.0));
41+ Label label(surface);
42+ layer.push_front(&label);
4343
44- CallbackEvent quit_event;
45- setQuitEvent(&quit_event);
46- layer_manager.insertEvent(&quit_event);
44+ CallbackEvent quit_event;
45+ setQuitEvent(&quit_event);
46+ layer_manager.insertEvent(&quit_event);
4747
48- // 矩形の移動範囲を定義
49- Rect<long> screen_rect = screen.rect();
50- int left_edge = 100;
51- int right_edge = screen_rect.w - 100;
52- Point<long> position(left_edge, screen_rect.h / 2);
53- long xx = +1;
48+ // 矩形の移動範囲を定義
49+ Rect<long> screen_rect = screen.rect();
50+ int left_edge = 100;
51+ int right_edge = screen_rect.w - 100;
52+ Point<long> position(left_edge, screen_rect.h / 2);
53+ long xx = +1;
5454
55- bool quit = false;
56- while (! quit) {
55+ bool quit = false;
56+ while (! quit) {
5757
58- // 矩形の表示位置を更新
59- if (position.x > right_edge) {
60- xx = -1;
61- } else if (position.x < left_edge) {
62- xx = +1;
63- }
64- position.x += xx;
65- label.setPosition(position);
58+ // 矩形の表示位置を更新
59+ if (position.x > right_edge) {
60+ xx = -1;
61+ } else if (position.x < left_edge) {
62+ xx = +1;
63+ }
64+ position.x += xx;
65+ label.setPosition(position);
6666
67- layer_manager.updateEvent();
68- quit |= quit_event.isActive();
67+ layer_manager.updateEvent();
68+ quit |= quit_event.isActive();
6969
70- screen.clear();
71- layer_manager.draw();
72- layer_manager.swap();
70+ screen.clear();
71+ layer_manager.draw();
72+ layer_manager.swap();
7373
74- delay(10);
75- }
76- return 0;
74+ delay(10);
75+ }
76+ return 0;
7777 }
--- trunk/libs/gui/samples/chatMessageSample.cpp (revision 1813)
+++ trunk/libs/gui/samples/chatMessageSample.cpp (revision 1814)
@@ -25,50 +25,50 @@
2525
2626 int main(int argc, char *argv[])
2727 {
28- string font_file = "font.ttf";
29- if (argc >= 2) {
30- font_file = argv[1];
31- }
28+ string font_file = "font.ttf";
29+ if (argc >= 2) {
30+ font_file = argv[1];
31+ }
3232
33- Screen screen;
34- screen.show(SDL_OPENGL);
33+ Screen screen;
34+ screen.show(SDL_OPENGL);
3535
36- LayerManager layer_manager;
37- Layer layer;
38- layer_manager.push_back(&layer);
36+ LayerManager layer_manager;
37+ Layer layer;
38+ layer_manager.push_back(&layer);
3939
40- // 指定フォントからの文字列を作成
41- enum {
42- FontSize = 20,
43- };
44- Font font(font_file.c_str(), FontSize);
40+ // 指定フォントからの文字列を作成
41+ enum {
42+ FontSize = 20,
43+ };
44+ Font font(font_file.c_str(), FontSize);
4545
46- Rect<long> screen_rect = screen.rect();
47- Rect<long> message_rect = screen_rect;
48- message_rect.h = message_rect.h / 4;
49- ChatMessage message(font, message_rect);
50- message.setPosition(Point<long>(0, screen_rect.h - (screen_rect.h / 4)));
46+ Rect<long> screen_rect = screen.rect();
47+ Rect<long> message_rect = screen_rect;
48+ message_rect.h = message_rect.h / 4;
49+ ChatMessage message(font, message_rect);
50+ message.setPosition(Point<long>(0, screen_rect.h - (screen_rect.h / 4)));
5151
52- layer.push_front(&message);
52+ layer.push_front(&message);
5353
54- message.print("メッセージの表示サンプル");
55- message.newline();
54+ message.print("メッセージの表示サンプル");
55+ message.newline();
5656
57- message.print("2行目のメッセージ表示");
58- message.newline();
57+ message.print("2行目のメッセージ表示");
58+ message.newline();
5959
60- CallbackEvent quit_event;
61- setQuitEvent(&quit_event);
62- layer_manager.insertEvent(&quit_event);
60+ CallbackEvent quit_event;
61+ setQuitEvent(&quit_event);
62+ layer_manager.insertEvent(&quit_event);
6363
64- while (! quit_event.isActive()) {
64+ while (! quit_event.isActive()) {
6565
66- layer_manager.updateEvent();
66+ layer_manager.updateEvent();
6767
68- screen.clear();
69- layer_manager.draw();
70- layer_manager.swap();
71- delay(10);
72- }
73- return 0;
68+ screen.clear();
69+ layer_manager.draw();
70+ layer_manager.swap();
71+ delay(10);
72+ }
73+ return 0;
7474 }
--- trunk/libs/gui/samples/captionAndIcon.cpp (revision 1813)
+++ trunk/libs/gui/samples/captionAndIcon.cpp (revision 1814)
@@ -13,46 +13,46 @@
1313
1414 namespace
1515 {
16- void exitAndError(void)
17- {
18- printf("error: %s\n", SDL_GetError());
19- exit(1);
20- }
16+ void exitAndError(void)
17+ {
18+ printf("error: %s\n", SDL_GetError());
19+ exit(1);
20+ }
2121 }
2222
2323
2424 int main(int argc, char *argv[])
2525 {
26- static_cast<void>(argc);
27- static_cast<void>(argv);
26+ static_cast<void>(argc);
27+ static_cast<void>(argv);
2828
29- // SDL の初期化
30- if (SDL_Init(SDL_INIT_VIDEO) < 0) {
31- exitAndError();
32- }
29+ // SDL の初期化
30+ if (SDL_Init(SDL_INIT_VIDEO) < 0) {
31+ exitAndError();
32+ }
3333
34- // アイコンの登録
35- SDL_Surface* icon_surface = SDL_LoadBMP("cross_blue.bmp");
36- if (icon_surface) {
37- SDL_WM_SetIcon(icon_surface, NULL);
38- SDL_FreeSurface(icon_surface);
39- }
34+ // アイコンの登録
35+ SDL_Surface* icon_surface = SDL_LoadBMP("cross_blue.bmp");
36+ if (icon_surface) {
37+ SDL_WM_SetIcon(icon_surface, NULL);
38+ SDL_FreeSurface(icon_surface);
39+ }
4040
41- // 画面の作成
42- int bpp = 0; // デフォルトのピクセル深度を用いる
43- SDL_Surface* screen = SDL_SetVideoMode(640, 480, bpp, 0);
44- if (! screen) {
45- exitAndError();
46- }
41+ // 画面の作成
42+ int bpp = 0; // デフォルトのピクセル深度を用いる
43+ SDL_Surface* screen = SDL_SetVideoMode(640, 480, bpp, 0);
44+ if (! screen) {
45+ exitAndError();
46+ }
4747
48- // キャプションの設定
49- SDL_WM_SetCaption("Caption and Icon", "Caption and Icon");
48+ // キャプションの設定
49+ SDL_WM_SetCaption("Caption and Icon", "Caption and Icon");
5050
51- // 待機
52- SDL_Delay(3000);
51+ // 待機
52+ SDL_Delay(3000);
5353
54- // SDL の終了処理
55- SDL_Quit();
54+ // SDL の終了処理
55+ SDL_Quit();
5656
57- return 0;
57+ return 0;
5858 }
--- trunk/libs/gui/samples/simpleScreen.cpp (revision 1813)
+++ trunk/libs/gui/samples/simpleScreen.cpp (revision 1814)
@@ -13,41 +13,41 @@
1313
1414 namespace
1515 {
16- void exitAndError(void)
17- {
18- printf("error: %s\n", SDL_GetError());
19- exit(1);
20- }
16+ void exitAndError(void)
17+ {
18+ printf("error: %s\n", SDL_GetError());
19+ exit(1);
20+ }
2121 }
2222
2323
2424 int main(int argc, char *argv[])
2525 {
26- // "-f" が引数に渡されたらフルスクリーン画面にする
27- Uint32 flags = 0;
28- for (int i = 1; i < argc; ++i) {
29- if (! strcmp(argv[i], "-f")) {
30- flags |= SDL_FULLSCREEN;
26+ // "-f" が引数に渡されたらフルスクリーン画面にする
27+ Uint32 flags = 0;
28+ for (int i = 1; i < argc; ++i) {
29+ if (! strcmp(argv[i], "-f")) {
30+ flags |= SDL_FULLSCREEN;
31+ }
3132 }
32- }
3333
34- // SDL の初期化
35- if (SDL_Init(SDL_INIT_VIDEO) < 0) {
36- exitAndError();
37- }
34+ // SDL の初期化
35+ if (SDL_Init(SDL_INIT_VIDEO) < 0) {
36+ exitAndError();
37+ }
3838
39- // 画面の作成
40- int bpp = 0; // デフォルトのピクセル深度を用いる
41- SDL_Surface* screen = SDL_SetVideoMode(640, 480, bpp, flags);
42- if (! screen) {
43- exitAndError();
44- }
39+ // 画面の作成
40+ int bpp = 0; // デフォルトのピクセル深度を用いる
41+ SDL_Surface* screen = SDL_SetVideoMode(640, 480, bpp, flags);
42+ if (! screen) {
43+ exitAndError();
44+ }
4545
46- // 待機
47- SDL_Delay(1000);
46+ // 待機
47+ SDL_Delay(1000);
4848
49- // SDL の終了処理
50- SDL_Quit();
49+ // SDL の終了処理
50+ SDL_Quit();
5151
52- return 0;
52+ return 0;
5353 }
--- trunk/libs/gui/samples/handleEvent.cpp (revision 1813)
+++ trunk/libs/gui/samples/handleEvent.cpp (revision 1814)
@@ -20,63 +20,63 @@
2020
2121 namespace
2222 {
23- void enterCallback(void)
24- {
25- cout << "return key pressed." << endl;
26- }
23+ void enterCallback(void)
24+ {
25+ cout << "return key pressed." << endl;
26+ }
2727 }
2828
2929
3030 int main(int argc, char *argv[])
3131 {
32- static_cast<void>(argc);
33- static_cast<void>(argv);
32+ static_cast<void>(argc);
33+ static_cast<void>(argv);
3434
35- Screen screen;
36- if (! screen.show()) {
37- cout << "Screen::show: " << screen.what() << endl;
38- exit(1);
39- }
35+ Screen screen;
36+ if (! screen.show()) {
37+ cout << "Screen::show: " << screen.what() << endl;
38+ exit(1);
39+ }
4040
41- // 複数イベントを登録した場合
42- CallbackEvent quit_event;
43- quit_event.key(SDLK_ESCAPE);
44- quit_event.key(SDLK_q, SDL_KEYDOWN, KMOD_LCTRL);
45- quit_event.key(SDLK_q, SDL_KEYDOWN, KMOD_RCTRL);
46- quit_event.key(SDLK_F4, SDL_KEYDOWN, KMOD_LALT);
47- quit_event.key(SDLK_F4, SDL_KEYDOWN, KMOD_RALT);
41+ // 複数イベントを登録した場合
42+ CallbackEvent quit_event;
43+ quit_event.key(SDLK_ESCAPE);
44+ quit_event.key(SDLK_q, SDL_KEYDOWN, KMOD_LCTRL);
45+ quit_event.key(SDLK_q, SDL_KEYDOWN, KMOD_RCTRL);
46+ quit_event.key(SDLK_F4, SDL_KEYDOWN, KMOD_LALT);
47+ quit_event.key(SDLK_F4, SDL_KEYDOWN, KMOD_RALT);
4848
49- // ポーリングのみで使う場合
50- CallbackEvent space_event;
51- space_event.key(SDLK_SPACE);
49+ // ポーリングのみで使う場合
50+ CallbackEvent space_event;
51+ space_event.key(SDLK_SPACE);
5252
53- // コールバックで使う場合
54- CallbackEvent enter_event;
55- enter_event.key(SDLK_RETURN);
56- enter_event.key(SDLK_KP_ENTER);
57- enter_event.setCallback(enterCallback);
53+ // コールバックで使う場合
54+ CallbackEvent enter_event;
55+ enter_event.key(SDLK_RETURN);
56+ enter_event.key(SDLK_KP_ENTER);
57+ enter_event.setCallback(enterCallback);
5858
59- cout << "hit enter key, or space key." << endl;
59+ cout << "hit enter key, or space key." << endl;
6060
61- LayerManager layer_manager;
62- layer_manager.insertEvent(&quit_event);
63- layer_manager.insertEvent(&enter_event);
64- layer_manager.insertEvent(&space_event);
61+ LayerManager layer_manager;
62+ layer_manager.insertEvent(&quit_event);
63+ layer_manager.insertEvent(&enter_event);
64+ layer_manager.insertEvent(&space_event);
6565
66- bool quit = false;
67- while (! quit) {
68- layer_manager.updateEvent();
66+ bool quit = false;
67+ while (! quit) {
68+ layer_manager.updateEvent();
6969
70- if (quit_event.isActive()) {
71- quit = true;
70+ if (quit_event.isActive()) {
71+ quit = true;
72+ }
73+ if (space_event.isActive()) {
74+ cout << "space key pressed." << endl;
75+ }
76+
77+ delay(10);
7278 }
73- if (space_event.isActive()) {
74- cout << "space key pressed." << endl;
75- }
79+ layer_manager.clearEvent();
7680
77- delay(10);
78- }
79- layer_manager.clearEvent();
80-
81- return 0;
81+ return 0;
8282 }
旧リポジトリブラウザで表示