ASPiK SDK
cslider.h
1 // This file is part of VSTGUI. It is subject to the license terms
2 // in the LICENSE file found in the top-level directory of this
3 // distribution and at http://github.com/steinbergmedia/vstgui/LICENSE
4 
5 #ifndef __cslider__
6 #define __cslider__
7 
8 #include "ccontrol.h"
9 #include "../ccolor.h"
10 
11 namespace VSTGUI {
12 
13 //-----------------------------------------------------------------------------
14 // CSlider Declaration
17 //-----------------------------------------------------------------------------
18 class CSlider : public CControl
19 {
20 public:
21  CSlider (const CRect& size, IControlListener* listener, int32_t tag, int32_t iMinPos, int32_t iMaxPos, CBitmap* handle, CBitmap* background, const CPoint& offset = CPoint (0, 0), const int32_t style = kLeft|kHorizontal);
22  CSlider (const CRect& rect, IControlListener* listener, int32_t tag, const CPoint& offsetHandle, int32_t rangeHandle, CBitmap* handle, CBitmap* background, const CPoint& offset = CPoint (0, 0), const int32_t style = kLeft|kHorizontal);
23  CSlider (const CSlider& slider);
24 
25  enum Mode {
26  kTouchMode,
27  kRelativeTouchMode,
28  kFreeClickMode
29  };
30  //-----------------------------------------------------------------------------
32  //-----------------------------------------------------------------------------
34  virtual void setDrawTransparentHandle (bool val) { bDrawTransparentEnabled = val; }
35  virtual bool getDrawTransparentHandle () const { return bDrawTransparentEnabled; }
36  virtual void setMode (Mode newMode) { mode = newMode; }
37  virtual Mode getMode () const { return mode; }
38  virtual void setOffsetHandle (const CPoint& val);
39  virtual CPoint getOffsetHandle () const { return offsetHandle; }
40  virtual void setOffset (const CPoint& val) { offset = val; }
41  virtual CPoint getOffset () const { return offset; }
42 
43  virtual void setStyle (int32_t style);
44  virtual int32_t getStyle () const { return style; }
45 
46  virtual void setHandle (CBitmap* pHandle);
47  virtual CBitmap* getHandle () const { return pHandle; }
48 
49  virtual void setZoomFactor (float val) { zoomFactor = val; }
50  virtual float getZoomFactor () const { return zoomFactor; }
52 
53  //-----------------------------------------------------------------------------
55  //-----------------------------------------------------------------------------
57  enum DrawStyle {
58  kDrawFrame = 1 << 0,
59  kDrawBack = 1 << 1,
60  kDrawValue = 1 << 2,
61  kDrawValueFromCenter = 1 << 3,
62  kDrawInverted = 1 << 4
63  };
64 
65  virtual void setDrawStyle (int32_t style);
66  virtual void setFrameWidth (CCoord width);
67  virtual void setFrameColor (CColor color);
68  virtual void setBackColor (CColor color);
69  virtual void setValueColor (CColor color);
70 
71  int32_t getDrawStyle () const { return drawStyle; }
72  CCoord getFrameWidth () const { return frameWidth; }
73  CColor getFrameColor () const { return frameColor; }
74  CColor getBackColor () const { return backColor; }
75  CColor getValueColor () const { return valueColor; }
77 
78  // overrides
79  void draw (CDrawContext*) override;
80 
81  CMouseEventResult onMouseDown (CPoint& where, const CButtonState& buttons) override;
82  CMouseEventResult onMouseUp (CPoint& where, const CButtonState& buttons) override;
83  CMouseEventResult onMouseMoved (CPoint& where, const CButtonState& buttons) override;
84  CMouseEventResult onMouseCancel () override;
85 
86  bool onWheel (const CPoint& where, const float& distance, const CButtonState& buttons) override;
87  int32_t onKeyDown (VstKeyCode& keyCode) override;
88 
89  bool sizeToFit () override;
90 
91  static bool kAlwaysUseZoomFactor;
92 
93  CLASS_METHODS(CSlider, CControl)
94 protected:
95  ~CSlider () noexcept override;
96  void setViewSize (const CRect& rect, bool invalid) override;
97 
98  float calculateDelta (const CPoint& where, CRect* handleRect = nullptr) const;
99 
100  CPoint offset;
101  CPoint offsetHandle;
102 
103  CBitmap* pHandle;
104 
105  int32_t style;
106  Mode mode;
107 
108  CCoord widthOfSlider;
109  CCoord heightOfSlider;
110  CCoord rangeHandle;
111  CCoord minTmp;
112  CCoord maxTmp;
113  CCoord minPos;
114  CCoord widthControl;
115  CCoord heightControl;
116  CCoord frameWidth {1.};
117  float zoomFactor;
118 
119  bool bDrawTransparentEnabled;
120 
121  int32_t drawStyle {0};
122  CColor frameColor {kGreyCColor};
123  CColor backColor {kBlackCColor};
124  CColor valueColor {kWhiteCColor};
125 private:
126  CCoord delta;
127  float oldVal;
128  float startVal;
129  CButtonState oldButton;
130  CPoint mouseStartPoint;
131 };
132 
133 //-----------------------------------------------------------------------------
134 // CVerticalSlider Declaration
137 //-----------------------------------------------------------------------------
138 class CVerticalSlider : public CSlider
139 {
140 public:
141  CVerticalSlider (const CRect& size, IControlListener* listener, int32_t tag, int32_t iMinPos, int32_t iMaxPos, CBitmap* handle, CBitmap* background, const CPoint& offset = CPoint (0, 0), const int32_t style = kBottom);
142  CVerticalSlider (const CRect& rect, IControlListener* listener, int32_t tag, const CPoint& offsetHandle, int32_t rangeHandle, CBitmap* handle, CBitmap* background, const CPoint& offset = CPoint (0, 0), const int32_t style = kBottom);
143  CVerticalSlider (const CVerticalSlider& slider) = default;
144 };
145 
146 //-----------------------------------------------------------------------------
147 // CHorizontalSlider Declaration
150 //-----------------------------------------------------------------------------
152 {
153 public:
154  CHorizontalSlider (const CRect& size, IControlListener* listener, int32_t tag, int32_t iMinPos, int32_t iMaxPos, CBitmap* handle, CBitmap* background, const CPoint& offset = CPoint (0, 0), const int32_t style = kRight);
155  CHorizontalSlider (const CRect& rect, IControlListener* listener, int32_t tag, const CPoint& offsetHandle, int32_t rangeHandle, CBitmap* handle, CBitmap* background, const CPoint& offset = CPoint (0, 0), const int32_t style = kRight);
156  CHorizontalSlider (const CHorizontalSlider& slider) = default;
157 };
158 
159 } // namespace
160 
161 #endif
void setViewSize(const CRect &rect, bool invalid) override
set views size
Definition: cslider.cpp:174
Rect structure.
Definition: crect.h:17
Definition: xmlparse.c:181
CMouseEventResult onMouseCancel() override
called when mouse tracking should be canceled
Definition: cslider.cpp:449
Definition: vstkeycode.h:12
bool sizeToFit() override
resize view to optimal size
Definition: cslider.cpp:195
A drawing context encapsulates the drawing context of the underlying OS.
Definition: cdrawcontext.h:29
RGBA Color structure.
Definition: ccolor.h:15
CMouseEventResult onMouseMoved(CPoint &where, const CButtonState &buttons) override
called when a mouse move event occurs
Definition: cslider.cpp:477
CMouseEventResult onMouseDown(CPoint &where, const CButtonState &buttons) override
called when a mouse down event occurs
Definition: cslider.cpp:420
a slider control
Definition: cslider.h:18
a vertical slider control
Definition: cslider.h:138
CVerticalSlider(const CRect &size, IControlListener *listener, int32_t tag, int32_t iMinPos, int32_t iMaxPos, CBitmap *handle, CBitmap *background, const CPoint &offset=CPoint(0, 0), const int32_t style=kBottom)
Definition: cslider.cpp:713
Encapsulates various platform depended kinds of bitmaps.
Definition: cbitmap.h:21
a horizontal slider control
Definition: cslider.h:151
Definition: customcontrols.cpp:8
base class of all VSTGUI controls
Definition: ccontrol.h:76
Button and Modifier state.
Definition: cbuttonstate.h:34
CMouseEventResult onMouseUp(CPoint &where, const CButtonState &buttons) override
called when a mouse up event occurs
Definition: cslider.cpp:466
CSlider(const CRect &size, IControlListener *listener, int32_t tag, int32_t iMinPos, int32_t iMaxPos, CBitmap *handle, CBitmap *background, const CPoint &offset=CPoint(0, 0), const int32_t style=kLeft|kHorizontal)
Definition: cslider.cpp:38
CHorizontalSlider(const CRect &size, IControlListener *listener, int32_t tag, int32_t iMinPos, int32_t iMaxPos, CBitmap *handle, CBitmap *background, const CPoint &offset=CPoint(0, 0), const int32_t style=kRight)
Definition: cslider.cpp:755
virtual void invalid()
mark whole view as invalid
Definition: cview.h:63
Point structure.
Definition: cpoint.h:17
int32_t onKeyDown(VstKeyCode &keyCode) override
called if a key down event occurs and this view has focus
Definition: cslider.cpp:583
bool onWheel(const CPoint &where, const float &distance, const CButtonState &buttons) override
called if a mouse wheel event is happening over this view
Definition: cslider.cpp:550
Definition: icontrollistener.h:14
void draw(CDrawContext *) override
called if the view should draw itself
Definition: cslider.cpp:227