forked from osoumen/C700
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLabelOnOffButton.cpp
83 lines (73 loc) · 1.95 KB
/
LabelOnOffButton.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
/*
* LabelOnOffButton.cpp
* 文字ラベル付きオンオフボタン
*
* Created by osoumen on 12/10/03.
* Copyright 2012 __MyCompanyName__. All rights reserved.
*
*/
#include "LabelOnOffButton.h"
extern CFontRef kLabelFont;
//-----------------------------------------------------------------------------
CLabelOnOffButton::CLabelOnOffButton(const CRect& size, CControlListener* listener, long tag, CBitmap* background, const char *txt, long style)
: COnOffButton(size, listener, tag, background, style)
, text(NULL)
{
mLabelFont = new CFontDesc(*kLabelFont);
setText(txt);
}
//-----------------------------------------------------------------------------
CLabelOnOffButton::~CLabelOnOffButton()
{
freeText();
mLabelFont->forget();
}
//------------------------------------------------------------------------
void CLabelOnOffButton::freeText()
{
if (text)
{
free(text);
}
text = 0;
}
//-----------------------------------------------------------------------------
void CLabelOnOffButton::setText(const char* txt)
{
if ((!text && !txt) || (text && txt && strcmp(text, txt) == 0))
{
return;
}
freeText();
if (txt)
{
text = (char*)malloc(strlen(txt)+1);
strcpy(text, txt);
}
setDirty(true);
}
//-----------------------------------------------------------------------------
const char* CLabelOnOffButton::getText() const
{
return text;
}
//-----------------------------------------------------------------------------
void CLabelOnOffButton::draw(CDrawContext* pContext)
{
COnOffButton::draw(pContext);
//文字を描画
// CRect oldClip;
// pContext->getClipRect(oldClip);
CRect newClip(size);
newClip.offset( getBackground()->getWidth(), 0 );
// newClip.bound(oldClip);
// pContext->setClipRect(newClip);
pContext->setFont(mLabelFont);
pContext->setFontColor(kBlackCColor);
#if VSTGUI_USES_UTF8
pContext->drawStringUTF8(text, newClip, kLeftText, true);
#else
pContext->drawString(text, newClip, true, kLeftText);
#endif
// pContext->setClipRect(oldClip);
}