-
Notifications
You must be signed in to change notification settings - Fork 1
/
GCP_Button.cpp
93 lines (75 loc) · 2.57 KB
/
GCP_Button.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
#include "GCP_FormComponent.h"
#include "GCP_Button.h"
using namespace gcp;
GCP_Button::GCP_Button()
{
_iType = GCP_BUTTON_SHARPRECT; //ïðàìåòð - êàêèå ó êíîïêè óãëû
_bChecked = false; //ñîñòîÿíèå êíîïêè åñëè íàæàòà
setStyle(GCP_ButtonWhiteStyle);
}
gcp_formEvent GCP_Button::OnEvent(const GCP_Event &event)
{
basicOnEvent(event);
if (event.eventType == GCP_ON_GLEFT_CLICK || event.eventType == GCP_ON_LEFT_CLICK)
_isMouseOver = false;
gcp_formEvent evt;
evt.isEventInsideForm = false;
return evt;
}
void GCP_Button::OnDraw(const GCP_Event &event)
{
if(!isVisible())
return;
gcp_spStyle ptrStyle = getStyle();
GCP_Color cTColor = ptrStyle->textColor;
GCP_Color cBColor = ptrStyle->backgroundColor;
//Öâåòà òîæå íàäî â ñòðóêòóðó ñäåëàòü
if(_isMouseOver)
{
cBColor = ptrStyle->backgroundMouseHoverColor;
cTColor = ptrStyle->textMouseHoverColor;
}
if (!_isEnabled)
{
cBColor = ptrStyle->backgroundDisabledColor;
cTColor = ptrStyle->textDisabledColor;
}
if(_bChecked)
cBColor = ptrStyle->backgroundMouseHoverColor;
//Åñëè êíîïêå ïðèñâîåí ôàéëèê ñ èêîíêîé
if(_sIconPath != "") {
//Ðèñóåì êîíòóð
if (_iType==GCP_BUTTON_ROUNDRECT)
GCP_Draw::Render()->Draw_FillRound(_position, ptrStyle->roundCff, cBColor);
if (_iType==GCP_BUTTON_SHARPRECT)
GCP_Draw::Render()->Draw_FillRect(_position, cBColor);
//GCP_Draw::Render()->SetBlendMode(E_BLEND_ADD);
GCP_Draw::Render()->Draw_Image(_sIconPath, _position.x() + 2, _position.y() + 2);
//GCP_Draw::Render()->SetBlendMode(E_BLEND_NONE);
}
else {
//Ïðîñòî âûâîäèì íàäïèñü
string sCaption = getCaption();
gcpUint8 alphaOrig = GCP_Draw::Render()->GetAlpha();
if (_iType==GCP_BUTTON_ROUNDRECT)
{
GCP_Draw::Render()->SetAlpha(ptrStyle->drawTextBackgroundAlpha);
GCP_Draw::Render()->Draw_FillRound(_position, ptrStyle->roundCff, cBColor);
GCP_Draw::Render()->SetAlpha(alphaOrig);
GCP_Draw::Render()->Draw_Round(_position, ptrStyle->roundCff, ptrStyle->borderColor);
}
if (_iType==GCP_BUTTON_SHARPRECT)
{
GCP_Draw::Render()->SetAlpha(ptrStyle->drawTextBackgroundAlpha);
GCP_Draw::Render()->Draw_FillRect(_position, cBColor);
GCP_Draw::Render()->SetAlpha(alphaOrig);
GCP_Draw::Render()->Draw_Rect(_position, ptrStyle->borderColor);
}
gcp_spStyle color = gcp_spStyle(new GCP_Style());
color->textColor = cTColor;
color->font = ptrStyle->font;
GCP_Draw::Render()->Draw_Text(sCaption,_position, color, &drawdata);
}
//Áàçîâûé ìåòîä îí äðàâ äëÿ âñåõ êîìïîííò
basicOnDraw( event);
}