Mercurial > otakunoraifu
comparison window/event.h @ 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 | 5ae5533b3a9a |
children | 4416cfac86ae |
comparison
equal
deleted
inserted
replaced
51:cbb301016a4e | 52:15a18fbe6f21 |
---|---|
26 */ | 26 */ |
27 | 27 |
28 #ifndef __EVENT__ | 28 #ifndef __EVENT__ |
29 #define __EVENT__ | 29 #define __EVENT__ |
30 | 30 |
31 #include"rect.h" | 31 #include "rect.h" |
32 #include"SDL.h" | 32 #include "SDL.h" |
33 | 33 |
34 namespace Event { | 34 namespace Event { |
35 | 35 |
36 class Video; | 36 class Video; |
37 class Time; | 37 class Time; |
38 class Container; | 38 class Container; |
39 | 39 |
40 /* | 40 /* |
41 ** マウスの press, ドラッグ、in/out を検出できる | 41 ** マウスの press, ドラッグ、in/out を検出できる |
42 ** focus がある時の left/right/space(==press) のキーを判別できる | 42 ** focus がある時の left/right/space(==press) のキーを判別できる |
43 */ | 43 */ |
44 struct Video { | 44 struct Video { |
45 virtual void Press(void) {} | 45 public: |
46 virtual void Release(void) {} | 46 virtual void Press(void) {} |
47 virtual void Drag(int x_from, int y_from, int x_to, int y_to) {} | 47 virtual void Release(void) {} |
48 virtual void Motion(int x, int y) {} | 48 virtual void Drag(int x_from, int y_from, int x_to, int y_to) {} |
49 virtual void In(void) {} | 49 virtual void Motion(int x, int y) {} |
50 virtual void Out(void) {} | 50 virtual void In(void) {} |
51 virtual void KeyLeft(void) {} | 51 virtual void Out(void) {} |
52 virtual void KeyRight(void) {} | 52 virtual void KeyLeft(void) {} |
53 virtual void KeyRight(void) {} | |
53 | 54 |
54 int point_in(int x, int y); /* z or -1 を返す。大きいほど高いところにある */ | 55 int point_in(int x, int y); /* z or -1 を返す。大きいほど高いところにある */ |
55 | 56 |
56 Video(Container& container); | 57 Video(Container& container); |
57 Video(Container& container, const Rect& init_rect); | 58 Video(Container& container, const Rect& init_rect); |
58 Video(Container& container, const Rect& init_rect, int z); | 59 Video(Container& container, const Rect& init_rect, int z); |
59 void SetRegion(const Rect& new_rect); | 60 void SetRegion(const Rect& new_rect); |
60 void SetZ(int new_z); | 61 void SetZ(int new_z); |
61 void activate(void); | 62 void activate(void); |
62 void deactivate(void); | 63 void deactivate(void); |
63 virtual ~Video(); | 64 virtual ~Video(); |
64 | 65 |
65 Rect Region(void) const { return region;} | 66 Rect Region(void) const { return region;} |
66 private: | 67 private: |
67 Rect region; | 68 Rect region; |
68 int z; | 69 int z; |
69 Container& parent; | 70 Container& parent; |
70 bool activated; | 71 bool activated; |
71 friend bool operator <(const Video& position1, const Video& position2); | 72 friend bool operator <(const Video& position1, const Video& position2); |
72 }; | 73 }; |
73 | 74 |
74 struct Time { | 75 struct Time { |
75 enum { NEVER_WAKE = 0xffffffff, FRAME_UPDATE = 0xfffffffe}; | 76 public: |
76 virtual void Elapsed(unsigned int current_time) {wakeup_time = NEVER_WAKE; }; /* next: never elapsed */ | 77 enum { NEVER_WAKE = 0xffffffffUL, FRAME_UPDATE = 0xfffffffeUL}; |
77 void SetWakeup(unsigned int new_wakeup_time) { wakeup_time = new_wakeup_time; } | 78 virtual void Elapsed(unsigned int current_time) {wakeup_time = NEVER_WAKE; }; /* next: never elapsed */ |
78 unsigned Wakeup(void) const { return wakeup_time; } | 79 void SetWakeup(unsigned int new_wakeup_time) { wakeup_time = new_wakeup_time; } |
80 unsigned Wakeup(void) const { return wakeup_time; } | |
79 | 81 |
80 Time(Container& container); | 82 Time(Container& container); |
81 ~Time(); | 83 ~Time(); |
82 private: | 84 private: |
83 unsigned int wakeup_time; | 85 unsigned int wakeup_time; |
84 Container& parent; | 86 Container& parent; |
85 }; | 87 }; |
86 | 88 |
87 struct Container { | 89 struct Container { |
88 #define MOUSE_LEFT 0 | 90 #define MOUSE_LEFT 0 |
89 #define MOUSE_MIDDLE 1 | 91 #define MOUSE_MIDDLE 1 |
90 #define MOUSE_RIGHT 2 | 92 #define MOUSE_RIGHT 2 |
91 #define MOUSE_UP 3 | 93 #define MOUSE_UP 3 |
92 #define MOUSE_DOWN 4 | 94 #define MOUSE_DOWN 4 |
93 #define KEY_SHIFT 10 | 95 #define KEY_SHIFT 10 |
94 #define BUTTON_MAX 32 | 96 #define BUTTON_MAX 32 |
95 int button_pressed; | 97 public: |
96 int button_presscount[BUTTON_MAX]; | 98 int button_pressed; |
97 int current_time; | 99 int button_presscount[BUTTON_MAX]; |
100 int current_time; | |
98 | 101 |
99 void MousePos(int& x, int& y); | 102 void MousePos(int& x, int& y); |
100 bool Exec(unsigned int current_time); | 103 bool Exec(unsigned int current_time); |
101 | 104 |
102 void Add(Video* item); | 105 void Add(Video* item); |
103 void Delete(Video* item); | 106 void Delete(Video* item); |
104 | 107 |
105 void Add(Time* item); | 108 void Add(Time* item); |
106 void Delete(Time* item); | 109 void Delete(Time* item); |
107 | 110 |
108 typedef bool (*motionfunc)(int x, int y, void* pointer); | 111 typedef bool (*motionfunc)(int x, int y, void* pointer); |
109 void RegisterGlobalMotionFunc(motionfunc, void* pointer); // マウスの移動のたびに呼び出される関数を登録する | 112 void RegisterGlobalMotionFunc(motionfunc, void* pointer); // マウスの移動のたびに呼び出される関数を登録する |
110 void DeleteGlobalMotionFunc(motionfunc, void* pointer); | 113 void DeleteGlobalMotionFunc(motionfunc, void* pointer); |
111 void RegisterGlobalPressFunc(motionfunc, void* pointer); // マウスのクリックのたびに呼び出される関数を登録する | 114 void RegisterGlobalPressFunc(motionfunc, void* pointer); // マウスのクリックのたびに呼び出される関数を登録する |
112 void DeleteGlobalPressFunc(motionfunc, void* pointer); | 115 void DeleteGlobalPressFunc(motionfunc, void* pointer); |
113 | 116 |
114 Container(void); | 117 Container(void); |
115 ~Container(void); | 118 ~Container(void); |
116 bool pressed(int mask); | 119 bool pressed(int mask); |
117 bool presscount(int mask); | 120 bool presscount(int mask); |
118 private: | 121 private: |
119 class ContainerImplVideo* pimpl_video; | 122 class ContainerImplVideo* pimpl_video; |
120 class ContainerImplTime* pimpl_time; | 123 class ContainerImplTime* pimpl_time; |
121 }; | 124 }; |
122 | 125 |
123 }; /* end of namespace Event */ | 126 } /* end of namespace Event */ |
124 | 127 |
125 | 128 |
126 #endif | 129 #endif |