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/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    }