From 889efe51b26d505171d132097ac77a14ade5a101 Mon Sep 17 00:00:00 2001 From: dec05eba Date: Wed, 30 Mar 2022 16:16:51 +0200 Subject: Initial commit, showing ui above target window --- src/gui/Button.cpp | 71 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ src/gui/Widget.cpp | 7 ++++++ 2 files changed, 78 insertions(+) create mode 100644 src/gui/Button.cpp create mode 100644 src/gui/Widget.cpp (limited to 'src/gui') diff --git a/src/gui/Button.cpp b/src/gui/Button.cpp new file mode 100644 index 0000000..b266639 --- /dev/null +++ b/src/gui/Button.cpp @@ -0,0 +1,71 @@ +#include "../../include/gui/Button.hpp" +#include +#include +#include +#include + +namespace gsr { + Button::Button(mgl::vec2f size) : size(size) { + + } + + 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) { + mouse_inside = false; + } else if(!mouse_inside && inside) { + mouse_inside = true; + } + } + } + + void Button::draw(mgl::Window &window) { + 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); + + // Green line at top + { + mgl::Rectangle rect({ size.x, border_size }); + rect.set_position(position); + rect.set_color(border_color); + window.draw(rect); + } + + // Green line at bottom + { + mgl::Rectangle rect({ size.x, border_size }); + rect.set_position(position + mgl::vec2f(0.0f, size.y - border_size)); + rect.set_color(border_color); + window.draw(rect); + } + + // Green line at left + { + mgl::Rectangle rect({ border_size, size.y }); + rect.set_position(position); + 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)); + rect.set_color(border_color); + window.draw(rect); + } + } + } +} \ No newline at end of file diff --git a/src/gui/Widget.cpp b/src/gui/Widget.cpp new file mode 100644 index 0000000..c30c1d1 --- /dev/null +++ b/src/gui/Widget.cpp @@ -0,0 +1,7 @@ +#include "../../include/gui/Widget.hpp" + +namespace gsr { + void Widget::set_position(mgl::vec2f position) { + this->position = position; + } +} \ No newline at end of file -- cgit v1.2.3