annotate window/event.h @ 46:3aa3d244ad90

Brand new README!
author thib
date Thu, 26 Mar 2009 18:06:32 +0000
parents 5ae5533b3a9a
children 15a18fbe6f21
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
31
5ae5533b3a9a * Added some license headers
thib
parents: 0
diff changeset
1 /*
5ae5533b3a9a * Added some license headers
thib
parents: 0
diff changeset
2 * Copyright (c) 2004-2006 Kazunori "jagarl" Ueno
5ae5533b3a9a * Added some license headers
thib
parents: 0
diff changeset
3 * All rights reserved.
5ae5533b3a9a * Added some license headers
thib
parents: 0
diff changeset
4 *
5ae5533b3a9a * Added some license headers
thib
parents: 0
diff changeset
5 * Redistribution and use in source and binary forms, with or without
5ae5533b3a9a * Added some license headers
thib
parents: 0
diff changeset
6 * modification, are permitted provided that the following conditions
5ae5533b3a9a * Added some license headers
thib
parents: 0
diff changeset
7 * are met:
5ae5533b3a9a * Added some license headers
thib
parents: 0
diff changeset
8 * 1. Redistributions of source code must retain the above copyright
5ae5533b3a9a * Added some license headers
thib
parents: 0
diff changeset
9 * notice, this list of conditions and the following disclaimer.
5ae5533b3a9a * Added some license headers
thib
parents: 0
diff changeset
10 * 2. Redistributions in binary form must reproduce the above copyright
5ae5533b3a9a * Added some license headers
thib
parents: 0
diff changeset
11 * notice, this list of conditions and the following disclaimer in the
5ae5533b3a9a * Added some license headers
thib
parents: 0
diff changeset
12 * documentation and/or other materials provided with the distribution.
5ae5533b3a9a * Added some license headers
thib
parents: 0
diff changeset
13 * 3. The name of the author may not be used to endorse or promote products
5ae5533b3a9a * Added some license headers
thib
parents: 0
diff changeset
14 * derived from this software without specific prior written permission.
5ae5533b3a9a * Added some license headers
thib
parents: 0
diff changeset
15 *
5ae5533b3a9a * Added some license headers
thib
parents: 0
diff changeset
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
5ae5533b3a9a * Added some license headers
thib
parents: 0
diff changeset
17 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
5ae5533b3a9a * Added some license headers
thib
parents: 0
diff changeset
18 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
5ae5533b3a9a * Added some license headers
thib
parents: 0
diff changeset
19 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
5ae5533b3a9a * Added some license headers
thib
parents: 0
diff changeset
20 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
5ae5533b3a9a * Added some license headers
thib
parents: 0
diff changeset
21 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
5ae5533b3a9a * Added some license headers
thib
parents: 0
diff changeset
22 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
5ae5533b3a9a * Added some license headers
thib
parents: 0
diff changeset
23 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
5ae5533b3a9a * Added some license headers
thib
parents: 0
diff changeset
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
5ae5533b3a9a * Added some license headers
thib
parents: 0
diff changeset
25 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
5ae5533b3a9a * Added some license headers
thib
parents: 0
diff changeset
26 */
5ae5533b3a9a * Added some license headers
thib
parents: 0
diff changeset
27
0
223b71206888 Initial import
thib
parents:
diff changeset
28 #ifndef __EVENT__
223b71206888 Initial import
thib
parents:
diff changeset
29 #define __EVENT__
223b71206888 Initial import
thib
parents:
diff changeset
30
223b71206888 Initial import
thib
parents:
diff changeset
31 #include"rect.h"
223b71206888 Initial import
thib
parents:
diff changeset
32 #include"SDL.h"
223b71206888 Initial import
thib
parents:
diff changeset
33
223b71206888 Initial import
thib
parents:
diff changeset
34 namespace Event {
223b71206888 Initial import
thib
parents:
diff changeset
35
223b71206888 Initial import
thib
parents:
diff changeset
36 class Video;
223b71206888 Initial import
thib
parents:
diff changeset
37 class Time;
223b71206888 Initial import
thib
parents:
diff changeset
38 class Container;
223b71206888 Initial import
thib
parents:
diff changeset
39
223b71206888 Initial import
thib
parents:
diff changeset
40 /*
223b71206888 Initial import
thib
parents:
diff changeset
41 ** マウスの press, ドラッグ、in/out を検出できる
223b71206888 Initial import
thib
parents:
diff changeset
42 ** focus がある時の left/right/space(==press) のキーを判別できる
223b71206888 Initial import
thib
parents:
diff changeset
43 */
223b71206888 Initial import
thib
parents:
diff changeset
44 struct Video {
223b71206888 Initial import
thib
parents:
diff changeset
45 virtual void Press(void) {}
223b71206888 Initial import
thib
parents:
diff changeset
46 virtual void Release(void) {}
223b71206888 Initial import
thib
parents:
diff changeset
47 virtual void Drag(int x_from, int y_from, int x_to, int y_to) {}
223b71206888 Initial import
thib
parents:
diff changeset
48 virtual void Motion(int x, int y) {}
223b71206888 Initial import
thib
parents:
diff changeset
49 virtual void In(void) {}
223b71206888 Initial import
thib
parents:
diff changeset
50 virtual void Out(void) {}
223b71206888 Initial import
thib
parents:
diff changeset
51 virtual void KeyLeft(void) {}
223b71206888 Initial import
thib
parents:
diff changeset
52 virtual void KeyRight(void) {}
223b71206888 Initial import
thib
parents:
diff changeset
53
223b71206888 Initial import
thib
parents:
diff changeset
54 int point_in(int x, int y); /* z or -1 を返す。大きいほど高いところにある */
223b71206888 Initial import
thib
parents:
diff changeset
55
223b71206888 Initial import
thib
parents:
diff changeset
56 Video(Container& container);
223b71206888 Initial import
thib
parents:
diff changeset
57 Video(Container& container, const Rect& init_rect);
223b71206888 Initial import
thib
parents:
diff changeset
58 Video(Container& container, const Rect& init_rect, int z);
223b71206888 Initial import
thib
parents:
diff changeset
59 void SetRegion(const Rect& new_rect);
223b71206888 Initial import
thib
parents:
diff changeset
60 void SetZ(int new_z);
223b71206888 Initial import
thib
parents:
diff changeset
61 void activate(void);
223b71206888 Initial import
thib
parents:
diff changeset
62 void deactivate(void);
223b71206888 Initial import
thib
parents:
diff changeset
63 virtual ~Video();
223b71206888 Initial import
thib
parents:
diff changeset
64
223b71206888 Initial import
thib
parents:
diff changeset
65 Rect Region(void) const { return region;}
223b71206888 Initial import
thib
parents:
diff changeset
66 private:
223b71206888 Initial import
thib
parents:
diff changeset
67 Rect region;
223b71206888 Initial import
thib
parents:
diff changeset
68 int z;
223b71206888 Initial import
thib
parents:
diff changeset
69 Container& parent;
223b71206888 Initial import
thib
parents:
diff changeset
70 bool activated;
223b71206888 Initial import
thib
parents:
diff changeset
71 friend bool operator <(const Video& position1, const Video& position2);
223b71206888 Initial import
thib
parents:
diff changeset
72 };
223b71206888 Initial import
thib
parents:
diff changeset
73
223b71206888 Initial import
thib
parents:
diff changeset
74 struct Time {
223b71206888 Initial import
thib
parents:
diff changeset
75 enum { NEVER_WAKE = 0xffffffff, FRAME_UPDATE = 0xfffffffe};
223b71206888 Initial import
thib
parents:
diff changeset
76 virtual void Elapsed(unsigned int current_time) {wakeup_time = NEVER_WAKE; }; /* next: never elapsed */
223b71206888 Initial import
thib
parents:
diff changeset
77 void SetWakeup(unsigned int new_wakeup_time) { wakeup_time = new_wakeup_time; }
223b71206888 Initial import
thib
parents:
diff changeset
78 unsigned Wakeup(void) const { return wakeup_time; }
223b71206888 Initial import
thib
parents:
diff changeset
79
223b71206888 Initial import
thib
parents:
diff changeset
80 Time(Container& container);
223b71206888 Initial import
thib
parents:
diff changeset
81 ~Time();
223b71206888 Initial import
thib
parents:
diff changeset
82 private:
223b71206888 Initial import
thib
parents:
diff changeset
83 unsigned int wakeup_time;
223b71206888 Initial import
thib
parents:
diff changeset
84 Container& parent;
223b71206888 Initial import
thib
parents:
diff changeset
85 };
223b71206888 Initial import
thib
parents:
diff changeset
86
223b71206888 Initial import
thib
parents:
diff changeset
87 struct Container {
223b71206888 Initial import
thib
parents:
diff changeset
88 #define MOUSE_LEFT 0
223b71206888 Initial import
thib
parents:
diff changeset
89 #define MOUSE_MIDDLE 1
223b71206888 Initial import
thib
parents:
diff changeset
90 #define MOUSE_RIGHT 2
223b71206888 Initial import
thib
parents:
diff changeset
91 #define MOUSE_UP 3
223b71206888 Initial import
thib
parents:
diff changeset
92 #define MOUSE_DOWN 4
223b71206888 Initial import
thib
parents:
diff changeset
93 #define KEY_SHIFT 10
223b71206888 Initial import
thib
parents:
diff changeset
94 #define BUTTON_MAX 32
223b71206888 Initial import
thib
parents:
diff changeset
95 int button_pressed;
223b71206888 Initial import
thib
parents:
diff changeset
96 int button_presscount[BUTTON_MAX];
223b71206888 Initial import
thib
parents:
diff changeset
97 int current_time;
223b71206888 Initial import
thib
parents:
diff changeset
98
223b71206888 Initial import
thib
parents:
diff changeset
99 void MousePos(int& x, int& y);
223b71206888 Initial import
thib
parents:
diff changeset
100 bool Exec(unsigned int current_time);
223b71206888 Initial import
thib
parents:
diff changeset
101
223b71206888 Initial import
thib
parents:
diff changeset
102 void Add(Video* item);
223b71206888 Initial import
thib
parents:
diff changeset
103 void Delete(Video* item);
223b71206888 Initial import
thib
parents:
diff changeset
104
223b71206888 Initial import
thib
parents:
diff changeset
105 void Add(Time* item);
223b71206888 Initial import
thib
parents:
diff changeset
106 void Delete(Time* item);
223b71206888 Initial import
thib
parents:
diff changeset
107
223b71206888 Initial import
thib
parents:
diff changeset
108 typedef bool (*motionfunc)(int x, int y, void* pointer);
223b71206888 Initial import
thib
parents:
diff changeset
109 void RegisterGlobalMotionFunc(motionfunc, void* pointer); // マウスの移動のたびに呼び出される関数を登録する
223b71206888 Initial import
thib
parents:
diff changeset
110 void DeleteGlobalMotionFunc(motionfunc, void* pointer);
223b71206888 Initial import
thib
parents:
diff changeset
111 void RegisterGlobalPressFunc(motionfunc, void* pointer); // マウスのクリックのたびに呼び出される関数を登録する
223b71206888 Initial import
thib
parents:
diff changeset
112 void DeleteGlobalPressFunc(motionfunc, void* pointer);
223b71206888 Initial import
thib
parents:
diff changeset
113
223b71206888 Initial import
thib
parents:
diff changeset
114 Container(void);
223b71206888 Initial import
thib
parents:
diff changeset
115 ~Container(void);
223b71206888 Initial import
thib
parents:
diff changeset
116 bool pressed(int mask);
223b71206888 Initial import
thib
parents:
diff changeset
117 bool presscount(int mask);
223b71206888 Initial import
thib
parents:
diff changeset
118 private:
223b71206888 Initial import
thib
parents:
diff changeset
119 class ContainerImplVideo* pimpl_video;
223b71206888 Initial import
thib
parents:
diff changeset
120 class ContainerImplTime* pimpl_time;
223b71206888 Initial import
thib
parents:
diff changeset
121 };
223b71206888 Initial import
thib
parents:
diff changeset
122
223b71206888 Initial import
thib
parents:
diff changeset
123 }; /* end of namespace Event */
223b71206888 Initial import
thib
parents:
diff changeset
124
223b71206888 Initial import
thib
parents:
diff changeset
125
223b71206888 Initial import
thib
parents:
diff changeset
126 #endif