aboutsummaryrefslogtreecommitdiff
path: root/src/gui
diff options
context:
space:
mode:
Diffstat (limited to 'src/gui')
-rw-r--r--src/gui/Button.cpp71
-rw-r--r--src/gui/Widget.cpp7
2 files changed, 78 insertions, 0 deletions
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 <mglpp/graphics/Rectangle.hpp>
+#include <mglpp/window/Window.hpp>
+#include <mglpp/window/Event.hpp>
+#include <mglpp/system/FloatRect.hpp>
+
+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