iPlug2 - C++ Audio Plug-in Framework
Loading...
Searching...
No Matches
TestTextSizeControl.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 = 14;
25
26public:
27 TestTextSizeControl(const IRECT& bounds, int paramIdx)
28 : IKnobControlBase(bounds, paramIdx)
29 , mCount(-1)
30 {
31 SetTooltip("TestTextSizeControl");
32 mDblAsSingleClick = true;
33 Next();
34 SetValue(0.2);
35 }
36
37 void Draw(IGraphics& g) override
38 {
39 const char* str = "Some Text To Resize";
40 mText.mSize = static_cast<float>(GetValue()) * 100.f + 12.f;
41
42 g.FillRect(COLOR_WHITE, mRECT);
43 g.DrawText(mText, str, mRECT);
44 }
45
46 void OnMouseDown(float x, float y, const IMouseMod& mod) override
47 {
48 mDrag = false;
49 }
50
51 void OnMouseUp(float x, float y, const IMouseMod& mod) override
52 {
53 if (!mDrag)
54 {
55 Next();
56 SetDirty(false);
57 }
58 }
59
60 void OnMouseDrag(float x, float y, float dX, float dY, const IMouseMod& mod) override
61 {
62 mDrag = true;
63 IKnobControlBase::OnMouseDrag(x, y, dX, dY, mod);
64 }
65
66 void Next()
67 {
68 if (++mCount > 8)
69 mCount = 0;
70
71 IColor c = DEFAULT_TEXT_FGCOLOR;
72 const char* font = "Roboto-Regular";
73 if (mCount == 0)
74 mText = IText(size, c, font, EAlign::Near, EVAlign::Top);
75 else if (mCount == 1)
76 mText = IText(size, c, font, EAlign::Center, EVAlign::Top);
77 else if (mCount == 2)
78 mText = IText(size, c, font, EAlign::Far, EVAlign::Top);
79 else if (mCount == 3)
80 mText = IText(size, c, font, EAlign::Near, EVAlign::Middle);
81 else if (mCount == 4)
82 mText = IText(size, c, font, EAlign::Center, EVAlign::Middle);
83 else if (mCount == 5)
84 mText = IText(size, c, font, EAlign::Far, EVAlign::Middle);
85 else if (mCount == 6)
86 mText = IText(size, c, font, EAlign::Near, EVAlign::Bottom);
87 else if (mCount == 7)
88 mText = IText(size, c, font, EAlign::Center, EVAlign::Bottom);
89 else
90 mText = IText(size, c, font, EAlign::Far, EVAlign::Bottom);
91 }
92
93private:
94 bool mDrag = false;
95 int mCount;
96};
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
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 varying size.
void Draw(IGraphics &g) override
Draw the control to the graphics context.
void OnMouseDown(float x, float y, const IMouseMod &mod) override
Implement this method to respond to a mouse down 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.
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.
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,...