| @@ -22,8 +22,13 @@ OBJS = \ | |||
| src/ImageButton.cpp.o \ | |||
| src/ImageKnob.cpp.o \ | |||
| src/ImageSlider.cpp.o \ | |||
| src/Widget.cpp.o \ | |||
| src/Window.cpp.o | |||
| src/Widget.cpp.o | |||
| ifeq ($(MACOS),true) | |||
| OBJS += src/Window.mm.o | |||
| else | |||
| OBJS += src/Window.cpp.o | |||
| endif | |||
| # freetype-gl | |||
| # OBJS += \ | |||
| @@ -37,10 +42,6 @@ OBJS = \ | |||
| # src/freetype-gl/vertex-attribute.c.o \ | |||
| # src/freetype-gl/vertex-buffer.c.o | |||
| ifeq ($(MACOS),true) | |||
| OBJS += src/pugl/pugl_osx_extended.m.o | |||
| endif | |||
| TARGET = ../libdgl.a | |||
| # -------------------------------------------------------------- | |||
| @@ -74,6 +75,9 @@ all: $(TARGET) | |||
| %.m.o: %.m | |||
| $(CC) $< $(BUILD_C_FLAGS) -ObjC -c -o $@ | |||
| %.mm.o: %.mm | |||
| $(CXX) $< $(BUILD_CXX_FLAGS) -ObjC++ -c -o $@ | |||
| # -------------------------------------------------------------- | |||
| clean: | |||
| @@ -80,7 +80,8 @@ struct Window::PrivateData { | |||
| xDisplay(nullptr), | |||
| xWindow(0) | |||
| #elif defined(DISTRHO_OS_MAC) | |||
| fNeedsIdle(true) | |||
| fNeedsIdle(true), | |||
| xWindow(nullptr) | |||
| #else | |||
| _dummy('\0') | |||
| #endif | |||
| @@ -104,7 +105,8 @@ struct Window::PrivateData { | |||
| xDisplay(nullptr), | |||
| xWindow(0) | |||
| #elif defined(DISTRHO_OS_MAC) | |||
| fNeedsIdle(false) | |||
| fNeedsIdle(false), | |||
| xWindow(nullptr) | |||
| #else | |||
| _dummy('\0') | |||
| #endif | |||
| @@ -133,7 +135,8 @@ struct Window::PrivateData { | |||
| xDisplay(nullptr), | |||
| xWindow(0) | |||
| #elif defined(DISTRHO_OS_MAC) | |||
| fNeedsIdle(false) | |||
| fNeedsIdle(false), | |||
| xWindow(nullptr) | |||
| #else | |||
| _dummy('\0') | |||
| #endif | |||
| @@ -184,12 +187,14 @@ struct Window::PrivateData { | |||
| puglCreateWindow(fView, nullptr); | |||
| #if defined(DISTRHO_OS_WINDOWS) | |||
| PuglInternals* impl = fView->impl; | |||
| #if defined(DISTRHO_OS_WINDOWS) | |||
| hwnd = impl->hwnd; | |||
| DISTRHO_SAFE_ASSERT(hwnd != 0); | |||
| #elif defined(DISTRHO_OS_MAC) | |||
| xWindow = impl->window; | |||
| DISTRHO_SAFE_ASSERT(xWindow != nullptr); | |||
| #elif defined(DISTRHO_OS_LINUX) | |||
| PuglInternals* impl = fView->impl; | |||
| xDisplay = impl->display; | |||
| xWindow = impl->win; | |||
| DISTRHO_SAFE_ASSERT(xWindow != 0); | |||
| @@ -227,10 +232,12 @@ struct Window::PrivateData { | |||
| } | |||
| #if defined(DISTRHO_OS_WINDOWS) | |||
| hwnd = 0; | |||
| hwnd = 0; | |||
| #elif defined(DISTRHO_OS_MAC) | |||
| xWindow = nullptr; | |||
| #elif defined(DISTRHO_OS_LINUX) | |||
| xDisplay = nullptr; | |||
| xWindow = 0; | |||
| xDisplay = nullptr; | |||
| xWindow = 0; | |||
| #endif | |||
| DBG("Success!\n"); | |||
| @@ -281,7 +288,9 @@ struct Window::PrivateData { | |||
| SetActiveWindow(hwnd); | |||
| SetFocus(hwnd); | |||
| #elif defined(DISTRHO_OS_MAC) | |||
| puglImplFocus(fView); | |||
| // TODO | |||
| //[NSApp activateIgnoringOtherApps:YES]; | |||
| //[xWindow makeKeyAndOrderFront:xWindow]; | |||
| #elif defined(DISTRHO_OS_LINUX) | |||
| XRaiseWindow(xDisplay, xWindow); | |||
| XSetInputFocus(xDisplay, xWindow, RevertToPointerRoot, CurrentTime); | |||
| @@ -330,7 +339,10 @@ struct Window::PrivateData { | |||
| UpdateWindow(hwnd); | |||
| #elif defined(DISTRHO_OS_MAC) | |||
| puglImplSetVisible(fView, yesNo); | |||
| if (yesNo) | |||
| [xWindow setIsVisible:YES]; | |||
| else | |||
| [xWindow setIsVisible:NO]; | |||
| #elif defined(DISTRHO_OS_LINUX) | |||
| if (yesNo) | |||
| XMapRaised(xDisplay, xWindow); | |||
| @@ -429,7 +441,18 @@ struct Window::PrivateData { | |||
| if (! forced) | |||
| UpdateWindow(hwnd); | |||
| #elif defined(DISTRHO_OS_MAC) | |||
| puglImplSetSize(fView, width, height, forced); | |||
| [xWindow setContentSize:NSMakeSize(width, height)]; | |||
| # if 0 | |||
| NSRect frame = [xWindow frame]; | |||
| frame.origin.y -= height - frame.size.height; | |||
| frame.size.width = width; | |||
| frame.size.height = height+20; | |||
| //if (forced) | |||
| // [xWindow setFrame:frame]; | |||
| //else | |||
| [xWindow setFrame:frame display:YES animate:NO]; | |||
| # endif | |||
| #elif defined(DISTRHO_OS_LINUX) | |||
| XResizeWindow(xDisplay, xWindow, width, height); | |||
| @@ -465,7 +488,12 @@ struct Window::PrivateData { | |||
| #if defined(DISTRHO_OS_WINDOWS) | |||
| SetWindowTextA(hwnd, title); | |||
| #elif defined(DISTRHO_OS_MAC) | |||
| puglImplSetTitle(fView, title); | |||
| NSString* titleString = [[NSString alloc] | |||
| initWithBytes:title | |||
| length:strlen(title) | |||
| encoding:NSUTF8StringEncoding]; | |||
| [xWindow setTitle:titleString]; | |||
| #elif defined(DISTRHO_OS_LINUX) | |||
| XStoreName(xDisplay, xWindow, title); | |||
| #endif | |||
| @@ -522,7 +550,34 @@ struct Window::PrivateData { | |||
| #ifdef DISTRHO_OS_MAC | |||
| if (fNeedsIdle) | |||
| puglImplIdle(fView); | |||
| { | |||
| 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 = [xWindow | |||
| nextEventMatchingMask:eventMask | |||
| untilDate:[NSDate distantPast] | |||
| inMode:NSEventTrackingRunLoopMode | |||
| dequeue:YES]; | |||
| if (event == nil) | |||
| break; | |||
| [xWindow sendEvent: event]; | |||
| } | |||
| [pool release]; | |||
| } | |||
| #endif | |||
| if (fModal.enabled && fModal.parent != nullptr) | |||
| @@ -741,6 +796,7 @@ struct Window::PrivateData { | |||
| ::Window xWindow; | |||
| #elif defined(DISTRHO_OS_MAC) | |||
| bool fNeedsIdle; | |||
| id xWindow; | |||
| #else | |||
| char _dummy; | |||
| #endif | |||
| @@ -351,55 +351,64 @@ struct PuglInternalsImpl { | |||
| id window; | |||
| }; | |||
| PuglView* | |||
| puglCreate(PuglNativeWindow parent, | |||
| const char* title, | |||
| int width, | |||
| int height, | |||
| bool resizable, | |||
| bool visible) | |||
| { | |||
| PuglView* view = (PuglView*)calloc(1, sizeof(PuglView)); | |||
| PuglInternals* impl = (PuglInternals*)calloc(1, sizeof(PuglInternals)); | |||
| if (!view || !impl) { | |||
| return NULL; | |||
| } | |||
| PuglInternals* | |||
| puglInitInternals() | |||
| { | |||
| return (PuglInternals*)calloc(1, sizeof(PuglInternals)); | |||
| } | |||
| view->impl = impl; | |||
| view->width = width; | |||
| view->height = height; | |||
| int | |||
| puglCreateWindow(PuglView* view, const char* title) | |||
| { | |||
| PuglInternals* impl = view->impl; | |||
| [NSAutoreleasePool new]; | |||
| [NSApplication sharedApplication]; | |||
| NSString* titleString = [[NSString alloc] | |||
| initWithBytes:title | |||
| length:strlen(title) | |||
| encoding:NSUTF8StringEncoding]; | |||
| id window = [[PuglWindow new]retain]; | |||
| [window setPuglview:view]; | |||
| [window setTitle:titleString]; | |||
| if (title) { | |||
| NSString* titleString = [[NSString alloc] | |||
| initWithBytes:title | |||
| length:strlen(title) | |||
| encoding:NSUTF8StringEncoding]; | |||
| [window setTitle:titleString]; | |||
| } | |||
| impl->glview = [PuglOpenGLView new]; | |||
| impl->window = window; | |||
| impl->glview->puglview = view; | |||
| [window setContentView:impl->glview]; | |||
| [NSApp activateIgnoringOtherApps:YES]; | |||
| [window setContentView:impl->glview]; | |||
| [window makeFirstResponder:impl->glview]; | |||
| [window makeKeyAndOrderFront:window]; | |||
| if (! visible) { | |||
| [window setIsVisible:NO]; | |||
| } | |||
| // wait for first puglShowWindow | |||
| [window setIsVisible:NO]; | |||
| return view; | |||
| // TODO - handle view->parent and view->resizable | |||
| // unused | |||
| (void)parent; (void)resizable; | |||
| return 0; | |||
| } | |||
| void | |||
| puglShowWindow(PuglView* view) | |||
| { | |||
| id window = view->impl->window; | |||
| [window setIsVisible:YES]; | |||
| } | |||
| void | |||
| puglHideWindow(PuglView* view) | |||
| { | |||
| id window = view->impl->window; | |||
| [window setIsVisible:NO]; | |||
| } | |||
| void | |||
| @@ -1,38 +0,0 @@ | |||
| /* | |||
| Copyright 2012 David Robillard <http://drobilla.net> | |||
| Copyright 2013 Filipe Coelho <falktx@falktx.com> | |||
| Permission to use, copy, modify, and/or distribute this software for any | |||
| purpose with or without fee is hereby granted, provided that the above | |||
| copyright notice and this permission notice appear in all copies. | |||
| THIS SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES | |||
| WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF | |||
| MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR | |||
| ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | |||
| WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN | |||
| ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF | |||
| OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | |||
| */ | |||
| /** | |||
| @file pugl_osx_extended.h Extended OSX/Cocoa Pugl Implementation. | |||
| */ | |||
| #include <stdbool.h> | |||
| #include "pugl.h" | |||
| #ifdef __cplusplus | |||
| extern "C" { | |||
| #endif | |||
| void puglImplIdle(PuglView* view); | |||
| void puglImplFocus(PuglView* view); | |||
| void puglImplSetSize(PuglView* view, unsigned int width, unsigned int height, bool forced); | |||
| void puglImplSetTitle(PuglView* view, const char* title); | |||
| void puglImplSetVisible(PuglView* view, bool yesNo); | |||
| #ifdef __cplusplus | |||
| } /* extern "C" */ | |||
| #endif | |||
| @@ -1,104 +0,0 @@ | |||
| /* | |||
| Copyright 2012 David Robillard <http://drobilla.net> | |||
| Copyright 2013 Filipe Coelho <falktx@falktx.com> | |||
| Permission to use, copy, modify, and/or distribute this software for any | |||
| purpose with or without fee is hereby granted, provided that the above | |||
| copyright notice and this permission notice appear in all copies. | |||
| THIS SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES | |||
| WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF | |||
| MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR | |||
| ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | |||
| WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN | |||
| ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF | |||
| OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | |||
| */ | |||
| /** | |||
| @file pugl_osx_extended.m Extended OSX/Cocoa Pugl Implementation. | |||
| */ | |||
| #import "pugl_osx.m" | |||
| #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) | |||
| { | |||
| id window = view->impl->window; | |||
| // TODO | |||
| [NSApp activateIgnoringOtherApps:YES]; | |||
| [window makeKeyAndOrderFront:window]; | |||
| } | |||
| void puglImplSetSize(PuglView* view, unsigned int width, unsigned int height, bool forced) | |||
| { | |||
| id window = view->impl->window; | |||
| NSRect frame = [window frame]; | |||
| frame.origin.y -= height - frame.size.height; | |||
| frame.size.width = width; | |||
| frame.size.height = height+20; | |||
| // if (forced) { | |||
| // [window setFrame:frame]; | |||
| // } else { | |||
| [window setFrame:frame display:YES animate:NO]; | |||
| // } | |||
| // unused | |||
| return; (void)forced; | |||
| } | |||
| void puglImplSetTitle(PuglView* view, const char* title) | |||
| { | |||
| id window = view->impl->window; | |||
| NSString* titleString = [[NSString alloc] | |||
| initWithBytes:title | |||
| length:strlen(title) | |||
| encoding:NSUTF8StringEncoding]; | |||
| [window setTitle:titleString]; | |||
| } | |||
| void puglImplSetVisible(PuglView* view, bool yesNo) | |||
| { | |||
| id window = view->impl->window; | |||
| if (yesNo) | |||
| [window setIsVisible:YES]; | |||
| else | |||
| [window setIsVisible:NO]; | |||
| } | |||