-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbutton.h
More file actions
111 lines (97 loc) · 2.4 KB
/
button.h
File metadata and controls
111 lines (97 loc) · 2.4 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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
#ifndef BUTTON_H_INCLUDED
#define BUTTON_H_INCLUDED
#include "variables.h"
//can be clicked and have text
class Button
{
public:
// position / size / displayed text / function called when pressed
Button(int i, int j, int isize, int jsize, const wchar_t name[], void (*foo)())
{
textsize = 0;
while(name[textsize])
{
text[textsize]=name[textsize];
++textsize;
}
text[textsize] = L'\0';
func = foo;
left_margin = i;
j1 = j;
right_margin = i + isize;
j2 = j + jsize;
}
Button(int i, int j, int isize, int jsize, const wchar_t name[])
{
textsize = 0;
while (name[textsize])
{
text[textsize] = name[textsize];
++textsize;
}
text[textsize] = L'\0';
left_margin = i;
j1 = j;
right_margin = i + isize;
j2 = j + jsize;
}
Button(int i, int j, int isize, int jsize, const char name[], void (*foo)())
{
textsize = 0;
while (name[textsize])
{
text[textsize] = (wchar_t)name[textsize];
++textsize;
}
text[textsize] = L'\0';
func = foo;
left_margin = i;
right_margin = i + isize;
j1 = j;
j2 = j + jsize;
}
Button(){}
virtual void update()
{
if(mouse.isClicked() && mi >= left_margin && mi < right_margin && mj >= j1 && mj < j2)
func();
}
int update2()
{
if (mouse.isClicked() && mi >= left_margin && mi < right_margin && mj >= j1 && mj < j2)
{
return 1;
}
}
void draw()
{
int aux = 0;
for(int i = left_margin; i < right_margin; i++)
{
for(int j = j1; j < j2; j++)
{
if(aux>=0 && aux < textsize)
screen[i * screen_width + j] = text[aux++];
}
}
}
void draw(wchar_t *screen, int screen_width, int i = 0, int j = 0)
{
int aux = 0;
while (text[aux] != 0)
{
screen[i * screen_width + j + aux] = text[aux];
++aux;
}
}
wchar_t* name()
{
return text;
}
protected:
wchar_t text[200];
unsigned short textsize;
short left_margin, right_margin, j1, j2;
void (*func)();
};
#endif // BUTTON_H_INCLUDED