Changeset 16 in pugl


Ignore:
Timestamp:
04/30/12 00:21:38 (2 years ago)
Author:
drobilla
Message:

Send special key events for individual modifier key presses (X11 for now).
Improve documentation.

Location:
trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/pugl/pugl.h

    r15 r16  
    6363#endif 
    6464 
     65/** 
     66   An OpenGL view. 
     67*/ 
    6568typedef struct PuglViewImpl PuglView; 
    6669 
     
    7477typedef intptr_t PuglNativeWindow; 
    7578 
     79/** 
     80   Return status code. 
     81*/ 
    7682typedef enum { 
    7783    PUGL_SUCCESS = 0 
    7884} PuglStatus; 
    7985 
     86/** 
     87   Convenience symbols for ASCII control characters. 
     88*/ 
     89typedef enum { 
     90    PUGL_CHAR_BACKSPACE = 0x08, 
     91    PUGL_CHAR_ESCAPE    = 0x1B, 
     92    PUGL_CHAR_DELETE    = 0x7F 
     93} PuglChar; 
     94     
     95/** 
     96   Special (non-Unicode) keyboard keys. 
     97*/ 
    8098typedef enum { 
    8199    PUGL_KEY_F1 = 1, 
     
    99117    PUGL_KEY_HOME, 
    100118    PUGL_KEY_END, 
    101     PUGL_KEY_INSERT 
     119    PUGL_KEY_INSERT, 
     120    PUGL_KEY_SHIFT_L, 
     121    PUGL_KEY_SHIFT_R, 
     122    PUGL_KEY_CTRL_L, 
     123    PUGL_KEY_CTRL_R, 
     124    PUGL_KEY_ALT_L, 
     125    PUGL_KEY_ALT_R, 
     126    PUGL_KEY_SUPER_L, 
     127    PUGL_KEY_SUPER_R 
    102128} PuglKey; 
    103129 
     130/** 
     131   Keyboard modifier flags. 
     132*/ 
    104133typedef enum { 
    105134    PUGL_MOD_SHIFT = 1,       /**< Shift key */  
     
    107136    PUGL_MOD_ALT   = 1 << 2,  /**< Alt/Option key */ 
    108137    PUGL_MOD_SUPER = 1 << 3,  /**< Mod4/Command/Windows key */ 
    109 } PuglModifier; 
     138} PuglMod; 
    110139     
    111140/** 
     
    114143typedef void* PuglHandle; 
    115144 
     145/** 
     146   A function called when the window is closed. 
     147*/ 
    116148typedef void (*PuglCloseFunc)(PuglView* view); 
     149 
     150/** 
     151   A function called to draw the view contents with OpenGL. 
     152*/ 
    117153typedef void (*PuglDisplayFunc)(PuglView* view); 
     154 
     155/** 
     156   A function called when a key is pressed or released. 
     157   @param view The view the event occured in. 
     158   @param press True if the key was pressed, false if released. 
     159   @param key Unicode point of the key pressed. 
     160*/ 
    118161typedef void (*PuglKeyboardFunc)(PuglView* view, bool press, uint32_t key); 
     162 
     163/** 
     164   A function called when the pointer moves. 
     165   @param view The view the event occured in. 
     166   @param x The window-relative x coordinate of the pointer. 
     167   @param y The window-relative y coordinate of the pointer. 
     168*/ 
    119169typedef void (*PuglMotionFunc)(PuglView* view, int x, int y); 
    120 typedef void (*PuglMouseFunc)(PuglView* view, int button, bool down, 
    121                               int x, int y); 
     170 
     171/** 
     172   A function called when a mouse button is pressed or released. 
     173   @param view The view the event occured in. 
     174   @param button The button number (1 = left, 2 = middle, 3 = right). 
     175   @param press True if the key was pressed, false if released. 
     176   @param x The window-relative x coordinate of the pointer. 
     177   @param y The window-relative y coordinate of the pointer. 
     178*/ 
     179typedef void (*PuglMouseFunc)( 
     180    PuglView* view, int button, bool press, int x, int y); 
     181 
     182/** 
     183   A function called when the view is resized. 
     184   @param view The view being resized. 
     185   @param width The new view width. 
     186   @param height The new view height. 
     187*/ 
    122188typedef void (*PuglReshapeFunc)(PuglView* view, int width, int height); 
     189 
     190/** 
     191   A function called on scrolling (e.g. mouse wheel or track pad). 
     192 
     193   The distances used here are in "lines", a single tick of a clicking mouse 
     194   wheel.  For example, @p dy = 1.0 scrolls 1 line up.  Some systems and 
     195   devices support finer resolution and/or higher values for fast scrolls, 
     196   so programs should handle any value gracefully. 
     197 
     198   @param view The view being scrolled. 
     199   @param dx The scroll x distance. 
     200   @param dx The scroll y distance. 
     201*/ 
    123202typedef void (*PuglScrollFunc)(PuglView* view, float dx, float dy); 
     203 
     204/** 
     205   A function called when a special key is pressed or released. 
     206 
     207   This callback allows the use of keys that do not have unicode points.  Note 
     208   that some non-printable keys  
     209   @param view The view the event occured in. 
     210   @param press True if the key was pressed, false if released. 
     211   @param key The key pressed. 
     212*/ 
    124213typedef void (*PuglSpecialFunc)(PuglView* view, bool press, PuglKey key); 
    125214 
     
    158247 
    159248/** 
    160    Get the currently active modifiers (PuglModifier flags). 
     249   Get the currently active modifiers (PuglMod flags). 
    161250 
    162251   This should only be called from an event handler. 
  • trunk/pugl/pugl_x11.c

    r15 r16  
    233233    case XK_End:       return PUGL_KEY_END; 
    234234    case XK_Insert:    return PUGL_KEY_INSERT; 
     235    case XK_Shift_L:   return PUGL_KEY_SHIFT_L; 
     236    case XK_Shift_R:   return PUGL_KEY_SHIFT_R; 
     237    case XK_Control_L: return PUGL_KEY_CTRL_L; 
     238    case XK_Control_R: return PUGL_KEY_CTRL_R; 
     239    case XK_Alt_L:     return PUGL_KEY_ALT_L; 
     240    case XK_Alt_R:     return PUGL_KEY_ALT_R; 
     241    case XK_Super_L:   return PUGL_KEY_SUPER_L; 
     242    case XK_Super_R:   return PUGL_KEY_SUPER_R; 
    235243    } 
    236244    return (PuglKey)0; 
     
    308316            setModifiers(view, event.xkey.state); 
    309317            if (view->keyboardFunc) { 
    310                 KeySym sym = XKeycodeToKeysym( 
    311                     view->impl->display, event.xkey.keycode, 0); 
    312                 PuglKey special = keySymToSpecial(sym); 
    313                 if (!special) { 
    314                     view->keyboardFunc(view, true, sym); 
     318                KeySym  sym; 
     319                char    str[5]; 
     320                int     n   = XLookupString(&event.xkey, str, 4, &sym, NULL); 
     321                PuglKey key = keySymToSpecial(sym); 
     322                if (!key) { 
     323                    if (n == 1) { 
     324                        view->keyboardFunc(view, true, str[0]); 
     325                    } else { 
     326                        fprintf(stderr, "warning: Unknown key %X\n", (int)sym); 
     327                    } 
    315328                } else if (view->specialFunc) { 
    316                     view->specialFunc(view, true, special); 
     329                    view->specialFunc(view, true, key); 
    317330                } 
    318331            } 
  • trunk/pugl_test.c

    r15 r16  
    2727static float yAngle = 0.0f; 
    2828static float dist   = 10.0f; 
    29  
    30 #define KEY_ESCAPE 27 
    3129 
    3230static void 
     
    9189    fprintf(stderr, "Key %c %s ", (char)key, press ? "down" : "up"); 
    9290    printModifiers(view); 
    93     if (key == 'q' || key == 'Q' || key == KEY_ESCAPE) { 
     91    if (key == 'q' || key == 'Q' || key == PUGL_CHAR_ESCAPE || 
     92        key == PUGL_CHAR_DELETE || key == PUGL_CHAR_BACKSPACE) { 
    9493        quit = 1; 
    9594    } 
Note: See TracChangeset for help on using the changeset viewer.