ASPiK SDK
ccontrol.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 __ccontrol__
6 #define __ccontrol__
7 
8 #include "../cview.h"
9 #include "../ifocusdrawing.h"
10 #include "../idependency.h"
11 #include "../dispatchlist.h"
12 #include "icontrollistener.h"
13 #include <list>
14 
15 //------------------
16 // defines
17 //------------------
18 #ifndef kPI
19 #define kPI 3.14159265358979323846
20 #endif
21 
22 #ifndef k2PI
23 #define k2PI 6.28318530717958647692
24 #endif
25 
26 #ifndef kPI_2
27 #define kPI_2 1.57079632679489661923f
28 #endif
29 
30 #ifndef kPI_4
31 #define kPI_4 0.78539816339744830962
32 #endif
33 
34 #ifndef kE
35 #define kE 2.7182818284590452354
36 #endif
37 
38 #ifndef kLN2
39 #define kLN2 0.69314718055994530942
40 #endif
41 
42 #ifndef kSQRT2
43 #define kSQRT2 1.41421356237309504880
44 #endif
45 
46 namespace VSTGUI {
47 
48 //------------------
49 // CControlEnum type
50 //------------------
51 enum CControlEnum
52 {
53  kHorizontal = 1 << 0,
54  kVertical = 1 << 1,
55  kShadowText = 1 << 2,
56  kLeft = 1 << 3,
57  kRight = 1 << 4,
58  kTop = 1 << 5,
59  kBottom = 1 << 6,
60  k3DIn = 1 << 7,
61  k3DOut = 1 << 8,
62  kPopupStyle = 1 << 9,
63  kCheckStyle = 1 << 10,
64  kMultipleCheckStyle,
65  kNoTextStyle = 1 << 11,
66  kNoDrawStyle = 1 << 12,
67  kDoubleClickStyle = 1 << 13,
68  kNoFrame = 1 << 14,
69  kRoundRectStyle = 1 << 15
70 };
71 
72 //-----------------------------------------------------------------------------
73 // CControl Declaration
75 //-----------------------------------------------------------------------------
76 class CControl : public CView, public IFocusDrawing, public IDependency
77 {
78 public:
79  CControl (const CRect& size, IControlListener* listener = nullptr, int32_t tag = 0, CBitmap* pBackground = nullptr);
80  CControl (const CControl& c);
81 
82  //-----------------------------------------------------------------------------
84  //-----------------------------------------------------------------------------
86  virtual void setValue (float val);
87  virtual float getValue () const { return value; }
88 
89  virtual void setValueNormalized (float val);
90  virtual float getValueNormalized () const;
91 
92  virtual void setMin (float val) { vmin = val; bounceValue (); }
93  virtual float getMin () const { return vmin; }
94  virtual void setMax (float val) { vmax = val; bounceValue (); }
95  virtual float getMax () const { return vmax; }
96  float getRange () const { return getMax () - getMin (); }
97 
98  virtual void setOldValue (float val) { oldValue = val; }
99  virtual float getOldValue (void) const { return oldValue; }
100  virtual void setDefaultValue (float val) { defaultValue = val; }
101  virtual float getDefaultValue (void) const { return defaultValue; }
102 
103  virtual void bounceValue ();
104  virtual bool checkDefaultValue (CButtonState button);
105 
106  virtual void valueChanged ();
107 
108 
109  //-----------------------------------------------------------------------------
111  //-----------------------------------------------------------------------------
113  virtual void setTag (int32_t val);
114  virtual int32_t getTag () const { return tag; }
115 
116  virtual void beginEdit ();
117  virtual void endEdit ();
118  bool isEditing () const { return editing > 0; }
119 
120  virtual IControlListener* getListener () const { return listener; }
121  virtual void setListener (IControlListener* l) { listener = l; }
122 
123  void registerControlListener (IControlListener* listener);
125 
126 
127  //-----------------------------------------------------------------------------
129  //-----------------------------------------------------------------------------
131  virtual void setBackOffset (const CPoint& offset);
132  virtual const CPoint& getBackOffset () const { return backOffset; }
133  virtual void copyBackOffset ();
134 
135  virtual void setWheelInc (float val) { wheelInc = val; }
136  virtual float getWheelInc () const { return wheelInc; }
138 
139  // overrides
140  void draw (CDrawContext* pContext) override = 0;
141  bool isDirty () const override;
142  void setDirty (bool val = true) override;
143 
144  bool drawFocusOnTop () override;
145  bool getFocusPath (CGraphicsPath& outPath) override;
146 
147  static int32_t kZoomModifier;
148  static int32_t kDefaultValueModifier;
149 
150  // messages send to dependent objects
151  static IdStringPtr kMessageTagWillChange;
152  static IdStringPtr kMessageTagDidChange;
153  static IdStringPtr kMessageValueChanged;
154  static IdStringPtr kMessageBeginEdit;
155  static IdStringPtr kMessageEndEdit;
156 
157  CLASS_METHODS_VIRTUAL(CControl, CView)
158 protected:
159  ~CControl () noexcept override = default;
160  static int32_t mapVstKeyModifier (int32_t vstModifier);
161 
163 
164  IControlListener* listener;
165  SubListenerDispatcher subListeners;
166  int32_t tag;
167  float oldValue;
168  float defaultValue;
169  float value;
170  float vmin;
171  float vmax;
172  float wheelInc;
173  int32_t editing;
174 
175  CPoint backOffset;
176 };
177 
178 //-----------------------------------------------------------------------------
179 // IMultiBitmapControl Declaration
181 //-----------------------------------------------------------------------------
183 {
184 public:
185  virtual ~IMultiBitmapControl() {}
186  virtual void setHeightOfOneImage (const CCoord& height) { heightOfOneImage = height; }
187  virtual CCoord getHeightOfOneImage () const { return heightOfOneImage; }
188 
189  virtual void setNumSubPixmaps (int32_t numSubPixmaps) { subPixmaps = numSubPixmaps; }
190  virtual int32_t getNumSubPixmaps () const { return subPixmaps; }
191 
192  virtual void autoComputeHeightOfOneImage ();
193 protected:
194  IMultiBitmapControl () : heightOfOneImage (0), subPixmaps (0) {}
195  CCoord heightOfOneImage;
196  int32_t subPixmaps;
197 };
198 
199 } // namespace
200 
201 #endif
void draw(CDrawContext *pContext) override=0
called if the view should draw itself
Rect structure.
Definition: crect.h:17
bool getFocusPath(CGraphicsPath &outPath) override
Definition: ccontrol.cpp:285
Definition: xmlparse.c:181
Definition: dispatchlist.h:14
Custom focus drawing interface.
Definition: ifocusdrawing.h:21
virtual void setListener(IControlListener *l)
set main listener
Definition: ccontrol.h:121
static int32_t kDefaultValueModifier
default value modifier key, per default is the control key
Definition: ccontrol.h:148
virtual IControlListener * getListener() const
get main listener
Definition: ccontrol.h:120
Encapsulates various platform depended kinds of bitmaps.
Definition: cbitmap.h:21
Definition: customcontrols.cpp:8
base class of all VSTGUI controls
Definition: ccontrol.h:76
void registerControlListener(IControlListener *listener)
register a sub listener
Definition: ccontrol.cpp:104
void setDirty(bool val=true) override
set the view to dirty so that it is redrawn in the next idle. Thread Safe !
Definition: ccontrol.cpp:217
Button and Modifier state.
Definition: cbuttonstate.h:34
Base Class of all view objects.
Definition: cview.h:44
bool drawFocusOnTop() override
Definition: ccontrol.cpp:279
void unregisterControlListener(IControlListener *listener)
unregister a sub listener
Definition: ccontrol.cpp:110
bool isDirty() const override
check if view is dirty
Definition: ccontrol.cpp:209
Point structure.
Definition: cpoint.h:17
static int32_t kZoomModifier
zoom modifier key, per default is the shift key
Definition: ccontrol.h:147
virtual void valueChanged()
notifies listener and dependent objects
Definition: ccontrol.cpp:200
Definition: icontrollistener.h:14
simple dependency between objects.
Definition: idependency.h:26
interface for controls with sub images
Definition: ccontrol.h:182