-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathButton.cpp
More file actions
53 lines (44 loc) · 905 Bytes
/
Copy pathButton.cpp
File metadata and controls
53 lines (44 loc) · 905 Bytes
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
#include "Button.h"
Button::Button(SDL_Rect rect, void(*func)())
{
this->location = rect;
this->func = func;
}
Button::Button(SDL_Rect rect, std::function<void()> func)
{
this->location = rect;
this->func = func;
}
void Button::MouseDown(MousePos mouse)
{
if (CheckMouseOver(mouse))
{
func();
}
}
bool Button::CheckMouseOver(MousePos mouse)
{
if (location.x < mouse.x && mouse.x < (location.x + location.w) &&
location.y < mouse.y && mouse.y < (location.y + location.h))
{
return true;
}
return false;
}
void Button::RenderCall(SDL_Renderer* renderer)
{
MousePos mousePos;
SDL_GetMouseState(&mousePos.x, &mousePos.y);
if (CheckMouseOver(mousePos))
{
SDL_SetTextureColorMod(texture, 100, 100, 100);
}
else
{
SDL_SetTextureColorMod(texture, 255, 255, 255);
}
if (SDL_RenderCopy(renderer, texture, NULL, &location) != 0)
{
SDL_LogError(0, "Failed to Render");
}
}