Changeset 48
- Timestamp:
- 04/22/07 06:28:25 (2 years ago)
- Files:
-
- trunk/luigi/adapter.d (modified) (5 diffs)
- trunk/luigi/adapters/gld.d (modified) (4 diffs)
- trunk/luigi/adapters/glfw.d (modified) (4 diffs)
- trunk/luigi/adapters/sdl.d (modified) (2 diffs)
- trunk/luigi/gui.d (modified) (6 diffs)
- trunk/luigi/theme.d (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/luigi/adapter.d
r46 r48 51 51 interface InputAdapter 52 52 { 53 /// Get the size of the specified window, using an opaque 54 /// window handle. 55 Size get_window_size(WindowHandle h); 56 57 53 58 /** 54 * These are "raw" callbacks in that they haven't yet been translated or dispatched 55 * to widgets. This is all the input that comes in at the window level. 56 * Luigi uses these to get input which is then dispatched to widgets based on 57 * current focus item, location of the mouse, etc. 58 * See event.d for the definitons of the function types. 59 * These are standard user-level callbacks. 60 * These get dispatched to your code only for 61 * events that weren't handled by any widget 62 * on the GUI overlay. 59 63 */ 60 64 void addKeyCallback(KeyEventFn cb) ; … … 90 94 void removeWindowCloseCallback(WindowCloseEventDg cb) ; 91 95 92 Size get_window_size(WindowHandle h); 96 /** 97 * These are "raw" system callbacks in that they haven't yet been 98 * translated or dispatched to widgets. This is all the input 99 * that comes in at the window level. Luigi uses these to get 100 * input which is then dispatched to widgets based on current 101 * focus item, location of the mouse, etc. See event.d for the 102 * definitons of the function types. 103 */ 104 void addSysKeyCallback(KeyEventFn cb) ; 105 void addSysMouseButtonCallback(MouseButtonEventFn cb) ; 106 107 // And again for delegates... 108 void addSysKeyCallback(KeyEventDg cb) ; 109 void addSysMouseButtonCallback(MouseButtonEventDg cb) ; 110 111 // remove raw system callback 112 void removeSysKeyCallback(KeyEventFn cb) ; 113 void removeSysMouseButtonCallback(MouseButtonEventFn cb) ; 114 115 // And again for delegates... 116 void removeSysKeyCallback(KeyEventDg cb) ; 117 void removeSysMouseButtonCallback(MouseButtonEventDg cb) ; 93 118 94 119 // addRaw Paint … … 124 149 windowSize = new WindowSizeEventSignal; 125 150 windowClose = new WindowCloseEventSignal; 151 152 sysKey = new KeyEventSignal; 153 sysMouseButton = new MouseButtonEventSignal; 126 154 } 127 155 } … … 136 164 WindowSizeEventSignal windowSize; 137 165 WindowCloseEventSignal windowClose; 166 167 KeyEventSignal sysKey; 168 MouseButtonEventSignal sysMouseButton; 138 169 } 139 170 private _LuigiSignals _lsig; … … 171 202 void removeWindowSizeCallback(WindowSizeEventDg cb) {_lsig.windowSize.disconnect(cb);} 172 203 void removeWindowCloseCallback(WindowCloseEventDg cb) {_lsig.windowClose.disconnect(cb);} 204 205 206 // Implementation of InputAdapter 207 void addSysKeyCallback(KeyEventFn cb) {_lsig.sysKey.connect(cb);} 208 void addSysMouseButtonCallback(MouseButtonEventFn cb) {_lsig.sysMouseButton.connect(cb);} 209 210 // And again for delegates... 211 void addSysKeyCallback(KeyEventDg cb) {_lsig.sysKey.connect(cb);} 212 void addSysMouseButtonCallback(MouseButtonEventDg cb) {_lsig.sysMouseButton.connect(cb);} 213 214 // remove raw system callback 215 void removeSysKeyCallback(KeyEventFn cb) {_lsig.sysKey.disconnect(cb);} 216 void removeSysMouseButtonCallback(MouseButtonEventFn cb) {_lsig.sysMouseButton.disconnect(cb);}; 217 218 // And again for delegates... 219 void removeSysKeyCallback(KeyEventDg cb) {_lsig.sysKey.disconnect(cb);} 220 void removeSysMouseButtonCallback(MouseButtonEventDg cb) {_lsig.sysMouseButton.disconnect(cb);}; 221 222 223 173 224 } 174 225 trunk/luigi/adapters/gld.d
r42 r48 32 32 import luigi.adapter; 33 33 private import gld; 34 //import sslot.signal;35 34 import luigi.signalobj; 36 35 … … 159 158 { 160 159 _KeyEvent ev; 161 ev.key = translate_key(k); 162 m_lastKey = ev.key; 163 ev.ch = 0; 164 ev.is_press = (action==GLD_PRESS); 165 ev.mods = inst._getMods(); 166 ev.is_key = true; 167 ev.is_char = false; 168 inst.sig.key.emit(&ev); 160 void _initEvent() { 161 ev.key = translate_key(k); 162 m_lastKey = ev.key; 163 ev.ch = 0; 164 ev.is_press = (action==GLD_PRESS); 165 ev.mods = inst._getMods(); 166 ev.is_key = true; 167 ev.is_char = false; 168 } 169 _initEvent(); 170 inst.sig.sysKey.emit(&ev); 171 if (ev.alive) { 172 _initEvent(); 173 inst.sig.key.emit(&ev); 174 } 169 175 } 170 176 static void charCallbackC(int ch, int action) … … 177 183 // (e.g. european and asian) but it seems to be the case with GLD. 178 184 // Not every key has a char, but every char has a key in GLD 179 ev.key = m_lastKey; 180 ev.ch = ch; 181 ev.is_press = (action==GLD_PRESS); 182 ev.mods = inst._getMods(); 183 ev.is_key = false; 184 ev.is_char = true; 185 inst.sig.key.emit(&ev); 185 void _initEvent() { 186 ev.key = m_lastKey; 187 ev.ch = ch; 188 ev.is_press = (action==GLD_PRESS); 189 ev.mods = inst._getMods(); 190 ev.is_key = false; 191 ev.is_char = true; 192 } 193 _initEvent(); 194 inst.sig.sysKey.emit(&ev); 195 if (ev.alive) { 196 _initEvent(); 197 inst.sig.key.emit(&ev); 198 } 186 199 } 187 200 static void mouseButtonCallbackC(int button, int action) … … 190 203 int x,y; 191 204 gldGetMousePos(&x, &y); 192 ev.x = ev.winx = x; 193 ev.y = ev.winy = y; 194 ev.is_press = (action==GLD_PRESS); 195 ev.mods = inst._getMods(); 196 ev.pressed = inst._getButtons(); 197 if (button == GLD_MOUSE_BUTTON_LEFT) ev.button = MouseButtons.Left; 198 else if (button == GLD_MOUSE_BUTTON_RIGHT) ev.button = MouseButtons.Right; 199 else if (button == GLD_MOUSE_BUTTON_MIDDLE) ev.button = MouseButtons.Middle; 200 201 inst.sig.mouseButton.emit(&ev); 205 void _initEvent() { 206 ev.x = ev.winx = x; 207 ev.y = ev.winy = y; 208 ev.is_press = (action==GLD_PRESS); 209 ev.mods = inst._getMods(); 210 ev.pressed = inst._getButtons(); 211 if (button == GLD_MOUSE_BUTTON_LEFT) ev.button = MouseButtons.Left; 212 else if (button == GLD_MOUSE_BUTTON_RIGHT) ev.button = MouseButtons.Right; 213 else if (button == GLD_MOUSE_BUTTON_MIDDLE) ev.button = MouseButtons.Middle; 214 } 215 _initEvent(); 216 inst.sig.sysMouseButton.emit(&ev); 217 if (ev.alive) { 218 // reinit because GUI might much with it 219 _initEvent(); 220 inst.sig.mouseButton.emit(&ev); 221 } 202 222 } 203 223 static void mousePosCallbackC(int x, int y) trunk/luigi/adapters/glfw.d
r33 r48 5 5 luigi/adapter/glfw.d 6 6 -- GLFW input adapter for the 'Luigi' user interface library. 7 This was originally written for DerelictGLFW, but the Derelict 8 project has since decided to abandon the project. 9 There are supposedly D bindings distributed with GLFW, so you can 10 link to it directly without Derelict's help. 11 12 This is made to work with Derelict's former GLFW. Should be 13 easy to get it working with the D bindings that come with GLFW, or 14 just use GLD, the all-D native port of GLFW for D. 15 The Luigi GLD bindings are better tested than these. 7 16 8 17 Copyright (C) 2006 William V. Baxter III … … 159 168 { 160 169 _KeyEvent ev; 161 ev.key = translate_key(k); 162 m_lastKey = ev.key; 163 ev.ch = 0; 164 ev.is_press = (action==GLFW_PRESS); 165 ev.mods = inst._getMods(); 166 ev.is_key = true; 167 ev.is_char = false; 168 inst.sig.key.emit(&ev); 170 void _initEvent() { 171 ev.key = translate_key(k); 172 m_lastKey = ev.key; 173 ev.ch = 0; 174 ev.is_press = (action==GLFW_PRESS); 175 ev.mods = inst._getMods(); 176 ev.is_key = true; 177 ev.is_char = false; 178 } 179 _initEvent(); 180 inst.sig.sysKey.emit(&ev); 181 if (ev.alive) { 182 _initEvent(); 183 inst.sig.key.emit(&ev); 184 } 169 185 } 170 186 static void charCallbackC(int ch, int action) … … 177 193 // (e.g. european and asian) but it seems to be the case with GLFW. 178 194 // Not every key has a char, but every char has a key in GLFW 179 ev.key = m_lastKey; 180 ev.ch = ch; 181 ev.is_press = (action==GLFW_PRESS); 182 ev.mods = inst._getMods(); 183 ev.is_key = false; 184 ev.is_char = true; 185 inst.sig.key.emit(&ev); 195 void _initEvent() { 196 ev.key = m_lastKey; 197 ev.ch = ch; 198 ev.is_press = (action==GLFW_PRESS); 199 ev.mods = inst._getMods(); 200 ev.is_key = false; 201 ev.is_char = true; 202 } 203 _initEvent(); 204 inst.sig.sysKey.emit(&ev); 205 if (ev.alive) { 206 _initEvent(); 207 inst.sig.key.emit(&ev); 208 } 186 209 } 187 210 static void mouseButtonCallbackC(int button, int action) … … 190 213 int x,y; 191 214 glfwGetMousePos(&x, &y); 192 ev.x = ev.winx = x; 193 ev.y = ev.winy = y; 194 ev.is_press = (action==GLFW_PRESS); 195 ev.mods = inst._getMods(); 196 ev.pressed = inst._getButtons(); 197 if (button == GLFW_MOUSE_BUTTON_LEFT) ev.button = MouseButtons.Left; 198 else if (button == GLFW_MOUSE_BUTTON_RIGHT) ev.button = MouseButtons.Right; 199 else if (button == GLFW_MOUSE_BUTTON_MIDDLE) ev.button = MouseButtons.Middle; 200 201 inst.sig.mouseButton.emit(&ev); 215 void _initEvent() { 216 ev.x = ev.winx = x; 217 ev.y = ev.winy = y; 218 ev.is_press = (action==GLFW_PRESS); 219 ev.mods = inst._getMods(); 220 ev.pressed = inst._getButtons(); 221 if (button == GLFW_MOUSE_BUTTON_LEFT) ev.button = MouseButtons.Left; 222 else if (button == GLFW_MOUSE_BUTTON_RIGHT) ev.button = MouseButtons.Right; 223 else if (button == GLFW_MOUSE_BUTTON_MIDDLE) ev.button = MouseButtons.Middle; 224 } 225 _initEvent(); 226 inst.sig.sysMouseButton.emit(&ev); 227 if (ev.alive) { 228 // reinit because GUI might much with it 229 _initEvent(); 230 inst.sig.mouseButton.emit(&ev); 231 } 202 232 } 203 233 static void mousePosCallbackC(int x, int y) trunk/luigi/adapters/sdl.d
r34 r48 356 356 { 357 357 _KeyEvent ev; 358 ev.key= translate_key(sdl.keysym.sym);359 ev.mods = inst._getMods();358 int k = translate_key(sdl.keysym.sym); 359 dchar ch; 360 360 if (SDL_EnableUNICODE(-1)) { 361 ev.ch = sdl.keysym.unicode;361 ch = sdl.keysym.unicode; 362 362 } 363 363 else { 364 ev.ch = translate_char(sdl.keysym.sym, ev.mods); 365 } 366 ev.is_press = (sdl.type==SDL_KEYDOWN); 367 ev.is_key = true; 368 ev.is_char = (ev.ch != 0); 369 370 inst.sig.key.emit(&ev); 364 ch = translate_char(sdl.keysym.sym, ev.mods); 365 } 366 void _initEvent() { 367 ev.key = k; 368 ev.ch = ch; 369 ev.mods = inst._getMods(); 370 ev.is_press = (sdl.type==SDL_KEYDOWN); 371 ev.is_key = true; 372 ev.is_char = (ev.ch != 0); 373 } 374 _initEvent(); 375 inst.sig.sysKey.emit(&ev); 376 if (ev.alive) { 377 _initEvent(); 378 inst.sig.key.emit(&ev); 379 } 371 380 return ev.alive; 372 381 } … … 378 387 } 379 388 _MouseButtonEvent ev; 380 ev.x = ev.winx = sdl.x; 381 ev.y = ev.winy = sdl.y; 382 ev.is_press = (sdl.type==SDL_MOUSEBUTTONDOWN); 383 ev.mods = inst._getMods(); 384 ev.pressed = inst._getButtons(); 385 if (sdl.button == SDL_BUTTON_LEFT) ev.button = MouseButtons.Left; 386 else if (sdl.button == SDL_BUTTON_RIGHT) ev.button = MouseButtons.Right; 387 else if (sdl.button == SDL_BUTTON_MIDDLE) ev.button = MouseButtons.Middle; 388 389 inst.sig.mouseButton.emit(&ev); 389 void _initEvent() { 390 ev.x = ev.winx = sdl.x; 391 ev.y = ev.winy = sdl.y; 392 ev.is_press = (sdl.type==SDL_MOUSEBUTTONDOWN); 393 ev.mods = inst._getMods(); 394 ev.pressed = inst._getButtons(); 395 if (sdl.button == SDL_BUTTON_LEFT) ev.button = MouseButtons.Left; 396 else if (sdl.button == SDL_BUTTON_RIGHT) ev.button = MouseButtons.Right; 397 else if (sdl.button == SDL_BUTTON_MIDDLE) ev.button = MouseButtons.Middle; 398 } 399 _initEvent(); 400 inst.sig.sysMouseButton.emit(&ev); 401 if (ev.alive) { 402 _initEvent(); 403 inst.sig.mouseButton.emit(&ev); 404 } 390 405 return ev.alive; 391 406 } trunk/luigi/gui.d
r47 r48 54 54 getter rather than the setter. 55 55 */ 56 57 56 module luigi.gui; 58 57 … … 87 86 * Holds GUI globals including the theme, the input adapter, and keeps track 88 87 * of all the top-level Frames and Overlays. 89 */88 */ 90 89 class Luigi 91 90 { 92 91 /// Return the singleton instance 93 static Luigi opCall() { 92 static Luigi opCall() 93 { 94 94 static Luigi instance = null; 95 95 if (!instance) instance = new Luigi; … … 168 168 // add in top-level input hooks 169 169 with (m_inputsys) { 170 add KeyCallback(&ov.on_sys_key);171 add MouseButtonCallback(&ov.on_sys_mouse_button) ;170 addSysKeyCallback(&ov.on_sys_key); 171 addSysMouseButtonCallback(&ov.on_sys_mouse_button) ; 172 172 addMouseMoveCallback(&ov.on_sys_mouse_move); 173 173 addMouseWheelCallback(&ov.on_sys_mouse_wheel); … … 209 209 210 210 211 /// Add a system-level input callback211 /// Add a user-level input callback functions and delegates 212 212 void add_key_callback(KeyEventFn cb) {Luigi().adapter.addKeyCallback(cb);} 213 void add_key_callback(KeyEventDg cb) {Luigi().adapter.addKeyCallback(cb);} 213 214 void add_mouse_button_callback(MouseButtonEventFn cb) {Luigi().adapter.addMouseButtonCallback(cb); } 215 void add_mouse_button_callback(MouseButtonEventDg cb) {Luigi().adapter.addMouseButtonCallback(cb);} 214 216 void add_mouse_move_callback(MouseMoveEventFn cb) {Luigi().adapter.addMouseMoveCallback(cb);} 217 void add_mouse_move_callback(MouseMoveEventDg cb) {Luigi().adapter.addMouseMoveCallback(cb);} 215 218 void add_mouse_wheel_callback(MouseWheelEventFn cb) {Luigi().adapter.addMouseWheelCallback(cb);} 219 void add_mouse_wheel_callback(MouseWheelEventDg cb) {Luigi().adapter.addMouseWheelCallback(cb);} 216 220 void add_window_size_callback(WindowSizeEventFn cb) {Luigi().adapter.addWindowSizeCallback(cb);} 221 void add_window_size_callback(WindowSizeEventDg cb) {Luigi().adapter.addWindowSizeCallback(cb);} 217 222 void add_window_close_callback(WindowCloseEventFn cb) {Luigi().adapter.addWindowCloseCallback(cb);} 218 223 void add_window_close_callback(WindowCloseEventDg cb) {Luigi().adapter.addWindowCloseCallback(cb);} 224 /// Add a system-level input callback function or delegate -- Use with caution! 225 void add_sys_key_callback(KeyEventFn cb) {Luigi().adapter.addSysKeyCallback(cb);} 226 void add_sys_key_callback(KeyEventDg cb) {Luigi().adapter.addSysKeyCallback(cb);} 227 void add_sys_mouse_button_callback(MouseButtonEventFn cb) {Luigi().adapter.addSysMouseButtonCallback(cb); } 228 void add_sys_mouse_button_callback(MouseButtonEventDg cb) {Luigi().adapter.addSysMouseButtonCallback(cb); } 229 230 231 /// Remove installed callbacks 219 232 void remove_key_callback(KeyEventFn cb) {Luigi().adapter.removeKeyCallback(cb);} 220 //void add_mouse_button_callback(MouseButtonEventFn cb) {Luigi().adapter.addMouseButtonCallback(cb); } 221 //void add_mouse_move_callback(MouseMoveEventFn cb) {Luigi().adapter.addMouseMoveCallback(cb);} 222 //void add_mouse_wheel_callback(MouseWheelEventFn cb) {Luigi().adapter.addMouseWheelCallback(cb);} 223 //void add_window_size_callback(WindowSizeEventFn cb) {Luigi().adapter.addWindowSizeCallback(cb);} 224 //void add_window_close_callback(WindowCloseEventFn cb) {Luigi().adapter.addWindowCloseCallback(cb);} 225 226 227 /// ditto 228 void add_key_callback(KeyEventDg cb) {Luigi().adapter.addKeyCallback(cb);} 229 void add_mouse_button_callback(MouseButtonEventDg cb) {Luigi().adapter.addMouseButtonCallback(cb);} 230 void add_mouse_move_callback(MouseMoveEventDg cb) {Luigi().adapter.addMouseMoveCallback(cb);} 231 void add_mouse_wheel_callback(MouseWheelEventDg cb) {Luigi().adapter.addMouseWheelCallback(cb);} 232 void add_window_size_callback(WindowSizeEventDg cb) {Luigi().adapter.addWindowSizeCallback(cb);} 233 void add_window_close_callback(WindowCloseEventDg cb) {Luigi().adapter.addWindowCloseCallback(cb);} 233 void remove_key_callback(KeyEventDg cb) {Luigi().adapter.removeKeyCallback(cb);} 234 void remove_mouse_button_callback(MouseButtonEventFn cb) {Luigi().adapter.removeMouseButtonCallback(cb); } 235 void remove_mouse_button_callback(MouseButtonEventDg cb) {Luigi().adapter.removeMouseButtonCallback(cb); } 236 void remove_mouse_move_callback(MouseMoveEventFn cb) {Luigi().adapter.removeMouseMoveCallback(cb);} 237 void remove_mouse_move_callback(MouseMoveEventDg cb) {Luigi().adapter.removeMouseMoveCallback(cb);} 238 void remove_mouse_wheel_callback(MouseWheelEventFn cb) {Luigi().adapter.removeMouseWheelCallback(cb);} 239 void remove_mouse_wheel_callback(MouseWheelEventDg cb) {Luigi().adapter.removeMouseWheelCallback(cb);} 240 void remove_window_size_callback(WindowSizeEventFn cb) {Luigi().adapter.removeWindowSizeCallback(cb);} 241 void remove_window_size_callback(WindowSizeEventDg cb) {Luigi().adapter.removeWindowSizeCallback(cb);} 242 void remove_window_close_callback(WindowCloseEventFn cb) {Luigi().adapter.removeWindowCloseCallback(cb);} 243 void remove_window_close_callback(WindowCloseEventDg cb) {Luigi().adapter.removeWindowCloseCallback(cb);} 244 void remove_sys_key_callback(KeyEventFn cb) {Luigi().adapter.removeSysKeyCallback(cb);} 245 void remove_sys_key_callback(KeyEventDg cb) {Luigi().adapter.removeSysKeyCallback(cb);} 246 void remove_sys_mouse_button_callback(MouseButtonEventFn cb) {Luigi().adapter.removeSysMouseButtonCallback(cb); } 247 void remove_sys_mouse_button_callback(MouseButtonEventDg cb) {Luigi().adapter.removeSysMouseButtonCallback(cb); } 248 234 249 235 250 … … 1342 1357 override void on_key(KeyEvent ev) 1343 1358 { 1344 if (ev.is_press ) {1359 if (ev.is_press && !ev.is_char) { 1345 1360 if (ev.key == Key.Space || 1346 1361 ev.key == Key.Enter || … … 1696 1711 return m_increment; 1697 1712 } 1698 if (ev.is_press ) {1713 if (ev.is_press && !ev.is_char) { 1699 1714 switch(ev.key) 1700 1715 { trunk/luigi/theme.d
r26 r48 180 180 if (f) f(item, ev); 181 181 if (!f || ev.alive) { item.on_key(ev); } 182 else {ev.alive=true;} 182 183 } 183 184 override void on_mouse_button(Widget item, MouseButtonEvent ev) … … 186 187 if (f) f(item, ev); 187 188 if (!f || ev.alive) { item.on_mouse_button(ev); } 189 else { ev.alive=true; } 188 190 } 189 191 override void on_mouse_move(Widget item, MouseMoveEvent ev) … … 192 194 if (f) f(item, ev); 193 195 if (!f || ev.alive) { item.on_mouse_move(ev); } 194 } 195 } 196 197 198 196 else {ev.alive=true;} 197 } 198 } 199 200 201
