diff --git a/common/device-model.cpp b/common/device-model.cpp index 3632c34e9a..d0ca7eea15 100644 --- a/common/device-model.cpp +++ b/common/device-model.cpp @@ -798,7 +798,7 @@ namespace rs2 float seek_bar_width = 300.f; ImGui::PushItemWidth(seek_bar_width); std::string label1 = "## " + id; - if (ImGui::SeekSlider(label1.c_str(), &seek_pos, "")) + if (ImGui::SliderInt(label1.c_str(), &seek_pos, 0, 100, "")) { //Seek was dragged if (playback_status != RS2_PLAYBACK_STATUS_STOPPED) //Ignore seek when playback is stopped diff --git a/common/option-model.cpp b/common/option-model.cpp index 6a3b6ee9ed..cebc5bf0bc 100644 --- a/common/option-model.cpp +++ b/common/option-model.cpp @@ -257,8 +257,7 @@ bool option_model::draw_combobox( notifications_model & model, if( new_line ) ImGui::SetCursorPosX( combo_position_x ); - float combo_width = 315 - combo_position_x; - ImGui::PushItemWidth( new_line ? combo_width : 100.f ); + ImGui::PushItemWidth( new_line ? -1.f : 100.f ); int selected; std::vector< const char * > labels = get_combo_labels( &selected ); @@ -339,7 +338,7 @@ bool option_model::draw_slider( notifications_model & model, ImGui::Text( "%s", txt.c_str() ); ImGui::SameLine(); - ImGui::SetCursorPosX( read_only ? 268.f : 245.f ); + ImGui::SetCursorPosX( read_only ? 280.f : 257.f ); ImGui::PushStyleColor( ImGuiCol_Text, grey ); ImGui::PushStyleColor( ImGuiCol_TextSelectedBg, grey ); ImGui::PushStyleColor( ImGuiCol_ButtonActive, { 1.f, 1.f, 1.f, 0.f } ); @@ -355,7 +354,7 @@ bool option_model::draw_slider( notifications_model & model, if( ! read_only ) { ImGui::SameLine(); - ImGui::SetCursorPosX( 268 ); + ImGui::SetCursorPosX( 280 ); if( ! edit_mode ) { std::string edit_id = rsutils::string::from() << textual_icons::edit << "##" << id; @@ -392,8 +391,8 @@ bool option_model::draw_slider( notifications_model & model, ImGui::PopStyleColor( 4 ); } } - - ImGui::PushItemWidth(245); + float customWidth = 295 - ImGui::GetCursorPosX(); //set slider width from the current Xpos to the right border at 295 (the edit button pos) + ImGui::PushItemWidth(customWidth); ImGui::PushStyleColor(ImGuiCol_FrameBgHovered, black); ImGui::PushStyleColor(ImGuiCol_FrameBgActive, black); try @@ -502,8 +501,7 @@ bool option_model::draw_slider( notifications_model & model, &int_value, static_cast< int >( range.min ), static_cast< int >( range.max ), - static_cast< int >( range.step ), - "%.3f" ) ) // integers don't have any precision + static_cast< int >( range.step )) ) { // TODO: Round to step? slider_clicked = slider_selected( opt, @@ -583,6 +581,7 @@ bool option_model::draw_slider( notifications_model & model, error_message = error_to_string( e ); } ImGui::PopStyleColor(2); + ImGui::PopItemWidth(); return slider_clicked; } diff --git a/common/subdevice-model.cpp b/common/subdevice-model.cpp index 13905beb8a..2b459628b4 100644 --- a/common/subdevice-model.cpp +++ b/common/subdevice-model.cpp @@ -560,7 +560,7 @@ namespace rs2 } else { - ImGui::PushItemWidth(170); // Set the width for the combo box itself + ImGui::PushItemWidth(-1); // Set the width for the combo box itself ImGui::PushStyleColor(ImGuiCol_TextSelectedBg, { 1,1,1,1 }); auto tmp_selected_res_id = ui.selected_res_id; if (ImGui::CustomComboBox(label.c_str(), &tmp_selected_res_id, res_chars.data(), @@ -639,7 +639,7 @@ namespace rs2 } else { - ImGui::PushItemWidth(170); // Set the width for the combo box itself + ImGui::PushItemWidth(-1); // Set the width for the combo box itself ImGui::PushStyleColor(ImGuiCol_TextSelectedBg, { 1,1,1,1 }); if (ImGui::CustomComboBox(label.c_str(), &ui.selected_shared_fps_id, fps_chars.data(), static_cast(fps_chars.size()))) @@ -718,7 +718,7 @@ namespace rs2 } else { - ImGui::PushItemWidth(170); // Set the width for the combo box itself + ImGui::PushItemWidth(-1); // Set the width for the combo box itself ImGui::PushStyleColor(ImGuiCol_TextSelectedBg, { 1,1,1,1 }); ImGui::CustomComboBox(label.c_str(), &ui.selected_format_id[f.first], formats_chars.data(), static_cast(formats_chars.size())); @@ -745,7 +745,7 @@ namespace rs2 } else { - ImGui::PushItemWidth(170); // Set the width for the combo box itself + ImGui::PushItemWidth(-1); // Set the width for the combo box itself ImGui::PushStyleColor(ImGuiCol_TextSelectedBg, { 1,1,1,1 }); ImGui::CustomComboBox(label.c_str(), &ui.selected_fps_id[f.first], fps_chars.data(), static_cast(fps_chars.size())); @@ -800,7 +800,7 @@ namespace rs2 } else { - ImGui::PushItemWidth(170); // Set the width for the combo box itself + ImGui::PushItemWidth(-1); // Set the width for the combo box itself ImGui::PushStyleColor(ImGuiCol_TextSelectedBg, { 1,1,1,1 }); auto tmp_selected_res_id = ui.selected_res_id_map[stream_type_id]; if (ImGui::CustomComboBox(label.c_str(), &tmp_selected_res_id, res_chars.data(), @@ -933,7 +933,7 @@ namespace rs2 } else { - ImGui::PushItemWidth(170); // Set the width for the combo box itself + ImGui::PushItemWidth(-1); // Set the width for the combo box itself ImGui::PushStyleColor(ImGuiCol_TextSelectedBg, { 1,1,1,1 }); ImGui::CustomComboBox(label.c_str(), &ui.selected_format_id[f.first], formats_chars.data(), static_cast(formats_chars.size())); diff --git a/common/ux-window.cpp b/common/ux-window.cpp index 538dae69f2..b4128c7bbf 100644 --- a/common/ux-window.cpp +++ b/common/ux-window.cpp @@ -216,7 +216,6 @@ namespace rs2 void ux_window::open_window() { - if (_win) { rs2::gl::shutdown_rendering(); @@ -637,7 +636,8 @@ namespace rs2 } // reset graphic pipe - begin_frame(); + begin_frame(); + if (_link_hovered) glfwSetCursor(_win, _hand_cursor); else if (_cross_hovered) diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt index b43469404d..5be323b74b 100644 --- a/examples/CMakeLists.txt +++ b/examples/CMakeLists.txt @@ -19,6 +19,9 @@ else() endif() endif() +# Add all imgui cpp source files and store the list in the IMGUI_SOURCES variable +file(GLOB IMGUI_SOURCES "../third-party/imgui/*.cpp") + # We need tclap for command-line interface list(APPEND DEPENDENCIES tclap) diff --git a/examples/align-advanced/CMakeLists.txt b/examples/align-advanced/CMakeLists.txt index 5e24752a65..d35475534d 100644 --- a/examples/align-advanced/CMakeLists.txt +++ b/examples/align-advanced/CMakeLists.txt @@ -6,10 +6,7 @@ project( rs-align-advanced ) if( BUILD_GRAPHICAL_EXAMPLES ) -add_executable( ${PROJECT_NAME} rs-align-advanced.cpp - ../../third-party/imgui/imgui.cpp ../../third-party/imgui/imgui_draw.cpp ../../third-party/imgui/imgui_impl_glfw.cpp - ../../third-party/imgui/realsense_imgui.cpp ../../third-party/imgui/imgui_impl_opengl3.cpp ../../third-party/imgui/imgui_widgets.cpp ../../third-party/imgui/imgui_tables.cpp - ) +add_executable( ${PROJECT_NAME} rs-align-advanced.cpp ${IMGUI_SOURCES}) set_property( TARGET ${PROJECT_NAME} PROPERTY CXX_STANDARD 11 ) target_link_libraries( ${PROJECT_NAME} ${DEPENDENCIES} ) include_directories( ../../third-party/imgui ../../examples ) diff --git a/examples/align-advanced/rs-align-advanced.cpp b/examples/align-advanced/rs-align-advanced.cpp index ba2765ecc6..9be310847f 100644 --- a/examples/align-advanced/rs-align-advanced.cpp +++ b/examples/align-advanced/rs-align-advanced.cpp @@ -12,7 +12,7 @@ #include #include "imgui_impl_glfw.h" #include -#include +#include void render_slider(rect location, float& clipping_dist); void remove_background(rs2::video_frame& other, const rs2::depth_frame& depth_frame, float depth_scale, float clipping_dist); @@ -172,15 +172,14 @@ void render_slider(rect location, float& clipping_dist) //Render the vertical slider ImGui::Begin("slider", nullptr, flags); - ImGui::PushStyleColor(ImGuiCol_FrameBg, { 0.2f / 255, 0.3f / 255, 0.7f / 255 ,1}); - ImGui::PushStyleColor(ImGuiCol_SliderGrab, { 215.f / 255, 215.0f / 255, 215.0f / 255,1 }); - ImGui::PushStyleColor(ImGuiCol_SliderGrabActive, { 215.f / 255, 215.0f / 255, 215.0f / 255,1 }); - ImGui::PushStyleColor(ImGuiCol_FrameBg, { 1.0f, 1.0f, 1.0f, 1.0f }); // White slider bar (background) + ImGui::PushStyleColor(ImGuiCol_FrameBg, ImColor(215.f / 255, 215.0f / 255, 215.0f / 255).Value); + ImGui::PushStyleColor(ImGuiCol_SliderGrab, ImColor(215.f / 255, 215.0f / 255, 215.0f / 255).Value); + ImGui::PushStyleColor(ImGuiCol_SliderGrabActive, ImColor(215.f / 255, 215.0f / 255, 215.0f / 255).Value); auto slider_size = ImVec2(slider_window_width / 2, location.h - (pixels_to_buttom_of_stream_text * 2) - 20); ImGui::VSliderFloat("##vslider", slider_size, &clipping_dist, 0.0f, 6.0f, "", 1.0f, true); if (ImGui::IsItemHovered()) ImGui::SetTooltip("Depth Clipping Distance: %.3f", clipping_dist); - ImGui::PopStyleColor(4); + ImGui::PopStyleColor(3); //Display bars next to slider float bars_dist = (slider_size.y / 6.0f); diff --git a/examples/align-gl/CMakeLists.txt b/examples/align-gl/CMakeLists.txt index b228b749cb..f1852c536c 100644 --- a/examples/align-gl/CMakeLists.txt +++ b/examples/align-gl/CMakeLists.txt @@ -9,10 +9,7 @@ set(CMAKE_EXPORT_COMPILE_COMMANDS 1) if(BUILD_GRAPHICAL_EXAMPLES AND NOT APPLE) -add_executable( ${PROJECT_NAME} rs-align-gl.cpp - ../../third-party/imgui/imgui.cpp ../../third-party/imgui/imgui_draw.cpp ../../third-party/imgui/imgui_impl_glfw.cpp - ../../third-party/imgui/realsense_imgui.cpp ../../third-party/imgui/imgui_impl_opengl3.cpp ../../third-party/imgui/imgui_widgets.cpp ../../third-party/imgui/imgui_tables.cpp - ) +add_executable( ${PROJECT_NAME} rs-align-gl.cpp ${IMGUI_SOURCES}) set_property( TARGET ${PROJECT_NAME} PROPERTY CXX_STANDARD 11 ) target_link_libraries( ${PROJECT_NAME} ${DEPENDENCIES} realsense2-gl ) include_directories( ../../third-party/imgui ../../examples ) diff --git a/examples/align-gl/rs-align-gl.cpp b/examples/align-gl/rs-align-gl.cpp index dc6acb9146..b966b3187a 100644 --- a/examples/align-gl/rs-align-gl.cpp +++ b/examples/align-gl/rs-align-gl.cpp @@ -7,7 +7,7 @@ #include #include "imgui_impl_glfw.h" #include -#include +#include /* This example introduces the concept of spatial stream alignment. diff --git a/examples/align/CMakeLists.txt b/examples/align/CMakeLists.txt index ca17db53f7..b84b12e3cc 100644 --- a/examples/align/CMakeLists.txt +++ b/examples/align/CMakeLists.txt @@ -6,8 +6,7 @@ project( rs-align ) if(BUILD_GRAPHICAL_EXAMPLES) -add_executable( ${PROJECT_NAME} rs-align.cpp ../../third-party/imgui/imgui.cpp ../../third-party/imgui/imgui_draw.cpp ../../third-party/imgui/imgui_impl_glfw.cpp -../../third-party/imgui/realsense_imgui.cpp ../../third-party/imgui/imgui_impl_opengl3.cpp ../../third-party/imgui/imgui_widgets.cpp ../../third-party/imgui/imgui_tables.cpp) +add_executable( ${PROJECT_NAME} rs-align.cpp ${IMGUI_SOURCES}) set_property( TARGET ${PROJECT_NAME} PROPERTY CXX_STANDARD 11 ) target_link_libraries( ${PROJECT_NAME} ${DEPENDENCIES} ) include_directories( ../../third-party/imgui ../../examples ) diff --git a/examples/align/rs-align.cpp b/examples/align/rs-align.cpp index e0bba7d63a..2126906edc 100644 --- a/examples/align/rs-align.cpp +++ b/examples/align/rs-align.cpp @@ -7,7 +7,7 @@ #include "imgui_impl_glfw.h" #include -#include +#include /* This example introduces the concept of spatial stream alignment. diff --git a/examples/capture/CMakeLists.txt b/examples/capture/CMakeLists.txt index 7e469ec2ac..89c48cf939 100644 --- a/examples/capture/CMakeLists.txt +++ b/examples/capture/CMakeLists.txt @@ -5,7 +5,7 @@ cmake_minimum_required(VERSION 3.8) project(RealsenseExamplesCapture) if(BUILD_GRAPHICAL_EXAMPLES) - add_executable(rs-capture rs-capture.cpp ../example.hpp) + add_executable(rs-capture rs-capture.cpp ../example.hpp ${IMGUI_SOURCES}) set_property(TARGET rs-capture PROPERTY CXX_STANDARD 11) target_link_libraries( rs-capture ${DEPENDENCIES} tclap ) include_directories(../ ../../examples) diff --git a/examples/example.hpp b/examples/example.hpp index 5677f87cd3..b4be5f0bfa 100644 --- a/examples/example.hpp +++ b/examples/example.hpp @@ -8,7 +8,6 @@ #define GL_SILENCE_DEPRECATION #define GLFW_INCLUDE_GLU #include -#include #include #include @@ -21,6 +20,7 @@ #include "../third-party/stb_easy_font.h" #include "example-utils.hpp" +#include "../third-party/imgui/imgui_impl_glfw.h" #ifndef PI #define PI 3.14159265358979323846 @@ -531,28 +531,40 @@ class window glfwSetWindowUserPointer(win, this); glfwSetMouseButtonCallback(win, [](GLFWwindow* w, int button, int action, int mods) { - ImGui_ImplGlfw_MouseButtonCallback(w, button, action, mods);// Forward the event to ImGui's GLFW implementation + if (ImGui::GetCurrentContext() != nullptr) + { + ImGui_ImplGlfw_MouseButtonCallback(w, button, action, mods);// Forward the event to ImGui's GLFW implementation + } auto s = (window*)glfwGetWindowUserPointer(w); if (button == 0) s->on_left_mouse(action == GLFW_PRESS); }); glfwSetScrollCallback(win, [](GLFWwindow* w, double xoffset, double yoffset) { - ImGui_ImplGlfw_ScrollCallback(w, xoffset, yoffset); // Forwards scroll events to ImGui + if (ImGui::GetCurrentContext() != nullptr) + { + ImGui_ImplGlfw_ScrollCallback(w, xoffset, yoffset); // Forwards scroll events to ImGui + } auto s = (window*)glfwGetWindowUserPointer(w); s->on_mouse_scroll(xoffset, yoffset); }); glfwSetCursorPosCallback(win, [](GLFWwindow* w, double x, double y) { - ImGui_ImplGlfw_CursorPosCallback(w, x, y); // Forward the cursor position to ImGui + if (ImGui::GetCurrentContext() != nullptr) + { + ImGui_ImplGlfw_CursorPosCallback(w, x, y); // Forward the cursor position to ImGui + } auto s = (window*)glfwGetWindowUserPointer(w); s->on_mouse_move(x, y); }); glfwSetKeyCallback(win, [](GLFWwindow* w, int key, int scancode, int action, int mods) { - ImGui_ImplGlfw_KeyCallback(w, key, scancode, action, mods); + if (ImGui::GetCurrentContext() != nullptr) + { + ImGui_ImplGlfw_KeyCallback(w, key, scancode, action, mods); + } auto s = (window*)glfwGetWindowUserPointer(w); if (0 == action) // on key release { @@ -607,24 +619,40 @@ class window glfwSetWindowUserPointer(win, this); glfwSetMouseButtonCallback(win, [](GLFWwindow* w, int button, int action, int mods) { + if (ImGui::GetCurrentContext() != nullptr) + { + ImGui_ImplGlfw_MouseButtonCallback(w, button, action, mods);// Forward the event to ImGui's GLFW implementation + } auto s = (window*)glfwGetWindowUserPointer(w); if (button == 0) s->on_left_mouse(action == GLFW_PRESS); }); glfwSetScrollCallback(win, [](GLFWwindow* w, double xoffset, double yoffset) { + if (ImGui::GetCurrentContext() != nullptr) + { + ImGui_ImplGlfw_ScrollCallback(w, xoffset, yoffset); // Forwards scroll events to ImGui + } auto s = (window*)glfwGetWindowUserPointer(w); s->on_mouse_scroll(xoffset, yoffset); }); glfwSetCursorPosCallback(win, [](GLFWwindow* w, double x, double y) { + if (ImGui::GetCurrentContext() != nullptr) + { + ImGui_ImplGlfw_CursorPosCallback(w, x, y); // Forward the cursor position to ImGui + } auto s = (window*)glfwGetWindowUserPointer(w); s->on_mouse_move(x, y); }); glfwSetKeyCallback(win, [](GLFWwindow* w, int key, int scancode, int action, int mods) { + if (ImGui::GetCurrentContext() != nullptr) + { + ImGui_ImplGlfw_KeyCallback(w, key, scancode, action, mods); + } auto s = (window*)glfwGetWindowUserPointer(w); if (0 == action) // on key release { diff --git a/examples/gl/CMakeLists.txt b/examples/gl/CMakeLists.txt index f7692f62a9..e824d311a5 100644 --- a/examples/gl/CMakeLists.txt +++ b/examples/gl/CMakeLists.txt @@ -9,7 +9,7 @@ set(CMAKE_EXPORT_COMPILE_COMMANDS 1) if(BUILD_GRAPHICAL_EXAMPLES AND NOT APPLE) #pointcloud - add_executable(rs-gl rs-gl.cpp ../example.hpp) + add_executable(rs-gl rs-gl.cpp ../example.hpp ${IMGUI_SOURCES}) set_property(TARGET rs-gl PROPERTY CXX_STANDARD 11) target_link_libraries(rs-gl ${DEPENDENCIES} realsense2-gl) include_directories(../) diff --git a/examples/hdr/CMakeLists.txt b/examples/hdr/CMakeLists.txt index 846ed0faf8..244999686a 100644 --- a/examples/hdr/CMakeLists.txt +++ b/examples/hdr/CMakeLists.txt @@ -5,7 +5,7 @@ cmake_minimum_required(VERSION 3.8) project(RealsenseExamplesHdr) if(BUILD_GRAPHICAL_EXAMPLES) - add_executable(rs-hdr rs-hdr.cpp ../example.hpp ../../third-party/imgui/imgui.cpp ../../third-party/imgui/imgui_draw.cpp ../../third-party/imgui/imgui_impl_glfw.cpp ../../third-party/imgui/realsense_imgui.cpp ../../third-party/imgui/imgui_impl_opengl3.cpp ../../third-party/imgui/imgui_widgets.cpp ../../third-party/imgui/imgui_tables.cpp) + add_executable(rs-hdr rs-hdr.cpp ../example.hpp ${IMGUI_SOURCES}) set_property(TARGET rs-hdr PROPERTY CXX_STANDARD 11) target_link_libraries( rs-hdr ${DEPENDENCIES} tclap ) include_directories(../ ../../third-party/imgui ../../third-party/glfw/include) diff --git a/examples/hdr/rs-hdr.cpp b/examples/hdr/rs-hdr.cpp index f5feae61f6..caf61e7387 100644 --- a/examples/hdr/rs-hdr.cpp +++ b/examples/hdr/rs-hdr.cpp @@ -109,7 +109,7 @@ int main() try // Setup Dear ImGui context ImGui::CreateContext(); // Setup Platform/Renderer backends - ImGui_ImplGlfw_InitForOpenGL(app, true); + ImGui_ImplGlfw_InitForOpenGL(app, false); ImGui_ImplOpenGL3_Init(); // init hdr_widgets object diff --git a/examples/measure/CMakeLists.txt b/examples/measure/CMakeLists.txt index ed9e74493d..bba3241545 100644 --- a/examples/measure/CMakeLists.txt +++ b/examples/measure/CMakeLists.txt @@ -8,7 +8,7 @@ set(THREADS_PREFER_PTHREAD_FLAG ON) find_package(Threads REQUIRED) if(BUILD_GRAPHICAL_EXAMPLES) - add_executable(${PROJECT_NAME} rs-measure.cpp ../example.hpp) + add_executable(${PROJECT_NAME} rs-measure.cpp ../example.hpp ${IMGUI_SOURCES}) set_property(TARGET ${PROJECT_NAME} PROPERTY CXX_STANDARD 11) target_link_libraries(${PROJECT_NAME} ${DEPENDENCIES} Threads::Threads) include_directories(../) diff --git a/examples/motion/CMakeLists.txt b/examples/motion/CMakeLists.txt index 219003331b..7df12ecd11 100644 --- a/examples/motion/CMakeLists.txt +++ b/examples/motion/CMakeLists.txt @@ -5,7 +5,7 @@ cmake_minimum_required(VERSION 3.8) project(RealsenseExamplesMotion) if(BUILD_GRAPHICAL_EXAMPLES) - add_executable(rs-motion rs-motion.cpp ../example.hpp ../../common/res/d435.h ${LZ4_DIR}/lz4.c) + add_executable(rs-motion rs-motion.cpp ../example.hpp ../../common/res/d435.h ${LZ4_DIR}/lz4.c ${IMGUI_SOURCES}) set_property(TARGET rs-motion PROPERTY CXX_STANDARD 11) target_link_libraries(rs-motion ${DEPENDENCIES}) include_directories(../ ../../common/res ${LZ4_DIR}) diff --git a/examples/multicam/CMakeLists.txt b/examples/multicam/CMakeLists.txt index 26e12744c1..861404052a 100644 --- a/examples/multicam/CMakeLists.txt +++ b/examples/multicam/CMakeLists.txt @@ -5,7 +5,7 @@ cmake_minimum_required(VERSION 3.8) project(RealsenseExamplesMulticam) if(BUILD_GRAPHICAL_EXAMPLES) - add_executable(rs-multicam rs-multicam.cpp ../example.hpp) + add_executable(rs-multicam rs-multicam.cpp ../example.hpp ${IMGUI_SOURCES}) set_property(TARGET rs-multicam PROPERTY CXX_STANDARD 11) include_directories(../) target_link_libraries(rs-multicam ${DEPENDENCIES}) diff --git a/examples/pointcloud/CMakeLists.txt b/examples/pointcloud/CMakeLists.txt index a548a7a73c..6477922ba2 100644 --- a/examples/pointcloud/CMakeLists.txt +++ b/examples/pointcloud/CMakeLists.txt @@ -5,7 +5,7 @@ cmake_minimum_required(VERSION 3.8) project(RealsenseExamplesPointcloud) if(BUILD_GRAPHICAL_EXAMPLES) - add_executable(rs-pointcloud rs-pointcloud.cpp ../example.hpp) + add_executable(rs-pointcloud rs-pointcloud.cpp ../example.hpp ${IMGUI_SOURCES}) set_property(TARGET rs-pointcloud PROPERTY CXX_STANDARD 11) target_link_libraries(rs-pointcloud ${DEPENDENCIES}) include_directories(../) diff --git a/examples/post-processing/CMakeLists.txt b/examples/post-processing/CMakeLists.txt index aff5e08518..85603d3754 100644 --- a/examples/post-processing/CMakeLists.txt +++ b/examples/post-processing/CMakeLists.txt @@ -5,7 +5,7 @@ cmake_minimum_required(VERSION 3.8) project(RealsenseExamplesPost-Processing) if(BUILD_GRAPHICAL_EXAMPLES) - add_executable(rs-post-processing rs-post-processing.cpp ../example.hpp ../../third-party/imgui/imgui.cpp ../../third-party/imgui/imgui_draw.cpp ../../third-party/imgui/imgui_impl_glfw.cpp ../../third-party/imgui/realsense_imgui.cpp ../../third-party/imgui/imgui_impl_opengl3.cpp ../../third-party/imgui/imgui_widgets.cpp ../../third-party/imgui/imgui_tables.cpp) + add_executable(rs-post-processing rs-post-processing.cpp ../example.hpp ${IMGUI_SOURCES}) set_property(TARGET rs-post-processing PROPERTY CXX_STANDARD 11) target_link_libraries( rs-post-processing ${DEPENDENCIES} tclap ) include_directories(../ ../../third-party/imgui) diff --git a/examples/post-processing/rs-post-processing.cpp b/examples/post-processing/rs-post-processing.cpp index c1f0dd9c4f..fa063aa540 100644 --- a/examples/post-processing/rs-post-processing.cpp +++ b/examples/post-processing/rs-post-processing.cpp @@ -336,7 +336,7 @@ bool filter_slider_ui::render(const float3& location, bool enabled) if (is_int) { int value_as_int = static_cast(value); - value_changed = ImGui::SliderInt(("##" + name).c_str(), &value_as_int, static_cast(range.min), static_cast(range.max), "%.0f"); + value_changed = ImGui::SliderIntTofloat(("##" + name).c_str(), &value_as_int, static_cast(range.min), static_cast(range.max), "%.0f"); if( step > 1 ) { value_as_int = static_cast< int >( range.min ) diff --git a/examples/record-playback/CMakeLists.txt b/examples/record-playback/CMakeLists.txt index 9fb4ade713..902f5c5c81 100644 --- a/examples/record-playback/CMakeLists.txt +++ b/examples/record-playback/CMakeLists.txt @@ -5,7 +5,7 @@ cmake_minimum_required(VERSION 3.8) project(RealsenseExamplesRecord-Playback) if(BUILD_GRAPHICAL_EXAMPLES) - add_executable(rs-record-playback rs-record-playback.cpp ../example.hpp ../../third-party/imgui/imgui.cpp ../../third-party/imgui/imgui_draw.cpp ../../third-party/imgui/imgui_impl_glfw.cpp ../../third-party/imgui/realsense_imgui.cpp ../../third-party/imgui/imgui_impl_opengl3.cpp ../../third-party/imgui/imgui_widgets.cpp ../../third-party/imgui/imgui_tables.cpp) + add_executable(rs-record-playback rs-record-playback.cpp ../example.hpp ${IMGUI_SOURCES}) set_property(TARGET rs-record-playback PROPERTY CXX_STANDARD 11) target_link_libraries( rs-record-playback ${DEPENDENCIES} tclap ) include_directories(../ ../../third-party/imgui) diff --git a/examples/sensor-control/CMakeLists.txt b/examples/sensor-control/CMakeLists.txt index 64d6f29ffe..b4d57e62af 100644 --- a/examples/sensor-control/CMakeLists.txt +++ b/examples/sensor-control/CMakeLists.txt @@ -5,7 +5,7 @@ cmake_minimum_required(VERSION 3.8) project(RealsenseExamplesSensorControl) if(BUILD_GRAPHICAL_EXAMPLES) - add_executable(rs-sensor-control api_how_to.h rs-sensor-control.cpp) + add_executable(rs-sensor-control api_how_to.h rs-sensor-control.cpp ${IMGUI_SOURCES}) set_property(TARGET rs-sensor-control PROPERTY CXX_STANDARD 11) target_link_libraries(rs-sensor-control ${DEPENDENCIES}) set_target_properties (rs-sensor-control PROPERTIES FOLDER Examples) diff --git a/examples/software-device/CMakeLists.txt b/examples/software-device/CMakeLists.txt index 28539563e0..13d2c890a2 100644 --- a/examples/software-device/CMakeLists.txt +++ b/examples/software-device/CMakeLists.txt @@ -8,7 +8,7 @@ project(RealsenseExamplesSoftwareDevice) set(CMAKE_EXPORT_COMPILE_COMMANDS 1) if(BUILD_GRAPHICAL_EXAMPLES) - add_executable(rs-software-device rs-software-device.cpp) + add_executable(rs-software-device rs-software-device.cpp ${IMGUI_SOURCES}) set_property(TARGET rs-software-device PROPERTY CXX_STANDARD 11) target_link_libraries( rs-software-device ${DEPENDENCIES} tclap ) include_directories(../ ../../third-party/ ../../common/res) diff --git a/third-party/imgui/imgui.cpp b/third-party/imgui/imgui.cpp index 31220bdf28..d13b7678c1 100644 --- a/third-party/imgui/imgui.cpp +++ b/third-party/imgui/imgui.cpp @@ -5547,8 +5547,8 @@ bool ImGui::BeginChildEx(const char* name, ImGuiID id, const ImVec2& size_arg, I #ifndef IMGUI_DISABLE_OBSOLETE_FUNCTIONS if (window_flags & ImGuiWindowFlags_AlwaysUseWindowPadding) child_flags |= ImGuiChildFlags_AlwaysUseWindowPadding; - if (window_flags & ImGuiWindowFlags_NavFlattened) - child_flags |= ImGuiChildFlags_NavFlattened; + //if (window_flags & ImGuiWindowFlags_NavFlattened) + // child_flags |= ImGuiChildFlags_NavFlattened; #endif if (child_flags & ImGuiChildFlags_AutoResizeX) child_flags &= ~ImGuiChildFlags_ResizeX; diff --git a/third-party/imgui/imgui.h b/third-party/imgui/imgui.h index a22e7ae9ce..c106214897 100644 --- a/third-party/imgui/imgui.h +++ b/third-party/imgui/imgui.h @@ -1055,7 +1055,7 @@ enum ImGuiWindowFlags_ // Obsolete names #ifndef IMGUI_DISABLE_OBSOLETE_FUNCTIONS ImGuiWindowFlags_AlwaysUseWindowPadding = 1 << 30, // Obsoleted in 1.90: Use ImGuiChildFlags_AlwaysUseWindowPadding in BeginChild() call. - ImGuiWindowFlags_NavFlattened = 1 << 31, // Obsoleted in 1.90.9: Use ImGuiChildFlags_NavFlattened in BeginChild() call. + //ImGuiWindowFlags_NavFlattened = 1 << 31, // Obsoleted in 1.90.9: Use ImGuiChildFlags_NavFlattened in BeginChild() call. #endif }; diff --git a/third-party/imgui/realsense_imgui.cpp b/third-party/imgui/realsense_imgui.cpp index b1edec2279..c46a91cc45 100644 --- a/third-party/imgui/realsense_imgui.cpp +++ b/third-party/imgui/realsense_imgui.cpp @@ -2,101 +2,36 @@ /* Copyright(c) 2024 Intel Corporation. All Rights Reserved. */ //Overloading imgui functions to accommodate realsense GUI -#include +#include "realsense_imgui.h" - -static void ClosePopup(ImGuiID id); - -bool ImGui::SeekSlider(const char* label, int* v, const char* display_format) { - return SliderInt(label, v, 0, 100, display_format, true); -} - -// center_y_ratio: 0.0f top of last item, 0.5f vertical center of last item, 1.0f bottom of last item. -void ImGui::SetScrollHere(float center_y_ratio) -{ - ImGuiWindow* window = GetCurrentWindow(); - float target_y = window->DC.CursorPosPrevLine.y + (window->DC.PrevLineTextBaseOffset * center_y_ratio) + (GImGui->Style.ItemSpacing.y * (center_y_ratio - 0.5f) * 2.0f); // Precisely aim above, in the middle or below the last line. - SetScrollFromPosY(target_y - window->Pos.y, center_y_ratio); -} -static bool Items_SingleStringGetter(void* data, int idx, const char** out_text) -{ - // FIXME-OPT: we could pre-compute the indices to fasten this. But only 1 active combo means the waste is limited. - const char* items_separated_by_zeros = (const char*)data; - int items_count = 0; - const char* p = items_separated_by_zeros; - while (*p) - { - if (idx == items_count) - break; - p += strlen(p) + 1; - items_count++; - } - if (!*p) - return false; - if (out_text) - *out_text = p; - return true; -} -static bool Items_ArrayGetter(void* data, int idx, const char** out_text) -{ - const char** items = (const char**)data; - if (out_text) - *out_text = items[idx]; - return true; -} -// NB: This is an internal helper. The user-facing IsItemHovered() is using data emitted from ItemAdd(), with a slightly different logic. -bool ImGui::IsHovered(const ImRect& bb, ImGuiID id, bool flatten_childs) +bool ImGui::SliderIntWithSteps(const char* label, int* v, int v_min, int v_max, int v_step) { - ImGuiContext& g = *GImGui; - if (g.HoveredId == 0 || g.HoveredId == id || g.HoveredIdAllowOverlap) - { - ImGuiWindow* window = GetCurrentWindowRead(); - if (g.HoveredWindow == window || (flatten_childs && g.HoveredWindow == window->RootWindow)) - if ((g.ActiveId == 0 || g.ActiveId == id || g.ActiveIdAllowOverlap) && IsMouseHoveringRect(bb.Min, bb.Max)) - if (IsWindowContentHoverable(g.HoveredWindow)) - return true; - } - return false; -} + float originalValue = *v; + bool changed = false; -// Provide GUI slider with values according to interval steps -bool ImGui::SliderIntWithSteps(const char* label, int* v, int v_min, int v_max, int v_step, const char* display_format) -{ - if (!display_format) - display_format = "%d"; + float tempValue = static_cast(*v); //to use SliderFloat (integers don't have any precision) - if (!display_format) - display_format = "%.0f"; + // Create the slider with float precision during drag + if (ImGui::SliderFloat(label, &tempValue, static_cast(v_min), static_cast(v_max), "%.3f")) { + changed = true; - float v_f = (float)*v; - bool value_changed = SliderFloat(label, &v_f, (float)v_min, (float)v_max, display_format, 1.0f); + // Round to nearest step while dragging + if (ImGui::IsItemActive()) { + tempValue = roundf(tempValue / static_cast(v_step)) * static_cast(v_step); + *v = static_cast(tempValue); + } + else { + // When not dragging ensure we have a round integer value + *v = static_cast(roundf(tempValue)); + } - *v = (int)v_f; + // ensure the value is between min and max + *v = ImClamp(*v, v_min, v_max); + } - return value_changed; + return changed && (*v != originalValue); } - -// Parse display precision back from the display format string -int ImGui::ParseFormatPrecision(const char* fmt, int default_precision) -{ - int precision = default_precision; - while ((fmt = strchr(fmt, '%')) != NULL) - { - fmt++; - if (fmt[0] == '%') { fmt++; continue; } // Ignore "%%" - while (*fmt >= '0' && *fmt <= '9') - fmt++; - if (*fmt == '.') - { - precision = atoi(fmt + 1); - if (precision < 0 || precision > 10) - precision = default_precision; - } - break; - } - return precision; -} float ImGui::RoundScalar(float value, int decimal_precision) { // Round past decimal precision @@ -113,42 +48,25 @@ float ImGui::RoundScalar(float value, int decimal_precision) value += (min_step - remainder); return negative ? -value : value; } -static void ClosePopup(ImGuiID id) -{ - if (!ImGui::IsPopupOpen(id, ImGuiPopupFlags_AnyPopupLevel)) - return; - ImGuiContext& g = *GImGui; - ImGui::ClosePopupToLevel(g.OpenPopupStack.Size - 1,true); -} -// Render a triangle to denote expanded/collapsed state -void ImGui::RenderCollapseTriangle(ImVec2 p_min, bool is_open, float scale, bool shadow) +bool Items_SingleStringGetter(void* data, int idx, const char** out_text) { - ImGuiContext& g = *GImGui; - ImGuiWindow* window = GetCurrentWindow(); - - const float h = g.FontSize * 1.00f; - const float r = h * 0.40f * scale; - ImVec2 center = ImVec2(h * 0.50f+ p_min.x, h * 0.50f * scale+ p_min.y); - - ImVec2 a, b, c; - if (is_open) - { - center.y -= r * 0.25f; - a = ImVec2(0 * r+ center.x, 1 * r+ center.y) ; - b = ImVec2(-0.866f * r+ center.x, -0.5f * r+ center.y) ; - c = ImVec2(0.866f * r + center.x, -0.5f * r + center.y) ; - } - else + // FIXME-OPT: we could pre-compute the indices to fasten this. But only 1 active combo means the waste is limited. + const char* items_separated_by_zeros = (const char*)data; + int items_count = 0; + const char* p = items_separated_by_zeros; + while (*p) { - a = ImVec2(1 * r+ center.x, 0 * r+ center.y) ; - b = ImVec2(-0.500f*r+ center.x, 0.866f*r+ center.y); - c = ImVec2(-0.500f*r+ center.x, -0.866f*r+ center.y); + if (idx == items_count) + break; + p += strlen(p) + 1; + items_count++; } - - if (shadow && (window->Flags) != 0) - window->DrawList->AddTriangleFilled(ImVec2(2+a.x, 2+a.y), ImVec2(2+b.x, 2+b.y), ImVec2(2+c.x, 2+c.y), GetColorU32(ImGuiCol_BorderShadow)); - window->DrawList->AddTriangleFilled(a, b, c, GetColorU32(ImGuiCol_Text)); + if (!*p) + return false; + if (out_text) + *out_text = p; + return true; } IMGUI_API bool ImGui::CustomComboBox(const char* label, int* current_item, const char* const items[], int items_count) @@ -385,60 +303,6 @@ IMGUI_API bool ImGui::SliderBehavior(const ImRect& frame_bb, ImGuiID id, float* return value_changed; } -// Create text input in place of a slider (when CTRL+Clicking on slider) -IMGUI_API bool ImGui::InputScalarAsWidgetReplacement(const ImRect& aabb, const char* label, ImGuiDataType data_type, void* data_ptr, ImGuiID id, int decimal_precision) -{ - ImGuiContext& g = *GImGui; - ImGuiWindow* window = GetCurrentWindow(); - - // Track whether the item is being used for text input - bool start_text_input = false; - - // First, determine if we should start text input (e.g., CTRL+Click on the slider) - if (ImGui::IsItemFocused() || (ImGui::IsItemHovered() && g.IO.MouseClicked[0])) - { - SetActiveID(id, window); - FocusWindow(window); - - if (ImGui::IsItemFocused() || g.IO.KeyCtrl) - { - start_text_input = true; - } - } - - // If we are in text input mode or if the item is actively being edited, use InputText - if (start_text_input || (g.ActiveId == id && g.ActiveIdSource == ImGuiInputSource_Keyboard)) - { - bool text_value_changed = false; - - // Use InputScalar to handle scalar input (e.g., float, int) - switch (data_type) - { - case ImGuiDataType_Float: - text_value_changed = ImGui::InputScalar(label, data_type, data_ptr, NULL, NULL, ".3f"); - break; - case ImGuiDataType_S32: - text_value_changed = ImGui::InputScalar(label, data_type, data_ptr, NULL, NULL, 0); - break; - // Add other cases if you need support for other scalar types - default: - break; - } - - if (text_value_changed) - { - return true; // If the value changed, return true - } - } - else - { - // If not in text input mode, render the slider as usual - ImGui::SliderFloat(label, (float*)data_ptr, 0.0f, 6.0f); - } - - return false; -} - bool ImGui::VSliderFloat(const char* label, const ImVec2& size, float* v, float v_min, float v_max, const char* display_format, float power, bool render_bg) { ImGuiWindow* window = GetCurrentWindow(); @@ -457,13 +321,13 @@ bool ImGui::VSliderFloat(const char* label, const ImVec2& size, float* v, float if (!ItemAdd(frame_bb, id)) return false; - const bool hovered = IsHovered(frame_bb, id); + const bool hovered = IsItemHovered(); if (hovered) SetHoveredID(id); if (!display_format) display_format = "%.3f"; - int decimal_precision = ParseFormatPrecision(display_format, 3); + int decimal_precision = ImParseFormatPrecision(display_format, 3); if (hovered && g.IO.MouseClicked[0]) { @@ -484,3 +348,13 @@ bool ImGui::VSliderFloat(const char* label, const ImVec2& size, float* v, float return value_changed; } + +bool ImGui::SliderIntTofloat(const char* label, int* v, int v_min, int v_max, const char* display_format) +{ + if (!display_format) + display_format = "%.0f"; + float v_f = (float)*v; + bool value_changed = SliderFloat(label, &v_f, (float)v_min, (float)v_max, display_format, 1.0f); + *v = (int)v_f; + return value_changed; +} diff --git a/third-party/imgui/realsense_imgui.h b/third-party/imgui/realsense_imgui.h index 256e8fb89b..bb9cd09d1b 100644 --- a/third-party/imgui/realsense_imgui.h +++ b/third-party/imgui/realsense_imgui.h @@ -2,8 +2,8 @@ /* Copyright(c) 2024 Intel Corporation. All Rights Reserved. */ #pragma once -#include -#include +#include "imgui.h" +#include "imgui_internal.h" namespace ImGui { @@ -26,17 +26,12 @@ namespace ImGui ScopePushStyleVar(ImGuiStyleVar idx, const ImVec2& val) { PushStyleVar(idx, val); } ~ScopePushStyleVar() { PopStyleVar(); } }; - IMGUI_API void RenderCollapseTriangle(ImVec2 p_min, bool is_open, float scale = 1.0f, bool shadow = false); - IMGUI_API bool SeekSlider(const char* label, int* v, const char* display_format = "%.0f%%"); - IMGUI_API bool SliderIntWithSteps(const char* label, int* v, int v_min, int v_max, int v_step = 1, const char* display_format = "%.3f"); - IMGUI_API bool IsHovered(const ImRect& bb, ImGuiID id, bool flatten_childs = false); - IMGUI_API void SetScrollHere(float center_y_ratio = 0.5f); - IMGUI_API int ParseFormatPrecision(const char* fmt, int default_precision); + IMGUI_API bool SliderIntWithSteps(const char* label, int* v, int v_min, int v_max, int v_step = 1); IMGUI_API float RoundScalar(float value, int decimal_precision); IMGUI_API bool CustomComboBox(const char* label, int* current_item, const char* const items[], int items_count); - IMGUI_API bool VSliderFloat(const char* label, const ImVec2& size, float* v, float v_min, float v_max, const char* display_format, float power, bool render_bg); - IMGUI_API bool InputScalarAsWidgetReplacement(const ImRect& aabb, const char* label, ImGuiDataType data_type, void* data_ptr, ImGuiID id, int decimal_precision); IMGUI_API bool SliderBehavior(const ImRect& frame_bb, ImGuiID id, float* v, float v_min, float v_max, float power, int decimal_precision, ImGuiSliderFlags flags, bool render_bg); + IMGUI_API bool VSliderFloat(const char* label, const ImVec2& size, float* v, float v_min, float v_max, const char* display_format, float power, bool render_bg); + IMGUI_API bool SliderIntTofloat(const char* label, int* v, int v_min, int v_max, const char* display_format = "%.0f"); } #define CONCAT_(x,y) x##y diff --git a/tools/CMakeLists.txt b/tools/CMakeLists.txt index 7098757b98..67381264e5 100644 --- a/tools/CMakeLists.txt +++ b/tools/CMakeLists.txt @@ -10,6 +10,8 @@ set(CMAKE_EXPORT_COMPILE_COMMANDS 1) set_security_flags_for_executable() # tools are executables so we want position indepandent executables and not libraries list( APPEND DEPENDENCIES ${LRS_TARGET} tclap ) +# Add all imgui cpp source files and store the list in the IMGUI_SOURCES variable +file(GLOB IMGUI_SOURCES "../third-party/imgui/*.cpp") if(BUILD_TOOLS) add_subdirectory(convert) diff --git a/tools/depth-quality/CMakeLists.txt b/tools/depth-quality/CMakeLists.txt index e89a1a1b31..9879e708a7 100644 --- a/tools/depth-quality/CMakeLists.txt +++ b/tools/depth-quality/CMakeLists.txt @@ -34,15 +34,7 @@ if(BUILD_GRAPHICAL_EXAMPLES) depth-quality-model.cpp depth-metrics.h ../../common/realsense-ui-advanced-mode.h - ../../third-party/imgui/imgui.cpp - ../../third-party/imgui/imgui_draw.cpp - ../../third-party/imgui/imgui_impl_glfw.cpp - ../../third-party/imgui/imgui_impl_opengl3.cpp - ../../third-party/imgui/imgui_widgets.cpp - ../../third-party/imgui/imgui_tables.cpp - ../../third-party/imgui/realsense_imgui.cpp - ../../third-party/imgui/imgui-fonts-karla.hpp - ../../third-party/imgui/imgui-fonts-fontawesome.hpp + ${IMGUI_SOURCES} ../../third-party/glad/glad.c ../../third-party/tinyfiledialogs/tinyfiledialogs.c ../../third-party/tinyfiledialogs/tinyfiledialogs.h diff --git a/tools/realsense-viewer/CMakeLists.txt b/tools/realsense-viewer/CMakeLists.txt index 48d18687c6..da56392617 100644 --- a/tools/realsense-viewer/CMakeLists.txt +++ b/tools/realsense-viewer/CMakeLists.txt @@ -23,15 +23,7 @@ if(BUILD_GRAPHICAL_EXAMPLES) set(RS_VIEWER_CPP ${COMMON_SRC} realsense-viewer.cpp - ../../third-party/imgui/imgui.cpp - ../../third-party/imgui/imgui_draw.cpp - ../../third-party/imgui/imgui_impl_glfw.cpp - ../../third-party/imgui/imgui-fonts-karla.hpp - ../../third-party/imgui/imgui-fonts-fontawesome.hpp - ../../third-party/imgui/imgui_impl_opengl3.cpp - ../../third-party/imgui/imgui_widgets.cpp - ../../third-party/imgui/imgui_tables.cpp - ../../third-party/imgui/realsense_imgui.cpp + ${IMGUI_SOURCES} ../../common/realsense-ui-advanced-mode.h ../../common/rendering.h ../../common/model-views.h diff --git a/tools/rosbag-inspector/CMakeLists.txt b/tools/rosbag-inspector/CMakeLists.txt index 9cb831c254..1b4c60e6a4 100644 --- a/tools/rosbag-inspector/CMakeLists.txt +++ b/tools/rosbag-inspector/CMakeLists.txt @@ -15,15 +15,7 @@ if(BUILD_GRAPHICAL_EXAMPLES) ../../common/os.h ../../common/os.cpp ../../third-party/glad/glad.c - ../../third-party/imgui/imgui.cpp - ../../third-party/imgui/imgui_draw.cpp - ../../third-party/imgui/imgui_impl_glfw.cpp - ../../third-party/imgui/imgui_impl_opengl3.cpp - ../../third-party/imgui/imgui_widgets.cpp - ../../third-party/imgui/imgui_tables.cpp - ../../third-party/imgui/realsense_imgui.cpp - ../../third-party/imgui/imgui-fonts-karla.hpp - ../../third-party/imgui/imgui-fonts-fontawesome.hpp + ${IMGUI_SOURCES} ../../third-party/tinyfiledialogs/tinyfiledialogs.c ../../third-party/tinyfiledialogs/tinyfiledialogs.h )