aboutsummaryrefslogtreecommitdiff
path: root/src/gui
diff options
context:
space:
mode:
Diffstat (limited to 'src/gui')
-rw-r--r--src/gui/Button.cpp4
-rw-r--r--src/gui/ComboBox.cpp3
-rw-r--r--src/gui/DropdownButton.cpp11
-rw-r--r--src/gui/ScrollablePage.cpp14
-rw-r--r--src/gui/StaticPage.cpp16
5 files changed, 39 insertions, 9 deletions
diff --git a/src/gui/Button.cpp b/src/gui/Button.cpp
index 48ab085..ad516b5 100644
--- a/src/gui/Button.cpp
+++ b/src/gui/Button.cpp
@@ -28,8 +28,8 @@ namespace gsr {
}
void Button::draw(mgl::Window &window, mgl::vec2f offset) {
- mgl::Rectangle background(size);
- background.set_position(position + offset);
+ mgl::Rectangle background(size.floor());
+ background.set_position((position + offset).floor());
background.set_color(bg_color);
window.draw(background);
diff --git a/src/gui/ComboBox.cpp b/src/gui/ComboBox.cpp
index 6b8ec26..81c804f 100644
--- a/src/gui/ComboBox.cpp
+++ b/src/gui/ComboBox.cpp
@@ -41,7 +41,8 @@ namespace gsr {
if(mgl::FloatRect(draw_pos, item_size).contains(mouse_pos)) {
show_dropdown = !show_dropdown;
- move_to_top = true;
+ if(show_dropdown)
+ move_to_top = true;
} else {
show_dropdown = false;
}
diff --git a/src/gui/DropdownButton.cpp b/src/gui/DropdownButton.cpp
index ecc284a..bfda834 100644
--- a/src/gui/DropdownButton.cpp
+++ b/src/gui/DropdownButton.cpp
@@ -38,8 +38,13 @@ namespace gsr {
} else if(event.type == mgl::Event::MouseButtonPressed) {
const bool clicked_inside = mouse_inside;
show_dropdown = clicked_inside;
- if(on_click && mouse_inside_item >= 0 && mouse_inside_item < (int)items.size())
- on_click(items[mouse_inside_item].id);
+ if(show_dropdown)
+ move_to_top = true;
+ if(mouse_inside_item >= 0 && mouse_inside_item < (int)items.size()) {
+ if(on_click)
+ on_click(items[mouse_inside_item].id);
+ return false;
+ }
}
return true;
}
@@ -82,7 +87,7 @@ namespace gsr {
// Background
mgl::Rectangle rect(size);
rect.set_position(draw_pos);
- rect.set_color(mgl::Color(0, 0, 0, 120));
+ rect.set_color(mgl::Color(0, 0, 0, 180));
window.draw(rect);
}
diff --git a/src/gui/ScrollablePage.cpp b/src/gui/ScrollablePage.cpp
index 4a4f88b..7394ec3 100644
--- a/src/gui/ScrollablePage.cpp
+++ b/src/gui/ScrollablePage.cpp
@@ -24,7 +24,16 @@ namespace gsr {
const mgl::vec2f draw_pos = position + offset;
offset = draw_pos + mgl::vec2f(0.0f, get_border_size(window)).floor();
- mgl::Rectangle background(size);
+ mgl_scissor prev_scissor;
+ mgl_window_get_scissor(window.internal_window(), &prev_scissor);
+
+ mgl_scissor new_scissor = {
+ mgl_vec2i{(int)draw_pos.x, (int)draw_pos.y},
+ mgl_vec2i{(int)size.x, (int)size.y}
+ };
+ mgl_window_set_scissor(window.internal_window(), &new_scissor);
+
+ mgl::Rectangle background(size.floor());
background.set_position(draw_pos);
background.set_color(get_theme().scrollable_page_bg_color);
window.draw(background);
@@ -39,12 +48,13 @@ namespace gsr {
widget->move_to_top = false;
std::swap(widget, widgets.back());
}
- widget->draw(window, offset);
}
for(auto &widget : widgets) {
widget->draw(window, offset);
}
+
+ mgl_window_set_scissor(window.internal_window(), &prev_scissor);
}
float ScrollablePage::get_border_size(mgl::Window &window) const {
diff --git a/src/gui/StaticPage.cpp b/src/gui/StaticPage.cpp
index 78fa497..a5b89cd 100644
--- a/src/gui/StaticPage.cpp
+++ b/src/gui/StaticPage.cpp
@@ -1,6 +1,10 @@
#include "../../include/gui/StaticPage.hpp"
+#include <mglpp/window/Window.hpp>
+
namespace gsr {
+ StaticPage::StaticPage(mgl::vec2f size) : size(size) {}
+
bool StaticPage::on_event(mgl::Event &event, mgl::Window &window, mgl::vec2f offset) {
const mgl::vec2f draw_pos = position + offset;
offset = draw_pos;
@@ -18,16 +22,26 @@ namespace gsr {
const mgl::vec2f draw_pos = position + offset;
offset = draw_pos;
+ mgl_scissor prev_scissor;
+ mgl_window_get_scissor(window.internal_window(), &prev_scissor);
+
+ mgl_scissor new_scissor = {
+ mgl_vec2i{(int)draw_pos.x, (int)draw_pos.y},
+ mgl_vec2i{(int)size.x, (int)size.y}
+ };
+ mgl_window_set_scissor(window.internal_window(), &new_scissor);
+
for(auto &widget : widgets) {
if(widget->move_to_top) {
widget->move_to_top = false;
std::swap(widget, widgets.back());
}
- widget->draw(window, offset);
}
for(auto &widget : widgets) {
widget->draw(window, offset);
}
+
+ mgl_window_set_scissor(window.internal_window(), &prev_scissor);
}
} \ No newline at end of file