Skip to content

Commit

Permalink
pers: highlight hovered corners
Browse files Browse the repository at this point in the history
  • Loading branch information
hanatos committed Feb 5, 2024
1 parent a553304 commit dae3151
Showing 1 changed file with 21 additions and 18 deletions.
39 changes: 21 additions & 18 deletions src/gui/widget_image.hh
Original file line number Diff line number Diff line change
Expand Up @@ -22,27 +22,12 @@ dt_image_events(dt_image_widget_t *w, bool hovered, int main)
dt_image_to_view(&vkdt.wstate.img_widget, v+2*k, p+2*k);
ImGui::GetWindowDrawList()->AddPolyline(
(ImVec2 *)p, 4, IM_COL32_WHITE, true, 1.0);
if(vkdt.wstate.selected >= 0)
{
float q[2] = {
p[2*vkdt.wstate.selected],
p[2*vkdt.wstate.selected+1]};
ImGui::GetWindowDrawList()->AddCircleFilled(
ImVec2(q[0],q[1]), 0.02 * vkdt.state.center_wd,
0x77777777u, 20);
if(hovered && ImGui::IsKeyDown(ImGuiKey_MouseLeft))
{
ImVec2 pos = ImGui::GetMousePos();
float v[] = {pos.x, pos.y}, n[2] = {0};
dt_image_from_view(&vkdt.wstate.img_widget, v, n);
dt_gui_dr_pers_adjust(n, 0);
}
}
int corner_hovered = -1;
if(ImGui::IsKeyReleased(ImGuiKey_MouseLeft))
{
vkdt.wstate.selected = -1;
}
if(hovered && ImGui::IsKeyPressed(ImGuiKey_MouseLeft, false))
if(hovered)
{ // find active corner if close enough
ImVec2 pos = ImGui::GetMousePos();
float m[] = {pos.x, pos.y};
Expand All @@ -60,11 +45,29 @@ dt_image_events(dt_image_widget_t *w, bool hovered, int main)
if(dist2 < max_dist)
{
max_dist = dist2;
vkdt.wstate.selected = cc;
corner_hovered = cc;
if(ImGui::IsKeyPressed(ImGuiKey_MouseLeft, false))
vkdt.wstate.selected = cc;
}
}
}
}
if(corner_hovered >= 0)
{
float q[2] = {
p[2*corner_hovered],
p[2*corner_hovered+1]};
ImGui::GetWindowDrawList()->AddCircleFilled(
ImVec2(q[0],q[1]), 0.02 * vkdt.state.center_wd,
0x77777777u, 20);
if(hovered && ImGui::IsKeyDown(ImGuiKey_MouseLeft))
{
ImVec2 pos = ImGui::GetMousePos();
float v[] = {pos.x, pos.y}, n[2] = {0};
dt_image_from_view(&vkdt.wstate.img_widget, v, n);
dt_gui_dr_pers_adjust(n, 0);
}
}
break;
}
case dt_token("straight"):
Expand Down

0 comments on commit dae3151

Please sign in to comment.