From 8165b6063af7a1c8761acf9627858e7917f60fbb Mon Sep 17 00:00:00 2001 From: falkTX Date: Tue, 18 Nov 2014 00:14:08 +0000 Subject: [PATCH] Continue pugl update --- dgl/Makefile | 5 +++- dgl/src/pugl/pugl_internal.h | 16 ----------- dgl/src/pugl/pugl_osx.m | 20 ++++++++++++-- dgl/src/pugl/pugl_win.cpp | 53 ++++++++++++++++++++++++++---------- dgl/src/pugl/pugl_x11.c | 2 -- 5 files changed, 61 insertions(+), 35 deletions(-) diff --git a/dgl/Makefile b/dgl/Makefile index 443bcc68..4d1434f9 100644 --- a/dgl/Makefile +++ b/dgl/Makefile @@ -63,7 +63,10 @@ all: $(TARGET) %.cpp.o: %.cpp $(CXX) $< $(BUILD_CXX_FLAGS) -c -o $@ -%.mm.o: %.cpp +src/Window.cpp.o: src/Window.cpp src/pugl/* + $(CXX) $< $(BUILD_CXX_FLAGS) -c -o $@ + +src/Window.mm.o: src/Window.cpp src/pugl/* $(CXX) $< $(BUILD_CXX_FLAGS) -ObjC++ -c -o $@ # -------------------------------------------------------------- diff --git a/dgl/src/pugl/pugl_internal.h b/dgl/src/pugl/pugl_internal.h index 5b05c573..33fc303c 100644 --- a/dgl/src/pugl/pugl_internal.h +++ b/dgl/src/pugl/pugl_internal.h @@ -152,22 +152,6 @@ puglIgnoreKeyRepeat(PuglView* view, bool ignore) view->ignoreKeyRepeat = ignore; } -static void -puglDefaultReshape(PuglView* view, int width, int height) -{ - glMatrixMode(GL_PROJECTION); - glLoadIdentity(); - glOrtho(0, width, height, 0, 0, 1); - glViewport(0, 0, width, height); - - glMatrixMode(GL_MODELVIEW); - glLoadIdentity(); - return; - - // unused - (void)view; -} - void puglSetEventFunc(PuglView* view, PuglEventFunc eventFunc) { diff --git a/dgl/src/pugl/pugl_osx.m b/dgl/src/pugl/pugl_osx.m index 5fdcdc0b..f4d71295 100644 --- a/dgl/src/pugl/pugl_osx.m +++ b/dgl/src/pugl/pugl_osx.m @@ -36,6 +36,8 @@ defer:(BOOL)flag; - (void) setPuglview:(PuglView*)view; - (BOOL) windowShouldClose:(id)sender; +- (BOOL) canBecomeKeyWindow:(id)sender; +- (BOOL) canBecomeMainWindow:(id)sender; @end @implementation PuglWindow @@ -76,6 +78,22 @@ (void)sender; } +- (BOOL) canBecomeKeyWindow:(id)sender +{ + return YES; + + // unused + (void)sender; +} + +- (BOOL) canBecomeMainWindow:(id)sender +{ + return YES; + + // unused + (void)sender; +} + @end static void @@ -196,8 +214,6 @@ puglDisplay(PuglView* view) if (puglview->reshapeFunc) { puglview->reshapeFunc(puglview, width, height); - } else { - puglDefaultReshape(puglview, width, height); } puglview->width = width; diff --git a/dgl/src/pugl/pugl_win.cpp b/dgl/src/pugl/pugl_win.cpp index aee37a7e..8334bf6c 100644 --- a/dgl/src/pugl/pugl_win.cpp +++ b/dgl/src/pugl/pugl_win.cpp @@ -1,5 +1,5 @@ /* - Copyright 2012 David Robillard + Copyright 2012-2014 David Robillard Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted, provided that the above @@ -40,8 +40,6 @@ #define PUGL_LOCAL_CLOSE_MSG (WM_USER + 50) -HINSTANCE hInstance = NULL; - struct PuglInternalsImpl { HWND hwnd; HDC hdc; @@ -49,6 +47,8 @@ struct PuglInternalsImpl { WNDCLASS wc; }; +static HINSTANCE hInstance = NULL; + LRESULT CALLBACK wndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam); @@ -67,6 +67,27 @@ puglInitInternals() return (PuglInternals*)calloc(1, sizeof(PuglInternals)); } +void +puglEnterContext(PuglView* view) +{ +#ifdef PUGL_HAVE_GL + if (view->ctx_type == PUGL_GL) { + wglMakeCurrent(view->impl->hdc, view->impl->hglrc); + } +#endif +} + +void +puglLeaveContext(PuglView* view, bool flush) +{ +#ifdef PUGL_HAVE_GL + if (view->ctx_type == PUGL_GL && flush) { + glFlush(); + SwapBuffers(view->impl->hdc); + } +#endif +} + int puglCreateWindow(PuglView* view, const char* title) { @@ -80,8 +101,8 @@ puglCreateWindow(PuglView* view, const char* title) // Should class be a parameter? Does this make sense on other platforms? static int wc_count = 0; char classNameBuf[256]; - std::srand((std::time(NULL))); - _snprintf(classNameBuf, sizeof(classNameBuf), "%s_%d-%d\n", title, std::rand(), ++wc_count); + srand((time(NULL))); + _snprintf(classNameBuf, sizeof(classNameBuf), "%d-%d_%s\n", ++wc_count, rand(), title); impl->wc.style = CS_OWNDC; impl->wc.lpfnWndProc = wndProc; @@ -112,7 +133,7 @@ puglCreateWindow(PuglView* view, const char* title) (HWND)view->parent, NULL, hInstance, NULL); if (!impl->hwnd) { - UnregisterClass(impl->wc.lpszClassName, NULL); + UnregisterClass(impl->wc.lpszClassName, hInstance); free((void*)impl->wc.lpszClassName); free(impl); free(view); @@ -169,8 +190,8 @@ puglDestroy(PuglView* view) wglDeleteContext(view->impl->hglrc); ReleaseDC(view->impl->hwnd, view->impl->hdc); DestroyWindow(view->impl->hwnd); - UnregisterClass(view->impl->wc.lpszClassName, NULL); - free((void*)impl->wc.lpszClassName); + UnregisterClass(view->impl->wc.lpszClassName, hInstance); + free((void*)view->impl->wc.lpszClassName); free(view->impl); free(view); } @@ -178,12 +199,10 @@ puglDestroy(PuglView* view) static void puglReshape(PuglView* view, int width, int height) { - wglMakeCurrent(view->impl->hdc, view->impl->hglrc); + puglEnterContext(view); if (view->reshapeFunc) { view->reshapeFunc(view, width, height); - } else { - puglDefaultReshape(view, width, height); } view->width = width; @@ -193,14 +212,13 @@ puglReshape(PuglView* view, int width, int height) static void puglDisplay(PuglView* view) { - wglMakeCurrent(view->impl->hdc, view->impl->hglrc); + puglEnterContext(view); if (view->displayFunc) { view->displayFunc(view); } - glFlush(); - SwapBuffers(view->impl->hdc); + puglLeaveContext(view, true); view->redisplay = false; } @@ -290,6 +308,7 @@ handleMessage(PuglView* view, UINT message, WPARAM wParam, LPARAM lParam) break; case WM_MOUSEMOVE: if (view->motionFunc) { + view->event_timestamp_ms = GetMessageTime(); view->motionFunc(view, GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam)); } break; @@ -355,6 +374,12 @@ handleMessage(PuglView* view, UINT message, WPARAM wParam, LPARAM lParam) return 0; } +void +puglGrabFocus(PuglView* /*view*/) +{ + // TODO +} + PuglStatus puglProcessEvents(PuglView* view) { diff --git a/dgl/src/pugl/pugl_x11.c b/dgl/src/pugl/pugl_x11.c index 81e7db7d..1f4948ec 100644 --- a/dgl/src/pugl/pugl_x11.c +++ b/dgl/src/pugl/pugl_x11.c @@ -205,8 +205,6 @@ puglReshape(PuglView* view, int width, int height) if (view->reshapeFunc) { view->reshapeFunc(view, width, height); - } else { - puglDefaultReshape(view, width, height); } view->width = width;