bad highlighting
parent
7c73318b2a
commit
113646c190
|
@ -1,5 +1,5 @@
|
||||||
cmake_minimum_required(VERSION 3.25)
|
cmake_minimum_required(VERSION 3.25)
|
||||||
project(graphs VERSION 0.0.42)
|
project(graphs VERSION 0.0.43)
|
||||||
|
|
||||||
option(ENABLE_ADDRSAN "Enable the address sanitizer" OFF)
|
option(ENABLE_ADDRSAN "Enable the address sanitizer" OFF)
|
||||||
option(ENABLE_UBSAN "Enable the ub sanitizer" OFF)
|
option(ENABLE_UBSAN "Enable the ub sanitizer" OFF)
|
||||||
|
|
|
@ -57,7 +57,9 @@ class graph_t
|
||||||
static constexpr float POINT_SIZE = 35;
|
static constexpr float POINT_SIZE = 35;
|
||||||
|
|
||||||
blt::i32 selected_node = -1;
|
blt::i32 selected_node = -1;
|
||||||
blt::quint_easing easing;
|
blt::i32 highlighted_node = -1;
|
||||||
|
blt::quad_easing easing;
|
||||||
|
blt::quint_easing highlight_easing;
|
||||||
|
|
||||||
void create_random_graph(bounding_box bb, blt::size_t min_nodes, blt::size_t max_nodes, blt::f64 connectivity,
|
void create_random_graph(bounding_box bb, blt::size_t min_nodes, blt::size_t max_nodes, blt::f64 connectivity,
|
||||||
blt::f64 scaling_connectivity, blt::f64 distance_factor);
|
blt::f64 scaling_connectivity, blt::f64 distance_factor);
|
||||||
|
@ -99,11 +101,22 @@ class graph_t
|
||||||
|
|
||||||
void reset_mouse_drag()
|
void reset_mouse_drag()
|
||||||
{
|
{
|
||||||
easing.reset();
|
if (selected_node != -1)
|
||||||
|
{
|
||||||
nodes[selected_node].setOutlineColor(color::POINT_OUTLINE_COLOR);
|
nodes[selected_node].setOutlineColor(color::POINT_OUTLINE_COLOR);
|
||||||
|
easing.reset();
|
||||||
|
}
|
||||||
selected_node = -1;
|
selected_node = -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void reset_mouse_highlight()
|
||||||
|
{
|
||||||
|
if (highlighted_node != -1)
|
||||||
|
nodes[highlighted_node].setOutlineColor(color::POINT_OUTLINE_COLOR);
|
||||||
|
highlighted_node = -1;
|
||||||
|
highlight_easing.reset();
|
||||||
|
}
|
||||||
|
|
||||||
void process_mouse_drag(blt::i32 width, blt::i32 height);
|
void process_mouse_drag(blt::i32 width, blt::i32 height);
|
||||||
|
|
||||||
void handle_mouse();
|
void handle_mouse();
|
||||||
|
@ -193,11 +206,9 @@ class engine_t
|
||||||
|
|
||||||
auto& io = ImGui::GetIO();
|
auto& io = ImGui::GetIO();
|
||||||
|
|
||||||
if (!io.WantCaptureMouse){
|
if (!io.WantCaptureMouse)
|
||||||
if (blt::gfx::isMousePressed(0))
|
{
|
||||||
graph.process_mouse_drag(data.width, data.height);
|
graph.process_mouse_drag(data.width, data.height);
|
||||||
else
|
|
||||||
graph.reset_mouse_drag();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1 +1 @@
|
||||||
Subproject commit 8ec4c2c30b0a6d313ca5df5ff83210fd4f553908
|
Subproject commit ae2ad8d1ab9f9fc557de8dd51065d5dae77b98fe
|
|
@ -84,6 +84,8 @@ void graph_t::process_mouse_drag(const blt::i32 width, const blt::i32 height)
|
||||||
const auto mouse_pos = blt::make_vec2(blt::gfx::calculateRay2D(width, height, global_matrices.getScale2D(), global_matrices.getView2D(),
|
const auto mouse_pos = blt::make_vec2(blt::gfx::calculateRay2D(width, height, global_matrices.getScale2D(), global_matrices.getView2D(),
|
||||||
global_matrices.getOrtho()));
|
global_matrices.getOrtho()));
|
||||||
|
|
||||||
|
bool mouse_pressed = blt::gfx::isMousePressed(0);
|
||||||
|
|
||||||
if (selected_node < 0)
|
if (selected_node < 0)
|
||||||
{
|
{
|
||||||
for (const auto& [index, node] : blt::enumerate(nodes))
|
for (const auto& [index, node] : blt::enumerate(nodes))
|
||||||
|
@ -91,19 +93,38 @@ void graph_t::process_mouse_drag(const blt::i32 width, const blt::i32 height)
|
||||||
const auto pos = node.getPosition();
|
const auto pos = node.getPosition();
|
||||||
const auto dist = pos - mouse_pos;
|
const auto dist = pos - mouse_pos;
|
||||||
|
|
||||||
if (const auto mag = dist.magnitude(); mag < POINT_SIZE)
|
const auto mag = dist.magnitude();
|
||||||
|
|
||||||
|
if (mag < POINT_SIZE && mouse_pressed)
|
||||||
{
|
{
|
||||||
selected_node = static_cast<blt::i32>(index);
|
selected_node = static_cast<blt::i32>(index);
|
||||||
|
reset_mouse_highlight();
|
||||||
break;
|
break;
|
||||||
|
} else if (mag < POINT_SIZE * (node.getOutlineScale() + (node.getOutlineScale() - 1) * 2))
|
||||||
|
{
|
||||||
|
highlighted_node = static_cast<blt::i32>(index);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else
|
} else
|
||||||
{
|
{
|
||||||
auto& node = nodes[selected_node];
|
auto& node = nodes[selected_node];
|
||||||
easing.progress(5 * static_cast<float>(blt::gfx::getFrameDeltaSeconds()));
|
easing.progress(8 * static_cast<float>(blt::gfx::getFrameDeltaSeconds()));
|
||||||
node.setOutlineColor(easing.apply(color::POINT_OUTLINE_COLOR, color::POINT_SELECT_COLOR));
|
node.setOutlineColor(easing.apply(color::POINT_HIGHLIGHT_COLOR, color::POINT_SELECT_COLOR));
|
||||||
node.getPositionRef() = mouse_pos;
|
node.getPositionRef() = mouse_pos;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (highlighted_node != -1)
|
||||||
|
{
|
||||||
|
highlight_easing.progress(8 * static_cast<float>(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()
|
void graph_t::handle_mouse()
|
||||||
|
|
Loading…
Reference in New Issue