From 029834fc9c6b47d638fba758ac8ebebb5a93e588 Mon Sep 17 00:00:00 2001 From: f0e <7321764+f0e@users.noreply.github.com> Date: Sun, 1 Dec 2024 16:43:50 +1000 Subject: [PATCH] feat: cursor setting, add missing config options --- src/gui/event_handler.cpp | 2 ++ src/gui/renderer.cpp | 19 ++++++++++++------- src/gui/ui/elements/button.cpp | 2 ++ src/gui/ui/elements/checkbox.cpp | 18 +++++++++++------- src/gui/ui/elements/dropdown.cpp | 3 +++ src/gui/ui/elements/slider.cpp | 8 ++++++-- src/gui/ui/elements/text_input.cpp | 3 +++ src/gui/ui/ui.cpp | 18 +++++++++++++++--- src/gui/ui/ui.h | 6 +++++- 9 files changed, 59 insertions(+), 20 deletions(-) diff --git a/src/gui/event_handler.cpp b/src/gui/event_handler.cpp index f2d02fc..efc1119 100644 --- a/src/gui/event_handler.cpp +++ b/src/gui/event_handler.cpp @@ -27,6 +27,8 @@ bool gui::event_handler::process_event(const os::Event& event) { updated |= ui::update_container_input(renderer::main_container); updated |= ui::update_container_input(renderer::config_container); updated |= ui::update_container_input(renderer::config_preview_container); + + ui::on_update_input_end(); } keys::on_input_end(); diff --git a/src/gui/renderer.cpp b/src/gui/renderer.cpp index 3832b7b..24338c3 100644 --- a/src/gui/renderer.cpp +++ b/src/gui/renderer.cpp @@ -389,7 +389,7 @@ void gui::renderer::components::configs::options(ui::Container& container, BlurS if (settings.gpu_rendering) { ui::add_dropdown( - "dropdown", + "gpu rendering dropdown", container, "gpu rendering - gpu type", { "nvidia", "amd", "intel" }, @@ -398,6 +398,16 @@ void gui::renderer::components::configs::options(ui::Container& container, BlurS ); } + ui::add_text_input( + "video container text input", container, settings.video_container, "video container", fonts::font + ); + + ui::add_text_input( + "custom ffmpeg filters text input", container, settings.ffmpeg_override, "custom ffmpeg filters", fonts::font + ); + + ui::add_checkbox("debug checkbox", container, "debug", settings.debug, fonts::font); + section_component("advanced blur"); ui::add_slider( @@ -796,7 +806,7 @@ bool gui::renderer::redraw_window(os::Window* window, bool force_render) { want_to_render |= ui::update_container_frame(main_container, delta_time); want_to_render |= ui::update_container_frame(config_container, delta_time); want_to_render |= ui::update_container_frame(config_preview_container, delta_time); - ui::on_update_end(); + ui::on_update_frame_end(); if (!want_to_render && !force_render) // note: DONT RENDER ANYTHING ABOVE HERE!!! todo: render queue? @@ -868,11 +878,6 @@ bool gui::renderer::redraw_window(os::Window* window, bool force_render) { window->invalidateRegion(gfx::Region(rect)); - // reset cursor - if (!set_cursor_this_frame) { - set_cursor(os::NativeCursor::Arrow); - } - return want_to_render; } diff --git a/src/gui/ui/elements/button.cpp b/src/gui/ui/elements/button.cpp index af9a5dc..cf61210 100644 --- a/src/gui/ui/elements/button.cpp +++ b/src/gui/ui/elements/button.cpp @@ -42,6 +42,8 @@ bool ui::update_button(const Container& container, AnimatedElement& element) { anim.set_goal(hovered ? 1.f : 0.f); if (hovered) { + set_cursor(os::NativeCursor::Link); + if (button_data.on_press) { if (keys::is_mouse_down()) { (*button_data.on_press)(); diff --git a/src/gui/ui/elements/checkbox.cpp b/src/gui/ui/elements/checkbox.cpp index 4d3f67a..94eee0b 100644 --- a/src/gui/ui/elements/checkbox.cpp +++ b/src/gui/ui/elements/checkbox.cpp @@ -74,16 +74,20 @@ bool ui::update_checkbox(const Container& container, AnimatedElement& element) { bool hovered = element.element->rect.contains(keys::mouse_pos); hover_anim.set_goal(hovered ? 1.f : 0.f); - if (hovered && keys::is_mouse_down()) { - *checkbox_data.checked = !(*checkbox_data.checked); - check_anim.set_goal(*checkbox_data.checked ? 1.f : 0.f); + if (hovered) { + set_cursor(os::NativeCursor::Link); - keys::on_mouse_press_handled(os::Event::MouseButton::LeftButton); + if (keys::is_mouse_down()) { + *checkbox_data.checked = !(*checkbox_data.checked); + check_anim.set_goal(*checkbox_data.checked ? 1.f : 0.f); - if (checkbox_data.on_change) - (*checkbox_data.on_change)(*checkbox_data.checked); + keys::on_mouse_press_handled(os::Event::MouseButton::LeftButton); - return true; + if (checkbox_data.on_change) + (*checkbox_data.on_change)(*checkbox_data.checked); + + return true; + } } return false; diff --git a/src/gui/ui/elements/dropdown.cpp b/src/gui/ui/elements/dropdown.cpp index 7d8fcbd..bf9d8b9 100644 --- a/src/gui/ui/elements/dropdown.cpp +++ b/src/gui/ui/elements/dropdown.cpp @@ -169,6 +169,9 @@ bool ui::update_dropdown(const Container& container, AnimatedElement& element) { bool res = false; + if (hovered) + set_cursor(os::NativeCursor::Link); + if (hovered && keys::is_mouse_down()) { // toggle dropdown toggle_active(); diff --git a/src/gui/ui/elements/slider.cpp b/src/gui/ui/elements/slider.cpp index 2762a1e..4f4728f 100644 --- a/src/gui/ui/elements/slider.cpp +++ b/src/gui/ui/elements/slider.cpp @@ -150,8 +150,12 @@ bool ui::update_slider(const Container& container, AnimatedElement& element) { slider_data.max_value ); - if (hovered && keys::is_mouse_down()) - active_element = &element; + if (hovered) { + set_cursor(os::NativeCursor::Link); + + if (keys::is_mouse_down()) + active_element = &element; + } hover_anim.set_goal(hovered || active ? 1.f : 0.f); diff --git a/src/gui/ui/elements/text_input.cpp b/src/gui/ui/elements/text_input.cpp index 3e57380..8017a75 100644 --- a/src/gui/ui/elements/text_input.cpp +++ b/src/gui/ui/elements/text_input.cpp @@ -355,6 +355,9 @@ bool ui::update_text_input(const Container& container, AnimatedElement& element) bool hovered = element.element->rect.contains(keys::mouse_pos); hover_anim.set_goal(hovered ? 1.f : 0.f); + if (hovered) + set_cursor(os::NativeCursor::IBeam); + // Handle mouse click to focus/unfocus if (hovered && keys::is_mouse_down()) { active_element = &element; diff --git a/src/gui/ui/ui.cpp b/src/gui/ui/ui.cpp index 2288018..cd5a0b0 100644 --- a/src/gui/ui/ui.cpp +++ b/src/gui/ui/ui.cpp @@ -1,12 +1,13 @@ #include "ui.h" -#include -#include +#include "gui/renderer.h" #include "gui/ui/keys.h" #include "render.h" #include "os/draw_text.h" namespace { + os::NativeCursor desired_cursor = os::NativeCursor::Arrow; + int get_content_height(const ui::Container& container) { int total_height = container.current_position.y - container.rect.y; @@ -225,6 +226,10 @@ void ui::center_elements_in_container(Container& container, bool horizontal, boo element.element->orig_rect = element.element->rect; } +void ui::set_cursor(os::NativeCursor cursor) { + desired_cursor = cursor; +} + std::vector ui::get_sorted_container_elements(Container& container) { std::vector sorted_elements; sorted_elements.reserve(container.elements.size()); @@ -285,9 +290,14 @@ bool ui::update_container_input(Container& container) { return updated; } -void ui::on_update_end() { +void ui::on_update_input_end() { + // reset scroll, shouldn't scroll stuff on a later update keys::scroll_delta = 0.f; keys::scroll_delta_precise = 0.f; + + // set cursor based on if an element wanted pointer + gui::renderer::set_cursor(desired_cursor); + desired_cursor = desired_cursor = os::NativeCursor::Arrow; } bool ui::update_container_frame(Container& container, float delta_time) { @@ -356,6 +366,8 @@ bool ui::update_container_frame(Container& container, float delta_time) { return container.updated || need_to_render_animation_update; } +void ui::on_update_frame_end() {} + void ui::render_container(os::Surface* surface, Container& container) { if (container.background_color) { render::rect_filled(surface, container.rect, *container.background_color); diff --git a/src/gui/ui/ui.h b/src/gui/ui/ui.h index ecee1b5..23c80b7 100644 --- a/src/gui/ui/ui.h +++ b/src/gui/ui/ui.h @@ -374,9 +374,13 @@ namespace ui { std::vector get_sorted_container_elements(Container& container); + void set_cursor(os::NativeCursor cursor); + bool update_container_input(Container& container); + void on_update_input_end(); + bool update_container_frame(Container& container, float delta_time); - void on_update_end(); + void on_update_frame_end(); void render_container(os::Surface* surface, Container& container); }