annotate window/event.cc @ 38:658272d883ed

* Support (more or less) button style selects (fuuko's ones) * Strip text objects from strings (may support object text objects later)
author thib
date Tue, 17 Mar 2009 20:35:08 +0000
parents 223b71206888
children 01aa5ddf7dc8
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
223b71206888 Initial import
thib
parents:
diff changeset
1 /*
223b71206888 Initial import
thib
parents:
diff changeset
2 * Copyright (c) 2004-2006 Kazunori "jagarl" Ueno
223b71206888 Initial import
thib
parents:
diff changeset
3 * All rights reserved.
223b71206888 Initial import
thib
parents:
diff changeset
4 *
223b71206888 Initial import
thib
parents:
diff changeset
5 * Redistribution and use in source and binary forms, with or without
223b71206888 Initial import
thib
parents:
diff changeset
6 * modification, are permitted provided that the following conditions
223b71206888 Initial import
thib
parents:
diff changeset
7 * are met:
223b71206888 Initial import
thib
parents:
diff changeset
8 * 1. Redistributions of source code must retain the above copyright
223b71206888 Initial import
thib
parents:
diff changeset
9 * notice, this list of conditions and the following disclaimer.
223b71206888 Initial import
thib
parents:
diff changeset
10 * 2. Redistributions in binary form must reproduce the above copyright
223b71206888 Initial import
thib
parents:
diff changeset
11 * notice, this list of conditions and the following disclaimer in the
223b71206888 Initial import
thib
parents:
diff changeset
12 * documentation and/or other materials provided with the distribution.
223b71206888 Initial import
thib
parents:
diff changeset
13 * 3. The name of the author may not be used to endorse or promote products
223b71206888 Initial import
thib
parents:
diff changeset
14 * derived from this software without specific prior written permission.
223b71206888 Initial import
thib
parents:
diff changeset
15 *
223b71206888 Initial import
thib
parents:
diff changeset
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
223b71206888 Initial import
thib
parents:
diff changeset
17 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
223b71206888 Initial import
thib
parents:
diff changeset
18 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
223b71206888 Initial import
thib
parents:
diff changeset
19 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
223b71206888 Initial import
thib
parents:
diff changeset
20 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
223b71206888 Initial import
thib
parents:
diff changeset
21 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
223b71206888 Initial import
thib
parents:
diff changeset
22 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
223b71206888 Initial import
thib
parents:
diff changeset
23 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
223b71206888 Initial import
thib
parents:
diff changeset
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
223b71206888 Initial import
thib
parents:
diff changeset
25 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
223b71206888 Initial import
thib
parents:
diff changeset
26 */
223b71206888 Initial import
thib
parents:
diff changeset
27
223b71206888 Initial import
thib
parents:
diff changeset
28 #include"SDL.h"
223b71206888 Initial import
thib
parents:
diff changeset
29 #include"event.h"
223b71206888 Initial import
thib
parents:
diff changeset
30 #include<vector>
223b71206888 Initial import
thib
parents:
diff changeset
31 #include<list>
223b71206888 Initial import
thib
parents:
diff changeset
32 #include<algorithm>
223b71206888 Initial import
thib
parents:
diff changeset
33 #include<iostream>
223b71206888 Initial import
thib
parents:
diff changeset
34 #include<sys/stat.h>
223b71206888 Initial import
thib
parents:
diff changeset
35
223b71206888 Initial import
thib
parents:
diff changeset
36 using namespace std;
223b71206888 Initial import
thib
parents:
diff changeset
37
223b71206888 Initial import
thib
parents:
diff changeset
38 extern bool save_req = false, load_req = false, grpdump_req = false; // scn2k/scn2k_impl.cc: キーボードからセーブ・ロードできるように
223b71206888 Initial import
thib
parents:
diff changeset
39 extern bool pressAreq=false,pressFreq=false,pressDreq=false;
223b71206888 Initial import
thib
parents:
diff changeset
40 namespace Event {
223b71206888 Initial import
thib
parents:
diff changeset
41 /* Impl: struct Event::Video */
223b71206888 Initial import
thib
parents:
diff changeset
42
223b71206888 Initial import
thib
parents:
diff changeset
43 Video::Video(Container& container) : region(0, 0, 0, 0), z(0), parent(container) {
223b71206888 Initial import
thib
parents:
diff changeset
44 activated = false;
223b71206888 Initial import
thib
parents:
diff changeset
45 parent.Add(this);
223b71206888 Initial import
thib
parents:
diff changeset
46 }
223b71206888 Initial import
thib
parents:
diff changeset
47 Video::Video(Container& container, const Rect& init_rect) : region(init_rect), z(0), parent(container) {
223b71206888 Initial import
thib
parents:
diff changeset
48 activated = false;
223b71206888 Initial import
thib
parents:
diff changeset
49 parent.Add(this);
223b71206888 Initial import
thib
parents:
diff changeset
50 }
223b71206888 Initial import
thib
parents:
diff changeset
51 Video::Video(Container& container, const Rect& init_rect, int _z) : region(init_rect), z(_z), parent(container) {
223b71206888 Initial import
thib
parents:
diff changeset
52 activated = false;
223b71206888 Initial import
thib
parents:
diff changeset
53 parent.Add(this);
223b71206888 Initial import
thib
parents:
diff changeset
54 }
223b71206888 Initial import
thib
parents:
diff changeset
55 Video::~Video() {
223b71206888 Initial import
thib
parents:
diff changeset
56 parent.Delete(this);
223b71206888 Initial import
thib
parents:
diff changeset
57 };
223b71206888 Initial import
thib
parents:
diff changeset
58 void Video::SetRegion(const Rect& new_rect) {
223b71206888 Initial import
thib
parents:
diff changeset
59 region = new_rect;
223b71206888 Initial import
thib
parents:
diff changeset
60 }
223b71206888 Initial import
thib
parents:
diff changeset
61 void Video::SetZ(int new_z) {
223b71206888 Initial import
thib
parents:
diff changeset
62 z = new_z;
223b71206888 Initial import
thib
parents:
diff changeset
63 }
223b71206888 Initial import
thib
parents:
diff changeset
64 void Video::activate(void) {
223b71206888 Initial import
thib
parents:
diff changeset
65 activated = true;
223b71206888 Initial import
thib
parents:
diff changeset
66 }
223b71206888 Initial import
thib
parents:
diff changeset
67 void Video::deactivate(void) {
223b71206888 Initial import
thib
parents:
diff changeset
68 activated = false;
223b71206888 Initial import
thib
parents:
diff changeset
69 }
223b71206888 Initial import
thib
parents:
diff changeset
70 inline int Video::point_in(int x, int y) {
223b71206888 Initial import
thib
parents:
diff changeset
71 if (!activated) return -1;
223b71206888 Initial import
thib
parents:
diff changeset
72 if (region.point_in(x,y)) return z;
223b71206888 Initial import
thib
parents:
diff changeset
73 else return -1;
223b71206888 Initial import
thib
parents:
diff changeset
74 }
223b71206888 Initial import
thib
parents:
diff changeset
75
223b71206888 Initial import
thib
parents:
diff changeset
76 /* カーソルの動く順序:上、左の順に準位付け */
223b71206888 Initial import
thib
parents:
diff changeset
77 bool operator <(const Video& pos1, const Video& pos2) {
223b71206888 Initial import
thib
parents:
diff changeset
78 if (pos1.region.ty < pos2.region.ty) return true;
223b71206888 Initial import
thib
parents:
diff changeset
79 if (pos1.region.ty == pos2.region.ty) return pos1.region.lx < pos2.region.lx;
223b71206888 Initial import
thib
parents:
diff changeset
80 if (pos1.region.by >= pos2.region.by) return pos1.region.lx <= pos2.region.lx;
223b71206888 Initial import
thib
parents:
diff changeset
81 return false;
223b71206888 Initial import
thib
parents:
diff changeset
82 }
223b71206888 Initial import
thib
parents:
diff changeset
83
223b71206888 Initial import
thib
parents:
diff changeset
84
223b71206888 Initial import
thib
parents:
diff changeset
85 /* Impl: struct Event::Time */
223b71206888 Initial import
thib
parents:
diff changeset
86 Time::Time(Container& container) : wakeup_time(container.current_time), parent(container) {
223b71206888 Initial import
thib
parents:
diff changeset
87 parent.Add(this);
223b71206888 Initial import
thib
parents:
diff changeset
88 }
223b71206888 Initial import
thib
parents:
diff changeset
89 Time::~Time() {
223b71206888 Initial import
thib
parents:
diff changeset
90 parent.Delete(this);
223b71206888 Initial import
thib
parents:
diff changeset
91 }
223b71206888 Initial import
thib
parents:
diff changeset
92 /* Define: struct Event::ContainerImpl */
223b71206888 Initial import
thib
parents:
diff changeset
93
223b71206888 Initial import
thib
parents:
diff changeset
94 struct ContainerImplTime_Item {
223b71206888 Initial import
thib
parents:
diff changeset
95 Time* instance;
223b71206888 Initial import
thib
parents:
diff changeset
96 bool valid;
223b71206888 Initial import
thib
parents:
diff changeset
97 bool operator ==(Time* const& to) const {
223b71206888 Initial import
thib
parents:
diff changeset
98 return to == instance;
223b71206888 Initial import
thib
parents:
diff changeset
99 }
223b71206888 Initial import
thib
parents:
diff changeset
100 ContainerImplTime_Item(Time* _time) :
223b71206888 Initial import
thib
parents:
diff changeset
101 instance(_time), valid(true) {
223b71206888 Initial import
thib
parents:
diff changeset
102 }
223b71206888 Initial import
thib
parents:
diff changeset
103 };
223b71206888 Initial import
thib
parents:
diff changeset
104
223b71206888 Initial import
thib
parents:
diff changeset
105 class ContainerImplTime : private vector<ContainerImplTime_Item> {
223b71206888 Initial import
thib
parents:
diff changeset
106 public:
223b71206888 Initial import
thib
parents:
diff changeset
107 ContainerImplTime(void);
223b71206888 Initial import
thib
parents:
diff changeset
108 bool Exec(unsigned int current_time);
223b71206888 Initial import
thib
parents:
diff changeset
109 void Add(Time* new_event);
223b71206888 Initial import
thib
parents:
diff changeset
110 void Delete(Time* delete_event);
223b71206888 Initial import
thib
parents:
diff changeset
111 private:
223b71206888 Initial import
thib
parents:
diff changeset
112 static vector<ContainerImplTime_Item> new_item;
223b71206888 Initial import
thib
parents:
diff changeset
113 unsigned int prev_execed_time;
223b71206888 Initial import
thib
parents:
diff changeset
114 static bool is_invalid(const_reference value) {
223b71206888 Initial import
thib
parents:
diff changeset
115 return !value.valid;
223b71206888 Initial import
thib
parents:
diff changeset
116 }
223b71206888 Initial import
thib
parents:
diff changeset
117 };
223b71206888 Initial import
thib
parents:
diff changeset
118
223b71206888 Initial import
thib
parents:
diff changeset
119 vector<ContainerImplTime_Item> ContainerImplTime::new_item;
223b71206888 Initial import
thib
parents:
diff changeset
120
223b71206888 Initial import
thib
parents:
diff changeset
121 ContainerImplTime::ContainerImplTime(void) {
223b71206888 Initial import
thib
parents:
diff changeset
122 prev_execed_time = 0;
223b71206888 Initial import
thib
parents:
diff changeset
123 }
223b71206888 Initial import
thib
parents:
diff changeset
124 void ContainerImplTime::Add(Time* event) {
223b71206888 Initial import
thib
parents:
diff changeset
125 ContainerImplTime_Item item(event);
223b71206888 Initial import
thib
parents:
diff changeset
126 new_item.push_back(item);
223b71206888 Initial import
thib
parents:
diff changeset
127 }
223b71206888 Initial import
thib
parents:
diff changeset
128 void ContainerImplTime::Delete(Time* delete_event) {
223b71206888 Initial import
thib
parents:
diff changeset
129 iterator it = find(begin(), end(), delete_event);
223b71206888 Initial import
thib
parents:
diff changeset
130 if (it != end()) {
223b71206888 Initial import
thib
parents:
diff changeset
131 it->valid = false;
223b71206888 Initial import
thib
parents:
diff changeset
132 it->instance = 0;
223b71206888 Initial import
thib
parents:
diff changeset
133 return;
223b71206888 Initial import
thib
parents:
diff changeset
134 }
223b71206888 Initial import
thib
parents:
diff changeset
135 it = find(new_item.begin(), new_item.end(), delete_event);
223b71206888 Initial import
thib
parents:
diff changeset
136 if (it != end()) {
223b71206888 Initial import
thib
parents:
diff changeset
137 it->valid = false;
223b71206888 Initial import
thib
parents:
diff changeset
138 it->instance = 0;
223b71206888 Initial import
thib
parents:
diff changeset
139 return;
223b71206888 Initial import
thib
parents:
diff changeset
140 }
223b71206888 Initial import
thib
parents:
diff changeset
141 return;
223b71206888 Initial import
thib
parents:
diff changeset
142 }
223b71206888 Initial import
thib
parents:
diff changeset
143 bool ContainerImplTime::Exec(unsigned int current_time) {
223b71206888 Initial import
thib
parents:
diff changeset
144 if (current_time == Time::NEVER_WAKE) return true;
223b71206888 Initial import
thib
parents:
diff changeset
145 // 呼び出しまでに作製されたitemを追加
223b71206888 Initial import
thib
parents:
diff changeset
146 insert(end(), new_item.begin(), new_item.end());
223b71206888 Initial import
thib
parents:
diff changeset
147 new_item.clear();
223b71206888 Initial import
thib
parents:
diff changeset
148 if (empty()) return true;
223b71206888 Initial import
thib
parents:
diff changeset
149 if (current_time == Time::FRAME_UPDATE) { // ビデオフレームの更新時
223b71206888 Initial import
thib
parents:
diff changeset
150 for (iterator it = begin(); it != end(); it++) {
223b71206888 Initial import
thib
parents:
diff changeset
151 if (! it->valid) continue;
223b71206888 Initial import
thib
parents:
diff changeset
152
223b71206888 Initial import
thib
parents:
diff changeset
153 unsigned tm = it->instance->Wakeup();
223b71206888 Initial import
thib
parents:
diff changeset
154 if (tm == Time::FRAME_UPDATE) {
223b71206888 Initial import
thib
parents:
diff changeset
155 it->instance->Elapsed(prev_execed_time);
223b71206888 Initial import
thib
parents:
diff changeset
156 }
223b71206888 Initial import
thib
parents:
diff changeset
157 }
223b71206888 Initial import
thib
parents:
diff changeset
158 } else { // 時間変化時
223b71206888 Initial import
thib
parents:
diff changeset
159 if (current_time < prev_execed_time) prev_execed_time = 0; /* 時間が一回りして0に戻ったとき */
223b71206888 Initial import
thib
parents:
diff changeset
160 for (iterator it = begin(); it != end(); it++) {
223b71206888 Initial import
thib
parents:
diff changeset
161 if (! it->valid) continue;
223b71206888 Initial import
thib
parents:
diff changeset
162 unsigned tm = it->instance->Wakeup();
223b71206888 Initial import
thib
parents:
diff changeset
163 if (tm >= prev_execed_time && tm < current_time) {
223b71206888 Initial import
thib
parents:
diff changeset
164 it->instance->Elapsed(current_time);
223b71206888 Initial import
thib
parents:
diff changeset
165 }
223b71206888 Initial import
thib
parents:
diff changeset
166 }
223b71206888 Initial import
thib
parents:
diff changeset
167 prev_execed_time = current_time;
223b71206888 Initial import
thib
parents:
diff changeset
168 }
223b71206888 Initial import
thib
parents:
diff changeset
169 // 処理中に削除された item を実際に削除
223b71206888 Initial import
thib
parents:
diff changeset
170 erase(remove_if(begin(), end(), is_invalid), end());
223b71206888 Initial import
thib
parents:
diff changeset
171 return true;
223b71206888 Initial import
thib
parents:
diff changeset
172 }
223b71206888 Initial import
thib
parents:
diff changeset
173
223b71206888 Initial import
thib
parents:
diff changeset
174
223b71206888 Initial import
thib
parents:
diff changeset
175 class ContainerImplVideo : private vector<Video*> {
223b71206888 Initial import
thib
parents:
diff changeset
176 public:
223b71206888 Initial import
thib
parents:
diff changeset
177 bool Exec(void);
223b71206888 Initial import
thib
parents:
diff changeset
178
223b71206888 Initial import
thib
parents:
diff changeset
179 ContainerImplVideo(void);
223b71206888 Initial import
thib
parents:
diff changeset
180 ~ContainerImplVideo();
223b71206888 Initial import
thib
parents:
diff changeset
181 void Add(Video* item);
223b71206888 Initial import
thib
parents:
diff changeset
182 void Delete(Video* item);
223b71206888 Initial import
thib
parents:
diff changeset
183 void RegisterGlobalMotionFunc(Container::motionfunc, void* pointer);
223b71206888 Initial import
thib
parents:
diff changeset
184 void DeleteGlobalMotionFunc(Container::motionfunc, void* pointer);
223b71206888 Initial import
thib
parents:
diff changeset
185 void RegisterGlobalPressFunc(Container::motionfunc, void* pointer);
223b71206888 Initial import
thib
parents:
diff changeset
186 void DeleteGlobalPressFunc(Container::motionfunc, void* pointer);
223b71206888 Initial import
thib
parents:
diff changeset
187 private:
223b71206888 Initial import
thib
parents:
diff changeset
188 struct Motionfunc {
223b71206888 Initial import
thib
parents:
diff changeset
189 Container::motionfunc func;
223b71206888 Initial import
thib
parents:
diff changeset
190 void* pointer;
223b71206888 Initial import
thib
parents:
diff changeset
191 bool operator ==(const Motionfunc& m) const { return func == m.func && pointer == m.pointer;}
223b71206888 Initial import
thib
parents:
diff changeset
192 };
223b71206888 Initial import
thib
parents:
diff changeset
193 list<Motionfunc> motion_vec;
223b71206888 Initial import
thib
parents:
diff changeset
194 list<Motionfunc> press_vec;
223b71206888 Initial import
thib
parents:
diff changeset
195 typedef list<Motionfunc>::iterator MotionIterator;
223b71206888 Initial import
thib
parents:
diff changeset
196 bool is_sorted;
223b71206888 Initial import
thib
parents:
diff changeset
197 public:
223b71206888 Initial import
thib
parents:
diff changeset
198 int button_pressed;
223b71206888 Initial import
thib
parents:
diff changeset
199 int button_released;
223b71206888 Initial import
thib
parents:
diff changeset
200 int mouse_x, mouse_y;
223b71206888 Initial import
thib
parents:
diff changeset
201 int new_mouse_x, new_mouse_y;
223b71206888 Initial import
thib
parents:
diff changeset
202 private:
223b71206888 Initial import
thib
parents:
diff changeset
203 void SetChanged(void);
223b71206888 Initial import
thib
parents:
diff changeset
204 static bool SortLess(const Video* pos1, const Video* pos2) {
223b71206888 Initial import
thib
parents:
diff changeset
205 return pos1 < pos2;
223b71206888 Initial import
thib
parents:
diff changeset
206 }
223b71206888 Initial import
thib
parents:
diff changeset
207 void Sort(void);
223b71206888 Initial import
thib
parents:
diff changeset
208 void Motion(int x, int y); // mouse motion
223b71206888 Initial import
thib
parents:
diff changeset
209 void Press(void);
223b71206888 Initial import
thib
parents:
diff changeset
210 void TakeScreenshot(void);
223b71206888 Initial import
thib
parents:
diff changeset
211 iterator cur_pos;
223b71206888 Initial import
thib
parents:
diff changeset
212 Video* cur_item; // 現在のフォーカス位置
223b71206888 Initial import
thib
parents:
diff changeset
213 int cur_pressed_x, cur_pressed_y;
223b71206888 Initial import
thib
parents:
diff changeset
214 };
223b71206888 Initial import
thib
parents:
diff changeset
215
223b71206888 Initial import
thib
parents:
diff changeset
216 void ContainerImplVideo::SetChanged(void) {
223b71206888 Initial import
thib
parents:
diff changeset
217 if (is_sorted) {
223b71206888 Initial import
thib
parents:
diff changeset
218 if (cur_item) {
223b71206888 Initial import
thib
parents:
diff changeset
219 cur_pos = find(begin(), end(), cur_item);
223b71206888 Initial import
thib
parents:
diff changeset
220 if (cur_pos == end()) cur_item = 0;
223b71206888 Initial import
thib
parents:
diff changeset
221 }
223b71206888 Initial import
thib
parents:
diff changeset
222 is_sorted = false;
223b71206888 Initial import
thib
parents:
diff changeset
223 }
223b71206888 Initial import
thib
parents:
diff changeset
224 }
223b71206888 Initial import
thib
parents:
diff changeset
225
223b71206888 Initial import
thib
parents:
diff changeset
226 void ContainerImplVideo::Sort(void) {
223b71206888 Initial import
thib
parents:
diff changeset
227 sort(begin(), end(), SortLess);
223b71206888 Initial import
thib
parents:
diff changeset
228 if (cur_item) {
223b71206888 Initial import
thib
parents:
diff changeset
229 cur_pos = lower_bound(begin(), end(), cur_item, SortLess);
223b71206888 Initial import
thib
parents:
diff changeset
230 } else {
223b71206888 Initial import
thib
parents:
diff changeset
231 cur_pos = end();
223b71206888 Initial import
thib
parents:
diff changeset
232 }
223b71206888 Initial import
thib
parents:
diff changeset
233 is_sorted = true;
223b71206888 Initial import
thib
parents:
diff changeset
234 }
223b71206888 Initial import
thib
parents:
diff changeset
235
223b71206888 Initial import
thib
parents:
diff changeset
236 ContainerImplVideo::ContainerImplVideo(void) {
223b71206888 Initial import
thib
parents:
diff changeset
237 is_sorted = false;
223b71206888 Initial import
thib
parents:
diff changeset
238 button_pressed = 0;
223b71206888 Initial import
thib
parents:
diff changeset
239 button_released = 0;
223b71206888 Initial import
thib
parents:
diff changeset
240 cur_item = 0;
223b71206888 Initial import
thib
parents:
diff changeset
241 mouse_x = 0; mouse_y = 0;
223b71206888 Initial import
thib
parents:
diff changeset
242 new_mouse_x = 0; new_mouse_y = 0;
223b71206888 Initial import
thib
parents:
diff changeset
243 }
223b71206888 Initial import
thib
parents:
diff changeset
244 ContainerImplVideo::~ContainerImplVideo(void) {
223b71206888 Initial import
thib
parents:
diff changeset
245 };
223b71206888 Initial import
thib
parents:
diff changeset
246 void ContainerImplVideo::Add(Video* event) {
223b71206888 Initial import
thib
parents:
diff changeset
247 push_back(event);
223b71206888 Initial import
thib
parents:
diff changeset
248 SetChanged();
223b71206888 Initial import
thib
parents:
diff changeset
249 }
223b71206888 Initial import
thib
parents:
diff changeset
250 void ContainerImplVideo::Delete(Video* delete_event) {
223b71206888 Initial import
thib
parents:
diff changeset
251 iterator it = find(begin(), end(), delete_event);
223b71206888 Initial import
thib
parents:
diff changeset
252 if (it != end()) {
223b71206888 Initial import
thib
parents:
diff changeset
253 erase(it);
223b71206888 Initial import
thib
parents:
diff changeset
254 SetChanged();
223b71206888 Initial import
thib
parents:
diff changeset
255 } else {
223b71206888 Initial import
thib
parents:
diff changeset
256 fprintf(stderr,"\nXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX\n");
223b71206888 Initial import
thib
parents:
diff changeset
257 fprintf(stderr,"X ContainerImplVideo: Cannot delete node %x\n",delete_event);
223b71206888 Initial import
thib
parents:
diff changeset
258 fprintf(stderr,"XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX\n\n");
223b71206888 Initial import
thib
parents:
diff changeset
259 fprintf(stderr,"vector from:\n");
223b71206888 Initial import
thib
parents:
diff changeset
260 for(it=begin(); it!=end(); it++) {
223b71206888 Initial import
thib
parents:
diff changeset
261 fprintf(stderr,"%x, ",*it);
223b71206888 Initial import
thib
parents:
diff changeset
262 }
223b71206888 Initial import
thib
parents:
diff changeset
263 fprintf(stderr,"\n");
223b71206888 Initial import
thib
parents:
diff changeset
264 }
223b71206888 Initial import
thib
parents:
diff changeset
265 if (delete_event == cur_item) {
223b71206888 Initial import
thib
parents:
diff changeset
266 cur_pos = end();
223b71206888 Initial import
thib
parents:
diff changeset
267 cur_item = 0;
223b71206888 Initial import
thib
parents:
diff changeset
268 Motion(mouse_x, mouse_y);
223b71206888 Initial import
thib
parents:
diff changeset
269 }
223b71206888 Initial import
thib
parents:
diff changeset
270 return;
223b71206888 Initial import
thib
parents:
diff changeset
271 }
223b71206888 Initial import
thib
parents:
diff changeset
272 void ContainerImplVideo::RegisterGlobalMotionFunc(Container::motionfunc func, void* pointer) {
223b71206888 Initial import
thib
parents:
diff changeset
273 Motionfunc f;
223b71206888 Initial import
thib
parents:
diff changeset
274 f.func = func;
223b71206888 Initial import
thib
parents:
diff changeset
275 f.pointer = pointer;
223b71206888 Initial import
thib
parents:
diff changeset
276 if (find(motion_vec.begin(), motion_vec.end(), f) == motion_vec.end()) {
223b71206888 Initial import
thib
parents:
diff changeset
277 motion_vec.push_back(f);
223b71206888 Initial import
thib
parents:
diff changeset
278 }
223b71206888 Initial import
thib
parents:
diff changeset
279 }
223b71206888 Initial import
thib
parents:
diff changeset
280 void ContainerImplVideo::DeleteGlobalMotionFunc(Container::motionfunc func, void* pointer) {
223b71206888 Initial import
thib
parents:
diff changeset
281 Motionfunc f;
223b71206888 Initial import
thib
parents:
diff changeset
282 f.func = func;
223b71206888 Initial import
thib
parents:
diff changeset
283 f.pointer = pointer;
223b71206888 Initial import
thib
parents:
diff changeset
284 list<Motionfunc>::iterator it = find(motion_vec.begin(), motion_vec.end(), f);
223b71206888 Initial import
thib
parents:
diff changeset
285 if (it != motion_vec.end())
223b71206888 Initial import
thib
parents:
diff changeset
286 motion_vec.erase(it);
223b71206888 Initial import
thib
parents:
diff changeset
287 return;
223b71206888 Initial import
thib
parents:
diff changeset
288 }
223b71206888 Initial import
thib
parents:
diff changeset
289 void ContainerImplVideo::RegisterGlobalPressFunc(Container::motionfunc func, void* pointer) {
223b71206888 Initial import
thib
parents:
diff changeset
290 Motionfunc f;
223b71206888 Initial import
thib
parents:
diff changeset
291 f.func = func;
223b71206888 Initial import
thib
parents:
diff changeset
292 f.pointer = pointer;
223b71206888 Initial import
thib
parents:
diff changeset
293 if (find(press_vec.begin(), press_vec.end(), f) == press_vec.end()) {
223b71206888 Initial import
thib
parents:
diff changeset
294 press_vec.push_back(f);
223b71206888 Initial import
thib
parents:
diff changeset
295 }
223b71206888 Initial import
thib
parents:
diff changeset
296 }
223b71206888 Initial import
thib
parents:
diff changeset
297 void ContainerImplVideo::DeleteGlobalPressFunc(Container::motionfunc func, void* pointer) {
223b71206888 Initial import
thib
parents:
diff changeset
298 Motionfunc f;
223b71206888 Initial import
thib
parents:
diff changeset
299 f.func = func;
223b71206888 Initial import
thib
parents:
diff changeset
300 f.pointer = pointer;
223b71206888 Initial import
thib
parents:
diff changeset
301 list<Motionfunc>::iterator it = find(press_vec.begin(), press_vec.end(), f);
223b71206888 Initial import
thib
parents:
diff changeset
302 if (it != press_vec.end())
223b71206888 Initial import
thib
parents:
diff changeset
303 press_vec.erase(it);
223b71206888 Initial import
thib
parents:
diff changeset
304 return;
223b71206888 Initial import
thib
parents:
diff changeset
305 }
223b71206888 Initial import
thib
parents:
diff changeset
306 void ContainerImplVideo::Motion(int x, int y) {
223b71206888 Initial import
thib
parents:
diff changeset
307 mouse_x = x; mouse_y = y;
223b71206888 Initial import
thib
parents:
diff changeset
308 MotionIterator mit;
223b71206888 Initial import
thib
parents:
diff changeset
309 for (mit=motion_vec.begin(); mit != motion_vec.end();) {
223b71206888 Initial import
thib
parents:
diff changeset
310 MotionIterator mit_next = mit;
223b71206888 Initial import
thib
parents:
diff changeset
311 mit_next++;
223b71206888 Initial import
thib
parents:
diff changeset
312 if (!(*mit->func)(x, y, mit->pointer)) motion_vec.erase(mit);
223b71206888 Initial import
thib
parents:
diff changeset
313 mit = mit_next;
223b71206888 Initial import
thib
parents:
diff changeset
314
223b71206888 Initial import
thib
parents:
diff changeset
315 }
223b71206888 Initial import
thib
parents:
diff changeset
316
223b71206888 Initial import
thib
parents:
diff changeset
317 /* @@@ ドラッグ処理とマウスを押す処理のバッティングで「二回ボタンを押さないと云々」関連のバグの可能性あり */
223b71206888 Initial import
thib
parents:
diff changeset
318 if (button_pressed & (1<<MOUSE_LEFT)) {
223b71206888 Initial import
thib
parents:
diff changeset
319 if (cur_item) cur_item->Drag(cur_pressed_x, cur_pressed_y, x, y);
223b71206888 Initial import
thib
parents:
diff changeset
320 return;
223b71206888 Initial import
thib
parents:
diff changeset
321 }
223b71206888 Initial import
thib
parents:
diff changeset
322 if (cur_item) cur_item->Motion(x,y);
223b71206888 Initial import
thib
parents:
diff changeset
323 int z = -1; iterator z_it;
223b71206888 Initial import
thib
parents:
diff changeset
324 iterator it;
223b71206888 Initial import
thib
parents:
diff changeset
325 for (it = begin(); it != end(); it++) {
223b71206888 Initial import
thib
parents:
diff changeset
326 int new_z = (*it)->point_in(x, y);
223b71206888 Initial import
thib
parents:
diff changeset
327 if (z < new_z) {
223b71206888 Initial import
thib
parents:
diff changeset
328 z = new_z;
223b71206888 Initial import
thib
parents:
diff changeset
329 z_it = it;
223b71206888 Initial import
thib
parents:
diff changeset
330 }
223b71206888 Initial import
thib
parents:
diff changeset
331 }
223b71206888 Initial import
thib
parents:
diff changeset
332 if (z != -1) {
223b71206888 Initial import
thib
parents:
diff changeset
333 if (cur_item == *z_it) return;
223b71206888 Initial import
thib
parents:
diff changeset
334 if (cur_item) cur_item->Out();
223b71206888 Initial import
thib
parents:
diff changeset
335 cur_pos = z_it;
223b71206888 Initial import
thib
parents:
diff changeset
336 cur_item = *z_it;
223b71206888 Initial import
thib
parents:
diff changeset
337 cur_item->In();
223b71206888 Initial import
thib
parents:
diff changeset
338 return;
223b71206888 Initial import
thib
parents:
diff changeset
339 } else {
223b71206888 Initial import
thib
parents:
diff changeset
340 if (cur_item) cur_item->Out();
223b71206888 Initial import
thib
parents:
diff changeset
341 cur_pos = end();
223b71206888 Initial import
thib
parents:
diff changeset
342 cur_item = 0;
223b71206888 Initial import
thib
parents:
diff changeset
343 }
223b71206888 Initial import
thib
parents:
diff changeset
344 return;
223b71206888 Initial import
thib
parents:
diff changeset
345 }
223b71206888 Initial import
thib
parents:
diff changeset
346
223b71206888 Initial import
thib
parents:
diff changeset
347 void ContainerImplVideo::Press(void) {
223b71206888 Initial import
thib
parents:
diff changeset
348 if (cur_item) {
223b71206888 Initial import
thib
parents:
diff changeset
349 cur_pressed_x = mouse_x;
223b71206888 Initial import
thib
parents:
diff changeset
350 cur_pressed_y = mouse_y;
223b71206888 Initial import
thib
parents:
diff changeset
351 cur_item->Press();
223b71206888 Initial import
thib
parents:
diff changeset
352 return;
223b71206888 Initial import
thib
parents:
diff changeset
353 }
223b71206888 Initial import
thib
parents:
diff changeset
354 MotionIterator mit;
223b71206888 Initial import
thib
parents:
diff changeset
355 for (mit=press_vec.begin(); mit != press_vec.end(); ) {
223b71206888 Initial import
thib
parents:
diff changeset
356 MotionIterator mit_next = mit;
223b71206888 Initial import
thib
parents:
diff changeset
357 mit_next++;
223b71206888 Initial import
thib
parents:
diff changeset
358 if (!(*mit->func)(mouse_x, mouse_y, mit->pointer)) {
223b71206888 Initial import
thib
parents:
diff changeset
359 press_vec.erase(mit);
223b71206888 Initial import
thib
parents:
diff changeset
360 }
223b71206888 Initial import
thib
parents:
diff changeset
361 mit = mit_next;
223b71206888 Initial import
thib
parents:
diff changeset
362 }
223b71206888 Initial import
thib
parents:
diff changeset
363 }
223b71206888 Initial import
thib
parents:
diff changeset
364 void ContainerImplVideo::TakeScreenshot(void) {
223b71206888 Initial import
thib
parents:
diff changeset
365 int n=0;
223b71206888 Initial import
thib
parents:
diff changeset
366 char filename[1024];
223b71206888 Initial import
thib
parents:
diff changeset
367 struct stat buffer;
223b71206888 Initial import
thib
parents:
diff changeset
368 for(n=0; n<9999; n++) {
223b71206888 Initial import
thib
parents:
diff changeset
369 // XXX: put screenshots in a seperate dir?
223b71206888 Initial import
thib
parents:
diff changeset
370 sprintf(filename, "xclannad_%04i.bmp", n);
223b71206888 Initial import
thib
parents:
diff changeset
371 if(stat(filename, &buffer) == -1) break;
223b71206888 Initial import
thib
parents:
diff changeset
372 }
223b71206888 Initial import
thib
parents:
diff changeset
373 SDL_SaveBMP(SDL_GetVideoSurface(), filename);
223b71206888 Initial import
thib
parents:
diff changeset
374 }
223b71206888 Initial import
thib
parents:
diff changeset
375 bool ContainerImplVideo::Exec(void) {
223b71206888 Initial import
thib
parents:
diff changeset
376
223b71206888 Initial import
thib
parents:
diff changeset
377 bool is_mouse_motion = false;
223b71206888 Initial import
thib
parents:
diff changeset
378 int motion_x = 0, motion_y = 0;
223b71206888 Initial import
thib
parents:
diff changeset
379 SDL_Event event;
223b71206888 Initial import
thib
parents:
diff changeset
380 SDL_PumpEvents();
223b71206888 Initial import
thib
parents:
diff changeset
381 while(SDL_PeepEvents(&event, 1, SDL_GETEVENT, SDL_ALLEVENTS) == 1) {
223b71206888 Initial import
thib
parents:
diff changeset
382 switch(event.type) {
223b71206888 Initial import
thib
parents:
diff changeset
383 case SDL_QUIT: return false; // @@@ なにかやらないと
223b71206888 Initial import
thib
parents:
diff changeset
384 case SDL_ACTIVEEVENT: // なにもしない
223b71206888 Initial import
thib
parents:
diff changeset
385 // cout<<"active : gain "<<int(event.active.gain)<<", state "<<int(event.active.state)<<endl;
223b71206888 Initial import
thib
parents:
diff changeset
386 break;
223b71206888 Initial import
thib
parents:
diff changeset
387 case SDL_KEYDOWN:
223b71206888 Initial import
thib
parents:
diff changeset
388 if (!is_sorted) Sort();
223b71206888 Initial import
thib
parents:
diff changeset
389 switch(event.key.keysym.sym) {
223b71206888 Initial import
thib
parents:
diff changeset
390 case SDLK_F12:
223b71206888 Initial import
thib
parents:
diff changeset
391 case SDLK_PRINT:
223b71206888 Initial import
thib
parents:
diff changeset
392 case SDLK_p: // for Zaurus
223b71206888 Initial import
thib
parents:
diff changeset
393 TakeScreenshot();
223b71206888 Initial import
thib
parents:
diff changeset
394 break;
223b71206888 Initial import
thib
parents:
diff changeset
395 // Some window managers (eg enlightenment) use Alt-Enter for
223b71206888 Initial import
thib
parents:
diff changeset
396 // themselves, F11 is a good alternative
223b71206888 Initial import
thib
parents:
diff changeset
397 case SDLK_F11:
223b71206888 Initial import
thib
parents:
diff changeset
398 SDL_WM_ToggleFullScreen(SDL_GetVideoSurface());
223b71206888 Initial import
thib
parents:
diff changeset
399 break;
223b71206888 Initial import
thib
parents:
diff changeset
400 case SDLK_RETURN:
223b71206888 Initial import
thib
parents:
diff changeset
401 if (SDL_GetModState() & KMOD_ALT) {
223b71206888 Initial import
thib
parents:
diff changeset
402 SDL_WM_ToggleFullScreen(SDL_GetVideoSurface());
223b71206888 Initial import
thib
parents:
diff changeset
403 break;
223b71206888 Initial import
thib
parents:
diff changeset
404 }
223b71206888 Initial import
thib
parents:
diff changeset
405 case SDLK_SPACE:
223b71206888 Initial import
thib
parents:
diff changeset
406 Press();
223b71206888 Initial import
thib
parents:
diff changeset
407 break;
223b71206888 Initial import
thib
parents:
diff changeset
408 case SDLK_TAB: // move to next widget
223b71206888 Initial import
thib
parents:
diff changeset
409 if (cur_pos != end()) cur_pos++;
223b71206888 Initial import
thib
parents:
diff changeset
410 if (cur_pos == end()) cur_pos = begin();
223b71206888 Initial import
thib
parents:
diff changeset
411 if (cur_pos != end()) {
223b71206888 Initial import
thib
parents:
diff changeset
412 cur_item = *cur_pos;
223b71206888 Initial import
thib
parents:
diff changeset
413 cur_item->In();
223b71206888 Initial import
thib
parents:
diff changeset
414 } else {
223b71206888 Initial import
thib
parents:
diff changeset
415 cur_item = 0;
223b71206888 Initial import
thib
parents:
diff changeset
416 }
223b71206888 Initial import
thib
parents:
diff changeset
417 break;
223b71206888 Initial import
thib
parents:
diff changeset
418 case SDLK_LEFT: if (cur_pos != end()) (*cur_pos)->KeyLeft(); break;
223b71206888 Initial import
thib
parents:
diff changeset
419 case SDLK_RIGHT:if (cur_pos != end()) (*cur_pos)->KeyRight(); break;
223b71206888 Initial import
thib
parents:
diff changeset
420 case SDLK_LSHIFT: case SDLK_RSHIFT: button_pressed |= (1<<KEY_SHIFT); break;
223b71206888 Initial import
thib
parents:
diff changeset
421 case SDLK_ESCAPE: button_pressed |= (1<<MOUSE_RIGHT); break; /* for Zaurus */
223b71206888 Initial import
thib
parents:
diff changeset
422 case SDLK_s: save_req = true; break;
223b71206888 Initial import
thib
parents:
diff changeset
423 case SDLK_l: load_req = true; break;
223b71206888 Initial import
thib
parents:
diff changeset
424 case SDLK_g: grpdump_req = true; break;
223b71206888 Initial import
thib
parents:
diff changeset
425 case SDLK_a: pressAreq = true; break;
223b71206888 Initial import
thib
parents:
diff changeset
426 case SDLK_d: pressDreq = true; break;
223b71206888 Initial import
thib
parents:
diff changeset
427 case SDLK_f: pressFreq = true; break;
223b71206888 Initial import
thib
parents:
diff changeset
428 }
223b71206888 Initial import
thib
parents:
diff changeset
429 break;
223b71206888 Initial import
thib
parents:
diff changeset
430 case SDL_KEYUP:
223b71206888 Initial import
thib
parents:
diff changeset
431 // cout << "keyup which "<<int(event.key.which)<<", sym "<<int(event.key.keysym.sym)<<endl;
223b71206888 Initial import
thib
parents:
diff changeset
432 switch(event.key.keysym.sym) {
223b71206888 Initial import
thib
parents:
diff changeset
433 case SDLK_RETURN: case SDLK_SPACE:
223b71206888 Initial import
thib
parents:
diff changeset
434 if (cur_item) cur_item->Release();
223b71206888 Initial import
thib
parents:
diff changeset
435 case SDLK_LSHIFT: case SDLK_RSHIFT: button_pressed &= ~(1<<KEY_SHIFT); button_released |= 1<<KEY_SHIFT; break;
223b71206888 Initial import
thib
parents:
diff changeset
436 case SDLK_ESCAPE: button_pressed &= ~(1<<MOUSE_RIGHT); button_released |= 1<<MOUSE_RIGHT; break; /* for Zaurus */
223b71206888 Initial import
thib
parents:
diff changeset
437 }
223b71206888 Initial import
thib
parents:
diff changeset
438 break;
223b71206888 Initial import
thib
parents:
diff changeset
439 case SDL_MOUSEMOTION:
223b71206888 Initial import
thib
parents:
diff changeset
440 motion_x = event.motion.x;
223b71206888 Initial import
thib
parents:
diff changeset
441 motion_y = event.motion.y;
223b71206888 Initial import
thib
parents:
diff changeset
442 is_mouse_motion = true;
223b71206888 Initial import
thib
parents:
diff changeset
443 // Motion(event.motion.x, event.motion.y);
223b71206888 Initial import
thib
parents:
diff changeset
444 // cout<< "motion which "<<int(event.motion.which)<<
223b71206888 Initial import
thib
parents:
diff changeset
445 // "x "<<event.motion.x << "y "<<event.motion.y<<endl;
223b71206888 Initial import
thib
parents:
diff changeset
446 break;
223b71206888 Initial import
thib
parents:
diff changeset
447 case SDL_MOUSEBUTTONUP:
223b71206888 Initial import
thib
parents:
diff changeset
448 if (event.button.button == 1) {
223b71206888 Initial import
thib
parents:
diff changeset
449 Motion(event.button.x, event.button.y);
223b71206888 Initial import
thib
parents:
diff changeset
450 is_mouse_motion = false;
223b71206888 Initial import
thib
parents:
diff changeset
451 if (cur_item) cur_item->Release();
223b71206888 Initial import
thib
parents:
diff changeset
452 }
223b71206888 Initial import
thib
parents:
diff changeset
453 switch(event.button.button) {
223b71206888 Initial import
thib
parents:
diff changeset
454 case 1: button_pressed &= ~(1<<MOUSE_LEFT); button_released |= 1<<MOUSE_LEFT; break;
223b71206888 Initial import
thib
parents:
diff changeset
455 case 2: button_pressed &= ~(1<<MOUSE_MIDDLE); button_released |= 1<<MOUSE_MIDDLE; break;
223b71206888 Initial import
thib
parents:
diff changeset
456 case 3: button_pressed &= ~(1<<MOUSE_RIGHT); button_released |= 1<<MOUSE_RIGHT; break;
223b71206888 Initial import
thib
parents:
diff changeset
457 case 4: button_pressed &= ~(1<<MOUSE_UP); button_released |= 1<<MOUSE_UP; break;
223b71206888 Initial import
thib
parents:
diff changeset
458 case 5: button_pressed &= ~(1<<MOUSE_DOWN); button_released |= 1<<MOUSE_DOWN; break;
223b71206888 Initial import
thib
parents:
diff changeset
459 }
223b71206888 Initial import
thib
parents:
diff changeset
460 break;
223b71206888 Initial import
thib
parents:
diff changeset
461 case SDL_MOUSEBUTTONDOWN:
223b71206888 Initial import
thib
parents:
diff changeset
462 if (event.button.button == 1) {
223b71206888 Initial import
thib
parents:
diff changeset
463 Motion(event.button.x, event.button.y);
223b71206888 Initial import
thib
parents:
diff changeset
464 is_mouse_motion = false;
223b71206888 Initial import
thib
parents:
diff changeset
465 Press();
223b71206888 Initial import
thib
parents:
diff changeset
466 }
223b71206888 Initial import
thib
parents:
diff changeset
467 switch(event.button.button) {
223b71206888 Initial import
thib
parents:
diff changeset
468 case 1: button_pressed |= (1<<MOUSE_LEFT); break;
223b71206888 Initial import
thib
parents:
diff changeset
469 case 2: button_pressed |= (1<<MOUSE_MIDDLE); break;
223b71206888 Initial import
thib
parents:
diff changeset
470 case 3: button_pressed |= (1<<MOUSE_RIGHT); break;
223b71206888 Initial import
thib
parents:
diff changeset
471 case 4: button_pressed |= (1<<MOUSE_UP); break;
223b71206888 Initial import
thib
parents:
diff changeset
472 case 5: button_pressed |= (1<<MOUSE_DOWN); break;
223b71206888 Initial import
thib
parents:
diff changeset
473 }
223b71206888 Initial import
thib
parents:
diff changeset
474 // cout << "mouse which "<<int(event.button.which)<<"button "<<int(event.button.button)<<
223b71206888 Initial import
thib
parents:
diff changeset
475 // "state "<<int(event.button.state)<<"x "<<event.button.x << "y "<<event.button.y<<endl;
223b71206888 Initial import
thib
parents:
diff changeset
476 break;
223b71206888 Initial import
thib
parents:
diff changeset
477 case SDL_VIDEOEXPOSE: // redraw の必要がある?
223b71206888 Initial import
thib
parents:
diff changeset
478 // cout<<"expose."<<endl;
223b71206888 Initial import
thib
parents:
diff changeset
479 break;
223b71206888 Initial import
thib
parents:
diff changeset
480 }
223b71206888 Initial import
thib
parents:
diff changeset
481 }
223b71206888 Initial import
thib
parents:
diff changeset
482 // Motion 呼び出しは一回だけ
223b71206888 Initial import
thib
parents:
diff changeset
483 if (is_mouse_motion)
223b71206888 Initial import
thib
parents:
diff changeset
484 Motion(motion_x, motion_y);
223b71206888 Initial import
thib
parents:
diff changeset
485 return true;
223b71206888 Initial import
thib
parents:
diff changeset
486 };
223b71206888 Initial import
thib
parents:
diff changeset
487 /* Impl: struct Event::Container */
223b71206888 Initial import
thib
parents:
diff changeset
488 Container::Container(void) {
223b71206888 Initial import
thib
parents:
diff changeset
489 pimpl_video = new ContainerImplVideo;
223b71206888 Initial import
thib
parents:
diff changeset
490 try {
223b71206888 Initial import
thib
parents:
diff changeset
491 pimpl_time = new ContainerImplTime;
223b71206888 Initial import
thib
parents:
diff changeset
492 } catch(...) {
223b71206888 Initial import
thib
parents:
diff changeset
493 delete pimpl_video;
223b71206888 Initial import
thib
parents:
diff changeset
494 throw;
223b71206888 Initial import
thib
parents:
diff changeset
495 }
223b71206888 Initial import
thib
parents:
diff changeset
496 button_pressed = 0;
223b71206888 Initial import
thib
parents:
diff changeset
497 current_time = 0;
223b71206888 Initial import
thib
parents:
diff changeset
498 int i; for (i=0; i<BUTTON_MAX; i++) button_presscount[i] = 0;
223b71206888 Initial import
thib
parents:
diff changeset
499 return;
223b71206888 Initial import
thib
parents:
diff changeset
500 }
223b71206888 Initial import
thib
parents:
diff changeset
501 Container::~Container(void) {
223b71206888 Initial import
thib
parents:
diff changeset
502 delete pimpl_video;
223b71206888 Initial import
thib
parents:
diff changeset
503 delete pimpl_time;
223b71206888 Initial import
thib
parents:
diff changeset
504 }
223b71206888 Initial import
thib
parents:
diff changeset
505 void Container::Add(Video* item) {
223b71206888 Initial import
thib
parents:
diff changeset
506 pimpl_video->Add(item);
223b71206888 Initial import
thib
parents:
diff changeset
507 }
223b71206888 Initial import
thib
parents:
diff changeset
508 void Container::Delete(Video* item) {
223b71206888 Initial import
thib
parents:
diff changeset
509 pimpl_video->Delete(item);
223b71206888 Initial import
thib
parents:
diff changeset
510 }
223b71206888 Initial import
thib
parents:
diff changeset
511 void Container::Add(Time* item) {
223b71206888 Initial import
thib
parents:
diff changeset
512 pimpl_time->Add(item);
223b71206888 Initial import
thib
parents:
diff changeset
513 }
223b71206888 Initial import
thib
parents:
diff changeset
514 void Container::Delete(Time* item) {
223b71206888 Initial import
thib
parents:
diff changeset
515 pimpl_time->Delete(item);
223b71206888 Initial import
thib
parents:
diff changeset
516 }
223b71206888 Initial import
thib
parents:
diff changeset
517 void Container::RegisterGlobalMotionFunc(Container::motionfunc f, void* pointer) {
223b71206888 Initial import
thib
parents:
diff changeset
518 pimpl_video->RegisterGlobalMotionFunc(f, pointer);
223b71206888 Initial import
thib
parents:
diff changeset
519 }
223b71206888 Initial import
thib
parents:
diff changeset
520 void Container::DeleteGlobalMotionFunc(Container::motionfunc f, void* pointer) {
223b71206888 Initial import
thib
parents:
diff changeset
521 pimpl_video->DeleteGlobalMotionFunc(f, pointer);
223b71206888 Initial import
thib
parents:
diff changeset
522 }
223b71206888 Initial import
thib
parents:
diff changeset
523 void Container::RegisterGlobalPressFunc(Container::motionfunc f, void* pointer) {
223b71206888 Initial import
thib
parents:
diff changeset
524 pimpl_video->RegisterGlobalPressFunc(f, pointer);
223b71206888 Initial import
thib
parents:
diff changeset
525 }
223b71206888 Initial import
thib
parents:
diff changeset
526 void Container::DeleteGlobalPressFunc(Container::motionfunc f, void* pointer) {
223b71206888 Initial import
thib
parents:
diff changeset
527 pimpl_video->DeleteGlobalPressFunc(f, pointer);
223b71206888 Initial import
thib
parents:
diff changeset
528 }
223b71206888 Initial import
thib
parents:
diff changeset
529 bool Container::Exec(unsigned int time) {
223b71206888 Initial import
thib
parents:
diff changeset
530 current_time = time;
223b71206888 Initial import
thib
parents:
diff changeset
531 bool ret = true;
223b71206888 Initial import
thib
parents:
diff changeset
532 ret = ret && pimpl_video->Exec();
223b71206888 Initial import
thib
parents:
diff changeset
533 ret = ret && pimpl_time->Exec(time);
223b71206888 Initial import
thib
parents:
diff changeset
534 int i; int mask = 1;
223b71206888 Initial import
thib
parents:
diff changeset
535 int new_button_pressed = pimpl_video->button_pressed;
223b71206888 Initial import
thib
parents:
diff changeset
536 for (i=0; i<BUTTON_MAX; i++) {
223b71206888 Initial import
thib
parents:
diff changeset
537 if (pimpl_video->button_released&mask) {
223b71206888 Initial import
thib
parents:
diff changeset
538 button_presscount[i]++;
223b71206888 Initial import
thib
parents:
diff changeset
539 }
223b71206888 Initial import
thib
parents:
diff changeset
540 mask <<= 1;
223b71206888 Initial import
thib
parents:
diff changeset
541 }
223b71206888 Initial import
thib
parents:
diff changeset
542 pimpl_video->button_released = 0;
223b71206888 Initial import
thib
parents:
diff changeset
543 button_pressed = pimpl_video->button_pressed;
223b71206888 Initial import
thib
parents:
diff changeset
544 return ret;
223b71206888 Initial import
thib
parents:
diff changeset
545 }
223b71206888 Initial import
thib
parents:
diff changeset
546
223b71206888 Initial import
thib
parents:
diff changeset
547 void Container::MousePos(int& x, int& y) {
223b71206888 Initial import
thib
parents:
diff changeset
548 x = pimpl_video->mouse_x;
223b71206888 Initial import
thib
parents:
diff changeset
549 y = pimpl_video->mouse_y;
223b71206888 Initial import
thib
parents:
diff changeset
550 }
223b71206888 Initial import
thib
parents:
diff changeset
551
223b71206888 Initial import
thib
parents:
diff changeset
552 bool Container::pressed(int mask) {
223b71206888 Initial import
thib
parents:
diff changeset
553 if (mask < 0 || mask >= BUTTON_MAX) return 0;
223b71206888 Initial import
thib
parents:
diff changeset
554 return (button_pressed & (1<<mask)) != 0;
223b71206888 Initial import
thib
parents:
diff changeset
555 }
223b71206888 Initial import
thib
parents:
diff changeset
556 bool Container::presscount(int mask) {
223b71206888 Initial import
thib
parents:
diff changeset
557 if (mask < 0 || mask >= BUTTON_MAX) return 0;
223b71206888 Initial import
thib
parents:
diff changeset
558 int count = button_presscount[mask];
223b71206888 Initial import
thib
parents:
diff changeset
559 button_presscount[mask] = 0;
223b71206888 Initial import
thib
parents:
diff changeset
560 return count;
223b71206888 Initial import
thib
parents:
diff changeset
561 }
223b71206888 Initial import
thib
parents:
diff changeset
562
223b71206888 Initial import
thib
parents:
diff changeset
563 }; /* end of namespace Container */
223b71206888 Initial import
thib
parents:
diff changeset
564
223b71206888 Initial import
thib
parents:
diff changeset
565 // 問題:
223b71206888 Initial import
thib
parents:
diff changeset
566 // z 軸と xy 軸の相互干渉;高速化
223b71206888 Initial import
thib
parents:
diff changeset
567 // 移動するウィジット描画の高速化
223b71206888 Initial import
thib
parents:
diff changeset
568 // キャッシュ
223b71206888 Initial import
thib
parents:
diff changeset
569 // 文字列の一部のみ更新の高速化
223b71206888 Initial import
thib
parents:
diff changeset
570 // 「階層 z で x なる領域無効化、y なる領域生成」で良い?>Expose