Signed-off-by: falkTX <falktx@falktx.com>pull/272/head
@@ -27,8 +27,11 @@ OBJS_common = \ | |||||
../build/dgl/Color.cpp.o \ | ../build/dgl/Color.cpp.o \ | ||||
../build/dgl/Geometry.cpp.o \ | ../build/dgl/Geometry.cpp.o \ | ||||
../build/dgl/ImageBase.cpp.o \ | ../build/dgl/ImageBase.cpp.o \ | ||||
../build/dgl/Resources.cpp.o \ | |||||
../build/dgl/Widget.cpp.o | |||||
../build/dgl/Resources.cpp.o\ | |||||
../build/dgl/StandaloneWindow.cpp.o \ | |||||
../build/dgl/Widget.cpp.o \ | |||||
../build/dgl/Window.cpp.o\ | |||||
../build/dgl/WindowFileBrowser.cpp.o | |||||
# TODO: ImageWidgets.cpp | # TODO: ImageWidgets.cpp | ||||
@@ -36,13 +39,14 @@ OBJS_common = \ | |||||
OBJS_cairo = $(OBJS_common) \ | OBJS_cairo = $(OBJS_common) \ | ||||
../build/dgl/Cairo.cpp.cairo.o \ | ../build/dgl/Cairo.cpp.cairo.o \ | ||||
../build/dgl/WidgetPrivateData.cpp.cairo.o | |||||
../build/dgl/WidgetPrivateData.cpp.cairo.o \ | |||||
../build/dgl/WindowPrivateData.cpp.cairo.o | |||||
ifeq ($(MACOS),true) | |||||
OBJS_cairo += ../build/dgl/Window.mm.cairo.o | |||||
else | |||||
OBJS_cairo += ../build/dgl/Window.cpp.cairo.o | |||||
endif | |||||
# ifeq ($(MACOS),true) | |||||
# OBJS_cairo += ../build/dgl/Window.mm.cairo.o | |||||
# else | |||||
# OBJS_cairo += ../build/dgl/Window.cpp.cairo.o | |||||
# endif | |||||
# --------------------------------------------------------------------------------------------------------------------- | # --------------------------------------------------------------------------------------------------------------------- | ||||
@@ -51,13 +55,14 @@ OBJS_opengl = $(OBJS_common) \ | |||||
../build/dgl/Image.cpp.opengl.o \ | ../build/dgl/Image.cpp.opengl.o \ | ||||
../build/dgl/ImageWidgets.cpp.opengl.o \ | ../build/dgl/ImageWidgets.cpp.opengl.o \ | ||||
../build/dgl/NanoVG.cpp.opengl.o \ | ../build/dgl/NanoVG.cpp.opengl.o \ | ||||
../build/dgl/WidgetPrivateData.cpp.opengl.o | |||||
../build/dgl/WidgetPrivateData.cpp.opengl.o \ | |||||
../build/dgl/WindowPrivateData.cpp.opengl.o | |||||
ifeq ($(MACOS),true) | |||||
OBJS_opengl += ../build/dgl/Window.mm.opengl.o | |||||
else | |||||
OBJS_opengl += ../build/dgl/Window.cpp.opengl.o | |||||
endif | |||||
# ifeq ($(MACOS),true) | |||||
# OBJS_opengl += ../build/dgl/Window.mm.opengl.o | |||||
# else | |||||
# OBJS_opengl += ../build/dgl/Window.cpp.opengl.o | |||||
# endif | |||||
# --------------------------------------------------------------------------------------------------------------------- | # --------------------------------------------------------------------------------------------------------------------- | ||||
@@ -118,7 +118,7 @@ public: | |||||
void setIgnoringKeyRepeat(bool ignore) noexcept; | void setIgnoringKeyRepeat(bool ignore) noexcept; | ||||
Application& getApp() const noexcept; | Application& getApp() const noexcept; | ||||
intptr_t getWindowId() const noexcept; | |||||
uintptr_t getWindowId() const noexcept; | |||||
const GraphicsContext& getGraphicsContext() const noexcept; | const GraphicsContext& getGraphicsContext() const noexcept; | ||||
@@ -0,0 +1,64 @@ | |||||
/* | |||||
* DISTRHO Plugin Framework (DPF) | |||||
* Copyright (C) 2012-2020 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. | |||||
* | |||||
* THE 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. | |||||
*/ | |||||
#include "../StandaloneWindow.hpp" | |||||
#include "WidgetPrivateData.hpp" | |||||
START_NAMESPACE_DGL | |||||
// ----------------------------------------------------------------------- | |||||
StandaloneWindow::StandaloneWindow() | |||||
: Application(true), | |||||
Window((Application&)*this), | |||||
fWidget(nullptr) {} | |||||
void StandaloneWindow::exec() | |||||
{ | |||||
Window::show(); | |||||
Application::exec(); | |||||
} | |||||
void StandaloneWindow::onReshape(uint width, uint height) | |||||
{ | |||||
if (fWidget != nullptr) | |||||
fWidget->setSize(width, height); | |||||
Window::onReshape(width, height); | |||||
} | |||||
void StandaloneWindow::_addWidget(Widget* widget) | |||||
{ | |||||
if (fWidget == nullptr) | |||||
{ | |||||
fWidget = widget; | |||||
fWidget->pData->needsFullViewport = true; | |||||
} | |||||
Window::_addWidget(widget); | |||||
} | |||||
void StandaloneWindow::_removeWidget(Widget* widget) | |||||
{ | |||||
if (fWidget == widget) | |||||
{ | |||||
fWidget->pData->needsFullViewport = false; | |||||
fWidget = nullptr; | |||||
} | |||||
Window::_removeWidget(widget); | |||||
} | |||||
// ----------------------------------------------------------------------- | |||||
END_NAMESPACE_DGL |
@@ -0,0 +1,223 @@ | |||||
/* | |||||
* DISTRHO Plugin Framework (DPF) | |||||
* Copyright (C) 2012-2020 Filipe Coelho <falktx@falktx.com> | |||||
* Copyright (C) 2019 Jean Pierre Cimalando <jp-dev@inbox.ru> | |||||
* Copyright (C) 2019 Robin Gareus <robin@gareus.org> | |||||
* | |||||
* 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. | |||||
* | |||||
* THE 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. | |||||
*/ | |||||
#include "../StandaloneWindow.hpp" | |||||
// static int fib_filter_filename_filter(const char* const name) | |||||
// { | |||||
// return 1; | |||||
// (void)name; | |||||
// } | |||||
// TODO use DGL_NAMESPACE for class names | |||||
#ifdef DISTRHO_OS_MAC | |||||
@interface FilePanelDelegate : NSObject | |||||
{ | |||||
void (*fCallback)(NSOpenPanel*, int, void*); | |||||
void* fUserData; | |||||
} | |||||
-(id)initWithCallback:(void(*)(NSOpenPanel*, int, void*))callback userData:(void*)userData; | |||||
-(void)openPanelDidEnd:(NSOpenPanel *)sheet returnCode:(int)returnCode contextInfo:(void *)contextInfo; | |||||
@end | |||||
@implementation FilePanelDelegate | |||||
-(id)initWithCallback:(void(*)(NSOpenPanel*, int, void*))callback userData:(void *)userData | |||||
{ | |||||
[super init]; | |||||
self->fCallback = callback; | |||||
self->fUserData = userData; | |||||
return self; | |||||
} | |||||
-(void)openPanelDidEnd:(NSOpenPanel *)sheet returnCode:(int)returnCode contextInfo:(void *)contextInfo | |||||
{ | |||||
self->fCallback(sheet, returnCode, self->fUserData); | |||||
(void)contextInfo; | |||||
} | |||||
@end | |||||
#endif | |||||
START_NAMESPACE_DGL | |||||
// ----------------------------------------------------------------------- | |||||
bool Window::openFileBrowser(const FileBrowserOptions& options) | |||||
{ | |||||
#if defined(DISTRHO_OS_WINDOWS) | |||||
// the old and compatible dialog API | |||||
OPENFILENAMEW ofn; | |||||
memset(&ofn, 0, sizeof(ofn)); | |||||
ofn.lStructSize = sizeof(ofn); | |||||
ofn.hwndOwner = pData->hwnd; | |||||
// set initial directory in UTF-16 coding | |||||
std::vector<WCHAR> startDirW; | |||||
if (options.startDir) | |||||
{ | |||||
startDirW.resize(strlen(options.startDir) + 1); | |||||
if (MultiByteToWideChar(CP_UTF8, 0, options.startDir, -1, startDirW.data(), startDirW.size())) | |||||
ofn.lpstrInitialDir = startDirW.data(); | |||||
} | |||||
// set title in UTF-16 coding | |||||
std::vector<WCHAR> titleW; | |||||
if (options.title) | |||||
{ | |||||
titleW.resize(strlen(options.title) + 1); | |||||
if (MultiByteToWideChar(CP_UTF8, 0, options.title, -1, titleW.data(), titleW.size())) | |||||
ofn.lpstrTitle = titleW.data(); | |||||
} | |||||
// prepare a buffer to receive the result | |||||
std::vector<WCHAR> fileNameW(32768); // the Unicode maximum | |||||
ofn.lpstrFile = fileNameW.data(); | |||||
ofn.nMaxFile = (DWORD)fileNameW.size(); | |||||
// TODO synchronous only, can't do better with WinAPI native dialogs. | |||||
// threading might work, if someone is motivated to risk it. | |||||
if (GetOpenFileNameW(&ofn)) | |||||
{ | |||||
// back to UTF-8 | |||||
std::vector<char> fileNameA(4 * 32768); | |||||
if (WideCharToMultiByte(CP_UTF8, 0, fileNameW.data(), -1, fileNameA.data(), (int)fileNameA.size(), nullptr, nullptr)) | |||||
{ | |||||
// handle it during the next idle cycle (fake async) | |||||
pData->fSelectedFile = fileNameA.data(); | |||||
} | |||||
} | |||||
return true; | |||||
#elif defined(DISTRHO_OS_MAC) | |||||
if (pData->fOpenFilePanel) // permit one dialog at most | |||||
{ | |||||
[pData->fOpenFilePanel makeKeyAndOrderFront:nil]; | |||||
return false; | |||||
} | |||||
NSOpenPanel* panel = [NSOpenPanel openPanel]; | |||||
pData->fOpenFilePanel = [panel retain]; | |||||
[panel setCanChooseFiles:YES]; | |||||
[panel setCanChooseDirectories:NO]; | |||||
[panel setAllowsMultipleSelection:NO]; | |||||
if (options.startDir) | |||||
[panel setDirectory:[NSString stringWithUTF8String:options.startDir]]; | |||||
if (options.title) | |||||
{ | |||||
NSString* titleString = [[NSString alloc] | |||||
initWithBytes:options.title | |||||
length:strlen(options.title) | |||||
encoding:NSUTF8StringEncoding]; | |||||
[panel setTitle:titleString]; | |||||
} | |||||
id delegate = pData->fFilePanelDelegate; | |||||
if (!delegate) | |||||
{ | |||||
delegate = [[FilePanelDelegate alloc] initWithCallback:&PrivateData::openPanelDidEnd | |||||
userData:pData]; | |||||
pData->fFilePanelDelegate = [delegate retain]; | |||||
} | |||||
[panel beginSheetForDirectory:nullptr | |||||
file:nullptr | |||||
modalForWindow:nullptr | |||||
modalDelegate:delegate | |||||
didEndSelector:@selector(openPanelDidEnd:returnCode:contextInfo:) | |||||
contextInfo:nullptr]; | |||||
return true; | |||||
#elif defined(SOFD_HAVE_X11) | |||||
using DISTRHO_NAMESPACE::String; | |||||
// -------------------------------------------------------------------------- | |||||
// configure start dir | |||||
// TODO: get abspath if needed | |||||
// TODO: cross-platform | |||||
String startDir(options.startDir); | |||||
# ifdef DISTRHO_OS_LINUX | |||||
if (startDir.isEmpty()) | |||||
{ | |||||
if (char* const dir_name = get_current_dir_name()) | |||||
{ | |||||
startDir = dir_name; | |||||
std::free(dir_name); | |||||
} | |||||
} | |||||
# endif | |||||
DISTRHO_SAFE_ASSERT_RETURN(startDir.isNotEmpty(), false); | |||||
if (! startDir.endsWith('/')) | |||||
startDir += "/"; | |||||
DISTRHO_SAFE_ASSERT_RETURN(x_fib_configure(0, startDir) == 0, false); | |||||
// -------------------------------------------------------------------------- | |||||
// configure title | |||||
String title(options.title); | |||||
if (title.isEmpty()) | |||||
{ | |||||
title = pData->getTitle(); | |||||
if (title.isEmpty()) | |||||
title = "FileBrowser"; | |||||
} | |||||
DISTRHO_SAFE_ASSERT_RETURN(x_fib_configure(1, title) == 0, false); | |||||
// -------------------------------------------------------------------------- | |||||
// configure filters | |||||
x_fib_cfg_filter_callback(nullptr); //fib_filter_filename_filter); | |||||
// -------------------------------------------------------------------------- | |||||
// configure buttons | |||||
x_fib_cfg_buttons(3, options.buttons.listAllFiles-1); | |||||
x_fib_cfg_buttons(1, options.buttons.showHidden-1); | |||||
x_fib_cfg_buttons(2, options.buttons.showPlaces-1); | |||||
// -------------------------------------------------------------------------- | |||||
// show | |||||
return (x_fib_show(pData->xDisplay, pData->xWindow, /*options.width*/0, /*options.height*/0) == 0); | |||||
#else | |||||
// not implemented | |||||
return false; | |||||
// unused | |||||
(void)options; | |||||
#endif | |||||
} | |||||
// ----------------------------------------------------------------------- | |||||
END_NAMESPACE_DGL |
@@ -0,0 +1,83 @@ | |||||
/* | |||||
* DISTRHO Plugin Framework (DPF) | |||||
* Copyright (C) 2012-2020 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. | |||||
* | |||||
* THE 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. | |||||
*/ | |||||
#include "WindowPrivateData.hpp" | |||||
#ifdef DGL_CAIRO | |||||
# define PUGL_CAIRO | |||||
# include "../Cairo.hpp" | |||||
#endif | |||||
#ifdef DGL_OPENGL | |||||
# define PUGL_OPENGL | |||||
# include "../OpenGL.hpp" | |||||
#endif | |||||
extern "C" { | |||||
#include "pugl-upstream/pugl/detail/implementation.c" | |||||
} | |||||
#if defined(DISTRHO_OS_HAIKU) | |||||
# define DGL_DEBUG_EVENTS | |||||
# include "pugl-upstream/pugl/detail/haiku.cpp" | |||||
#elif defined(DISTRHO_OS_MAC) | |||||
# define PuglWindow DISTRHO_JOIN_MACRO(PuglWindow, DGL_NAMESPACE) | |||||
# define PuglOpenGLView DISTRHO_JOIN_MACRO(PuglOpenGLView, DGL_NAMESPACE) | |||||
# include "pugl-upstream/pugl/detail/mac.m" | |||||
#elif defined(DISTRHO_OS_WINDOWS) | |||||
# include "ppugl-upstream/pugl/detail/win.c" | |||||
# undef max | |||||
# undef min | |||||
#else | |||||
# include <sys/types.h> | |||||
# include <unistd.h> | |||||
extern "C" { | |||||
# include "pugl-upstream/pugl/detail/x11.c" | |||||
} | |||||
#endif | |||||
START_NAMESPACE_DGL | |||||
// ----------------------------------------------------------------------- | |||||
void DGL::Window::PrivateData::Fallback::onDisplayBefore() | |||||
{ | |||||
#ifdef DGL_OPENGL | |||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); | |||||
glLoadIdentity(); | |||||
#endif | |||||
} | |||||
void DGL::Window::PrivateData::Fallback::onDisplayAfter() | |||||
{ | |||||
} | |||||
void DGL::Window::PrivateData::Fallback::onReshape(const uint width, const uint height) | |||||
{ | |||||
#ifdef DGL_OPENGL | |||||
glEnable(GL_BLEND); | |||||
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); | |||||
glMatrixMode(GL_PROJECTION); | |||||
glLoadIdentity(); | |||||
glOrtho(0.0, static_cast<GLdouble>(width), static_cast<GLdouble>(height), 0.0, 0.0, 1.0); | |||||
glViewport(0, 0, static_cast<GLsizei>(width), static_cast<GLsizei>(height)); | |||||
glMatrixMode(GL_MODELVIEW); | |||||
glLoadIdentity(); | |||||
#endif | |||||
} | |||||
// ----------------------------------------------------------------------- | |||||
END_NAMESPACE_DGL |