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
|
#include "DialogButton.h"
#include "NativeFont.h"
#include "WidgetManager.h"
#include "SexyAppBase.h"
using namespace Sexy;
static int gDialogButtonColors[][3] = {
{255, 255, 255},
{220, 220, 220},
{0, 0, 0},
{255, 255, 255},
{132, 132, 132},
{212, 212, 212}};
DialogButton::DialogButton(Image* theComponentImage, int theId, ButtonListener* theListener) :
ButtonWidget(theId, theListener)
{
mComponentImage = theComponentImage;
mTextOffsetX = mTextOffsetY = 0;
mTranslateX = mTranslateY = 1;
mDoFinger = true;
SetColors(gDialogButtonColors, NUM_COLORS);
}
void DialogButton::Draw(Graphics* g)
{
if (mBtnNoDraw)
return;
if (mComponentImage==NULL)
{
ButtonWidget::Draw(g);
return;
}
if ((mFont == NULL) && (mLabel.length() > 0))
mFont = mWidgetManager->mApp->mDDInterface->CreateFont
(mWidgetManager->mApp, "Arial Unicode MS", 12, true);
bool doTranslate = IsButtonDown();
if (mNormalRect.mWidth==0)
{
if (doTranslate)
g->Translate(mTranslateX, mTranslateY);
g->DrawImageBox(Rect(0, 0, mWidth, mHeight), mComponentImage);
}
else
{
if (mDisabled && (mDisabledRect.mWidth > 0) && (mDisabledRect.mHeight > 0))
g->DrawImageBox(mDisabledRect, Rect(0, 0, mWidth, mHeight), mComponentImage);
else if (IsButtonDown())
g->DrawImageBox(mDownRect, Rect(0, 0, mWidth, mHeight), mComponentImage);
else if ((mOverAlpha > 0))
{
if (mOverAlpha<1)
g->DrawImageBox(mNormalRect, Rect(0, 0, mWidth, mHeight), mComponentImage);
g->SetColorizeImages(true);
g->SetColor(Color(255,255,255,(int)(mOverAlpha * 255)));
g->DrawImageBox(mOverRect, Rect(0, 0, mWidth, mHeight), mComponentImage);
g->SetColorizeImages(false);
}
else if(mIsOver || mHasFocus)
g->DrawImageBox(mOverRect, Rect(0, 0, mWidth, mHeight), mComponentImage);
else
g->DrawImageBox(mNormalRect, Rect(0, 0, mWidth, mHeight), mComponentImage);
if (doTranslate)
g->Translate(mTranslateX, mTranslateY);
}
if (mFont != NULL)
{
g->SetFont(mFont);
if (mIsOver || mHasFocus)
g->SetColor(mColors[COLOR_LABEL_HILITE]);
else
g->SetColor(mColors[COLOR_LABEL]);
//int aFontX = (mWidth - mFont->StringWidth(mLabel))/2;
int aFontX = (mWidth - mLabelText.GetWidth())/2;
int aFontY = (mHeight + mFont->GetAscent() - mFont->GetAscentPadding() - mFont->GetAscent()/6 - 1)/2;
//g->DrawString(mLabel, aFontX + mTextOffsetX, aFontY + mTextOffsetY);
mLabelText.Draw(g, aFontX + mTextOffsetX, aFontY + mTextOffsetY,
g->GetColor());
}
if (doTranslate)
g->Translate(-mTranslateX, -mTranslateY);
}
|