iPlug2 - C++ Audio Plug-in Framework
Loading...
Searching...
No Matches
TestTextControl.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{
24public:
25 TestTextControl(const IRECT& bounds)
26 : IControl(bounds)
27 {
28 SetTooltip("TestTextControl");
29 Randomise();
30 }
31
32 void Draw(IGraphics& g) override
33 {
34 const char* words[] = { "there", "are many" , "possible", "ways", "to display text", "here" };
35
36 g.FillRect(COLOR_WHITE, mRECT);
37 g.DrawText(mText, words[mStringIndex], mRECT);
38 }
39
40 void OnMouseDown(float x, float y, const IMouseMod& mod) override
41 {
42 Randomise();
43 SetDirty(false);
44 }
45
46 void OnMouseDblClick(float x, float y, const IMouseMod& mod) override
47 {
48 GetUI()->CreateTextEntry(*this, mText, mRECT);
49 SetDirty(false);
50 }
51
52 void Randomise()
53 {
54 int size = (std::rand() % 200) + 12;
55 int align = (std::rand() % 3);
56 int valign = (std::rand() % 3);
57 int type = (std::rand() % 2);
58 mStringIndex = (std::rand() % 6);
59
60 const char* types[] = { "Roboto-Regular", "Montserrat-LightItalic" };
61
62 mText = IText(static_cast<float>(size), IColor::GetRandomColor(), types[type], (EAlign) align, (EVAlign) valign);
63 }
64
65private:
66 int mStringIndex;
67};
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
IGraphics * GetUI()
Definition: IControl.h:467
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
void CreateTextEntry(IControl &control, const IText &text, const IRECT &bounds, const char *str="", int valIdx=0)
Create a text entry box.
Definition: IGraphics.cpp:1923
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 text.
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 OnMouseDblClick(float x, float y, const IMouseMod &mod) override
Implement this method to respond to a mouse double click event on this control.
static IColor GetRandomColor(bool randomAlpha=false)
Get a random IColor.
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,...