Dusk Audio Framework
Loading...
Searching...
No Matches
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
24START_NAMESPACE_DGL
25
26// --------------------------------------------------------------------------------------------------------------------
27
28/**
29 DGL Image About Window class.
30
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.
33
34 Pressing 'Esc' or clicking anywhere on the window will automatically close it.
35
36 @see CairoImageAboutWindow, OpenGLImageAboutWindow, Window::runAsModal(bool)
37 */
38template <class ImageType>
40{
41public:
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.
45 */
46 explicit ImageBaseAboutWindow(Window& transientParentWindow, const ImageType& image = ImageType());
47
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.
51 */
52 explicit ImageBaseAboutWindow(TopLevelWidget* topLevelWidget, const ImageType& image = ImageType());
53
54 /**
55 Set a new image to use as background for this window.
56 Window size will adjust to match the image size.
57 */
58 void setImage(const ImageType& image);
59
60protected:
61 void onDisplay() override;
62 bool onKeyboard(const KeyboardEvent&) override;
63 bool onMouse(const MouseEvent&) override;
64
65private:
66 ImageType img;
67
68 DAF_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(ImageBaseAboutWindow)
69};
70
71// --------------------------------------------------------------------------------------------------------------------
72
73/**
74 DGL Image Button class.
75
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.
78
79 The event logic for this button comes from the ButtonEventHandler class.
80
81 @see CairoImageButton, OpenGLImageButton
82 */
83template <class ImageType>
84class ImageBaseButton : public SubWidget,
85 public ButtonEventHandler
86{
87public:
89 {
90 public:
91 virtual ~Callback() {}
92 virtual void imageButtonClicked(ImageBaseButton* imageButton, int button) = 0;
93 };
94
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);
98
99 ~ImageBaseButton() override;
100
101 void setCallback(Callback* callback) noexcept;
102
103protected:
104 void onDisplay() override;
105 bool onMouse(const MouseEvent&) override;
106 bool onMotion(const MotionEvent&) override;
107
108private:
109 struct PrivateData;
110 PrivateData* const pData;
111
112 DAF_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(ImageBaseButton)
113};
114
115// --------------------------------------------------------------------------------------------------------------------
116
117/**
118 DGL Image Knob class.
119
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.
124
125 The event logic for this knob comes from the KnobEventHandler class.
126
127 @see CairoImageKnob, OpenGLImageKnob
128 */
129template <class ImageType>
130class ImageBaseKnob : public SubWidget,
131 public KnobEventHandler
132{
133public:
135 {
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;
141 virtual void imageKnobDoubleClicked(ImageBaseKnob*) {};
142 };
143
144 explicit ImageBaseKnob(Widget* parentWidget, const ImageType& image, Orientation orientation = Vertical) noexcept;
145 explicit ImageBaseKnob(const ImageBaseKnob& imageKnob);
146 ImageBaseKnob& operator=(const ImageBaseKnob& imageKnob);
147 ~ImageBaseKnob() override;
148
149 void setCallback(Callback* callback) noexcept;
150 void setImageLayerCount(uint count) noexcept;
151 void setRotationAngle(int angle);
152 bool setValue(float value, bool sendCallback = false) noexcept override;
153
154protected:
155 void onDisplay() override;
156 bool onMouse(const MouseEvent&) override;
157 bool onMotion(const MotionEvent&) override;
158 bool onScroll(const ScrollEvent&) override;
159
160private:
161 struct PrivateData;
162 PrivateData* const pData;
163
164 DAF_LEAK_DETECTOR(ImageBaseKnob)
165};
166
167// --------------------------------------------------------------------------------------------------------------------
168
169// note set range and step before setting the value
170
171template <class ImageType>
172class ImageBaseSlider : public SubWidget
173{
174public:
176 {
177 public:
178 virtual ~Callback() {}
179 virtual void imageSliderDragStarted(ImageBaseSlider* imageSlider) = 0;
180 virtual void imageSliderDragFinished(ImageBaseSlider* imageSlider) = 0;
181 virtual void imageSliderValueChanged(ImageBaseSlider* imageSlider, float value) = 0;
182 };
183
184 explicit ImageBaseSlider(Widget* parentWidget, const ImageType& image) noexcept;
185 ~ImageBaseSlider() override;
186
187 float getValue() const noexcept;
188 void setValue(float value, bool sendCallback = false) noexcept;
189 void setDefault(float def) noexcept;
190
191 void setStartPos(const Point<int>& startPos) noexcept;
192 void setStartPos(int x, int y) noexcept;
193 void setEndPos(const Point<int>& endPos) noexcept;
194 void setEndPos(int x, int y) noexcept;
195
196 void setCheckable(bool checkable) noexcept;
197 void setInverted(bool inverted) noexcept;
198 void setRange(float min, float max) noexcept;
199 void setStep(float step) noexcept;
200
201 void setCallback(Callback* callback) noexcept;
202
203protected:
204 void onDisplay() override;
205 bool onMouse(const MouseEvent&) override;
206 bool onMotion(const MotionEvent&) override;
207
208private:
209 struct PrivateData;
210 PrivateData* const pData;
211
212 // these should not be used
213 void setAbsoluteX(int) const noexcept {}
214 void setAbsoluteY(int) const noexcept {}
215 void setAbsolutePos(int, int) const noexcept {}
216 void setAbsolutePos(const Point<int>&) const noexcept {}
217
218 DAF_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(ImageBaseSlider)
219};
220
221// --------------------------------------------------------------------------------------------------------------------
222
223template <class ImageType>
224class ImageBaseSwitch : public SubWidget
225{
226public:
228 {
229 public:
230 virtual ~Callback() {}
231 virtual void imageSwitchClicked(ImageBaseSwitch* imageSwitch, bool down) = 0;
232 };
233
234 explicit ImageBaseSwitch(Widget* parentWidget, const ImageType& imageNormal, const ImageType& imageDown) noexcept;
235 explicit ImageBaseSwitch(const ImageBaseSwitch& imageSwitch) noexcept;
236 ImageBaseSwitch& operator=(const ImageBaseSwitch& imageSwitch) noexcept;
237 ~ImageBaseSwitch() override;
238
239 bool isDown() const noexcept;
240 void setDown(bool down) noexcept;
241
242 void setCallback(Callback* callback) noexcept;
243
244protected:
245 void onDisplay() override;
246 bool onMouse(const MouseEvent&) override;
247
248private:
249 struct PrivateData;
250 PrivateData* const pData;
251
252 DAF_LEAK_DETECTOR(ImageBaseSwitch)
253};
254
255// --------------------------------------------------------------------------------------------------------------------
256
257END_NAMESPACE_DGL
258
259#endif // DGL_IMAGE_BASE_WIDGETS_HPP_INCLUDED
void setImage(const ImageType &image)
bool onKeyboard(const KeyboardEvent &) override
void onDisplay() override
ImageBaseAboutWindow(TopLevelWidget *topLevelWidget, const ImageType &image=ImageType())
bool onMouse(const MouseEvent &) override
ImageBaseAboutWindow(Window &transientParentWindow, const ImageType &image=ImageType())
Definition ImageBaseWidgets.hpp:89
void onDisplay() override
bool onMotion(const MotionEvent &) override
bool onMouse(const MouseEvent &) override
Definition ImageBaseWidgets.hpp:135
bool onMouse(const MouseEvent &) override
bool onMotion(const MotionEvent &) override
bool onScroll(const ScrollEvent &) override
Definition ImageBaseWidgets.hpp:176
bool onMotion(const MotionEvent &) override
bool onMouse(const MouseEvent &) override
Definition ImageBaseWidgets.hpp:228
bool onMouse(const MouseEvent &) override
Definition Geometry.hpp:41
StandaloneWindow(Application &app)
Definition StandaloneWindow.hpp:34
void setAbsolutePos(int x, int y) noexcept
void setAbsoluteY(int y) noexcept
SubWidget(Widget *parentWidget)
Definition TopLevelWidget.hpp:47
Definition Window.hpp:67
Definition Widget.hpp:92
Definition Widget.hpp:184
Definition Widget.hpp:161
Definition Widget.hpp:208