Cleanup
[carla.git] / source / modules / dgl / ImageBaseWidgets.hpp
blob1a4fbbea93caa9c6a56a4b4a4805e20e45eebb25
1 /*
2 * DISTRHO Plugin Framework (DPF)
3 * Copyright (C) 2012-2021 Filipe Coelho <falktx@falktx.com>
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.
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.
17 #ifndef DGL_IMAGE_BASE_WIDGETS_HPP_INCLUDED
18 #define DGL_IMAGE_BASE_WIDGETS_HPP_INCLUDED
20 #include "EventHandlers.hpp"
21 #include "StandaloneWindow.hpp"
22 #include "SubWidget.hpp"
24 START_NAMESPACE_DGL
26 // --------------------------------------------------------------------------------------------------------------------
28 /**
29 DGL Image About Window class.
31 This is a Window attached (transient) to another Window that simply shows an Image as its content.
32 It is typically used for "about this project" style pop-up Windows.
34 Pressing 'Esc' or clicking anywhere on the window will automatically close it.
36 @see CairoImageAboutWindow, OpenGLImageAboutWindow, Window::runAsModal(bool)
38 template <class ImageType>
39 class ImageBaseAboutWindow : public StandaloneWindow
41 public:
42 /**
43 Constructor taking an existing Window as the parent transient window and an optional image.
44 If @a image is valid, the about window size will match the image size.
46 explicit ImageBaseAboutWindow(Window& transientParentWindow, const ImageType& image = ImageType());
48 /**
49 Constructor taking a top-level-widget's Window as the parent transient window and an optional image.
50 If @a image is valid, the about window size will match the image size.
52 explicit ImageBaseAboutWindow(TopLevelWidget* topLevelWidget, const ImageType& image = ImageType());
54 /**
55 Set a new image to use as background for this window.
56 Window size will adjust to match the image size.
58 void setImage(const ImageType& image);
60 protected:
61 void onDisplay() override;
62 bool onKeyboard(const KeyboardEvent&) override;
63 bool onMouse(const MouseEvent&) override;
65 private:
66 ImageType img;
68 DISTRHO_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(ImageBaseAboutWindow)
71 // --------------------------------------------------------------------------------------------------------------------
73 /**
74 DGL Image Button class.
76 This is a typical button, where the drawing comes from a pregenerated set of images.
77 The button can be under "normal", "hover" and "down" states, with one separate image possible for each.
79 The event logic for this button comes from the ButtonEventHandler class.
81 @see CairoImageButton, OpenGLImageButton
83 template <class ImageType>
84 class ImageBaseButton : public SubWidget,
85 public ButtonEventHandler
87 public:
88 class Callback
90 public:
91 virtual ~Callback() {}
92 virtual void imageButtonClicked(ImageBaseButton* imageButton, int button) = 0;
95 explicit ImageBaseButton(Widget* parentWidget, const ImageType& image);
96 explicit ImageBaseButton(Widget* parentWidget, const ImageType& imageNormal, const ImageType& imageDown);
97 explicit ImageBaseButton(Widget* parentWidget, const ImageType& imageNormal, const ImageType& imageHover, const ImageType& imageDown);
99 ~ImageBaseButton() override;
101 void setCallback(Callback* callback) noexcept;
103 protected:
104 void onDisplay() override;
105 bool onMouse(const MouseEvent&) override;
106 bool onMotion(const MotionEvent&) override;
108 private:
109 struct PrivateData;
110 PrivateData* const pData;
112 DISTRHO_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(ImageBaseButton)
115 // --------------------------------------------------------------------------------------------------------------------
118 DGL Image Knob class.
120 This is a typical knob/dial, where the drawing comes from a pregenerated image "filmstrip".
121 The knob's "filmstrip" image can be either horizontal or vertical,
122 with the number of steps automatically based on the largest value (ie, horizontal if width>height, vertical if height>width).
123 There are no different images for "hover" or "down" states.
125 The event logic for this knob comes from the KnobEventHandler class.
127 @see CairoImageKnob, OpenGLImageKnob
129 template <class ImageType>
130 class ImageBaseKnob : public SubWidget,
131 public KnobEventHandler
133 public:
134 class Callback
136 public:
137 virtual ~Callback() {}
138 virtual void imageKnobDragStarted(ImageBaseKnob* imageKnob) = 0;
139 virtual void imageKnobDragFinished(ImageBaseKnob* imageKnob) = 0;
140 virtual void imageKnobValueChanged(ImageBaseKnob* imageKnob, float value) = 0;
143 explicit ImageBaseKnob(Widget* parentWidget, const ImageType& image, Orientation orientation = Vertical) noexcept;
144 explicit ImageBaseKnob(const ImageBaseKnob& imageKnob);
145 ImageBaseKnob& operator=(const ImageBaseKnob& imageKnob);
146 ~ImageBaseKnob() override;
148 void setCallback(Callback* callback) noexcept;
149 void setImageLayerCount(uint count) noexcept;
150 void setRotationAngle(int angle);
151 bool setValue(float value, bool sendCallback = false) noexcept override;
153 protected:
154 void onDisplay() override;
155 bool onMouse(const MouseEvent&) override;
156 bool onMotion(const MotionEvent&) override;
157 bool onScroll(const ScrollEvent&) override;
159 private:
160 struct PrivateData;
161 PrivateData* const pData;
163 DISTRHO_LEAK_DETECTOR(ImageBaseKnob)
166 // --------------------------------------------------------------------------------------------------------------------
168 // note set range and step before setting the value
170 template <class ImageType>
171 class ImageBaseSlider : public SubWidget
173 public:
174 class Callback
176 public:
177 virtual ~Callback() {}
178 virtual void imageSliderDragStarted(ImageBaseSlider* imageSlider) = 0;
179 virtual void imageSliderDragFinished(ImageBaseSlider* imageSlider) = 0;
180 virtual void imageSliderValueChanged(ImageBaseSlider* imageSlider, float value) = 0;
183 explicit ImageBaseSlider(Widget* parentWidget, const ImageType& image) noexcept;
184 ~ImageBaseSlider() override;
186 float getValue() const noexcept;
187 void setValue(float value, bool sendCallback = false) noexcept;
188 void setDefault(float def) noexcept;
190 void setStartPos(const Point<int>& startPos) noexcept;
191 void setStartPos(int x, int y) noexcept;
192 void setEndPos(const Point<int>& endPos) noexcept;
193 void setEndPos(int x, int y) noexcept;
195 void setInverted(bool inverted) noexcept;
196 void setRange(float min, float max) noexcept;
197 void setStep(float step) noexcept;
199 void setCallback(Callback* callback) noexcept;
201 protected:
202 void onDisplay() override;
203 bool onMouse(const MouseEvent&) override;
204 bool onMotion(const MotionEvent&) override;
206 private:
207 struct PrivateData;
208 PrivateData* const pData;
210 // these should not be used
211 void setAbsoluteX(int) const noexcept {}
212 void setAbsoluteY(int) const noexcept {}
213 void setAbsolutePos(int, int) const noexcept {}
214 void setAbsolutePos(const Point<int>&) const noexcept {}
216 DISTRHO_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(ImageBaseSlider)
219 // --------------------------------------------------------------------------------------------------------------------
221 template <class ImageType>
222 class ImageBaseSwitch : public SubWidget
224 public:
225 class Callback
227 public:
228 virtual ~Callback() {}
229 virtual void imageSwitchClicked(ImageBaseSwitch* imageSwitch, bool down) = 0;
232 explicit ImageBaseSwitch(Widget* parentWidget, const ImageType& imageNormal, const ImageType& imageDown) noexcept;
233 explicit ImageBaseSwitch(const ImageBaseSwitch& imageSwitch) noexcept;
234 ImageBaseSwitch& operator=(const ImageBaseSwitch& imageSwitch) noexcept;
235 ~ImageBaseSwitch() override;
237 bool isDown() const noexcept;
238 void setDown(bool down) noexcept;
240 void setCallback(Callback* callback) noexcept;
242 protected:
243 void onDisplay() override;
244 bool onMouse(const MouseEvent&) override;
246 private:
247 struct PrivateData;
248 PrivateData* const pData;
250 DISTRHO_LEAK_DETECTOR(ImageBaseSwitch)
253 // --------------------------------------------------------------------------------------------------------------------
255 END_NAMESPACE_DGL
257 #endif // DGL_IMAGE_BASE_WIDGETS_HPP_INCLUDED