diff options
Diffstat (limited to 'src/gui')
-rw-r--r-- | src/gui/Button.cpp | 2 | ||||
-rw-r--r-- | src/gui/CheckBox.cpp | 4 | ||||
-rw-r--r-- | src/gui/ComboBox.cpp | 4 | ||||
-rw-r--r-- | src/gui/CustomRendererWidget.cpp | 41 | ||||
-rw-r--r-- | src/gui/Entry.cpp | 2 | ||||
-rw-r--r-- | src/gui/RadioButton.cpp | 2 |
6 files changed, 50 insertions, 5 deletions
diff --git a/src/gui/Button.cpp b/src/gui/Button.cpp index d2c4a2c..e36d07b 100644 --- a/src/gui/Button.cpp +++ b/src/gui/Button.cpp @@ -46,7 +46,7 @@ namespace gsr { const bool mouse_inside = mgl::FloatRect(draw_pos, item_size).contains(window.get_mouse_position().to_vec2f()) && !has_parent_with_selected_child_widget(); if(mouse_inside) - draw_rectangle_outline(window, draw_pos, item_size, get_theme().tint_color, border_scale * get_theme().window_height); + draw_rectangle_outline(window, draw_pos, item_size, get_theme().tint_color, std::max(1.0f, border_scale * get_theme().window_height)); } mgl::vec2f Button::get_size() { diff --git a/src/gui/CheckBox.cpp b/src/gui/CheckBox.cpp index 94e5f9e..e0904ba 100644 --- a/src/gui/CheckBox.cpp +++ b/src/gui/CheckBox.cpp @@ -75,6 +75,10 @@ namespace gsr { return mgl::vec2f(text_bounds.y, text_bounds.y).floor(); } + void CheckBox::set_checked(bool checked) { + this->checked = checked; + } + bool CheckBox::is_checked() const { return checked; } diff --git a/src/gui/ComboBox.cpp b/src/gui/ComboBox.cpp index 6aff979..373b06b 100644 --- a/src/gui/ComboBox.cpp +++ b/src/gui/ComboBox.cpp @@ -14,7 +14,7 @@ namespace gsr { static const float padding_right_scale = 0.007f; static const float border_scale = 0.0015f; - ComboBox::ComboBox(mgl::Font *font) : font(font), dropdown_arrow(&get_theme().combobox_arrow) { + ComboBox::ComboBox(mgl::Font *font) : font(font), dropdown_arrow(&get_theme().combobox_arrow_texture) { assert(font); } @@ -109,7 +109,7 @@ namespace gsr { Item &item = items[selected_item]; item.text.set_position(pos.floor()); if(show_dropdown || mouse_inside) { - const int border_size = border_scale * get_theme().window_height; + const int border_size = std::max(1.0f, border_scale * get_theme().window_height); const mgl::Color border_color = get_theme().tint_color; draw_rectangle_outline(window, pos - mgl::vec2f(padding_left, padding_top), item_size.floor(), border_color, border_size); } diff --git a/src/gui/CustomRendererWidget.cpp b/src/gui/CustomRendererWidget.cpp new file mode 100644 index 0000000..98b7caf --- /dev/null +++ b/src/gui/CustomRendererWidget.cpp @@ -0,0 +1,41 @@ +#include "../../include/gui/CustomRendererWidget.hpp" + +#include <mglpp/window/Window.hpp> + +namespace gsr { + CustomRendererWidget::CustomRendererWidget(mgl::vec2f size) : size(size) {} + + bool CustomRendererWidget::on_event(mgl::Event &event, mgl::Window &window, mgl::vec2f offset) { + if(!visible || !event_handler) + return true; + return event_handler(event, window, position + offset, size); + } + + void CustomRendererWidget::draw(mgl::Window &window, mgl::vec2f offset) { + if(!visible) + return; + + const mgl::vec2f draw_pos = position + offset; + + 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); + + if(draw_handler) + draw_handler(window, draw_pos, size); + + mgl_window_set_scissor(window.internal_window(), &prev_scissor); + } + + mgl::vec2f CustomRendererWidget::get_size() { + if(!visible) + return {0.0f, 0.0f}; + + return size; + } +}
\ No newline at end of file diff --git a/src/gui/Entry.cpp b/src/gui/Entry.cpp index e74e41e..f337bcf 100644 --- a/src/gui/Entry.cpp +++ b/src/gui/Entry.cpp @@ -57,7 +57,7 @@ namespace gsr { window.draw(background); if(selected) { - const int border_size = border_scale * get_theme().window_height; + const int border_size = std::max(1.0f, border_scale * get_theme().window_height); draw_rectangle_outline(window, draw_pos.floor(), get_size().floor(), get_theme().tint_color, border_size); const int caret_width = std::max(1.0f, caret_width_scale * get_theme().window_height); diff --git a/src/gui/RadioButton.cpp b/src/gui/RadioButton.cpp index 15b0989..eb1f900 100644 --- a/src/gui/RadioButton.cpp +++ b/src/gui/RadioButton.cpp @@ -77,7 +77,7 @@ namespace gsr { const bool mouse_inside = mgl::FloatRect(draw_pos, item_size).contains(window.get_mouse_position().to_vec2f()); if(can_select_item && mouse_inside) { - const int border_size = border_scale * get_theme().window_height; + const int border_size = std::max(1.0f, border_scale * get_theme().window_height); const mgl::Color border_color = get_theme().tint_color; draw_rectangle_outline(window, draw_pos.floor(), item_size.floor(), border_color, border_size); } |