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.

168 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 UI;
  22. class UIExporter;
  23. END_NAMESPACE_DISTRHO
  24. #endif
  25. START_NAMESPACE_DGL
  26. // -----------------------------------------------------------------------
  27. class Application;
  28. class Widget;
  29. class StandaloneWindow;
  30. class Window
  31. {
  32. public:
  33. #ifndef DGL_FILE_BROWSER_DISABLED
  34. /**
  35. File browser options.
  36. */
  37. struct FileBrowserOptions {
  38. const char* startDir;
  39. const char* title;
  40. uint width;
  41. uint height;
  42. /**
  43. File browser buttons.
  44. 0 means hidden.
  45. 1 means visible and unchecked.
  46. 2 means visible and checked.
  47. */
  48. struct Buttons {
  49. uint listAllFiles;
  50. uint showHidden;
  51. uint showPlaces;
  52. /** Constuctor for default values */
  53. Buttons()
  54. : listAllFiles(2),
  55. showHidden(1),
  56. showPlaces(1) {}
  57. } buttons;
  58. /** Constuctor for default values */
  59. FileBrowserOptions()
  60. : startDir(nullptr),
  61. title(nullptr),
  62. width(0),
  63. height(0),
  64. buttons() {}
  65. };
  66. #endif // DGL_FILE_BROWSER_DISABLED
  67. explicit Window(Application& app);
  68. explicit Window(Application& app, Window& parent);
  69. explicit Window(Application& app, intptr_t parentId, double scaling, bool resizable);
  70. virtual ~Window();
  71. void show();
  72. void hide();
  73. void close();
  74. void exec(bool lockWait = false);
  75. void focus();
  76. void repaint() noexcept;
  77. #ifndef DGL_FILE_BROWSER_DISABLED
  78. bool openFileBrowser(const FileBrowserOptions& options);
  79. #endif
  80. bool isEmbed() const noexcept;
  81. bool isVisible() const noexcept;
  82. void setVisible(bool yesNo);
  83. bool isResizable() const noexcept;
  84. void setResizable(bool yesNo);
  85. uint getWidth() const noexcept;
  86. uint getHeight() const noexcept;
  87. Size<uint> getSize() const noexcept;
  88. void setSize(uint width, uint height);
  89. void setSize(Size<uint> size);
  90. const char* getTitle() const noexcept;
  91. void setTitle(const char* title);
  92. void setGeometryConstraints(uint width, uint height, bool aspect);
  93. void setTransientWinId(uintptr_t winId);
  94. double getScaling() const noexcept;
  95. bool getIgnoringKeyRepeat() const noexcept;
  96. void setIgnoringKeyRepeat(bool ignore) noexcept;
  97. Application& getApp() const noexcept;
  98. uintptr_t getWindowId() const noexcept;
  99. const GraphicsContext& getGraphicsContext() const noexcept;
  100. void addIdleCallback(IdleCallback* const callback);
  101. void removeIdleCallback(IdleCallback* const callback);
  102. protected:
  103. virtual void onDisplayBefore();
  104. virtual void onDisplayAfter();
  105. virtual void onReshape(uint width, uint height);
  106. virtual void onClose();
  107. #ifndef DGL_FILE_BROWSER_DISABLED
  108. virtual void fileBrowserSelected(const char* filename);
  109. #endif
  110. // internal
  111. void _setAutoScaling(double scaling) noexcept;
  112. private:
  113. struct PrivateData;
  114. PrivateData* const pData;
  115. friend class Application;
  116. friend class Widget;
  117. friend class StandaloneWindow;
  118. #ifdef DISTRHO_DEFINES_H_INCLUDED
  119. friend class DISTRHO_NAMESPACE::UI;
  120. friend class DISTRHO_NAMESPACE::UIExporter;
  121. #endif
  122. virtual void _addWidget(Widget* const widget);
  123. virtual void _removeWidget(Widget* const widget);
  124. void _idle();
  125. bool handlePluginKeyboard(const bool press, const uint key);
  126. bool handlePluginSpecial(const bool press, const Key key);
  127. DISTRHO_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(Window)
  128. };
  129. // -----------------------------------------------------------------------
  130. END_NAMESPACE_DGL
  131. #endif // DGL_WINDOW_HPP_INCLUDED