| 1 |
//--------------------------------------------------------------------- |
|---|
| 2 |
/* |
|---|
| 3 |
Copyright: |
|---|
| 4 |
|
|---|
| 5 |
luigi/event.d -- event basics for the 'Luigi' user |
|---|
| 6 |
interface library. |
|---|
| 7 |
|
|---|
| 8 |
Copyright (C) 2006 William V. Baxter III |
|---|
| 9 |
|
|---|
| 10 |
This software is provided 'as-is', without any express or implied |
|---|
| 11 |
warranty. In no event will the authors be held liable for any |
|---|
| 12 |
damages arising from the use of this software. |
|---|
| 13 |
|
|---|
| 14 |
Permission is granted to anyone to use this software for any |
|---|
| 15 |
purpose, including commercial applications, and to alter it and |
|---|
| 16 |
redistribute it freely, subject to the following restrictions: |
|---|
| 17 |
|
|---|
| 18 |
1. The origin of this software must not be misrepresented; you must |
|---|
| 19 |
not claim that you wrote the original software. If you use this |
|---|
| 20 |
software in a product, an acknowledgment in the product |
|---|
| 21 |
documentation would be appreciated but is not required. |
|---|
| 22 |
2. Altered source versions must be plainly marked as such, and must |
|---|
| 23 |
not be misrepresented as being the original software. |
|---|
| 24 |
3. This notice may not be removed or altered from any source distribution. |
|---|
| 25 |
|
|---|
| 26 |
William Baxter wbaxter@gmail.com |
|---|
| 27 |
*/ |
|---|
| 28 |
|
|---|
| 29 |
module luigi.event; |
|---|
| 30 |
|
|---|
| 31 |
//import sslot.signal; |
|---|
| 32 |
import luigi.signalobj; |
|---|
| 33 |
import luigi.base; |
|---|
| 34 |
|
|---|
| 35 |
|
|---|
| 36 |
/** WindowHandle is just an opaque piece of data used to identify |
|---|
| 37 |
windows on the underlying windowing system. It could be an int for |
|---|
| 38 |
GLUT, or an HWND for Win32, etc. |
|---|
| 39 |
*/ |
|---|
| 40 |
typedef void* WindowHandle; |
|---|
| 41 |
|
|---|
| 42 |
enum KeyMods { |
|---|
| 43 |
None = 0, |
|---|
| 44 |
Ctrl = 0x1, CtrlBit = 1, |
|---|
| 45 |
Shift = 0x2, ShiftBit = 2, |
|---|
| 46 |
Alt = 0x4, AltBit = 3 |
|---|
| 47 |
}; |
|---|
| 48 |
|
|---|
| 49 |
char[] modsToString(KeyMods k) { |
|---|
| 50 |
alias KeyMods e; |
|---|
| 51 |
char [] ret; |
|---|
| 52 |
if (k & e.Shift) { ret ~= "Shift"; } |
|---|
| 53 |
if (k & e.Ctrl) { if (ret) ret~="|"; ret ~= "Ctrl"; } |
|---|
| 54 |
if (k & e.Alt) { if (ret) ret~="|"; ret ~= "Alt"; } |
|---|
| 55 |
if (!ret) ret = "None"; |
|---|
| 56 |
return ret; |
|---|
| 57 |
} |
|---|
| 58 |
|
|---|
| 59 |
enum MouseButtons { |
|---|
| 60 |
None = 0, |
|---|
| 61 |
Left = 0x1, LeftBit = 1, |
|---|
| 62 |
Right = 0x2, RightBit = 2, |
|---|
| 63 |
Middle = 0x4, MiddleBit = 3, |
|---|
| 64 |
Button0 = Left, Button0Bit = 1, |
|---|
| 65 |
Button1 = Right, Button1Bit = 2, |
|---|
| 66 |
Button2 = Middle, Button2Bit = 3, |
|---|
| 67 |
Button3 = 0x8, Button3Bit = 4, |
|---|
| 68 |
Button4 = 0x10, Button4Bit = 5, |
|---|
| 69 |
Button5 = 0x20, Button5Bit = 6 |
|---|
| 70 |
}; |
|---|
| 71 |
|
|---|
| 72 |
char[] buttonsToString(MouseButtons b) { |
|---|
| 73 |
alias MouseButtons e; |
|---|
| 74 |
char[] ret; |
|---|
| 75 |
if (b & e.Left) { ret ~= "Left"; } |
|---|
| 76 |
if (b & e.Middle) { if (ret) ret~="|"; ret ~= "Middle"; } |
|---|
| 77 |
if (b & e.Right) { if (ret) ret~="|"; ret ~= "Right"; } |
|---|
| 78 |
if (b & e.Button3){ if (ret) ret~="|"; ret ~= "Button3"; } |
|---|
| 79 |
if (b & e.Button4) { if (ret) ret~="|"; ret ~= "Button4"; } |
|---|
| 80 |
if (b & e.Button5) { if (ret) ret~="|"; ret ~= "Button5"; } |
|---|
| 81 |
if (!ret) ret = "None"; |
|---|
| 82 |
return ret; |
|---|
| 83 |
} |
|---|
| 84 |
|
|---|
| 85 |
enum Key { |
|---|
| 86 |
Unknown = -1, |
|---|
| 87 |
Space = 32, |
|---|
| 88 |
Special = 256, |
|---|
| 89 |
Escape, |
|---|
| 90 |
F1, |
|---|
| 91 |
F2, |
|---|
| 92 |
F3, |
|---|
| 93 |
F4, |
|---|
| 94 |
F5, |
|---|
| 95 |
F6, |
|---|
| 96 |
F7, |
|---|
| 97 |
F8, |
|---|
| 98 |
F9, |
|---|
| 99 |
F10, |
|---|
| 100 |
F11, |
|---|
| 101 |
F12, |
|---|
| 102 |
F13, |
|---|
| 103 |
F14, |
|---|
| 104 |
F15, |
|---|
| 105 |
F16, |
|---|
| 106 |
F17, |
|---|
| 107 |
F18, |
|---|
| 108 |
F19, |
|---|
| 109 |
F20, |
|---|
| 110 |
F21, |
|---|
| 111 |
F22, |
|---|
| 112 |
F23, |
|---|
| 113 |
F24, |
|---|
| 114 |
F25, |
|---|
| 115 |
Up, |
|---|
| 116 |
Down, |
|---|
| 117 |
Left, |
|---|
| 118 |
Right, |
|---|
| 119 |
LShift, Shift = LShift, |
|---|
| 120 |
RShift, |
|---|
| 121 |
LCtrl, Ctrl = LCtrl, |
|---|
| 122 |
RCtrl, |
|---|
| 123 |
LAlt, Alt = LAlt, |
|---|
| 124 |
RAlt, |
|---|
| 125 |
LMeta, |
|---|
| 126 |
RMeta, |
|---|
| 127 |
LSuper, |
|---|
| 128 |
RSuper, |
|---|
| 129 |
Mode, |
|---|
| 130 |
Compose, |
|---|
| 131 |
Tab, |
|---|
| 132 |
Enter, |
|---|
| 133 |
Backspace, |
|---|
| 134 |
Insert, |
|---|
| 135 |
Delete, |
|---|
| 136 |
PageUp, |
|---|
| 137 |
PageDown, |
|---|
| 138 |
Home, |
|---|
| 139 |
End, |
|---|
| 140 |
KP0, |
|---|
| 141 |
KP1, |
|---|
| 142 |
KP2, |
|---|
| 143 |
KP3, |
|---|
| 144 |
KP4, |
|---|
| 145 |
KP5, |
|---|
| 146 |
KP6, |
|---|
| 147 |
KP7, |
|---|
| 148 |
KP8, |
|---|
| 149 |
KP9, |
|---|
| 150 |
KP_Divide, |
|---|
| 151 |
KP_Multiply, |
|---|
| 152 |
KP_Subtract, |
|---|
| 153 |
KP_Add, |
|---|
| 154 |
KP_Decimal, |
|---|
| 155 |
KP_Equals, |
|---|
| 156 |
KP_Enter, |
|---|
| 157 |
|
|---|
| 158 |
NumLock, |
|---|
| 159 |
CapsLock, |
|---|
| 160 |
ScrollLock, |
|---|
| 161 |
|
|---|
| 162 |
Help, |
|---|
| 163 |
Print, |
|---|
| 164 |
SysReq, |
|---|
| 165 |
Break, |
|---|
| 166 |
Menu, |
|---|
| 167 |
Power, |
|---|
| 168 |
Euro, |
|---|
| 169 |
Undo, |
|---|
| 170 |
} |
|---|
| 171 |
|
|---|
| 172 |
|
|---|
| 173 |
|
|---|
| 174 |
struct _KeyEvent |
|---|
| 175 |
{ |
|---|
| 176 |
union { |
|---|
| 177 |
Point p; |
|---|
| 178 |
struct { float x,y; } |
|---|
| 179 |
} |
|---|
| 180 |
union { |
|---|
| 181 |
Point winp; |
|---|
| 182 |
struct { float winx,winy; } |
|---|
| 183 |
} |
|---|
| 184 |
int key; // an ascii char (uppercase) or enum Key |
|---|
| 185 |
dchar ch; |
|---|
| 186 |
KeyMods mods; |
|---|
| 187 |
bool shift_down() { return (mods & KeyMods.Shift)!=0; } |
|---|
| 188 |
bool ctrl_down() { return (mods & KeyMods.Ctrl)!=0; } |
|---|
| 189 |
bool alt_down() { return (mods & KeyMods.Alt)!=0; } |
|---|
| 190 |
bool is_press; |
|---|
| 191 |
bool is_release() { return !is_press; } |
|---|
| 192 |
bool is_char; |
|---|
| 193 |
bool is_key; |
|---|
| 194 |
|
|---|
| 195 |
bool is_alive = false; |
|---|
| 196 |
bool alive(bool tf) { return is_alive=tf; } |
|---|
| 197 |
bool alive() { return is_alive; } |
|---|
| 198 |
} |
|---|
| 199 |
|
|---|
| 200 |
struct _MouseButtonEvent |
|---|
| 201 |
{ |
|---|
| 202 |
union { |
|---|
| 203 |
Point p; |
|---|
| 204 |
struct { float x,y; } |
|---|
| 205 |
} |
|---|
| 206 |
union { |
|---|
| 207 |
Point winp; |
|---|
| 208 |
struct { float winx,winy; } |
|---|
| 209 |
} |
|---|
| 210 |
bool is_press; // otherwise release |
|---|
| 211 |
bool is_release() { return !is_press; } |
|---|
| 212 |
MouseButtons button; |
|---|
| 213 |
bool is_left() { return (button & MouseButtons.Left)!=0; } |
|---|
| 214 |
bool is_right() { return (button & MouseButtons.Right)!=0; } |
|---|
| 215 |
bool is_middle() { return (button & MouseButtons.Middle)!=0; } |
|---|
| 216 |
MouseButtons pressed; |
|---|
| 217 |
bool left_down() { return (pressed & MouseButtons.Left)!=0; } |
|---|
| 218 |
bool right_down() { return (pressed & MouseButtons.Right)!=0; } |
|---|
| 219 |
bool middle_down() { return (pressed & MouseButtons.Middle)!=0; } |
|---|
| 220 |
KeyMods mods; |
|---|
| 221 |
bool shift_down() { return (mods & KeyMods.Shift)!=0; } |
|---|
| 222 |
bool ctrl_down() { return (mods & KeyMods.Ctrl)!=0; } |
|---|
| 223 |
bool alt_down() { return (mods & KeyMods.Alt)!=0; } |
|---|
| 224 |
|
|---|
| 225 |
bool is_left_press() { return (is_press && is_left); } |
|---|
| 226 |
bool is_right_press() { return (is_press && is_right); } |
|---|
| 227 |
bool is_middle_press() { return (is_press && is_middle); } |
|---|
| 228 |
bool is_left_release() { return (is_release && is_left); } |
|---|
| 229 |
bool is_right_release() { return (is_release && is_right); } |
|---|
| 230 |
bool is_middle_release() { return (is_release && is_middle); } |
|---|
| 231 |
|
|---|
| 232 |
bool is_alive = false; |
|---|
| 233 |
bool alive(bool tf) { return is_alive=tf; } |
|---|
| 234 |
bool alive() { return is_alive; } |
|---|
| 235 |
} |
|---|
| 236 |
|
|---|
| 237 |
struct _MouseMoveEvent |
|---|
| 238 |
{ |
|---|
| 239 |
union { |
|---|
| 240 |
Point p; |
|---|
| 241 |
struct { float x,y; } |
|---|
| 242 |
} |
|---|
| 243 |
union { |
|---|
| 244 |
Point winp; |
|---|
| 245 |
struct { float winx,winy; } |
|---|
| 246 |
} |
|---|
| 247 |
MouseButtons pressed; |
|---|
| 248 |
bool left_down() { return (pressed & MouseButtons.Left)!=0; } |
|---|
| 249 |
bool right_down() { return (pressed & MouseButtons.Right)!=0; } |
|---|
| 250 |
bool middle_down() { return (pressed & MouseButtons.Middle)!=0; } |
|---|
| 251 |
KeyMods mods; |
|---|
| 252 |
bool shift_down() { return (mods & KeyMods.Shift)!=0; } |
|---|
| 253 |
bool ctrl_down() { return (mods & KeyMods.Ctrl)!=0; } |
|---|
| 254 |
bool alt_down() { return (mods & KeyMods.Alt)!=0; } |
|---|
| 255 |
|
|---|
| 256 |
bool is_alive = false; |
|---|
| 257 |
bool alive(bool tf) { return is_alive=tf; } |
|---|
| 258 |
bool alive() { return is_alive; } |
|---|
| 259 |
} |
|---|
| 260 |
|
|---|
| 261 |
struct _MouseWheelEvent |
|---|
| 262 |
{ |
|---|
| 263 |
union { |
|---|
| 264 |
Point p; |
|---|
| 265 |
struct { float x,y; } |
|---|
| 266 |
} |
|---|
| 267 |
union { |
|---|
| 268 |
Point winp; |
|---|
| 269 |
struct { float winx,winy; } |
|---|
| 270 |
} |
|---|
| 271 |
int delta; |
|---|
| 272 |
MouseButtons pressed; |
|---|
| 273 |
bool left_down() { return (pressed & MouseButtons.Left)!=0; } |
|---|
| 274 |
bool right_down() { return (pressed & MouseButtons.Right)!=0; } |
|---|
| 275 |
bool middle_down() { return (pressed & MouseButtons.Middle)!=0; } |
|---|
| 276 |
KeyMods mods; |
|---|
| 277 |
bool shift_down() { return (mods & KeyMods.Shift)!=0; } |
|---|
| 278 |
bool ctrl_down() { return (mods & KeyMods.Ctrl)!=0; } |
|---|
| 279 |
bool alt_down() { return (mods & KeyMods.Alt)!=0; } |
|---|
| 280 |
|
|---|
| 281 |
bool is_alive = false; |
|---|
| 282 |
bool alive(bool tf) { return is_alive=tf; } |
|---|
| 283 |
bool alive() { return is_alive; } |
|---|
| 284 |
} |
|---|
| 285 |
|
|---|
| 286 |
struct _WindowSizeEvent |
|---|
| 287 |
{ |
|---|
| 288 |
WindowHandle id; |
|---|
| 289 |
float width,height; |
|---|
| 290 |
alias width w; |
|---|
| 291 |
alias height h; |
|---|
| 292 |
|
|---|
| 293 |
bool is_alive = false; |
|---|
| 294 |
bool alive(bool tf) { return is_alive=tf; } |
|---|
| 295 |
bool alive() { return is_alive; } |
|---|
| 296 |
} |
|---|
| 297 |
|
|---|
| 298 |
struct _WindowCloseEvent |
|---|
| 299 |
{ |
|---|
| 300 |
WindowHandle id; |
|---|
| 301 |
|
|---|
| 302 |
bool is_alive = false; |
|---|
| 303 |
bool alive(bool tf) { return is_alive=tf; } |
|---|
| 304 |
bool alive() { return is_alive; } |
|---|
| 305 |
} |
|---|
| 306 |
|
|---|
| 307 |
struct _FocusEvent |
|---|
| 308 |
{ |
|---|
| 309 |
Object previous; // would rather have Widget here |
|---|
| 310 |
|
|---|
| 311 |
bool is_alive = false; |
|---|
| 312 |
bool alive(bool tf) { return is_alive=tf; } |
|---|
| 313 |
bool alive() { return is_alive; } |
|---|
| 314 |
} |
|---|
| 315 |
|
|---|
| 316 |
struct _EnterEvent |
|---|
| 317 |
{ |
|---|
| 318 |
// is anything needed here? |
|---|
| 319 |
} |
|---|
| 320 |
|
|---|
| 321 |
|
|---|
| 322 |
alias _KeyEvent* KeyEvent; |
|---|
| 323 |
alias _MouseButtonEvent* MouseButtonEvent; |
|---|
| 324 |
alias _MouseMoveEvent* MouseMoveEvent; |
|---|
| 325 |
alias _MouseWheelEvent* MouseWheelEvent; |
|---|
| 326 |
alias _WindowSizeEvent* WindowSizeEvent; |
|---|
| 327 |
alias _WindowCloseEvent* WindowCloseEvent; |
|---|
| 328 |
alias _FocusEvent* FocusEvent; |
|---|
| 329 |
alias _EnterEvent* EnterEvent; |
|---|
| 330 |
alias _EnterEvent* LeaveEvent; |
|---|
| 331 |
|
|---|
| 332 |
alias void function(KeyEvent) KeyEventFn; |
|---|
| 333 |
alias void function(MouseButtonEvent) MouseButtonEventFn; |
|---|
| 334 |
alias void function(MouseMoveEvent) MouseMoveEventFn; |
|---|
| 335 |
alias void function(MouseWheelEvent) MouseWheelEventFn; |
|---|
| 336 |
alias void function(WindowSizeEvent) WindowSizeEventFn; |
|---|
| 337 |
alias void function(WindowCloseEvent) WindowCloseEventFn; |
|---|
| 338 |
|
|---|
| 339 |
alias void delegate(KeyEvent) KeyEventDg; |
|---|
| 340 |
alias void delegate(MouseButtonEvent) MouseButtonEventDg; |
|---|
| 341 |
alias void delegate(MouseMoveEvent) MouseMoveEventDg; |
|---|
| 342 |
alias void delegate(MouseWheelEvent) MouseWheelEventDg; |
|---|
| 343 |
alias void delegate(WindowSizeEvent) WindowSizeEventDg; |
|---|
| 344 |
alias void delegate(WindowCloseEvent) WindowCloseEventDg; |
|---|
| 345 |
|
|---|
| 346 |
alias FlexSignal!(KeyEvent) KeyEventSignal; |
|---|
| 347 |
alias FlexSignal!(MouseButtonEvent) MouseButtonEventSignal; |
|---|
| 348 |
alias FlexSignal!(MouseMoveEvent) MouseMoveEventSignal; |
|---|
| 349 |
alias FlexSignal!(MouseWheelEvent) MouseWheelEventSignal; |
|---|
| 350 |
alias FlexSignal!(WindowSizeEvent) WindowSizeEventSignal; |
|---|
| 351 |
alias FlexSignal!(WindowCloseEvent) WindowCloseEventSignal; |
|---|