DISTRHO Plugin Framework
ImageBaseWidgets.hpp
1 /*
2  * DISTRHO Plugin Framework (DPF)
3  * Copyright (C) 2012-2021 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_BASE_WIDGETS_HPP_INCLUDED
18 #define DGL_IMAGE_BASE_WIDGETS_HPP_INCLUDED
19 
20 #include "EventHandlers.hpp"
21 #include "StandaloneWindow.hpp"
22 #include "SubWidget.hpp"
23 
24 START_NAMESPACE_DGL
25 
26 // --------------------------------------------------------------------------------------------------------------------
27 
28 template <class ImageType>
30 {
31 public:
32  explicit ImageBaseAboutWindow(Window& parentWindow, const ImageType& image = ImageType());
33  explicit ImageBaseAboutWindow(TopLevelWidget* parentTopLevelWidget, const ImageType& image = ImageType());
34 
35  void setImage(const ImageType& image);
36 
37 protected:
38  void onDisplay() override;
39  bool onKeyboard(const KeyboardEvent&) override;
40  bool onMouse(const MouseEvent&) override;
41 
42 private:
43  ImageType img;
44 
45  DISTRHO_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(ImageBaseAboutWindow)
46 };
47 
48 // --------------------------------------------------------------------------------------------------------------------
49 
50 template <class ImageType>
51 class ImageBaseButton : public SubWidget,
52  public ButtonEventHandler
53 {
54 public:
55  class Callback
56  {
57  public:
58  virtual ~Callback() {}
59  virtual void imageButtonClicked(ImageBaseButton* imageButton, int button) = 0;
60  };
61 
62  explicit ImageBaseButton(Widget* parentWidget, const ImageType& image);
63  explicit ImageBaseButton(Widget* parentWidget, const ImageType& imageNormal, const ImageType& imageDown);
64  explicit ImageBaseButton(Widget* parentWidget, const ImageType& imageNormal, const ImageType& imageHover, const ImageType& imageDown);
65 
66  ~ImageBaseButton() override;
67 
68  void setCallback(Callback* callback) noexcept;
69 
70 protected:
71  void onDisplay() override;
72  bool onMouse(const MouseEvent&) override;
73  bool onMotion(const MotionEvent&) override;
74 
75 private:
76  struct PrivateData;
77  PrivateData* const pData;
78 
79  DISTRHO_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(ImageBaseButton)
80 };
81 
82 // --------------------------------------------------------------------------------------------------------------------
83 
84 template <class ImageType>
85 class ImageBaseKnob : public SubWidget
86 {
87 public:
88  enum Orientation {
89  Horizontal,
90  Vertical
91  };
92 
93  class Callback
94  {
95  public:
96  virtual ~Callback() {}
97  virtual void imageKnobDragStarted(ImageBaseKnob* imageKnob) = 0;
98  virtual void imageKnobDragFinished(ImageBaseKnob* imageKnob) = 0;
99  virtual void imageKnobValueChanged(ImageBaseKnob* imageKnob, float value) = 0;
100  };
101 
102  explicit ImageBaseKnob(Widget* parentWidget, const ImageType& image, Orientation orientation = Vertical) noexcept;
103  explicit ImageBaseKnob(const ImageBaseKnob& imageKnob);
104  ImageBaseKnob& operator=(const ImageBaseKnob& imageKnob);
105  ~ImageBaseKnob() override;
106 
107  float getValue() const noexcept;
108 
109  void setDefault(float def) noexcept;
110  void setRange(float min, float max) noexcept;
111  void setStep(float step) noexcept;
112  void setValue(float value, bool sendCallback = false) noexcept;
113  void setUsingLogScale(bool yesNo) noexcept;
114 
115  void setCallback(Callback* callback) noexcept;
116  void setOrientation(Orientation orientation) noexcept;
117  void setRotationAngle(int angle);
118 
119  void setImageLayerCount(uint count) noexcept;
120 
121 protected:
122  void onDisplay() override;
123  bool onMouse(const MouseEvent&) override;
124  bool onMotion(const MotionEvent&) override;
125  bool onScroll(const ScrollEvent&) override;
126 
127 private:
128  struct PrivateData;
129  PrivateData* const pData;
130 
131  DISTRHO_LEAK_DETECTOR(ImageBaseKnob)
132 };
133 
134 // --------------------------------------------------------------------------------------------------------------------
135 
136 // note set range and step before setting the value
137 
138 template <class ImageType>
140 {
141 public:
142  class Callback
143  {
144  public:
145  virtual ~Callback() {}
146  virtual void imageSliderDragStarted(ImageBaseSlider* imageSlider) = 0;
147  virtual void imageSliderDragFinished(ImageBaseSlider* imageSlider) = 0;
148  virtual void imageSliderValueChanged(ImageBaseSlider* imageSlider, float value) = 0;
149  };
150 
151  explicit ImageBaseSlider(Widget* parentWidget, const ImageType& image) noexcept;
152  ~ImageBaseSlider() override;
153 
154  float getValue() const noexcept;
155  void setValue(float value, bool sendCallback = false) noexcept;
156  void setDefault(float def) noexcept;
157 
158  void setStartPos(const Point<int>& startPos) noexcept;
159  void setStartPos(int x, int y) noexcept;
160  void setEndPos(const Point<int>& endPos) noexcept;
161  void setEndPos(int x, int y) noexcept;
162 
163  void setInverted(bool inverted) noexcept;
164  void setRange(float min, float max) noexcept;
165  void setStep(float step) noexcept;
166 
167  void setCallback(Callback* callback) noexcept;
168 
169 protected:
170  void onDisplay() override;
171  bool onMouse(const MouseEvent&) override;
172  bool onMotion(const MotionEvent&) override;
173 
174 private:
175  struct PrivateData;
176  PrivateData* const pData;
177 
178  // these should not be used
179  void setAbsoluteX(int) const noexcept {}
180  void setAbsoluteY(int) const noexcept {}
181  void setAbsolutePos(int, int) const noexcept {}
182  void setAbsolutePos(const Point<int>&) const noexcept {}
183 
184  DISTRHO_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(ImageBaseSlider)
185 };
186 
187 // --------------------------------------------------------------------------------------------------------------------
188 
189 template <class ImageType>
191 {
192 public:
193  class Callback
194  {
195  public:
196  virtual ~Callback() {}
197  virtual void imageSwitchClicked(ImageBaseSwitch* imageSwitch, bool down) = 0;
198  };
199 
200  explicit ImageBaseSwitch(Widget* parentWidget, const ImageType& imageNormal, const ImageType& imageDown) noexcept;
201  explicit ImageBaseSwitch(const ImageBaseSwitch& imageSwitch) noexcept;
202  ImageBaseSwitch& operator=(const ImageBaseSwitch& imageSwitch) noexcept;
203  ~ImageBaseSwitch() override;
204 
205  bool isDown() const noexcept;
206  void setDown(bool down) noexcept;
207 
208  void setCallback(Callback* callback) noexcept;
209 
210 protected:
211  void onDisplay() override;
212  bool onMouse(const MouseEvent&) override;
213 
214 private:
215  struct PrivateData;
216  PrivateData* const pData;
217 
218  DISTRHO_LEAK_DETECTOR(ImageBaseSwitch)
219 };
220 
221 // --------------------------------------------------------------------------------------------------------------------
222 
223 END_NAMESPACE_DGL
224 
225 #endif // DGL_IMAGE_BASE_WIDGETS_HPP_INCLUDED
ImageBaseAboutWindow::onDisplay
void onDisplay() override
ImageBaseButton
Definition: ImageBaseWidgets.hpp:51
ImageBaseKnob
Definition: ImageBaseWidgets.hpp:85
Widget::ScrollEvent
Definition: Widget.hpp:213
ImageBaseSlider
Definition: ImageBaseWidgets.hpp:139
Widget::KeyboardEvent
Definition: Widget.hpp:94
SubWidget::setAbsolutePos
void setAbsolutePos(int x, int y) noexcept
Window
Definition: Window.hpp:50
ImageBaseKnob::onScroll
bool onScroll(const ScrollEvent &) override
SubWidget::setAbsoluteY
void setAbsoluteY(int y) noexcept
ImageBaseButton::onDisplay
void onDisplay() override
SubWidget::setAbsoluteX
void setAbsoluteX(int x) noexcept
ImageBaseKnob::onMouse
bool onMouse(const MouseEvent &) override
ImageBaseAboutWindow::onMouse
bool onMouse(const MouseEvent &) override
Widget::MotionEvent
Definition: Widget.hpp:187
ImageBaseAboutWindow::onKeyboard
bool onKeyboard(const KeyboardEvent &) override
ImageBaseAboutWindow
Definition: ImageBaseWidgets.hpp:29
ImageBaseKnob::Callback
Definition: ImageBaseWidgets.hpp:93
ImageBaseKnob::onDisplay
void onDisplay() override
ImageBaseButton::onMouse
bool onMouse(const MouseEvent &) override
StandaloneWindow
Definition: StandaloneWindow.hpp:27
ImageBaseKnob::onMotion
bool onMotion(const MotionEvent &) override
Point
Definition: Geometry.hpp:40
ImageBaseButton::Callback
Definition: ImageBaseWidgets.hpp:55
SubWidget
Definition: SubWidget.hpp:39
Widget::MouseEvent
Definition: Widget.hpp:165
ImageBaseButton::onMotion
bool onMotion(const MotionEvent &) override
ImageBaseSwitch::Callback
Definition: ImageBaseWidgets.hpp:193
ImageBaseSwitch
Definition: ImageBaseWidgets.hpp:190
ButtonEventHandler
Definition: EventHandlers.hpp:26
TopLevelWidget
Definition: TopLevelWidget.hpp:46
ImageBaseSlider::Callback
Definition: ImageBaseWidgets.hpp:142
Widget
Definition: Widget.hpp:53