DISTRHO Plugin Framework
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

166 lines
4.5KB

  1. /*
  2. * DISTRHO Plugin Framework (DPF)
  3. * Copyright (C) 2012-2019 Filipe Coelho <falktx@falktx.com>
  4. *
  5. * Permission to use, copy, modify, and/or distribute this software for any purpose with
  6. * or without fee is hereby granted, provided that the above copyright notice and this
  7. * permission notice appear in all copies.
  8. *
  9. * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD
  10. * TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN
  11. * NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
  12. * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER
  13. * IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
  14. * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  15. */
  16. #ifndef DGL_WINDOW_HPP_INCLUDED
  17. #define DGL_WINDOW_HPP_INCLUDED
  18. #include "Geometry.hpp"
  19. #ifdef DISTRHO_DEFINES_H_INCLUDED
  20. START_NAMESPACE_DISTRHO
  21. class UIExporter;
  22. END_NAMESPACE_DISTRHO
  23. #endif
  24. START_NAMESPACE_DGL
  25. // -----------------------------------------------------------------------
  26. class Application;
  27. class Widget;
  28. class StandaloneWindow;
  29. class Window
  30. {
  31. public:
  32. #ifndef DGL_FILE_BROWSER_DISABLED
  33. /**
  34. File browser options.
  35. */
  36. struct FileBrowserOptions {
  37. const char* startDir;
  38. const char* title;
  39. uint width;
  40. uint height;
  41. /**
  42. File browser buttons.
  43. 0 means hidden.
  44. 1 means visible and unchecked.
  45. 2 means visible and checked.
  46. */
  47. struct Buttons {
  48. uint listAllFiles;
  49. uint showHidden;
  50. uint showPlaces;
  51. /** Constuctor for default values */
  52. Buttons()
  53. : listAllFiles(2),
  54. showHidden(1),
  55. showPlaces(1) {}
  56. } buttons;
  57. /** Constuctor for default values */
  58. FileBrowserOptions()
  59. : startDir(nullptr),
  60. title(nullptr),
  61. width(0),
  62. height(0),
  63. buttons() {}
  64. };
  65. #endif // DGL_FILE_BROWSER_DISABLED
  66. explicit Window(Application& app);
  67. explicit Window(Application& app, Window& parent);
  68. explicit Window(Application& app, intptr_t parentId, double scaling, bool resizable);
  69. virtual ~Window();
  70. void show();
  71. void hide();
  72. void close();
  73. void exec(bool lockWait = false);
  74. void focus();
  75. void repaint() noexcept;
  76. #ifndef DGL_FILE_BROWSER_DISABLED
  77. bool openFileBrowser(const FileBrowserOptions& options);
  78. #endif
  79. bool isEmbed() const noexcept;
  80. bool isVisible() const noexcept;
  81. void setVisible(bool yesNo);
  82. bool isResizable() const noexcept;
  83. void setResizable(bool yesNo);
  84. uint getWidth() const noexcept;
  85. uint getHeight() const noexcept;
  86. Size<uint> getSize() const noexcept;
  87. void setSize(uint width, uint height);
  88. void setSize(Size<uint> size);
  89. const char* getTitle() const noexcept;
  90. void setTitle(const char* title);
  91. void setGeometryConstraints(uint width, uint height, bool aspect);
  92. void setTransientWinId(uintptr_t winId);
  93. double getScaling() const noexcept;
  94. bool getIgnoringKeyRepeat() const noexcept;
  95. void setIgnoringKeyRepeat(bool ignore) noexcept;
  96. Application& getApp() const noexcept;
  97. intptr_t getWindowId() const noexcept;
  98. const GraphicsContext& getGraphicsContext() const noexcept;
  99. void addIdleCallback(IdleCallback* const callback);
  100. void removeIdleCallback(IdleCallback* const callback);
  101. protected:
  102. virtual void onDisplayBefore();
  103. virtual void onDisplayAfter();
  104. virtual void onReshape(uint width, uint height);
  105. virtual void onClose();
  106. #ifndef DGL_FILE_BROWSER_DISABLED
  107. virtual void fileBrowserSelected(const char* filename);
  108. #endif
  109. // internal
  110. void _setAutoScaling(double scaling) noexcept;
  111. private:
  112. struct PrivateData;
  113. PrivateData* const pData;
  114. friend class Application;
  115. friend class Widget;
  116. friend class StandaloneWindow;
  117. #ifdef DISTRHO_DEFINES_H_INCLUDED
  118. friend class DISTRHO_NAMESPACE::UIExporter;
  119. #endif
  120. virtual void _addWidget(Widget* const widget);
  121. virtual void _removeWidget(Widget* const widget);
  122. void _idle();
  123. bool handlePluginKeyboard(const bool press, const uint key);
  124. bool handlePluginSpecial(const bool press, const Key key);
  125. DISTRHO_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(Window)
  126. };
  127. // -----------------------------------------------------------------------
  128. END_NAMESPACE_DGL
  129. #endif // DGL_WINDOW_HPP_INCLUDED