Browse Source

Update to latest pugl code

gh-pages
falkTX 11 years ago
parent
commit
a5b044c8d8
4 changed files with 52 additions and 41 deletions
  1. +10
    -6
      dgl/src/pugl/pugl.h
  2. +5
    -1
      dgl/src/pugl/pugl_osx.m
  3. +4
    -2
      dgl/src/pugl/pugl_win.cpp
  4. +33
    -32
      dgl/src/pugl/pugl_x11.c

+ 10
- 6
dgl/src/pugl/pugl.h View File

@@ -95,7 +95,7 @@ typedef enum {
PUGL_CHAR_ESCAPE = 0x1B, PUGL_CHAR_ESCAPE = 0x1B,
PUGL_CHAR_DELETE = 0x7F PUGL_CHAR_DELETE = 0x7F
} PuglChar; } PuglChar;
/** /**
Special (non-Unicode) keyboard keys. Special (non-Unicode) keyboard keys.
*/ */
@@ -131,12 +131,12 @@ typedef enum {
Keyboard modifier flags. Keyboard modifier flags.
*/ */
typedef enum { typedef enum {
PUGL_MOD_SHIFT = 1, /**< Shift key */
PUGL_MOD_SHIFT = 1, /**< Shift key */
PUGL_MOD_CTRL = 1 << 1, /**< Control key */ PUGL_MOD_CTRL = 1 << 1, /**< Control key */
PUGL_MOD_ALT = 1 << 2, /**< Alt/Option key */ PUGL_MOD_ALT = 1 << 2, /**< Alt/Option key */
PUGL_MOD_SUPER = 1 << 3 /**< Mod4/Command/Windows key */ PUGL_MOD_SUPER = 1 << 3 /**< Mod4/Command/Windows key */
} PuglMod; } PuglMod;
/** /**
Handle for opaque user data. Handle for opaque user data.
*/ */
@@ -199,13 +199,17 @@ typedef void (*PuglReshapeFunc)(PuglView* view, int width, int height);
@param dx The scroll x distance. @param dx The scroll x distance.
@param dx The scroll y distance. @param dx The scroll y distance.
*/ */
typedef void (*PuglScrollFunc)(PuglView* view, float dx, float dy);
typedef void (*PuglScrollFunc)(PuglView* view,
int x,
int y,
float dx,
float dy);


/** /**
A function called when a special key is pressed or released. A function called when a special key is pressed or released.


This callback allows the use of keys that do not have unicode points. Note
that some non-printable keys
This callback allows the use of keys that do not have unicode points.
@param view The view the event occured in. @param view The view the event occured in.
@param press True if the key was pressed, false if released. @param press True if the key was pressed, false if released.
@param key The key pressed. @param key The key pressed.


+ 5
- 1
dgl/src/pugl/pugl_osx.m View File

@@ -293,8 +293,11 @@ getModifiers(PuglView* view, NSEvent* ev)
- (void) scrollWheel:(NSEvent*)event - (void) scrollWheel:(NSEvent*)event
{ {
if (puglview->scrollFunc) { if (puglview->scrollFunc) {
NSPoint loc = [event locationInWindow];
puglview->mods = getModifiers(puglview, event); puglview->mods = getModifiers(puglview, event);
puglview->scrollFunc(puglview, [event deltaX], [event deltaY]);
puglview->scrollFunc(puglview,
loc.x, puglview->height - loc.y,
[event deltaX], [event deltaY]);
} }
[self updateTrackingAreas]; [self updateTrackingAreas];
} }
@@ -379,6 +382,7 @@ puglCreate(PuglNativeWindow parent,
[window setContentView:impl->glview]; [window setContentView:impl->glview];
[NSApp activateIgnoringOtherApps:YES]; [NSApp activateIgnoringOtherApps:YES];
[window makeFirstResponder:impl->glview]; [window makeFirstResponder:impl->glview];

[window makeKeyAndOrderFront:window]; [window makeKeyAndOrderFront:window];


if (! visible) { if (! visible) {


+ 4
- 2
dgl/src/pugl/pugl_win.cpp View File

@@ -293,13 +293,15 @@ handleMessage(PuglView* view, UINT message, WPARAM wParam, LPARAM lParam)
case WM_MOUSEWHEEL: case WM_MOUSEWHEEL:
if (view->scrollFunc) { if (view->scrollFunc) {
view->scrollFunc( view->scrollFunc(
view, 0, (int16_t)HIWORD(wParam) / (float)WHEEL_DELTA);
view, GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam),
(int16_t)HIWORD(wParam) / (float)WHEEL_DELTA);
} }
break; break;
case WM_MOUSEHWHEEL: case WM_MOUSEHWHEEL:
if (view->scrollFunc) { if (view->scrollFunc) {
view->scrollFunc( view->scrollFunc(
view, (int16_t)HIWORD(wParam) / float(WHEEL_DELTA), 0);
view, GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam),
(int16_t)HIWORD(wParam) / float(WHEEL_DELTA), 0);
} }
break; break;
case WM_KEYDOWN: case WM_KEYDOWN:


+ 33
- 32
dgl/src/pugl/pugl_x11.c View File

@@ -1,5 +1,5 @@
/* /*
Copyright 2012 David Robillard <http://drobilla.net>
Copyright 2012-2014 David Robillard <http://drobilla.net>
Copyright 2011-2012 Ben Loftis, Harrison Consoles Copyright 2011-2012 Ben Loftis, Harrison Consoles
Copyright 2013 Robin Gareus <robin@gareus.org> Copyright 2013 Robin Gareus <robin@gareus.org>


@@ -114,7 +114,7 @@ puglCreate(PuglNativeWindow parent,
int glxMajor, glxMinor; int glxMajor, glxMinor;
glXQueryVersion(impl->display, &glxMajor, &glxMinor); glXQueryVersion(impl->display, &glxMajor, &glxMinor);
#ifdef VERBOSE_PUGL #ifdef VERBOSE_PUGL
printf("puGL: GLX-Version : %d.%d\n", glxMajor, glxMinor);
printf("puGL: GLX-Version %d.%d\n", glxMajor, glxMinor);
#endif #endif


impl->ctx = glXCreateContext(impl->display, vi, 0, GL_TRUE); impl->ctx = glXCreateContext(impl->display, vi, 0, GL_TRUE);
@@ -295,6 +295,27 @@ setModifiers(PuglView* view, unsigned xstate, unsigned xtime)
view->mods |= (xstate & Mod4Mask) ? PUGL_MOD_SUPER : 0; view->mods |= (xstate & Mod4Mask) ? PUGL_MOD_SUPER : 0;
} }


static void
dispatchKey(PuglView* view, XEvent* event, bool press)
{
KeySym sym;
char str[5];
const int n = XLookupString(&event->xkey, str, 4, &sym, NULL);
if (n == 0) {
return;
} else if (n > 1) {
fprintf(stderr, "warning: Unsupported multi-byte key %X\n", (int)sym);
return;
}

const PuglKey special = keySymToSpecial(sym);
if (special && view->specialFunc) {
view->specialFunc(view, press, special);
} else if (!special && view->keyboardFunc) {
view->keyboardFunc(view, press, str[0]);
}
}

PuglStatus PuglStatus
puglProcessEvents(PuglView* view) puglProcessEvents(PuglView* view)
{ {
@@ -336,7 +357,9 @@ puglProcessEvents(PuglView* view)
case 6: dx = -1.0f; break; case 6: dx = -1.0f; break;
case 7: dx = 1.0f; break; case 7: dx = 1.0f; break;
} }
view->scrollFunc(view, dx, dy);
view->scrollFunc(view,
event.xbutton.x, event.xbutton.y,
dx, dy);
} }
break; break;
} }
@@ -350,25 +373,12 @@ puglProcessEvents(PuglView* view)
event.xbutton.x, event.xbutton.y); event.xbutton.x, event.xbutton.y);
} }
break; break;
case KeyPress: {
case KeyPress:
setModifiers(view, event.xkey.state, event.xkey.time); setModifiers(view, event.xkey.state, event.xkey.time);
KeySym sym;
char str[5];
int n = XLookupString(&event.xkey, str, 4, &sym, NULL);
PuglKey key = keySymToSpecial(sym);
if (!key && view->keyboardFunc) {
if (n == 1) {
view->keyboardFunc(view, true, str[0]);
} else {
fprintf(stderr, "warning: Unknown key %X\n", (int)sym);
}
} else if (view->specialFunc) {
view->specialFunc(view, true, key);
}
} break;
case KeyRelease: {
dispatchKey(view, &event, true);
break;
case KeyRelease:
setModifiers(view, event.xkey.state, event.xkey.time); setModifiers(view, event.xkey.state, event.xkey.time);
bool repeated = false;
if (view->ignoreKeyRepeat && if (view->ignoreKeyRepeat &&
XEventsQueued(view->impl->display, QueuedAfterReading)) { XEventsQueued(view->impl->display, QueuedAfterReading)) {
XEvent next; XEvent next;
@@ -377,20 +387,11 @@ puglProcessEvents(PuglView* view)
next.xkey.time == event.xkey.time && next.xkey.time == event.xkey.time &&
next.xkey.keycode == event.xkey.keycode) { next.xkey.keycode == event.xkey.keycode) {
XNextEvent(view->impl->display, &event); XNextEvent(view->impl->display, &event);
repeated = true;
}
}

if (!repeated && view->keyboardFunc) {
KeySym sym = XLookupKeysym(&event.xkey, 0);
PuglKey special = keySymToSpecial(sym);
if (!special) {
view->keyboardFunc(view, false, sym);
} else if (view->specialFunc) {
view->specialFunc(view, false, special);
break;
} }
} }
} break;
dispatchKey(view, &event, false);
break;
case ClientMessage: case ClientMessage:
if (!strcmp(XGetAtomName(view->impl->display, if (!strcmp(XGetAtomName(view->impl->display,
event.xclient.message_type), event.xclient.message_type),


Loading…
Cancel
Save