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