iPlug2 - C++ Audio Plug-in Framework
Loading...
Searching...
No Matches
TestTextOrientationControl.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{
24 static const int size = 36;
25
26public:
27 TestTextOrientationControl(const IRECT& bounds, int paramIdx)
28 : IKnobControlBase(bounds, paramIdx), mCount(-1)
29 {
30 SetTooltip("TestTextOrientationControl");
31 mDblAsSingleClick = true;
32 Next();
33 SetValue(0.5);
34 }
35
36 void Draw(IGraphics& g) override
37 {
38 IRECT drawRECT = mRECT;
39 const char* str = "Some Text To Rotate";
40 mText.mAngle = static_cast<float>(GetValue()) * 360.f - 180.f;
41
42 g.MeasureText(mText, str, drawRECT);
43 g.FillRect(COLOR_WHITE, mRECT);
44 g.FillRect(COLOR_MID_GRAY, drawRECT);
45 g.DrawText(mText, str, mRECT);
46 }
47
48 void OnMouseDown(float x, float y, const IMouseMod& mod) override
49 {
50 mDrag = false;
51 }
52
53 void OnMouseUp(float x, float y, const IMouseMod& mod) override
54 {
55 if (!mDrag)
56 {
57 Next();
58 SetDirty(false);
59 }
60 }
61
62 void OnMouseDrag(float x, float y, float dX, float dY, const IMouseMod& mod) override
63 {
64 mDrag = true;
65 IKnobControlBase::OnMouseDrag(x, y, dX, dY, mod);
66 }
67
68 void Next()
69 {
70 if (++mCount > 8)
71 mCount = 0;
72
73 IColor c = DEFAULT_TEXT_FGCOLOR;
74 const char* font = "Roboto-Regular";
75 if (mCount == 0)
76 mText = IText(size, c, font, EAlign::Near, EVAlign::Top);
77 else if (mCount == 1)
78 mText = IText(size, c, font, EAlign::Center, EVAlign::Top);
79 else if (mCount == 2)
80 mText = IText(size, c, font, EAlign::Far, EVAlign::Top);
81 else if (mCount == 3)
82 mText = IText(size, c, font, EAlign::Near, EVAlign::Middle);
83 else if (mCount == 4)
84 mText = IText(size, c, font, EAlign::Center, EVAlign::Middle);
85 else if (mCount == 5)
86 mText = IText(size, c, font, EAlign::Far, EVAlign::Middle);
87 else if (mCount == 6)
88 mText = IText(size, c, font, EAlign::Near, EVAlign::Bottom);
89 else if (mCount == 7)
90 mText = IText(size, c, font, EAlign::Center, EVAlign::Bottom);
91 else
92 mText = IText(size, c, font, EAlign::Far, EVAlign::Bottom);
93 }
94
95private:
96 bool mDrag = false;
97 int mCount;
98};
This file contains the base IControl implementation, along with some base classes for specific types ...
IControl * SetTooltip(const char *str)
Set a tooltip for the control.
Definition: IControl.h:216
virtual void SetValue(double value, int valIdx=0)
Set one of the control's values.
Definition: IControl.cpp:147
double GetValue(int valIdx=0) const
Get the control's value.
Definition: IControl.cpp:153
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 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
virtual float MeasureText(const IText &text, const char *str, IRECT &bounds) const
Measure the rectangular region that some text will occupy.
Definition: IGraphics.cpp:678
A base class for knob/dial controls, to handle mouse action and Sender.
Definition: IControl.h:1368
void OnMouseDrag(float x, float y, float dX, float dY, const IMouseMod &mod) override
Implement this method to respond to a mouse drag event on this control.
Definition: IControl.cpp:819
Control to test drawing text with orientation.
void OnMouseDown(float x, float y, const IMouseMod &mod) override
Implement this method to respond to a mouse down event on this control.
void Draw(IGraphics &g) override
Draw the control to the graphics context.
void OnMouseDrag(float x, float y, float dX, float dY, const IMouseMod &mod) override
Implement this method to respond to a mouse drag event on this control.
void OnMouseUp(float x, float y, const IMouseMod &mod) override
Implement this method to respond to a mouse up event on this control.
Used to manage color data, independent of draw class/platform.
Used to manage mouse modifiers i.e.
Used to manage a rectangular area, independent of draw class/platform.
IText is used to manage font and text/text entry style for a piece of text on the UI,...