Browse Source

Update DGL

tags/2018-04-16
falkTX 11 years ago
parent
commit
c05ee5c2c9
4 changed files with 68 additions and 51 deletions
  1. +14
    -6
      libs/dgl/src/Window.cpp
  2. +20
    -45
      libs/dgl/src/pugl/pugl_osx.m
  3. +1
    -0
      libs/dgl/src/pugl/pugl_osx_extended.h
  4. +33
    -0
      libs/dgl/src/pugl/pugl_osx_extended.m

+ 14
- 6
libs/dgl/src/Window.cpp View File

@@ -80,6 +80,8 @@ public:
#elif defined(DGL_OS_LINUX) #elif defined(DGL_OS_LINUX)
xDisplay(nullptr), xDisplay(nullptr),
xWindow(0) xWindow(0)
#elif defined(DGL_OS_MAC)
fNeedsIdle(true)
#else #else
_dummy('\0') _dummy('\0')
#endif #endif
@@ -102,6 +104,8 @@ public:
#elif defined(DGL_OS_LINUX) #elif defined(DGL_OS_LINUX)
xDisplay(nullptr), xDisplay(nullptr),
xWindow(0) xWindow(0)
#elif defined(DGL_OS_MAC)
fNeedsIdle(false)
#else #else
_dummy('\0') _dummy('\0')
#endif #endif
@@ -129,6 +133,8 @@ public:
#elif defined(DGL_OS_LINUX) #elif defined(DGL_OS_LINUX)
xDisplay(nullptr), xDisplay(nullptr),
xWindow(0) xWindow(0)
#elif defined(DGL_OS_MAC)
fNeedsIdle(false)
#else #else
_dummy('\0') _dummy('\0')
#endif #endif
@@ -241,12 +247,7 @@ public:
{ {
for (; fVisible && fModal.enabled;) for (; fVisible && fModal.enabled;)
{ {
// idle()
puglProcessEvents(fView);

if (fModal.parent != nullptr)
fModal.parent->idle();

idle();
msleep(10); msleep(10);
} }


@@ -492,6 +493,11 @@ public:
{ {
puglProcessEvents(fView); puglProcessEvents(fView);


#ifdef DGL_OS_MAC
if (fNeedsIdle)
puglImplIdle(fView);
#endif

if (fModal.enabled && fModal.parent != nullptr) if (fModal.enabled && fModal.parent != nullptr)
fModal.parent->idle(); fModal.parent->idle();
} }
@@ -713,6 +719,8 @@ private:
#elif defined(DGL_OS_LINUX) #elif defined(DGL_OS_LINUX)
Display* xDisplay; Display* xDisplay;
::Window xWindow; ::Window xWindow;
#elif defined(DGL_OS_MAC)
bool fNeedsIdle;
#else #else
char _dummy; char _dummy;
#endif #endif


+ 20
- 45
libs/dgl/src/pugl/pugl_osx.m View File

@@ -36,7 +36,6 @@
defer:(BOOL)flag; defer:(BOOL)flag;
- (void) setPuglview:(PuglView*)view; - (void) setPuglview:(PuglView*)view;
- (BOOL) windowShouldClose:(id)sender; - (BOOL) windowShouldClose:(id)sender;
- (BOOL) canBecomeKeyWindow:(id)sender;
@end @end


@implementation PuglWindow @implementation PuglWindow
@@ -56,12 +55,15 @@
[result setLevel: CGShieldingWindowLevel() + 1]; [result setLevel: CGShieldingWindowLevel() + 1];


return result; return result;

// unused
(void)aStyle; (void)bufferingType; (void)flag;
} }


- (void)setPuglview:(PuglView*)view - (void)setPuglview:(PuglView*)view
{ {
puglview = view; puglview = view;
[self setContentSize:NSMakeSize(view->width, view->height) ];
[self setContentSize:NSMakeSize(view->width, view->height)];
} }


- (BOOL)windowShouldClose:(id)sender - (BOOL)windowShouldClose:(id)sender
@@ -69,16 +71,14 @@
if (puglview->closeFunc) if (puglview->closeFunc)
puglview->closeFunc(puglview); puglview->closeFunc(puglview);
return YES; return YES;
}


- (BOOL) canBecomeKeyWindow:(id)sender
{
return NO;
// unused
(void)sender;
} }


@end @end


