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