iPlug2 - C++ Audio Plug-in Framework
Loading...
Searching...
No Matches
TestCursorControl.h
Go to the documentation of this file.
1/*
2 ==============================================================================
3
4 This file is part of the iPlug 2 library. Copyright (C) the iPlug 2 developers.
5
6 See LICENSE.txt for more info.
7
8 ==============================================================================
9*/
10
11#pragma once
12
18#include "IControl.h"
19
23{
24public:
25 TestCursorControl(IRECT rect, int paramIdx = kNoParameter)
26 : IControl(rect, paramIdx)
27 {
28 SetTooltip("TestCursorControl");
29 }
30
31 void Draw(IGraphics& g) override
32 {
33 g.DrawDottedRect(COLOR_BLACK, mRECT);
34 g.FillRect(mMouseIsOver ? COLOR_TRANSLUCENT : COLOR_TRANSPARENT, mRECT);
35 g.DrawText(mText, GetCursorStr(mCursor), mRECT);
36 }
37
38 void OnMouseDown(float x, float y, const IMouseMod& mod) override
39 {
40 mCursor++;
41
42 if (mCursor > static_cast<int>(ECursor::HELP))
43 mCursor = -1;
44
45 GetUI()->SetMouseCursor((ECursor) std::max(0, mCursor));
46
47 SetDirty(false);
48 }
49
50 void OnMouseOut() override
51 {
52 mCursor = -1;
53 GetUI()->SetMouseCursor(ECursor::ARROW);
54
56 }
57
58private:
59 const char* GetCursorStr(int cursor)
60 {
61 if(cursor == -1)
62 return "Click to set cursor";
63
64 switch (static_cast<ECursor>(cursor))
65 {
66 case ECursor::ARROW: return "arrow";
67 case ECursor::IBEAM: return "ibeam";
68 case ECursor::WAIT: return "wait";
69 case ECursor::CROSS: return "cross";
70 case ECursor::UPARROW: return "up arrow";
71 case ECursor::SIZENWSE: return "size NW-SE";
72 case ECursor::SIZENESW: return "size NE-SW";
73 case ECursor::SIZEWE: return "size WE";
74 case ECursor::SIZENS: return "size NS";
75 case ECursor::SIZEALL: return "size all";
76 case ECursor::INO: return "no";
77 case ECursor::HAND: return "hand";
78 case ECursor::APPSTARTING: return "app starting";
79 case ECursor::HELP: return "help";
80 }
81
82 return "";
83 }
84
85 int mCursor = -1;
86};
This file contains the base IControl implementation, along with some base classes for specific types ...
The lowest level base class of an IGraphics control.
Definition: IControl.h:49
IGraphics * GetUI()
Definition: IControl.h:467
virtual void OnMouseOut()
Implement this method to respond to a mouseout event on this control.
Definition: IControl.cpp:275
bool mMouseIsOver
if mGraphics::mHandleMouseOver = true, this will be true when the mouse is over control.
Definition: IControl.h:560
IControl * SetTooltip(const char *str)
Set a tooltip for the control.
Definition: IControl.h:216
virtual void SetDirty(bool triggerAction=true, int valIdx=kNoValIdx)
Mark the control as dirty, i.e.
Definition: IControl.cpp:198
The lowest level base class of an IGraphics context.
Definition: IGraphics.h:86
void DrawText(const IText &text, const char *str, const IRECT &bounds, const IBlend *pBlend=0)
Draw some text to the graphics context in a specific rectangle.
Definition: IGraphics.cpp:670
virtual ECursor SetMouseCursor(ECursor cursorType=ECursor::ARROW)
Sets the mouse cursor to one of ECursor (implementations should return the result of the base impleme...
Definition: IGraphics.h:828
virtual void DrawDottedRect(const IColor &color, const IRECT &bounds, const IBlend *pBlend=0, float thickness=1.f, float dashLen=2.f)
Draw a dotted rectangle to the graphics context.
Definition: IGraphics.cpp:2539
virtual void FillRect(const IColor &color, const IRECT &bounds, const IBlend *pBlend=0)
Fill a rectangular region of the graphics context with a color.
Definition: IGraphics.cpp:2569
Control to test changing the platform cursor.
void OnMouseDown(float x, float y, const IMouseMod &mod) override
Implement this method to respond to a mouse down event on this control.
void OnMouseOut() override
Implement this method to respond to a mouseout event on this control.
void Draw(IGraphics &g) override
Draw the control to the graphics context.
Used to manage mouse modifiers i.e.
Used to manage a rectangular area, independent of draw class/platform.