From 357167f917c3f92bf3fbeb11bf29a304caa50593 Mon Sep 17 00:00:00 2001 From: ocornut Date: Sun, 6 Nov 2016 18:13:14 +0100 Subject: [PATCH] Demo: Custom Rendering: Tweak so end of line can be dropped outside of canvas, more pleasing. --- imgui_demo.cpp | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/imgui_demo.cpp b/imgui_demo.cpp index 544d6230f..4ad5e6472 100644 --- a/imgui_demo.cpp +++ b/imgui_demo.cpp @@ -2041,21 +2041,21 @@ static void ShowExampleAppCustomRendering(bool* p_open) bool adding_preview = false; ImGui::InvisibleButton("canvas", canvas_size); + ImVec2 mouse_pos_in_canvas = ImVec2(ImGui::GetIO().MousePos.x - canvas_pos.x, ImGui::GetIO().MousePos.y - canvas_pos.y); + if (adding_line) + { + adding_preview = true; + points.push_back(mouse_pos_in_canvas); + if (!ImGui::GetIO().MouseDown[0]) + adding_line = adding_preview = false; + } if (ImGui::IsItemHovered()) { - ImVec2 mouse_pos_in_canvas = ImVec2(ImGui::GetIO().MousePos.x - canvas_pos.x, ImGui::GetIO().MousePos.y - canvas_pos.y); if (!adding_line && ImGui::IsMouseClicked(0)) { points.push_back(mouse_pos_in_canvas); adding_line = true; } - if (adding_line) - { - adding_preview = true; - points.push_back(mouse_pos_in_canvas); - if (!ImGui::GetIO().MouseDown[0]) - adding_line = adding_preview = false; - } if (ImGui::IsMouseClicked(1) && !points.empty()) { adding_line = adding_preview = false;