-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathUI.cpp
68 lines (66 loc) · 1.56 KB
/
UI.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
#include "pch.h"
#include "UI.h"
UI::UI()
{
}
UI::~UI()
{
G_DestroyTexture(texture);
texture = NULL;
}
Button::~Button()
{
clickSound = NULL;
}
void Icon::self_load(G_Font* font, const char* cont, int ft1, int ft2, int ft3, int pos1, int pos2, int pos3, int pos4)
{
texture = G_LoadFont(font, cont, ft1, ft2, ft3);
position = { pos1,pos2,pos3,pos4 };
}
void UI::self_load(const char*file, int pos1, int pos2, int pos3, int pos4)
{
texture = G_LoadImage(file);
position = { pos1,pos2,pos3,pos4 };
}
void Icon::self_load(const char*file, int pos1, int pos2, int pos3, int pos4)
{
UI::self_load(file, pos1, pos2, pos3, pos4);
}
void Button::self_load(const char*file, int pos1, int pos2, int pos3, int pos4, G_Sound* sound = NULL)
{
texture = G_LoadImage(file);
position = { pos1,pos2,pos3,pos4 };
clickSound = sound;
}
int UI::getPos(char dim)
{
if (dim == 'y') return position.y;
return position.x;
}
void Icon::self_update(G_Font *font, char* chars)
{
G_DestroyTexture(texture);
texture = G_LoadFont(font, chars, 255, 255, 255);
}
void UI::self_draw()
{
G_Draw(texture, &position);
}
void UI::self_draw(G_Rect pos)
{
G_Draw(texture, &pos);
}
void UI::settexture(G_Texture* txture)
{
texture = txture;
}
bool Button::clickOnButton(int &gameEvent, bool onSound)
{
SDL_Point mouse_point = { G_motion.x , G_motion.y };
if (gameEvent == G_MOUSEBUTTONDOWN && G_Mouse == G_BUTTON_LEFT && SDL_PointInRect(&mouse_point, &position))
{
if (onSound == true) G_PlaySound(clickSound, 0);
return true;
}
return false;
}