From 8dbddb79fab658fa47d5b0201c08e36c55779afa Mon Sep 17 00:00:00 2001 From: Brett Date: Wed, 15 May 2024 13:48:06 -0400 Subject: [PATCH] hi --- CMakeLists.txt | 2 +- include/graph.h | 12 ++++++--- src/graph.cpp | 68 +++++++++++++++++++++++++++---------------------- 3 files changed, 46 insertions(+), 36 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 4191253..562e9c5 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,5 +1,5 @@ cmake_minimum_required(VERSION 3.25) -project(graphs VERSION 0.0.43) +project(graphs VERSION 0.0.44) option(ENABLE_ADDRSAN "Enable the address sanitizer" OFF) option(ENABLE_UBSAN "Enable the ub sanitizer" OFF) diff --git a/include/graph.h b/include/graph.h index f71fbeb..bda1be8 100644 --- a/include/graph.h +++ b/include/graph.h @@ -26,6 +26,14 @@ namespace im = ImGui; +enum class anim_state_t +{ + NONE, + HIGHLIGHT_NODE, + SELECT_NODE, + HIGHLIGHT_TO_SELECT +}; + struct bounding_box { int min_x = 0; @@ -57,7 +65,6 @@ class graph_t static constexpr float POINT_SIZE = 35; blt::i32 selected_node = -1; - blt::i32 highlighted_node = -1; blt::quad_easing easing; blt::quint_easing highlight_easing; @@ -111,9 +118,6 @@ class graph_t void reset_mouse_highlight() { - if (highlighted_node != -1) - nodes[highlighted_node].setOutlineColor(color::POINT_OUTLINE_COLOR); - highlighted_node = -1; highlight_easing.reset(); } diff --git a/src/graph.cpp b/src/graph.cpp index 5141e59..9f0e425 100644 --- a/src/graph.cpp +++ b/src/graph.cpp @@ -15,6 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ +#include #include #include #include @@ -85,46 +86,51 @@ void graph_t::process_mouse_drag(const blt::i32 width, const blt::i32 height) global_matrices.getOrtho())); bool mouse_pressed = blt::gfx::isMousePressed(0); + blt::i32 new_selection = selected_node; - if (selected_node < 0) + for (const auto& [index, node] : blt::enumerate(nodes)) { - for (const auto& [index, node] : blt::enumerate(nodes)) + const auto pos = node.getPosition(); + const auto dist = pos - mouse_pos; + + const auto mag = dist.magnitude(); + + if (mag < POINT_SIZE && (selected_node == -1 || !mouse_pressed)) { - const auto pos = node.getPosition(); - const auto dist = pos - mouse_pos; - - const auto mag = dist.magnitude(); - - if (mag < POINT_SIZE && mouse_pressed) - { - selected_node = static_cast(index); - reset_mouse_highlight(); - break; - } else if (mag < POINT_SIZE * (node.getOutlineScale() + (node.getOutlineScale() - 1) * 2)) - { - highlighted_node = static_cast(index); - } + new_selection = static_cast(index); + break; } - } else + } + + if (new_selection != selected_node) + { + if (selected_node != -1) + nodes[selected_node].setOutlineColor(color::POINT_OUTLINE_COLOR); + } + + if (!mouse_pressed && blt::gfx::mouseReleaseLastFrame()) + { + reset_mouse_drag(); + } + + selected_node = new_selection; + +// if (!mouse_pressed && selected_node != -1 && found && nodes[selected_node].getOutlineColor() != color::POINT_HIGHLIGHT_COLOR) +// { +// highlight_easing.progress(8 * static_cast(blt::gfx::getFrameDeltaSeconds())); +// nodes[selected_node].setOutlineColor(highlight_easing.apply(color::POINT_OUTLINE_COLOR, color::POINT_HIGHLIGHT_COLOR)); +// } +// +// if (!found) +// reset_mouse_highlight(); + + if (selected_node != -1 && mouse_pressed) { auto& node = nodes[selected_node]; easing.progress(8 * static_cast(blt::gfx::getFrameDeltaSeconds())); - node.setOutlineColor(easing.apply(color::POINT_HIGHLIGHT_COLOR, color::POINT_SELECT_COLOR)); + node.setOutlineColor(easing.apply(color::POINT_OUTLINE_COLOR, color::POINT_SELECT_COLOR)); node.getPositionRef() = mouse_pos; } - - if (highlighted_node != -1) - { - highlight_easing.progress(8 * static_cast(blt::gfx::getFrameDeltaSeconds())); - BLT_TRACE("Hmew"); - nodes[highlighted_node].setOutlineColor(highlight_easing.apply(color::POINT_OUTLINE_COLOR, color::POINT_HIGHLIGHT_COLOR)); - } else - reset_mouse_highlight(); - - if (!mouse_pressed) - { - reset_mouse_drag(); - } } void graph_t::handle_mouse()