forked from scarsty/kys-cpp
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathButton.cpp
More file actions
91 lines (84 loc) · 1.86 KB
/
Button.cpp
File metadata and controls
91 lines (84 loc) · 1.86 KB
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
#include "Button.h"
#include "Font.h"
#include "PotConv.h"
Button::Button(const std::string& path, int normal_id, int pass_id /*= -1*/, int press_id /*= -1*/) : Button()
{
setTexture(path, normal_id, pass_id, press_id);
}
Button::~Button()
{
}
void Button::dealEvent(BP_Event& e)
{
result_ = -1;
if (e.type == BP_MOUSEBUTTONUP)
{
if (inSide(e.motion.x, e.motion.y))
{
result_ = 0;
}
}
}
void Button::draw()
{
//视情况重新计算尺寸
if (w_ * h_ == 0)
{
auto tex = TextureManager::getInstance()->getTexture(texture_path_, texture_normal_id_);
if (tex)
{
w_ = tex->w;
h_ = tex->h;
}
}
int x = x_;
int y = y_;
auto id = texture_normal_id_;
BP_Color color = { 255, 255, 255, 255 };
uint8_t alpha = 225;
if (state_ == NodeNormal)
{
if (texture_normal_id_ == texture_pass_id_)
{
color = { 224, 224, 224, 255 };
}
}
if (state_ == NodePass)
{
id = texture_pass_id_;
alpha = 240;
x += 2;
}
else if (state_ == NodePress)
{
id = texture_press_id_;
alpha = 255;
x += 2;
y += 2;
}
TextureManager::getInstance()->renderTexture(texture_path_, id, x, y, color, alpha);
if (!text_.empty())
{
BP_Color color_text = color_normal_;
if (state_ == NodePass)
{
color_text = color_pass_;
}
else if (state_ == NodePress)
{
color_text = color_press_;
}
Font::getInstance()->drawWithBox(text_, font_size_, x + text_x_, y + text_y_, color_text, 255, alpha);
}
}
ButtonGetKey::~ButtonGetKey()
{
}
void ButtonGetKey::dealEvent(BP_Event& e)
{
if (e.type == BP_KEYUP)
{
result_ = e.key.keysym.sym;
setExit(true);
}
}