Changeset 16 in pugl
- Timestamp:
- 2012-04-30 00:21:38 (13 months ago)
- Location:
- trunk
- Files:
-
- 3 edited
-
pugl/pugl.h (modified) (6 diffs)
-
pugl/pugl_x11.c (modified) (2 diffs)
-
pugl_test.c (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/pugl/pugl.h
r15 r16 63 63 #endif 64 64 65 /** 66 An OpenGL view. 67 */ 65 68 typedef struct PuglViewImpl PuglView; 66 69 … … 74 77 typedef intptr_t PuglNativeWindow; 75 78 79 /** 80 Return status code. 81 */ 76 82 typedef enum { 77 83 PUGL_SUCCESS = 0 78 84 } PuglStatus; 79 85 86 /** 87 Convenience symbols for ASCII control characters. 88 */ 89 typedef 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 */ 80 98 typedef enum { 81 99 PUGL_KEY_F1 = 1, … … 99 117 PUGL_KEY_HOME, 100 118 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 102 128 } PuglKey; 103 129 130 /** 131 Keyboard modifier flags. 132 */ 104 133 typedef enum { 105 134 PUGL_MOD_SHIFT = 1, /**< Shift key */ … … 107 136 PUGL_MOD_ALT = 1 << 2, /**< Alt/Option key */ 108 137 PUGL_MOD_SUPER = 1 << 3, /**< Mod4/Command/Windows key */ 109 } PuglMod ifier;138 } PuglMod; 110 139 111 140 /** … … 114 143 typedef void* PuglHandle; 115 144 145 /** 146 A function called when the window is closed. 147 */ 116 148 typedef void (*PuglCloseFunc)(PuglView* view); 149 150 /** 151 A function called to draw the view contents with OpenGL. 152 */ 117 153 typedef 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 */ 118 161 typedef 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 */ 119 169 typedef 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 */ 179 typedef 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 */ 122 188 typedef 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 */ 123 202 typedef 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 */ 124 213 typedef void (*PuglSpecialFunc)(PuglView* view, bool press, PuglKey key); 125 214 … … 158 247 159 248 /** 160 Get the currently active modifiers (PuglMod ifierflags).249 Get the currently active modifiers (PuglMod flags). 161 250 162 251 This should only be called from an event handler. -
trunk/pugl/pugl_x11.c
r15 r16 233 233 case XK_End: return PUGL_KEY_END; 234 234 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; 235 243 } 236 244 return (PuglKey)0; … … 308 316 setModifiers(view, event.xkey.state); 309 317 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 } 315 328 } else if (view->specialFunc) { 316 view->specialFunc(view, true, special);329 view->specialFunc(view, true, key); 317 330 } 318 331 } -
trunk/pugl_test.c
r15 r16 27 27 static float yAngle = 0.0f; 28 28 static float dist = 10.0f; 29 30 #define KEY_ESCAPE 2731 29 32 30 static void … … 91 89 fprintf(stderr, "Key %c %s ", (char)key, press ? "down" : "up"); 92 90 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) { 94 93 quit = 1; 95 94 }
Note: See TracChangeset
for help on using the changeset viewer.
