Browse Source

Get file browser to work, including test

Signed-off-by: falkTX <falktx@falktx.com>
pull/272/head
falkTX 4 years ago
parent
commit
1425c28b2e
Signed by: falkTX <falktx@falktx.com> GPG Key ID: CDBAA37ABC74FBA0
2 changed files with 31 additions and 12 deletions
  1. +3
    -0
      dgl/src/ApplicationPrivateData.cpp
  2. +28
    -12
      tests/FileBrowserDialog.cpp

+ 3
- 0
dgl/src/ApplicationPrivateData.cpp View File

@@ -39,6 +39,9 @@ Application::PrivateData::PrivateData(const bool standalone)


puglSetWorldHandle(world, this); puglSetWorldHandle(world, this);
puglSetClassName(world, DISTRHO_MACRO_AS_STRING(DGL_NAMESPACE)); puglSetClassName(world, DISTRHO_MACRO_AS_STRING(DGL_NAMESPACE));
#ifdef HAVE_X11
sofdFileDialogSetup(world);
#endif
} }


Application::PrivateData::~PrivateData() Application::PrivateData::~PrivateData()


+ 28
- 12
tests/FileBrowserDialog.cpp View File

@@ -27,43 +27,44 @@ class NanoFilePicker : public NanoStandaloneWindow
Rectangle<uint> buttonBounds; Rectangle<uint> buttonBounds;
bool buttonClick = false; bool buttonClick = false;
bool buttonHover = false; bool buttonHover = false;
String selectedFile;


public: public:
NanoFilePicker(Application& app) NanoFilePicker(Application& app)
: NanoStandaloneWindow(app)
: NanoStandaloneWindow(app),
selectedFile("No file selected yet")
{ {
#ifndef DGL_NO_SHARED_RESOURCES #ifndef DGL_NO_SHARED_RESOURCES
loadSharedResources(); loadSharedResources();
#endif #endif

} }


protected: protected:
void onNanoDisplay() override 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 // Button background
beginPath(); 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()); rect(buttonBounds.getX(), buttonBounds.getY(), buttonBounds.getWidth(), buttonBounds.getHeight());
fill(); fill();
stroke(); stroke();
closePath(); closePath();


// Label
// Button label
beginPath(); beginPath();
fontSize(14); fontSize(14);
fillColor(labelColor);
Rectangle<float> buttonTextBounds; Rectangle<float> buttonTextBounds;
textBounds(0, 0, "Press me", NULL, buttonTextBounds); textBounds(0, 0, "Press me", NULL, buttonTextBounds);
textAlign(ALIGN_CENTER | ALIGN_MIDDLE); textAlign(ALIGN_CENTER | ALIGN_MIDDLE);

fillColor(255, 255, 255, 255); fillColor(255, 255, 255, 255);
text(buttonBounds.getX() + buttonBounds.getWidth()/2, text(buttonBounds.getX() + buttonBounds.getWidth()/2,
buttonBounds.getY() + buttonBounds.getHeight()/2, buttonBounds.getY() + buttonBounds.getHeight()/2,
@@ -110,6 +111,9 @@ protected:


if (newButtonClick) if (newButtonClick)
{ {
selectedFile = "(in progress)";
repaint();

FileBrowserOptions opts; FileBrowserOptions opts;
opts.title = "Look at me"; opts.title = "Look at me";
openFileBrowser(opts); openFileBrowser(opts);
@@ -128,6 +132,18 @@ protected:


buttonBounds = Rectangle<uint>(width - 120, height/2 - 20, 100, 40); buttonBounds = Rectangle<uint>(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();
}
}; };


// -------------------------------------------------------------------------------------------------------------------- // --------------------------------------------------------------------------------------------------------------------


Loading…
Cancel
Save