DISTRHO Plugin Framework
ImageWidgets.hpp
1 /*
2  * DISTRHO Plugin Framework (DPF)
3  * Copyright (C) 2012-2016 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_IMAGE_WIDGETS_HPP_INCLUDED
18 #define DGL_IMAGE_WIDGETS_HPP_INCLUDED
19 
20 #include "Image.hpp"
21 #include "Widget.hpp"
22 #include "Window.hpp"
23 
24 START_NAMESPACE_DGL
25 
26 // -----------------------------------------------------------------------
27 
28 class ImageAboutWindow : public Window,
29  public Widget
30 {
31 public:
32  explicit ImageAboutWindow(Window& parent, const Image& image = Image());
33  explicit ImageAboutWindow(Widget* widget, const Image& image = Image());
34 
35  void setImage(const Image& image);
36 
37 protected:
38  void onDisplay() override;
39  bool onKeyboard(const KeyboardEvent&) override;
40  bool onMouse(const MouseEvent&) override;
41  void onReshape(uint width, uint height) override;
42 
43 private:
44  Image fImgBackground;
45 
46  DISTRHO_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(ImageAboutWindow)
47 };
48 
49 // -----------------------------------------------------------------------
50 
51 class ImageButton : public Widget
52 {
53 public:
54  class Callback
55  {
56  public:
57  virtual ~Callback() {}
58  virtual void imageButtonClicked(ImageButton* imageButton, int button) = 0;
59  };
60 
61  explicit ImageButton(Window& parent, const Image& image);
62  explicit ImageButton(Window& parent, const Image& imageNormal, const Image& imageDown);
63  explicit ImageButton(Window& parent, const Image& imageNormal, const Image& imageHover, const Image& imageDown);
64 
65  explicit ImageButton(Widget* widget, const Image& image);
66  explicit ImageButton(Widget* widget, const Image& imageNormal, const Image& imageDown);
67  explicit ImageButton(Widget* widget, const Image& imageNormal, const Image& imageHover, const Image& imageDown);
68 
69  ~ImageButton() override;
70 
71  void setCallback(Callback* callback) noexcept;
72 
73 protected:
74  void onDisplay() override;
75  bool onMouse(const MouseEvent&) override;
76  bool onMotion(const MotionEvent&) override;
77 
78 private:
79  struct PrivateData;
80  PrivateData* const pData;
81 
82  DISTRHO_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(ImageButton)
83 };
84 
85 // -----------------------------------------------------------------------
86 
87 class ImageKnob : public Widget
88 {
89 public:
90  enum Orientation {
91  Horizontal,
92  Vertical
93  };
94 
95  class Callback
96  {
97  public:
98  virtual ~Callback() {}
99  virtual void imageKnobDragStarted(ImageKnob* imageKnob) = 0;
100  virtual void imageKnobDragFinished(ImageKnob* imageKnob) = 0;
101  virtual void imageKnobValueChanged(ImageKnob* imageKnob, float value) = 0;
102  };
103 
104  explicit ImageKnob(Window& parent, const Image& image, Orientation orientation = Vertical) noexcept;
105  explicit ImageKnob(Widget* widget, const Image& image, Orientation orientation = Vertical) noexcept;
106  explicit ImageKnob(const ImageKnob& imageKnob);
107  ImageKnob& operator=(const ImageKnob& imageKnob);
108  ~ImageKnob() override;
109 
110  float getValue() const noexcept;
111 
112  void setDefault(float def) noexcept;
113  void setRange(float min, float max) noexcept;
114  void setStep(float step) noexcept;
115  void setValue(float value, bool sendCallback = false) noexcept;
116  void setUsingLogScale(bool yesNo) noexcept;
117 
118  void setCallback(Callback* callback) noexcept;
119  void setOrientation(Orientation orientation) noexcept;
120  void setRotationAngle(int angle);
121 
122  void setImageLayerCount(uint count) noexcept;
123 
124 protected:
125  void onDisplay() override;
126  bool onMouse(const MouseEvent&) override;
127  bool onMotion(const MotionEvent&) override;
128  bool onScroll(const ScrollEvent&) override;
129 
130 private:
131  Image fImage;
132  float fMinimum;
133  float fMaximum;
134  float fStep;
135  float fValue;
136  float fValueDef;
137  float fValueTmp;
138  bool fUsingDefault;
139  bool fUsingLog;
140  Orientation fOrientation;
141 
142  int fRotationAngle;
143  bool fDragging;
144  int fLastX;
145  int fLastY;
146 
147  Callback* fCallback;
148 
149  bool fIsImgVertical;
150  uint fImgLayerWidth;
151  uint fImgLayerHeight;
152  uint fImgLayerCount;
153  bool fIsReady;
154  GLuint fTextureId;
155 
156  float _logscale(float value) const;
157  float _invlogscale(float value) const;
158 
159  DISTRHO_LEAK_DETECTOR(ImageKnob)
160 };
161 
162 // -----------------------------------------------------------------------
163 
164 // note set range and step before setting the value
165 
166 class ImageSlider : public Widget
167 {
168 public:
169  class Callback
170  {
171  public:
172  virtual ~Callback() {}
173  virtual void imageSliderDragStarted(ImageSlider* imageSlider) = 0;
174  virtual void imageSliderDragFinished(ImageSlider* imageSlider) = 0;
175  virtual void imageSliderValueChanged(ImageSlider* imageSlider, float value) = 0;
176  };
177 
178  explicit ImageSlider(Window& parent, const Image& image) noexcept;
179  explicit ImageSlider(Widget* widget, const Image& image) noexcept;
180 
181  float getValue() const noexcept;
182  void setValue(float value, bool sendCallback = false) noexcept;
183  void setDefault(float def) noexcept;
184 
185  void setStartPos(const Point<int>& startPos) noexcept;
186  void setStartPos(int x, int y) noexcept;
187  void setEndPos(const Point<int>& endPos) noexcept;
188  void setEndPos(int x, int y) noexcept;
189 
190  void setInverted(bool inverted) noexcept;
191  void setRange(float min, float max) noexcept;
192  void setStep(float step) noexcept;
193 
194  void setCallback(Callback* callback) noexcept;
195 
196 protected:
197  void onDisplay() override;
198  bool onMouse(const MouseEvent&) override;
199  bool onMotion(const MotionEvent&) override;
200 
201 private:
202  Image fImage;
203  float fMinimum;
204  float fMaximum;
205  float fStep;
206  float fValue;
207  float fValueDef;
208  float fValueTmp;
209  bool fUsingDefault;
210 
211  bool fDragging;
212  bool fInverted;
213  bool fValueIsSet;
214  int fStartedX;
215  int fStartedY;
216 
217  Callback* fCallback;
218 
219  Point<int> fStartPos;
220  Point<int> fEndPos;
221  Rectangle<int> fSliderArea;
222 
223  void _recheckArea() noexcept;
224 
225  // these should not be used
226  void setAbsoluteX(int) const noexcept {}
227  void setAbsoluteY(int) const noexcept {}
228  void setAbsolutePos(int, int) const noexcept {}
229  void setAbsolutePos(const Point<int>&) const noexcept {}
230 
231  DISTRHO_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(ImageSlider)
232 };
233 
234 // -----------------------------------------------------------------------
235 
236 class ImageSwitch : public Widget
237 {
238 public:
239  class Callback
240  {
241  public:
242  virtual ~Callback() {}
243  virtual void imageSwitchClicked(ImageSwitch* imageSwitch, bool down) = 0;
244  };
245 
246  explicit ImageSwitch(Window& parent, const Image& imageNormal, const Image& imageDown) noexcept;
247  explicit ImageSwitch(Widget* widget, const Image& imageNormal, const Image& imageDown) noexcept;
248  explicit ImageSwitch(const ImageSwitch& imageSwitch) noexcept;
249  ImageSwitch& operator=(const ImageSwitch& imageSwitch) noexcept;
250 
251  bool isDown() const noexcept;
252  void setDown(bool down) noexcept;
253 
254  void setCallback(Callback* callback) noexcept;
255 
256 protected:
257  void onDisplay() override;
258  bool onMouse(const MouseEvent&) override;
259 
260 private:
261  Image fImageNormal;
262  Image fImageDown;
263  bool fIsDown;
264 
265  Callback* fCallback;
266 
267  DISTRHO_LEAK_DETECTOR(ImageSwitch)
268 };
269 
270 // -----------------------------------------------------------------------
271 
272 END_NAMESPACE_DGL
273 
274 #endif // DGL_IMAGE_WIDGETS_HPP_INCLUDED
Definition: ImageWidgets.hpp:28
virtual bool onScroll(const ScrollEvent &)
Definition: Window.hpp:36
Definition: ImageWidgets.hpp:169
Definition: ImageWidgets.hpp:51
Definition: Widget.hpp:85
void setAbsolutePos(int x, int y) noexcept
void setAbsoluteX(int x) noexcept
Definition: ImageWidgets.hpp:95
bool onKeyboard(const KeyboardEvent &) override
Definition: Widget.hpp:138
void setAbsoluteY(int y) noexcept
void onDisplay() override
virtual bool onMotion(const MotionEvent &)
Definition: Widget.hpp:61
Definition: Widget.hpp:120
bool onMouse(const MouseEvent &) override
Definition: Image.hpp:38
Definition: ImageWidgets.hpp:87
Definition: Widget.hpp:153
Definition: ImageWidgets.hpp:54
Definition: ImageWidgets.hpp:239
Definition: ImageWidgets.hpp:166
Definition: ImageWidgets.hpp:236