-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathTextBox.cpp
105 lines (95 loc) · 2.43 KB
/
TextBox.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
#include "TextBox.h"
#include "SpectralHarp.h"
TextBox::TextBox(IPlugBase* pPlug, IRECT pR, int paramIdx, IText* pText, IGraphics* pGraphics, const char * maxText, bool showParamUnits, float scrollSpeed)
: ICaptionControl(pPlug, pR, paramIdx, pText, showParamUnits)
, mTextRect(pR)
, mScrollSpeed(scrollSpeed)
{
mTextRect = pR.GetHPadded(-3);
pGraphics->MeasureIText(pText, const_cast<char*>(maxText), &mTextRect);
#ifdef OS_OSX
mTextRect.B -= 4;
#endif
const int offset = (mRECT.H() - mTextRect.H()) / 2;
mTextRect.T += offset;
mTextRect.B += offset;
SetTextEntryLength(strlen(maxText) - 1);
}
bool TextBox::Draw(IGraphics* pGraphics)
{
pGraphics->FillIRect(&mText.mTextEntryBGColor, &mRECT);
IColor* borderColor = &mText.mTextEntryFGColor;
const int bi = 2;
const int bt = mRECT.T;
const int bb = mRECT.B - 1;
// bracket on left side
pGraphics->DrawLine(borderColor, mRECT.L, bt, mRECT.L, bb);
pGraphics->DrawLine(borderColor, mRECT.L, bt, mRECT.L + bi, bt);
pGraphics->DrawLine(borderColor, mRECT.L, bb, mRECT.L + bi, bb);
// bracket on right side
pGraphics->DrawLine(borderColor, mRECT.R, bt, mRECT.R, bb);
pGraphics->DrawLine(borderColor, mRECT.R, bt, mRECT.R - bi, bt);
pGraphics->DrawLine(borderColor, mRECT.R, bb, mRECT.R - bi, bb);
IRECT ourRect = mRECT;
mRECT = mTextRect;
if (IsGrayed())
{
char display[32];
GetParam()->GetDisplayForHost(mValue, true, display, false);
mStr.Set(display);
ITextControl::Draw(pGraphics);
}
else
{
ICaptionControl::Draw(pGraphics);
}
mRECT = ourRect;
return true;
}
void TextBox::OnMouseDown(int x, int y, IMouseMod* pMod)
{
if (pMod->L)
{
IText ourText = mText;
IRECT promptRect = mTextRect;
#if defined(OS_OSX)
mText.mSize -= 2;
promptRect.T -= 1;
#endif
mPlug->GetGUI()->PromptUserInput(this, mPlug->GetParam(mParamIdx), &promptRect);
mText = ourText;
Redraw();
}
else if (pMod->R)
{
SpectralHarp* plug = static_cast<SpectralHarp*>(mPlug);
if (plug != nullptr)
{
plug->BeginMIDILearn(mParamIdx, -1, x, y);
}
}
}
void TextBox::OnMouseWheel(int x, int y, IMouseMod* pMod, int d)
{
#ifdef PROTOOLS
if (pMod->C)
{
mValue += GetParam()->GetStep() * mScrollSpeed/10 * d;
}
#else
if (pMod->C || pMod->S)
{
mValue += GetParam()->GetStep() * mScrollSpeed/10 * d;
}
#endif
else
{
mValue += GetParam()->GetStep() * mScrollSpeed * d;
}
SetDirty();
}
void TextBox::GrayOut(bool gray)
{
ICaptionControl::GrayOut(gray);
mText.mColor.A = gray ? 128 : 255;
}