1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
|
/*
* DISTRHO Plugin Framework (DPF)
* Copyright (C) 2012-2014 Filipe Coelho <falktx@falktx.com>
*
* Permission to use, copy, modify, and/or distribute this software for any purpose with
* or without fee is hereby granted, provided that the above copyright notice and this
* permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD
* TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN
* NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
* DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER
* IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
* CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
#ifndef DGL_IMAGE_KNOB_HPP_INCLUDED
#define DGL_IMAGE_KNOB_HPP_INCLUDED
#include "Image.hpp"
#include "Widget.hpp"
START_NAMESPACE_DGL
// -----------------------------------------------------------------------
class ImageKnob : public Widget
{
public:
enum Orientation {
Horizontal,
Vertical
};
class Callback
{
public:
virtual ~Callback() {}
virtual void imageKnobDragStarted(ImageKnob* imageKnob) = 0;
virtual void imageKnobDragFinished(ImageKnob* imageKnob) = 0;
virtual void imageKnobValueChanged(ImageKnob* imageKnob, float value) = 0;
};
ImageKnob(Window& parent, const Image& image, Orientation orientation = Vertical);
ImageKnob(Widget* widget, const Image& image, Orientation orientation = Vertical);
ImageKnob(const ImageKnob& imageKnob);
float getValue() const;
void setOrientation(Orientation orientation);
void setRange(float min, float max);
void setLogScale(bool log = false);
void setStep(float step);
void setValue(float value, bool sendCallback = false);
void setDefault(float value);
void resetDefault(void);
void setRotationAngle(int angle);
void setCallback(Callback* callback);
protected:
void onDisplay() override;
bool onMouse(int button, bool press, int x, int y) override;
bool onMotion(int x, int y) override;
void onReshape(int width, int height) override;
void onClose() override;
float logscale(float value);
float invlogscale(float value);
private:
Image fImage;
float fMinimum;
float fMaximum;
float fStep;
bool fLog;
bool fFirst;
float fValue;
float fValueDef;
float fValueTmp;
Orientation fOrientation;
int fRotationAngle;
bool fDragging;
int fLastX;
int fLastY;
Callback* fCallback;
bool fIsImgVertical;
int fImgLayerSize;
int fImgLayerCount;
Rectangle<int> fKnobArea;
GLuint fTextureId;
};
// -----------------------------------------------------------------------
END_NAMESPACE_DGL
#endif // DGL_IMAGE_KNOB_HPP_INCLUDED
|