-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEasySDL-objects.cpp
More file actions
111 lines (86 loc) · 2.31 KB
/
EasySDL-objects.cpp
File metadata and controls
111 lines (86 loc) · 2.31 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
#include "EasySDL.hpp"
#include "EasySDL-objects.hpp"
void objects::Area::areaPlace(SDL_Surface *surf, bool autoDestroySurface, int x, int y, int x0, int y0, double angle, double scale)
{
blit(area, surf, autoDestroySurface, x, y, x0, y0, angle, scale);
}
void objects::Area::place()
{
window::place(area, false, x, y);
}
void objects::Area::place(int x0, int y0, double angle, double scale)
{
window::place(area, false, x, y, x0, y0, angle, scale);
}
objects::Area::Area() {}
void objects::Area::init(int _w, int _h)
{
SDL_FreeSurface(area);
w=_w; h=_h;
area=SDL_CreateRGBSurface(SDL_HWSURFACE|SDL_SRCALPHA, w, h, 32, 0, 0, 0, 0);
}
objects::Area::Area(int _w, int _h)
{
init(_w, _h);
}
objects::Area::~Area()
{
SDL_FreeSurface(area);
}
void objects::Area::ignoreColor(int r, int g, int b) {SDL_SetColorKey(area, SDL_SRCCOLORKEY, SDL_MapRGB(area->format, r, g, b));}
bool objects::BasicArea::isFocused(int _x, int _y)
{
return (x<=_x) && ((x+w)>_x) && (y<=_y) && ((y+h)>_y);
}
objects::BasicArea::BasicArea(int _w, int _h) : Area(_w, _h) {}
objects::BasicArea::BasicArea() : Area() {}
bool objects::Button::isFocused(int _x, int _y)
{
return (x<=_x) && ((x+w)>_x) && (y<=_y) && ((y+h)>_y);
}
void objects::Button::build()
{
SDL_FillRect(area, NULL, SDL_MapRGB(area->format, 0, 0, 0));
drawContent(this);
/*
drawRectangle(0, 0, w, h, 63, 63, 63);
drawRectangle(2, 2, w-4, h-4, 127, 127, 127);
writeText(txt, w/2, h/2, "default", 63, 63, 63, x_center, y_middle);
*/
}
void objects::Button::press(int screenX, int screenY)
{
action(screenX-x, screenY-y);
}
bool objects::Scrollable::isFocused(int _x, int _y)
{
return (x<=_x) && ((x+w)>_x) && (y<=_y) && ((y+h)>_y);
}
void objects::Scrollable::initContent(int _h)
{
content.init(w-5, _h);
}
void objects::Scrollable::shiftDown()
{
deltaY+=defilementSpeed;
if (deltaY>(content.h-h))
{
deltaY=content.h-h;
}
}
void objects::Scrollable::shiftUp()
{
deltaY-=defilementSpeed;
if (deltaY<0)
{
deltaY=0;
}
}
void objects::Scrollable::build()
{
SDL_FillRect(area, NULL, SDL_MapRGB(area->format, 0, 0, 0));
areaPlace(content.area, false, 0, -deltaY);
areaPlace(draw::createRect(5, h, 31, 31, 31), true, w-5, 0);
areaPlace(draw::createRect(5, (h/(double)(content.h))*h, 127, 127, 127), true, w-5, (h/(double)(content.h))*deltaY);
}
objects::Scrollable::Scrollable() {}