Skip to content

Commit

Permalink
imgui CMake addition and dimensions fix
Browse files Browse the repository at this point in the history
  • Loading branch information
Noy-Zini committed Nov 19, 2024
1 parent 7359a51 commit dd72548
Show file tree
Hide file tree
Showing 33 changed files with 136 additions and 267 deletions.
2 changes: 1 addition & 1 deletion common/device-model.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
15 changes: 7 additions & 8 deletions common/option-model.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
Expand Down Expand Up @@ -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 } );
Expand All @@ -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;
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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;
}

Expand Down
12 changes: 6 additions & 6 deletions common/subdevice-model.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down Expand Up @@ -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<int>(fps_chars.size())))
Expand Down Expand Up @@ -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<int>(formats_chars.size()));
Expand All @@ -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<int>(fps_chars.size()));
Expand Down Expand Up @@ -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(),
Expand Down Expand Up @@ -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<int>(formats_chars.size()));
Expand Down
4 changes: 2 additions & 2 deletions common/ux-window.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,6 @@ namespace rs2

void ux_window::open_window()
{

if (_win)
{
rs2::gl::shutdown_rendering();
Expand Down Expand Up @@ -637,7 +636,8 @@ namespace rs2
}

// reset graphic pipe
begin_frame();
begin_frame();

if (_link_hovered)
glfwSetCursor(_win, _hand_cursor);
else if (_cross_hovered)
Expand Down
3 changes: 3 additions & 0 deletions examples/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
5 changes: 1 addition & 4 deletions examples/align-advanced/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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 )
Expand Down
11 changes: 5 additions & 6 deletions examples/align-advanced/rs-align-advanced.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
#include <cstring>
#include "imgui_impl_glfw.h"
#include <imgui_impl_opengl3.h>
#include<realsense_imgui.h>
#include <realsense_imgui.h>

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);
Expand Down Expand Up @@ -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);
Expand Down
5 changes: 1 addition & 4 deletions examples/align-gl/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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 )
Expand Down
2 changes: 1 addition & 1 deletion examples/align-gl/rs-align-gl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
#include <common/cli.h>
#include "imgui_impl_glfw.h"
#include <imgui_impl_opengl3.h>
#include<realsense_imgui.h>
#include <realsense_imgui.h>

/*
This example introduces the concept of spatial stream alignment.
Expand Down
3 changes: 1 addition & 2 deletions examples/align/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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 )
Expand Down
2 changes: 1 addition & 1 deletion examples/align/rs-align.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

#include "imgui_impl_glfw.h"
#include <imgui_impl_opengl3.h>
#include<realsense_imgui.h>
#include <realsense_imgui.h>

/*
This example introduces the concept of spatial stream alignment.
Expand Down
2 changes: 1 addition & 1 deletion examples/capture/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
38 changes: 33 additions & 5 deletions examples/example.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
#define GL_SILENCE_DEPRECATION
#define GLFW_INCLUDE_GLU
#include <GLFW/glfw3.h>
#include <imgui_impl_glfw.h>

#include <string>
#include <sstream>
Expand All @@ -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
Expand Down Expand Up @@ -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
{
Expand Down Expand Up @@ -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
{
Expand Down
2 changes: 1 addition & 1 deletion examples/gl/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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(../)
Expand Down
2 changes: 1 addition & 1 deletion examples/hdr/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion examples/hdr/rs-hdr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion examples/measure/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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(../)
Expand Down
2 changes: 1 addition & 1 deletion examples/motion/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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})
Expand Down
2 changes: 1 addition & 1 deletion examples/multicam/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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})
Expand Down
Loading

0 comments on commit dd72548

Please sign in to comment.