iPlug2 - C++ Audio Plug-in Framework
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 
26 public:
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 
95 private:
96  bool mDrag = false;
97  int mCount;
98 };
Used to manage a rectangular area, independent of draw class/platform.
Used to manage mouse modifiers i.e.
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 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 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
Control to test drawing text with orientation.
This file contains the base IControl implementation, along with some base classes for specific types ...
void OnMouseUp(float x, float y, const IMouseMod &mod) override
Implement this method to respond to a mouse up event on this control.
IText is used to manage font and text/text entry style for a piece of text on the UI...
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
A base class for knob/dial controls, to handle mouse action and Sender.
Definition: IControl.h:1191
double GetValue(int valIdx=0) const
Get the control&#39;s value.
Definition: IControl.cpp:151
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:817
virtual void SetValue(double value, int valIdx=0)
Set one of the control&#39;s values.
Definition: IControl.cpp:145
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.
virtual float MeasureText(const IText &text, const char *str, IRECT &bounds) const
Measure the rectangular region that some text will occupy.
Definition: IGraphics.cpp:639
virtual void SetDirty(bool triggerAction=true, int valIdx=kNoValIdx)
Mark the control as dirty, i.e.
Definition: IControl.cpp:196