iPlug2 - C++ Audio Plug-in Framework
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 
22 class TestFontControl : public IControl
23 {
24  static const int size = 36;
25 
26 public:
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 
92 private:
93 
94  int mCount;
95  int mFontCount;
96  int mStrCount;
97 };
The lowest level base class of an IGraphics control.
Definition: IControl.h:42
Used to manage a rectangular area, independent of draw class/platform.
Used to manage mouse modifiers i.e.
void SetTooltip(const char *str)
Set a tooltip for the control.
Definition: IControl.h:210
Used to manage color data, independent of draw class/platform.
void Draw(IGraphics &g) override
Draw the control to the graphics context.
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:631
This file contains the base IControl implementation, along with some base classes for specific types ...
float W() const
IText is used to manage font and text/text entry style for a piece of text on the UI...
IControl(const IRECT &bounds, int paramIdx=kNoParameter, IActionFunction actionFunc=nullptr)
Constructor.
Definition: IControl.cpp:81
void OnMouseDown(float x, float y, const IMouseMod &mod) override
Implement this method to respond to a mouse down event on this control.
The lowest level base class of an IGraphics context.
Definition: IGraphics.h:86
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:2547
IRECT GetCentredInside(const IRECT &sr) const
Get a rectangle the size of sr but with the same center point as this rectangle.
Control to test drawing fonts.
IRECT GetFromBottom(float amount) const
Get a subrect of this IRECT bounded in Y by 'amount' and the bottom edge.
IRECT GetFromTop(float amount) const
Get a subrect of this IRECT bounded in Y by the top edge and 'amount'.
virtual void SetDirty(bool triggerAction=true, int valIdx=kNoValIdx)
Mark the control as dirty, i.e.
Definition: IControl.cpp:196