summaryrefslogtreecommitdiff
path: root/my_imgui_widgets.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'my_imgui_widgets.cpp')
-rw-r--r--my_imgui_widgets.cpp313
1 files changed, 244 insertions, 69 deletions
diff --git a/my_imgui_widgets.cpp b/my_imgui_widgets.cpp
index d237b3c..a688283 100644
--- a/my_imgui_widgets.cpp
+++ b/my_imgui_widgets.cpp
@@ -72,6 +72,59 @@ ImGui_KeyframeDragging(project_data *File, project_state *State, ui *UI, propert
}
}
+// NOTE(fox): We have to do a bit of hackery here to tell how many times the
+// mouse has been wrapped during a drag, since it doesn't seem like we can rely
+// on SDL_WarpMouseGlobal to update on the first frame of a WantSetPos request.
+
+static void
+ImGui_WrapMouse(ui *UI, ImVec2 MousePos, ImVec2 Min, ImVec2 Max, int Direction = 3)
+{
+ if (Direction & 1) {
+ if (MousePos.x < Min.x) {
+ UI->WantSetPos = true;
+ UI->SetPos = ImVec2(Max.x - 5, MousePos.y);
+ UI->InitPos = MousePos.x;
+ UI->WrapDirection = 0;
+ }
+ if (MousePos.x > Max.x) {
+ UI->WantSetPos = true;
+ UI->SetPos = ImVec2(Min.x + 5, MousePos.y);
+ UI->InitPos = MousePos.x;
+ UI->WrapDirection = 1;
+ }
+ }
+ if (Direction & 2) {
+ if (MousePos.y < Min.y) {
+ UI->WantSetPos = true;
+ UI->SetPos = ImVec2(MousePos.x, Max.y - 5);
+ UI->InitPos = MousePos.y;
+ UI->WrapDirection = 2;
+ }
+ if (MousePos.y > Max.y) {
+ UI->WantSetPos = true;
+ UI->SetPos = ImVec2(MousePos.x, Min.y + 5);
+ UI->InitPos = MousePos.y;
+ UI->WrapDirection = 3;
+ }
+ }
+}
+
+static void
+ImGui_WrapMouseFinish(ui *UI, ImVec2 MousePos)
+{
+ if (UI->WrapDirection == 0) {
+ if (MousePos.x < UI->InitPos) UI->Wrap_X--;
+ } else if (UI->WrapDirection == 1) {
+ if (MousePos.x > UI->InitPos) UI->Wrap_X++;
+ } else if (UI->WrapDirection == 2) {
+ if (MousePos.y < UI->InitPos) UI->Wrap_Y--;
+ } else if (UI->WrapDirection == 3) {
+ if (MousePos.y > UI->InitPos) UI->Wrap_Y++;
+ } else {
+ Assert(0);
+ }
+}
+
static void
ImGui_InteractSliderProperty(project_state *State, memory *Memory, property_channel *Property)
{
@@ -256,24 +309,6 @@ ImGui_TimelineIncrementDraw(project_data *File, ui *UI, ImDrawList *draw_list,
RightmostEdge = true;
}
}
-
-#if 0
- x = -0.25;
- bool32 LeftmostEdge = false;
- while (!LeftmostEdge) {
- ImVec2 Min = ImVec2(TimelineAbsolutePos.x + TimelineMoveSize + x*TimelineZoomSize, TimelineStartingPos.y);
- ImVec2 Max = ImVec2(Min.x + 2, WindowMaxAbs.y);
- if (Min.x > TimelineAbsolutePos.x) {
- draw_list->AddLine(Min, Max, LineColor);
- char buf2[6];
- sprintf(buf2, "%.2f", x);
- draw_list->AddText(ImVec2(Min.x, TimelineAbsolutePos.y), IM_COL32(200, 200, 200, 130), buf2);
- x -= 0.25;
- } else {
- LeftmostEdge = true;
- }
- }
-#endif
}
static void
@@ -325,37 +360,6 @@ ImGui_TimelineIncrementDraw2(project_data *File, ImDrawList *draw_list, real32 M
LeftmostEdge = true;
}
}
-#if 0
- while (!RightmostEdge) {
- ImVec2 Min = ImVec2(TimelineAbsolutePos.x, TimelineAbsolutePos.y + TimelineZoomSize + TimelineMoveSize - x*TimelineZoomSize);
- ImVec2 Max = ImVec2(TimelineAbsolutePos.x + TimelineSizeWithBorder.x, Min.y + 2);
- if (Min.y > TimelineAbsolutePos.y) {
- draw_list->AddLine(Min, Max, LineColor);
- char buf2[6];
- sprintf(buf2, "%.2f", (x / Increment) + MinVal_Y);
- draw_list->AddText(ImVec2(TimelineAbsolutePos.x, Min.y), IM_COL32(200, 200, 200, 130), buf2);
- x += Increment;
- } else {
- RightmostEdge = true;
- }
- }
-
- x = -Increment;
- bool32 LeftmostEdge = false;
- while (!LeftmostEdge) {
- ImVec2 Min = ImVec2(TimelineAbsolutePos.x, TimelineAbsolutePos.y + TimelineZoomSize + TimelineMoveSize - x*TimelineZoomSize);
- ImVec2 Max = ImVec2(TimelineAbsolutePos.x + TimelineSizeWithBorder.x, Min.y + 2);
- if (Min.y < TimelineAbsolutePos.y + TimelineSizeWithBorder.y) {
- draw_list->AddLine(Min, Max, LineColor);
- char buf2[6];
- sprintf(buf2, "%.2f", (x / Increment) + MinVal_Y);
- draw_list->AddText(ImVec2(TimelineAbsolutePos.x, Min.y), IM_COL32(200, 200, 200, 130), buf2);
- x -= Increment;
- } else {
- LeftmostEdge = true;
- }
- }
-#endif
}
static void
@@ -1175,6 +1179,13 @@ ImGui_Timeline(project_data *File, project_state *State, memory *Memory, ui *UI,
sprintf(buf2, "%.2i:%.2i", File->CurrentFrame / File->FPS, File->CurrentFrame % File->FPS);
ImGui::Text(buf2);
/*
+ if (UI->IsDragging) {
+ ImGui::SameLine();
+ sprintf(buf2, "X: %.3f, Y: %.3f",
+ ImGui::Text(buf2);
+ }
+ */
+ /*
ImGui::Button("V", TopbarButtonSize); ImGui::SameLine();
ImGui::Button("V", TopbarButtonSize); ImGui::SameLine();
ImGui::Button("V", TopbarButtonSize); ImGui::SameLine();
@@ -1259,6 +1270,11 @@ ImGui_Timeline(project_data *File, project_state *State, memory *Memory, ui *UI,
MinVal_Y = (Keyframe->Value.f < MinVal_Y) ? Keyframe->Value.f : MinVal_Y;
}
+ keyframe *FirstKeyframe = KeyframeLookup(Property, 0);
+ keyframe *LastKeyframe = KeyframeLookup(Property, Property->NumberOfTotalKeyframes - 1);
+ real32 MinVal_X = (Layer->BitmapInfo.FrameOffset + FirstKeyframe->FrameNumber);
+ real32 MaxVal_X = (Layer->BitmapInfo.FrameOffset + LastKeyframe->FrameNumber);
+
UI->Y_MaxVal = MaxVal_Y;
UI->Y_MinVal = MinVal_Y;
@@ -1275,39 +1291,72 @@ ImGui_Timeline(project_data *File, project_state *State, memory *Memory, ui *UI,
DebugWatchVar("offset: ", &Y_TimelinePercentOffset, d_float);
DebugWatchVar("zoom: ", &Y_TimelinePercentZoomed, d_float);
+ real32 Ratio_Graph_X = (MaxVal_X - MinVal_X) / File->NumberOfFrames;
+ real32 TimelineZoomSize = TimelineSizeWithBorder.x / UI->TimelinePercentZoomed;
+ real32 TimelineMoveSize = TimelineSizeWithBorder.x * UI->TimelinePercentOffset / UI->TimelinePercentZoomed;
+ real32 Y_TimelineZoomSize = TimelineSizeWithBorder.y / Y_TimelinePercentZoomed;
+ real32 Y_TimelineMoveSize = TimelineSizeWithBorder.y * Y_TimelinePercentOffset / Y_TimelinePercentZoomed;
+
for (int b = 0; b < Property->NumberOfTotalKeyframes; b++) {
ImGui::PushID(b);
- real32 TimelineZoomSize = TimelineSizeWithBorder.x / UI->TimelinePercentZoomed;
- real32 TimelineMoveSize = TimelineSizeWithBorder.x * UI->TimelinePercentOffset / UI->TimelinePercentZoomed;
- real32 Y_TimelineZoomSize = TimelineSizeWithBorder.y / Y_TimelinePercentZoomed;
- real32 Y_TimelineMoveSize = TimelineSizeWithBorder.y * Y_TimelinePercentOffset / Y_TimelinePercentZoomed;
keyframe *Keyframe = KeyframeLookup(Property, b);
// Only used for drawing the bezier.
- keyframe *NextKeyframe = (b != Property->NumberOfTotalKeyframes - 1) ? KeyframeLookup(Property, b) : NULL;
+ keyframe *NextKeyframe = (b != Property->NumberOfTotalKeyframes - 1) ? KeyframeLookup(Property, b + 1) : NULL;
- real32 Ratio_X = (real32)(Layer->BitmapInfo.FrameOffset + Keyframe->FrameNumber) / File->NumberOfFrames;
- real32 Ratio_Y = (Keyframe->Value.f - MinVal_Y) / (MaxVal_Y - MinVal_Y);
+ real32 Increment_X = (real32)1 / File->NumberOfFrames;
+ real32 UI_FrameDistance = Increment_X*TimelineZoomSize;
- ImVec2 KeyframePos = ImVec2(TimelineAbsolutePos.x + TimelineMoveSize + Ratio_X*TimelineZoomSize,
- TimelineAbsolutePos.y + Y_TimelineMoveSize + (1.0f - Ratio_Y)*Y_TimelineZoomSize);
- ImGui::SetCursorScreenPos(KeyframePos);
+ int32 Keyframe_X = (Layer->BitmapInfo.FrameOffset + Keyframe->FrameNumber);
+ real32 Keyframe_Y = Keyframe->Value.f;
+
+ real32 Ratio_X_Mid = (real32)Keyframe_X / File->NumberOfFrames;
+ real32 Ratio_Y_Mid = (Keyframe_Y - MinVal_Y) / (MaxVal_Y - MinVal_Y);
+
+ ImVec2 KeyframePos_Mid = ImVec2(TimelineAbsolutePos.x + TimelineMoveSize + Ratio_X_Mid*TimelineZoomSize,
+ TimelineAbsolutePos.y + Y_TimelineMoveSize + (1.0f - Ratio_Y_Mid)*Y_TimelineZoomSize);
+
+ ImGui::SetCursorScreenPos(KeyframePos_Mid);
ImGui::Button("##keyframe", ImVec2(FontHeight, FontHeight));
+ if (ImGui::IsItemHovered() && ImGui::IsKeyPressed(ImGuiKey_R)) {
+ UI->TempVal = Keyframe->Value.f;
+ UI->TempVal_X = Keyframe->FrameNumber;
+ }
+
if (ImGui::IsItemActivated()) {
UI->IsDragging = true;
UI->TempVal = Keyframe->Value.f;
+ UI->TempVal_X = Keyframe->FrameNumber;
}
if ((ImGui::IsItemActive() && ImGui::IsMouseDragging(ImGuiMouseButton_Left, -1)))
{
- real32 MouseDeltaRatio = -io.MouseDelta.y / TimelineSizeWithBorder.y * Y_TimelinePercentZoomed;
- if (io.KeyShift)
- Ratio_Y = (real32)((int32)(Ratio_Y * 1000) / 10) / 100;
- real32 Test = ((MaxVal_Y - MinVal_Y) * (Ratio_Y + MouseDeltaRatio)) + MinVal_Y;
- DebugWatchVar("RatioY", &Ratio_Y, d_float);
- DebugWatchVar("NewRatioY", &UI->Y_MaxVal, d_float);
- Keyframe->Value.f = Test;
+ ImVec2 DragDelta = ImGui::GetMouseDragDelta();
+ DragDelta = DragDelta + (ImVec2(UI->Wrap_X, UI->Wrap_Y) * TimelineSize);
+ DebugWatchVar("DragX", &DragDelta.x, d_float);
+ DebugWatchVar("DragY", &DragDelta.y, d_float);
+ DebugWatchVar("Wrap_X", &UI->Wrap_X, d_int);
+ DebugWatchVar("Wrap_Y", &UI->Wrap_Y, d_int);
+ real32 MouseDeltaRatio = -DragDelta.y / TimelineSizeWithBorder.y * Y_TimelinePercentZoomed;
+ ImVec2 Increment = ImVec2(DragDelta.x / UI_FrameDistance, ((MaxVal_Y - MinVal_Y) * MouseDeltaRatio));
+
+ // The plus 0.5 * X_Direction is for making the frame jump happen
+ // when the cursor is between two frames rather than when passing one.
+ real32 X_Direction = (Increment.x > 0) ? fabsf(Increment.x) / Increment.x : 0;
+
+ Keyframe->FrameNumber = UI->TempVal_X + (int32)(Increment.x + 0.5*X_Direction);
+ Keyframe->Value.f = UI->TempVal + Increment.y;
+
+ if (io.KeyShift) {
+ bool32 RestrainAxis = (fabsf(DragDelta.x) > fabsf(DragDelta.y));
+ if (RestrainAxis) {
+ Keyframe->Value.f = UI->TempVal;
+ } else {
+ Keyframe->FrameNumber = UI->TempVal_X;
+ }
+ }
+ ImGui_WrapMouse(UI, io.MousePos, TimelineAbsolutePos, TimelineAbsolutePos + TimelineSizeWithBorder);
}
// TODO(fox): This is kind of a mess. I built the graph around the
@@ -1317,7 +1366,7 @@ ImGui_Timeline(project_data *File, project_state *State, memory *Memory, ui *UI,
if (ImGui::IsItemDeactivated()) {
if ((UI->TempVal >= MaxVal_Y) || Keyframe->Value.f == UI->Y_MaxVal) {
- real32 Min = ((Ratio_Y <= 0.0f) && (UI->TempVal >= MaxVal_Y)) ? MinVal_Y : UI->Y_MinVal;
+ real32 Min = ((Ratio_Y_Mid <= 0.0f) && (UI->TempVal >= MaxVal_Y)) ? MinVal_Y : UI->Y_MinVal;
real32 RealRatio_Y = (UI->Y_MaxVal - UI->Y_MinVal) / (MaxVal_Y - MinVal_Y);
UI->Y_TimelinePercentZoomed = UI->Y_TimelinePercentZoomed / RealRatio_Y;
UI->Y_TimelinePercentOffset = (1.0f/RealRatio_Y + UI->Y_TimelinePercentOffset/RealRatio_Y - 1.0f);
@@ -1327,6 +1376,67 @@ ImGui_Timeline(project_data *File, project_state *State, memory *Memory, ui *UI,
UI->Y_TimelinePercentZoomed = UI->Y_TimelinePercentZoomed / (1 - RealRatio_Y);
}
UI->IsDragging = false;
+ UI->Wrap_X = 0;
+ UI->Wrap_Y = 0;
+ }
+
+ ImU32 col = ImGui::GetColorU32(ImGuiCol_ScrollbarGrab);
+
+ ImVec2 Handle_Pos[2] = {};
+
+ if (Keyframe->Type == bezier) {
+ ImVec2 Handle_Ratio[2] = {};
+
+ Handle_Ratio[0] = ImVec2((real32)(Keyframe_X + Keyframe->TangentLeft.x) / File->NumberOfFrames,
+ (Keyframe_Y + Keyframe->TangentLeft.y - MinVal_Y) / (MaxVal_Y - MinVal_Y));
+ Handle_Ratio[1] = ImVec2((real32)(Keyframe_X + Keyframe->TangentRight.x) / File->NumberOfFrames,
+ (Keyframe_Y + Keyframe->TangentRight.y - MinVal_Y) / (MaxVal_Y - MinVal_Y));
+
+ Handle_Pos[0] = ImVec2(TimelineAbsolutePos.x + TimelineMoveSize + Handle_Ratio[0].x*TimelineZoomSize,
+ TimelineAbsolutePos.y + Y_TimelineMoveSize + (1.0f - Handle_Ratio[0].y)*Y_TimelineZoomSize);
+ Handle_Pos[1] = ImVec2(TimelineAbsolutePos.x + TimelineMoveSize + Handle_Ratio[1].x*TimelineZoomSize,
+ TimelineAbsolutePos.y + Y_TimelineMoveSize + (1.0f - Handle_Ratio[1].y)*Y_TimelineZoomSize);
+
+ draw_list->AddLine(KeyframePos_Mid, Handle_Pos[0], col, 1.0f);
+ draw_list->AddLine(KeyframePos_Mid, Handle_Pos[1], col, 1.0f);
+
+ for (int i = 0; i < 2; i++) {
+ ImGui::SetCursorScreenPos(Handle_Pos[i]);
+ ImGui::Button((i == 0) ? "##keyframe_left" : "##keyframe_right", ImVec2(FontHeight, FontHeight));
+ v2 *Tangent = (i == 0) ? &Keyframe->TangentLeft : &Keyframe->TangentRight;
+
+ if (ImGui::IsItemActivated()) {
+ UI->IsDragging = true;
+ UI->TempVal_X = Tangent->x;
+ UI->TempVal = Tangent->y;
+ }
+
+ if ((ImGui::IsItemActive() && ImGui::IsMouseDragging(ImGuiMouseButton_Left, -1)))
+ {
+ ImVec2 DragDelta = ImGui::GetMouseDragDelta();
+ DragDelta = DragDelta + (ImVec2(UI->Wrap_X, UI->Wrap_Y) * TimelineSize);
+ ImVec2 MouseDeltaRatio = (ImVec2(1, -1) * DragDelta) / TimelineSizeWithBorder * ImVec2(UI->TimelinePercentZoomed / Ratio_Graph_X, Y_TimelinePercentZoomed);
+ real32 NewPos_X = ((MaxVal_X - MinVal_X) * MouseDeltaRatio.x);
+ real32 NewPos_Y = (io.KeyShift) ? 0 : ((MaxVal_Y - MinVal_Y) * MouseDeltaRatio.y);
+ *Tangent = V2(UI->TempVal_X, UI->TempVal) + V2(NewPos_X, NewPos_Y);
+ ImGui_WrapMouse(UI, io.MousePos, TimelineAbsolutePos, TimelineAbsolutePos + TimelineSizeWithBorder);
+ }
+
+ if (ImGui::IsItemDeactivated()) {
+ UI->IsDragging = false;
+ UI->Wrap_X = 0;
+ UI->Wrap_Y = 0;
+ }
+ }
+ }
+
+ if (NextKeyframe) {
+ real32 Ratio_X_2 = (real32)(Layer->BitmapInfo.FrameOffset + NextKeyframe->FrameNumber) / File->NumberOfFrames;
+ real32 Ratio_Y_2 = (NextKeyframe->Value.f - MinVal_Y) / (MaxVal_Y - MinVal_Y);
+
+ ImVec2 NextKeyframePos = ImVec2(TimelineAbsolutePos.x + TimelineMoveSize + Ratio_X_2*TimelineZoomSize,
+ TimelineAbsolutePos.y + Y_TimelineMoveSize + (1.0f - Ratio_Y_2)*Y_TimelineZoomSize);
+ draw_list->AddLine(KeyframePos_Mid, NextKeyframePos, col, 1.0f);
}
ImGui::PopID();
@@ -1371,6 +1481,7 @@ ImGui_Timeline(project_data *File, project_state *State, memory *Memory, ui *UI,
BarH_Offset = Min(BarH_Offset, TimelineSize.x - BarH_SizeUI - BarHandleSize*4);
ImVec2 BarH_PosUI = TimelineAbsolutePos + ImVec2(BarH_Offset, TimelineSize.y - BarThickness);
+ bool32 BarHeld = false;
ImGui::SetCursorScreenPos(BarH_PosUI);
ImGui::Button("##scrollbarleft", ImVec2(BarHandleSize, BarThickness));
@@ -1381,6 +1492,7 @@ ImGui_Timeline(project_data *File, project_state *State, memory *Memory, ui *UI,
UI->TimelinePercentZoomed -= MouseDelta.x;
UI->TimelinePercentOffset -= MouseDelta.x;
}
+ BarHeld = true;
}
ImGui::SetCursorScreenPos(BarH_PosUI + ImVec2(BarHandleSize, 0));
@@ -1389,6 +1501,7 @@ ImGui_Timeline(project_data *File, project_state *State, memory *Memory, ui *UI,
if (ImGui::IsItemActive() && ImGui::IsMouseDragging(ImGuiMouseButton_Left, -1))
{
UI->TimelinePercentOffset -= MouseDelta.x;
+ BarHeld = true;
}
ImGui::SetCursorScreenPos(BarH_PosUI + ImVec2(BarHandleSize, 0) + ImVec2(BarH_SizeUI, 0));
@@ -1399,6 +1512,11 @@ ImGui_Timeline(project_data *File, project_state *State, memory *Memory, ui *UI,
if ((UI->TimelinePercentZoomed + MouseDelta.x) > BarMinZoom) {
UI->TimelinePercentZoomed += MouseDelta.x;
}
+ BarHeld = true;
+ }
+
+ if (BarHeld) {
+ ImGui_WrapMouse(UI, io.MousePos, TimelineAbsolutePos, TimelineAbsolutePos + TimelineSizeWithBorder, 1);
}
Assert(UI->TimelinePercentZoomed > BarMinZoom);
@@ -1423,6 +1541,7 @@ ImGui_Timeline(project_data *File, project_state *State, memory *Memory, ui *UI,
BarV_Offset = Min(BarV_Offset, BarV_MaxSize - BarV_SizeUI - BarHandleSize*4);
ImVec2 BarV_PosUI = TimelineAbsolutePos + ImVec2(TimelineSize.x - BarThickness, BarV_Offset);
+ BarHeld = false;
ImGui::SetCursorScreenPos(BarV_PosUI);
ImGui::Button("##h-scrollbarleft", ImVec2(BarThickness, BarHandleSize));
@@ -1431,14 +1550,21 @@ ImGui_Timeline(project_data *File, project_state *State, memory *Memory, ui *UI,
{
UI->Y_TimelinePercentZoomed -= MouseDelta.y;
UI->Y_TimelinePercentOffset -= MouseDelta.y;
+ BarHeld = true;
}
ImGui::SetCursorScreenPos(BarV_PosUI + ImVec2(0, BarHandleSize));
- ImGui::Button("##h-scrollbarhori", ImVec2(BarThickness, BarV_SizeUI));
+ ImGui::Button("##h-scrollbar", ImVec2(BarThickness, BarV_SizeUI));
+
+ if (ImGui::IsItemHovered() && io.MouseWheel)
+ {
+ UI->Y_TimelinePercentOffset -= io.MouseWheel/10;
+ }
if (ImGui::IsItemActive() && ImGui::IsMouseDragging(ImGuiMouseButton_Left, -1))
{
UI->Y_TimelinePercentOffset -= MouseDelta.y;
+ BarHeld = true;
}
ImGui::SetCursorScreenPos(BarV_PosUI + ImVec2(0, BarHandleSize) + ImVec2(0, BarV_SizeUI));
@@ -1447,15 +1573,58 @@ ImGui_Timeline(project_data *File, project_state *State, memory *Memory, ui *UI,
if ((ImGui::IsItemActive() && ImGui::IsMouseDragging(ImGuiMouseButton_Left, -1)))
{
UI->Y_TimelinePercentZoomed += MouseDelta.y;
+ BarHeld = true;
}
UI->Y_TimelinePercentZoomed = Max(UI->Y_TimelinePercentZoomed, 0.01);
+ if (BarHeld) {
+ ImGui_WrapMouse(UI, io.MousePos, TimelineAbsolutePos, TimelineAbsolutePos + TimelineSizeWithBorder, 2);
+ }
+
draw_list->PopClipRect();
ImGui::PopClipRect();
ImGui::PopStyleVar();
+ if (io.MouseWheel) {
+ // NOTE(fox): Change this if any other action is added when hovering over the bar area.
+ bool32 BarHovering_H = TestRectangle(TimelineAbsolutePos + ImVec2(0, TimelineSize.y - BarThickness),
+ TimelineAbsolutePos + ImVec2(TimelineSize.x, TimelineSize.y),
+ io.MousePos);
+ bool32 BarHovering_V = TestRectangle(TimelineAbsolutePos + ImVec2(TimelineSize.x - BarThickness, 0),
+ TimelineAbsolutePos + ImVec2(TimelineSize.x, TimelineSize.y),
+ io.MousePos);
+ if (BarHovering_H && io.MouseWheel) {
+ UI->TimelinePercentOffset -= io.MouseWheel/15;
+ } else if (BarHovering_V && io.MouseWheel) {
+ UI->Y_TimelinePercentOffset -= io.MouseWheel/15;
+ } else {
+ real32 Increment = 0.1;
+ bool32 Direction = (io.MouseWheel > 0) ? 1 : -1;
+ real32 Offset = (io.MousePos.y - (TimelineAbsolutePos.y + Y_TimelineMoveSize)) / Y_TimelineZoomSize;
+ real32 X_Offset = (io.MousePos.x - (TimelineAbsolutePos.x + TimelineMoveSize)) / TimelineZoomSize;
+ DebugWatchVar("X Offset", &X_Offset, d_float);
+ if (io.KeyShift) {
+ UI->Y_TimelinePercentOffset += Increment*Direction;
+ } else if (io.KeyCtrl) {
+ UI->TimelinePercentOffset += Increment*Direction*0.3;
+ } else {
+ if (Direction == 1) {
+ UI->Y_TimelinePercentZoomed -= (UI->Y_TimelinePercentZoomed * Increment);
+ UI->Y_TimelinePercentOffset -= (UI->Y_TimelinePercentOffset * Increment) + Offset*Increment;
+ UI->TimelinePercentZoomed -= (UI->TimelinePercentZoomed * Increment);
+ UI->TimelinePercentOffset -= (UI->TimelinePercentOffset * Increment) + X_Offset*Increment;
+ } else {
+ UI->Y_TimelinePercentOffset = ((UI->Y_TimelinePercentOffset + Offset*Increment) / (1.0f - Increment));
+ UI->Y_TimelinePercentZoomed = (UI->Y_TimelinePercentZoomed / (1.0f - Increment));
+ UI->TimelinePercentOffset = ((UI->TimelinePercentOffset + X_Offset*Increment) / (1.0f - Increment));
+ UI->TimelinePercentZoomed = (UI->TimelinePercentZoomed / (1.0f - Increment));
+ }
+ }
+ }
+ }
+
// General timeline interaction
ImGui::SetCursorScreenPos(TimelineAbsolutePos);
@@ -1550,14 +1719,20 @@ ImGui_ProcessInputs(project_data *File, project_state *State, comp_buffer *CompB
// ImGui::SaveIniSettingsToDisk("asda");
#endif
if (ImGui::IsKeyPressed(ImGuiKey_R)) {
+ /*
UI->Y_TimelinePercentZoomed = UI->Default_Y_TimelinePercentZoomed;
UI->Y_TimelinePercentOffset = UI->Default_Y_TimelinePercentOffset;
keyframe *Keyframe = KeyframeLookup(&File->Layer[0]->x, 0);
Keyframe->Value.f = -10;
Keyframe = KeyframeLookup(&File->Layer[0]->x, 1);
- Keyframe->Value.f = 0;
+ Keyframe->Value.f = -5;
Keyframe = KeyframeLookup(&File->Layer[0]->x, 2);
+ Keyframe->Value.f = 0;
+ Keyframe = KeyframeLookup(&File->Layer[0]->x, 3);
+ Keyframe->Value.f = 5;
+ Keyframe = KeyframeLookup(&File->Layer[0]->x, 4);
Keyframe->Value.f = 10;
+ */
}
if (ImGui::IsKeyPressed(ImGuiKey_D)) {