iPlug2 - C++ Audio Plug-in Framework
Loading...
Searching...
No Matches
TestFontControl.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 TestFontControl(const IRECT& bounds)
28 : IControl(bounds), mCount(-1), mFontCount(0), mStrCount(0)
29 {
30 SetTooltip("TestFontControl");
31 mDblAsSingleClick = true;
32 Next();
33 }
34
35 void Draw(IGraphics& g) override
36 {
37 int pos = mCount / 3;
38 IRECT rect = mRECT;
39
40 if (pos == 0)
41 rect = mRECT.GetFromTop(size);
42 else if (pos == 1)
43 rect = mRECT.GetCentredInside(mRECT.W(), size);
44 else
45 rect = mRECT.GetFromBottom(size);
46
47 const char* str = mStrCount ? "Quickly dog" : "Font Test";
48
49 g.FillRect(COLOR_WHITE, mRECT);
50 g.FillRect(COLOR_MID_GRAY, rect);
51 g.DrawText(mText, str, mRECT);
52 }
53
54 void OnMouseDown(float x, float y, const IMouseMod& mod) override
55 {
56 Next();
57 SetDirty(false);
58 }
59
60 void Next()
61 {
62 if (++mCount > 8)
63 {
64 mCount = 0;
65 mFontCount = 1 - mFontCount;
66 }
67
68 mStrCount = 1 - mStrCount;
69
70 IColor c = DEFAULT_TEXT_FGCOLOR;
71 const char* font = mFontCount ? "Roboto-Regular" : "Alternative Font";
72 if (mCount == 0)
73 mText = IText(size, c, font, EAlign::Near, EVAlign::Top);
74 else if (mCount == 1)
75 mText = IText(size, c, font, EAlign::Center, EVAlign::Top);
76 else if (mCount == 2)
77 mText = IText(size, c, font, EAlign::Far, EVAlign::Top);
78 else if (mCount == 3)
79 mText = IText(size, c, font, EAlign::Near, EVAlign::Middle);
80 else if (mCount == 4)
81 mText = IText(size, c, font, EAlign::Center, EVAlign::Middle);
82 else if (mCount == 5)
83 mText = IText(size, c, font, EAlign::Far, EVAlign::Middle);
84 else if (mCount == 6)
85 mText = IText(size, c, font, EAlign::Near, EVAlign::Bottom);
86 else if (mCount == 7)
87 mText = IText(size, c, font, EAlign::Center, EVAlign::Bottom);
88 else
89 mText = IText(size, c, font, EAlign::Far, EVAlign::Bottom);
90 }
91
92private:
93
94 int mCount;
95 int mFontCount;
96 int mStrCount;
97};
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
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 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 drawing fonts.
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.
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.
IRECT GetFromBottom(float amount) const
Get a subrect of this IRECT bounded in Y by 'amount' and the bottom edge.
IRECT GetCentredInside(const IRECT &sr) const
Get a rectangle the size of sr but with the same center point as this rectangle.
float W() const
IRECT GetFromTop(float amount) const
Get a subrect of this IRECT bounded in Y by the top edge and 'amount'.
IText is used to manage font and text/text entry style for a piece of text on the UI,...