ASPiK SDK
cview.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 __cview__
6 #define __cview__
7 
8 #include "vstguifwd.h"
9 #include "cpoint.h"
10 #include "crect.h"
11 #include "vstkeycode.h"
12 #include "cbuttonstate.h"
13 #include "cgraphicstransform.h"
14 #include <memory>
15 
16 namespace VSTGUI {
17 
18 //-----------------------------------------------------------------------------
19 // Definitions of special characters in a platform independent way
20 extern UTF8StringPtr kDegreeSymbol;
21 extern UTF8StringPtr kInfiniteSymbol;
22 extern UTF8StringPtr kCopyrightSymbol;
23 extern UTF8StringPtr kTrademarkSymbol;
24 extern UTF8StringPtr kRegisteredSymbol;
25 extern UTF8StringPtr kMicroSymbol;
26 extern UTF8StringPtr kPerthousandSymbol;
27 
28 //-----------------------------------------------------------------------------
29 extern IdStringPtr kMsgViewSizeChanged;
30 
31 //-----------------------------------------------------------------------------
32 // Attributes
33 // all attributes where the first letter is lowercase are reserved for the vstgui lib
34 
35 extern const CViewAttributeID kCViewAttributeReferencePointer; // 'cvrp'
36 extern const CViewAttributeID kCViewTooltipAttribute; // 'cvtt'
37 extern const CViewAttributeID kCViewControllerAttribute; // 'ictr' ///< see @ref IController
38 
39 //-----------------------------------------------------------------------------
40 // CView Declaration
43 //-----------------------------------------------------------------------------
44 class CView : public CBaseObject
45 {
46 public:
47  explicit CView (const CRect& size);
48  CView (const CView& view);
49 
50  //-----------------------------------------------------------------------------
52  //-----------------------------------------------------------------------------
54  virtual void draw (CDrawContext *pContext);
55  virtual void drawRect (CDrawContext *pContext, const CRect& updateRect) { draw (pContext); }
56  virtual bool checkUpdate (const CRect& updateRect) const { return updateRect.rectOverlap (getViewSize ()); }
57 
58  virtual bool isDirty () const { return hasViewFlag (kDirty); }
59  virtual void setDirty (bool val = true);
61 
62  virtual void invalidRect (const CRect& rect);
63  virtual void invalid () { setDirty (false); invalidRect (getViewSize ()); }
64 
65  virtual void setVisible (bool state);
66  bool isVisible () const { return hasViewFlag (kVisible) && getAlphaValue () > 0.f; }
67 
68 
69  //-----------------------------------------------------------------------------
71  //-----------------------------------------------------------------------------
73  virtual CMouseEventResult onMouseDown (CPoint& where, const CButtonState& buttons);
74  virtual CMouseEventResult onMouseUp (CPoint& where, const CButtonState& buttons);
75  virtual CMouseEventResult onMouseMoved (CPoint& where, const CButtonState& buttons);
76  virtual CMouseEventResult onMouseCancel ();
77 
78  virtual CMouseEventResult onMouseEntered (CPoint& where, const CButtonState& buttons) {return kMouseEventNotImplemented;}
79  virtual CMouseEventResult onMouseExited (CPoint& where, const CButtonState& buttons) {return kMouseEventNotImplemented;}
80 
81  void setHitTestPath (CGraphicsPath* path);
82  virtual bool hitTest (const CPoint& where, const CButtonState& buttons = -1);
83 
84  virtual bool onWheel (const CPoint& where, const float& distance, const CButtonState& buttons);
85  virtual bool onWheel (const CPoint& where, const CMouseWheelAxis& axis, const float& distance, const CButtonState& buttons);
86 
87  virtual void setMouseEnabled (bool bEnable = true);
88  bool getMouseEnabled () const { return hasViewFlag (kMouseEnabled); }
89 
90  virtual void setMouseableArea (const CRect& rect);
91  CRect& getMouseableArea (CRect& rect) const;
92  const CRect& getMouseableArea () const;
93 
94 
95 #if VSTGUI_TOUCH_EVENT_HANDLING
96  //-----------------------------------------------------------------------------
98  //-----------------------------------------------------------------------------
100  virtual void onTouchEvent (ITouchEvent& event) {}
101  virtual bool wantsMultiTouchEvents () const { return false; }
103 #endif
104 
105  //-----------------------------------------------------------------------------
107  //-----------------------------------------------------------------------------
109  virtual DragResult doDrag (IDataPackage* source, const CPoint& offset = CPoint (0, 0), CBitmap* dragBitmap = nullptr);
110  virtual bool onDrop (IDataPackage* drag, const CPoint& where) { return false; }
111  virtual void onDragEnter (IDataPackage* drag, const CPoint& where) {}
112  virtual void onDragLeave (IDataPackage* drag, const CPoint& where) {}
113  virtual void onDragMove (IDataPackage* drag, const CPoint& where) {}
114 
115 
116  //-----------------------------------------------------------------------------
118  //-----------------------------------------------------------------------------
120  virtual int32_t onKeyDown (VstKeyCode& keyCode);
121  virtual int32_t onKeyUp (VstKeyCode& keyCode);
122 
123 
124  //-----------------------------------------------------------------------------
126  //-----------------------------------------------------------------------------
128  CCoord getHeight () const { return getViewSize ().getHeight (); }
129  CCoord getWidth () const { return getViewSize ().getWidth (); }
130  virtual void setViewSize (const CRect& rect, bool invalid = true);
131  const CRect& getViewSize () const;
132  virtual CRect getVisibleViewSize () const;
133  virtual void parentSizeChanged () {}
134  virtual CPoint& frameToLocal (CPoint& point) const;
135  virtual CPoint& localToFrame (CPoint& point) const;
136  virtual void setAutosizeFlags (int32_t flags);
137  int32_t getAutosizeFlags () const;
138  virtual bool sizeToFit () { return false; }
139 
140 
141  //-----------------------------------------------------------------------------
143  //-----------------------------------------------------------------------------
145  virtual void looseFocus ();
146  virtual void takeFocus ();
147  virtual bool wantsFocus () const { return hasViewFlag (kWantsFocus); }
148  virtual void setWantsFocus (bool state);
149 
150 
151  //-----------------------------------------------------------------------------
153  //-----------------------------------------------------------------------------
155  bool getAttributeSize (const CViewAttributeID id, uint32_t& outSize) const;
156  bool getAttribute (const CViewAttributeID id, const uint32_t inSize, void* outData, uint32_t& outSize) const;
157  bool setAttribute (const CViewAttributeID id, const uint32_t inSize, const void* inData);
158  bool removeAttribute (const CViewAttributeID id);
159 
160 
161  //-----------------------------------------------------------------------------
163  //-----------------------------------------------------------------------------
165  virtual void setBackground (CBitmap* background);
166  CBitmap* getBackground () const;
167 
168  virtual void setDisabledBackground (CBitmap* background);
169  CBitmap* getDisabledBackground () const;
170 
171  CBitmap* getDrawBackground () const;
173 
174  //-----------------------------------------------------------------------------
176  //-----------------------------------------------------------------------------
178  virtual void setTransparency (bool val);
179  bool getTransparency () const { return hasViewFlag (kTransparencyEnabled); }
180 
181  virtual void setAlphaValue (float alpha);
182  float getAlphaValue () const;
183 
184 
185  //-----------------------------------------------------------------------------
187  //-----------------------------------------------------------------------------
189  virtual bool removed (CView* parent);
190  virtual bool attached (CView* parent);
191  bool isAttached () const { return hasViewFlag (kIsAttached); }
192 
193 
194  void setSubviewState (bool state);
195  bool isSubview () const { return hasViewFlag (kIsSubview); }
196 
197  //-----------------------------------------------------------------------------
199  //-----------------------------------------------------------------------------
201  CView* getParentView () const;
202  CFrame* getFrame () const;
203  virtual VSTGUIEditorInterface* getEditor () const;
204 
205 
206  //-----------------------------------------------------------------------------
208  //-----------------------------------------------------------------------------
210  void addAnimation (IdStringPtr name, Animation::IAnimationTarget* target, Animation::ITimingFunction* timingFunction, CBaseObject* notificationObject = nullptr);
211  void addAnimation (IdStringPtr name, Animation::IAnimationTarget* target, Animation::ITimingFunction* timingFunction, const Animation::DoneFunction& doneFunc);
212  void removeAnimation (IdStringPtr name);
213  void removeAllAnimations ();
215 
216  //-----------------------------------------------------------------------------
220  //-----------------------------------------------------------------------------
222  virtual void onIdle () {}
223  void setWantsIdle (bool state);
224  bool wantsIdle () const { return hasViewFlag (kWantsIdle); }
225  static uint32_t idleRate;
226 
227 
229  virtual bool wantsWindowActiveStateChangeNotification () const { return false; }
231  virtual void onWindowActivate (bool state) {}
232 
233  //-----------------------------------------------------------------------------
235  //-----------------------------------------------------------------------------
237  void registerViewListener (IViewListener* listener);
238  void unregisterViewListener (IViewListener* listener);
240 
241  CGraphicsTransform getGlobalTransform () const;
242  template<typename T> T& translateToGlobal (T& t) const { getGlobalTransform ().transform (t); return t; }
243  template<typename T> T translateToGlobal (const T& t) const { T tmp (t); getGlobalTransform ().transform (tmp); return tmp; }
244  template<typename T> T& translateToLocal (T& t) const { getGlobalTransform ().inverse ().transform (t); return t; }
245  template<typename T> T translateToLocal (const T& t) const { T tmp (t); getGlobalTransform ().inverse ().transform (tmp); return tmp; }
246 
247  #if DEBUG
248  virtual void dumpInfo ();
249  #endif
250 
251  virtual CViewContainer* asViewContainer () { return nullptr; }
252  virtual const CViewContainer* asViewContainer () const { return nullptr; }
253 
254  // overwrites
255  CMessageResult notify (CBaseObject* sender, IdStringPtr message) override;
256  void beforeDelete () override;
257 
258  //-------------------------------------------
259  CLASS_METHODS(CView, CBaseObject)
260 protected:
261  enum {
262  kMouseEnabled = 1 << 0,
263  kTransparencyEnabled = 1 << 1,
264  kWantsFocus = 1 << 2,
265  kIsAttached = 1 << 3,
266  kVisible = 1 << 4,
267  kDirty = 1 << 5,
268  kWantsIdle = 1 << 6,
269  kIsSubview = 1 << 7,
270  kLastCViewFlag = 7
271  };
272 
273  ~CView () noexcept override;
274 
275  CGraphicsPath* getHitTestPath () const;
276 
277  bool hasViewFlag (int32_t bit) const;
278  void setViewFlag (int32_t bit, bool state);
279 
280  void setAlphaValueNoInvalidate (float value);
281  void setParentFrame (CFrame* frame);
282  void setParentView (CView* parent);
283 
284 private:
285  struct Impl;
286  std::unique_ptr<Impl> pImpl;
287 };
288 
289 //-----------------------------------------------------------------------------
292 //-----------------------------------------------------------------------------
294 {
295 public:
296  explicit CDragContainerHelper (IDataPackage* drag);
297  CDragContainerHelper () = delete;
298 
299  void* first (int32_t& size, int32_t& type);
300  void* next (int32_t& size, int32_t& type);
301 
302  int32_t getType (int32_t idx) const;
303  int32_t getCount () const;
304 
305  enum CDragType {
306  kFile = 0,
309 
310  kUnknown = -1,
311  kError = -2
312  };
313 protected:
314 
315  IDataPackage* drag {nullptr};
316  int32_t index {0};
317 };
318 
319 } // namespace
320 
321 #endif
Helper class to port old code which used CDragContainer.
Definition: cview.h:293
virtual bool attached(CView *parent)
view is attached to a parent view
Definition: cview.cpp:359
void setWantsIdle(bool state)
enable/disable onIdle() callback
Definition: cview.cpp:323
virtual void setMouseableArea(const CRect &rect)
set the area in which the view reacts to the mouse
Definition: cview.cpp:256
virtual bool removed(CView *parent)
view is removed from parent view
Definition: cview.cpp:382
Container Class of CView objects.
Definition: cviewcontainer.h:52
bool getAttribute(const CViewAttributeID id, const uint32_t inSize, void *outData, uint32_t &outSize) const
get an attribute
Definition: cview.cpp:831
Rect structure.
Definition: crect.h:17
ASCII Text.
Definition: cview.h:307
virtual CPoint & localToFrame(CPoint &point) const
conversion from local view coordinates to frame coordinates
Definition: cview.cpp:481
virtual VSTGUIEditorInterface * getEditor() const
get editor
Definition: cview.cpp:756
virtual void onWindowActivate(bool state)
Definition: cview.h:231
UTF8 Text.
Definition: cview.h:308
T & translateToGlobal(T &t) const
translates a local coordinate to a global one using parent transforms
Definition: cview.h:242
virtual void drawRect(CDrawContext *pContext, const CRect &updateRect)
called if the view should draw itself
Definition: cview.h:55
virtual CMouseEventResult onMouseExited(CPoint &where, const CButtonState &buttons)
called when the mouse leaves this view
Definition: cview.h:79
virtual CMouseEventResult onMouseDown(CPoint &where, const CButtonState &buttons)
called when a mouse down event occurs
Definition: cview.cpp:405
void setHitTestPath(CGraphicsPath *path)
Definition: cview.cpp:442
Definition: vstkeycode.h:12
virtual void looseFocus()
called if view should loose focus
Definition: cview.cpp:622
T translateToLocal(const T &t) const
translates a local coordinate to a global one using parent transforms
Definition: cview.h:245
float getAlphaValue() const
get alpha value
Definition: cview.cpp:714
virtual CMouseEventResult onMouseEntered(CPoint &where, const CButtonState &buttons)
called when the mouse enters this view
Definition: cview.h:78
virtual DragResult doDrag(IDataPackage *source, const CPoint &offset=CPoint(0, 0), CBitmap *dragBitmap=nullptr)
start a drag operation. See CDropSource to create the source data package
Definition: cview.cpp:600
A drawing context encapsulates the drawing context of the underlying OS.
Definition: cdrawcontext.h:29
virtual CPoint & frameToLocal(CPoint &point) const
conversion from frame coordinates to local view coordinates
Definition: cview.cpp:469
static uint32_t idleRate
global idle rate in Hz, defaults to 30 Hz
Definition: cview.h:225
Base Object with reference counter.
Definition: vstguibase.h:276
virtual void parentSizeChanged()
notification that one of the views parent has changed its size
Definition: cview.h:133
bool isVisible() const
get visibility state
Definition: cview.h:66
CBitmap * getBackground() const
get the background image of this view
Definition: cview.cpp:773
virtual CMouseEventResult onMouseMoved(CPoint &where, const CButtonState &buttons)
called when a mouse move event occurs
Definition: cview.cpp:427
virtual void setWantsFocus(bool state)
set focus support on/off
Definition: cview.cpp:317
bool removeAttribute(const CViewAttributeID id)
remove an attribute
Definition: cview.cpp:868
virtual bool onDrop(IDataPackage *drag, const CPoint &where)
called if a drag is dropped onto this view
Definition: cview.h:110
CCoord getWidth() const
get the width of the view
Definition: cview.h:129
CDragType
Definition: cview.h:305
Graphics Path Object.
Definition: cgraphicspath.h:19
CView * getParentView() const
get parent view
Definition: cview.cpp:744
virtual bool hitTest(const CPoint &where, const CButtonState &buttons=-1)
check if where hits this view
Definition: cview.cpp:453
bool setAttribute(const CViewAttributeID id, const uint32_t inSize, const void *inData)
set an attribute
Definition: cview.cpp:855
virtual bool onWheel(const CPoint &where, const float &distance, const CButtonState &buttons)
called if a mouse wheel event is happening over this view
Definition: cview.cpp:547
virtual void setAutosizeFlags(int32_t flags)
set autosize flags
Definition: cview.cpp:720
virtual void setTransparency(bool val)
set views transparent state
Definition: cview.cpp:307
virtual CMouseEventResult onMouseCancel()
called when mouse tracking should be canceled
Definition: cview.cpp:433
virtual CMouseEventResult onMouseUp(CPoint &where, const CButtonState &buttons)
called when a mouse up event occurs
Definition: cview.cpp:416
virtual void setViewSize(const CRect &rect, bool invalid=true)
set views size
Definition: cview.cpp:642
Encapsulates various platform depended kinds of bitmaps.
Definition: cbitmap.h:21
bool getAttributeSize(const CViewAttributeID id, uint32_t &outSize) const
get the size of an attribute
Definition: cview.cpp:812
CBitmap * getDisabledBackground() const
get background image used when the mouse is not enabled
Definition: cview.cpp:779
Definition: customcontrols.cpp:8
virtual void onDragMove(IDataPackage *drag, const CPoint &where)
called if a drag is moved inside this view
Definition: cview.h:113
bool getTransparency() const
get views transparent state
Definition: cview.h:179
bool isAttached() const
is view attached to a parentView
Definition: cview.h:191
virtual void invalidRect(const CRect &rect)
mark rect as invalid
Definition: cview.cpp:518
virtual void setMouseEnabled(bool bEnable=true)
turn on/off mouse usage for this view
Definition: cview.cpp:293
int32_t getAutosizeFlags() const
get autosize flags
Definition: cview.cpp:726
Button and Modifier state.
Definition: cbuttonstate.h:34
virtual void onIdle()
called on idle when view wants idle
Definition: cview.h:222
const CRect & getViewSize() const
read only access to view size
Definition: cview.cpp:661
virtual void setDirty(bool val=true)
set the view to dirty so that it is redrawn in the next idle. Thread Safe !
Definition: cview.cpp:333
virtual void onDragLeave(IDataPackage *drag, const CPoint &where)
called if a drag is leaving this view
Definition: cview.h:112
static bool kDirtyCallAlwaysOnMainThread
if this is true, setting a view dirty will call invalid() instead of checking it in idle...
Definition: cview.h:60
T & translateToLocal(T &t) const
translates a global coordinate to a local one using parent transforms
Definition: cview.h:244
const CRect & getMouseableArea() const
read only access to the mouseable area
Definition: cview.cpp:269
Base Class of all view objects.
Definition: cview.h:44
View Listener Interface.
Definition: iviewlistener.h:15
virtual bool sizeToFit()
resize view to optimal size
Definition: cview.h:138
interface for drag&drop and clipboard data
Definition: idatapackage.h:15
Graphics Transform Matrix.
Definition: cgraphicstransform.h:23
virtual void setBackground(CBitmap *background)
set the background image of this view
Definition: cview.cpp:765
virtual CRect getVisibleViewSize() const
returns the visible size of the view
Definition: cview.cpp:670
bool getMouseEnabled() const
get the state of wheather this view uses the mouse or not
Definition: cview.h:88
CFrame * getFrame() const
get frame
Definition: cview.cpp:750
virtual void draw(CDrawContext *pContext)
called if the view should draw itself
Definition: cview.cpp:531
virtual void invalid()
mark whole view as invalid
Definition: cview.h:63
virtual int32_t onKeyUp(VstKeyCode &keyCode)
called if a key up event occurs and this view has focus
Definition: cview.cpp:587
CCoord getHeight() const
get the height of the view
Definition: cview.h:128
virtual void takeFocus()
called if view should take focus
Definition: cview.cpp:630
virtual int32_t onKeyDown(VstKeyCode &keyCode)
called if a key down event occurs and this view has focus
Definition: cview.cpp:577
virtual bool isDirty() const
check if view is dirty
Definition: cview.h:58
virtual void setDisabledBackground(CBitmap *background)
set background image used when the mouse is not enabled
Definition: cview.cpp:794
Point structure.
Definition: cpoint.h:17
T translateToGlobal(const T &t) const
translates a local coordinate to a global one using parent transforms
Definition: cview.h:243
virtual void onDragEnter(IDataPackage *drag, const CPoint &where)
called if a drag is entering this view
Definition: cview.h:111
virtual bool wantsFocus() const
check if view supports focus
Definition: cview.h:147
virtual void setVisible(bool state)
set visibility state
Definition: cview.cpp:678
virtual void setAlphaValue(float alpha)
set alpha value which will be applied when drawing this view
Definition: cview.cpp:702
bool wantsIdle() const
returns if the view wants idle callback or not
Definition: cview.h:224
virtual bool wantsWindowActiveStateChangeNotification() const
Definition: cview.h:229
CMessageResult notify(CBaseObject *sender, IdStringPtr message) override
Definition: cview.cpp:616