comparison window/event.cc @ 52:15a18fbe6f21

* Known bugs added to the README * Code cleaning (0 -> NULL when needed, indentation, spaces, ...)
author thib
date Sat, 18 Apr 2009 18:35:39 +0000
parents ed6c21dde840
children 4416cfac86ae
comparison
equal deleted inserted replaced
51:cbb301016a4e 52:15a18fbe6f21
23 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 23 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
25 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */ 26 */
27 27
28 #include"SDL.h" 28 #include "SDL.h"
29 #include"event.h" 29 #include "event.h"
30 #include<vector> 30 #include <vector>
31 #include<list> 31 #include <list>
32 #include<algorithm> 32 #include <algorithm>
33 #include<iostream> 33 #include <iostream>
34 #include<sys/stat.h> 34 #include <sys/stat.h>
35 35
36 using namespace std; 36 using namespace std;
37 37
38 bool save_req = false, load_req = false, grpdump_req = false; // scn2k/scn2k_impl.cc: キーボードからセーブ・ロードできるように 38 bool save_req = false, load_req = false, grpdump_req = false; // scn2k/scn2k_impl.cc: キーボードからセーブ・ロードできるように
39 bool pressAreq=false,pressFreq=false,pressDreq=false; 39 bool pressAreq=false,pressFreq=false,pressDreq=false;
127 } 127 }
128 void ContainerImplTime::Delete(Time* delete_event) { 128 void ContainerImplTime::Delete(Time* delete_event) {
129 iterator it = find(begin(), end(), delete_event); 129 iterator it = find(begin(), end(), delete_event);
130 if (it != end()) { 130 if (it != end()) {
131 it->valid = false; 131 it->valid = false;
132 it->instance = 0; 132 it->instance = NULL;
133 return; 133 return;
134 } 134 }
135 it = find(new_item.begin(), new_item.end(), delete_event); 135 it = find(new_item.begin(), new_item.end(), delete_event);
136 if (it != end()) { 136 if (it != end()) {
137 it->valid = false; 137 it->valid = false;
138 it->instance = 0; 138 it->instance = NULL;
139 return; 139 return;
140 } 140 }
141 return; 141 }
142 } 142
143 bool ContainerImplTime::Exec(unsigned int current_time) { 143 bool ContainerImplTime::Exec(unsigned int current_time) {
144 if (current_time == Time::NEVER_WAKE) return true; 144 if (current_time == Time::NEVER_WAKE) return true;
145 // 呼び出しまでに作製されたitemを追加 145 // 呼び出しまでに作製されたitemを追加
146 insert(end(), new_item.begin(), new_item.end()); 146 insert(end(), new_item.begin(), new_item.end());
147 new_item.clear(); 147 new_item.clear();
171 return true; 171 return true;
172 } 172 }
173 173
174 174
175 class ContainerImplVideo : private vector<Video*> { 175 class ContainerImplVideo : private vector<Video*> {
176 public: 176 public:
177 bool Exec(void); 177 bool Exec(void);
178 178
179 ContainerImplVideo(void); 179 ContainerImplVideo(void);
180 ~ContainerImplVideo(); 180 ~ContainerImplVideo();
181 void Add(Video* item); 181 void Add(Video* item);
182 void Delete(Video* item); 182 void Delete(Video* item);
183 void RegisterGlobalMotionFunc(Container::motionfunc, void* pointer); 183 void RegisterGlobalMotionFunc(Container::motionfunc, void* pointer);
184 void DeleteGlobalMotionFunc(Container::motionfunc, void* pointer); 184 void DeleteGlobalMotionFunc(Container::motionfunc, void* pointer);
185 void RegisterGlobalPressFunc(Container::motionfunc, void* pointer); 185 void RegisterGlobalPressFunc(Container::motionfunc, void* pointer);
186 void DeleteGlobalPressFunc(Container::motionfunc, void* pointer); 186 void DeleteGlobalPressFunc(Container::motionfunc, void* pointer);
187 private: 187 private:
188 struct Motionfunc { 188 struct Motionfunc {
189 Container::motionfunc func; 189 Container::motionfunc func;
190 void* pointer; 190 void* pointer;
191 bool operator ==(const Motionfunc& m) const { return func == m.func && pointer == m.pointer;} 191 bool operator ==(const Motionfunc& m) const { return func == m.func && pointer == m.pointer;}
192 }; 192 };
193 list<Motionfunc> motion_vec; 193 list<Motionfunc> motion_vec;
194 list<Motionfunc> press_vec; 194 list<Motionfunc> press_vec;
195 typedef list<Motionfunc>::iterator MotionIterator; 195 typedef list<Motionfunc>::iterator MotionIterator;
196 bool is_sorted; 196 bool is_sorted;
197 public: 197 public:
198 int button_pressed; 198 int button_pressed;
199 int button_released; 199 int button_released;
200 int mouse_x, mouse_y; 200 int mouse_x, mouse_y;
201 int new_mouse_x, new_mouse_y; 201 int new_mouse_x, new_mouse_y;
202 private: 202 private:
203 void SetChanged(void); 203 void SetChanged(void);
204 static bool SortLess(const Video* pos1, const Video* pos2) { 204 static bool SortLess(const Video* pos1, const Video* pos2) {
205 return pos1 < pos2; 205 return pos1 < pos2;
206 } 206 }
207 void Sort(void); 207 void Sort(void);
208 void Motion(int x, int y); // mouse motion 208 void Motion(int x, int y); // mouse motion
209 void Press(void); 209 void Press(void);
210 void TakeScreenshot(void); 210 void TakeScreenshot(void);
211 iterator cur_pos; 211 iterator cur_pos;
212 Video* cur_item; // 現在のフォーカス位置 212 Video* cur_item; // 現在のフォーカス位置
213 int cur_pressed_x, cur_pressed_y; 213 int cur_pressed_x, cur_pressed_y;
214 }; 214 };
215 215
216 void ContainerImplVideo::SetChanged(void) { 216 void ContainerImplVideo::SetChanged(void) {
217 if (is_sorted) { 217 if (is_sorted) {
218 if (cur_item) { 218 if (cur_item != NULL) {
219 cur_pos = find(begin(), end(), cur_item); 219 cur_pos = find(begin(), end(), cur_item);
220 if (cur_pos == end()) cur_item = 0; 220 if (cur_pos == end()) cur_item = NULL;
221 } 221 }
222 is_sorted = false; 222 is_sorted = false;
223 } 223 }
224 } 224 }
225 225
226 void ContainerImplVideo::Sort(void) { 226 void ContainerImplVideo::Sort(void) {
227 sort(begin(), end(), SortLess); 227 sort(begin(), end(), SortLess);
228 if (cur_item) { 228 if (cur_item != NULL) {
229 cur_pos = lower_bound(begin(), end(), cur_item, SortLess); 229 cur_pos = lower_bound(begin(), end(), cur_item, SortLess);
230 } else { 230 } else {
231 cur_pos = end(); 231 cur_pos = end();
232 } 232 }
233 is_sorted = true; 233 is_sorted = true;
235 235
236 ContainerImplVideo::ContainerImplVideo(void) { 236 ContainerImplVideo::ContainerImplVideo(void) {
237 is_sorted = false; 237 is_sorted = false;
238 button_pressed = 0; 238 button_pressed = 0;
239 button_released = 0; 239 button_released = 0;
240 cur_item = 0; 240 cur_item = NULL;
241 mouse_x = 0; mouse_y = 0; 241 mouse_x = 0; mouse_y = 0;
242 new_mouse_x = 0; new_mouse_y = 0; 242 new_mouse_x = 0; new_mouse_y = 0;
243 } 243 }
244
244 ContainerImplVideo::~ContainerImplVideo(void) { 245 ContainerImplVideo::~ContainerImplVideo(void) {
245 }; 246 };
247
246 void ContainerImplVideo::Add(Video* event) { 248 void ContainerImplVideo::Add(Video* event) {
247 push_back(event); 249 push_back(event);
248 SetChanged(); 250 SetChanged();
249 } 251 }
252
250 void ContainerImplVideo::Delete(Video* delete_event) { 253 void ContainerImplVideo::Delete(Video* delete_event) {
251 iterator it = find(begin(), end(), delete_event); 254 iterator it = find(begin(), end(), delete_event);
252 if (it != end()) { 255 if (it != end()) {
253 erase(it); 256 erase(it);
254 SetChanged(); 257 SetChanged();
262 } 265 }
263 fprintf(stderr,"\n"); 266 fprintf(stderr,"\n");
264 } 267 }
265 if (delete_event == cur_item) { 268 if (delete_event == cur_item) {
266 cur_pos = end(); 269 cur_pos = end();
267 cur_item = 0; 270 cur_item = NULL;
268 Motion(mouse_x, mouse_y); 271 Motion(mouse_x, mouse_y);
269 } 272 }
270 return; 273 }
271 } 274
272 void ContainerImplVideo::RegisterGlobalMotionFunc(Container::motionfunc func, void* pointer) { 275 void ContainerImplVideo::RegisterGlobalMotionFunc(Container::motionfunc func, void* pointer) {
273 Motionfunc f; 276 Motionfunc f;
274 f.func = func; 277 f.func = func;
275 f.pointer = pointer; 278 f.pointer = pointer;
276 if (find(motion_vec.begin(), motion_vec.end(), f) == motion_vec.end()) { 279 if (find(motion_vec.begin(), motion_vec.end(), f) == motion_vec.end()) {
277 motion_vec.push_back(f); 280 motion_vec.push_back(f);
278 } 281 }
279 } 282 }
283
280 void ContainerImplVideo::DeleteGlobalMotionFunc(Container::motionfunc func, void* pointer) { 284 void ContainerImplVideo::DeleteGlobalMotionFunc(Container::motionfunc func, void* pointer) {
281 Motionfunc f; 285 Motionfunc f;
282 f.func = func; 286 f.func = func;
283 f.pointer = pointer; 287 f.pointer = pointer;
284 list<Motionfunc>::iterator it = find(motion_vec.begin(), motion_vec.end(), f); 288 list<Motionfunc>::iterator it = find(motion_vec.begin(), motion_vec.end(), f);
285 if (it != motion_vec.end()) 289 if (it != motion_vec.end())
286 motion_vec.erase(it); 290 motion_vec.erase(it);
287 return; 291 }
288 } 292
289 void ContainerImplVideo::RegisterGlobalPressFunc(Container::motionfunc func, void* pointer) { 293 void ContainerImplVideo::RegisterGlobalPressFunc(Container::motionfunc func, void* pointer) {
290 Motionfunc f; 294 Motionfunc f;
291 f.func = func; 295 f.func = func;
292 f.pointer = pointer; 296 f.pointer = pointer;
293 if (find(press_vec.begin(), press_vec.end(), f) == press_vec.end()) { 297 if (find(press_vec.begin(), press_vec.end(), f) == press_vec.end()) {
294 press_vec.push_back(f); 298 press_vec.push_back(f);
295 } 299 }
296 } 300 }
301
297 void ContainerImplVideo::DeleteGlobalPressFunc(Container::motionfunc func, void* pointer) { 302 void ContainerImplVideo::DeleteGlobalPressFunc(Container::motionfunc func, void* pointer) {
298 Motionfunc f; 303 Motionfunc f;
299 f.func = func; 304 f.func = func;
300 f.pointer = pointer; 305 f.pointer = pointer;
301 list<Motionfunc>::iterator it = find(press_vec.begin(), press_vec.end(), f); 306 list<Motionfunc>::iterator it = find(press_vec.begin(), press_vec.end(), f);
302 if (it != press_vec.end()) 307 if (it != press_vec.end())
303 press_vec.erase(it); 308 press_vec.erase(it);
304 return; 309 }
305 } 310
306 void ContainerImplVideo::Motion(int x, int y) { 311 void ContainerImplVideo::Motion(int x, int y) {
307 mouse_x = x; mouse_y = y; 312 mouse_x = x; mouse_y = y;
308 MotionIterator mit; 313 MotionIterator mit;
309 for (mit=motion_vec.begin(); mit != motion_vec.end();) { 314 for (mit=motion_vec.begin(); mit != motion_vec.end();) {
310 MotionIterator mit_next = mit; 315 MotionIterator mit_next = mit;
317 /* @@@ ドラッグ処理とマウスを押す処理のバッティングで「二回ボタンを押さないと云々」関連のバグの可能性あり */ 322 /* @@@ ドラッグ処理とマウスを押す処理のバッティングで「二回ボタンを押さないと云々」関連のバグの可能性あり */
318 if (button_pressed & (1<<MOUSE_LEFT)) { 323 if (button_pressed & (1<<MOUSE_LEFT)) {
319 if (cur_item) cur_item->Drag(cur_pressed_x, cur_pressed_y, x, y); 324 if (cur_item) cur_item->Drag(cur_pressed_x, cur_pressed_y, x, y);
320 return; 325 return;
321 } 326 }
322 if (cur_item) cur_item->Motion(x,y); 327 if (cur_item != NULL) cur_item->Motion(x,y);
323 int z = -1; iterator z_it; 328 int z = -1; iterator z_it;
324 iterator it; 329 iterator it;
325 for (it = begin(); it != end(); it++) { 330 for (it = begin(); it != end(); it++) {
326 int new_z = (*it)->point_in(x, y); 331 int new_z = (*it)->point_in(x, y);
327 if (z < new_z) { 332 if (z < new_z) {
337 cur_item->In(); 342 cur_item->In();
338 return; 343 return;
339 } else { 344 } else {
340 if (cur_item) cur_item->Out(); 345 if (cur_item) cur_item->Out();
341 cur_pos = end(); 346 cur_pos = end();
342 cur_item = 0; 347 cur_item = NULL;
343 } 348 }
344 return; 349 return;
345 } 350 }
346 351
347 void ContainerImplVideo::Press(void) { 352 void ContainerImplVideo::Press(void) {
359 press_vec.erase(mit); 364 press_vec.erase(mit);
360 } 365 }
361 mit = mit_next; 366 mit = mit_next;
362 } 367 }
363 } 368 }
369
364 void ContainerImplVideo::TakeScreenshot(void) { 370 void ContainerImplVideo::TakeScreenshot(void) {
365 int n=0; 371 int n=0;
366 char filename[1024]; 372 char filename[1024];
367 struct stat buffer; 373 struct stat buffer;
368 for(n=0; n<9999; n++) { 374 for(n=0; n<9999; n++) {
370 sprintf(filename, "xclannad_%04i.bmp", n); 376 sprintf(filename, "xclannad_%04i.bmp", n);
371 if(stat(filename, &buffer) == -1) break; 377 if(stat(filename, &buffer) == -1) break;
372 } 378 }
373 SDL_SaveBMP(SDL_GetVideoSurface(), filename); 379 SDL_SaveBMP(SDL_GetVideoSurface(), filename);
374 } 380 }
381
375 bool ContainerImplVideo::Exec(void) { 382 bool ContainerImplVideo::Exec(void) {
376
377 bool is_mouse_motion = false; 383 bool is_mouse_motion = false;
378 int motion_x = 0, motion_y = 0; 384 int motion_x = 0, motion_y = 0;
379 SDL_Event event; 385 SDL_Event event;
380 SDL_PumpEvents(); 386 SDL_PumpEvents();
381 while(SDL_PeepEvents(&event, 1, SDL_GETEVENT, SDL_ALLEVENTS) == 1) { 387 while(SDL_PeepEvents(&event, 1, SDL_GETEVENT, SDL_ALLEVENTS) == 1) {
382 switch(event.type) { 388 switch(event.type) {
383 case SDL_QUIT: return false; // @@@ なにかやらないと 389 case SDL_QUIT: return false; // @@@ なにかやらないと
384 case SDL_ACTIVEEVENT: // なにもしない 390 case SDL_ACTIVEEVENT: // なにもしない
385 // cout<<"active : gain "<<int(event.active.gain)<<", state "<<int(event.active.state)<<endl; 391 // cout<<"active : gain "<<int(event.active.gain)<<", state "<<int(event.active.state)<<endl;
386 break;
387 case SDL_KEYDOWN:
388 if (!is_sorted) Sort();
389 switch(event.key.keysym.sym) {
390 case SDLK_F12:
391 case SDLK_PRINT:
392 case SDLK_p: // for Zaurus
393 TakeScreenshot();
394 break; 392 break;
395 // Some window managers (eg enlightenment) use Alt-Enter for 393 case SDL_KEYDOWN:
396 // themselves, F11 is a good alternative 394 if (!is_sorted) Sort();
397 case SDLK_F11: 395 switch(event.key.keysym.sym) {
398 SDL_WM_ToggleFullScreen(SDL_GetVideoSurface()); 396 case SDLK_F12:
399 break; 397 case SDLK_PRINT:
400 case SDLK_RETURN: 398 case SDLK_p: // for Zaurus
401 if (SDL_GetModState() & KMOD_ALT) { 399 TakeScreenshot();
402 SDL_WM_ToggleFullScreen(SDL_GetVideoSurface()); 400 break;
403 break; 401 // Some window managers (eg enlightenment) use Alt-Enter for
404 } 402 // themselves, F11 is a good alternative
405 case SDLK_SPACE: 403 case SDLK_F11:
406 Press(); 404 SDL_WM_ToggleFullScreen(SDL_GetVideoSurface());
407 break; 405 break;
408 case SDLK_TAB: // move to next widget 406 case SDLK_RETURN:
409 if (cur_pos != end()) cur_pos++; 407 if (SDL_GetModState() & KMOD_ALT) {
410 if (cur_pos == end()) cur_pos = begin(); 408 SDL_WM_ToggleFullScreen(SDL_GetVideoSurface());
411 if (cur_pos != end()) { 409 break;
412 cur_item = *cur_pos; 410 }
413 cur_item->In(); 411 case SDLK_SPACE:
414 } else { 412 Press();
415 cur_item = 0; 413 break;
414 case SDLK_TAB: // move to next widget
415 if (cur_pos != end()) cur_pos++;
416 if (cur_pos == end()) cur_pos = begin();
417 if (cur_pos != end()) {
418 cur_item = *cur_pos;
419 cur_item->In();
420 } else {
421 cur_item = NULL;
422 }
423 break;
424 case SDLK_LEFT: if (cur_pos != end()) (*cur_pos)->KeyLeft(); break;
425 case SDLK_RIGHT:if (cur_pos != end()) (*cur_pos)->KeyRight(); break;
426 case SDLK_LSHIFT: case SDLK_RSHIFT: button_pressed |= (1<<KEY_SHIFT); break;
427 case SDLK_ESCAPE: button_pressed |= (1<<MOUSE_RIGHT); break; /* for Zaurus */
428 case SDLK_s: save_req = true; break;
429 case SDLK_l: load_req = true; break;
430 case SDLK_g: grpdump_req = true; break;
431 case SDLK_a: pressAreq = true; break;
432 case SDLK_d: pressDreq = true; break;
433 case SDLK_f: pressFreq = true; break;
416 } 434 }
417 break; 435 break;
418 case SDLK_LEFT: if (cur_pos != end()) (*cur_pos)->KeyLeft(); break; 436 case SDL_KEYUP:
419 case SDLK_RIGHT:if (cur_pos != end()) (*cur_pos)->KeyRight(); break; 437 // cout << "keyup which "<<int(event.key.which)<<", sym "<<int(event.key.keysym.sym)<<endl;
420 case SDLK_LSHIFT: case SDLK_RSHIFT: button_pressed |= (1<<KEY_SHIFT); break; 438 switch(event.key.keysym.sym) {
421 case SDLK_ESCAPE: button_pressed |= (1<<MOUSE_RIGHT); break; /* for Zaurus */ 439 case SDLK_RETURN: case SDLK_SPACE:
422 case SDLK_s: save_req = true; break; 440 if (cur_item) cur_item->Release();
423 case SDLK_l: load_req = true; break; 441 case SDLK_LSHIFT: case SDLK_RSHIFT: button_pressed &= ~(1<<KEY_SHIFT); button_released |= 1<<KEY_SHIFT; break;
424 case SDLK_g: grpdump_req = true; break; 442 case SDLK_ESCAPE: button_pressed &= ~(1<<MOUSE_RIGHT); button_released |= 1<<MOUSE_RIGHT; break; /* for Zaurus */
425 case SDLK_a: pressAreq = true; break; 443 }
426 case SDLK_d: pressDreq = true; break; 444 break;
427 case SDLK_f: pressFreq = true; break; 445 case SDL_MOUSEMOTION:
428 } 446 motion_x = event.motion.x;
429 break; 447 motion_y = event.motion.y;
430 case SDL_KEYUP: 448 is_mouse_motion = true;
431 // cout << "keyup which "<<int(event.key.which)<<", sym "<<int(event.key.keysym.sym)<<endl; 449 // Motion(event.motion.x, event.motion.y);
432 switch(event.key.keysym.sym) { 450 // cout<< "motion which "<<int(event.motion.which)<<
433 case SDLK_RETURN: case SDLK_SPACE: 451 // "x "<<event.motion.x << "y "<<event.motion.y<<endl;
434 if (cur_item) cur_item->Release(); 452 break;
435 case SDLK_LSHIFT: case SDLK_RSHIFT: button_pressed &= ~(1<<KEY_SHIFT); button_released |= 1<<KEY_SHIFT; break; 453 case SDL_MOUSEBUTTONUP:
436 case SDLK_ESCAPE: button_pressed &= ~(1<<MOUSE_RIGHT); button_released |= 1<<MOUSE_RIGHT; break; /* for Zaurus */ 454 if (event.button.button == 1) {
437 } 455 Motion(event.button.x, event.button.y);
438 break; 456 is_mouse_motion = false;
439 case SDL_MOUSEMOTION: 457 if (cur_item) cur_item->Release();
440 motion_x = event.motion.x; 458 }
441 motion_y = event.motion.y; 459 switch(event.button.button) {
442 is_mouse_motion = true; 460 case 1:
443 // Motion(event.motion.x, event.motion.y); 461 button_pressed &= ~(1<<MOUSE_LEFT);
444 // cout<< "motion which "<<int(event.motion.which)<< 462 button_released |= 1<<MOUSE_LEFT;
445 // "x "<<event.motion.x << "y "<<event.motion.y<<endl; 463 break;
446 break; 464 case 2:
447 case SDL_MOUSEBUTTONUP: 465 button_pressed &= ~(1<<MOUSE_MIDDLE);
448 if (event.button.button == 1) { 466 button_released |= 1<<MOUSE_MIDDLE;
449 Motion(event.button.x, event.button.y); 467 break;
450 is_mouse_motion = false; 468 case 3:
451 if (cur_item) cur_item->Release(); 469 button_pressed &= ~(1<<MOUSE_RIGHT);
452 } 470 button_released |= 1<<MOUSE_RIGHT;
453 switch(event.button.button) { 471 break;
454 case 1: button_pressed &= ~(1<<MOUSE_LEFT); button_released |= 1<<MOUSE_LEFT; break; 472 case 4:
455 case 2: button_pressed &= ~(1<<MOUSE_MIDDLE); button_released |= 1<<MOUSE_MIDDLE; break; 473 button_pressed &= ~(1<<MOUSE_UP);
456 case 3: button_pressed &= ~(1<<MOUSE_RIGHT); button_released |= 1<<MOUSE_RIGHT; break; 474 button_released |= 1<<MOUSE_UP;
457 case 4: button_pressed &= ~(1<<MOUSE_UP); button_released |= 1<<MOUSE_UP; break; 475 break;
458 case 5: button_pressed &= ~(1<<MOUSE_DOWN); button_released |= 1<<MOUSE_DOWN; break; 476 case 5:
459 } 477 button_pressed &= ~(1<<MOUSE_DOWN);
460 break; 478 button_released |= 1<<MOUSE_DOWN;
461 case SDL_MOUSEBUTTONDOWN: 479 break;
462 if (event.button.button == 1) { 480 }
463 Motion(event.button.x, event.button.y); 481 break;
464 is_mouse_motion = false; 482 case SDL_MOUSEBUTTONDOWN:
465 Press(); 483 if (event.button.button == 1) {
466 } 484 Motion(event.button.x, event.button.y);
467 switch(event.button.button) { 485 is_mouse_motion = false;
468 case 1: button_pressed |= (1<<MOUSE_LEFT); break; 486 Press();
469 case 2: button_pressed |= (1<<MOUSE_MIDDLE); break; 487 }
470 case 3: button_pressed |= (1<<MOUSE_RIGHT); break; 488 switch(event.button.button) {
471 case 4: button_pressed |= (1<<MOUSE_UP); break; 489 case 1: button_pressed |= (1<<MOUSE_LEFT); break;
472 case 5: button_pressed |= (1<<MOUSE_DOWN); break; 490 case 2: button_pressed |= (1<<MOUSE_MIDDLE); break;
473 } 491 case 3: button_pressed |= (1<<MOUSE_RIGHT); break;
474 // cout << "mouse which "<<int(event.button.which)<<"button "<<int(event.button.button)<< 492 case 4: button_pressed |= (1<<MOUSE_UP); break;
475 // "state "<<int(event.button.state)<<"x "<<event.button.x << "y "<<event.button.y<<endl; 493 case 5: button_pressed |= (1<<MOUSE_DOWN); break;
476 break; 494 }
477 case SDL_VIDEOEXPOSE: // redraw の必要がある? 495 // cout << "mouse which "<<int(event.button.which)<<"button "<<int(event.button.button)<<
478 // cout<<"expose."<<endl; 496 // "state "<<int(event.button.state)<<"x "<<event.button.x << "y "<<event.button.y<<endl;
479 break; 497 break;
498 case SDL_VIDEOEXPOSE: // redraw の必要がある?
499 // cout<<"expose."<<endl;
500 break;
480 } 501 }
481 } 502 }
482 // Motion 呼び出しは一回だけ 503 // Motion 呼び出しは一回だけ
483 if (is_mouse_motion) 504 if (is_mouse_motion)
484 Motion(motion_x, motion_y); 505 Motion(motion_x, motion_y);
485 return true; 506 return true;
486 }; 507 }
508
487 /* Impl: struct Event::Container */ 509 /* Impl: struct Event::Container */
488 Container::Container(void) { 510 Container::Container(void) {
489 pimpl_video = new ContainerImplVideo; 511 pimpl_video = new ContainerImplVideo;
490 try { 512 try {
491 pimpl_time = new ContainerImplTime; 513 pimpl_time = new ContainerImplTime;
493 delete pimpl_video; 515 delete pimpl_video;
494 throw; 516 throw;
495 } 517 }
496 button_pressed = 0; 518 button_pressed = 0;
497 current_time = 0; 519 current_time = 0;
498 int i; for (i=0; i<BUTTON_MAX; i++) button_presscount[i] = 0; 520 int i;
499 return; 521 for (i=0; i<BUTTON_MAX; i++) button_presscount[i] = 0;
500 } 522 }
523
501 Container::~Container(void) { 524 Container::~Container(void) {
502 delete pimpl_video; 525 delete pimpl_video;
503 delete pimpl_time; 526 delete pimpl_time;
504 } 527 }
528
505 void Container::Add(Video* item) { 529 void Container::Add(Video* item) {
506 pimpl_video->Add(item); 530 pimpl_video->Add(item);
507 } 531 }
532
508 void Container::Delete(Video* item) { 533 void Container::Delete(Video* item) {
509 pimpl_video->Delete(item); 534 pimpl_video->Delete(item);
510 } 535 }
536
511 void Container::Add(Time* item) { 537 void Container::Add(Time* item) {
512 pimpl_time->Add(item); 538 pimpl_time->Add(item);
513 } 539 }
540
514 void Container::Delete(Time* item) { 541 void Container::Delete(Time* item) {
515 pimpl_time->Delete(item); 542 pimpl_time->Delete(item);
516 } 543 }
544
517 void Container::RegisterGlobalMotionFunc(Container::motionfunc f, void* pointer) { 545 void Container::RegisterGlobalMotionFunc(Container::motionfunc f, void* pointer) {
518 pimpl_video->RegisterGlobalMotionFunc(f, pointer); 546 pimpl_video->RegisterGlobalMotionFunc(f, pointer);
519 } 547 }
548
520 void Container::DeleteGlobalMotionFunc(Container::motionfunc f, void* pointer) { 549 void Container::DeleteGlobalMotionFunc(Container::motionfunc f, void* pointer) {
521 pimpl_video->DeleteGlobalMotionFunc(f, pointer); 550 pimpl_video->DeleteGlobalMotionFunc(f, pointer);
522 } 551 }
552
523 void Container::RegisterGlobalPressFunc(Container::motionfunc f, void* pointer) { 553 void Container::RegisterGlobalPressFunc(Container::motionfunc f, void* pointer) {
524 pimpl_video->RegisterGlobalPressFunc(f, pointer); 554 pimpl_video->RegisterGlobalPressFunc(f, pointer);
525 } 555 }
556
526 void Container::DeleteGlobalPressFunc(Container::motionfunc f, void* pointer) { 557 void Container::DeleteGlobalPressFunc(Container::motionfunc f, void* pointer) {
527 pimpl_video->DeleteGlobalPressFunc(f, pointer); 558 pimpl_video->DeleteGlobalPressFunc(f, pointer);
528 } 559 }
560
529 bool Container::Exec(unsigned int time) { 561 bool Container::Exec(unsigned int time) {
530 current_time = time; 562 current_time = time;
531 bool ret = true; 563 bool ret = true;
532 ret = ret && pimpl_video->Exec(); 564 ret = ret && pimpl_video->Exec();
533 ret = ret && pimpl_time->Exec(time); 565 ret = ret && pimpl_time->Exec(time);
551 583
552 bool Container::pressed(int mask) { 584 bool Container::pressed(int mask) {
553 if (mask < 0 || mask >= BUTTON_MAX) return 0; 585 if (mask < 0 || mask >= BUTTON_MAX) return 0;
554 return (button_pressed & (1<<mask)) != 0; 586 return (button_pressed & (1<<mask)) != 0;
555 } 587 }
588
556 bool Container::presscount(int mask) { 589 bool Container::presscount(int mask) {
557 if (mask < 0 || mask >= BUTTON_MAX) return 0; 590 if (mask < 0 || mask >= BUTTON_MAX) return 0;
558 int count = button_presscount[mask]; 591 int count = button_presscount[mask];
559 button_presscount[mask] = 0; 592 button_presscount[mask] = 0;
560 return count; 593 return count;
561 } 594 }
562 595
563 }; /* end of namespace Container */ 596 } /* end of namespace Container */
564 597
565 // 問題: 598 // 問題:
566 // z 軸と xy 軸の相互干渉;高速化 599 // z 軸と xy 軸の相互干渉;高速化
567 // 移動するウィジット描画の高速化 600 // 移動するウィジット描画の高速化
568 // キャッシュ 601 // キャッシュ