Browse Source

Continue pugl update

gh-pages
falkTX 10 years ago
parent
commit
8165b6063a
5 changed files with 61 additions and 35 deletions
  1. +4
    -1
      dgl/Makefile
  2. +0
    -16
      dgl/src/pugl/pugl_internal.h
  3. +18
    -2
      dgl/src/pugl/pugl_osx.m
  4. +39
    -14
      dgl/src/pugl/pugl_win.cpp
  5. +0
    -2
      dgl/src/pugl/pugl_x11.c

+ 4
- 1
dgl/Makefile View File

@@ -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 $@

# --------------------------------------------------------------


+ 0
- 16
dgl/src/pugl/pugl_internal.h View File

@@ -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)
{


+ 18
- 2
dgl/src/pugl/pugl_osx.m View File

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


+ 39
- 14
dgl/src/pugl/pugl_win.cpp View File

@@ -1,5 +1,5 @@
/*
Copyright 2012 David Robillard <http://drobilla.net>
Copyright 2012-2014 David Robillard <http://drobilla.net>

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)
{


+ 0
- 2
dgl/src/pugl/pugl_x11.c View File

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


Loading…
Cancel
Save