Changeset 48

Show
Ignore:
Timestamp:
04/22/07 06:28:25 (2 years ago)
Author:
baxissimo
Message:

Finally fixed it so that the GUI can steal mouse clicks and the user can listen for everything else.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/luigi/adapter.d

    r46 r48  
    5151interface InputAdapter 
    5252{ 
     53    /// Get the size of the specified window, using an opaque 
     54    /// window handle. 
     55    Size get_window_size(WindowHandle h); 
     56 
     57 
    5358    /** 
    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. 
    5963     */ 
    6064    void addKeyCallback(KeyEventFn cb)                 ; 
     
    9094    void removeWindowCloseCallback(WindowCloseEventDg cb) ; 
    9195 
    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) ; 
    93118 
    94119    // addRaw Paint 
     
    124149            windowSize = new WindowSizeEventSignal;  
    125150            windowClose = new WindowCloseEventSignal; 
     151 
     152            sysKey = new KeyEventSignal; 
     153            sysMouseButton = new MouseButtonEventSignal; 
    126154        } 
    127155    } 
     
    136164        WindowSizeEventSignal  windowSize;  
    137165        WindowCloseEventSignal windowClose; 
     166 
     167        KeyEventSignal         sysKey; 
     168        MouseButtonEventSignal sysMouseButton; 
    138169    } 
    139170    private _LuigiSignals _lsig; 
     
    171202    void removeWindowSizeCallback(WindowSizeEventDg cb)   {_lsig.windowSize.disconnect(cb);}   
    172203    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 
    173224} 
    174225 
  • trunk/luigi/adapters/gld.d

    r42 r48  
    3232import luigi.adapter; 
    3333private import gld; 
    34 //import sslot.signal; 
    3534import luigi.signalobj; 
    3635 
     
    159158    { 
    160159        _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        } 
    169175    } 
    170176    static void charCallbackC(int ch, int action) 
     
    177183        // (e.g. european and asian) but it seems to be the case with GLD. 
    178184        // 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        } 
    186199    } 
    187200    static void mouseButtonCallbackC(int button, int action) 
     
    190203        int x,y; 
    191204        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        } 
    202222    } 
    203223    static void mousePosCallbackC(int x, int y) 
  • trunk/luigi/adapters/glfw.d

    r33 r48  
    55  luigi/adapter/glfw.d 
    66     -- 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. 
    716 
    817  Copyright (C) 2006 William V. Baxter III 
     
    159168    { 
    160169        _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        } 
    169185    } 
    170186    static void charCallbackC(int ch, int action) 
     
    177193        // (e.g. european and asian) but it seems to be the case with GLFW. 
    178194        // 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        } 
    186209    } 
    187210    static void mouseButtonCallbackC(int button, int action) 
     
    190213        int x,y; 
    191214        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        } 
    202232    } 
    203233    static void mousePosCallbackC(int x, int y) 
  • trunk/luigi/adapters/sdl.d

    r34 r48  
    356356    { 
    357357        _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
    360360        if (SDL_EnableUNICODE(-1)) { 
    361             ev.ch = sdl.keysym.unicode; 
     361            ch = sdl.keysym.unicode; 
    362362        } 
    363363        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        } 
    371380        return ev.alive; 
    372381    } 
     
    378387        } 
    379388        _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        } 
    390405        return ev.alive; 
    391406    } 
  • trunk/luigi/gui.d

    r47 r48  
    5454   getter rather than the setter. 
    5555 */ 
    56  
    5756module luigi.gui; 
    5857 
     
    8786 * Holds GUI globals including the theme, the input adapter, and keeps track 
    8887 * of all the top-level Frames and Overlays. 
    89 */ 
     88 */ 
    9089class Luigi 
    9190{ 
    9291    /// Return the singleton instance 
    93     static Luigi opCall() { 
     92    static Luigi opCall()  
     93    { 
    9494        static Luigi instance = null; 
    9595        if (!instance) instance = new Luigi; 
     
    168168        // add in top-level input hooks 
    169169        with (m_inputsys) { 
    170             addKeyCallback(&ov.on_sys_key); 
    171             addMouseButtonCallback(&ov.on_sys_mouse_button) ; 
     170            addSysKeyCallback(&ov.on_sys_key); 
     171            addSysMouseButtonCallback(&ov.on_sys_mouse_button) ; 
    172172            addMouseMoveCallback(&ov.on_sys_mouse_move); 
    173173            addMouseWheelCallback(&ov.on_sys_mouse_wheel); 
     
    209209 
    210210 
    211 /// Add a system-level input callback 
     211/// Add a user-level input callback functions and delegates 
    212212void add_key_callback(KeyEventFn cb)                  {Luigi().adapter.addKeyCallback(cb);} 
     213void add_key_callback(KeyEventDg cb)                  {Luigi().adapter.addKeyCallback(cb);} 
    213214void add_mouse_button_callback(MouseButtonEventFn cb) {Luigi().adapter.addMouseButtonCallback(cb); } 
     215void add_mouse_button_callback(MouseButtonEventDg cb) {Luigi().adapter.addMouseButtonCallback(cb);} 
    214216void add_mouse_move_callback(MouseMoveEventFn cb)     {Luigi().adapter.addMouseMoveCallback(cb);} 
     217void add_mouse_move_callback(MouseMoveEventDg cb)     {Luigi().adapter.addMouseMoveCallback(cb);} 
    215218void add_mouse_wheel_callback(MouseWheelEventFn cb)   {Luigi().adapter.addMouseWheelCallback(cb);} 
     219void add_mouse_wheel_callback(MouseWheelEventDg cb)   {Luigi().adapter.addMouseWheelCallback(cb);} 
    216220void add_window_size_callback(WindowSizeEventFn cb)   {Luigi().adapter.addWindowSizeCallback(cb);} 
     221void add_window_size_callback(WindowSizeEventDg cb)   {Luigi().adapter.addWindowSizeCallback(cb);} 
    217222void add_window_close_callback(WindowCloseEventFn cb) {Luigi().adapter.addWindowCloseCallback(cb);} 
    218  
     223void add_window_close_callback(WindowCloseEventDg cb) {Luigi().adapter.addWindowCloseCallback(cb);} 
     224/// Add a system-level input callback function or delegate -- Use with caution! 
     225void add_sys_key_callback(KeyEventFn cb)                  {Luigi().adapter.addSysKeyCallback(cb);} 
     226void add_sys_key_callback(KeyEventDg cb)                  {Luigi().adapter.addSysKeyCallback(cb);} 
     227void add_sys_mouse_button_callback(MouseButtonEventFn cb) {Luigi().adapter.addSysMouseButtonCallback(cb); } 
     228void add_sys_mouse_button_callback(MouseButtonEventDg cb) {Luigi().adapter.addSysMouseButtonCallback(cb); } 
     229 
     230 
     231/// Remove installed callbacks 
    219232void 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);} 
     233void remove_key_callback(KeyEventDg cb)                  {Luigi().adapter.removeKeyCallback(cb);} 
     234void remove_mouse_button_callback(MouseButtonEventFn cb) {Luigi().adapter.removeMouseButtonCallback(cb); } 
     235void remove_mouse_button_callback(MouseButtonEventDg cb) {Luigi().adapter.removeMouseButtonCallback(cb); } 
     236void remove_mouse_move_callback(MouseMoveEventFn cb)     {Luigi().adapter.removeMouseMoveCallback(cb);} 
     237void remove_mouse_move_callback(MouseMoveEventDg cb)     {Luigi().adapter.removeMouseMoveCallback(cb);} 
     238void remove_mouse_wheel_callback(MouseWheelEventFn cb)   {Luigi().adapter.removeMouseWheelCallback(cb);} 
     239void remove_mouse_wheel_callback(MouseWheelEventDg cb)   {Luigi().adapter.removeMouseWheelCallback(cb);} 
     240void remove_window_size_callback(WindowSizeEventFn cb)   {Luigi().adapter.removeWindowSizeCallback(cb);} 
     241void remove_window_size_callback(WindowSizeEventDg cb)   {Luigi().adapter.removeWindowSizeCallback(cb);} 
     242void remove_window_close_callback(WindowCloseEventFn cb) {Luigi().adapter.removeWindowCloseCallback(cb);} 
     243void remove_window_close_callback(WindowCloseEventDg cb) {Luigi().adapter.removeWindowCloseCallback(cb);} 
     244void remove_sys_key_callback(KeyEventFn cb)                  {Luigi().adapter.removeSysKeyCallback(cb);} 
     245void remove_sys_key_callback(KeyEventDg cb)                  {Luigi().adapter.removeSysKeyCallback(cb);} 
     246void remove_sys_mouse_button_callback(MouseButtonEventFn cb) {Luigi().adapter.removeSysMouseButtonCallback(cb); } 
     247void remove_sys_mouse_button_callback(MouseButtonEventDg cb) {Luigi().adapter.removeSysMouseButtonCallback(cb); } 
     248 
    234249 
    235250 
     
    13421357    override void on_key(KeyEvent ev) 
    13431358    { 
    1344         if (ev.is_press) { 
     1359        if (ev.is_press && !ev.is_char) { 
    13451360            if (ev.key == Key.Space || 
    13461361                ev.key == Key.Enter || 
     
    16961711            return m_increment; 
    16971712        } 
    1698         if (ev.is_press) { 
     1713        if (ev.is_press && !ev.is_char) { 
    16991714            switch(ev.key)  
    17001715            { 
  • trunk/luigi/theme.d

    r26 r48  
    180180        if (f) f(item, ev); 
    181181        if (!f || ev.alive) { item.on_key(ev); } 
     182        else {ev.alive=true;} 
    182183    } 
    183184    override void on_mouse_button(Widget item, MouseButtonEvent ev)  
     
    186187        if (f) f(item, ev); 
    187188        if (!f || ev.alive) { item.on_mouse_button(ev); } 
     189        else { ev.alive=true; } 
    188190    } 
    189191    override void on_mouse_move(Widget item, MouseMoveEvent ev)  
     
    192194        if (f) f(item, ev); 
    193195        if (!f || ev.alive) { item.on_mouse_move(ev); } 
    194     } 
    195 
    196  
    197  
    198  
     196        else {ev.alive=true;} 
     197    } 
     198
     199 
     200 
     201