Fixed picking of handles

This commit is contained in:
brunoherbelin
2020-06-06 23:20:46 +02:00
parent 4261dedff1
commit 1068d9fdad
3 changed files with 36 additions and 19 deletions

View File

@@ -145,11 +145,11 @@ void ImGuiVisitor::visit(Shader &n)
{ {
ImGui::PushID(n.id()); ImGui::PushID(n.id());
if (ImGuiToolkit::ButtonIcon(10, 2)) { // if (ImGuiToolkit::ButtonIcon(10, 2)) {
n.blending = Shader::BLEND_OPACITY; // n.blending = Shader::BLEND_OPACITY;
n.color = glm::vec4(1.f, 1.f, 1.f, 1.f); // n.color = glm::vec4(1.f, 1.f, 1.f, 1.f);
} // }
ImGui::SameLine(0, 10); // ImGui::SameLine(0, 10);
// ImGui::ColorEdit3("Color", glm::value_ptr(n.color), ImGuiColorEditFlags_NoInputs | ImGuiColorEditFlags_NoLabel ) ; // ImGui::ColorEdit3("Color", glm::value_ptr(n.color), ImGuiColorEditFlags_NoInputs | ImGuiColorEditFlags_NoLabel ) ;
// ImGui::SameLine(0, 5); // ImGui::SameLine(0, 5);
ImGui::SetNextItemWidth(IMGUI_RIGHT_ALIGN); ImGui::SetNextItemWidth(IMGUI_RIGHT_ALIGN);
@@ -167,8 +167,8 @@ void ImGuiVisitor::visit(ImageShader &n)
// get index of the mask used in this ImageShader // get index of the mask used in this ImageShader
int item_current = n.mask; int item_current = n.mask;
if (ImGuiToolkit::ButtonIcon(10, 3)) n.mask = 0; // if (ImGuiToolkit::ButtonIcon(10, 3)) n.mask = 0;
ImGui::SameLine(0, 10); // ImGui::SameLine(0, 10);
ImGui::SetNextItemWidth(IMGUI_RIGHT_ALIGN); ImGui::SetNextItemWidth(IMGUI_RIGHT_ALIGN);
// combo list of masks // combo list of masks
if ( ImGui::Combo("Mask", &item_current, ImageShader::mask_names, IM_ARRAYSIZE(ImageShader::mask_names) ) ) if ( ImGui::Combo("Mask", &item_current, ImageShader::mask_names, IM_ARRAYSIZE(ImageShader::mask_names) ) )
@@ -187,7 +187,14 @@ void ImGuiVisitor::visit(ImageProcessingShader &n)
{ {
ImGui::PushID(n.id()); ImGui::PushID(n.id());
if (ImGuiToolkit::ButtonIcon(6, 2)) n.gamma = glm::vec4(1.f, 1.f, 1.f, 1.f); if (ImGuiToolkit::ButtonIcon(6, 2)) {
ImageProcessingShader defaultvalues;
n = defaultvalues;
}
ImGui::SameLine(0, 10);
ImGui::Text("Filters");
if (ImGuiToolkit::ButtonIcon(6, 4)) n.gamma = glm::vec4(1.f, 1.f, 1.f, 1.f);
ImGui::SameLine(0, 10); ImGui::SameLine(0, 10);
ImGui::ColorEdit3("GammaColor", glm::value_ptr(n.gamma), ImGuiColorEditFlags_NoInputs | ImGuiColorEditFlags_NoLabel) ; ImGui::ColorEdit3("GammaColor", glm::value_ptr(n.gamma), ImGuiColorEditFlags_NoInputs | ImGuiColorEditFlags_NoLabel) ;
ImGui::SameLine(0, 5); ImGui::SameLine(0, 5);

View File

@@ -9,6 +9,7 @@
#include <glm/gtc/matrix_access.hpp> #include <glm/gtc/matrix_access.hpp>
#include <glm/gtc/matrix_transform.hpp> #include <glm/gtc/matrix_transform.hpp>
#include <glm/gtx/string_cast.hpp> #include <glm/gtx/string_cast.hpp>
#include <glm/gtx/vector_angle.hpp>
PickingVisitor::PickingVisitor(glm::vec2 coordinates) : Visitor(), point_(coordinates) PickingVisitor::PickingVisitor(glm::vec2 coordinates) : Visitor(), point_(coordinates)
@@ -77,27 +78,33 @@ void PickingVisitor::visit(Handles &n)
// apply inverse transform to the point of interest // apply inverse transform to the point of interest
glm::vec4 P = glm::inverse(modelview_) * glm::vec4( point_, 0.f, 1.f ); glm::vec4 P = glm::inverse(modelview_) * glm::vec4( point_, 0.f, 1.f );
// inverse transform to check the scale
glm::vec4 S = glm::inverse(modelview_) * glm::vec4( 0.05f, 0.05f, 0.f, 0.f );
float scale = glm::length( glm::vec2(S) );
bool picked = false; bool picked = false;
// test by distance to the corners (more tolerant than bbox)
if ( n.type() == Handles::RESIZE ) { if ( n.type() == Handles::RESIZE ) {
// 4 corners // 4 corners
picked = ( glm::length(glm::vec2(+1.f, +1.f)-glm::vec2(P)) < 0.05f || picked = ( glm::length(glm::vec2(+1.f, +1.f)- glm::vec2(P)) < scale ||
glm::length(glm::vec2(+1.f, -1.f)- glm::vec2(P)) < 0.05f || glm::length(glm::vec2(+1.f, -1.f)- glm::vec2(P)) < scale ||
glm::length(glm::vec2(-1.f, +1.f)- glm::vec2(P)) < 0.05f || glm::length(glm::vec2(-1.f, +1.f)- glm::vec2(P)) < scale ||
glm::length(glm::vec2(-1.f, -1.f)- glm::vec2(P)) < 0.05f ); glm::length(glm::vec2(-1.f, -1.f)- glm::vec2(P)) < scale );
} }
else if ( n.type() == Handles::RESIZE_H ){ else if ( n.type() == Handles::RESIZE_H ){
// left & right // left & right
picked = ( glm::length(glm::vec2(+1.f, 0.f)- glm::vec2(P)) < 0.05f || picked = ( glm::length(glm::vec2(+1.f, 0.f)- glm::vec2(P)) < scale ||
glm::length(glm::vec2(-1.f, 0.f)- glm::vec2(P)) < 0.05f ); glm::length(glm::vec2(-1.f, 0.f)- glm::vec2(P)) < scale );
} }
else if ( n.type() == Handles::RESIZE_V ){ else if ( n.type() == Handles::RESIZE_V ){
// top & bottom // top & bottom
picked = ( glm::length(glm::vec2(0.f, +1.f)- glm::vec2(P)) < 0.05f || picked = ( glm::length(glm::vec2(0.f, +1.f)- glm::vec2(P)) < scale ||
glm::length(glm::vec2(0.f, -1.f)- glm::vec2(P)) < 0.05f ); glm::length(glm::vec2(0.f, -1.f)- glm::vec2(P)) < scale );
} }
else if ( n.type() == Handles::ROTATE ){ else if ( n.type() == Handles::ROTATE ){
picked = glm::length(glm::vec2(+1.1f, +1.1f)- glm::vec2(P)) < 0.1f; // the icon for rotation is on the right top corner at (0.12, 0.12) in screen coordinates
glm::vec4 vec = glm::inverse(modelview_) * glm::vec4( 0.12f, 0.12f, 0.f, 0.f );
vec += glm::vec4(+1.f, +1.f, 0.f, 0.f);
picked = glm::length( glm::vec2(vec) - glm::vec2(P) ) < scale;
} }
if ( picked ) if ( picked )

View File

@@ -397,6 +397,9 @@ void UserInterface::handleMouse()
{ {
// display source in left pannel // display source in left pannel
navigator.showPannelSource( Mixer::manager().indexCurrentSource() ); navigator.showPannelSource( Mixer::manager().indexCurrentSource() );
// discard current to select front most source
// (because single clic maintains same source active)
Mixer::manager().unsetCurrentSource();
} }
} }
@@ -1111,7 +1114,7 @@ void Navigator::RenderSourcePannel(Source *s)
ImGui::PopFont(); ImGui::PopFont();
ImGui::SetCursorPos(ImVec2(pannel_width_ - 35.f, 10.f)); ImGui::SetCursorPos(ImVec2(pannel_width_ - 35.f, 10.f));
ImGuiToolkit::IconToggle(13,11,11,11,&pannel_stick_); ImGuiToolkit::IconToggle(13,11,11,11, &pannel_stick_);
static char buf5[128]; static char buf5[128];
sprintf ( buf5, "%s", s->name().c_str() ); sprintf ( buf5, "%s", s->name().c_str() );