| 1 | /* |
|---|
| 2 | * Copyright (c) 2004-2006 Kazunori "jagarl" Ueno |
|---|
| 3 | * All rights reserved. |
|---|
| 4 | * |
|---|
| 5 | * Redistribution and use in source and binary forms, with or without |
|---|
| 6 | * modification, are permitted provided that the following conditions |
|---|
| 7 | * are met: |
|---|
| 8 | * 1. Redistributions of source code must retain the above copyright |
|---|
| 9 | * notice, this list of conditions and the following disclaimer. |
|---|
| 10 | * 2. Redistributions in binary form must reproduce the above copyright |
|---|
| 11 | * notice, this list of conditions and the following disclaimer in the |
|---|
| 12 | * documentation and/or other materials provided with the distribution. |
|---|
| 13 | * 3. The name of the author may not be used to endorse or promote products |
|---|
| 14 | * derived from this software without specific prior written permission. |
|---|
| 15 | * |
|---|
| 16 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR |
|---|
| 17 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
|---|
| 18 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
|---|
| 19 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, |
|---|
| 20 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
|---|
| 21 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
|---|
| 22 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
|---|
| 23 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
|---|
| 24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
|---|
| 25 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
|---|
| 26 | */ |
|---|
| 27 | |
|---|
| 28 | #ifndef __EVENT__ |
|---|
| 29 | #define __EVENT__ |
|---|
| 30 | |
|---|
| 31 | #include "rect.h" |
|---|
| 32 | #include "SDL.h" |
|---|
| 33 | |
|---|
| 34 | namespace Event { |
|---|
| 35 | |
|---|
| 36 | class Video; |
|---|
| 37 | class Time; |
|---|
| 38 | class Container; |
|---|
| 39 | |
|---|
| 40 | /* |
|---|
| 41 | ** ããŠã¹ã® press, ãã©ãã°ãin/out ãæ€åºã§ãã |
|---|
| 42 | ** focus ãããæã® left/right/space(==press) ã®ããŒãå€å¥ã§ãã |
|---|
| 43 | */ |
|---|
| 44 | struct Video { |
|---|
| 45 | public: |
|---|
| 46 | virtual void Press(void) {} |
|---|
| 47 | virtual void Release(void) {} |
|---|
| 48 | virtual void Drag(int x_from, int y_from, int x_to, int y_to) {} |
|---|
| 49 | virtual void Motion(int x, int y) {} |
|---|
| 50 | virtual void In(void) {} |
|---|
| 51 | virtual void Out(void) {} |
|---|
| 52 | virtual void KeyLeft(void) {} |
|---|
| 53 | virtual void KeyRight(void) {} |
|---|
| 54 | |
|---|
| 55 | int point_in(int x, int y); /* z or -1 ãè¿ãã倧ããã»ã©é«ããšããã«ãã */ |
|---|
| 56 | |
|---|
| 57 | Video(Container& container); |
|---|
| 58 | Video(Container& container, const Rect& init_rect); |
|---|
| 59 | Video(Container& container, const Rect& init_rect, int z); |
|---|
| 60 | void SetRegion(const Rect& new_rect); |
|---|
| 61 | void SetZ(int new_z); |
|---|
| 62 | void activate(void); |
|---|
| 63 | void deactivate(void); |
|---|
| 64 | virtual ~Video(); |
|---|
| 65 | |
|---|
| 66 | Rect Region(void) const { return region;} |
|---|
| 67 | private: |
|---|
| 68 | Rect region; |
|---|
| 69 | int z; |
|---|
| 70 | Container& parent; |
|---|
| 71 | bool activated; |
|---|
| 72 | friend bool operator <(const Video& position1, const Video& position2); |
|---|
| 73 | }; |
|---|
| 74 | |
|---|
| 75 | struct Time { |
|---|
| 76 | public: |
|---|
| 77 | enum { NEVER_WAKE = 0xffffffffUL, FRAME_UPDATE = 0xfffffffeUL}; |
|---|
| 78 | virtual void Elapsed(unsigned int current_time) {wakeup_time = NEVER_WAKE; }; /* next: never elapsed */ |
|---|
| 79 | void SetWakeup(unsigned int new_wakeup_time) { wakeup_time = new_wakeup_time; } |
|---|
| 80 | unsigned Wakeup(void) const { return wakeup_time; } |
|---|
| 81 | |
|---|
| 82 | Time(Container& container); |
|---|
| 83 | ~Time(); |
|---|
| 84 | private: |
|---|
| 85 | unsigned int wakeup_time; |
|---|
| 86 | Container& parent; |
|---|
| 87 | }; |
|---|
| 88 | |
|---|
| 89 | struct Container { |
|---|
| 90 | #define MOUSE_LEFT 0 |
|---|
| 91 | #define MOUSE_MIDDLE 1 |
|---|
| 92 | #define MOUSE_RIGHT 2 |
|---|
| 93 | #define MOUSE_UP 3 |
|---|
| 94 | #define MOUSE_DOWN 4 |
|---|
| 95 | #define KEY_SHIFT 10 |
|---|
| 96 | #define BUTTON_MAX 32 |
|---|
| 97 | public: |
|---|
| 98 | int button_pressed; |
|---|
| 99 | int button_presscount[BUTTON_MAX]; |
|---|
| 100 | int current_time; |
|---|
| 101 | |
|---|
| 102 | void MousePos(int& x, int& y); |
|---|
| 103 | bool Exec(unsigned int current_time); |
|---|
| 104 | |
|---|
| 105 | void Add(Video* item); |
|---|
| 106 | void Delete(Video* item); |
|---|
| 107 | |
|---|
| 108 | void Add(Time* item); |
|---|
| 109 | void Delete(Time* item); |
|---|
| 110 | |
|---|
| 111 | typedef bool (*motionfunc)(int x, int y, void* pointer); |
|---|
| 112 | void RegisterGlobalMotionFunc(motionfunc, void* pointer); // ããŠã¹ã®ç§»åã®ãã³ã«åŒã³åºããã颿°ãç»é²ãã |
|---|
| 113 | void DeleteGlobalMotionFunc(motionfunc, void* pointer); |
|---|
| 114 | void RegisterGlobalPressFunc(motionfunc, void* pointer); // ããŠã¹ã®ã¯ãªãã¯ã®ãã³ã«åŒã³åºããã颿°ãç»é²ãã |
|---|
| 115 | void DeleteGlobalPressFunc(motionfunc, void* pointer); |
|---|
| 116 | |
|---|
| 117 | Container(void); |
|---|
| 118 | ~Container(void); |
|---|
| 119 | bool pressed(int mask); |
|---|
| 120 | bool presscount(int mask); |
|---|
| 121 | private: |
|---|
| 122 | class ContainerImplVideo* pimpl_video; |
|---|
| 123 | class ContainerImplTime* pimpl_time; |
|---|
| 124 | }; |
|---|
| 125 | |
|---|
| 126 | } /* end of namespace Event */ |
|---|
| 127 | |
|---|
| 128 | |
|---|
| 129 | #endif |
|---|