From 10d37a3f559e3c94101253227954ddc08d845f6a Mon Sep 17 00:00:00 2001 From: David Robillard Date: Mon, 30 Apr 2012 01:45:40 +0000 Subject: PuglWindow => PuglView. --- pugl/pugl.h | 46 +++++++++---------- pugl/pugl_internal.h | 38 ++++++++-------- pugl/pugl_osx.m | 106 +++++++++++++++++++++---------------------- pugl/pugl_win.cpp | 120 ++++++++++++++++++++++++------------------------- pugl/pugl_x11.c | 124 +++++++++++++++++++++++++-------------------------- 5 files changed, 217 insertions(+), 217 deletions(-) (limited to 'pugl') diff --git a/pugl/pugl.h b/pugl/pugl.h index da9eea4..8bc3f72 100644 --- a/pugl/pugl.h +++ b/pugl/pugl.h @@ -62,7 +62,7 @@ extern "C" { # include #endif -typedef struct PuglWindowImpl PuglWindow; +typedef struct PuglViewImpl PuglView; /** A native window handle. @@ -82,14 +82,14 @@ typedef enum { */ typedef void* PuglHandle; -typedef void (*PuglCloseFunc)(PuglWindow* win); -typedef void (*PuglDisplayFunc)(PuglWindow* win); -typedef void (*PuglKeyboardFunc)(PuglWindow* win, bool press, uint32_t key); -typedef void (*PuglMotionFunc)(PuglWindow* win, int x, int y); -typedef void (*PuglMouseFunc)(PuglWindow* win, - int button, bool down, int x, int y); -typedef void (*PuglReshapeFunc)(PuglWindow* win, int width, int height); -typedef void (*PuglScrollFunc)(PuglWindow* win, float dx, float dy); +typedef void (*PuglCloseFunc)(PuglView* view); +typedef void (*PuglDisplayFunc)(PuglView* view); +typedef void (*PuglKeyboardFunc)(PuglView* view, bool press, uint32_t key); +typedef void (*PuglMotionFunc)(PuglView* view, int x, int y); +typedef void (*PuglMouseFunc)(PuglView* view, int button, bool down, + int x, int y); +typedef void (*PuglReshapeFunc)(PuglView* view, int width, int height); +typedef void (*PuglScrollFunc)(PuglView* view, float dx, float dy); /** Create a new GL window. @@ -99,7 +99,7 @@ typedef void (*PuglScrollFunc)(PuglWindow* win, float dx, float dy); @param height Window height in pixels. @param resizable Whether window should be user resizable. */ -PUGL_API PuglWindow* +PUGL_API PuglView* puglCreate(PuglNativeWindow parent, const char* title, int width, @@ -116,61 +116,61 @@ puglCreate(PuglNativeWindow parent, non-trivial programs; this mistake is largely why Pugl exists. */ PUGL_API void -puglSetHandle(PuglWindow* window, PuglHandle handle); +puglSetHandle(PuglView* view, PuglHandle handle); /** Get the handle to be passed to all callbacks. */ PUGL_API PuglHandle -puglGetHandle(PuglWindow* window); +puglGetHandle(PuglView* view); /** Set the function to call when the window is closed. */ PUGL_API void -puglSetCloseFunc(PuglWindow* window, PuglCloseFunc closeFunc); +puglSetCloseFunc(PuglView* view, PuglCloseFunc closeFunc); /** Set the display function which should draw the UI using GL. */ PUGL_API void -puglSetDisplayFunc(PuglWindow* window, PuglDisplayFunc displayFunc); +puglSetDisplayFunc(PuglView* view, PuglDisplayFunc displayFunc); /** Set the function to call on keyboard events. */ PUGL_API void -puglSetKeyboardFunc(PuglWindow* window, PuglKeyboardFunc keyboardFunc); +puglSetKeyboardFunc(PuglView* view, PuglKeyboardFunc keyboardFunc); /** Set the function to call on mouse motion. */ PUGL_API void -puglSetMotionFunc(PuglWindow* window, PuglMotionFunc motionFunc); +puglSetMotionFunc(PuglView* view, PuglMotionFunc motionFunc); /** Set the function to call on mouse button events. */ PUGL_API void -puglSetMouseFunc(PuglWindow* window, PuglMouseFunc mouseFunc); +puglSetMouseFunc(PuglView* view, PuglMouseFunc mouseFunc); /** Set the function to call on scroll events. */ PUGL_API void -puglSetScrollFunc(PuglWindow* window, PuglScrollFunc scrollFunc); +puglSetScrollFunc(PuglView* view, PuglScrollFunc scrollFunc); /** Set the function to call when the window size changes. */ PUGL_API void -puglSetReshapeFunc(PuglWindow* window, PuglReshapeFunc reshapeFunc); +puglSetReshapeFunc(PuglView* view, PuglReshapeFunc reshapeFunc); /** Return the native window handle. */ PUGL_API PuglNativeWindow -puglGetNativeWindow(PuglWindow* win); +puglGetNativeWindow(PuglView* view); /** Process all pending window events. @@ -179,19 +179,19 @@ puglGetNativeWindow(PuglWindow* win); regularly and rapidly enough to keep the UI responsive. */ PUGL_API PuglStatus -puglProcessEvents(PuglWindow* win); +puglProcessEvents(PuglView* view); /** Request a redisplay on the next call to puglProcessEvents(). */ PUGL_API void -puglPostRedisplay(PuglWindow* win); +puglPostRedisplay(PuglView* view); /** Destroy a GL window. */ PUGL_API void -puglDestroy(PuglWindow* win); +puglDestroy(PuglView* view); #ifdef __cplusplus } /* extern "C" */ diff --git a/pugl/pugl_internal.h b/pugl/pugl_internal.h index 3685522..0b04e5d 100644 --- a/pugl/pugl_internal.h +++ b/pugl/pugl_internal.h @@ -27,7 +27,7 @@ typedef struct PuglPlatformDataImpl PuglPlatformData; -struct PuglWindowImpl { +struct PuglViewImpl { PuglHandle handle; PuglCloseFunc closeFunc; PuglDisplayFunc displayFunc; @@ -45,55 +45,55 @@ struct PuglWindowImpl { }; void -puglSetHandle(PuglWindow* window, PuglHandle handle) +puglSetHandle(PuglView* view, PuglHandle handle) { - window->handle = handle; + view->handle = handle; } PuglHandle -puglGetHandle(PuglWindow* window) +puglGetHandle(PuglView* view) { - return window->handle; + return view->handle; } void -puglSetCloseFunc(PuglWindow* window, PuglCloseFunc closeFunc) +puglSetCloseFunc(PuglView* view, PuglCloseFunc closeFunc) { - window->closeFunc = closeFunc; + view->closeFunc = closeFunc; } void -puglSetDisplayFunc(PuglWindow* window, PuglDisplayFunc displayFunc) +puglSetDisplayFunc(PuglView* view, PuglDisplayFunc displayFunc) { - window->displayFunc = displayFunc; + view->displayFunc = displayFunc; } void -puglSetKeyboardFunc(PuglWindow* window, PuglKeyboardFunc keyboardFunc) +puglSetKeyboardFunc(PuglView* view, PuglKeyboardFunc keyboardFunc) { - window->keyboardFunc = keyboardFunc; + view->keyboardFunc = keyboardFunc; } void -puglSetMotionFunc(PuglWindow* window, PuglMotionFunc motionFunc) +puglSetMotionFunc(PuglView* view, PuglMotionFunc motionFunc) { - window->motionFunc = motionFunc; + view->motionFunc = motionFunc; } void -puglSetMouseFunc(PuglWindow* window, PuglMouseFunc mouseFunc) +puglSetMouseFunc(PuglView* view, PuglMouseFunc mouseFunc) { - window->mouseFunc = mouseFunc; + view->mouseFunc = mouseFunc; } void -puglSetReshapeFunc(PuglWindow* window, PuglReshapeFunc reshapeFunc) +puglSetReshapeFunc(PuglView* view, PuglReshapeFunc reshapeFunc) { - window->reshapeFunc = reshapeFunc; + view->reshapeFunc = reshapeFunc; } void -puglSetScrollFunc(PuglWindow* window, PuglScrollFunc scrollFunc) +puglSetScrollFunc(PuglView* view, PuglScrollFunc scrollFunc) { - window->scrollFunc = scrollFunc; + view->scrollFunc = scrollFunc; } diff --git a/pugl/pugl_osx.m b/pugl/pugl_osx.m index 619e453..c3dc03b 100644 --- a/pugl/pugl_osx.m +++ b/pugl/pugl_osx.m @@ -25,7 +25,7 @@ int colorBits; int depthBits; @public - PuglWindow* win; + PuglView* view; } - (id) initWithFrame:(NSRect)frame @@ -87,9 +87,9 @@ int width = bounds.size.width; int height = bounds.size.height; - if (win->reshapeFunc) { + if (view->reshapeFunc) { // User provided a reshape function, defer to that - win->reshapeFunc(win, width, height); + view->reshapeFunc(view, width, height); } else { // No custom reshape function, do something reasonable glMatrixMode(GL_PROJECTION); @@ -101,9 +101,9 @@ glLoadIdentity(); } - win->width = width; - win->height = height; - win->redisplay = true; + view->width = width; + view->height = height; + view->redisplay = true; } - (void) drawRect:(NSRect)rect @@ -111,8 +111,8 @@ glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glLoadIdentity(); - if (self->win->displayFunc) { - self->win->displayFunc(self->win); + if (self->view->displayFunc) { + self->view->displayFunc(self->view); } glFlush(); @@ -122,63 +122,63 @@ - (void) mouseMoved:(NSEvent*)event { NSPoint loc = [event locationInWindow]; - if (win->motionFunc) { - win->motionFunc(win, loc.x, loc.y); + if (view->motionFunc) { + view->motionFunc(view, loc.x, loc.y); } } - (void) mouseDown:(NSEvent*)event { NSPoint loc = [event locationInWindow]; - if (win->mouseFunc) { - win->mouseFunc(win, 1, true, loc.x, loc.y); + if (view->mouseFunc) { + view->mouseFunc(view, 1, true, loc.x, loc.y); } } - (void) mouseUp:(NSEvent*)event { NSPoint loc = [event locationInWindow]; - if (win->mouseFunc) { - win->mouseFunc(win, 1, false, loc.x, loc.y); + if (view->mouseFunc) { + view->mouseFunc(view, 1, false, loc.x, loc.y); } } - (void) rightMouseDown:(NSEvent*)event { NSPoint loc = [event locationInWindow]; - if (win->mouseFunc) { - win->mouseFunc(win, 3, true, loc.x, loc.y); + if (view->mouseFunc) { + view->mouseFunc(view, 3, true, loc.x, loc.y); } } - (void) rightMouseUp:(NSEvent*)event { NSPoint loc = [event locationInWindow]; - if (win->mouseFunc) { - win->mouseFunc(win, 3, false, loc.x, loc.y); + if (view->mouseFunc) { + view->mouseFunc(view, 3, false, loc.x, loc.y); } } - (void) scrollWheel:(NSEvent*)event { - if (win->scrollFunc) { - win->scrollFunc(win, [event deltaX], [event deltaY]); + if (view->scrollFunc) { + view->scrollFunc(view, [event deltaX], [event deltaY]); } } - (void) keyDown:(NSEvent*)event { NSString* chars = [event characters];; - if (win->keyboardFunc) { - win->keyboardFunc(win, true, [chars characterAtIndex:0]); + if (view->keyboardFunc) { + view->keyboardFunc(view, true, [chars characterAtIndex:0]); } } - (void) keyUp:(NSEvent*)event { NSString* chars = [event characters];; - if (win->keyboardFunc) { - win->keyboardFunc(win, false, [chars characterAtIndex:0]); + if (view->keyboardFunc) { + view->keyboardFunc(view, false, [chars characterAtIndex:0]); } } @@ -197,13 +197,13 @@ puglCreate(PuglNativeWindow parent, int height, bool resizable) { - PuglWindow* win = (PuglWindow*)calloc(1, sizeof(PuglWindow)); - win->width = width; - win->height = height; + PuglView* view = (PuglWindow*)calloc(1, sizeof(PuglWindow)); + view->width = width; + view->height = height; - win->impl = (PuglPlatformData*)calloc(1, sizeof(PuglPlatformData)); + view->impl = (PuglPlatformData*)calloc(1, sizeof(PuglPlatformData)); - PuglPlatformData* impl = win->impl; + PuglPlatformData* impl = view->impl; [NSAutoreleasePool new]; [NSApplication sharedApplication]; @@ -225,67 +225,67 @@ puglCreate(PuglNativeWindow parent, [window setTitle:titleString]; [window setAcceptsMouseMovedEvents:YES]; - impl->view = [PuglOpenGLView new]; - impl->window = window; - impl->view->win = win; + impl->view = [PuglOpenGLView new]; + impl->window = window; + impl->view->view = view; [window setContentView:impl->view]; [NSApp activateIgnoringOtherApps:YES]; [window makeFirstResponder:impl->view]; - impl->session = [NSApp beginModalSessionForWindow:win->impl->window]; + impl->session = [NSApp beginModalSessionForWindow:view->impl->window]; - return win; + return view; } void -puglDestroy(PuglWindow* win) +puglDestroy(PuglView* view) { - [NSApp endModalSession:win->impl->session]; - [win->impl->view release]; - free(win->impl); - free(win); + [NSApp endModalSession:view->impl->session]; + [view->impl->view release]; + free(view->impl); + free(view); } void -puglDisplay(PuglWindow* win) +puglDisplay(PuglView* view) { glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glLoadIdentity(); - if (win->displayFunc) { - win->displayFunc(win); + if (view->displayFunc) { + view->displayFunc(view); } glFlush(); - win->redisplay = false; + view->redisplay = false; } PuglStatus -puglProcessEvents(PuglWindow* win) +puglProcessEvents(PuglView* view) { - NSInteger response = [NSApp runModalSession:win->impl->session]; + NSInteger response = [NSApp runModalSession:view->impl->session]; if (response != NSRunContinuesResponse) { - if (win->closeFunc) { - win->closeFunc(win); + if (view->closeFunc) { + view->closeFunc(view); } } - if (win->redisplay) { - puglDisplay(win); + if (view->redisplay) { + puglDisplay(view); } return PUGL_SUCCESS; } void -puglPostRedisplay(PuglWindow* win) +puglPostRedisplay(PuglView* view) { - win->redisplay = true; + view->redisplay = true; } PuglNativeWindow -puglGetNativeWindow(PuglWindow* win) +puglGetNativeWindow(PuglView* view) { - return (PuglNativeWindow)win->impl->view; + return (PuglNativeWindow)view->impl->view; } diff --git a/pugl/pugl_win.cpp b/pugl/pugl_win.cpp index a3354bf..f73d9da 100644 --- a/pugl/pugl_win.cpp +++ b/pugl/pugl_win.cpp @@ -55,11 +55,11 @@ puglCreate(PuglNativeWindow parent, int height, bool resizable) { - PuglWindow* win = (PuglWindow*)calloc(1, sizeof(PuglWindow)); + PuglView* view = (PuglWindow*)calloc(1, sizeof(PuglWindow)); - win->impl = (PuglPlatformData*)calloc(1, sizeof(PuglPlatformData)); + view->impl = (PuglPlatformData*)calloc(1, sizeof(PuglPlatformData)); - PuglPlatformData* impl = win->impl; + PuglPlatformData* impl = view->impl; WNDCLASS wc; wc.style = CS_OWNDC; @@ -97,158 +97,158 @@ puglCreate(PuglNativeWindow parent, impl->hglrc = wglCreateContext(impl->hdc); wglMakeCurrent(impl->hdc, impl->hglrc); - win->width = width; - win->height = height; + view->width = width; + view->height = height; - return win; + return view; } void -puglDestroy(PuglWindow* win) +puglDestroy(PuglView* view) { wglMakeCurrent(NULL, NULL); - wglDeleteContext(win->impl->hglrc); - ReleaseDC(win->impl->hwnd, win->impl->hdc); - DestroyWindow(win->impl->hwnd); - free(win); + wglDeleteContext(view->impl->hglrc); + ReleaseDC(view->impl->hwnd, view->impl->hdc); + DestroyWindow(view->impl->hwnd); + free(view); } void -puglReshape(PuglWindow* win, int width, int height) +puglReshape(PuglView* view, int width, int height) { - wglMakeCurrent(win->impl->hdc, win->impl->hglrc); + wglMakeCurrent(view->impl->hdc, view->impl->hglrc); - if (win->reshapeFunc) { + if (view->reshapeFunc) { // User provided a reshape function, defer to that - win->reshapeFunc(win, width, height); + view->reshapeFunc(view, width, height); } else { // No custom reshape function, do something reasonable glMatrixMode(GL_PROJECTION); glLoadIdentity(); - gluPerspective(45.0f, win->width/(float)win->height, 1.0f, 10.0f); - glViewport(0, 0, win->width, win->height); + gluPerspective(45.0f, view->width/(float)view->height, 1.0f, 10.0f); + glViewport(0, 0, view->width, view->height); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); } - win->width = width; - win->height = height; + view->width = width; + view->height = height; } void -puglDisplay(PuglWindow* win) +puglDisplay(PuglView* view) { - wglMakeCurrent(win->impl->hdc, win->impl->hglrc); + wglMakeCurrent(view->impl->hdc, view->impl->hglrc); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glLoadIdentity(); - if (win->displayFunc) { - win->displayFunc(win); + if (view->displayFunc) { + view->displayFunc(view); } glFlush(); - SwapBuffers(win->impl->hdc); - win->redisplay = false; + SwapBuffers(view->impl->hdc); + view->redisplay = false; } static void -processMouseEvent(PuglWindow* win, int button, bool press, LPARAM lParam) +processMouseEvent(PuglView* view, int button, bool press, LPARAM lParam) { - if (win->mouseFunc) { - win->mouseFunc(win, button, press, + if (view->mouseFunc) { + view->mouseFunc(view, button, press, GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam)); } } PuglStatus -puglProcessEvents(PuglWindow* win) +puglProcessEvents(PuglView* view) { MSG msg; PAINTSTRUCT ps; int button; bool down = true; - while (PeekMessage(&msg, /*win->impl->hwnd*/0, 0, 0, PM_REMOVE)) { + while (PeekMessage(&msg, /*view->impl->hwnd*/0, 0, 0, PM_REMOVE)) { switch (msg.message) { case WM_CREATE: case WM_SHOWWINDOW: case WM_SIZE: - puglReshape(win, win->width, win->height); + puglReshape(view, view->width, view->height); break; case WM_PAINT: - BeginPaint(win->impl->hwnd, &ps); - puglDisplay(win); - EndPaint(win->impl->hwnd, &ps); + BeginPaint(view->impl->hwnd, &ps); + puglDisplay(view); + EndPaint(view->impl->hwnd, &ps); break; case WM_MOUSEMOVE: - if (win->motionFunc) { - win->motionFunc( - win, GET_X_LPARAM(msg.lParam), GET_Y_LPARAM(msg.lParam)); + if (view->motionFunc) { + view->motionFunc( + view, GET_X_LPARAM(msg.lParam), GET_Y_LPARAM(msg.lParam)); } break; case WM_LBUTTONDOWN: - processMouseEvent(win, 1, true, msg.lParam); + processMouseEvent(view, 1, true, msg.lParam); break; case WM_MBUTTONDOWN: - processMouseEvent(win, 2, true, msg.lParam); + processMouseEvent(view, 2, true, msg.lParam); break; case WM_RBUTTONDOWN: - processMouseEvent(win, 3, true, msg.lParam); + processMouseEvent(view, 3, true, msg.lParam); break; case WM_LBUTTONUP: - processMouseEvent(win, 1, false, msg.lParam); + processMouseEvent(view, 1, false, msg.lParam); break; case WM_MBUTTONUP: - processMouseEvent(win, 2, false, msg.lParam); + processMouseEvent(view, 2, false, msg.lParam); break; case WM_RBUTTONUP: - processMouseEvent(win, 3, false, msg.lParam); + processMouseEvent(view, 3, false, msg.lParam); break; case WM_MOUSEWHEEL: - if (win->scrollFunc) { - win->scrollFunc( - win, 0, (int16_t)HIWORD(msg.wParam) / (float)WHEEL_DELTA); + if (view->scrollFunc) { + view->scrollFunc( + view, 0, (int16_t)HIWORD(msg.wParam) / (float)WHEEL_DELTA); } break; case WM_MOUSEHWHEEL: - if (win->scrollFunc) { - win->scrollFunc( - win, (int16_t)HIWORD(msg.wParam) / float(WHEEL_DELTA), 0); + if (view->scrollFunc) { + view->scrollFunc( + view, (int16_t)HIWORD(msg.wParam) / float(WHEEL_DELTA), 0); } break; case WM_KEYDOWN: case WM_KEYUP: - if (win->keyboardFunc) { - win->keyboardFunc(win, msg.message == WM_KEYDOWN, msg.wParam); + if (view->keyboardFunc) { + view->keyboardFunc(view, msg.message == WM_KEYDOWN, msg.wParam); } break; case WM_QUIT: - if (win->closeFunc) { - win->closeFunc(win); + if (view->closeFunc) { + view->closeFunc(view); } break; default: DefWindowProc( - win->impl->hwnd, msg.message, msg.wParam, msg.lParam); + view->impl->hwnd, msg.message, msg.wParam, msg.lParam); } } - if (win->redisplay) { - puglDisplay(win); + if (view->redisplay) { + puglDisplay(view); } return PUGL_SUCCESS; } void -puglPostRedisplay(PuglWindow* win) +puglPostRedisplay(PuglView* view) { - win->redisplay = true; + view->redisplay = true; } PuglNativeWindow -puglGetNativeWindow(PuglWindow* win) +puglGetNativeWindow(PuglView* view) { - return (PuglNativeWindow)win->impl->hwnd; + return (PuglNativeWindow)view->impl->hwnd; } diff --git a/pugl/pugl_x11.c b/pugl/pugl_x11.c index f4aa933..606f348 100644 --- a/pugl/pugl_x11.c +++ b/pugl/pugl_x11.c @@ -62,21 +62,21 @@ static int attrListDbl[] = { None }; -PuglWindow* +PuglView* puglCreate(PuglNativeWindow parent, const char* title, int width, int height, bool resizable) { - PuglWindow* win = (PuglWindow*)calloc(1, sizeof(PuglWindow)); + PuglView* view = (PuglView*)calloc(1, sizeof(PuglView)); - win->impl = (PuglPlatformData*)calloc(1, sizeof(PuglPlatformData)); + view->impl = (PuglPlatformData*)calloc(1, sizeof(PuglPlatformData)); - PuglPlatformData* impl = win->impl; + PuglPlatformData* impl = view->impl; - win->width = width; - win->height = height; + view->width = width; + view->height = height; impl->display = XOpenDisplay(0); impl->screen = DefaultScreen(impl->display); @@ -114,7 +114,7 @@ puglCreate(PuglNativeWindow parent, impl->win = XCreateWindow( impl->display, xParent, - 0, 0, win->width, win->height, 0, vi->depth, InputOutput, vi->visual, + 0, 0, view->width, view->height, 0, vi->depth, InputOutput, vi->visual, CWBorderPixel | CWColormap | CWEventMask, &attr); XSizeHints sizeHints; @@ -145,33 +145,33 @@ puglCreate(PuglNativeWindow parent, printf("no DRI available\n"); } - return win; + return view; } void -puglDestroy(PuglWindow* win) +puglDestroy(PuglView* view) { - if (win->impl->ctx) { - if (!glXMakeCurrent(win->impl->display, None, NULL)) { + if (view->impl->ctx) { + if (!glXMakeCurrent(view->impl->display, None, NULL)) { printf("Could not release drawing context.\n"); } /* destroy the context */ - glXDestroyContext(win->impl->display, win->impl->ctx); - win->impl->ctx = NULL; + glXDestroyContext(view->impl->display, view->impl->ctx); + view->impl->ctx = NULL; } - XCloseDisplay(win->impl->display); - free(win); + XCloseDisplay(view->impl->display); + free(view); } void -puglReshape(PuglWindow* win, int width, int height) +puglReshape(PuglView* view, int width, int height) { - glXMakeCurrent(win->impl->display, win->impl->win, win->impl->ctx); + glXMakeCurrent(view->impl->display, view->impl->win, view->impl->ctx); - if (win->reshapeFunc) { + if (view->reshapeFunc) { // User provided a reshape function, defer to that - win->reshapeFunc(win, width, height); + view->reshapeFunc(view, width, height); } else { // No custom reshape function, do something reasonable glMatrixMode(GL_PROJECTION); @@ -183,46 +183,46 @@ puglReshape(PuglWindow* win, int width, int height) glLoadIdentity(); } - win->width = width; - win->height = height; - win->redisplay = true; + view->width = width; + view->height = height; + view->redisplay = true; } void -puglDisplay(PuglWindow* win) +puglDisplay(PuglView* view) { - glXMakeCurrent(win->impl->display, win->impl->win, win->impl->ctx); + glXMakeCurrent(view->impl->display, view->impl->win, view->impl->ctx); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glLoadIdentity(); - if (win->displayFunc) { - win->displayFunc(win); + if (view->displayFunc) { + view->displayFunc(view); } glFlush(); - if (win->impl->doubleBuffered) { - glXSwapBuffers(win->impl->display, win->impl->win); + if (view->impl->doubleBuffered) { + glXSwapBuffers(view->impl->display, view->impl->win); } - win->redisplay = false; + view->redisplay = false; } PuglStatus -puglProcessEvents(PuglWindow* win) +puglProcessEvents(PuglView* view) { XEvent event; /* handle the events in the queue */ - while (XPending(win->impl->display) > 0) { - XNextEvent(win->impl->display, &event); + while (XPending(view->impl->display) > 0) { + XNextEvent(view->impl->display, &event); switch (event.type) { case MapNotify: - puglReshape(win, win->width, win->height); + puglReshape(view, view->width, view->height); break; case ConfigureNotify: - if ((event.xconfigure.width != win->width) || - (event.xconfigure.height != win->height)) { - puglReshape(win, + if ((event.xconfigure.width != view->width) || + (event.xconfigure.height != view->height)) { + puglReshape(view, event.xconfigure.width, event.xconfigure.height); } @@ -231,17 +231,17 @@ puglProcessEvents(PuglWindow* win) if (event.xexpose.count != 0) { break; } - puglDisplay(win); - win->redisplay = false; + puglDisplay(view); + view->redisplay = false; break; case MotionNotify: - if (win->motionFunc) { - win->motionFunc(win, event.xmotion.x, event.xmotion.y); + if (view->motionFunc) { + view->motionFunc(view, event.xmotion.x, event.xmotion.y); } break; case ButtonPress: if (event.xbutton.button >= 4 && event.xbutton.button <= 7) { - if (win->scrollFunc) { + if (view->scrollFunc) { float dx = 0, dy = 0; switch (event.xbutton.button) { case 4: dy = 1.0f; break; @@ -249,52 +249,52 @@ puglProcessEvents(PuglWindow* win) case 6: dx = -1.0f; break; case 7: dx = 1.0f; break; } - win->scrollFunc(win, dx, dy); + view->scrollFunc(view, dx, dy); } break; } // nobreak case ButtonRelease: - if (win->mouseFunc && + if (view->mouseFunc && (event.xbutton.button < 4 || event.xbutton.button > 7)) { - win->mouseFunc(win, + view->mouseFunc(view, event.xbutton.button, event.type == ButtonPress, event.xbutton.x, event.xbutton.y); } break; case KeyPress: - if (win->keyboardFunc) { + if (view->keyboardFunc) { KeySym sym = XKeycodeToKeysym( - win->impl->display, event.xkey.keycode, 0); - win->keyboardFunc(win, event.type == KeyPress, sym); + view->impl->display, event.xkey.keycode, 0); + view->keyboardFunc(view, event.type == KeyPress, sym); } break; case KeyRelease: { bool retriggered = false; - if (XEventsQueued(win->impl->display, QueuedAfterReading)) { + if (XEventsQueued(view->impl->display, QueuedAfterReading)) { XEvent next; - XPeekEvent(win->impl->display, &next); + XPeekEvent(view->impl->display, &next); if (next.type == KeyPress && next.xkey.time == event.xkey.time && next.xkey.keycode == event.xkey.keycode) { // Key repeat, ignore fake KeyPress event - XNextEvent(win->impl->display, &event); + XNextEvent(view->impl->display, &event); retriggered = true; } } - if (!retriggered && win->keyboardFunc) { + if (!retriggered && view->keyboardFunc) { KeySym sym = XKeycodeToKeysym( - win->impl->display, event.xkey.keycode, 0); - win->keyboardFunc(win, false, sym); + view->impl->display, event.xkey.keycode, 0); + view->keyboardFunc(view, false, sym); } } case ClientMessage: - if (!strcmp(XGetAtomName(win->impl->display, + if (!strcmp(XGetAtomName(view->impl->display, event.xclient.message_type), "WM_PROTOCOLS")) { - if (win->closeFunc) { - win->closeFunc(win); + if (view->closeFunc) { + view->closeFunc(view); } } break; @@ -303,21 +303,21 @@ puglProcessEvents(PuglWindow* win) } } - if (win->redisplay) { - puglDisplay(win); + if (view->redisplay) { + puglDisplay(view); } return PUGL_SUCCESS; } void -puglPostRedisplay(PuglWindow* win) +puglPostRedisplay(PuglView* view) { - win->redisplay = true; + view->redisplay = true; } PuglNativeWindow -puglGetNativeWindow(PuglWindow* win) +puglGetNativeWindow(PuglView* view) { - return win->impl->win; + return view->impl->win; } -- cgit v1.2.1