Adjusted animation editor timeline frame to fit size of keyframe indicator

This commit is contained in:
Kah Wei 2023-01-09 16:59:50 +08:00
parent 1c56864ccb
commit 1044d79243
1 changed files with 7 additions and 7 deletions

View File

@ -128,7 +128,7 @@ namespace SHADE
// Compute dimensions for the clip
const float COL_WIDTH = windowSize.x - CHANNELS_COL_WIDTH - TMP_TABLE_PADDING;
const float DIST_PER_SECOND = COL_WIDTH / clip.GetTotalTime();
const float DIST_PER_SECOND = 202.666672f;// COL_WIDTH / clip.GetTotalTime(); // Hardcoded distance based on the keyframe icon size
// Get Resources
const auto WINDOW_POS = ImGui::GetWindowPos();
@ -145,18 +145,18 @@ namespace SHADE
// Draw Text
ImGui::SetCursorPos(ImVec2(X_OFFSET, TIMELINE_HEADER_START_POS.y));
std::string timeText = std::format("{:.{}f}", time, 1);
SHEditorUI::CenteredText(timeText.c_str());
SHEditorUI::Text(timeText);
// Draw line
ImVec2 startPoint { WINDOW_POS.x + X_OFFSET, WINDOW_POS.y + TIMELINE_HEADER_START_POS.y };
drawList->AddLine(startPoint, ImVec2(startPoint.x, startPoint.y + windowSize.y), ImGui::GetColorU32(ImVec4(1.0f, 1.0f, 1.0f, 1.0f)));
drawList->AddLine(startPoint, ImVec2(startPoint.x, startPoint.y + beginContentRegionAvailable.y), ImGui::GetColorU32(ImVec4(1.0f, 1.0f, 1.0f, 1.0f)));
// Draw smaller lines
static constexpr float MINI_STEP = 0.1f;
for (float innerTime = time; innerTime < std::min(time + STEP, clip.GetTotalTime()); innerTime += MINI_STEP)
{
ImVec2 innerStartPoint { WINDOW_POS.x + TIMELINE_HEADER_START_POS.x + innerTime * DIST_PER_SECOND, WINDOW_POS.y + TIMELINE_HEADER_START_POS.y };
drawList->AddLine(innerStartPoint, ImVec2(innerStartPoint.x, innerStartPoint.y + windowSize.y), ImGui::GetColorU32(ImVec4(0.2f, 0.2f, 0.2f, 1.0f)));
ImVec2 innerStartPoint{ WINDOW_POS.x + TIMELINE_HEADER_START_POS.x + innerTime * DIST_PER_SECOND, WINDOW_POS.y + TIMELINE_HEADER_START_POS.y };
drawList->AddLine(innerStartPoint, ImVec2(innerStartPoint.x, innerStartPoint.y + beginContentRegionAvailable.y), ImGui::GetColorU32(ImVec4(0.2f, 0.2f, 0.2f, 1.0f)));
}
}
ImGui::SetCursorPos(TIMELINE_HEADER_START_POS);
@ -169,12 +169,12 @@ namespace SHADE
ImGui::Text(channel.Name.c_str());
ImGui::TableNextColumn();
// Draw all the keyframes
const auto START_POS = ImGui::GetCursorPos();
for (const auto& keyframe : channel.KeyFrames)
{
ImGui::SetCursorPos(ImVec2(START_POS.x + keyframe.TimeStamp * DIST_PER_SECOND, START_POS.y));
static constexpr float ICON_WIDTH = 6.0f; // We do this as ImGui gives the wrong width for icon fonts
SHEditorUI::OffsetText(ICON_MD_RADIO_BUTTON_CHECKED, -ICON_WIDTH * 0.5f);
SHEditorUI::OffsetText(ICON_MD_RADIO_BUTTON_CHECKED, 6.0f); // Hardcoded offset to align icon since ImGui can't calculate icon with properly
}
ImGui::SetCursorPos(START_POS);
}