Move DrawTextAt from imgui_bridge to imgui_widgets.
PiperOrigin-RevId: 919508805 Change-Id: Ie311b88164d8c2ff7a8452ec2f1b8be7e7d9770e
This commit is contained in:
committed by
Copybara-Service
parent
3499adacae
commit
8ae51e104d
@@ -32,6 +32,7 @@
|
|||||||
#include "experimental/filament/render_context_filament_cpp.h"
|
#include "experimental/filament/render_context_filament_cpp.h"
|
||||||
#include "experimental/platform/hal/graphics_mode.h"
|
#include "experimental/platform/hal/graphics_mode.h"
|
||||||
#include "experimental/platform/ux/imgui_bridge.h"
|
#include "experimental/platform/ux/imgui_bridge.h"
|
||||||
|
#include "experimental/platform/ux/imgui_widgets.h"
|
||||||
#include "experimental/platform/ux/plugin.h"
|
#include "experimental/platform/ux/plugin.h"
|
||||||
|
|
||||||
namespace mujoco::platform {
|
namespace mujoco::platform {
|
||||||
|
|||||||
@@ -318,36 +318,4 @@ mjrCamera ImguiBridge::GetCamera(int width, int height) const {
|
|||||||
return camera;
|
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
|
} // namespace mujoco
|
||||||
|
|||||||
@@ -65,10 +65,6 @@ class ImguiBridge {
|
|||||||
uintptr_t next_tex_id_ = 1;
|
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
|
} // namespace mujoco
|
||||||
|
|
||||||
#endif // MUJOCO_SRC_EXPERIMENTAL_PLATFORM_UX_IMGUI_BRIDGE_H_
|
#endif // MUJOCO_SRC_EXPERIMENTAL_PLATFORM_UX_IMGUI_BRIDGE_H_
|
||||||
|
|||||||
@@ -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
|
} // namespace mujoco::platform
|
||||||
|
|||||||
@@ -656,6 +656,10 @@ struct ImPlotPairLayout {
|
|||||||
// side-by-side; otherwise they are stacked vertically.
|
// side-by-side; otherwise they are stacked vertically.
|
||||||
ImPlotPairLayout ImPlot_ComputePairLayout();
|
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
|
} // namespace mujoco::platform
|
||||||
|
|
||||||
#endif // MUJOCO_SRC_EXPERIMENTAL_PLATFORM_UX_IMGUI_WIDGETS_H_
|
#endif // MUJOCO_SRC_EXPERIMENTAL_PLATFORM_UX_IMGUI_WIDGETS_H_
|
||||||
|
|||||||
Reference in New Issue
Block a user