annotate window/event.cc @ 68:043d5db57474

Fix index_series implementation (still incomplete)
author Thibaut Girka <thib@sitedethib.com>
date Wed, 23 Feb 2011 16:19:11 +0100
parents 4416cfac86ae
children
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
52
15a18fbe6f21 * Known bugs added to the README
thib
parents: 48
diff changeset
28 #include "SDL.h"
15a18fbe6f21 * Known bugs added to the README
thib
parents: 48
diff changeset
29 #include "event.h"
15a18fbe6f21 * Known bugs added to the README
thib
parents: 48
diff changeset
30 #include <vector>
15a18fbe6f21 * Known bugs added to the README
thib
parents: 48
diff changeset
31 #include <list>
15a18fbe6f21 * Known bugs added to the README
thib
parents: 48
diff changeset
32 #include <algorithm>
15a18fbe6f21 * Known bugs added to the README
thib
parents: 48
diff changeset
33 #include <iostream>
15a18fbe6f21 * Known bugs added to the README
thib
parents: 48
diff changeset
34 #include <sys/stat.h>
0
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
65
4416cfac86ae Convert EUC-JP files to UTF8
Thibaut Girka <thib@sitedethib.com>
parents: 52
diff changeset
38 bool save_req = false, load_req = false, grpdump_req = false; // scn2k/scn2k_impl.cc: キーボードからセーブ・ロードできるように
43
01aa5ddf7dc8 A lot of very minor improvements (deleted some unused variables, and other things like that...)
thib
parents: 0
diff changeset
39 bool pressAreq=false,pressFreq=false,pressDreq=false;
0
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
65
4416cfac86ae Convert EUC-JP files to UTF8
Thibaut Girka <thib@sitedethib.com>
parents: 52
diff changeset
76 /* カーソルの動く順序:上、左の順に準位付け */
0
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;
52
15a18fbe6f21 * Known bugs added to the README
thib
parents: 48
diff changeset
132 it->instance = NULL;
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;
52
15a18fbe6f21 * Known bugs added to the README
thib
parents: 48
diff changeset
138 it->instance = NULL;
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 }
52
15a18fbe6f21 * Known bugs added to the README
thib
parents: 48
diff changeset
142
0
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;
65
4416cfac86ae Convert EUC-JP files to UTF8
Thibaut Girka <thib@sitedethib.com>
parents: 52
diff changeset
145 // 呼び出しまでに作製されたitemを追加
0
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;
65
4416cfac86ae Convert EUC-JP files to UTF8
Thibaut Girka <thib@sitedethib.com>
parents: 52
diff changeset
149 if (current_time == Time::FRAME_UPDATE) { // ビデオフレームの更新時
0
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 }
65
4416cfac86ae Convert EUC-JP files to UTF8
Thibaut Girka <thib@sitedethib.com>
parents: 52
diff changeset
158 } else { // 時間変化時
4416cfac86ae Convert EUC-JP files to UTF8
Thibaut Girka <thib@sitedethib.com>
parents: 52
diff changeset
159 if (current_time < prev_execed_time) prev_execed_time = 0; /* 時間が一回りして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 }
65
4416cfac86ae Convert EUC-JP files to UTF8
Thibaut Girka <thib@sitedethib.com>
parents: 52
diff changeset
169 // 処理中に削除された item を実際に削除
0
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*> {
52
15a18fbe6f21 * Known bugs added to the README
thib
parents: 48
diff changeset
176 public:
15a18fbe6f21 * Known bugs added to the README
thib
parents: 48
diff changeset
177 bool Exec(void);
0
223b71206888 Initial import
thib
parents:
diff changeset
178
52
15a18fbe6f21 * Known bugs added to the README
thib
parents: 48
diff changeset
179 ContainerImplVideo(void);
15a18fbe6f21 * Known bugs added to the README
thib
parents: 48
diff changeset
180 ~ContainerImplVideo();
15a18fbe6f21 * Known bugs added to the README
thib
parents: 48
diff changeset
181 void Add(Video* item);
15a18fbe6f21 * Known bugs added to the README
thib
parents: 48
diff changeset
182 void Delete(Video* item);
15a18fbe6f21 * Known bugs added to the README
thib
parents: 48
diff changeset
183 void RegisterGlobalMotionFunc(Container::motionfunc, void* pointer);
15a18fbe6f21 * Known bugs added to the README
thib
parents: 48
diff changeset
184 void DeleteGlobalMotionFunc(Container::motionfunc, void* pointer);
15a18fbe6f21 * Known bugs added to the README
thib
parents: 48
diff changeset
185 void RegisterGlobalPressFunc(Container::motionfunc, void* pointer);
15a18fbe6f21 * Known bugs added to the README
thib
parents: 48
diff changeset
186 void DeleteGlobalPressFunc(Container::motionfunc, void* pointer);
15a18fbe6f21 * Known bugs added to the README
thib
parents: 48
diff changeset
187 private:
15a18fbe6f21 * Known bugs added to the README
thib
parents: 48
diff changeset
188 struct Motionfunc {
15a18fbe6f21 * Known bugs added to the README
thib
parents: 48
diff changeset
189 Container::motionfunc func;
15a18fbe6f21 * Known bugs added to the README
thib
parents: 48
diff changeset
190 void* pointer;
15a18fbe6f21 * Known bugs added to the README
thib
parents: 48
diff changeset
191 bool operator ==(const Motionfunc& m) const { return func == m.func && pointer == m.pointer;}
15a18fbe6f21 * Known bugs added to the README
thib
parents: 48
diff changeset
192 };
15a18fbe6f21 * Known bugs added to the README
thib
parents: 48
diff changeset
193 list<Motionfunc> motion_vec;
15a18fbe6f21 * Known bugs added to the README
thib
parents: 48
diff changeset
194 list<Motionfunc> press_vec;
15a18fbe6f21 * Known bugs added to the README
thib
parents: 48
diff changeset
195 typedef list<Motionfunc>::iterator MotionIterator;
15a18fbe6f21 * Known bugs added to the README
thib
parents: 48
diff changeset
196 bool is_sorted;
15a18fbe6f21 * Known bugs added to the README
thib
parents: 48
diff changeset
197 public:
15a18fbe6f21 * Known bugs added to the README
thib
parents: 48
diff changeset
198 int button_pressed;
15a18fbe6f21 * Known bugs added to the README
thib
parents: 48
diff changeset
199 int button_released;
15a18fbe6f21 * Known bugs added to the README
thib
parents: 48
diff changeset
200 int mouse_x, mouse_y;
15a18fbe6f21 * Known bugs added to the README
thib
parents: 48
diff changeset
201 int new_mouse_x, new_mouse_y;
15a18fbe6f21 * Known bugs added to the README
thib
parents: 48
diff changeset
202 private:
15a18fbe6f21 * Known bugs added to the README
thib
parents: 48
diff changeset
203 void SetChanged(void);
15a18fbe6f21 * Known bugs added to the README
thib
parents: 48
diff changeset
204 static bool SortLess(const Video* pos1, const Video* pos2) {
15a18fbe6f21 * Known bugs added to the README
thib
parents: 48
diff changeset
205 return pos1 < pos2;
15a18fbe6f21 * Known bugs added to the README
thib
parents: 48
diff changeset
206 }
15a18fbe6f21 * Known bugs added to the README
thib
parents: 48
diff changeset
207 void Sort(void);
15a18fbe6f21 * Known bugs added to the README
thib
parents: 48
diff changeset
208 void Motion(int x, int y); // mouse motion
15a18fbe6f21 * Known bugs added to the README
thib
parents: 48
diff changeset
209 void Press(void);
15a18fbe6f21 * Known bugs added to the README
thib
parents: 48
diff changeset
210 void TakeScreenshot(void);
15a18fbe6f21 * Known bugs added to the README
thib
parents: 48
diff changeset
211 iterator cur_pos;
65
4416cfac86ae Convert EUC-JP files to UTF8
Thibaut Girka <thib@sitedethib.com>
parents: 52
diff changeset
212 Video* cur_item; // 現在のフォーカス位置
52
15a18fbe6f21 * Known bugs added to the README
thib
parents: 48
diff changeset
213 int cur_pressed_x, cur_pressed_y;
0
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) {
52
15a18fbe6f21 * Known bugs added to the README
thib
parents: 48
diff changeset
218 if (cur_item != NULL) {
0
223b71206888 Initial import
thib
parents:
diff changeset
219 cur_pos = find(begin(), end(), cur_item);
52
15a18fbe6f21 * Known bugs added to the README
thib
parents: 48
diff changeset
220 if (cur_pos == end()) cur_item = NULL;
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);
52
15a18fbe6f21 * Known bugs added to the README
thib
parents: 48
diff changeset
228 if (cur_item != NULL) {
0
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;
52
15a18fbe6f21 * Known bugs added to the README
thib
parents: 48
diff changeset
240 cur_item = NULL;
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 }
52
15a18fbe6f21 * Known bugs added to the README
thib
parents: 48
diff changeset
244
0
223b71206888 Initial import
thib
parents:
diff changeset
245 ContainerImplVideo::~ContainerImplVideo(void) {
223b71206888 Initial import
thib
parents:
diff changeset
246 };
52
15a18fbe6f21 * Known bugs added to the README
thib
parents: 48
diff changeset
247
0
223b71206888 Initial import
thib
parents:
diff changeset
248 void ContainerImplVideo::Add(Video* event) {
223b71206888 Initial import
thib
parents:
diff changeset
249 push_back(event);
223b71206888 Initial import
thib
parents:
diff changeset
250 SetChanged();
223b71206888 Initial import
thib
parents:
diff changeset
251 }
52
15a18fbe6f21 * Known bugs added to the README
thib
parents: 48
diff changeset
252
0
223b71206888 Initial import
thib
parents:
diff changeset
253 void ContainerImplVideo::Delete(Video* delete_event) {
223b71206888 Initial import
thib
parents:
diff changeset
254 iterator it = find(begin(), end(), delete_event);
223b71206888 Initial import
thib
parents:
diff changeset
255 if (it != end()) {
223b71206888 Initial import
thib
parents:
diff changeset
256 erase(it);
223b71206888 Initial import
thib
parents:
diff changeset
257 SetChanged();
223b71206888 Initial import
thib
parents:
diff changeset
258 } else {
223b71206888 Initial import
thib
parents:
diff changeset
259 fprintf(stderr,"\nXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX\n");
48
ed6c21dde840 * use correct format (%p) for pointers
thib
parents: 43
diff changeset
260 fprintf(stderr,"X ContainerImplVideo: Cannot delete node %p\n",delete_event);
0
223b71206888 Initial import
thib
parents:
diff changeset
261 fprintf(stderr,"XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX\n\n");
223b71206888 Initial import
thib
parents:
diff changeset
262 fprintf(stderr,"vector from:\n");
223b71206888 Initial import
thib
parents:
diff changeset
263 for(it=begin(); it!=end(); it++) {
48
ed6c21dde840 * use correct format (%p) for pointers
thib
parents: 43
diff changeset
264 fprintf(stderr,"%p, ",*it);
0
223b71206888 Initial import
thib
parents:
diff changeset
265 }
223b71206888 Initial import
thib
parents:
diff changeset
266 fprintf(stderr,"\n");
223b71206888 Initial import
thib
parents:
diff changeset
267 }
223b71206888 Initial import
thib
parents:
diff changeset
268 if (delete_event == cur_item) {
223b71206888 Initial import
thib
parents:
diff changeset
269 cur_pos = end();
52
15a18fbe6f21 * Known bugs added to the README
thib
parents: 48
diff changeset
270 cur_item = NULL;
0
223b71206888 Initial import
thib
parents:
diff changeset
271 Motion(mouse_x, mouse_y);
223b71206888 Initial import
thib
parents:
diff changeset
272 }
223b71206888 Initial import
thib
parents:
diff changeset
273 }
52
15a18fbe6f21 * Known bugs added to the README
thib
parents: 48
diff changeset
274
0
223b71206888 Initial import
thib
parents:
diff changeset
275 void ContainerImplVideo::RegisterGlobalMotionFunc(Container::motionfunc func, void* pointer) {
223b71206888 Initial import
thib
parents:
diff changeset
276 Motionfunc f;
223b71206888 Initial import
thib
parents:
diff changeset
277 f.func = func;
223b71206888 Initial import
thib
parents:
diff changeset
278 f.pointer = pointer;
223b71206888 Initial import
thib
parents:
diff changeset
279 if (find(motion_vec.begin(), motion_vec.end(), f) == motion_vec.end()) {
223b71206888 Initial import
thib
parents:
diff changeset
280 motion_vec.push_back(f);
223b71206888 Initial import
thib
parents:
diff changeset
281 }
223b71206888 Initial import
thib
parents:
diff changeset
282 }
52
15a18fbe6f21 * Known bugs added to the README
thib
parents: 48
diff changeset
283
0
223b71206888 Initial import
thib
parents:
diff changeset
284 void ContainerImplVideo::DeleteGlobalMotionFunc(Container::motionfunc func, void* pointer) {
223b71206888 Initial import
thib
parents:
diff changeset
285 Motionfunc f;
223b71206888 Initial import
thib
parents:
diff changeset
286 f.func = func;
223b71206888 Initial import
thib
parents:
diff changeset
287 f.pointer = pointer;
223b71206888 Initial import
thib
parents:
diff changeset
288 list<Motionfunc>::iterator it = find(motion_vec.begin(), motion_vec.end(), f);
223b71206888 Initial import
thib
parents:
diff changeset
289 if (it != motion_vec.end())
223b71206888 Initial import
thib
parents:
diff changeset
290 motion_vec.erase(it);
223b71206888 Initial import
thib
parents:
diff changeset
291 }
52
15a18fbe6f21 * Known bugs added to the README
thib
parents: 48
diff changeset
292
0
223b71206888 Initial import
thib
parents:
diff changeset
293 void ContainerImplVideo::RegisterGlobalPressFunc(Container::motionfunc func, void* pointer) {
223b71206888 Initial import
thib
parents:
diff changeset
294 Motionfunc f;
223b71206888 Initial import
thib
parents:
diff changeset
295 f.func = func;
223b71206888 Initial import
thib
parents:
diff changeset
296 f.pointer = pointer;
223b71206888 Initial import
thib
parents:
diff changeset
297 if (find(press_vec.begin(), press_vec.end(), f) == press_vec.end()) {
223b71206888 Initial import
thib
parents:
diff changeset
298 press_vec.push_back(f);
223b71206888 Initial import
thib
parents:
diff changeset
299 }
223b71206888 Initial import
thib
parents:
diff changeset
300 }
52
15a18fbe6f21 * Known bugs added to the README
thib
parents: 48
diff changeset
301
0
223b71206888 Initial import
thib
parents:
diff changeset
302 void ContainerImplVideo::DeleteGlobalPressFunc(Container::motionfunc func, void* pointer) {
223b71206888 Initial import
thib
parents:
diff changeset
303 Motionfunc f;
223b71206888 Initial import
thib
parents:
diff changeset
304 f.func = func;
223b71206888 Initial import
thib
parents:
diff changeset
305 f.pointer = pointer;
223b71206888 Initial import
thib
parents:
diff changeset
306 list<Motionfunc>::iterator it = find(press_vec.begin(), press_vec.end(), f);
223b71206888 Initial import
thib
parents:
diff changeset
307 if (it != press_vec.end())
223b71206888 Initial import
thib
parents:
diff changeset
308 press_vec.erase(it);
223b71206888 Initial import
thib
parents:
diff changeset
309 }
52
15a18fbe6f21 * Known bugs added to the README
thib
parents: 48
diff changeset
310
0
223b71206888 Initial import
thib
parents:
diff changeset
311 void ContainerImplVideo::Motion(int x, int y) {
223b71206888 Initial import
thib
parents:
diff changeset
312 mouse_x = x; mouse_y = y;
223b71206888 Initial import
thib
parents:
diff changeset
313 MotionIterator mit;
223b71206888 Initial import
thib
parents:
diff changeset
314 for (mit=motion_vec.begin(); mit != motion_vec.end();) {
223b71206888 Initial import
thib
parents:
diff changeset
315 MotionIterator mit_next = mit;
223b71206888 Initial import
thib
parents:
diff changeset
316 mit_next++;
223b71206888 Initial import
thib
parents:
diff changeset
317 if (!(*mit->func)(x, y, mit->pointer)) motion_vec.erase(mit);
223b71206888 Initial import
thib
parents:
diff changeset
318 mit = mit_next;
223b71206888 Initial import
thib
parents:
diff changeset
319
223b71206888 Initial import
thib
parents:
diff changeset
320 }
223b71206888 Initial import
thib
parents:
diff changeset
321
65
4416cfac86ae Convert EUC-JP files to UTF8
Thibaut Girka <thib@sitedethib.com>
parents: 52
diff changeset
322 /* @@@ ドラッグ処理とマウスを押す処理のバッティングで「二回ボタンを押さないと云々」関連のバグの可能性あり */
0
223b71206888 Initial import
thib
parents:
diff changeset
323 if (button_pressed & (1<<MOUSE_LEFT)) {
223b71206888 Initial import
thib
parents:
diff changeset
324 if (cur_item) cur_item->Drag(cur_pressed_x, cur_pressed_y, x, y);
223b71206888 Initial import
thib
parents:
diff changeset
325 return;
223b71206888 Initial import
thib
parents:
diff changeset
326 }
52
15a18fbe6f21 * Known bugs added to the README
thib
parents: 48
diff changeset
327 if (cur_item != NULL) cur_item->Motion(x,y);
0
223b71206888 Initial import
thib
parents:
diff changeset
328 int z = -1; iterator z_it;
223b71206888 Initial import
thib
parents:
diff changeset
329 iterator it;
223b71206888 Initial import
thib
parents:
diff changeset
330 for (it = begin(); it != end(); it++) {
223b71206888 Initial import
thib
parents:
diff changeset
331 int new_z = (*it)->point_in(x, y);
223b71206888 Initial import
thib
parents:
diff changeset
332 if (z < new_z) {
223b71206888 Initial import
thib
parents:
diff changeset
333 z = new_z;
223b71206888 Initial import
thib
parents:
diff changeset
334 z_it = it;
223b71206888 Initial import
thib
parents:
diff changeset
335 }
223b71206888 Initial import
thib
parents:
diff changeset
336 }
223b71206888 Initial import
thib
parents:
diff changeset
337 if (z != -1) {
223b71206888 Initial import
thib
parents:
diff changeset
338 if (cur_item == *z_it) return;
223b71206888 Initial import
thib
parents:
diff changeset
339 if (cur_item) cur_item->Out();
223b71206888 Initial import
thib
parents:
diff changeset
340 cur_pos = z_it;
223b71206888 Initial import
thib
parents:
diff changeset
341 cur_item = *z_it;
223b71206888 Initial import
thib
parents:
diff changeset
342 cur_item->In();
223b71206888 Initial import
thib
parents:
diff changeset
343 return;
223b71206888 Initial import
thib
parents:
diff changeset
344 } else {
223b71206888 Initial import
thib
parents:
diff changeset
345 if (cur_item) cur_item->Out();
223b71206888 Initial import
thib
parents:
diff changeset
346 cur_pos = end();
52
15a18fbe6f21 * Known bugs added to the README
thib
parents: 48
diff changeset
347 cur_item = NULL;
0
223b71206888 Initial import
thib
parents:
diff changeset
348 }
223b71206888 Initial import
thib
parents:
diff changeset
349 return;
223b71206888 Initial import
thib
parents:
diff changeset
350 }
223b71206888 Initial import
thib
parents:
diff changeset
351
223b71206888 Initial import
thib
parents:
diff changeset
352 void ContainerImplVideo::Press(void) {
223b71206888 Initial import
thib
parents:
diff changeset
353 if (cur_item) {
223b71206888 Initial import
thib
parents:
diff changeset
354 cur_pressed_x = mouse_x;
223b71206888 Initial import
thib
parents:
diff changeset
355 cur_pressed_y = mouse_y;
223b71206888 Initial import
thib
parents:
diff changeset
356 cur_item->Press();
223b71206888 Initial import
thib
parents:
diff changeset
357 return;
223b71206888 Initial import
thib
parents:
diff changeset
358 }
223b71206888 Initial import
thib
parents:
diff changeset
359 MotionIterator mit;
223b71206888 Initial import
thib
parents:
diff changeset
360 for (mit=press_vec.begin(); mit != press_vec.end(); ) {
223b71206888 Initial import
thib
parents:
diff changeset
361 MotionIterator mit_next = mit;
223b71206888 Initial import
thib
parents:
diff changeset
362 mit_next++;
223b71206888 Initial import
thib
parents:
diff changeset
363 if (!(*mit->func)(mouse_x, mouse_y, mit->pointer)) {
223b71206888 Initial import
thib
parents:
diff changeset
364 press_vec.erase(mit);
223b71206888 Initial import
thib
parents:
diff changeset
365 }
223b71206888 Initial import
thib
parents:
diff changeset
366 mit = mit_next;
223b71206888 Initial import
thib
parents:
diff changeset
367 }
223b71206888 Initial import
thib
parents:
diff changeset
368 }
52
15a18fbe6f21 * Known bugs added to the README
thib
parents: 48
diff changeset
369
0
223b71206888 Initial import
thib
parents:
diff changeset
370 void ContainerImplVideo::TakeScreenshot(void) {
223b71206888 Initial import
thib
parents:
diff changeset
371 int n=0;
223b71206888 Initial import
thib
parents:
diff changeset
372 char filename[1024];
223b71206888 Initial import
thib
parents:
diff changeset
373 struct stat buffer;
223b71206888 Initial import
thib
parents:
diff changeset
374 for(n=0; n<9999; n++) {
223b71206888 Initial import
thib
parents:
diff changeset
375 // XXX: put screenshots in a seperate dir?
223b71206888 Initial import
thib
parents:
diff changeset
376 sprintf(filename, "xclannad_%04i.bmp", n);
223b71206888 Initial import
thib
parents:
diff changeset
377 if(stat(filename, &buffer) == -1) break;
223b71206888 Initial import
thib
parents:
diff changeset
378 }
223b71206888 Initial import
thib
parents:
diff changeset
379 SDL_SaveBMP(SDL_GetVideoSurface(), filename);
223b71206888 Initial import
thib
parents:
diff changeset
380 }
52
15a18fbe6f21 * Known bugs added to the README
thib
parents: 48
diff changeset
381
0
223b71206888 Initial import
thib
parents:
diff changeset
382 bool ContainerImplVideo::Exec(void) {
223b71206888 Initial import
thib
parents:
diff changeset
383 bool is_mouse_motion = false;
223b71206888 Initial import
thib
parents:
diff changeset
384 int motion_x = 0, motion_y = 0;
223b71206888 Initial import
thib
parents:
diff changeset
385 SDL_Event event;
223b71206888 Initial import
thib
parents:
diff changeset
386 SDL_PumpEvents();
223b71206888 Initial import
thib
parents:
diff changeset
387 while(SDL_PeepEvents(&event, 1, SDL_GETEVENT, SDL_ALLEVENTS) == 1) {
223b71206888 Initial import
thib
parents:
diff changeset
388 switch(event.type) {
65
4416cfac86ae Convert EUC-JP files to UTF8
Thibaut Girka <thib@sitedethib.com>
parents: 52
diff changeset
389 case SDL_QUIT: return false; // @@@ なにかやらないと
4416cfac86ae Convert EUC-JP files to UTF8
Thibaut Girka <thib@sitedethib.com>
parents: 52
diff changeset
390 case SDL_ACTIVEEVENT: // なにもしない
52
15a18fbe6f21 * Known bugs added to the README
thib
parents: 48
diff changeset
391 // cout<<"active : gain "<<int(event.active.gain)<<", state "<<int(event.active.state)<<endl;
0
223b71206888 Initial import
thib
parents:
diff changeset
392 break;
52
15a18fbe6f21 * Known bugs added to the README
thib
parents: 48
diff changeset
393 case SDL_KEYDOWN:
15a18fbe6f21 * Known bugs added to the README
thib
parents: 48
diff changeset
394 if (!is_sorted) Sort();
15a18fbe6f21 * Known bugs added to the README
thib
parents: 48
diff changeset
395 switch(event.key.keysym.sym) {
15a18fbe6f21 * Known bugs added to the README
thib
parents: 48
diff changeset
396 case SDLK_F12:
15a18fbe6f21 * Known bugs added to the README
thib
parents: 48
diff changeset
397 case SDLK_PRINT:
15a18fbe6f21 * Known bugs added to the README
thib
parents: 48
diff changeset
398 case SDLK_p: // for Zaurus
15a18fbe6f21 * Known bugs added to the README
thib
parents: 48
diff changeset
399 TakeScreenshot();
15a18fbe6f21 * Known bugs added to the README
thib
parents: 48
diff changeset
400 break;
15a18fbe6f21 * Known bugs added to the README
thib
parents: 48
diff changeset
401 // Some window managers (eg enlightenment) use Alt-Enter for
15a18fbe6f21 * Known bugs added to the README
thib
parents: 48
diff changeset
402 // themselves, F11 is a good alternative
15a18fbe6f21 * Known bugs added to the README
thib
parents: 48
diff changeset
403 case SDLK_F11:
15a18fbe6f21 * Known bugs added to the README
thib
parents: 48
diff changeset
404 SDL_WM_ToggleFullScreen(SDL_GetVideoSurface());
15a18fbe6f21 * Known bugs added to the README
thib
parents: 48
diff changeset
405 break;
15a18fbe6f21 * Known bugs added to the README
thib
parents: 48
diff changeset
406 case SDLK_RETURN:
15a18fbe6f21 * Known bugs added to the README
thib
parents: 48
diff changeset
407 if (SDL_GetModState() & KMOD_ALT) {
15a18fbe6f21 * Known bugs added to the README
thib
parents: 48
diff changeset
408 SDL_WM_ToggleFullScreen(SDL_GetVideoSurface());
15a18fbe6f21 * Known bugs added to the README
thib
parents: 48
diff changeset
409 break;
15a18fbe6f21 * Known bugs added to the README
thib
parents: 48
diff changeset
410 }
15a18fbe6f21 * Known bugs added to the README
thib
parents: 48
diff changeset
411 case SDLK_SPACE:
15a18fbe6f21 * Known bugs added to the README
thib
parents: 48
diff changeset
412 Press();
15a18fbe6f21 * Known bugs added to the README
thib
parents: 48
diff changeset
413 break;
15a18fbe6f21 * Known bugs added to the README
thib
parents: 48
diff changeset
414 case SDLK_TAB: // move to next widget
15a18fbe6f21 * Known bugs added to the README
thib
parents: 48
diff changeset
415 if (cur_pos != end()) cur_pos++;
15a18fbe6f21 * Known bugs added to the README
thib
parents: 48
diff changeset
416 if (cur_pos == end()) cur_pos = begin();
15a18fbe6f21 * Known bugs added to the README
thib
parents: 48
diff changeset
417 if (cur_pos != end()) {
15a18fbe6f21 * Known bugs added to the README
thib
parents: 48
diff changeset
418 cur_item = *cur_pos;
15a18fbe6f21 * Known bugs added to the README
thib
parents: 48
diff changeset
419 cur_item->In();
15a18fbe6f21 * Known bugs added to the README
thib
parents: 48
diff changeset
420 } else {
15a18fbe6f21 * Known bugs added to the README
thib
parents: 48
diff changeset
421 cur_item = NULL;
15a18fbe6f21 * Known bugs added to the README
thib
parents: 48
diff changeset
422 }
15a18fbe6f21 * Known bugs added to the README
thib
parents: 48
diff changeset
423 break;
15a18fbe6f21 * Known bugs added to the README
thib
parents: 48
diff changeset
424 case SDLK_LEFT: if (cur_pos != end()) (*cur_pos)->KeyLeft(); break;
15a18fbe6f21 * Known bugs added to the README
thib
parents: 48
diff changeset
425 case SDLK_RIGHT:if (cur_pos != end()) (*cur_pos)->KeyRight(); break;
15a18fbe6f21 * Known bugs added to the README
thib
parents: 48
diff changeset
426 case SDLK_LSHIFT: case SDLK_RSHIFT: button_pressed |= (1<<KEY_SHIFT); break;
15a18fbe6f21 * Known bugs added to the README
thib
parents: 48
diff changeset
427 case SDLK_ESCAPE: button_pressed |= (1<<MOUSE_RIGHT); break; /* for Zaurus */
15a18fbe6f21 * Known bugs added to the README
thib
parents: 48
diff changeset
428 case SDLK_s: save_req = true; break;
15a18fbe6f21 * Known bugs added to the README
thib
parents: 48
diff changeset
429 case SDLK_l: load_req = true; break;
15a18fbe6f21 * Known bugs added to the README
thib
parents: 48
diff changeset
430 case SDLK_g: grpdump_req = true; break;
15a18fbe6f21 * Known bugs added to the README
thib
parents: 48
diff changeset
431 case SDLK_a: pressAreq = true; break;
15a18fbe6f21 * Known bugs added to the README
thib
parents: 48
diff changeset
432 case SDLK_d: pressDreq = true; break;
15a18fbe6f21 * Known bugs added to the README
thib
parents: 48
diff changeset
433 case SDLK_f: pressFreq = true; break;
0
223b71206888 Initial import
thib
parents:
diff changeset
434 }
223b71206888 Initial import
thib
parents:
diff changeset
435 break;
52
15a18fbe6f21 * Known bugs added to the README
thib
parents: 48
diff changeset
436 case SDL_KEYUP:
15a18fbe6f21 * Known bugs added to the README
thib
parents: 48
diff changeset
437 // cout << "keyup which "<<int(event.key.which)<<", sym "<<int(event.key.keysym.sym)<<endl;
15a18fbe6f21 * Known bugs added to the README
thib
parents: 48
diff changeset
438 switch(event.key.keysym.sym) {
15a18fbe6f21 * Known bugs added to the README
thib
parents: 48
diff changeset
439 case SDLK_RETURN: case SDLK_SPACE:
15a18fbe6f21 * Known bugs added to the README
thib
parents: 48
diff changeset
440 if (cur_item) cur_item->Release();
15a18fbe6f21 * Known bugs added to the README
thib
parents: 48
diff changeset
441 case SDLK_LSHIFT: case SDLK_RSHIFT: button_pressed &= ~(1<<KEY_SHIFT); button_released |= 1<<KEY_SHIFT; break;
15a18fbe6f21 * Known bugs added to the README
thib
parents: 48
diff changeset
442 case SDLK_ESCAPE: button_pressed &= ~(1<<MOUSE_RIGHT); button_released |= 1<<MOUSE_RIGHT; break; /* for Zaurus */
0
223b71206888 Initial import
thib
parents:
diff changeset
443 }
223b71206888 Initial import
thib
parents:
diff changeset
444 break;
52
15a18fbe6f21 * Known bugs added to the README
thib
parents: 48
diff changeset
445 case SDL_MOUSEMOTION:
15a18fbe6f21 * Known bugs added to the README
thib
parents: 48
diff changeset
446 motion_x = event.motion.x;
15a18fbe6f21 * Known bugs added to the README
thib
parents: 48
diff changeset
447 motion_y = event.motion.y;
15a18fbe6f21 * Known bugs added to the README
thib
parents: 48
diff changeset
448 is_mouse_motion = true;
15a18fbe6f21 * Known bugs added to the README
thib
parents: 48
diff changeset
449 // Motion(event.motion.x, event.motion.y);
15a18fbe6f21 * Known bugs added to the README
thib
parents: 48
diff changeset
450 // cout<< "motion which "<<int(event.motion.which)<<
15a18fbe6f21 * Known bugs added to the README
thib
parents: 48
diff changeset
451 // "x "<<event.motion.x << "y "<<event.motion.y<<endl;
15a18fbe6f21 * Known bugs added to the README
thib
parents: 48
diff changeset
452 break;
15a18fbe6f21 * Known bugs added to the README
thib
parents: 48
diff changeset
453 case SDL_MOUSEBUTTONUP:
15a18fbe6f21 * Known bugs added to the README
thib
parents: 48
diff changeset
454 if (event.button.button == 1) {
15a18fbe6f21 * Known bugs added to the README
thib
parents: 48
diff changeset
455 Motion(event.button.x, event.button.y);
15a18fbe6f21 * Known bugs added to the README
thib
parents: 48
diff changeset
456 is_mouse_motion = false;
15a18fbe6f21 * Known bugs added to the README
thib
parents: 48
diff changeset
457 if (cur_item) cur_item->Release();
15a18fbe6f21 * Known bugs added to the README
thib
parents: 48
diff changeset
458 }
15a18fbe6f21 * Known bugs added to the README
thib
parents: 48
diff changeset
459 switch(event.button.button) {
15a18fbe6f21 * Known bugs added to the README
thib
parents: 48
diff changeset
460 case 1:
15a18fbe6f21 * Known bugs added to the README
thib
parents: 48
diff changeset
461 button_pressed &= ~(1<<MOUSE_LEFT);
15a18fbe6f21 * Known bugs added to the README
thib
parents: 48
diff changeset
462 button_released |= 1<<MOUSE_LEFT;
15a18fbe6f21 * Known bugs added to the README
thib
parents: 48
diff changeset
463 break;
15a18fbe6f21 * Known bugs added to the README
thib
parents: 48
diff changeset
464 case 2:
15a18fbe6f21 * Known bugs added to the README
thib
parents: 48
diff changeset
465 button_pressed &= ~(1<<MOUSE_MIDDLE);
15a18fbe6f21 * Known bugs added to the README
thib
parents: 48
diff changeset
466 button_released |= 1<<MOUSE_MIDDLE;
15a18fbe6f21 * Known bugs added to the README
thib
parents: 48
diff changeset
467 break;
15a18fbe6f21 * Known bugs added to the README
thib
parents: 48
diff changeset
468 case 3:
15a18fbe6f21 * Known bugs added to the README
thib
parents: 48
diff changeset
469 button_pressed &= ~(1<<MOUSE_RIGHT);
15a18fbe6f21 * Known bugs added to the README
thib
parents: 48
diff changeset
470 button_released |= 1<<MOUSE_RIGHT;
15a18fbe6f21 * Known bugs added to the README
thib
parents: 48
diff changeset
471 break;
15a18fbe6f21 * Known bugs added to the README
thib
parents: 48
diff changeset
472 case 4:
15a18fbe6f21 * Known bugs added to the README
thib
parents: 48
diff changeset
473 button_pressed &= ~(1<<MOUSE_UP);
15a18fbe6f21 * Known bugs added to the README
thib
parents: 48
diff changeset
474 button_released |= 1<<MOUSE_UP;
15a18fbe6f21 * Known bugs added to the README
thib
parents: 48
diff changeset
475 break;
15a18fbe6f21 * Known bugs added to the README
thib
parents: 48
diff changeset
476 case 5:
15a18fbe6f21 * Known bugs added to the README
thib
parents: 48
diff changeset
477 button_pressed &= ~(1<<MOUSE_DOWN);
15a18fbe6f21 * Known bugs added to the README
thib
parents: 48
diff changeset
478 button_released |= 1<<MOUSE_DOWN;
15a18fbe6f21 * Known bugs added to the README
thib
parents: 48
diff changeset
479 break;
15a18fbe6f21 * Known bugs added to the README
thib
parents: 48
diff changeset
480 }
15a18fbe6f21 * Known bugs added to the README
thib
parents: 48
diff changeset
481 break;
15a18fbe6f21 * Known bugs added to the README
thib
parents: 48
diff changeset
482 case SDL_MOUSEBUTTONDOWN:
15a18fbe6f21 * Known bugs added to the README
thib
parents: 48
diff changeset
483 if (event.button.button == 1) {
15a18fbe6f21 * Known bugs added to the README
thib
parents: 48
diff changeset
484 Motion(event.button.x, event.button.y);
15a18fbe6f21 * Known bugs added to the README
thib
parents: 48
diff changeset
485 is_mouse_motion = false;
15a18fbe6f21 * Known bugs added to the README
thib
parents: 48
diff changeset
486 Press();
15a18fbe6f21 * Known bugs added to the README
thib
parents: 48
diff changeset
487 }
15a18fbe6f21 * Known bugs added to the README
thib
parents: 48
diff changeset
488 switch(event.button.button) {
15a18fbe6f21 * Known bugs added to the README
thib
parents: 48
diff changeset
489 case 1: button_pressed |= (1<<MOUSE_LEFT); break;
15a18fbe6f21 * Known bugs added to the README
thib
parents: 48
diff changeset
490 case 2: button_pressed |= (1<<MOUSE_MIDDLE); break;
15a18fbe6f21 * Known bugs added to the README
thib
parents: 48
diff changeset
491 case 3: button_pressed |= (1<<MOUSE_RIGHT); break;
15a18fbe6f21 * Known bugs added to the README
thib
parents: 48
diff changeset
492 case 4: button_pressed |= (1<<MOUSE_UP); break;
15a18fbe6f21 * Known bugs added to the README
thib
parents: 48
diff changeset
493 case 5: button_pressed |= (1<<MOUSE_DOWN); break;
15a18fbe6f21 * Known bugs added to the README
thib
parents: 48
diff changeset
494 }
15a18fbe6f21 * Known bugs added to the README
thib
parents: 48
diff changeset
495 // cout << "mouse which "<<int(event.button.which)<<"button "<<int(event.button.button)<<
15a18fbe6f21 * Known bugs added to the README
thib
parents: 48
diff changeset
496 // "state "<<int(event.button.state)<<"x "<<event.button.x << "y "<<event.button.y<<endl;
15a18fbe6f21 * Known bugs added to the README
thib
parents: 48
diff changeset
497 break;
65
4416cfac86ae Convert EUC-JP files to UTF8
Thibaut Girka <thib@sitedethib.com>
parents: 52
diff changeset
498 case SDL_VIDEOEXPOSE: // redraw の必要がある?
52
15a18fbe6f21 * Known bugs added to the README
thib
parents: 48
diff changeset
499 // cout<<"expose."<<endl;
15a18fbe6f21 * Known bugs added to the README
thib
parents: 48
diff changeset
500 break;
0
223b71206888 Initial import
thib
parents:
diff changeset
501 }
223b71206888 Initial import
thib
parents:
diff changeset
502 }
65
4416cfac86ae Convert EUC-JP files to UTF8
Thibaut Girka <thib@sitedethib.com>
parents: 52
diff changeset
503 // Motion 呼び出しは一回だけ
0
223b71206888 Initial import
thib
parents:
diff changeset
504 if (is_mouse_motion)
223b71206888 Initial import
thib
parents:
diff changeset
505 Motion(motion_x, motion_y);
223b71206888 Initial import
thib
parents:
diff changeset
506 return true;
52
15a18fbe6f21 * Known bugs added to the README
thib
parents: 48
diff changeset
507 }
15a18fbe6f21 * Known bugs added to the README
thib
parents: 48
diff changeset
508
0
223b71206888 Initial import
thib
parents:
diff changeset
509 /* Impl: struct Event::Container */
223b71206888 Initial import
thib
parents:
diff changeset
510 Container::Container(void) {
223b71206888 Initial import
thib
parents:
diff changeset
511 pimpl_video = new ContainerImplVideo;
223b71206888 Initial import
thib
parents:
diff changeset
512 try {
223b71206888 Initial import
thib
parents:
diff changeset
513 pimpl_time = new ContainerImplTime;
223b71206888 Initial import
thib
parents:
diff changeset
514 } catch(...) {
223b71206888 Initial import
thib
parents:
diff changeset
515 delete pimpl_video;
223b71206888 Initial import
thib
parents:
diff changeset
516 throw;
223b71206888 Initial import
thib
parents:
diff changeset
517 }
223b71206888 Initial import
thib
parents:
diff changeset
518 button_pressed = 0;
223b71206888 Initial import
thib
parents:
diff changeset
519 current_time = 0;
52
15a18fbe6f21 * Known bugs added to the README
thib
parents: 48
diff changeset
520 int i;
15a18fbe6f21 * Known bugs added to the README
thib
parents: 48
diff changeset
521 for (i=0; i<BUTTON_MAX; i++) button_presscount[i] = 0;
0
223b71206888 Initial import
thib
parents:
diff changeset
522 }
52
15a18fbe6f21 * Known bugs added to the README
thib
parents: 48
diff changeset
523
0
223b71206888 Initial import
thib
parents:
diff changeset
524 Container::~Container(void) {
223b71206888 Initial import
thib
parents:
diff changeset
525 delete pimpl_video;
223b71206888 Initial import
thib
parents:
diff changeset
526 delete pimpl_time;
223b71206888 Initial import
thib
parents:
diff changeset
527 }
52
15a18fbe6f21 * Known bugs added to the README
thib
parents: 48
diff changeset
528
0
223b71206888 Initial import
thib
parents:
diff changeset
529 void Container::Add(Video* item) {
223b71206888 Initial import
thib
parents:
diff changeset
530 pimpl_video->Add(item);
223b71206888 Initial import
thib
parents:
diff changeset
531 }
52
15a18fbe6f21 * Known bugs added to the README
thib
parents: 48
diff changeset
532
0
223b71206888 Initial import
thib
parents:
diff changeset
533 void Container::Delete(Video* item) {
223b71206888 Initial import
thib
parents:
diff changeset
534 pimpl_video->Delete(item);
223b71206888 Initial import
thib
parents:
diff changeset
535 }
52
15a18fbe6f21 * Known bugs added to the README
thib
parents: 48
diff changeset
536
0
223b71206888 Initial import
thib
parents:
diff changeset
537 void Container::Add(Time* item) {
223b71206888 Initial import
thib
parents:
diff changeset
538 pimpl_time->Add(item);
223b71206888 Initial import
thib
parents:
diff changeset
539 }
52
15a18fbe6f21 * Known bugs added to the README
thib
parents: 48
diff changeset
540
0
223b71206888 Initial import
thib
parents:
diff changeset
541 void Container::Delete(Time* item) {
223b71206888 Initial import
thib
parents:
diff changeset
542 pimpl_time->Delete(item);
223b71206888 Initial import
thib
parents:
diff changeset
543 }
52
15a18fbe6f21 * Known bugs added to the README
thib
parents: 48
diff changeset
544
0
223b71206888 Initial import
thib
parents:
diff changeset
545 void Container::RegisterGlobalMotionFunc(Container::motionfunc f, void* pointer) {
223b71206888 Initial import
thib
parents:
diff changeset
546 pimpl_video->RegisterGlobalMotionFunc(f, pointer);
223b71206888 Initial import
thib
parents:
diff changeset
547 }
52
15a18fbe6f21 * Known bugs added to the README
thib
parents: 48
diff changeset
548
0
223b71206888 Initial import
thib
parents:
diff changeset
549 void Container::DeleteGlobalMotionFunc(Container::motionfunc f, void* pointer) {
223b71206888 Initial import
thib
parents:
diff changeset
550 pimpl_video->DeleteGlobalMotionFunc(f, pointer);
223b71206888 Initial import
thib
parents:
diff changeset
551 }
52
15a18fbe6f21 * Known bugs added to the README
thib
parents: 48
diff changeset
552
0
223b71206888 Initial import
thib
parents:
diff changeset
553 void Container::RegisterGlobalPressFunc(Container::motionfunc f, void* pointer) {
223b71206888 Initial import
thib
parents:
diff changeset
554 pimpl_video->RegisterGlobalPressFunc(f, pointer);
223b71206888 Initial import
thib
parents:
diff changeset
555 }
52
15a18fbe6f21 * Known bugs added to the README
thib
parents: 48
diff changeset
556
0
223b71206888 Initial import
thib
parents:
diff changeset
557 void Container::DeleteGlobalPressFunc(Container::motionfunc f, void* pointer) {
223b71206888 Initial import
thib
parents:
diff changeset
558 pimpl_video->DeleteGlobalPressFunc(f, pointer);
223b71206888 Initial import
thib
parents:
diff changeset
559 }
52
15a18fbe6f21 * Known bugs added to the README
thib
parents: 48
diff changeset
560
0
223b71206888 Initial import
thib
parents:
diff changeset
561 bool Container::Exec(unsigned int time) {
223b71206888 Initial import
thib
parents:
diff changeset
562 current_time = time;
223b71206888 Initial import
thib
parents:
diff changeset
563 bool ret = true;
223b71206888 Initial import
thib
parents:
diff changeset
564 ret = ret && pimpl_video->Exec();
223b71206888 Initial import
thib
parents:
diff changeset
565 ret = ret && pimpl_time->Exec(time);
223b71206888 Initial import
thib
parents:
diff changeset
566 int i; int mask = 1;
43
01aa5ddf7dc8 A lot of very minor improvements (deleted some unused variables, and other things like that...)
thib
parents: 0
diff changeset
567
0
223b71206888 Initial import
thib
parents:
diff changeset
568 for (i=0; i<BUTTON_MAX; i++) {
223b71206888 Initial import
thib
parents:
diff changeset
569 if (pimpl_video->button_released&mask) {
223b71206888 Initial import
thib
parents:
diff changeset
570 button_presscount[i]++;
223b71206888 Initial import
thib
parents:
diff changeset
571 }
223b71206888 Initial import
thib
parents:
diff changeset
572 mask <<= 1;
223b71206888 Initial import
thib
parents:
diff changeset
573 }
223b71206888 Initial import
thib
parents:
diff changeset
574 pimpl_video->button_released = 0;
223b71206888 Initial import
thib
parents:
diff changeset
575 button_pressed = pimpl_video->button_pressed;
223b71206888 Initial import
thib
parents:
diff changeset
576 return ret;
223b71206888 Initial import
thib
parents:
diff changeset
577 }
223b71206888 Initial import
thib
parents:
diff changeset
578
223b71206888 Initial import
thib
parents:
diff changeset
579 void Container::MousePos(int& x, int& y) {
223b71206888 Initial import
thib
parents:
diff changeset
580 x = pimpl_video->mouse_x;
223b71206888 Initial import
thib
parents:
diff changeset
581 y = pimpl_video->mouse_y;
223b71206888 Initial import
thib
parents:
diff changeset
582 }
223b71206888 Initial import
thib
parents:
diff changeset
583
223b71206888 Initial import
thib
parents:
diff changeset
584 bool Container::pressed(int mask) {
223b71206888 Initial import
thib
parents:
diff changeset
585 if (mask < 0 || mask >= BUTTON_MAX) return 0;
223b71206888 Initial import
thib
parents:
diff changeset
586 return (button_pressed & (1<<mask)) != 0;
223b71206888 Initial import
thib
parents:
diff changeset
587 }
52
15a18fbe6f21 * Known bugs added to the README
thib
parents: 48
diff changeset
588
0
223b71206888 Initial import
thib
parents:
diff changeset
589 bool Container::presscount(int mask) {
223b71206888 Initial import
thib
parents:
diff changeset
590 if (mask < 0 || mask >= BUTTON_MAX) return 0;
223b71206888 Initial import
thib
parents:
diff changeset
591 int count = button_presscount[mask];
223b71206888 Initial import
thib
parents:
diff changeset
592 button_presscount[mask] = 0;
223b71206888 Initial import
thib
parents:
diff changeset
593 return count;
223b71206888 Initial import
thib
parents:
diff changeset
594 }
223b71206888 Initial import
thib
parents:
diff changeset
595
52
15a18fbe6f21 * Known bugs added to the README
thib
parents: 48
diff changeset
596 } /* end of namespace Container */
0
223b71206888 Initial import
thib
parents:
diff changeset
597
65
4416cfac86ae Convert EUC-JP files to UTF8
Thibaut Girka <thib@sitedethib.com>
parents: 52
diff changeset
598 // 問題:
4416cfac86ae Convert EUC-JP files to UTF8
Thibaut Girka <thib@sitedethib.com>
parents: 52
diff changeset
599 // z 軸と xy 軸の相互干渉;高速化
4416cfac86ae Convert EUC-JP files to UTF8
Thibaut Girka <thib@sitedethib.com>
parents: 52
diff changeset
600 // 移動するウィジット描画の高速化
4416cfac86ae Convert EUC-JP files to UTF8
Thibaut Girka <thib@sitedethib.com>
parents: 52
diff changeset
601 // キャッシュ
4416cfac86ae Convert EUC-JP files to UTF8
Thibaut Girka <thib@sitedethib.com>
parents: 52
diff changeset
602 // 文字列の一部のみ更新の高速化
4416cfac86ae Convert EUC-JP files to UTF8
Thibaut Girka <thib@sitedethib.com>
parents: 52
diff changeset
603 // 「階層 z で x なる領域無効化、y なる領域生成」で良い?>Expose