From c27530c79fd135c499a52b222e9cec16aa1951ad Mon Sep 17 00:00:00 2001 From: Fox Caminiti Date: Fri, 11 Nov 2022 21:55:34 -0500 Subject: graph improvements --- my_imgui_widgets.cpp | 110 +++++++++++++++++++++------------------------------ 1 file changed, 44 insertions(+), 66 deletions(-) (limited to 'my_imgui_widgets.cpp') diff --git a/my_imgui_widgets.cpp b/my_imgui_widgets.cpp index 722ce1e..04cedb0 100644 --- a/my_imgui_widgets.cpp +++ b/my_imgui_widgets.cpp @@ -988,14 +988,14 @@ ImGui_GraphInfo(project_data *File, project_state *State, memory *Memory, ui *UI } static void -ImGui_Timeline_DrawGraph(project_data *File, project_state *State, memory *Memory, ui *UI, ImGuiIO io, ImDrawList *draw_list, graph_info GraphInfo, +ImGui_Timeline_DrawGraph(project_data *File, project_state *State, memory *Memory, ui *UI, ImGuiIO io, ImDrawList *draw_list, ImVec2 Increment, ImVec2 TimelineAbsolutePos, ImVec2 TimelineMoveSize, ImVec2 TimelineZoomSize, - ImVec2 TimelineSize, ImVec2 TimelineSizeWithBorder, real32 LayerIncrement) + ImVec2 TimelineSize, ImVec2 TimelineSizeWithBorder, real32 LayerIncrement, uint16 *SortedPropertyArray) { UI->Test.Split(draw_list, 2); - TimelineMoveSize.y = TimelineMoveSize.y + (TimelineZoomSize.y * (0.25 / 2)); - TimelineZoomSize.y = TimelineZoomSize.y * 0.75; + TimelineMoveSize.y = TimelineMoveSize.y + (TimelineZoomSize.y * (0.25 / 4)); + TimelineZoomSize.y = TimelineZoomSize.y * 0.6; int h = 0, c = 0, i = 0; while (Block_Loop(Memory, F_Layers, File->Layer_Count, &h, &c, &i)) @@ -1014,9 +1014,11 @@ ImGui_Timeline_DrawGraph(project_data *File, project_state *State, memory *Memor if (State->Interact_Active == interact_type_keyframe_move) { ImVec2 DragDelta = io.MousePos - ImVec2(State->Interact_Offset[2], State->Interact_Offset[3]); - // State->Interact_Offset[0] = (DragDelta.x / TimelineSizeWithBorder.x * UI->TimelinePercentZoomed.x) / Increment.x; - // State->Interact_Offset[1] = -1 * (DragDelta.y / TimelineSizeWithBorder.y * UI->TimelinePercentZoomed.y) * ((GraphInfo.MaxVal - GraphInfo.MinVal)); - State->Interact_Offset[0] = DragDelta.x; + // NOTE(fox): I'm setting the X (time) to the transformed value and + // the Y (value) to the raw drag delta, because the Y units can be + // normalized while the X units are always universal across all the + // graphs (and it has to be passed into the sorter). + State->Interact_Offset[0] = (DragDelta.x / TimelineZoomSize.x) / Increment.x; State->Interact_Offset[1] = DragDelta.y; DebugWatchVar("DeltaX: ", &DragDelta.x, d_float); DebugWatchVar("Deltay: ", &DragDelta.y, d_float); @@ -1036,50 +1038,30 @@ ImGui_Timeline_DrawGraph(project_data *File, project_state *State, memory *Memor for (int h = 0; h < AmountOf(Layer->Property); h++) { property_channel *Property = &Layer->Property[h]; + uint16 *ArrayLocation = SortedPropertyArray + (i * 7 * MAX_KEYFRAMES_PER_BLOCK) + (h * MAX_KEYFRAMES_PER_BLOCK); ImGui::PushID(Property); if (Property->Block_Bezier_Count) { - property_info PropertyInfo = Property_GetInfo(Memory, Property); - real32 Y_Increment = 1 / (GraphInfo.MaxVal - GraphInfo.MinVal); + v2 Min, Max; + Property_MinMax(Memory, State, Property, ArrayLocation, &Min, &Max); + real32 Y_Increment = 1 / (Max.y - Min.y); bezier_point *PointAddress[2] = {}; ImVec2 Keyframe_ScreenPos[6] = {}; - int k = 0; - for (;;) { - int Idx = (k % 2); + for (int p = 0; p < Property->Keyframe_Count; p++) { + int k = ArrayLocation[p]; + int Idx = (p % 2); int NewIdx = Idx * 3; int OldIdx = (NewIdx == 3) ? 0 : 3; - PointAddress[Idx] = Bezier_Lookup(Memory, Property, k); - bezier_point *Point = PointAddress[Idx]; - - if (!Point->Occupied) - break; - - v2 Keyframe_LocalPos_[3] = { Point->Pos[0], Point->Pos[1], Point->Pos[2] }; - - if (Point->IsSelected) { - /* - if (State->Interact_Active == interact_type_keyframe_rotate) { - ImVec2 Keyframe_LocalPos_Ratio = (V2(Keyframe_LocalPos_[0]) - ImVec2(0, GraphInfo.MinVal)) * ImVec2(Increment.x, Y_Increment); - ImVec2 Keyframe_ScreenPos = Layer_ScreenPos_Min + ((ImVec2(1, -1) * Keyframe_LocalPos_Ratio + ImVec2(0, 0.5)) * TimelineZoomSize) + ImVec2(0, Layer_ScreenSize.y/2); - real32 Slope_Old = (Keyframe_ScreenPos.y - State->Interact_Offset[3]) / (Keyframe_ScreenPos.x - State->Interact_Offset[2]); - real32 Slope_New = (Keyframe_ScreenPos.y - io.MousePos.y) / (Keyframe_ScreenPos.x - io.MousePos.x); - State->Interact_Offset[0] = atan((Slope_Old - Slope_New) / (1 + Slope_Old * Slope_New)); - DebugWatchVar("Rotation: ", &State->Interact_Offset[0], d_float); - } - */ - v2 Offset = V2(State->Interact_Offset[0], State->Interact_Offset[1]); - if (State->Interact_Active == interact_type_keyframe_move) { - Keyframe_LocalPos_[0].x += (Offset.x / TimelineZoomSize.x) / Increment.x; - Keyframe_LocalPos_[0].y -= ((Offset.y / TimelineZoomSize.y)) * (GraphInfo.MaxVal - GraphInfo.MinVal); - } - // Keyframe_Interact_Evaluate(Memory, State, Point->IsSelected, Point->Pos, Keyframe_LocalPos_); - } - ImVec2 Keyframe_LocalPos[3] = { V2(Keyframe_LocalPos_[0]), V2(Keyframe_LocalPos_[0] + Keyframe_LocalPos_[1]), V2(Keyframe_LocalPos_[0] + Keyframe_LocalPos_[2]) }; + PointAddress[Idx] = Bezier_LookupAddress(Memory, Property, k); + + v2 PointPos[3]; + Bezier_EvaluateValue(State, PointAddress[Idx], PointPos); + + ImVec2 Keyframe_LocalPos[3] = { V2(PointPos[0]), V2(PointPos[0] + PointPos[1]), V2(PointPos[0] + PointPos[2]) }; ImVec2 Keyframe_LocalPos_Ratio[3]; for (int b = 0; b < 3; b++) { - Keyframe_LocalPos_Ratio[b] = (Keyframe_LocalPos[b] - ImVec2(0, GraphInfo.MinVal)) * ImVec2(Increment.x, Y_Increment); - // Keyframe_ScreenPos[NewIdx + b] = Layer_ScreenPos_Min + ((ImVec2(1, -1) * Keyframe_LocalPos_Ratio[b] + ImVec2(0, 0.5)) * TimelineZoomSize) + ImVec2(0, Layer_ScreenSize.y/2); - Keyframe_ScreenPos[NewIdx + b] = TimelineAbsolutePos + TimelineMoveSize + ((ImVec2(1, -1) * Keyframe_LocalPos_Ratio[b] + ImVec2(0, 1)) * TimelineZoomSize); + Keyframe_LocalPos_Ratio[b] = (Keyframe_LocalPos[b] - ImVec2(0, Min.y)) * ImVec2(Increment.x, Y_Increment); + Keyframe_ScreenPos[NewIdx + b] = TimelineAbsolutePos + TimelineMoveSize + ((ImVec2(1, 1) * Keyframe_LocalPos_Ratio[b]) * TimelineZoomSize); } if (UI->BoxSelect) { @@ -1091,11 +1073,11 @@ ImGui_Timeline_DrawGraph(project_data *File, project_state *State, memory *Memor if (Keyframe_ScreenPos[NewIdx].y >= Y_Top && Keyframe_ScreenPos[NewIdx].y <= Y_Bottom && Keyframe_ScreenPos[NewIdx].x >= X_Left && Keyframe_ScreenPos[NewIdx].x <= X_Right) { - if (!Point->IsSelected) { - Point->IsSelected = 1; + if (!PointAddress[Idx]->IsSelected) { + PointAddress[Idx]->IsSelected = 1; } } else if (!io.KeyShift) { - Point->IsSelected = 0; + PointAddress[Idx]->IsSelected = 0; } } @@ -1104,10 +1086,10 @@ ImGui_Timeline_DrawGraph(project_data *File, project_state *State, memory *Memor ImVec2 ButtonSize(16, 16); ImGui::PushID(k); - int Max = (Point->IsSelected) ? 2 : 0; + int Max = PointAddress[Idx]->IsSelected ? 2 : 0; for (int b = Max; b >= 0; b--) { - ImU32 PointCol = ((Point->IsSelected - 1) == b) ? ImColor(0.8f, 0.5f, 0.0f, 1.0f) : ImColor(0.1f, 0.1f, 0.1f, 1.0f); - ImU32 LineCol = ((Point->IsSelected - 1) == b) ? ImColor(0.8f, 0.5f, 0.5f, 1.0f) : ImColor(0.4f, 0.4f, 0.4f, 1.0f); + ImU32 PointCol = ((PointAddress[Idx]->IsSelected - 1) == b) ? ImColor(0.8f, 0.5f, 0.0f, 1.0f) : ImColor(0.1f, 0.1f, 0.1f, 1.0f); + ImU32 LineCol = ((PointAddress[Idx]->IsSelected - 1) == b) ? ImColor(0.8f, 0.5f, 0.5f, 1.0f) : ImColor(0.4f, 0.4f, 0.4f, 1.0f); ImGui::PushID(b); ImGui::SetCursorScreenPos(Keyframe_ScreenPos[NewIdx + b] - (ButtonSize * 0.5)); ImGui::InvisibleButton("##keyframemover", ButtonSize, ImGuiMouseButton_Left); @@ -1122,10 +1104,10 @@ ImGui_Timeline_DrawGraph(project_data *File, project_state *State, memory *Memor PointCol = ImColor(1.0f, 0.8f, 0.8f, 1.0f); if (IsItemActivated) { - Point->IsSelected = b+1; + PointAddress[Idx]->IsSelected = b+1; } - if (b != 0 && Point->IsSelected) + if (b != 0 && PointAddress[Idx]->IsSelected) draw_list->AddLine(Keyframe_ScreenPos[NewIdx], Keyframe_ScreenPos[NewIdx + b], LineCol, 2.0f); if (b == 0) @@ -1139,7 +1121,7 @@ ImGui_Timeline_DrawGraph(project_data *File, project_state *State, memory *Memor UI->Test.SetCurrentChannel(draw_list, 0); - if (k != 0) { + if (p != 0) { if (PointAddress[0]->Type == interpolation_type_bezier && PointAddress[1]->Type == interpolation_type_bezier) { draw_list->AddBezierCubic(Keyframe_ScreenPos[OldIdx], Keyframe_ScreenPos[OldIdx + 2], Keyframe_ScreenPos[NewIdx + 1], Keyframe_ScreenPos[NewIdx], col, 1.0f, 0); @@ -1147,7 +1129,6 @@ ImGui_Timeline_DrawGraph(project_data *File, project_state *State, memory *Memor draw_list->AddLine(Keyframe_ScreenPos[0], Keyframe_ScreenPos[3], col, 1.0f); } } - k++; } } ImGui::PopID(); @@ -1500,7 +1481,7 @@ 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_info *SortedCompArray, sorted_layer *SortedLayerArray) +ImGui_Timeline(project_data *File, project_state *State, memory *Memory, ui *UI, ImGuiIO io, sorted_comp_info *SortedCompArray, sorted_layer *SortedLayerArray, uint16 *SortedPropertyArray) { if (UI->TimelineMode == timeline_mode_graph) ImGui_GraphInfo(File, State, Memory, UI, io); @@ -1602,10 +1583,9 @@ ImGui_Timeline(project_data *File, project_state *State, memory *Memory, ui *UI, draw_list->AddRectFilled(WindowMinAbs, WindowMaxAbs, IM_COL32(50, 50, 50, 150)); - graph_info GraphInfo = Graph_GetInfo(File, Memory); - ImGui_Timeline_DrawGraph(File, State, Memory, UI, io, draw_list, GraphInfo, + ImGui_Timeline_DrawGraph(File, State, Memory, UI, io, draw_list, Increment, TimelineAbsolutePos, GraphMoveSize, GraphZoomSize, - TimelineSize, TimelineSizeWithBorder, LayerIncrement); + TimelineSize, TimelineSizeWithBorder, LayerIncrement, SortedPropertyArray); } ImVec2 MouseDelta = io.MouseDelta / TimelineSize; @@ -1777,17 +1757,15 @@ ImGui_Timeline(project_data *File, project_state *State, memory *Memory, ui *UI, if (!Layer->IsSelected) continue; for (int h = 0; h < AmountOf(Layer->Property); h++) { + uint16 *ArrayLocation = SortedPropertyArray + (i * 7 * MAX_KEYFRAMES_PER_BLOCK) + (h * MAX_KEYFRAMES_PER_BLOCK); property_channel *Property = &Layer->Property[h]; - if (Property->Block_Bezier_Count) { - int k = 0; - for (;;) { - bezier_point *Point = Bezier_Lookup(Memory, Property, k); - if (!Point->Occupied) - break; - if (Point->IsSelected) { - Keyframe_Interact_Evaluate(Memory, State, Point->IsSelected, Point->Pos, Point->Pos); - } - k++; + for (int p = 0; p < Property->Keyframe_Count; p++) { + int k = ArrayLocation[p]; + bezier_point *PointAddress = Bezier_LookupAddress(Memory, Property, k); + if (PointAddress->IsSelected) { + v2 NewPos[3]; + Bezier_EvaluateValue(State, PointAddress, NewPos); + PointAddress->Pos[0].x = NewPos[0].x; } } } -- cgit v1.2.3