aboutsummaryrefslogtreecommitdiff
path: root/src/gui
diff options
context:
space:
mode:
Diffstat (limited to 'src/gui')
-rw-r--r--src/gui/Button.cpp51
1 files changed, 26 insertions, 25 deletions
diff --git a/src/gui/Button.cpp b/src/gui/Button.cpp
index e44843d..13bc8c6 100644
--- a/src/gui/Button.cpp
+++ b/src/gui/Button.cpp
@@ -1,42 +1,43 @@
#include "../../include/gui/Button.hpp"
#include "../../include/Theme.hpp"
#include "../../include/Config.hpp"
-#include <SFML/Graphics/RenderTarget.hpp>
-#include <SFML/Window/Event.hpp>
+#include <mglpp/system/FloatRect.hpp>
+#include <mglpp/window/Window.hpp>
+#include <mglpp/window/Event.hpp>
#include <cmath>
namespace QuickMedia {
- static const float PADDING_Y = 10.0f;
+ static const float PADDING_Y = 5.0f;
- Button::Button(const std::string &label, sf::Font *font, unsigned int character_size, float width, sf::Shader *rounded_rectangle_shader, float scale) :
- label(label, *font, character_size * scale),
- background(sf::Vector2f(1.0f, 1.0f), 10.0f * get_config().scale, get_theme().shade_color, rounded_rectangle_shader),
+ Button::Button(const std::string &label, mgl::Font *font, float width, mgl::Shader *rounded_rectangle_shader, float scale) :
+ label(label, *font),
+ background(mgl::vec2f(1.0f, 1.0f), 10.0f * get_config().scale, get_theme().shade_color, rounded_rectangle_shader),
scale(scale)
{
- background.set_size(sf::Vector2f(std::floor(width * scale), get_height()));
- set_position(sf::Vector2f(0.0f, 0.0f));
+ background.set_size(mgl::vec2f(std::floor(width * scale), get_height()));
+ set_position(mgl::vec2f(0.0f, 0.0f));
}
- ButtonEvent Button::on_event(sf::Event &event) {
+ ButtonEvent Button::on_event(mgl::Event &event) {
ButtonEvent performed_event = BUTTON_EVENT_NONE;
- if(event.type == sf::Event::MouseMoved) {
- if(sf::FloatRect(background.get_position(), background.get_size()).contains(event.mouseMove.x, event.mouseMove.y)) {
+ if(event.type == mgl::Event::MouseMoved) {
+ if(mgl::FloatRect(background.get_position(), background.get_size()).contains(mgl::vec2f(event.mouse_move.x, event.mouse_move.y))) {
const int inc = 20;
- background.set_color(sf::Color(
+ background.set_color(mgl::Color(
std::min(255, (int)background_color.r + inc),
std::min(255, (int)background_color.g + inc),
std::min(255, (int)background_color.b + inc)));
} else {
background.set_color(background_color);
}
- } else if(event.type == sf::Event::MouseButtonPressed) {
- if(event.mouseButton.button == sf::Mouse::Left && sf::FloatRect(background.get_position(), background.get_size()).contains(event.mouseButton.x, event.mouseButton.y)) {
+ } else if(event.type == mgl::Event::MouseButtonPressed) {
+ if(event.mouse_button.button == mgl::Mouse::Left && mgl::FloatRect(background.get_position(), background.get_size()).contains(mgl::vec2f(event.mouse_button.x, event.mouse_button.y))) {
clicked_inside = true;
} else {
clicked_inside = false;
}
- } else if(event.type == sf::Event::MouseButtonReleased) {
- if(clicked_inside && event.mouseButton.button == sf::Mouse::Left && sf::FloatRect(background.get_position(), background.get_size()).contains(event.mouseButton.x, event.mouseButton.y)) {
+ } else if(event.type == mgl::Event::MouseButtonReleased) {
+ if(clicked_inside && event.mouse_button.button == mgl::Mouse::Left && mgl::FloatRect(background.get_position(), background.get_size()).contains(mgl::vec2f(event.mouse_button.x, event.mouse_button.y))) {
performed_event = BUTTON_EVENT_CLICKED;
}
clicked_inside = false;
@@ -44,27 +45,27 @@ namespace QuickMedia {
return performed_event;
}
- void Button::draw(sf::RenderTarget &target) {
+ void Button::draw(mgl::Window &target) {
background.draw(target);
target.draw(label);
}
- void Button::set_background_color(sf::Color color) {
+ void Button::set_background_color(mgl::Color color) {
background_color = color;
background.set_color(background_color);
}
- void Button::set_position(sf::Vector2f pos) {
+ void Button::set_position(mgl::vec2f pos) {
background.set_position(pos);
- const auto label_bounds = label.getLocalBounds();
- sf::Vector2f label_pos(pos + background.get_size() * 0.5f - sf::Vector2f(label_bounds.width * 0.5f, label_bounds.height * 0.5f) - sf::Vector2f(0.0f, 5.0f * scale));
+ const auto label_bounds = label.get_bounds();
+ mgl::vec2f label_pos(pos + background.get_size() * 0.5f - label_bounds.size * 0.5f - mgl::vec2f(0.0f, 5.0f * scale));
label_pos.x = std::floor(label_pos.x);
label_pos.y = std::floor(label_pos.y);
- label.setPosition(label_pos);
+ label.set_position(label_pos);
}
- sf::Vector2f Button::get_position() const {
+ mgl::vec2f Button::get_position() const {
return background.get_position();
}
@@ -72,7 +73,7 @@ namespace QuickMedia {
return background.get_size().x;
}
- float Button::get_height() const {
- return std::floor((PADDING_Y * 2.0f) * scale + label.getLocalBounds().height);
+ float Button::get_height() {
+ return std::floor((PADDING_Y * 2.0f) * scale + label.get_bounds().size.y);
}
} \ No newline at end of file