diff --git a/src/experimental/platform/hal/renderer.cc b/src/experimental/platform/hal/renderer.cc index 591965dd..0acfc70c 100644 --- a/src/experimental/platform/hal/renderer.cc +++ b/src/experimental/platform/hal/renderer.cc @@ -32,6 +32,7 @@ #include "experimental/filament/render_context_filament_cpp.h" #include "experimental/platform/hal/graphics_mode.h" #include "experimental/platform/ux/imgui_bridge.h" +#include "experimental/platform/ux/imgui_widgets.h" #include "experimental/platform/ux/plugin.h" namespace mujoco::platform { diff --git a/src/experimental/platform/ux/imgui_bridge.cc b/src/experimental/platform/ux/imgui_bridge.cc index 91147fa4..ef042507 100644 --- a/src/experimental/platform/ux/imgui_bridge.cc +++ b/src/experimental/platform/ux/imgui_bridge.cc @@ -318,36 +318,4 @@ mjrCamera ImguiBridge::GetCamera(int width, int height) const { return camera; } -static ImVec2 ClipSpaceToWindowCoordinates(float x, float y) { - const ImVec2& display_size = ImGui::GetIO().DisplaySize; - const float pos_x = display_size.x * ((x + 1) * 0.5f); - const float pos_y = display_size.y * (1.0f - ((y + 1) * 0.5f)); - return ImVec2(pos_x, pos_y); -} - -void DrawTextAt(const char* text, float x, float y, float z) { - if (x < -1 || y < -1 || x > 1 || y > 1 || z < -1 || z > 1) { - return; - } - - const ImVec2 center_pos = ClipSpaceToWindowCoordinates(x, y); - const ImVec2 size = ImGui::CalcTextSize(text); - - const ImVec2 pos = ImVec2(center_pos.x - size.x / 2, center_pos.y); - const ImVec2 shadow_pos = ImVec2(pos.x + 2, pos.y + 2); - const int flags = ImGuiWindowFlags_NoBringToFrontOnFocus | - ImGuiWindowFlags_NoFocusOnAppearing | - ImGuiWindowFlags_NoBackground | - ImGuiWindowFlags_NoDecoration | ImGuiWindowFlags_NoInputs | - ImGuiWindowFlags_NoNav; - - ImGui::Begin("labels", nullptr, flags); - ImGui::BeginChild("labels", ImGui::GetIO().DisplaySize, 0, flags); - ImDrawList* draw_list = ImGui::GetWindowDrawList(); - draw_list->AddText(shadow_pos, IM_COL32_BLACK, text); - draw_list->AddText(pos, IM_COL32_WHITE, text); - ImGui::EndChild(); - ImGui::End(); -} - } // namespace mujoco diff --git a/src/experimental/platform/ux/imgui_bridge.h b/src/experimental/platform/ux/imgui_bridge.h index 9baefd04..f2fa8916 100644 --- a/src/experimental/platform/ux/imgui_bridge.h +++ b/src/experimental/platform/ux/imgui_bridge.h @@ -65,10 +65,6 @@ class ImguiBridge { uintptr_t next_tex_id_ = 1; }; -// Draws text at the given screen coordinates in clip space (i.e. [-1,-1,-1] to -// [1,1,1]). -void DrawTextAt(const char* text, float x, float y, float z); - } // namespace mujoco #endif // MUJOCO_SRC_EXPERIMENTAL_PLATFORM_UX_IMGUI_BRIDGE_H_ diff --git a/src/experimental/platform/ux/imgui_widgets.cc b/src/experimental/platform/ux/imgui_widgets.cc index cf33bc8d..2ee56a3d 100644 --- a/src/experimental/platform/ux/imgui_widgets.cc +++ b/src/experimental/platform/ux/imgui_widgets.cc @@ -446,4 +446,36 @@ ImPlotPairLayout ImPlot_ComputePairLayout() { }; } +static ImVec2 ClipSpaceToWindowCoordinates(float x, float y) { + const ImVec2& display_size = ImGui::GetIO().DisplaySize; + const float pos_x = display_size.x * ((x + 1) * 0.5f); + const float pos_y = display_size.y * (1.0f - ((y + 1) * 0.5f)); + return ImVec2(pos_x, pos_y); +} + +void DrawTextAt(const char* text, float x, float y, float z) { + if (x < -1 || y < -1 || x > 1 || y > 1 || z < -1 || z > 1) { + return; + } + + const ImVec2 center_pos = ClipSpaceToWindowCoordinates(x, y); + const ImVec2 size = ImGui::CalcTextSize(text); + + const ImVec2 pos = ImVec2(center_pos.x - size.x / 2, center_pos.y); + const ImVec2 shadow_pos = ImVec2(pos.x + 2, pos.y + 2); + const int flags = ImGuiWindowFlags_NoBringToFrontOnFocus | + ImGuiWindowFlags_NoFocusOnAppearing | + ImGuiWindowFlags_NoBackground | + ImGuiWindowFlags_NoDecoration | ImGuiWindowFlags_NoInputs | + ImGuiWindowFlags_NoNav; + + ImGui::Begin("labels", nullptr, flags); + ImGui::BeginChild("labels", ImGui::GetIO().DisplaySize, 0, flags); + ImDrawList* draw_list = ImGui::GetWindowDrawList(); + draw_list->AddText(shadow_pos, IM_COL32_BLACK, text); + draw_list->AddText(pos, IM_COL32_WHITE, text); + ImGui::EndChild(); + ImGui::End(); +} + } // namespace mujoco::platform diff --git a/src/experimental/platform/ux/imgui_widgets.h b/src/experimental/platform/ux/imgui_widgets.h index 3ee85efa..211b213d 100644 --- a/src/experimental/platform/ux/imgui_widgets.h +++ b/src/experimental/platform/ux/imgui_widgets.h @@ -656,6 +656,10 @@ struct ImPlotPairLayout { // side-by-side; otherwise they are stacked vertically. ImPlotPairLayout ImPlot_ComputePairLayout(); +// Draws text at the given screen coordinates in clip space (i.e. [-1,-1,-1] to +// [1,1,1]). +void DrawTextAt(const char* text, float x, float y, float z); + } // namespace mujoco::platform #endif // MUJOCO_SRC_EXPERIMENTAL_PLATFORM_UX_IMGUI_WIDGETS_H_