Skip to content

Commit

Permalink
feat: cursor setting, add missing config options
Browse files Browse the repository at this point in the history
  • Loading branch information
f0e committed Dec 1, 2024
1 parent ecf243f commit 029834f
Show file tree
Hide file tree
Showing 9 changed files with 59 additions and 20 deletions.
2 changes: 2 additions & 0 deletions src/gui/event_handler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
19 changes: 12 additions & 7 deletions src/gui/renderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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" },
Expand All @@ -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(
Expand Down Expand Up @@ -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?
Expand Down Expand Up @@ -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;
}

Expand Down
2 changes: 2 additions & 0 deletions src/gui/ui/elements/button.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)();
Expand Down
18 changes: 11 additions & 7 deletions src/gui/ui/elements/checkbox.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
3 changes: 3 additions & 0 deletions src/gui/ui/elements/dropdown.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
8 changes: 6 additions & 2 deletions src/gui/ui/elements/slider.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
3 changes: 3 additions & 0 deletions src/gui/ui/elements/text_input.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
18 changes: 15 additions & 3 deletions src/gui/ui/ui.cpp
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
#include "ui.h"

#include <algorithm>
#include <utility>
#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;

Expand Down Expand Up @@ -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<decltype(ui::Container::elements)::iterator> ui::get_sorted_container_elements(Container& container) {
std::vector<decltype(container.elements)::iterator> sorted_elements;
sorted_elements.reserve(container.elements.size());
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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);
Expand Down
6 changes: 5 additions & 1 deletion src/gui/ui/ui.h
Original file line number Diff line number Diff line change
Expand Up @@ -374,9 +374,13 @@ namespace ui {

std::vector<decltype(Container::elements)::iterator> 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);
}

0 comments on commit 029834f

Please sign in to comment.