diff --git a/RenderingManager.cpp b/RenderingManager.cpp index 4edffa1..3f5fc63 100644 --- a/RenderingManager.cpp +++ b/RenderingManager.cpp @@ -21,6 +21,7 @@ #include #include // glm::translate, glm::rotate, glm::scale +#include // glm::unproject #include // glm::perspective // Include GStreamer @@ -318,6 +319,18 @@ glm::mat4 Rendering::Projection() return projection * scale; } + +glm::vec3 Rendering::unProject(glm::vec2 screen_coordinate, glm::mat4 modelview) +{ + glm::vec3 point; + glm::vec3 coordinates = glm::vec3( glm::vec2(screen_coordinate), 0.f); + glm::vec4 viewport = glm::vec4( 0.f, 0.f, main_window_attributes_.viewport.x, main_window_attributes_.viewport.y); + + point = glm::unProject(coordinates, modelview, Projection(), viewport); + + return point; +} + float Rendering::Width() { return main_window_attributes_.viewport.x; } float Rendering::Height() { return main_window_attributes_.viewport.y; } diff --git a/RenderingManager.h b/RenderingManager.h index d2f4058..6356ae4 100644 --- a/RenderingManager.h +++ b/RenderingManager.h @@ -75,6 +75,8 @@ public: // get projection matrix (for sharers) => Views glm::mat4 Projection(); + // unproject from window coordinate + glm::vec3 unProject(glm::vec2 screen_coordinate, glm::mat4 modelview); // for opengl pipeline in gstreamer void LinkPipeline( GstPipeline *pipeline ); diff --git a/UserInterfaceManager.cpp b/UserInterfaceManager.cpp index 9a7ab00..f1bfc6a 100644 --- a/UserInterfaceManager.cpp +++ b/UserInterfaceManager.cpp @@ -19,6 +19,11 @@ // multiplatform #include +#include +#include +#include +#include + // generic image loader #define STB_IMAGE_IMPLEMENTATION #include @@ -155,7 +160,7 @@ void UserInterface::handleMouse() ImGuiIO& io = ImGui::GetIO(); // if not on any window - if ( !ImGui::IsAnyWindowHovered() ) + if ( !ImGui::IsAnyWindowHovered() && !ImGui::IsAnyWindowFocused() ) { // Mouse wheel over background if ( io.MouseWheel > 0) { @@ -165,6 +170,22 @@ void UserInterface::handleMouse() if ( ImGui::IsMouseDown(ImGuiMouseButton_Left)) { + Log::Info("Mouse press (%.1f,%.1f)", io.MousePos.x, io.MousePos.y); + + glm::mat4 mv = glm::identity(); + glm::vec3 point = Rendering::manager().unProject(glm::vec2(io.MousePos.x, io.MousePos.y), mv); + + Log::Info(" (%.1f,%.1f)", point.x, point.y); + + } + + if ( ImGui::IsMouseDragging(ImGuiMouseButton_Left, 10.0f) ) + { + Log::Info("Mouse drag (%.1f,%.1f)(%.1f,%.1f)", io.MouseClickedPos[0].x, io.MouseClickedPos[0].y, io.MousePos.x, io.MousePos.y); + ImGui::GetBackgroundDrawList()->AddRect(io.MouseClickedPos[0], io.MousePos, + ImGui::GetColorU32(ImGuiCol_ResizeGripHovered)); + ImGui::GetBackgroundDrawList()->AddRectFilled(io.MouseClickedPos[0], io.MousePos, + ImGui::GetColorU32(ImGuiCol_ResizeGripHovered, 0.3f)); } if ( ImGui::IsMouseReleased(ImGuiMouseButton_Left) ) @@ -177,15 +198,15 @@ void UserInterface::handleMouse() void UserInterface::NewFrame() { - // deal with keyboard and mouse events - handleKeyboard(); - handleMouse(); - // Start the Dear ImGui frame ImGui_ImplOpenGL3_NewFrame(); ImGui_ImplGlfw_NewFrame(); ImGui::NewFrame(); + // deal with keyboard and mouse events + handleKeyboard(); + handleMouse(); + // Main window mainwindow.Render(); diff --git a/main.cpp b/main.cpp index bae68cc..40f87eb 100644 --- a/main.cpp +++ b/main.cpp @@ -271,7 +271,6 @@ int main(int, char**) g2.addChild(&testnode1); g2.addChild(&testnode2); - g2.setActiveIndex(1); scene.root_.addChild(&g2); // init output FBO