aboutsummaryrefslogtreecommitdiff
path: root/src/gui
diff options
context:
space:
mode:
authordec05eba <dec05eba@protonmail.com>2022-03-31 13:38:02 +0200
committerdec05eba <dec05eba@protonmail.com>2022-03-31 13:38:02 +0200
commit2aea0635f46d4356953b1885bf6f8510cb5b038f (patch)
tree0fc47d2bec8844f4307586b0c18f28a3fab98232 /src/gui
parent5dc945eb6a0361ee7a64314f7a2acbf24ea9b565 (diff)
wip
Diffstat (limited to 'src/gui')
-rw-r--r--src/gui/Button.cpp30
1 files changed, 10 insertions, 20 deletions
diff --git a/src/gui/Button.cpp b/src/gui/Button.cpp
index 2250560..d7df26a 100644
--- a/src/gui/Button.cpp
+++ b/src/gui/Button.cpp
@@ -10,7 +10,6 @@ namespace gsr {
}
void Button::on_event(mgl::Event &event, mgl::Window&) {
- /*
if(event.type == mgl::Event::MouseMoved) {
const bool inside = mgl::FloatRect(position, size).contains({ (float)event.mouse_move.x, (float)event.mouse_move.y });
if(mouse_inside && !inside) {
@@ -18,34 +17,25 @@ namespace gsr {
} else if(!mouse_inside && inside) {
mouse_inside = true;
}
- } else if(event.type == mgl::Event::MouseButtonPressed && mouse_inside) {
-
- }
- */
- if(event.type == mgl::Event::MouseButtonPressed && mouse_inside) {
- if(on_click)
+ } else if(event.type == mgl::Event::MouseButtonPressed) {
+ pressed_inside = mouse_inside;
+ } else if(event.type == mgl::Event::MouseButtonReleased) {
+ const bool clicked_inside = pressed_inside && mouse_inside;
+ pressed_inside = false;
+ if(clicked_inside && on_click)
on_click();
}
}
void Button::draw(mgl::Window &window) {
- const bool inside = mgl::FloatRect(position, size).contains(window.get_mouse_position().to_vec2f());
- if(mouse_inside && !inside) {
- mouse_inside = false;
- } else if(!mouse_inside && inside) {
- mouse_inside = true;
- }
-
if(mouse_inside) {
// Background
- /*
{
mgl::Rectangle rect(size);
rect.set_position(position);
rect.set_color(mgl::Color(20, 20, 20, 255));
window.draw(rect);
}
- */
const int border_size = 5;
const mgl::Color border_color(118, 185, 0);
@@ -68,16 +58,16 @@ namespace gsr {
// Green line at left
{
- mgl::Rectangle rect({ border_size, size.y });
- rect.set_position(position);
+ mgl::Rectangle rect({ border_size, size.y - border_size * 2 });
+ rect.set_position(position + mgl::vec2f(0, border_size));
rect.set_color(border_color);
window.draw(rect);
}
// Green line at right
{
- mgl::Rectangle rect({ border_size, size.y });
- rect.set_position(position + mgl::vec2f(size.x - border_size, 0.0f));
+ mgl::Rectangle rect({ border_size, size.y - border_size * 2 });
+ rect.set_position(position + mgl::vec2f(size.x - border_size, border_size));
rect.set_color(border_color);
window.draw(rect);
}