diff options
author | Fox Caminiti <fox@foxcam.net> | 2023-02-13 11:12:47 -0500 |
---|---|---|
committer | Fox Caminiti <fox@foxcam.net> | 2023-02-13 11:12:47 -0500 |
commit | fffb3474ee0321d73a47db01dbc4b6b19670ddc5 (patch) | |
tree | af4c14469a6a49c59785c426f149be43f3bd1147 /src/imgui_ui_timeline.cpp | |
parent | bd25daeae033e4f905ae0145831a7d8fdd92e471 (diff) |
drag and drop file loading
Diffstat (limited to 'src/imgui_ui_timeline.cpp')
-rw-r--r-- | src/imgui_ui_timeline.cpp | 246 |
1 files changed, 126 insertions, 120 deletions
diff --git a/src/imgui_ui_timeline.cpp b/src/imgui_ui_timeline.cpp index 964f7c5..40bc889 100644 --- a/src/imgui_ui_timeline.cpp +++ b/src/imgui_ui_timeline.cpp @@ -818,127 +818,9 @@ ImGui_Timeline_DrawPrecomp(project_data *File, project_state *State, memory *Mem } static void -ImGui_Timeline(project_data *File, project_state *State, memory *Memory, ui *UI, ImGuiIO io, - sorted_comp_array *SortedCompArray, sorted_layer_array *SortedLayerArray, sorted_property_array *SortedPropertyStart, uint16 *SortedKeyframeArray) +ImGui_Timeline_Bar(project_data *File, project_state *State, memory *Memory, ui *UI, ImGuiIO io, + real32 FontHeight, ImVec2 MouseDelta, ImVec2 TimelineSizeWithBorder, ImVec2 *ActivePercentOffset, ImVec2 *ActivePercentZoomed, ImVec2 TimelineSize, ImVec2 TimelineAbsolutePos) { - ImVec2 FramePadding = ImGui::GetStyle().FramePadding; - ImVec2 ItemSpacing = ImGui::GetStyle().ItemSpacing; - ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, ImVec2(0, 0)); - ImGui::PushStyleVar(ImGuiStyleVar_ItemSpacing, ImVec2(0, 0)); // makes setting up the layout easier - ImGui::Begin("Timeline", NULL); - - if (ImGui::IsWindowHovered(ImGuiFocusedFlags_ChildWindows)) { - State->FocusedWindow = focus_timeline; - } - - // if (State->TimelineMode == timeline_mode_graph) - // ImGui_GraphInfo(File, State, Memory, UI, io, SortedPropertyStart, SortedKeyframeArray); - - real32 FontHeight = ImGui::GetFontSize(); - - ImVec2 WindowSize = ImGui::GetWindowSize(); - - if (WindowSize.x < 50 || WindowSize.y < 50) { - ImGui::PopStyleVar(2); - ImGui::End(); - return; - } - - block_composition *MainComp = (block_composition *)Memory_Block_AddressAtIndex(Memory, F_Precomps, File->PrincipalCompIndex); - - ImVec2 WindowMinAbs = ImGui::GetWindowPos(); - ImVec2 WindowMaxAbs = WindowMinAbs + WindowSize; - - ImVec2 ButtonSize = ImVec2(FontHeight*2, FontHeight*2); - - ImVec2 TimelineBorderPadding = ImVec2(FontHeight, FontHeight); - - ImVec2 TimelineSize = ImVec2(WindowSize.x, WindowSize.y); - ImVec2 TimelineSizeWithBorder = TimelineSize - TimelineBorderPadding*2; - ImVec2 TimelineAbsolutePos = WindowMinAbs + TimelineBorderPadding; - - ImVec2 KeyframeSize = ImVec2(FontHeight, FontHeight); - - int32 FrameCount = MainComp->Frame_Count; - - ImDrawList* draw_list = ImGui::GetWindowDrawList(); - draw_list->AddRectFilled(WindowMinAbs, WindowMaxAbs, - IM_COL32(255, 255, 255, 50)); - - - ImGui::BeginChild("Timeline", TimelineSize, true, ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoScrollbar); - - ImGui::PushStyleVar(ImGuiStyleVar_ItemSpacing, ImVec2(0.0f, ItemSpacing.y)); - - ImGui::PushClipRect(TimelineAbsolutePos, TimelineAbsolutePos + TimelineSizeWithBorder, true); - draw_list->PushClipRect(TimelineAbsolutePos, TimelineAbsolutePos + TimelineSizeWithBorder, true); - - real32 LayerIncrement = 40; - - ImVec2 Val_Min(0, 0); - ImVec2 Val_Max(40, LayerIncrement); - - // DebugWatchVar("Selection", &State->RecentSelectionType, d_int); - - // ImVec2 *ActivePercentZoomed = (UI->TimelineMode != timeline_mode_graph) ? &UI->TimelinePercentZoomed : &UI->GraphPercentZoomed; - // ImVec2 *ActivePercentOffset = (UI->TimelineMode != timeline_mode_graph) ? &UI->TimelinePercentOffset : &UI->GraphPercentOffset; - ImVec2 *ActivePercentZoomed = &UI->TimelinePercentZoomed; - ImVec2 *ActivePercentOffset = &UI->TimelinePercentOffset; - - if (ActivePercentZoomed->x == 0) { - *ActivePercentZoomed = ImVec2(1, 1); - } - - ImVec2 ActiveZoomSize = TimelineSizeWithBorder / *ActivePercentZoomed; - ImVec2 ActiveMoveSize = TimelineSizeWithBorder * *ActivePercentOffset / *ActivePercentZoomed; - - ImVec2 TimelineZoomSize = TimelineSizeWithBorder / UI->TimelinePercentZoomed; - ImVec2 TimelineMoveSize = TimelineSizeWithBorder * UI->TimelinePercentOffset / UI->TimelinePercentZoomed; - - // DebugWatchVar("TimelineY: ", &TimelineMoveSize.y, d_float); - - ImVec2 Increment = ImVec2((real32)1 / MainComp->Frame_Count, (real32)1 / LayerIncrement); - - ImGui_Timeline_BGElements(File, State, Memory, UI, draw_list, TimelineSizeWithBorder, TimelineAbsolutePos, *MainComp, TimelineZoomSize, TimelineMoveSize); - - int16 RecursionIdx[MAX_PRECOMP_RECURSIONS] = {}; - int32 Recursions = 0; - RecursionIdx[0] = -1; - ImGui_Timeline_DrawPrecomp(File, State, Memory, UI, io, draw_list, RecursionIdx, Recursions, - Increment, TimelineAbsolutePos, TimelineMoveSize, TimelineZoomSize, - TimelineSize, TimelineSizeWithBorder, LayerIncrement, - SortedCompArray, SortedLayerArray, SortedPropertyStart, SortedKeyframeArray); - - if (State->TimelineMode == timeline_mode_graph) { - - if (UI->GraphMoveSize.y == 0) { - UI->GraphZoomSize = ImVec2(1, UI->TimelinePercentZoomed.y ); - UI->GraphMoveSize = ImVec2(0, -UI->TimelinePercentOffset.y ); - } - - ImVec2 ZoomDifference = (UI->TimelinePercentZoomed / UI->GraphZoomSize); - ImVec2 MoveDifference = (UI->TimelinePercentOffset + (UI->GraphMoveSize)); - // DebugWatchVar("zoomdif: ", &ZoomDifference.y, d_float); - // DebugWatchVar("movedif: ", &MoveDifference.y, d_float); - ImVec2 GraphZoomSize = TimelineSizeWithBorder / ZoomDifference; - ImVec2 GraphMoveSize = TimelineSizeWithBorder * (MoveDifference) / UI->TimelinePercentZoomed; - // DebugWatchVar("zoomsize: ", &GraphZoomSize.y, d_float); - // DebugWatchVar("movesize: ", &GraphMoveSize.y, d_float); - - draw_list->AddRectFilled(WindowMinAbs, WindowMaxAbs, - IM_COL32(50, 50, 50, 230)); - ImGui_Timeline_DrawGraph(File, State, Memory, UI, io, draw_list, - Increment, TimelineAbsolutePos, GraphMoveSize, GraphZoomSize, - TimelineSize, TimelineSizeWithBorder, LayerIncrement, - SortedCompArray, SortedLayerArray, - SortedPropertyStart, SortedKeyframeArray); - } - - ImGui_Timeline_HorizontalIncrementDraw(State, UI, draw_list, TimelineSizeWithBorder, TimelineAbsolutePos, *MainComp, TimelineZoomSize, TimelineMoveSize); - - - ImVec2 MouseDelta = io.MouseDelta / TimelineSize; - real32 BarHandleSize = FontHeight; real32 BarThickness = 50; real32 BarMinZoom = 0.01; @@ -949,6 +831,7 @@ ImGui_Timeline(project_data *File, project_state *State, memory *Memory, ui *UI, // I use "UI" to denote the size/position after clipping the bar so that it // doesn't go out of bounds and the handles are always selectable at the edges. + real32 BarH_Offset = Max(BarH_Pos, 0); real32 BarH_SizeUI = (BarH_Size + BarH_Pos > TimelineSizeWithBorder.x) ? @@ -1064,6 +947,129 @@ ImGui_Timeline(project_data *File, project_state *State, memory *Memory, ui *UI, if (BarHeld) { ImGui_WarpMouse(State, io.MousePos, TimelineAbsolutePos, TimelineAbsolutePos + TimelineSizeWithBorder, 2); } +} + +static void +ImGui_Timeline(project_data *File, project_state *State, memory *Memory, ui *UI, ImGuiIO io, + sorted_comp_array *SortedCompArray, sorted_layer_array *SortedLayerArray, sorted_property_array *SortedPropertyStart, uint16 *SortedKeyframeArray) +{ + ImVec2 FramePadding = ImGui::GetStyle().FramePadding; + ImVec2 ItemSpacing = ImGui::GetStyle().ItemSpacing; + ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, ImVec2(0, 0)); + ImGui::PushStyleVar(ImGuiStyleVar_ItemSpacing, ImVec2(0, 0)); // makes setting up the layout easier + ImGui::Begin("Timeline", NULL); + + if (ImGui::IsWindowHovered(ImGuiFocusedFlags_ChildWindows)) { + State->FocusedWindow = focus_timeline; + } + + // if (State->TimelineMode == timeline_mode_graph) + // ImGui_GraphInfo(File, State, Memory, UI, io, SortedPropertyStart, SortedKeyframeArray); + + real32 FontHeight = ImGui::GetFontSize(); + + ImVec2 WindowSize = ImGui::GetWindowSize(); + + if (WindowSize.x < 50 || WindowSize.y < 50) { + ImGui::PopStyleVar(2); + ImGui::End(); + return; + } + + block_composition *MainComp = (block_composition *)Memory_Block_AddressAtIndex(Memory, F_Precomps, File->PrincipalCompIndex); + + ImVec2 WindowMinAbs = ImGui::GetWindowPos(); + ImVec2 WindowMaxAbs = WindowMinAbs + WindowSize; + + ImVec2 ButtonSize = ImVec2(FontHeight*2, FontHeight*2); + + ImVec2 TimelineBorderPadding = ImVec2(FontHeight, FontHeight); + + ImVec2 TimelineSize = ImVec2(WindowSize.x, WindowSize.y); + ImVec2 TimelineSizeWithBorder = TimelineSize - TimelineBorderPadding*2; + ImVec2 TimelineAbsolutePos = WindowMinAbs + TimelineBorderPadding; + + ImVec2 KeyframeSize = ImVec2(FontHeight, FontHeight); + + int32 FrameCount = MainComp->Frame_Count; + + ImDrawList* draw_list = ImGui::GetWindowDrawList(); + draw_list->AddRectFilled(WindowMinAbs, WindowMaxAbs, + IM_COL32(255, 255, 255, 50)); + + + ImGui::BeginChild("Timeline", TimelineSize, true, ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoScrollbar); + + ImGui::PushStyleVar(ImGuiStyleVar_ItemSpacing, ImVec2(0.0f, ItemSpacing.y)); + + ImGui::PushClipRect(TimelineAbsolutePos, TimelineAbsolutePos + TimelineSizeWithBorder, true); + draw_list->PushClipRect(TimelineAbsolutePos, TimelineAbsolutePos + TimelineSizeWithBorder, true); + + real32 LayerIncrement = 40; + + ImVec2 Val_Min(0, 0); + ImVec2 Val_Max(40, LayerIncrement); + + // DebugWatchVar("Selection", &State->RecentSelectionType, d_int); + + // ImVec2 *ActivePercentZoomed = (UI->TimelineMode != timeline_mode_graph) ? &UI->TimelinePercentZoomed : &UI->GraphPercentZoomed; + // ImVec2 *ActivePercentOffset = (UI->TimelineMode != timeline_mode_graph) ? &UI->TimelinePercentOffset : &UI->GraphPercentOffset; + ImVec2 *ActivePercentZoomed = &UI->TimelinePercentZoomed; + ImVec2 *ActivePercentOffset = &UI->TimelinePercentOffset; + + if (ActivePercentZoomed->x == 0) { + *ActivePercentZoomed = ImVec2(1, 1); + } + + ImVec2 ActiveZoomSize = TimelineSizeWithBorder / *ActivePercentZoomed; + ImVec2 ActiveMoveSize = TimelineSizeWithBorder * *ActivePercentOffset / *ActivePercentZoomed; + + ImVec2 TimelineZoomSize = TimelineSizeWithBorder / UI->TimelinePercentZoomed; + ImVec2 TimelineMoveSize = TimelineSizeWithBorder * UI->TimelinePercentOffset / UI->TimelinePercentZoomed; + + // DebugWatchVar("TimelineY: ", &TimelineMoveSize.y, d_float); + + ImVec2 Increment = ImVec2((real32)1 / MainComp->Frame_Count, (real32)1 / LayerIncrement); + + ImGui_Timeline_BGElements(File, State, Memory, UI, draw_list, TimelineSizeWithBorder, TimelineAbsolutePos, *MainComp, TimelineZoomSize, TimelineMoveSize); + + ImVec2 MouseDelta = io.MouseDelta / TimelineSize; + ImGui_Timeline_Bar(File, State, Memory, UI, io, FontHeight, MouseDelta, TimelineSizeWithBorder, ActivePercentOffset, ActivePercentZoomed, TimelineSize, TimelineAbsolutePos); + + int16 RecursionIdx[MAX_PRECOMP_RECURSIONS] = {}; + int32 Recursions = 0; + RecursionIdx[0] = -1; + ImGui_Timeline_DrawPrecomp(File, State, Memory, UI, io, draw_list, RecursionIdx, Recursions, + Increment, TimelineAbsolutePos, TimelineMoveSize, TimelineZoomSize, + TimelineSize, TimelineSizeWithBorder, LayerIncrement, + SortedCompArray, SortedLayerArray, SortedPropertyStart, SortedKeyframeArray); + + if (State->TimelineMode == timeline_mode_graph) { + + if (UI->GraphMoveSize.y == 0) { + UI->GraphZoomSize = ImVec2(1, UI->TimelinePercentZoomed.y ); + UI->GraphMoveSize = ImVec2(0, -UI->TimelinePercentOffset.y ); + } + + ImVec2 ZoomDifference = (UI->TimelinePercentZoomed / UI->GraphZoomSize); + ImVec2 MoveDifference = (UI->TimelinePercentOffset + (UI->GraphMoveSize)); + // DebugWatchVar("zoomdif: ", &ZoomDifference.y, d_float); + // DebugWatchVar("movedif: ", &MoveDifference.y, d_float); + ImVec2 GraphZoomSize = TimelineSizeWithBorder / ZoomDifference; + ImVec2 GraphMoveSize = TimelineSizeWithBorder * (MoveDifference) / UI->TimelinePercentZoomed; + // DebugWatchVar("zoomsize: ", &GraphZoomSize.y, d_float); + // DebugWatchVar("movesize: ", &GraphMoveSize.y, d_float); + + draw_list->AddRectFilled(WindowMinAbs, WindowMaxAbs, + IM_COL32(50, 50, 50, 230)); + ImGui_Timeline_DrawGraph(File, State, Memory, UI, io, draw_list, + Increment, TimelineAbsolutePos, GraphMoveSize, GraphZoomSize, + TimelineSize, TimelineSizeWithBorder, LayerIncrement, + SortedCompArray, SortedLayerArray, + SortedPropertyStart, SortedKeyframeArray); + } + + ImGui_Timeline_HorizontalIncrementDraw(State, UI, draw_list, TimelineSizeWithBorder, TimelineAbsolutePos, *MainComp, TimelineZoomSize, TimelineMoveSize); ImGui::SetCursorScreenPos(TimelineAbsolutePos); ImGui::InvisibleButton("TimelineMoving", TimelineSizeWithBorder, ImGuiButtonFlags_MouseButtonLeft | ImGuiButtonFlags_MouseButtonRight); |