void
static void
puglDisplay(PuglView* view) puglDisplay(PuglView* view)
{ {
if (view->displayFunc) { if (view->displayFunc) {
@@ -182,6 +182,9 @@ puglDisplay(PuglView* view)
puglDisplay(puglview); puglDisplay(puglview);
glFlush(); glFlush();
glSwapAPPLE(); glSwapAPPLE();

// unused
return; (void)rect;
} }


static unsigned static unsigned
@@ -191,10 +194,6 @@ getModifiers(PuglView* view, NSEvent* ev)


view->event_timestamp_ms = fmod([ev timestamp] * 1000.0, UINT32_MAX); view->event_timestamp_ms = fmod([ev timestamp] * 1000.0, UINT32_MAX);


double ts = [ev timestamp] * 1000.0;
ts = (uint32)ts % 500000; //ridiculously large vals won't fit
view->event_timestamp_ms = ts;

unsigned mods = 0; unsigned mods = 0;
mods |= (modifierFlags & NSShiftKeyMask) ? PUGL_MOD_SHIFT : 0; mods |= (modifierFlags & NSShiftKeyMask) ? PUGL_MOD_SHIFT : 0;
mods |= (modifierFlags & NSControlKeyMask) ? PUGL_MOD_CTRL : 0; mods |= (modifierFlags & NSControlKeyMask) ? PUGL_MOD_CTRL : 0;
@@ -223,10 +222,15 @@ getModifiers(PuglView* view, NSEvent* ev)
- (void)mouseEntered:(NSEvent*)theEvent - (void)mouseEntered:(NSEvent*)theEvent
{ {
[self updateTrackingAreas]; [self updateTrackingAreas];

// unused
return; (void)theEvent;
} }


- (void)mouseExited:(NSEvent*)theEvent - (void)mouseExited:(NSEvent*)theEvent
{ {
// unused
return; (void)theEvent;
} }


- (void) mouseMoved:(NSEvent*)event - (void) mouseMoved:(NSEvent*)event
@@ -345,7 +349,6 @@ getModifiers(PuglView* view, NSEvent* ev)
struct PuglInternalsImpl { struct PuglInternalsImpl {
PuglOpenGLView* glview; PuglOpenGLView* glview;
id window; id window;
bool isEmbed;
}; };


PuglView* PuglView*
@@ -379,9 +382,8 @@ puglCreate(PuglNativeWindow parent,
[window setPuglview:view]; [window setPuglview:view];
[window setTitle:titleString]; [window setTitle:titleString];


impl->glview = [PuglOpenGLView new];
impl->window = window;
impl->isEmbed = (parent != 0);
impl->glview = [PuglOpenGLView new];
impl->window = window;
impl->glview->puglview = view; impl->glview->puglview = view;


[window setContentView:impl->glview]; [window setContentView:impl->glview];
@@ -395,6 +397,9 @@ puglCreate(PuglNativeWindow parent,
} }


return view; return view;

// unused
(void)parent; (void)resizable;
} }


void void
@@ -411,36 +416,6 @@ puglDestroy(PuglView* view)
PuglStatus PuglStatus
puglProcessEvents(PuglView* view) puglProcessEvents(PuglView* view)
{ {
if (! view->impl->isEmbed)
{
NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init];
NSEvent* event;

static const NSUInteger eventMask = (NSLeftMouseDownMask | NSLeftMouseUpMask |
NSRightMouseDownMask | NSRightMouseUpMask |
NSMouseMovedMask |
NSLeftMouseDraggedMask | NSRightMouseDraggedMask |
NSMouseEnteredMask | NSMouseExitedMask |
NSKeyDownMask | NSKeyUpMask |
NSFlagsChangedMask |
NSCursorUpdateMask | NSScrollWheelMask);

for (;;) {
event = [view->impl->window
nextEventMatchingMask:eventMask
untilDate:[NSDate distantPast]
inMode:NSEventTrackingRunLoopMode
dequeue:YES];

if (event == nil)
break;

[view->impl->window sendEvent: event];
}

[pool release];
}

[view->impl->glview setNeedsDisplay: YES]; [view->impl->glview setNeedsDisplay: YES];


return PUGL_SUCCESS; return PUGL_SUCCESS;


+ 1
- 0
libs/dgl/src/pugl/pugl_osx_extended.h View File

@@ -27,6 +27,7 @@
extern "C" { extern "C" {
#endif #endif


void puglImplIdle(PuglView* view);
void puglImplFocus(PuglView* view); void puglImplFocus(PuglView* view);
void puglImplSetSize(PuglView* view, unsigned int width, unsigned int height, bool forced); void puglImplSetSize(PuglView* view, unsigned int width, unsigned int height, bool forced);
void puglImplSetTitle(PuglView* view, const char* title); void puglImplSetTitle(PuglView* view, const char* title);


+ 33
- 0
libs/dgl/src/pugl/pugl_osx_extended.m View File

@@ -23,6 +23,36 @@


#include "pugl_osx_extended.h" #include "pugl_osx_extended.h"


void puglImplIdle(PuglView* view)
{
NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init];
NSEvent* event;

static const NSUInteger eventMask = (NSLeftMouseDownMask | NSLeftMouseUpMask |
NSRightMouseDownMask | NSRightMouseUpMask |
NSMouseMovedMask |
NSLeftMouseDraggedMask | NSRightMouseDraggedMask |
NSMouseEnteredMask | NSMouseExitedMask |
NSKeyDownMask | NSKeyUpMask |
NSFlagsChangedMask |
NSCursorUpdateMask | NSScrollWheelMask);

for (;;) {
event = [view->impl->window
nextEventMatchingMask:eventMask
untilDate:[NSDate distantPast]
inMode:NSEventTrackingRunLoopMode
dequeue:YES];

if (event == nil)
break;

[view->impl->window sendEvent: event];
}

[pool release];
}

void puglImplFocus(PuglView* view) void puglImplFocus(PuglView* view)
{ {
id window = view->impl->window; id window = view->impl->window;
@@ -46,6 +76,9 @@ void puglImplSetSize(PuglView* view, unsigned int width, unsigned int height, bo
// } else { // } else {
[window setFrame:frame display:YES animate:NO]; [window setFrame:frame display:YES animate:NO];
// } // }

// unused
return; (void)forced;
} }


void puglImplSetTitle(PuglView* view, const char* title) void puglImplSetTitle(PuglView* view, const char* title)


Loading…
Cancel
Save