Add scene viewport move gizmo workflow
This commit is contained in:
@@ -10,6 +10,18 @@ Math::Matrix4x4 BuildOverlayViewMatrix(const SceneViewportOverlayData& overlay)
|
||||
return BuildSceneViewportViewMatrix(overlay);
|
||||
}
|
||||
|
||||
ImU32 ToImGuiColor(const Math::Color& color) {
|
||||
const auto toChannel = [](float value) -> int {
|
||||
return static_cast<int>(std::clamp(value, 0.0f, 1.0f) * 255.0f + 0.5f);
|
||||
};
|
||||
|
||||
return IM_COL32(
|
||||
toChannel(color.r),
|
||||
toChannel(color.g),
|
||||
toChannel(color.b),
|
||||
toChannel(color.a));
|
||||
}
|
||||
|
||||
void DrawAxisLabel(ImDrawList* drawList, const ImVec2& position, const char* label, ImU32 color) {
|
||||
if (drawList == nullptr || label == nullptr) {
|
||||
return;
|
||||
@@ -61,6 +73,31 @@ void DrawSceneAxisWidget(
|
||||
}
|
||||
}
|
||||
|
||||
void DrawSceneMoveGizmo(
|
||||
ImDrawList* drawList,
|
||||
const SceneViewportMoveGizmoDrawData& moveGizmo) {
|
||||
if (drawList == nullptr || !moveGizmo.visible) {
|
||||
return;
|
||||
}
|
||||
|
||||
const ImVec2 pivot(moveGizmo.pivot.x, moveGizmo.pivot.y);
|
||||
drawList->AddCircleFilled(pivot, moveGizmo.pivotRadius + 1.0f, IM_COL32(20, 22, 24, 220), 20);
|
||||
drawList->AddCircle(pivot, moveGizmo.pivotRadius + 1.0f, IM_COL32(255, 255, 255, 48), 20, 1.0f);
|
||||
|
||||
for (const SceneViewportMoveGizmoHandleDrawData& handle : moveGizmo.handles) {
|
||||
if (!handle.visible) {
|
||||
continue;
|
||||
}
|
||||
|
||||
const ImU32 color = ToImGuiColor(handle.color);
|
||||
const float thickness = handle.active ? 4.0f : (handle.hovered ? 3.0f : 2.0f);
|
||||
const ImVec2 start(handle.start.x, handle.start.y);
|
||||
const ImVec2 end(handle.end.x, handle.end.y);
|
||||
drawList->AddLine(start, end, color, thickness);
|
||||
drawList->AddCircleFilled(end, handle.active ? 6.5f : 5.5f, color, 20);
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
void DrawSceneViewportOverlay(
|
||||
@@ -68,13 +105,19 @@ void DrawSceneViewportOverlay(
|
||||
const SceneViewportOverlayData& overlay,
|
||||
const ImVec2& viewportMin,
|
||||
const ImVec2& viewportMax,
|
||||
const ImVec2& viewportSize) {
|
||||
if (drawList == nullptr || !overlay.valid || viewportSize.x <= 1.0f || viewportSize.y <= 1.0f) {
|
||||
const ImVec2& viewportSize,
|
||||
const SceneViewportMoveGizmoDrawData* moveGizmo) {
|
||||
if (drawList == nullptr || viewportSize.x <= 1.0f || viewportSize.y <= 1.0f) {
|
||||
return;
|
||||
}
|
||||
|
||||
drawList->PushClipRect(viewportMin, viewportMax, true);
|
||||
DrawSceneAxisWidget(drawList, overlay, viewportMin, viewportMax);
|
||||
if (overlay.valid) {
|
||||
DrawSceneAxisWidget(drawList, overlay, viewportMin, viewportMax);
|
||||
}
|
||||
if (moveGizmo != nullptr) {
|
||||
DrawSceneMoveGizmo(drawList, *moveGizmo);
|
||||
}
|
||||
drawList->PopClipRect();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user