milligram
リビジョン | 23811455b2b715fe64e9f8981c4550f0171c9bbf (tree) |
---|---|
日時 | 2011-03-25 17:04:20 |
作者 | beru <berupon@gmai...> |
コミッター | beru |
basic event system implemented
@@ -1,1038 +0,0 @@ | ||
1 | -#ifndef UTIL_CALLBACK_HPP | |
2 | -#define UTIL_CALLBACK_HPP | |
3 | - | |
4 | -#define UTIL_GET_CALLBACK_FACTORY_BIND_FREE(freeFuncPtr) \ | |
5 | - (util::GetCallbackFactory(freeFuncPtr).Bind<freeFuncPtr>()) | |
6 | -#define BIND_FREE_CB UTIL_GET_CALLBACK_FACTORY_BIND_FREE | |
7 | - | |
8 | -#define UTIL_GET_CALLBACK_FACTORY_BIND_MEMBER(memFuncPtr, instancePtr) \ | |
9 | - (util::GetCallbackFactory(memFuncPtr).Bind<memFuncPtr>(instancePtr)) | |
10 | -#define BIND_MEM_CB UTIL_GET_CALLBACK_FACTORY_BIND_MEMBER | |
11 | - | |
12 | -namespace util { | |
13 | - | |
14 | -template<typename FuncSignature> | |
15 | -class Callback; | |
16 | - | |
17 | -struct NullCallback {}; | |
18 | - | |
19 | -// 0 parameter version | |
20 | - | |
21 | -template<typename R> | |
22 | -class Callback<R ()> | |
23 | -{ | |
24 | -public: | |
25 | - static const int Arity = 0; | |
26 | - typedef R ReturnType; | |
27 | - | |
28 | - Callback() : func(0), obj(0) {} | |
29 | - Callback(NullCallback) : func(0), obj(0) {} | |
30 | - Callback(const Callback& rhs) : func(rhs.func), obj(rhs.obj) {} | |
31 | - ~Callback() {} | |
32 | - | |
33 | - Callback& operator=(NullCallback) | |
34 | - { obj = 0; func = 0; return *this; } | |
35 | - Callback& operator=(const Callback& rhs) | |
36 | - { obj = rhs.obj; func = rhs.func; return *this; } | |
37 | - | |
38 | - inline R operator()() const | |
39 | - { | |
40 | - return (*func)(obj); | |
41 | - } | |
42 | - | |
43 | -private: | |
44 | - typedef const void* Callback::*SafeBoolType; | |
45 | -public: | |
46 | - inline operator SafeBoolType() const | |
47 | - { return func != 0 ? &Callback::obj : 0; } | |
48 | - inline bool operator!() const | |
49 | - { return func == 0; } | |
50 | - | |
51 | -private: | |
52 | - typedef R (*FuncType)(const void*); | |
53 | - Callback(FuncType f, const void* o) : func(f), obj(o) {} | |
54 | - | |
55 | -private: | |
56 | - FuncType func; | |
57 | - const void* obj; | |
58 | - | |
59 | - template<typename FR> | |
60 | - friend class FreeCallbackFactory0; | |
61 | - template<typename FR, class FT> | |
62 | - friend class MemberCallbackFactory0; | |
63 | - template<typename FR, class FT> | |
64 | - friend class ConstMemberCallbackFactory0; | |
65 | -}; | |
66 | - | |
67 | -template<typename R> | |
68 | -void operator==(const Callback<R ()>&, | |
69 | - const Callback<R ()>&); | |
70 | -template<typename R> | |
71 | -void operator!=(const Callback<R ()>&, | |
72 | - const Callback<R ()>&); | |
73 | - | |
74 | -template<typename R> | |
75 | -class FreeCallbackFactory0 | |
76 | -{ | |
77 | -private: | |
78 | - template<R (*Func)()> | |
79 | - static R Wrapper(const void*) | |
80 | - { | |
81 | - return (*Func)(); | |
82 | - } | |
83 | - | |
84 | -public: | |
85 | - template<R (*Func)()> | |
86 | - inline static Callback<R ()> Bind() | |
87 | - { | |
88 | - return Callback<R ()> | |
89 | - (&FreeCallbackFactory0::Wrapper<Func>, 0); | |
90 | - } | |
91 | -}; | |
92 | - | |
93 | -template<typename R> | |
94 | -inline FreeCallbackFactory0<R> | |
95 | -GetCallbackFactory(R (*)()) | |
96 | -{ | |
97 | - return FreeCallbackFactory0<R>(); | |
98 | -} | |
99 | - | |
100 | -template<typename R, class T> | |
101 | -class MemberCallbackFactory0 | |
102 | -{ | |
103 | -private: | |
104 | - template<R (T::*Func)()> | |
105 | - static R Wrapper(const void* o) | |
106 | - { | |
107 | - T* obj = const_cast<T*>(static_cast<const T*>(o)); | |
108 | - return (obj->*Func)(); | |
109 | - } | |
110 | - | |
111 | -public: | |
112 | - template<R (T::*Func)()> | |
113 | - inline static Callback<R ()> Bind(T* o) | |
114 | - { | |
115 | - return Callback<R ()> | |
116 | - (&MemberCallbackFactory0::Wrapper<Func>, | |
117 | - static_cast<const void*>(o)); | |
118 | - } | |
119 | -}; | |
120 | - | |
121 | -template<typename R, class T> | |
122 | -inline MemberCallbackFactory0<R, T> | |
123 | -GetCallbackFactory(R (T::*)()) | |
124 | -{ | |
125 | - return MemberCallbackFactory0<R, T>(); | |
126 | -} | |
127 | - | |
128 | -template<typename R, class T> | |
129 | -class ConstMemberCallbackFactory0 | |
130 | -{ | |
131 | -private: | |
132 | - template<R (T::*Func)() const> | |
133 | - static R Wrapper(const void* o) | |
134 | - { | |
135 | - const T* obj = static_cast<const T*>(o); | |
136 | - return (obj->*Func)(); | |
137 | - } | |
138 | - | |
139 | -public: | |
140 | - template<R (T::*Func)() const> | |
141 | - inline static Callback<R ()> Bind(const T* o) | |
142 | - { | |
143 | - return Callback<R ()> | |
144 | - (&ConstMemberCallbackFactory0::Wrapper<Func>, | |
145 | - static_cast<const void*>(o)); | |
146 | - } | |
147 | -}; | |
148 | - | |
149 | -template<typename R, class T> | |
150 | -inline ConstMemberCallbackFactory0<R, T> | |
151 | -GetCallbackFactory(R (T::*)() const) | |
152 | -{ | |
153 | - return ConstMemberCallbackFactory0<R, T>(); | |
154 | -} | |
155 | - | |
156 | -// 1 parameter version | |
157 | - | |
158 | -template<typename R, typename P1> | |
159 | -class Callback<R (P1)> | |
160 | -{ | |
161 | -public: | |
162 | - static const int Arity = 1; | |
163 | - typedef R ReturnType; | |
164 | - typedef P1 Param1Type; | |
165 | - | |
166 | - Callback() : func(0), obj(0) {} | |
167 | - Callback(NullCallback) : func(0), obj(0) {} | |
168 | - Callback(const Callback& rhs) : func(rhs.func), obj(rhs.obj) {} | |
169 | - ~Callback() {} | |
170 | - | |
171 | - Callback& operator=(NullCallback) | |
172 | - { obj = 0; func = 0; return *this; } | |
173 | - Callback& operator=(const Callback& rhs) | |
174 | - { obj = rhs.obj; func = rhs.func; return *this; } | |
175 | - | |
176 | - inline R operator()(P1 a1) const | |
177 | - { | |
178 | - return (*func)(obj, a1); | |
179 | - } | |
180 | - | |
181 | -private: | |
182 | - typedef const void* Callback::*SafeBoolType; | |
183 | -public: | |
184 | - inline operator SafeBoolType() const | |
185 | - { return func != 0 ? &Callback::obj : 0; } | |
186 | - inline bool operator!() const | |
187 | - { return func == 0; } | |
188 | - | |
189 | -private: | |
190 | - typedef R (*FuncType)(const void*, P1); | |
191 | - Callback(FuncType f, const void* o) : func(f), obj(o) {} | |
192 | - | |
193 | -private: | |
194 | - FuncType func; | |
195 | - const void* obj; | |
196 | - | |
197 | - template<typename FR, typename FP1> | |
198 | - friend class FreeCallbackFactory1; | |
199 | - template<typename FR, class FT, typename FP1> | |
200 | - friend class MemberCallbackFactory1; | |
201 | - template<typename FR, class FT, typename FP1> | |
202 | - friend class ConstMemberCallbackFactory1; | |
203 | -}; | |
204 | - | |
205 | -template<typename R, typename P1> | |
206 | -void operator==(const Callback<R (P1)>&, | |
207 | - const Callback<R (P1)>&); | |
208 | -template<typename R, typename P1> | |
209 | -void operator!=(const Callback<R (P1)>&, | |
210 | - const Callback<R (P1)>&); | |
211 | - | |
212 | -template<typename R, typename P1> | |
213 | -class FreeCallbackFactory1 | |
214 | -{ | |
215 | -private: | |
216 | - template<R (*Func)(P1)> | |
217 | - static R Wrapper(const void*, P1 a1) | |
218 | - { | |
219 | - return (*Func)(a1); | |
220 | - } | |
221 | - | |
222 | -public: | |
223 | - template<R (*Func)(P1)> | |
224 | - inline static Callback<R (P1)> Bind() | |
225 | - { | |
226 | - return Callback<R (P1)> | |
227 | - (&FreeCallbackFactory1::Wrapper<Func>, 0); | |
228 | - } | |
229 | -}; | |
230 | - | |
231 | -template<typename R, typename P1> | |
232 | -inline FreeCallbackFactory1<R, P1> | |
233 | -GetCallbackFactory(R (*)(P1)) | |
234 | -{ | |
235 | - return FreeCallbackFactory1<R, P1>(); | |
236 | -} | |
237 | - | |
238 | -template<typename R, class T, typename P1> | |
239 | -class MemberCallbackFactory1 | |
240 | -{ | |
241 | -private: | |
242 | - template<R (T::*Func)(P1)> | |
243 | - static R Wrapper(const void* o, P1 a1) | |
244 | - { | |
245 | - T* obj = const_cast<T*>(static_cast<const T*>(o)); | |
246 | - return (obj->*Func)(a1); | |
247 | - } | |
248 | - | |
249 | -public: | |
250 | - template<R (T::*Func)(P1)> | |
251 | - inline static Callback<R (P1)> Bind(T* o) | |
252 | - { | |
253 | - return Callback<R (P1)> | |
254 | - (&MemberCallbackFactory1::Wrapper<Func>, | |
255 | - static_cast<const void*>(o)); | |
256 | - } | |
257 | -}; | |
258 | - | |
259 | -template<typename R, class T, typename P1> | |
260 | -inline MemberCallbackFactory1<R, T, P1> | |
261 | -GetCallbackFactory(R (T::*)(P1)) | |
262 | -{ | |
263 | - return MemberCallbackFactory1<R, T, P1>(); | |
264 | -} | |
265 | - | |
266 | -template<typename R, class T, typename P1> | |
267 | -class ConstMemberCallbackFactory1 | |
268 | -{ | |
269 | -private: | |
270 | - template<R (T::*Func)(P1) const> | |
271 | - static R Wrapper(const void* o, P1 a1) | |
272 | - { | |
273 | - const T* obj = static_cast<const T*>(o); | |
274 | - return (obj->*Func)(a1); | |
275 | - } | |
276 | - | |
277 | -public: | |
278 | - template<R (T::*Func)(P1) const> | |
279 | - inline static Callback<R (P1)> Bind(const T* o) | |
280 | - { | |
281 | - return Callback<R (P1)> | |
282 | - (&ConstMemberCallbackFactory1::Wrapper<Func>, | |
283 | - static_cast<const void*>(o)); | |
284 | - } | |
285 | -}; | |
286 | - | |
287 | -template<typename R, class T, typename P1> | |
288 | -inline ConstMemberCallbackFactory1<R, T, P1> | |
289 | -GetCallbackFactory(R (T::*)(P1) const) | |
290 | -{ | |
291 | - return ConstMemberCallbackFactory1<R, T, P1>(); | |
292 | -} | |
293 | - | |
294 | -// 2 parameter version | |
295 | - | |
296 | -template<typename R, typename P1, typename P2> | |
297 | -class Callback<R (P1, P2)> | |
298 | -{ | |
299 | -public: | |
300 | - static const int Arity = 2; | |
301 | - typedef R ReturnType; | |
302 | - typedef P1 Param1Type; | |
303 | - typedef P2 Param2Type; | |
304 | - | |
305 | - Callback() : func(0), obj(0) {} | |
306 | - Callback(NullCallback) : func(0), obj(0) {} | |
307 | - Callback(const Callback& rhs) : func(rhs.func), obj(rhs.obj) {} | |
308 | - ~Callback() {} | |
309 | - | |
310 | - Callback& operator=(NullCallback) | |
311 | - { obj = 0; func = 0; return *this; } | |
312 | - Callback& operator=(const Callback& rhs) | |
313 | - { obj = rhs.obj; func = rhs.func; return *this; } | |
314 | - | |
315 | - inline R operator()(P1 a1, P2 a2) const | |
316 | - { | |
317 | - return (*func)(obj, a1, a2); | |
318 | - } | |
319 | - | |
320 | -private: | |
321 | - typedef const void* Callback::*SafeBoolType; | |
322 | -public: | |
323 | - inline operator SafeBoolType() const | |
324 | - { return func != 0 ? &Callback::obj : 0; } | |
325 | - inline bool operator!() const | |
326 | - { return func == 0; } | |
327 | - | |
328 | -private: | |
329 | - typedef R (*FuncType)(const void*, P1, P2); | |
330 | - Callback(FuncType f, const void* o) : func(f), obj(o) {} | |
331 | - | |
332 | -private: | |
333 | - FuncType func; | |
334 | - const void* obj; | |
335 | - | |
336 | - template<typename FR, typename FP1, typename FP2> | |
337 | - friend class FreeCallbackFactory2; | |
338 | - template<typename FR, class FT, typename FP1, typename FP2> | |
339 | - friend class MemberCallbackFactory2; | |
340 | - template<typename FR, class FT, typename FP1, typename FP2> | |
341 | - friend class ConstMemberCallbackFactory2; | |
342 | -}; | |
343 | - | |
344 | -template<typename R, typename P1, typename P2> | |
345 | -void operator==(const Callback<R (P1, P2)>&, | |
346 | - const Callback<R (P1, P2)>&); | |
347 | -template<typename R, typename P1, typename P2> | |
348 | -void operator!=(const Callback<R (P1, P2)>&, | |
349 | - const Callback<R (P1, P2)>&); | |
350 | - | |
351 | -template<typename R, typename P1, typename P2> | |
352 | -class FreeCallbackFactory2 | |
353 | -{ | |
354 | -private: | |
355 | - template<R (*Func)(P1, P2)> | |
356 | - static R Wrapper(const void*, P1 a1, P2 a2) | |
357 | - { | |
358 | - return (*Func)(a1, a2); | |
359 | - } | |
360 | - | |
361 | -public: | |
362 | - template<R (*Func)(P1, P2)> | |
363 | - inline static Callback<R (P1, P2)> Bind() | |
364 | - { | |
365 | - return Callback<R (P1, P2)> | |
366 | - (&FreeCallbackFactory2::Wrapper<Func>, 0); | |
367 | - } | |
368 | -}; | |
369 | - | |
370 | -template<typename R, typename P1, typename P2> | |
371 | -inline FreeCallbackFactory2<R, P1, P2> | |
372 | -GetCallbackFactory(R (*)(P1, P2)) | |
373 | -{ | |
374 | - return FreeCallbackFactory2<R, P1, P2>(); | |
375 | -} | |
376 | - | |
377 | -template<typename R, class T, typename P1, typename P2> | |
378 | -class MemberCallbackFactory2 | |
379 | -{ | |
380 | -private: | |
381 | - template<R (T::*Func)(P1, P2)> | |
382 | - static R Wrapper(const void* o, P1 a1, P2 a2) | |
383 | - { | |
384 | - T* obj = const_cast<T*>(static_cast<const T*>(o)); | |
385 | - return (obj->*Func)(a1, a2); | |
386 | - } | |
387 | - | |
388 | -public: | |
389 | - template<R (T::*Func)(P1, P2)> | |
390 | - inline static Callback<R (P1, P2)> Bind(T* o) | |
391 | - { | |
392 | - return Callback<R (P1, P2)> | |
393 | - (&MemberCallbackFactory2::Wrapper<Func>, | |
394 | - static_cast<const void*>(o)); | |
395 | - } | |
396 | -}; | |
397 | - | |
398 | -template<typename R, class T, typename P1, typename P2> | |
399 | -inline MemberCallbackFactory2<R, T, P1, P2> | |
400 | -GetCallbackFactory(R (T::*)(P1, P2)) | |
401 | -{ | |
402 | - return MemberCallbackFactory2<R, T, P1, P2>(); | |
403 | -} | |
404 | - | |
405 | -template<typename R, class T, typename P1, typename P2> | |
406 | -class ConstMemberCallbackFactory2 | |
407 | -{ | |
408 | -private: | |
409 | - template<R (T::*Func)(P1, P2) const> | |
410 | - static R Wrapper(const void* o, P1 a1, P2 a2) | |
411 | - { | |
412 | - const T* obj = static_cast<const T*>(o); | |
413 | - return (obj->*Func)(a1, a2); | |
414 | - } | |
415 | - | |
416 | -public: | |
417 | - template<R (T::*Func)(P1, P2) const> | |
418 | - inline static Callback<R (P1, P2)> Bind(const T* o) | |
419 | - { | |
420 | - return Callback<R (P1, P2)> | |
421 | - (&ConstMemberCallbackFactory2::Wrapper<Func>, | |
422 | - static_cast<const void*>(o)); | |
423 | - } | |
424 | -}; | |
425 | - | |
426 | -template<typename R, class T, typename P1, typename P2> | |
427 | -inline ConstMemberCallbackFactory2<R, T, P1, P2> | |
428 | -GetCallbackFactory(R (T::*)(P1, P2) const) | |
429 | -{ | |
430 | - return ConstMemberCallbackFactory2<R, T, P1, P2>(); | |
431 | -} | |
432 | - | |
433 | -// 3 parameter version | |
434 | - | |
435 | -template<typename R, typename P1, typename P2, typename P3> | |
436 | -class Callback<R (P1, P2, P3)> | |
437 | -{ | |
438 | -public: | |
439 | - static const int Arity = 3; | |
440 | - typedef R ReturnType; | |
441 | - typedef P1 Param1Type; | |
442 | - typedef P2 Param2Type; | |
443 | - typedef P3 Param3Type; | |
444 | - | |
445 | - Callback() : func(0), obj(0) {} | |
446 | - Callback(NullCallback) : func(0), obj(0) {} | |
447 | - Callback(const Callback& rhs) : func(rhs.func), obj(rhs.obj) {} | |
448 | - ~Callback() {} | |
449 | - | |
450 | - Callback& operator=(NullCallback) | |
451 | - { obj = 0; func = 0; return *this; } | |
452 | - Callback& operator=(const Callback& rhs) | |
453 | - { obj = rhs.obj; func = rhs.func; return *this; } | |
454 | - | |
455 | - inline R operator()(P1 a1, P2 a2, P3 a3) const | |
456 | - { | |
457 | - return (*func)(obj, a1, a2, a3); | |
458 | - } | |
459 | - | |
460 | -private: | |
461 | - typedef const void* Callback::*SafeBoolType; | |
462 | -public: | |
463 | - inline operator SafeBoolType() const | |
464 | - { return func != 0 ? &Callback::obj : 0; } | |
465 | - inline bool operator!() const | |
466 | - { return func == 0; } | |
467 | - | |
468 | -private: | |
469 | - typedef R (*FuncType)(const void*, P1, P2, P3); | |
470 | - Callback(FuncType f, const void* o) : func(f), obj(o) {} | |
471 | - | |
472 | -private: | |
473 | - FuncType func; | |
474 | - const void* obj; | |
475 | - | |
476 | - template<typename FR, typename FP1, typename FP2, typename FP3> | |
477 | - friend class FreeCallbackFactory3; | |
478 | - template<typename FR, class FT, typename FP1, typename FP2, typename FP3> | |
479 | - friend class MemberCallbackFactory3; | |
480 | - template<typename FR, class FT, typename FP1, typename FP2, typename FP3> | |
481 | - friend class ConstMemberCallbackFactory3; | |
482 | -}; | |
483 | - | |
484 | -template<typename R, typename P1, typename P2, typename P3> | |
485 | -void operator==(const Callback<R (P1, P2, P3)>&, | |
486 | - const Callback<R (P1, P2, P3)>&); | |
487 | -template<typename R, typename P1, typename P2, typename P3> | |
488 | -void operator!=(const Callback<R (P1, P2, P3)>&, | |
489 | - const Callback<R (P1, P2, P3)>&); | |
490 | - | |
491 | -template<typename R, typename P1, typename P2, typename P3> | |
492 | -class FreeCallbackFactory3 | |
493 | -{ | |
494 | -private: | |
495 | - template<R (*Func)(P1, P2, P3)> | |
496 | - static R Wrapper(const void*, P1 a1, P2 a2, P3 a3) | |
497 | - { | |
498 | - return (*Func)(a1, a2, a3); | |
499 | - } | |
500 | - | |
501 | -public: | |
502 | - template<R (*Func)(P1, P2, P3)> | |
503 | - inline static Callback<R (P1, P2, P3)> Bind() | |
504 | - { | |
505 | - return Callback<R (P1, P2, P3)> | |
506 | - (&FreeCallbackFactory3::Wrapper<Func>, 0); | |
507 | - } | |
508 | -}; | |
509 | - | |
510 | -template<typename R, typename P1, typename P2, typename P3> | |
511 | -inline FreeCallbackFactory3<R, P1, P2, P3> | |
512 | -GetCallbackFactory(R (*)(P1, P2, P3)) | |
513 | -{ | |
514 | - return FreeCallbackFactory3<R, P1, P2, P3>(); | |
515 | -} | |
516 | - | |
517 | -template<typename R, class T, typename P1, typename P2, typename P3> | |
518 | -class MemberCallbackFactory3 | |
519 | -{ | |
520 | -private: | |
521 | - template<R (T::*Func)(P1, P2, P3)> | |
522 | - static R Wrapper(const void* o, P1 a1, P2 a2, P3 a3) | |
523 | - { | |
524 | - T* obj = const_cast<T*>(static_cast<const T*>(o)); | |
525 | - return (obj->*Func)(a1, a2, a3); | |
526 | - } | |
527 | - | |
528 | -public: | |
529 | - template<R (T::*Func)(P1, P2, P3)> | |
530 | - inline static Callback<R (P1, P2, P3)> Bind(T* o) | |
531 | - { | |
532 | - return Callback<R (P1, P2, P3)> | |
533 | - (&MemberCallbackFactory3::Wrapper<Func>, | |
534 | - static_cast<const void*>(o)); | |
535 | - } | |
536 | -}; | |
537 | - | |
538 | -template<typename R, class T, typename P1, typename P2, typename P3> | |
539 | -inline MemberCallbackFactory3<R, T, P1, P2, P3> | |
540 | -GetCallbackFactory(R (T::*)(P1, P2, P3)) | |
541 | -{ | |
542 | - return MemberCallbackFactory3<R, T, P1, P2, P3>(); | |
543 | -} | |
544 | - | |
545 | -template<typename R, class T, typename P1, typename P2, typename P3> | |
546 | -class ConstMemberCallbackFactory3 | |
547 | -{ | |
548 | -private: | |
549 | - template<R (T::*Func)(P1, P2, P3) const> | |
550 | - static R Wrapper(const void* o, P1 a1, P2 a2, P3 a3) | |
551 | - { | |
552 | - const T* obj = static_cast<const T*>(o); | |
553 | - return (obj->*Func)(a1, a2, a3); | |
554 | - } | |
555 | - | |
556 | -public: | |
557 | - template<R (T::*Func)(P1, P2, P3) const> | |
558 | - inline static Callback<R (P1, P2, P3)> Bind(const T* o) | |
559 | - { | |
560 | - return Callback<R (P1, P2, P3)> | |
561 | - (&ConstMemberCallbackFactory3::Wrapper<Func>, | |
562 | - static_cast<const void*>(o)); | |
563 | - } | |
564 | -}; | |
565 | - | |
566 | -template<typename R, class T, typename P1, typename P2, typename P3> | |
567 | -inline ConstMemberCallbackFactory3<R, T, P1, P2, P3> | |
568 | -GetCallbackFactory(R (T::*)(P1, P2, P3) const) | |
569 | -{ | |
570 | - return ConstMemberCallbackFactory3<R, T, P1, P2, P3>(); | |
571 | -} | |
572 | - | |
573 | -// 4 parameter version | |
574 | - | |
575 | -template<typename R, typename P1, typename P2, typename P3, | |
576 | - typename P4> | |
577 | -class Callback<R (P1, P2, P3, P4)> | |
578 | -{ | |
579 | -public: | |
580 | - static const int Arity = 4; | |
581 | - typedef R ReturnType; | |
582 | - typedef P1 Param1Type; | |
583 | - typedef P2 Param2Type; | |
584 | - typedef P3 Param3Type; | |
585 | - typedef P4 Param4Type; | |
586 | - | |
587 | - Callback() : func(0), obj(0) {} | |
588 | - Callback(NullCallback) : func(0), obj(0) {} | |
589 | - Callback(const Callback& rhs) : func(rhs.func), obj(rhs.obj) {} | |
590 | - ~Callback() {} | |
591 | - | |
592 | - Callback& operator=(NullCallback) | |
593 | - { obj = 0; func = 0; return *this; } | |
594 | - Callback& operator=(const Callback& rhs) | |
595 | - { obj = rhs.obj; func = rhs.func; return *this; } | |
596 | - | |
597 | - inline R operator()(P1 a1, P2 a2, P3 a3, P4 a4) const | |
598 | - { | |
599 | - return (*func)(obj, a1, a2, a3, a4); | |
600 | - } | |
601 | - | |
602 | -private: | |
603 | - typedef const void* Callback::*SafeBoolType; | |
604 | -public: | |
605 | - inline operator SafeBoolType() const | |
606 | - { return func != 0 ? &Callback::obj : 0; } | |
607 | - inline bool operator!() const | |
608 | - { return func == 0; } | |
609 | - | |
610 | -private: | |
611 | - typedef R (*FuncType)(const void*, P1, P2, P3, P4); | |
612 | - Callback(FuncType f, const void* o) : func(f), obj(o) {} | |
613 | - | |
614 | -private: | |
615 | - FuncType func; | |
616 | - const void* obj; | |
617 | - | |
618 | - template<typename FR, typename FP1, typename FP2, typename FP3, | |
619 | - typename FP4> | |
620 | - friend class FreeCallbackFactory4; | |
621 | - template<typename FR, class FT, typename FP1, typename FP2, typename FP3, | |
622 | - typename FP4> | |
623 | - friend class MemberCallbackFactory4; | |
624 | - template<typename FR, class FT, typename FP1, typename FP2, typename FP3, | |
625 | - typename FP4> | |
626 | - friend class ConstMemberCallbackFactory4; | |
627 | -}; | |
628 | - | |
629 | -template<typename R, typename P1, typename P2, typename P3, | |
630 | - typename P4> | |
631 | -void operator==(const Callback<R (P1, P2, P3, P4)>&, | |
632 | - const Callback<R (P1, P2, P3, P4)>&); | |
633 | -template<typename R, typename P1, typename P2, typename P3, | |
634 | - typename P4> | |
635 | -void operator!=(const Callback<R (P1, P2, P3, P4)>&, | |
636 | - const Callback<R (P1, P2, P3, P4)>&); | |
637 | - | |
638 | -template<typename R, typename P1, typename P2, typename P3, | |
639 | - typename P4> | |
640 | -class FreeCallbackFactory4 | |
641 | -{ | |
642 | -private: | |
643 | - template<R (*Func)(P1, P2, P3, P4)> | |
644 | - static R Wrapper(const void*, P1 a1, P2 a2, P3 a3, P4 a4) | |
645 | - { | |
646 | - return (*Func)(a1, a2, a3, a4); | |
647 | - } | |
648 | - | |
649 | -public: | |
650 | - template<R (*Func)(P1, P2, P3, P4)> | |
651 | - inline static Callback<R (P1, P2, P3, P4)> Bind() | |
652 | - { | |
653 | - return Callback<R (P1, P2, P3, P4)> | |
654 | - (&FreeCallbackFactory4::Wrapper<Func>, 0); | |
655 | - } | |
656 | -}; | |
657 | - | |
658 | -template<typename R, typename P1, typename P2, typename P3, | |
659 | - typename P4> | |
660 | -inline FreeCallbackFactory4<R, P1, P2, P3, P4> | |
661 | -GetCallbackFactory(R (*)(P1, P2, P3, P4)) | |
662 | -{ | |
663 | - return FreeCallbackFactory4<R, P1, P2, P3, P4>(); | |
664 | -} | |
665 | - | |
666 | -template<typename R, class T, typename P1, typename P2, typename P3, | |
667 | - typename P4> | |
668 | -class MemberCallbackFactory4 | |
669 | -{ | |
670 | -private: | |
671 | - template<R (T::*Func)(P1, P2, P3, P4)> | |
672 | - static R Wrapper(const void* o, P1 a1, P2 a2, P3 a3, P4 a4) | |
673 | - { | |
674 | - T* obj = const_cast<T*>(static_cast<const T*>(o)); | |
675 | - return (obj->*Func)(a1, a2, a3, a4); | |
676 | - } | |
677 | - | |
678 | -public: | |
679 | - template<R (T::*Func)(P1, P2, P3, P4)> | |
680 | - inline static Callback<R (P1, P2, P3, P4)> Bind(T* o) | |
681 | - { | |
682 | - return Callback<R (P1, P2, P3, P4)> | |
683 | - (&MemberCallbackFactory4::Wrapper<Func>, | |
684 | - static_cast<const void*>(o)); | |
685 | - } | |
686 | -}; | |
687 | - | |
688 | -template<typename R, class T, typename P1, typename P2, typename P3, | |
689 | - typename P4> | |
690 | -inline MemberCallbackFactory4<R, T, P1, P2, P3, P4> | |
691 | -GetCallbackFactory(R (T::*)(P1, P2, P3, P4)) | |
692 | -{ | |
693 | - return MemberCallbackFactory4<R, T, P1, P2, P3, P4>(); | |
694 | -} | |
695 | - | |
696 | -template<typename R, class T, typename P1, typename P2, typename P3, | |
697 | - typename P4> | |
698 | -class ConstMemberCallbackFactory4 | |
699 | -{ | |
700 | -private: | |
701 | - template<R (T::*Func)(P1, P2, P3, P4) const> | |
702 | - static R Wrapper(const void* o, P1 a1, P2 a2, P3 a3, P4 a4) | |
703 | - { | |
704 | - const T* obj = static_cast<const T*>(o); | |
705 | - return (obj->*Func)(a1, a2, a3, a4); | |
706 | - } | |
707 | - | |
708 | -public: | |
709 | - template<R (T::*Func)(P1, P2, P3, P4) const> | |
710 | - inline static Callback<R (P1, P2, P3, P4)> Bind(const T* o) | |
711 | - { | |
712 | - return Callback<R (P1, P2, P3, P4)> | |
713 | - (&ConstMemberCallbackFactory4::Wrapper<Func>, | |
714 | - static_cast<const void*>(o)); | |
715 | - } | |
716 | -}; | |
717 | - | |
718 | -template<typename R, class T, typename P1, typename P2, typename P3, | |
719 | - typename P4> | |
720 | -inline ConstMemberCallbackFactory4<R, T, P1, P2, P3, P4> | |
721 | -GetCallbackFactory(R (T::*)(P1, P2, P3, P4) const) | |
722 | -{ | |
723 | - return ConstMemberCallbackFactory4<R, T, P1, P2, P3, P4>(); | |
724 | -} | |
725 | - | |
726 | -// 5 parameter version | |
727 | - | |
728 | -template<typename R, typename P1, typename P2, typename P3, | |
729 | - typename P4, typename P5> | |
730 | -class Callback<R (P1, P2, P3, P4, P5)> | |
731 | -{ | |
732 | -public: | |
733 | - static const int Arity = 5; | |
734 | - typedef R ReturnType; | |
735 | - typedef P1 Param1Type; | |
736 | - typedef P2 Param2Type; | |
737 | - typedef P3 Param3Type; | |
738 | - typedef P4 Param4Type; | |
739 | - typedef P5 Param5Type; | |
740 | - | |
741 | - Callback() : func(0), obj(0) {} | |
742 | - Callback(NullCallback) : func(0), obj(0) {} | |
743 | - Callback(const Callback& rhs) : func(rhs.func), obj(rhs.obj) {} | |
744 | - ~Callback() {} | |
745 | - | |
746 | - Callback& operator=(NullCallback) | |
747 | - { obj = 0; func = 0; return *this; } | |
748 | - Callback& operator=(const Callback& rhs) | |
749 | - { obj = rhs.obj; func = rhs.func; return *this; } | |
750 | - | |
751 | - inline R operator()(P1 a1, P2 a2, P3 a3, P4 a4, P5 a5) const | |
752 | - { | |
753 | - return (*func)(obj, a1, a2, a3, a4, a5); | |
754 | - } | |
755 | - | |
756 | -private: | |
757 | - typedef const void* Callback::*SafeBoolType; | |
758 | -public: | |
759 | - inline operator SafeBoolType() const | |
760 | - { return func != 0 ? &Callback::obj : 0; } | |
761 | - inline bool operator!() const | |
762 | - { return func == 0; } | |
763 | - | |
764 | -private: | |
765 | - typedef R (*FuncType)(const void*, P1, P2, P3, P4, P5); | |
766 | - Callback(FuncType f, const void* o) : func(f), obj(o) {} | |
767 | - | |
768 | -private: | |
769 | - FuncType func; | |
770 | - const void* obj; | |
771 | - | |
772 | - template<typename FR, typename FP1, typename FP2, typename FP3, | |
773 | - typename FP4, typename FP5> | |
774 | - friend class FreeCallbackFactory5; | |
775 | - template<typename FR, class FT, typename FP1, typename FP2, typename FP3, | |
776 | - typename FP4, typename FP5> | |
777 | - friend class MemberCallbackFactory5; | |
778 | - template<typename FR, class FT, typename FP1, typename FP2, typename FP3, | |
779 | - typename FP4, typename FP5> | |
780 | - friend class ConstMemberCallbackFactory5; | |
781 | -}; | |
782 | - | |
783 | -template<typename R, typename P1, typename P2, typename P3, | |
784 | - typename P4, typename P5> | |
785 | -void operator==(const Callback<R (P1, P2, P3, P4, P5)>&, | |
786 | - const Callback<R (P1, P2, P3, P4, P5)>&); | |
787 | -template<typename R, typename P1, typename P2, typename P3, | |
788 | - typename P4, typename P5> | |
789 | -void operator!=(const Callback<R (P1, P2, P3, P4, P5)>&, | |
790 | - const Callback<R (P1, P2, P3, P4, P5)>&); | |
791 | - | |
792 | -template<typename R, typename P1, typename P2, typename P3, | |
793 | - typename P4, typename P5> | |
794 | -class FreeCallbackFactory5 | |
795 | -{ | |
796 | -private: | |
797 | - template<R (*Func)(P1, P2, P3, P4, P5)> | |
798 | - static R Wrapper(const void*, P1 a1, P2 a2, P3 a3, P4 a4, P5 a5) | |
799 | - { | |
800 | - return (*Func)(a1, a2, a3, a4, a5); | |
801 | - } | |
802 | - | |
803 | -public: | |
804 | - template<R (*Func)(P1, P2, P3, P4, P5)> | |
805 | - inline static Callback<R (P1, P2, P3, P4, P5)> Bind() | |
806 | - { | |
807 | - return Callback<R (P1, P2, P3, P4, P5)> | |
808 | - (&FreeCallbackFactory5::Wrapper<Func>, 0); | |
809 | - } | |
810 | -}; | |
811 | - | |
812 | -template<typename R, typename P1, typename P2, typename P3, | |
813 | - typename P4, typename P5> | |
814 | -inline FreeCallbackFactory5<R, P1, P2, P3, P4, P5> | |
815 | -GetCallbackFactory(R (*)(P1, P2, P3, P4, P5)) | |
816 | -{ | |
817 | - return FreeCallbackFactory5<R, P1, P2, P3, P4, P5>(); | |
818 | -} | |
819 | - | |
820 | -template<typename R, class T, typename P1, typename P2, typename P3, | |
821 | - typename P4, typename P5> | |
822 | -class MemberCallbackFactory5 | |
823 | -{ | |
824 | -private: | |
825 | - template<R (T::*Func)(P1, P2, P3, P4, P5)> | |
826 | - static R Wrapper(const void* o, P1 a1, P2 a2, P3 a3, P4 a4, P5 a5) | |
827 | - { | |
828 | - T* obj = const_cast<T*>(static_cast<const T*>(o)); | |
829 | - return (obj->*Func)(a1, a2, a3, a4, a5); | |
830 | - } | |
831 | - | |
832 | -public: | |
833 | - template<R (T::*Func)(P1, P2, P3, P4, P5)> | |
834 | - inline static Callback<R (P1, P2, P3, P4, P5)> Bind(T* o) | |
835 | - { | |
836 | - return Callback<R (P1, P2, P3, P4, P5)> | |
837 | - (&MemberCallbackFactory5::Wrapper<Func>, | |
838 | - static_cast<const void*>(o)); | |
839 | - } | |
840 | -}; | |
841 | - | |
842 | -template<typename R, class T, typename P1, typename P2, typename P3, | |
843 | - typename P4, typename P5> | |
844 | -inline MemberCallbackFactory5<R, T, P1, P2, P3, P4, P5> | |
845 | -GetCallbackFactory(R (T::*)(P1, P2, P3, P4, P5)) | |
846 | -{ | |
847 | - return MemberCallbackFactory5<R, T, P1, P2, P3, P4, P5>(); | |
848 | -} | |
849 | - | |
850 | -template<typename R, class T, typename P1, typename P2, typename P3, | |
851 | - typename P4, typename P5> | |
852 | -class ConstMemberCallbackFactory5 | |
853 | -{ | |
854 | -private: | |
855 | - template<R (T::*Func)(P1, P2, P3, P4, P5) const> | |
856 | - static R Wrapper(const void* o, P1 a1, P2 a2, P3 a3, P4 a4, P5 a5) | |
857 | - { | |
858 | - const T* obj = static_cast<const T*>(o); | |
859 | - return (obj->*Func)(a1, a2, a3, a4, a5); | |
860 | - } | |
861 | - | |
862 | -public: | |
863 | - template<R (T::*Func)(P1, P2, P3, P4, P5) const> | |
864 | - inline static Callback<R (P1, P2, P3, P4, P5)> Bind(const T* o) | |
865 | - { | |
866 | - return Callback<R (P1, P2, P3, P4, P5)> | |
867 | - (&ConstMemberCallbackFactory5::Wrapper<Func>, | |
868 | - static_cast<const void*>(o)); | |
869 | - } | |
870 | -}; | |
871 | - | |
872 | -template<typename R, class T, typename P1, typename P2, typename P3, | |
873 | - typename P4, typename P5> | |
874 | -inline ConstMemberCallbackFactory5<R, T, P1, P2, P3, P4, P5> | |
875 | -GetCallbackFactory(R (T::*)(P1, P2, P3, P4, P5) const) | |
876 | -{ | |
877 | - return ConstMemberCallbackFactory5<R, T, P1, P2, P3, P4, P5>(); | |
878 | -} | |
879 | - | |
880 | -// 6 parameter version | |
881 | - | |
882 | -template<typename R, typename P1, typename P2, typename P3, | |
883 | - typename P4, typename P5, typename P6> | |
884 | -class Callback<R (P1, P2, P3, P4, P5, P6)> | |
885 | -{ | |
886 | -public: | |
887 | - static const int Arity = 6; | |
888 | - typedef R ReturnType; | |
889 | - typedef P1 Param1Type; | |
890 | - typedef P2 Param2Type; | |
891 | - typedef P3 Param3Type; | |
892 | - typedef P4 Param4Type; | |
893 | - typedef P5 Param5Type; | |
894 | - typedef P6 Param6Type; | |
895 | - | |
896 | - Callback() : func(0), obj(0) {} | |
897 | - Callback(NullCallback) : func(0), obj(0) {} | |
898 | - Callback(const Callback& rhs) : func(rhs.func), obj(rhs.obj) {} | |
899 | - ~Callback() {} | |
900 | - | |
901 | - Callback& operator=(NullCallback) | |
902 | - { obj = 0; func = 0; return *this; } | |
903 | - Callback& operator=(const Callback& rhs) | |
904 | - { obj = rhs.obj; func = rhs.func; return *this; } | |
905 | - | |
906 | - inline R operator()(P1 a1, P2 a2, P3 a3, P4 a4, P5 a5, P6 a6) const | |
907 | - { | |
908 | - return (*func)(obj, a1, a2, a3, a4, a5, a6); | |
909 | - } | |
910 | - | |
911 | -private: | |
912 | - typedef const void* Callback::*SafeBoolType; | |
913 | -public: | |
914 | - inline operator SafeBoolType() const | |
915 | - { return func != 0 ? &Callback::obj : 0; } | |
916 | - inline bool operator!() const | |
917 | - { return func == 0; } | |
918 | - | |
919 | -private: | |
920 | - typedef R (*FuncType)(const void*, P1, P2, P3, P4, P5, P6); | |
921 | - Callback(FuncType f, const void* o) : func(f), obj(o) {} | |
922 | - | |
923 | -private: | |
924 | - FuncType func; | |
925 | - const void* obj; | |
926 | - | |
927 | - template<typename FR, typename FP1, typename FP2, typename FP3, | |
928 | - typename FP4, typename FP5, typename FP6> | |
929 | - friend class FreeCallbackFactory6; | |
930 | - template<typename FR, class FT, typename FP1, typename FP2, typename FP3, | |
931 | - typename FP4, typename FP5, typename FP6> | |
932 | - friend class MemberCallbackFactory6; | |
933 | - template<typename FR, class FT, typename FP1, typename FP2, typename FP3, | |
934 | - typename FP4, typename FP5, typename FP6> | |
935 | - friend class ConstMemberCallbackFactory6; | |
936 | -}; | |
937 | - | |
938 | -template<typename R, typename P1, typename P2, typename P3, | |
939 | - typename P4, typename P5, typename P6> | |
940 | -void operator==(const Callback<R (P1, P2, P3, P4, P5, P6)>&, | |
941 | - const Callback<R (P1, P2, P3, P4, P5, P6)>&); | |
942 | -template<typename R, typename P1, typename P2, typename P3, | |
943 | - typename P4, typename P5, typename P6> | |
944 | -void operator!=(const Callback<R (P1, P2, P3, P4, P5, P6)>&, | |
945 | - const Callback<R (P1, P2, P3, P4, P5, P6)>&); | |
946 | - | |
947 | -template<typename R, typename P1, typename P2, typename P3, | |
948 | - typename P4, typename P5, typename P6> | |
949 | -class FreeCallbackFactory6 | |
950 | -{ | |
951 | -private: | |
952 | - template<R (*Func)(P1, P2, P3, P4, P5, P6)> | |
953 | - static R Wrapper(const void*, P1 a1, P2 a2, P3 a3, P4 a4, P5 a5, P6 a6) | |
954 | - { | |
955 | - return (*Func)(a1, a2, a3, a4, a5, a6); | |
956 | - } | |
957 | - | |
958 | -public: | |
959 | - template<R (*Func)(P1, P2, P3, P4, P5, P6)> | |
960 | - inline static Callback<R (P1, P2, P3, P4, P5, P6)> Bind() | |
961 | - { | |
962 | - return Callback<R (P1, P2, P3, P4, P5, P6)> | |
963 | - (&FreeCallbackFactory6::Wrapper<Func>, 0); | |
964 | - } | |
965 | -}; | |
966 | - | |
967 | -template<typename R, typename P1, typename P2, typename P3, | |
968 | - typename P4, typename P5, typename P6> | |
969 | -inline FreeCallbackFactory6<R, P1, P2, P3, P4, P5, P6> | |
970 | -GetCallbackFactory(R (*)(P1, P2, P3, P4, P5, P6)) | |
971 | -{ | |
972 | - return FreeCallbackFactory6<R, P1, P2, P3, P4, P5, P6>(); | |
973 | -} | |
974 | - | |
975 | -template<typename R, class T, typename P1, typename P2, typename P3, | |
976 | - typename P4, typename P5, typename P6> | |
977 | -class MemberCallbackFactory6 | |
978 | -{ | |
979 | -private: | |
980 | - template<R (T::*Func)(P1, P2, P3, P4, P5, P6)> | |
981 | - static R Wrapper(const void* o, P1 a1, P2 a2, P3 a3, P4 a4, P5 a5, P6 a6) | |
982 | - { | |
983 | - T* obj = const_cast<T*>(static_cast<const T*>(o)); | |
984 | - return (obj->*Func)(a1, a2, a3, a4, a5, a6); | |
985 | - } | |
986 | - | |
987 | -public: | |
988 | - template<R (T::*Func)(P1, P2, P3, P4, P5, P6)> | |
989 | - inline static Callback<R (P1, P2, P3, P4, P5, P6)> Bind(T* o) | |
990 | - { | |
991 | - return Callback<R (P1, P2, P3, P4, P5, P6)> | |
992 | - (&MemberCallbackFactory6::Wrapper<Func>, | |
993 | - static_cast<const void*>(o)); | |
994 | - } | |
995 | -}; | |
996 | - | |
997 | -template<typename R, class T, typename P1, typename P2, typename P3, | |
998 | - typename P4, typename P5, typename P6> | |
999 | -inline MemberCallbackFactory6<R, T, P1, P2, P3, P4, P5, P6> | |
1000 | -GetCallbackFactory(R (T::*)(P1, P2, P3, P4, P5, P6)) | |
1001 | -{ | |
1002 | - return MemberCallbackFactory6<R, T, P1, P2, P3, P4, P5, P6>(); | |
1003 | -} | |
1004 | - | |
1005 | -template<typename R, class T, typename P1, typename P2, typename P3, | |
1006 | - typename P4, typename P5, typename P6> | |
1007 | -class ConstMemberCallbackFactory6 | |
1008 | -{ | |
1009 | -private: | |
1010 | - template<R (T::*Func)(P1, P2, P3, P4, P5, P6) const> | |
1011 | - static R Wrapper(const void* o, P1 a1, P2 a2, P3 a3, P4 a4, P5 a5, P6 a6) | |
1012 | - { | |
1013 | - const T* obj = static_cast<const T*>(o); | |
1014 | - return (obj->*Func)(a1, a2, a3, a4, a5, a6); | |
1015 | - } | |
1016 | - | |
1017 | -public: | |
1018 | - template<R (T::*Func)(P1, P2, P3, P4, P5, P6) const> | |
1019 | - inline static Callback<R (P1, P2, P3, P4, P5, P6)> Bind(const T* o) | |
1020 | - { | |
1021 | - return Callback<R (P1, P2, P3, P4, P5, P6)> | |
1022 | - (&ConstMemberCallbackFactory6::Wrapper<Func>, | |
1023 | - static_cast<const void*>(o)); | |
1024 | - } | |
1025 | -}; | |
1026 | - | |
1027 | -template<typename R, class T, typename P1, typename P2, typename P3, | |
1028 | - typename P4, typename P5, typename P6> | |
1029 | -inline ConstMemberCallbackFactory6<R, T, P1, P2, P3, P4, P5, P6> | |
1030 | -GetCallbackFactory(R (T::*)(P1, P2, P3, P4, P5, P6) const) | |
1031 | -{ | |
1032 | - return ConstMemberCallbackFactory6<R, T, P1, P2, P3, P4, P5, P6>(); | |
1033 | -} | |
1034 | - | |
1035 | -} | |
1036 | - | |
1037 | -#endif | |
1038 | - |
@@ -196,21 +196,21 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) | ||
196 | 196 | case WM_LBUTTONDOWN: |
197 | 197 | case WM_MBUTTONDOWN: |
198 | 198 | case WM_RBUTTONDOWN: |
199 | - ::SetCapture(hWnd); | |
199 | +// ::SetCapture(hWnd); | |
200 | 200 | OnMouseDown(hWnd, wParam, lParam); |
201 | 201 | break; |
202 | 202 | case WM_LBUTTONUP: |
203 | 203 | case WM_MBUTTONUP: |
204 | 204 | case WM_RBUTTONUP: |
205 | - if (::GetCapture() == hWnd) { | |
206 | - ::ReleaseCapture(); | |
205 | +// if (::GetCapture() == hWnd) { | |
206 | +// ::ReleaseCapture(); | |
207 | 207 | OnMouseUp(hWnd, wParam, lParam); |
208 | - } | |
208 | +// } | |
209 | 209 | break; |
210 | 210 | case WM_MOUSEMOVE: |
211 | - if (::GetCapture() == hWnd) { | |
211 | +// if (::GetCapture() == hWnd) { | |
212 | 212 | OnMouseMove(hWnd, wParam, lParam); |
213 | - } | |
213 | +// } | |
214 | 214 | break; |
215 | 215 | default: |
216 | 216 | return DefWindowProc(hWnd, message, wParam, lParam); |
@@ -52,7 +52,7 @@ HDC hMemDC; | ||
52 | 52 | MG::Renderer24 renderer; |
53 | 53 | |
54 | 54 | MG::Container mg(4, 8); |
55 | -MG::Button button1(0); | |
55 | +MG::Button button1(4); | |
56 | 56 | MG::Button button2(0); |
57 | 57 | MG::Element pic1(0); |
58 | 58 | MG::Element pic2(0); |
@@ -94,6 +94,26 @@ bool ReadImage(const char* filename, MG::Bitmap& bmp, std::vector<uint8_t>& buff | ||
94 | 94 | |
95 | 95 | } // anonymous namespace |
96 | 96 | |
97 | +void OnButton1MouseDown(void* param, const MG::Element::Event& e) | |
98 | +{ | |
99 | + OutputDebugString(L"MouseDown\n"); | |
100 | +} | |
101 | + | |
102 | +void OnButton1MouseUp(void* param, const MG::Element::Event& e) | |
103 | +{ | |
104 | + OutputDebugString(L"MouseUp\n"); | |
105 | +} | |
106 | + | |
107 | +void OnButton1MouseMove(void* param, const MG::Element::Event& e) | |
108 | +{ | |
109 | + OutputDebugString(L"MouseMove\n"); | |
110 | +} | |
111 | + | |
112 | +void OnButton1Click(void* param, const MG::Element::Event& e) | |
113 | +{ | |
114 | + OutputDebugString(L"Click\n"); | |
115 | +} | |
116 | + | |
97 | 117 | void OnCreate(HWND hWnd, WPARAM wParam, LPARAM lParam) |
98 | 118 | { |
99 | 119 | BITMAPINFO* pBMI = (BITMAPINFO*) &bmiBuff[0]; |
@@ -127,15 +147,15 @@ void OnCreate(HWND hWnd, WPARAM wParam, LPARAM lParam) | ||
127 | 147 | rect.y = 0; |
128 | 148 | rect.w = width; |
129 | 149 | rect.h = height; |
130 | - mg.rect = rect; | |
150 | + mg.rect_ = rect; | |
131 | 151 | MG::Color col; |
132 | 152 | col.r = 50; |
133 | 153 | col.g = 200; |
134 | 154 | col.b = 150; |
135 | 155 | |
136 | 156 | mainbg.color = col; |
137 | - mg.pBG = &mainbg; | |
138 | - mg.needsToDraw = true; | |
157 | + mg.pBG_ = &mainbg; | |
158 | + mg.needsToDraw_ = true; | |
139 | 159 | |
140 | 160 | col.g = 100; |
141 | 161 | buttonBG.color = col; |
@@ -146,18 +166,18 @@ void OnCreate(HWND hWnd, WPARAM wParam, LPARAM lParam) | ||
146 | 166 | rect.y = 100; |
147 | 167 | rect.w = 100; |
148 | 168 | rect.h = 50; |
149 | - button1.rect = rect; | |
150 | - button1.pBG = &buttonBG; | |
151 | - button1.pBGPressed = &buttonBGPressed; | |
169 | + button1.rect_ = rect; | |
170 | + button1.pBG_ = &buttonBG; | |
171 | + button1.pBGPressed_ = &buttonBGPressed; | |
152 | 172 | mg.AddChild(button1); |
153 | 173 | |
154 | 174 | rect.x = 300; |
155 | 175 | rect.y = 100; |
156 | 176 | rect.w = 100; |
157 | 177 | rect.h = 50; |
158 | - button2.rect = rect; | |
159 | - button2.pBG = &buttonBG; | |
160 | - button2.pBGPressed = &buttonBGPressed; | |
178 | + button2.rect_ = rect; | |
179 | + button2.pBG_ = &buttonBG; | |
180 | + button2.pBGPressed_ = &buttonBGPressed; | |
161 | 181 | mg.AddChild(button2); |
162 | 182 | |
163 | 183 | if (!ReadImage("test24.bmp", bmp24Content, image24Buffer)) { |
@@ -169,7 +189,7 @@ void OnCreate(HWND hWnd, WPARAM wParam, LPARAM lParam) | ||
169 | 189 | |
170 | 190 | rect.x = 100; |
171 | 191 | rect.y = 300; |
172 | - pic1.rect = rect; | |
192 | + pic1.rect_ = rect; | |
173 | 193 | MG::Rectangle irec; |
174 | 194 | irec.x = 510; |
175 | 195 | irec.y = 340; |
@@ -177,23 +197,23 @@ void OnCreate(HWND hWnd, WPARAM wParam, LPARAM lParam) | ||
177 | 197 | irec.h = 400; |
178 | 198 | picbg1.image.rect = irec; |
179 | 199 | picbg1.image.pBitmap = &bmp24Content; |
180 | - pic1.pBG = &picbg1; | |
181 | - pic1.needsToDraw = true; | |
200 | + pic1.pBG_ = &picbg1; | |
201 | + pic1.needsToDraw_ = true; | |
182 | 202 | mg.AddChild(pic1); |
183 | 203 | |
184 | 204 | rect.x = 300; |
185 | 205 | rect.y = 200; |
186 | 206 | rect.w = 336; |
187 | 207 | rect.h = 300; |
188 | - pic2.rect = rect; | |
208 | + pic2.rect_ = rect; | |
189 | 209 | irec.x = 0; |
190 | 210 | irec.y = 0; |
191 | 211 | irec.w = 336; |
192 | 212 | irec.h = 24; |
193 | 213 | picbg2.image.rect = irec; |
194 | 214 | picbg2.image.pBitmap = &bmp32Content; |
195 | - pic2.pBG = &picbg2; | |
196 | - pic2.needsToDraw = true; | |
215 | + pic2.pBG_ = &picbg2; | |
216 | + pic2.needsToDraw_ = true; | |
197 | 217 | mg.AddChild(pic2); |
198 | 218 | |
199 | 219 | HDC hWndDC = ::GetDC(hWnd); |
@@ -202,6 +222,12 @@ void OnCreate(HWND hWnd, WPARAM wParam, LPARAM lParam) | ||
202 | 222 | ::ReleaseDC(hWnd, hWndDC); |
203 | 223 | ::SelectObject(hMemDC, hBMP); |
204 | 224 | |
225 | + button1.AddEventListener(MG::Element::EventType_MouseDown, OnButton1MouseDown); | |
226 | + button1.AddEventListener(MG::Element::EventType_MouseUp, OnButton1MouseUp); | |
227 | +// button1.AddEventListener(MG::Element::EventType_MouseMove, OnButton1MouseMove); | |
228 | + button1.AddEventListener(MG::Button::EventType_Click, OnButton1Click); | |
229 | + | |
230 | + | |
205 | 231 | mg.Draw(0, 0, renderer); |
206 | 232 | } |
207 | 233 |
@@ -113,8 +113,9 @@ | ||
113 | 113 | /> |
114 | 114 | <Tool |
115 | 115 | Name="VCCLCompilerTool" |
116 | - Optimization="2" | |
116 | + Optimization="1" | |
117 | 117 | EnableIntrinsicFunctions="true" |
118 | + FavorSizeOrSpeed="2" | |
118 | 119 | AdditionalIncludeDirectories="./;./common/" |
119 | 120 | PreprocessorDefinitions="WIN32;NDEBUG;_WINDOWS;_CRT_SECURE_NO_WARNINGS" |
120 | 121 | RuntimeLibrary="2" |
@@ -313,10 +314,6 @@ | ||
313 | 314 | > |
314 | 315 | </File> |
315 | 316 | <File |
316 | - RelativePath=".\common\callback.hpp" | |
317 | - > | |
318 | - </File> | |
319 | - <File | |
320 | 317 | RelativePath=".\common\optional.h" |
321 | 318 | > |
322 | 319 | </File> |
@@ -7,19 +7,18 @@ namespace MG { | ||
7 | 7 | Button::Button(size_t nMaxEvents) |
8 | 8 | : |
9 | 9 | Element(nMaxEvents), |
10 | - pBGPressed(0) | |
10 | + pBGPressed_(0) | |
11 | 11 | { |
12 | - needsToDraw = true; | |
13 | - bClickable_ = true; | |
12 | + needsToDraw_ = true; | |
14 | 13 | } |
15 | 14 | |
16 | 15 | void Button::Draw(int16_t offsetX, int16_t offsetY, IRenderer& renderer) |
17 | 16 | { |
18 | 17 | if (isPressed_) { |
19 | - IBackground* backup = pBG; | |
20 | - pBG = pBGPressed; | |
18 | + IBackground* backup = pBG_; | |
19 | + pBG_ = pBGPressed_; | |
21 | 20 | __super::Draw(offsetX, offsetY, renderer); |
22 | - pBG = backup; | |
21 | + pBG_ = backup; | |
23 | 22 | }else { |
24 | 23 | __super::Draw(offsetX, offsetY, renderer); |
25 | 24 | } |
@@ -27,26 +26,38 @@ void Button::Draw(int16_t offsetX, int16_t offsetY, IRenderer& renderer) | ||
27 | 26 | |
28 | 27 | bool Button::HitTest(int16_t x, int16_t y) const |
29 | 28 | { |
30 | - return true; | |
29 | + return __super::HitTest(x, y); | |
31 | 30 | } |
32 | 31 | |
33 | 32 | void Button::OnMouseDown(int16_t x, int16_t y) |
34 | 33 | { |
35 | - needsToDraw = true; | |
34 | + needsToDraw_ = true; | |
36 | 35 | isPressed_ = true; |
36 | + s_pCapture_ = this; | |
37 | + __super::OnMouseDown(x, y); | |
37 | 38 | } |
38 | 39 | |
39 | 40 | void Button::OnMouseUp(int16_t x, int16_t y) |
40 | 41 | { |
42 | + __super::OnMouseUp(x, y); | |
41 | 43 | if (isPressed_) { |
42 | - needsToDraw = true; | |
44 | + needsToDraw_ = true; | |
43 | 45 | isPressed_ = false; |
46 | + s_pCapture_ = 0; | |
47 | + if (HitTest(x, y)) { | |
48 | + OnClick(x, y); | |
49 | + } | |
44 | 50 | } |
45 | 51 | } |
46 | 52 | |
47 | -void Button::OnMouseMove(int16_t x, int16_t y) | |
53 | +void Button::OnClick(int16_t x, int16_t y) | |
48 | 54 | { |
49 | - ; | |
55 | + Event e; | |
56 | + e.target = this; | |
57 | + e.type = EventType_Click; | |
58 | + e.x = x; | |
59 | + e.y = y; | |
60 | + fireEventListener(e); | |
50 | 61 | } |
51 | 62 | |
52 | 63 | } // anonymous MG |
@@ -16,12 +16,12 @@ public: | ||
16 | 16 | bool HitTest(int16_t x, int16_t y) const; |
17 | 17 | void OnMouseDown(int16_t x, int16_t y); |
18 | 18 | void OnMouseUp(int16_t x, int16_t y); |
19 | - void OnMouseMove(int16_t x, int16_t y); | |
19 | + void OnClick(int16_t x, int16_t y); | |
20 | 20 | |
21 | - IBackground* pBGPressed; | |
21 | + IBackground* pBGPressed_; | |
22 | 22 | |
23 | 23 | enum EventType { |
24 | - EventType_Clicked = __super::EventType_End, | |
24 | + EventType_Click = __super::EventType_End, | |
25 | 25 | |
26 | 26 | EventType_End, |
27 | 27 | }; |
@@ -13,11 +13,10 @@ namespace MG { | ||
13 | 13 | |
14 | 14 | Container::Container(size_t nMaxEvents, size_t nMaxChildren) |
15 | 15 | : |
16 | - Element(nMaxEvents), | |
17 | - clickedElementIndex_(0) | |
16 | + Element(nMaxEvents) | |
18 | 17 | { |
19 | - vElements_.buff_ = &s_elementPtrs[s_nElementEntries]; | |
20 | - vElements_.maxLength_ = nMaxChildren; | |
18 | + elements_.buff_ = &s_elementPtrs[s_nElementEntries]; | |
19 | + elements_.maxLength_ = nMaxChildren; | |
21 | 20 | s_nElementEntries += nMaxChildren; |
22 | 21 | assert(s_nElementEntries < countof(s_elementPtrs)); |
23 | 22 | } |
@@ -28,15 +27,15 @@ Container::~Container() | ||
28 | 27 | |
29 | 28 | void Container::AddChild(Element& e) |
30 | 29 | { |
31 | - vElements_.push_back(&e); | |
30 | + elements_.push_back(&e); | |
32 | 31 | e.SetParent(this); |
33 | 32 | } |
34 | 33 | |
35 | 34 | void Container::RemoveChild(Element& e) |
36 | 35 | { |
37 | - for (size_t i=0; i<vElements_.length_; ++i) { | |
38 | - if (vElements_[i] == &e) { | |
39 | - vElements_[i] = 0; | |
36 | + for (size_t i=0; i<elements_.length_; ++i) { | |
37 | + if (elements_[i] == &e) { | |
38 | + elements_[i] = 0; | |
40 | 39 | e.SetParent(0); |
41 | 40 | break; |
42 | 41 | } |
@@ -45,18 +44,18 @@ void Container::RemoveChild(Element& e) | ||
45 | 44 | |
46 | 45 | void Container::Draw(int16_t offsetX, int16_t offsetY, IRenderer& renderer) |
47 | 46 | { |
48 | - if (needsToDraw) { | |
47 | + if (needsToDraw_) { | |
49 | 48 | __super::Draw(offsetX, offsetY, renderer); |
50 | - needsToDraw = false; | |
49 | + needsToDraw_ = false; | |
51 | 50 | } |
52 | 51 | |
53 | - int16_t x = rect.x + offsetX; | |
54 | - int16_t y = rect.y + offsetY; | |
55 | - for (size_t i=0; i<vElements_.length_; ++i) { | |
56 | - Element* e = vElements_[i]; | |
57 | - if (e && e->needsToDraw) { | |
52 | + int16_t x = rect_.x + offsetX; | |
53 | + int16_t y = rect_.y + offsetY; | |
54 | + for (size_t i=0; i<elements_.length_; ++i) { | |
55 | + Element* e = elements_[i]; | |
56 | + if (e && e->needsToDraw_) { | |
58 | 57 | e->Draw(x, y, renderer); |
59 | - e->needsToDraw = false; | |
58 | + e->needsToDraw_ = false; | |
60 | 59 | } |
61 | 60 | } |
62 | 61 | } |
@@ -66,46 +65,66 @@ bool Container::HitTest(int16_t x, int16_t y) const | ||
66 | 65 | return true; |
67 | 66 | } |
68 | 67 | |
69 | -void Container::OnMouseDown(int16_t x, int16_t y) | |
68 | +static | |
69 | +Element* hitTestElements(varray<Element*>& elements, int16_t x, int16_t y) | |
70 | 70 | { |
71 | - int16_t ox = x - rect.x; | |
72 | - int16_t oy = y - rect.y; | |
73 | - for (size_t i=0; i<vElements_.length_; ++i) { | |
74 | - Element* e = vElements_[i]; | |
71 | + const size_t len = elements.length_; | |
72 | + for (size_t i=0; i<len; ++i) { | |
73 | + Element* e = elements[i]; | |
75 | 74 | if (e) { |
76 | - if (1 | |
77 | - && e->IsClickable() | |
78 | - && e->rect.Contains(ox, oy) | |
79 | - && e->HitTest(ox, oy) | |
80 | - ) { | |
81 | - clickedElementIndex_ = i; | |
82 | - e->OnMouseDown(ox, oy); | |
83 | - return; | |
75 | + if (e->HitTest(x, y)) { | |
76 | + return e; | |
84 | 77 | } |
85 | 78 | } |
86 | 79 | } |
80 | + return 0; | |
81 | +} | |
82 | + | |
83 | +void Container::OnMouseDown(int16_t x, int16_t y) | |
84 | +{ | |
85 | + int16_t ox = x - rect_.x; | |
86 | + int16_t oy = y - rect_.y; | |
87 | + | |
88 | + if (s_pCapture_) { | |
89 | + s_pCapture_->OnMouseDown(ox, oy); | |
90 | + }else { | |
91 | + Element* e = hitTestElements(elements_, x, y); | |
92 | + if (e) { | |
93 | + e->OnMouseDown(ox, oy); | |
94 | + return; | |
95 | + } | |
96 | + } | |
87 | 97 | } |
88 | 98 | |
89 | 99 | void Container::OnMouseUp(int16_t x, int16_t y) |
90 | 100 | { |
91 | - int16_t ox = x - rect.x; | |
92 | - int16_t oy = y - rect.y; | |
93 | - Element* e = vElements_[clickedElementIndex_]; | |
94 | - if (e) { | |
95 | - e->OnMouseUp(ox, oy); | |
101 | + int16_t ox = x - rect_.x; | |
102 | + int16_t oy = y - rect_.y; | |
103 | + if (s_pCapture_) { | |
104 | + s_pCapture_->OnMouseUp(ox, oy); | |
105 | + }else { | |
106 | + Element* e = hitTestElements(elements_, x, y); | |
107 | + if (e) { | |
108 | + e->OnMouseUp(ox, oy); | |
109 | + return; | |
110 | + } | |
96 | 111 | } |
97 | 112 | } |
98 | 113 | |
99 | 114 | void Container::OnMouseMove(int16_t x, int16_t y) |
100 | 115 | { |
101 | - int16_t ox = x - rect.x; | |
102 | - int16_t oy = y - rect.y; | |
103 | - Element* e = vElements_[clickedElementIndex_]; | |
104 | - if (e) { | |
105 | - e->OnMouseMove(ox, oy); | |
116 | + int16_t ox = x - rect_.x; | |
117 | + int16_t oy = y - rect_.y; | |
118 | + if (s_pCapture_) { | |
119 | + s_pCapture_->OnMouseMove(ox, oy); | |
120 | + }else { | |
121 | + Element* e = hitTestElements(elements_, x, y); | |
122 | + if (e) { | |
123 | + e->OnMouseMove(ox, oy); | |
124 | + return; | |
125 | + } | |
106 | 126 | } |
107 | 127 | } |
108 | 128 | |
109 | - | |
110 | 129 | } // namespace MG |
111 | 130 |
@@ -23,8 +23,7 @@ public: | ||
23 | 23 | virtual void OnMouseMove(int16_t x, int16_t y); |
24 | 24 | |
25 | 25 | protected: |
26 | - size_t clickedElementIndex_; | |
27 | - varray<Element*> vElements_; | |
26 | + varray<Element*> elements_; | |
28 | 27 | |
29 | 28 | }; |
30 | 29 |
@@ -12,6 +12,9 @@ MG::Element::EventListenerEntry s_eventEntries[128]; | ||
12 | 12 | |
13 | 13 | namespace MG { |
14 | 14 | |
15 | +// static | |
16 | +Element* Element::s_pCapture_ = 0; | |
17 | + | |
15 | 18 | Element::Element(size_t nMaxEvents) |
16 | 19 | { |
17 | 20 | eventEntries_.buff_ = &s_eventEntries[s_nEventEntries]; |
@@ -20,23 +23,90 @@ Element::Element(size_t nMaxEvents) | ||
20 | 23 | assert(s_nEventEntries < countof(s_eventEntries)); |
21 | 24 | |
22 | 25 | pParent_ = 0; |
23 | - needsToDraw = false; | |
24 | - pBG = 0; | |
25 | - bClickable_ = false; | |
26 | + needsToDraw_ = false; | |
27 | + pBG_ = 0; | |
28 | + pEventListenerParam_ = 0; | |
26 | 29 | } |
27 | 30 | |
28 | 31 | // virtual |
29 | 32 | void Element::Draw(int16_t offsetX, int16_t offsetY, IRenderer& renderer) |
30 | 33 | { |
31 | - Rectangle r = rect; | |
34 | + Rectangle r = rect_; | |
32 | 35 | r.x += offsetX; |
33 | 36 | r.y += offsetY; |
34 | 37 | |
35 | - if (pBG) { | |
36 | - pBG->Draw(r, renderer); | |
38 | + if (pBG_) { | |
39 | + pBG_->Draw(r, renderer); | |
37 | 40 | } |
38 | 41 | } |
39 | 42 | |
43 | +// virtual | |
44 | +bool Element::HitTest(int16_t x, int16_t y) const | |
45 | +{ | |
46 | + return rect_.Contains(x, y); | |
47 | +} | |
40 | 48 | |
41 | -} // namespace MG | |
49 | +void Element::AddEventListener(int type, const EventListener& listener) | |
50 | +{ | |
51 | + EventListenerEntry entry; | |
52 | + entry.type = type; | |
53 | + entry.listener = listener; | |
54 | + eventEntries_.push_back(entry); | |
55 | +} | |
56 | + | |
57 | +void Element::RemoveEventListener(int type, const EventListener& listener) | |
58 | +{ | |
59 | + for (size_t i=0; i<eventEntries_.length_; ++i) { | |
60 | + EventListenerEntry& entry = eventEntries_[i]; | |
61 | + if (entry.type == type && entry.listener == listener) { | |
62 | + entry.type = 0; | |
63 | + entry.listener = 0; | |
64 | + break; | |
65 | + } | |
66 | + } | |
67 | +} | |
68 | + | |
69 | +void Element::fireEventListener(const Event& e) | |
70 | +{ | |
71 | + for (size_t i=0; i<eventEntries_.length_; ++i) { | |
72 | + EventListenerEntry& entry = eventEntries_[i]; | |
73 | + if (entry.type == e.type) { | |
74 | + entry.listener(pEventListenerParam_, e); | |
75 | + } | |
76 | + } | |
77 | +} | |
78 | + | |
79 | +// virtual | |
80 | +void Element::OnMouseDown(int16_t x, int16_t y) | |
81 | +{ | |
82 | + Event e; | |
83 | + e.target = this; | |
84 | + e.type = EventType_MouseDown; | |
85 | + e.x = x; | |
86 | + e.y = y; | |
87 | + fireEventListener(e); | |
88 | +} | |
89 | + | |
90 | +// virtual | |
91 | +void Element::OnMouseUp(int16_t x, int16_t y) | |
92 | +{ | |
93 | + Event e; | |
94 | + e.target = this; | |
95 | + e.type = EventType_MouseUp; | |
96 | + e.x = x; | |
97 | + e.y = y; | |
98 | + fireEventListener(e); | |
99 | +} | |
42 | 100 | |
101 | +// virtual | |
102 | +void Element::OnMouseMove(int16_t x, int16_t y) | |
103 | +{ | |
104 | + Event e; | |
105 | + e.target = this; | |
106 | + e.type = EventType_MouseMove; | |
107 | + e.x = x; | |
108 | + e.y = y; | |
109 | + fireEventListener(e); | |
110 | +} | |
111 | + | |
112 | +} // namespace MG |
@@ -2,7 +2,6 @@ | ||
2 | 2 | |
3 | 3 | #include "renderer.h" |
4 | 4 | #include "optional.h" |
5 | -#include "callback.hpp" | |
6 | 5 | #include "varray.h" |
7 | 6 | |
8 | 7 | namespace MG { |
@@ -15,23 +14,20 @@ public: | ||
15 | 14 | Element(size_t nMaxEvents); |
16 | 15 | virtual ~Element() {} |
17 | 16 | |
18 | - bool IsClickable() const { | |
19 | - return bClickable_; | |
20 | - } | |
21 | - | |
22 | 17 | virtual void Draw(int16_t offsetX, int16_t offsetY, IRenderer& renderer); |
23 | - virtual bool HitTest(int16_t x, int16_t y) const { return false; } | |
24 | - virtual void OnMouseDown(int16_t x, int16_t y) {} | |
25 | - virtual void OnMouseUp(int16_t x, int16_t y) {} | |
26 | - virtual void OnMouseMove(int16_t x, int16_t y) {} | |
18 | + virtual bool HitTest(int16_t x, int16_t y) const; | |
19 | + | |
20 | + virtual void OnMouseDown(int16_t x, int16_t y); | |
21 | + virtual void OnMouseUp(int16_t x, int16_t y); | |
22 | + virtual void OnMouseMove(int16_t x, int16_t y); | |
27 | 23 | |
28 | - Rectangle rect; // positioning, size | |
29 | - bool needsToDraw; | |
24 | + Rectangle rect_; // positioning, size | |
25 | + bool needsToDraw_; | |
30 | 26 | |
31 | 27 | struct IBackground { |
32 | 28 | virtual void Draw(const Rectangle& rect, IRenderer& renderer) = 0; |
33 | 29 | }; |
34 | - IBackground* pBG; | |
30 | + IBackground* pBG_; | |
35 | 31 | |
36 | 32 | Element* GetParent() const { return pParent_; } |
37 | 33 | void SetParent(Element* pParent) { pParent_ = pParent; } |
@@ -51,19 +47,20 @@ public: | ||
51 | 47 | int16_t x; |
52 | 48 | int16_t y; |
53 | 49 | }; |
54 | - typedef util::Callback<void (const Event&)> EventListener; | |
50 | + typedef void (*EventListener)(void* param, const Event& e); | |
55 | 51 | struct EventListenerEntry { |
56 | 52 | int type; |
57 | 53 | EventListener listener; |
58 | 54 | }; |
55 | + void* pEventListenerParam_; | |
59 | 56 | void AddEventListener(int type, const EventListener& listener); |
60 | 57 | void RemoveEventListener(int type, const EventListener& listener); |
61 | - | |
58 | + static Element* s_pCapture_; | |
62 | 59 | protected: |
63 | - bool bClickable_; | |
64 | 60 | Element* pParent_; |
65 | 61 | |
66 | 62 | varray<EventListenerEntry> eventEntries_; |
63 | + void fireEventListener(const Event& e); | |
67 | 64 | }; |
68 | 65 | |
69 | 66 | } // namespace MG |
@@ -18,7 +18,7 @@ Rectangle Rectangle::Offset(const Rectangle& r, int16_t x, int16_t y) | ||
18 | 18 | return ret; |
19 | 19 | } |
20 | 20 | |
21 | -bool Rectangle::Contains(int16_t x, int16_t y) | |
21 | +bool Rectangle::Contains(int16_t x, int16_t y) const | |
22 | 22 | { |
23 | 23 | return |
24 | 24 | 1 |
@@ -29,7 +29,7 @@ bool Rectangle::Contains(int16_t x, int16_t y) | ||
29 | 29 | ; |
30 | 30 | } |
31 | 31 | |
32 | -bool Rectangle::Contains(const Rectangle& r) | |
32 | +bool Rectangle::Contains(const Rectangle& r) const | |
33 | 33 | { |
34 | 34 | return true; |
35 | 35 | } |
@@ -19,8 +19,8 @@ struct Rectangle | ||
19 | 19 | void Offset(int16_t x, int16_t y); |
20 | 20 | static Rectangle Offset(const Rectangle& r, int16_t x, int16_t y); |
21 | 21 | |
22 | - bool Contains(int16_t x, int16_t y); | |
23 | - bool Contains(const Rectangle& r); | |
22 | + bool Contains(int16_t x, int16_t y) const; | |
23 | + bool Contains(const Rectangle& r) const; | |
24 | 24 | |
25 | 25 | void Intersect(const Rectangle& r); |
26 | 26 | static Rectangle Intersect(const Rectangle& r1, const Rectangle& r2); |