ASPiK SDK
cswitch.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 __cswitch__
6 #define __cswitch__
7 
8 #include "ccontrol.h"
9 
10 namespace VSTGUI {
11 
12 //-----------------------------------------------------------------------------
14 {
15 protected:
16  CSwitchBase (const CRect& size, IControlListener* listener, int32_t tag, CBitmap* background,
17  const CPoint& offset = CPoint (0, 0));
18  CSwitchBase (const CRect& size, IControlListener* listener, int32_t tag, int32_t subPixmaps,
19  CCoord heightOfOneImage, int32_t iMaxPositions, CBitmap* background,
20  const CPoint& offset = CPoint (0, 0));
21  CSwitchBase (const CSwitchBase& other);
22  ~CSwitchBase () noexcept override = default;
23 
24  void draw (CDrawContext*) override;
25  CMouseEventResult onMouseDown (CPoint& where, const CButtonState& buttons) override;
26  CMouseEventResult onMouseUp (CPoint& where, const CButtonState& buttons) override;
27  CMouseEventResult onMouseMoved (CPoint& where, const CButtonState& buttons) override;
28  CMouseEventResult onMouseCancel () override;
29  bool sizeToFit () override;
30 
31  void setNumSubPixmaps (int32_t numSubPixmaps) override
32  {
33  IMultiBitmapControl::setNumSubPixmaps (numSubPixmaps);
34  invalid ();
35  }
36  const CPoint& getOffset () const { return offset; }
37 
38  double getCoef () const { return coef; }
39  int32_t normalizedToIndex (float norm) const
40  {
41  return static_cast<int32_t> (norm * (getNumSubPixmaps () - 1) + 0.5f);
42  }
43 
44  float indexToNormalized (int32_t index) const
45  {
46  return static_cast<float> (index) / static_cast<float> (getNumSubPixmaps () - 1);
47  }
48 
49  virtual double calculateCoef () const = 0;
50  virtual float calcNormFromPoint (const CPoint& where) const = 0;
51 
52 private:
53  CPoint offset;
54  double coef;
55  float mouseStartValue;
56 };
57 
58 //-----------------------------------------------------------------------------
59 // CVerticalSwitch Declaration
62 //-----------------------------------------------------------------------------
64 {
65 public:
66  CVerticalSwitch (const CRect& size, IControlListener* listener, int32_t tag, CBitmap* background, const CPoint& offset = CPoint (0, 0));
67  CVerticalSwitch (const CRect& size, IControlListener* listener, int32_t tag, int32_t subPixmaps, CCoord heightOfOneImage, int32_t iMaxPositions, CBitmap* background, const CPoint& offset = CPoint (0, 0));
68  CVerticalSwitch (const CVerticalSwitch& vswitch);
69 
70  int32_t onKeyDown (VstKeyCode& keyCode) override;
71 
72  CLASS_METHODS(CVerticalSwitch, CControl)
73 protected:
74  ~CVerticalSwitch () noexcept override = default;
75 
76  double calculateCoef () const override;
77  float calcNormFromPoint (const CPoint& where) const override;
78 };
79 
80 
81 //-----------------------------------------------------------------------------
82 // CHorizontalSwitch Declaration
85 //-----------------------------------------------------------------------------
87 {
88 public:
89  CHorizontalSwitch (const CRect& size, IControlListener* listener, int32_t tag, CBitmap* background, const CPoint& offset = CPoint (0, 0));
90  CHorizontalSwitch (const CRect& size, IControlListener* listener, int32_t tag, int32_t subPixmaps, CCoord heightOfOneImage, int32_t iMaxPositions, CBitmap* background, const CPoint& offset = CPoint (0, 0));
91  CHorizontalSwitch (const CHorizontalSwitch& hswitch);
92 
93  int32_t onKeyDown (VstKeyCode& keyCode) override;
94 
95  CLASS_METHODS(CHorizontalSwitch, CControl)
96 protected:
97  ~CHorizontalSwitch () noexcept override = default;
98 
99  double calculateCoef () const override;
100  float calcNormFromPoint (const CPoint& where) const override;
101 };
102 
103 
104 //-----------------------------------------------------------------------------
105 // CRockerSwitch Declaration
108 //-----------------------------------------------------------------------------
110 {
111 public:
112  CRockerSwitch (const CRect& size, IControlListener* listener, int32_t tag, CBitmap* background, const CPoint& offset = CPoint (0, 0), const int32_t style = kHorizontal);
113  CRockerSwitch (const CRect& size, IControlListener* listener, int32_t tag, CCoord heightOfOneImage, CBitmap* background, const CPoint& offset = CPoint (0, 0), const int32_t style = kHorizontal);
114  CRockerSwitch (const CRockerSwitch& rswitch);
115 
116  void draw (CDrawContext*) override;
117  bool onWheel (const CPoint& where, const float& distance, const CButtonState& buttons) override;
118 
119  CMouseEventResult onMouseDown (CPoint& where, const CButtonState& buttons) override;
120  CMouseEventResult onMouseUp (CPoint& where, const CButtonState& buttons) override;
121  CMouseEventResult onMouseMoved (CPoint& where, const CButtonState& buttons) override;
122  CMouseEventResult onMouseCancel () override;
123  int32_t onKeyDown (VstKeyCode& keyCode) override;
124  int32_t onKeyUp (VstKeyCode& keyCode) override;
125 
126  bool sizeToFit () override;
127 
128  void setNumSubPixmaps (int32_t numSubPixmaps) override { IMultiBitmapControl::setNumSubPixmaps (numSubPixmaps); invalid (); }
129 
130  CLASS_METHODS(CRockerSwitch, CControl)
131 protected:
132  ~CRockerSwitch () noexcept override;
133 
134  CMessageResult notify (CBaseObject* sender, IdStringPtr message) override;
135 
136  CPoint offset;
137  int32_t style;
138 
139  CVSTGUITimer* resetValueTimer;
140 private:
141  float mouseStartValue;
142 };
143 
144 } // namespace
145 
146 #endif
bool sizeToFit() override
resize view to optimal size
Definition: cswitch.cpp:594
Definition: cswitch.h:13
CMouseEventResult onMouseDown(CPoint &where, const CButtonState &buttons) override
called when a mouse down event occurs
Definition: cswitch.cpp:71
a horizontal switch control
Definition: cswitch.h:86
void draw(CDrawContext *) override
called if the view should draw itself
Definition: cswitch.cpp:42
int32_t onKeyDown(VstKeyCode &keyCode) override
called if a key down event occurs and this view has focus
Definition: cswitch.cpp:199
Rect structure.
Definition: crect.h:17
bool onWheel(const CPoint &where, const float &distance, const CButtonState &buttons) override
called if a mouse wheel event is happening over this view
Definition: cswitch.cpp:545
CMouseEventResult onMouseUp(CPoint &where, const CButtonState &buttons) override
called when a mouse up event occurs
Definition: cswitch.cpp:90
CHorizontalSwitch(const CRect &size, IControlListener *listener, int32_t tag, CBitmap *background, const CPoint &offset=CPoint(0, 0))
Definition: cswitch.cpp:247
Definition: xmlparse.c:181
Definition: vstkeycode.h:12
CMouseEventResult onMouseCancel() override
called when mouse tracking should be canceled
Definition: cswitch.cpp:446
CMouseEventResult onMouseMoved(CPoint &where, const CButtonState &buttons) override
called when a mouse move event occurs
Definition: cswitch.cpp:462
int32_t onKeyDown(VstKeyCode &keyCode) override
called if a key down event occurs and this view has focus
Definition: cswitch.cpp:502
CMouseEventResult onMouseUp(CPoint &where, const CButtonState &buttons) override
called when a mouse up event occurs
Definition: cswitch.cpp:433
A drawing context encapsulates the drawing context of the underlying OS.
Definition: cdrawcontext.h:29
Base Object with reference counter.
Definition: vstguibase.h:276
a switch control with 3 sub bitmaps
Definition: cswitch.h:109
CMouseEventResult onMouseMoved(CPoint &where, const CButtonState &buttons) override
called when a mouse move event occurs
Definition: cswitch.cpp:114
a vertical switch control
Definition: cswitch.h:63
bool sizeToFit() override
resize view to optimal size
Definition: cswitch.cpp:56
Encapsulates various platform depended kinds of bitmaps.
Definition: cbitmap.h:21
Definition: customcontrols.cpp:8
CVerticalSwitch(const CRect &size, IControlListener *listener, int32_t tag, CBitmap *background, const CPoint &offset=CPoint(0, 0))
Definition: cswitch.cpp:150
base class of all VSTGUI controls
Definition: ccontrol.h:76
Button and Modifier state.
Definition: cbuttonstate.h:34
A timer class, which posts timer messages to CBaseObjects or calls a lambda function (c++11 only)...
Definition: cvstguitimer.h:18
void draw(CDrawContext *) override
called if the view should draw itself
Definition: cswitch.cpp:406
int32_t onKeyUp(VstKeyCode &keyCode) override
called if a key up event occurs and this view has focus
Definition: cswitch.cpp:527
int32_t onKeyDown(VstKeyCode &keyCode) override
called if a key down event occurs and this view has focus
Definition: cswitch.cpp:296
virtual void invalid()
mark whole view as invalid
Definition: cview.h:63
Point structure.
Definition: cpoint.h:17
CMouseEventResult onMouseCancel() override
called when mouse tracking should be canceled
Definition: cswitch.cpp:98
CMouseEventResult onMouseDown(CPoint &where, const CButtonState &buttons) override
called when a mouse down event occurs
Definition: cswitch.cpp:423
Definition: icontrollistener.h:14
interface for controls with sub images
Definition: ccontrol.h:182
CRockerSwitch(const CRect &size, IControlListener *listener, int32_t tag, CBitmap *background, const CPoint &offset=CPoint(0, 0), const int32_t style=kHorizontal)
Definition: cswitch.cpp:347