Mercurial > otakunoraifu
comparison window/event.h @ 0:223b71206888
Initial import
author | thib |
---|---|
date | Fri, 01 Aug 2008 16:32:45 +0000 |
parents | |
children | 5ae5533b3a9a |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:223b71206888 |
---|---|
1 #ifndef __EVENT__ | |
2 #define __EVENT__ | |
3 | |
4 #include"rect.h" | |
5 #include"SDL.h" | |
6 | |
7 namespace Event { | |
8 | |
9 class Video; | |
10 class Time; | |
11 class Container; | |
12 | |
13 /* | |
14 ** マウスの press, ドラッグ、in/out を検出できる | |
15 ** focus がある時の left/right/space(==press) のキーを判別できる | |
16 */ | |
17 struct Video { | |
18 virtual void Press(void) {} | |
19 virtual void Release(void) {} | |
20 virtual void Drag(int x_from, int y_from, int x_to, int y_to) {} | |
21 virtual void Motion(int x, int y) {} | |
22 virtual void In(void) {} | |
23 virtual void Out(void) {} | |
24 virtual void KeyLeft(void) {} | |
25 virtual void KeyRight(void) {} | |
26 | |
27 int point_in(int x, int y); /* z or -1 を返す。大きいほど高いところにある */ | |
28 | |
29 Video(Container& container); | |
30 Video(Container& container, const Rect& init_rect); | |
31 Video(Container& container, const Rect& init_rect, int z); | |
32 void SetRegion(const Rect& new_rect); | |
33 void SetZ(int new_z); | |
34 void activate(void); | |
35 void deactivate(void); | |
36 virtual ~Video(); | |
37 | |
38 Rect Region(void) const { return region;} | |
39 private: | |
40 Rect region; | |
41 int z; | |
42 Container& parent; | |
43 bool activated; | |
44 friend bool operator <(const Video& position1, const Video& position2); | |
45 }; | |
46 | |
47 struct Time { | |
48 enum { NEVER_WAKE = 0xffffffff, FRAME_UPDATE = 0xfffffffe}; | |
49 virtual void Elapsed(unsigned int current_time) {wakeup_time = NEVER_WAKE; }; /* next: never elapsed */ | |
50 void SetWakeup(unsigned int new_wakeup_time) { wakeup_time = new_wakeup_time; } | |
51 unsigned Wakeup(void) const { return wakeup_time; } | |
52 | |
53 Time(Container& container); | |
54 ~Time(); | |
55 private: | |
56 unsigned int wakeup_time; | |
57 Container& parent; | |
58 }; | |
59 | |
60 struct Container { | |
61 #define MOUSE_LEFT 0 | |
62 #define MOUSE_MIDDLE 1 | |
63 #define MOUSE_RIGHT 2 | |
64 #define MOUSE_UP 3 | |
65 #define MOUSE_DOWN 4 | |
66 #define KEY_SHIFT 10 | |
67 #define BUTTON_MAX 32 | |
68 int button_pressed; | |
69 int button_presscount[BUTTON_MAX]; | |
70 int current_time; | |
71 | |
72 void MousePos(int& x, int& y); | |
73 bool Exec(unsigned int current_time); | |
74 | |
75 void Add(Video* item); | |
76 void Delete(Video* item); | |
77 | |
78 void Add(Time* item); | |
79 void Delete(Time* item); | |
80 | |
81 typedef bool (*motionfunc)(int x, int y, void* pointer); | |
82 void RegisterGlobalMotionFunc(motionfunc, void* pointer); // マウスの移動のたびに呼び出される関数を登録する | |
83 void DeleteGlobalMotionFunc(motionfunc, void* pointer); | |
84 void RegisterGlobalPressFunc(motionfunc, void* pointer); // マウスのクリックのたびに呼び出される関数を登録する | |
85 void DeleteGlobalPressFunc(motionfunc, void* pointer); | |
86 | |
87 Container(void); | |
88 ~Container(void); | |
89 bool pressed(int mask); | |
90 bool presscount(int mask); | |
91 private: | |
92 class ContainerImplVideo* pimpl_video; | |
93 class ContainerImplTime* pimpl_time; | |
94 }; | |
95 | |
96 }; /* end of namespace Event */ | |
97 | |
98 | |
99 #endif |