Browse Source

Update to latest pugl code

gh-pages
falkTX 10 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_DELETE = 0x7F
} PuglChar;
/**
Special (non-Unicode) keyboard keys.
*/
@@ -131,12 +131,12 @@ typedef enum {
Keyboard modifier flags.
*/
typedef enum {
PUGL_MOD_SHIFT = 1, /**< Shift key */
PUGL_MOD_SHIFT = 1, /**< Shift key */
PUGL_MOD_CTRL = 1 << 1, /**< Control key */
PUGL_MOD_ALT = 1 << 2, /**< Alt/Option key */
PUGL_MOD_SUPER = 1 << 3 /**< Mod4/Command/Windows key */
} PuglMod;
/**
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 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.

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 press True if the key was pressed, false if released.
@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
{
if (puglview->scrollFunc) {
NSPoint loc = [event locationInWindow];
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];
}
@@ -379,6 +382,7 @@ puglCreate(PuglNativeWindow parent,
[window setContentView:impl->glview];
[NSApp activateIgnoringOtherApps:YES];
[window makeFirstResponder:impl->glview];

[window makeKeyAndOrderFront:window];

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:
if (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;
case WM_MOUSEHWHEEL:
if (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;
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 2013 Robin Gareus <robin@gareus.org>

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

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

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
puglProcessEvents(PuglView* view)
{
@@ -336,7 +357,9 @@ puglProcessEvents(PuglView* view)
case 6: 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;
}
@@ -350,25 +373,12 @@ puglProcessEvents(PuglView* view)
event.xbutton.x, event.xbutton.y);
}
break;
case KeyPress: {
case KeyPress:
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);
bool repeated = false;
if (view->ignoreKeyRepeat &&
XEventsQueued(view->impl->display, QueuedAfterReading)) {
XEvent next;
@@ -377,20 +387,11 @@ puglProcessEvents(PuglView* view)
next.xkey.time == event.xkey.time &&
next.xkey.keycode == event.xkey.keycode) {
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:
if (!strcmp(XGetAtomName(view->impl->display,
event.xclient.message_type),


Loading…
Cancel
Save