diff --git a/dgl/src/ApplicationPrivateData.cpp b/dgl/src/ApplicationPrivateData.cpp index 0a75af82..20a678f5 100644 --- a/dgl/src/ApplicationPrivateData.cpp +++ b/dgl/src/ApplicationPrivateData.cpp @@ -39,6 +39,9 @@ Application::PrivateData::PrivateData(const bool standalone) puglSetWorldHandle(world, this); puglSetClassName(world, DISTRHO_MACRO_AS_STRING(DGL_NAMESPACE)); +#ifdef HAVE_X11 + sofdFileDialogSetup(world); +#endif } Application::PrivateData::~PrivateData() diff --git a/tests/FileBrowserDialog.cpp b/tests/FileBrowserDialog.cpp index e3a15847..6191956e 100644 --- a/tests/FileBrowserDialog.cpp +++ b/tests/FileBrowserDialog.cpp @@ -27,43 +27,44 @@ class NanoFilePicker : public NanoStandaloneWindow Rectangle buttonBounds; bool buttonClick = false; bool buttonHover = false; + String selectedFile; public: NanoFilePicker(Application& app) - : NanoStandaloneWindow(app) + : NanoStandaloneWindow(app), + selectedFile("No file selected yet") { #ifndef DGL_NO_SHARED_RESOURCES loadSharedResources(); #endif - } protected: void onNanoDisplay() override { - Color labelColor(255, 255, 255); - Color backgroundColor(32, - buttonClick ? 128 : 32, - buttonHover ? 128 : 32); - Color borderColor; + // Selected file + beginPath(); + fontSize(14); + textAlign(ALIGN_LEFT | ALIGN_MIDDLE); + fillColor(255, 255, 255, 255); + text(20, getHeight()/2, selectedFile, NULL); + closePath(); // Button background beginPath(); - fillColor(backgroundColor); - strokeColor(borderColor); + fillColor(Color(32, buttonClick ? 128 : 32, buttonHover ? 128 : 32)); + strokeColor(Color()); rect(buttonBounds.getX(), buttonBounds.getY(), buttonBounds.getWidth(), buttonBounds.getHeight()); fill(); stroke(); closePath(); - // Label + // Button label beginPath(); fontSize(14); - fillColor(labelColor); Rectangle buttonTextBounds; textBounds(0, 0, "Press me", NULL, buttonTextBounds); textAlign(ALIGN_CENTER | ALIGN_MIDDLE); - fillColor(255, 255, 255, 255); text(buttonBounds.getX() + buttonBounds.getWidth()/2, buttonBounds.getY() + buttonBounds.getHeight()/2, @@ -110,6 +111,9 @@ protected: if (newButtonClick) { + selectedFile = "(in progress)"; + repaint(); + FileBrowserOptions opts; opts.title = "Look at me"; openFileBrowser(opts); @@ -128,6 +132,18 @@ protected: buttonBounds = Rectangle(width - 120, height/2 - 20, 100, 40); } + + void onFileSelected(const char* filename) override + { + if (filename == nullptr) + filename = "Cancelled"; + + if (selectedFile == filename) + return; + + selectedFile = filename; + repaint(); + } }; // --------------------------------------------------------------------------------------------------------------------