2020-01-02 02:41:43 +00:00
|
|
|
//
|
|
|
|
// File: foldhaus_panel_animation_timeline.h
|
|
|
|
// Author: Peter Slattery
|
|
|
|
// Creation Date: 2020-01-01
|
|
|
|
//
|
|
|
|
#ifndef FOLDHAUS_PANEL_ANIMATION_TIMELINE_H
|
|
|
|
|
2020-03-01 01:11:15 +00:00
|
|
|
inline u32
|
|
|
|
GetFrameFromPointInAnimationPanel(v2 Point, rect PanelBounds, u32 StartFrame, u32 EndFrame)
|
2019-12-28 19:31:21 +00:00
|
|
|
{
|
2020-03-01 01:11:15 +00:00
|
|
|
r32 HorizontalPercentOfBounds = (Point.x - PanelBounds.Min.x) / (PanelBounds.Max.x - PanelBounds.Min.x);
|
|
|
|
u32 TimeAtPoint = (u32)(HorizontalPercentOfBounds * (EndFrame - StartFrame)) + StartFrame;
|
2019-12-28 19:31:21 +00:00
|
|
|
return TimeAtPoint;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline s32
|
2020-03-01 01:11:15 +00:00
|
|
|
GetXPositionFromFrameInAnimationPanel (u32 Frame, rect PanelBounds, s32 StartFrame, s32 EndFrame)
|
2019-12-28 19:31:21 +00:00
|
|
|
{
|
2020-03-01 01:11:15 +00:00
|
|
|
r32 PercentOfTimeline = (r32)(Frame - StartFrame) / (r32)(EndFrame - StartFrame);
|
|
|
|
s32 XPositionAtFrame = (PercentOfTimeline * Width(PanelBounds)) + PanelBounds.Min.x;
|
|
|
|
return XPositionAtFrame;
|
2019-12-28 19:31:21 +00:00
|
|
|
}
|
|
|
|
|
2020-03-01 01:11:15 +00:00
|
|
|
internal gs_list_handle
|
|
|
|
AddAnimationBlock(u32 StartFrame, u32 EndFrame, u32 AnimationProcHandle, animation_system* AnimationSystem)
|
2019-12-29 00:01:34 +00:00
|
|
|
{
|
2020-03-01 01:11:15 +00:00
|
|
|
gs_list_handle Result = {0};
|
2019-12-29 00:01:34 +00:00
|
|
|
animation_block NewBlock = {0};
|
2020-03-01 01:11:15 +00:00
|
|
|
NewBlock.StartFrame = StartFrame;
|
|
|
|
NewBlock.EndFrame = EndFrame;
|
2020-02-05 06:50:12 +00:00
|
|
|
NewBlock.AnimationProcHandle = AnimationProcHandle;
|
2020-03-01 01:11:15 +00:00
|
|
|
Result = AnimationSystem->Blocks.PushElementOnList(NewBlock);
|
|
|
|
return Result;
|
2019-12-29 00:01:34 +00:00
|
|
|
}
|
|
|
|
|
2020-03-01 01:11:15 +00:00
|
|
|
internal gs_list_handle
|
2020-02-05 06:50:12 +00:00
|
|
|
AddAnimationBlockAtCurrentTime (u32 AnimationProcHandle, animation_system* System)
|
2019-12-29 00:01:34 +00:00
|
|
|
{
|
2020-03-01 01:11:15 +00:00
|
|
|
u32 NewBlockStart = System->CurrentFrame;
|
|
|
|
u32 NewBlockEnd = NewBlockStart + SecondsToFrames(3, *System);
|
|
|
|
gs_list_handle Result = AddAnimationBlock(NewBlockStart, NewBlockEnd, AnimationProcHandle, System);
|
|
|
|
return Result;
|
2019-12-29 00:01:34 +00:00
|
|
|
}
|
|
|
|
|
2019-12-28 18:51:47 +00:00
|
|
|
internal void
|
2019-12-31 04:26:28 +00:00
|
|
|
DeleteAnimationBlock(gs_list_handle AnimationBlockHandle, app_state* State)
|
2019-12-28 18:51:47 +00:00
|
|
|
{
|
2019-12-31 04:26:28 +00:00
|
|
|
State->AnimationSystem.Blocks.FreeElementWithHandle(AnimationBlockHandle);
|
2019-12-28 18:51:47 +00:00
|
|
|
State->SelectedAnimationBlockHandle = {0};
|
|
|
|
}
|
|
|
|
|
|
|
|
internal void
|
2019-12-31 04:26:28 +00:00
|
|
|
SelectAnimationBlock(gs_list_handle BlockHandle, app_state* State)
|
2019-12-28 18:51:47 +00:00
|
|
|
{
|
|
|
|
State->SelectedAnimationBlockHandle = BlockHandle;
|
|
|
|
}
|
|
|
|
|
|
|
|
internal void
|
|
|
|
DeselectCurrentAnimationBlock(app_state* State)
|
|
|
|
{
|
|
|
|
State->SelectedAnimationBlockHandle = {};
|
|
|
|
}
|
|
|
|
|
|
|
|
FOLDHAUS_INPUT_COMMAND_PROC(DeleteAnimationBlockCommand)
|
|
|
|
{
|
2020-03-01 01:11:15 +00:00
|
|
|
if(ListHandleIsValid(State->SelectedAnimationBlockHandle))
|
|
|
|
{
|
|
|
|
DeleteAnimationBlock(State->SelectedAnimationBlockHandle, State);
|
|
|
|
}
|
2019-12-28 18:51:47 +00:00
|
|
|
}
|
|
|
|
|
2019-12-28 22:14:00 +00:00
|
|
|
//
|
|
|
|
// Drag Time Marker
|
|
|
|
//
|
|
|
|
|
|
|
|
OPERATION_STATE_DEF(drag_time_marker_operation_state)
|
|
|
|
{
|
|
|
|
rect TimelineBounds;
|
|
|
|
s32 StartFrame;
|
|
|
|
s32 EndFrame;
|
|
|
|
};
|
|
|
|
|
|
|
|
OPERATION_RENDER_PROC(UpdateDragTimeMarker)
|
|
|
|
{
|
|
|
|
drag_time_marker_operation_state* OpState = (drag_time_marker_operation_state*)Operation.OpStateMemory;
|
2020-03-01 01:11:15 +00:00
|
|
|
u32 FrameAtMouseX = GetFrameFromPointInAnimationPanel(Mouse.Pos, OpState->TimelineBounds, OpState->StartFrame, OpState->EndFrame);
|
|
|
|
State->AnimationSystem.CurrentFrame = FrameAtMouseX;
|
2019-12-28 22:14:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
FOLDHAUS_INPUT_COMMAND_PROC(EndDragTimeMarker)
|
|
|
|
{
|
|
|
|
DeactivateCurrentOperationMode(&State->Modes);
|
|
|
|
}
|
|
|
|
|
|
|
|
input_command DragTimeMarkerCommands [] = {
|
|
|
|
{ KeyCode_MouseLeftButton, KeyCode_Invalid, Command_Ended, EndDragTimeMarker },
|
|
|
|
};
|
|
|
|
|
|
|
|
internal void
|
|
|
|
StartDragTimeMarker(rect TimelineBounds, s32 PanelStartFrame, s32 PanelEndFrame, app_state* State)
|
|
|
|
{
|
|
|
|
operation_mode* DragTimeMarkerMode = ActivateOperationModeWithCommands(&State->Modes, DragTimeMarkerCommands, UpdateDragTimeMarker);
|
|
|
|
|
|
|
|
drag_time_marker_operation_state* OpState = CreateOperationState(DragTimeMarkerMode,
|
|
|
|
&State->Modes,
|
|
|
|
drag_time_marker_operation_state);
|
|
|
|
OpState->StartFrame = PanelStartFrame;
|
|
|
|
OpState->EndFrame = PanelEndFrame ;
|
|
|
|
OpState->TimelineBounds = TimelineBounds;
|
|
|
|
}
|
|
|
|
|
|
|
|
// --------------------
|
|
|
|
|
2019-12-28 19:31:21 +00:00
|
|
|
//
|
|
|
|
// Drag Animation Clip
|
|
|
|
//
|
|
|
|
|
2019-12-28 19:41:00 +00:00
|
|
|
#define CLICK_ANIMATION_BLOCK_EDGE_MAX_SCREEN_DISTANCE 10
|
|
|
|
|
2019-12-28 19:31:21 +00:00
|
|
|
OPERATION_STATE_DEF(drag_animation_clip_state)
|
|
|
|
{
|
2019-12-29 00:01:34 +00:00
|
|
|
rect TimelineBounds;
|
2020-03-01 01:11:15 +00:00
|
|
|
s32 AnimationPanel_StartFrame;
|
|
|
|
s32 AnimationPanel_EndFrame;
|
|
|
|
s32 SelectedClip_InitialStartFrame;
|
|
|
|
s32 SelectedClip_InitialEndFrame;
|
2019-12-28 19:31:21 +00:00
|
|
|
};
|
|
|
|
|
2020-03-01 01:11:15 +00:00
|
|
|
internal u32
|
|
|
|
AttemptToSnapPosition(u32 SnappingFrame, u32 SnapToFrame)
|
2020-02-29 23:43:06 +00:00
|
|
|
{
|
2020-03-01 01:11:15 +00:00
|
|
|
u32 Result = SnappingFrame;
|
|
|
|
s32 SnapDistance = 5;
|
|
|
|
if (GSAbs((s32)SnappingFrame - (s32)SnapToFrame) <= SnapDistance)
|
2020-02-29 23:43:06 +00:00
|
|
|
{
|
2020-03-01 01:11:15 +00:00
|
|
|
Result = SnapToFrame;
|
2020-02-29 23:43:06 +00:00
|
|
|
}
|
|
|
|
return Result;
|
|
|
|
}
|
|
|
|
|
2019-12-28 19:31:21 +00:00
|
|
|
OPERATION_RENDER_PROC(UpdateDragAnimationClip)
|
|
|
|
{
|
|
|
|
drag_animation_clip_state* OpState = (drag_animation_clip_state*)Operation.OpStateMemory;
|
|
|
|
|
2020-03-01 01:11:15 +00:00
|
|
|
u32 ClipInitialStartFrameXPosition = GetXPositionFromFrameInAnimationPanel(OpState->SelectedClip_InitialStartFrame, OpState->TimelineBounds, OpState->AnimationPanel_StartFrame, OpState->AnimationPanel_EndFrame);
|
|
|
|
u32 ClipInitialEndFrameXPosition = GetXPositionFromFrameInAnimationPanel(OpState->SelectedClip_InitialEndFrame, OpState->TimelineBounds, OpState->AnimationPanel_StartFrame, OpState->AnimationPanel_EndFrame);
|
|
|
|
|
|
|
|
u32 FrameAtMouseDownX = GetFrameFromPointInAnimationPanel(Mouse.DownPos, OpState->TimelineBounds, OpState->AnimationPanel_StartFrame, OpState->AnimationPanel_EndFrame);
|
2019-12-28 19:31:21 +00:00
|
|
|
|
2020-03-01 01:11:15 +00:00
|
|
|
u32 FrameAtMouseX = GetFrameFromPointInAnimationPanel(Mouse.Pos, OpState->TimelineBounds, OpState->AnimationPanel_StartFrame, OpState->AnimationPanel_EndFrame);
|
|
|
|
s32 FrameOffset = (s32)FrameAtMouseX - (s32)FrameAtMouseDownX;
|
2019-12-28 19:31:21 +00:00
|
|
|
|
2019-12-31 04:26:28 +00:00
|
|
|
animation_block* AnimationBlock = State->AnimationSystem.Blocks.GetElementWithHandle(State->SelectedAnimationBlockHandle);
|
2020-03-01 00:02:30 +00:00
|
|
|
if (!AnimationBlock)
|
|
|
|
{
|
|
|
|
EndCurrentOperationMode(State, {}, Mouse);
|
|
|
|
return;
|
|
|
|
}
|
2019-12-28 19:41:00 +00:00
|
|
|
|
2020-03-01 01:11:15 +00:00
|
|
|
if (GSAbs(Mouse.DownPos.x - ClipInitialStartFrameXPosition) < CLICK_ANIMATION_BLOCK_EDGE_MAX_SCREEN_DISTANCE)
|
2019-12-28 19:41:00 +00:00
|
|
|
{
|
2020-03-01 01:11:15 +00:00
|
|
|
u32 NewStartFrame = OpState->SelectedClip_InitialStartFrame + FrameOffset;
|
|
|
|
if (FrameOffset < 0)
|
2020-02-29 23:43:06 +00:00
|
|
|
{
|
2020-03-01 00:02:30 +00:00
|
|
|
for (u32 i = 0; i < State->AnimationSystem.Blocks.Used; i++)
|
|
|
|
{
|
|
|
|
gs_list_entry<animation_block>* OtherBlockEntry = State->AnimationSystem.Blocks.GetEntryAtIndex(i);
|
|
|
|
if (OtherBlockEntry->Free.NextFreeEntry != 0) { continue; }
|
|
|
|
animation_block OtherBlock = OtherBlockEntry->Value;
|
2020-03-01 01:11:15 +00:00
|
|
|
NewStartFrame = AttemptToSnapPosition(NewStartFrame, OtherBlock.EndFrame);
|
2020-03-01 00:02:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2020-03-01 01:11:15 +00:00
|
|
|
if (NewStartFrame >= AnimationBlock->EndFrame)
|
2020-03-01 00:02:30 +00:00
|
|
|
{
|
2020-03-01 01:11:15 +00:00
|
|
|
NewStartFrame = AnimationBlock->EndFrame - 1;
|
2020-03-01 00:02:30 +00:00
|
|
|
}
|
2020-02-29 23:43:06 +00:00
|
|
|
}
|
2020-03-01 01:11:15 +00:00
|
|
|
AnimationBlock->StartFrame = NewStartFrame;
|
2019-12-28 19:41:00 +00:00
|
|
|
}
|
2020-03-01 01:11:15 +00:00
|
|
|
else if (GSAbs(Mouse.DownPos.x - ClipInitialEndFrameXPosition) < CLICK_ANIMATION_BLOCK_EDGE_MAX_SCREEN_DISTANCE)
|
2019-12-28 19:41:00 +00:00
|
|
|
{
|
2020-03-01 01:11:15 +00:00
|
|
|
r32 NewEndFrame = OpState->SelectedClip_InitialEndFrame + FrameOffset;
|
|
|
|
if (FrameOffset > 0)
|
2020-02-29 23:43:06 +00:00
|
|
|
{
|
2020-03-01 00:02:30 +00:00
|
|
|
for (u32 i = 0; i < State->AnimationSystem.Blocks.Used; i++)
|
|
|
|
{
|
|
|
|
gs_list_entry<animation_block>* OtherBlockEntry = State->AnimationSystem.Blocks.GetEntryAtIndex(i);
|
|
|
|
if (OtherBlockEntry->Free.NextFreeEntry != 0) { continue; }
|
|
|
|
animation_block OtherBlock = OtherBlockEntry->Value;
|
2020-03-01 01:11:15 +00:00
|
|
|
NewEndFrame = AttemptToSnapPosition(NewEndFrame, OtherBlock.StartFrame);
|
2020-03-01 00:02:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2020-03-01 01:11:15 +00:00
|
|
|
if(NewEndFrame <= AnimationBlock->StartFrame)
|
2020-03-01 00:02:30 +00:00
|
|
|
{
|
2020-03-01 01:11:15 +00:00
|
|
|
NewEndFrame = AnimationBlock->StartFrame + 1;
|
2020-03-01 00:02:30 +00:00
|
|
|
}
|
2020-02-29 23:43:06 +00:00
|
|
|
}
|
2020-03-01 01:11:15 +00:00
|
|
|
AnimationBlock->EndFrame = NewEndFrame;
|
2019-12-28 19:41:00 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2020-03-01 01:11:15 +00:00
|
|
|
u32 NewStartFrame = OpState->SelectedClip_InitialStartFrame + FrameOffset;
|
|
|
|
u32 NewEndFrame = OpState->SelectedClip_InitialEndFrame + FrameOffset;
|
2020-02-29 23:43:06 +00:00
|
|
|
for (u32 i = 0; i < State->AnimationSystem.Blocks.Used; i++)
|
|
|
|
{
|
|
|
|
gs_list_entry<animation_block>* OtherBlockEntry = State->AnimationSystem.Blocks.GetEntryAtIndex(i);
|
|
|
|
if (OtherBlockEntry->Free.NextFreeEntry != 0) { continue; }
|
|
|
|
animation_block OtherBlock = OtherBlockEntry->Value;
|
|
|
|
|
2020-03-01 01:11:15 +00:00
|
|
|
u32 SnapFramesAmount = 0;
|
|
|
|
if (FrameOffset > 0)
|
2020-02-29 23:43:06 +00:00
|
|
|
{
|
2020-03-01 01:11:15 +00:00
|
|
|
u32 FinalEndFrame = AttemptToSnapPosition(NewEndFrame, OtherBlock.StartFrame);
|
|
|
|
SnapFramesAmount = FinalEndFrame - NewEndFrame;
|
2020-02-29 23:43:06 +00:00
|
|
|
}
|
2020-03-01 01:11:15 +00:00
|
|
|
else if (FrameOffset < 0)
|
2020-02-29 23:43:06 +00:00
|
|
|
{
|
2020-03-01 01:11:15 +00:00
|
|
|
u32 FinalStartFrame = AttemptToSnapPosition(NewStartFrame, OtherBlock.EndFrame);
|
|
|
|
SnapFramesAmount = FinalStartFrame - NewStartFrame;
|
2020-02-29 23:43:06 +00:00
|
|
|
}
|
2020-03-01 01:11:15 +00:00
|
|
|
NewEndFrame += SnapFramesAmount;
|
|
|
|
NewStartFrame += SnapFramesAmount;
|
2020-02-29 23:43:06 +00:00
|
|
|
}
|
2020-03-01 01:11:15 +00:00
|
|
|
AnimationBlock->StartFrame = NewStartFrame;
|
|
|
|
AnimationBlock->EndFrame = NewEndFrame;
|
2019-12-28 19:41:00 +00:00
|
|
|
}
|
2020-03-01 00:02:30 +00:00
|
|
|
|
2020-03-01 01:11:15 +00:00
|
|
|
s32 VisibleStartFrame = OpState->AnimationPanel_StartFrame;
|
|
|
|
s32 VisibleEndFrame = OpState->AnimationPanel_EndFrame;
|
|
|
|
AnimationBlock->StartFrame = (u32)GSClamp(VisibleStartFrame, (s32)AnimationBlock->StartFrame, VisibleEndFrame);
|
|
|
|
AnimationBlock->EndFrame = (u32)GSClamp(VisibleStartFrame, (s32)AnimationBlock->EndFrame, VisibleEndFrame);
|
2019-12-28 19:31:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
input_command DragAnimationClipCommands [] = {
|
2019-12-31 04:26:28 +00:00
|
|
|
{ KeyCode_MouseLeftButton, KeyCode_Invalid, Command_Ended, EndCurrentOperationMode },
|
2019-12-28 19:31:21 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
internal void
|
2019-12-31 04:26:28 +00:00
|
|
|
SelectAndBeginDragAnimationBlock(gs_list_handle BlockHandle, s32 PanelStartFrame, s32 PanelEndFrame, rect TimelineBounds, app_state* State)
|
2019-12-28 19:31:21 +00:00
|
|
|
{
|
|
|
|
SelectAnimationBlock(BlockHandle, State);
|
|
|
|
|
|
|
|
operation_mode* DragAnimationClipMode = ActivateOperationModeWithCommands(&State->Modes, DragAnimationClipCommands, UpdateDragAnimationClip);
|
|
|
|
|
|
|
|
drag_animation_clip_state* OpState = CreateOperationState(DragAnimationClipMode,
|
|
|
|
&State->Modes,
|
|
|
|
drag_animation_clip_state);
|
2019-12-29 00:01:34 +00:00
|
|
|
OpState->TimelineBounds = TimelineBounds;
|
2019-12-28 19:31:21 +00:00
|
|
|
OpState->AnimationPanel_StartFrame = PanelStartFrame;
|
|
|
|
OpState->AnimationPanel_EndFrame = PanelEndFrame ;
|
|
|
|
|
2019-12-31 04:26:28 +00:00
|
|
|
animation_block* SelectedBlock = State->AnimationSystem.Blocks.GetElementWithHandle(BlockHandle);
|
2020-03-01 01:11:15 +00:00
|
|
|
OpState->SelectedClip_InitialStartFrame = SelectedBlock->StartFrame;
|
|
|
|
OpState->SelectedClip_InitialEndFrame = SelectedBlock->EndFrame;
|
2019-12-28 19:31:21 +00:00
|
|
|
}
|
|
|
|
// -------------------
|
|
|
|
|
2019-12-28 18:51:47 +00:00
|
|
|
FOLDHAUS_INPUT_COMMAND_PROC(AddAnimationBlockCommand)
|
|
|
|
{
|
2019-12-28 21:02:19 +00:00
|
|
|
panel_and_bounds ActivePanel = GetPanelContainingPoint(Mouse.Pos, &State->PanelSystem, State->WindowBounds);
|
2020-03-01 01:11:15 +00:00
|
|
|
u32 MouseDownFrame = GetFrameFromPointInAnimationPanel(Mouse.Pos, ActivePanel.Bounds, State->AnimationSystem.StartFrame, State->AnimationSystem.EndFrame);
|
|
|
|
gs_list_handle NewBlockHandle = AddAnimationBlock(MouseDownFrame, MouseDownFrame + SecondsToFrames(3, State->AnimationSystem), 4, &State->AnimationSystem);
|
2019-12-28 18:51:47 +00:00
|
|
|
SelectAnimationBlock(NewBlockHandle, State);
|
|
|
|
}
|
|
|
|
|
|
|
|
input_command AnimationTimeline_Commands[] = {
|
|
|
|
{ KeyCode_X, KeyCode_Invalid, Command_Began, DeleteAnimationBlockCommand },
|
|
|
|
{ KeyCode_A, KeyCode_Invalid, Command_Began, AddAnimationBlockCommand },
|
|
|
|
};
|
2020-02-29 22:23:46 +00:00
|
|
|
s32 AnimationTimeline_CommandsCount = 2;
|
2020-02-02 03:15:04 +00:00
|
|
|
|
|
|
|
GSMetaTag(panel_init);
|
2020-02-29 22:23:46 +00:00
|
|
|
GSMetaTag(panel_type_animation_timeline);
|
2020-02-02 03:15:04 +00:00
|
|
|
internal void
|
|
|
|
AnimationTimeline_Init(panel* Panel, app_state* State)
|
2019-12-26 20:42:55 +00:00
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2020-02-02 03:15:04 +00:00
|
|
|
GSMetaTag(panel_cleanup);
|
2020-02-29 22:23:46 +00:00
|
|
|
GSMetaTag(panel_type_animation_timeline);
|
2020-02-02 03:15:04 +00:00
|
|
|
internal void
|
|
|
|
AnimationTimeline_Cleanup(panel* Panel, app_state* State)
|
2019-12-26 20:42:55 +00:00
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2019-12-27 02:40:14 +00:00
|
|
|
internal r32
|
2019-12-28 22:14:00 +00:00
|
|
|
DrawFrameBar (animation_system* AnimationSystem, render_command_buffer* RenderBuffer, s32 StartFrame, s32 EndFrame, rect PanelBounds, mouse_state Mouse, app_state* State)
|
2019-12-26 20:42:55 +00:00
|
|
|
{
|
2019-12-27 02:40:14 +00:00
|
|
|
MakeStringBuffer(TempString, 256);
|
2019-12-26 20:42:55 +00:00
|
|
|
|
2019-12-27 02:40:14 +00:00
|
|
|
s32 FrameCount = EndFrame - StartFrame;
|
2019-12-26 20:42:55 +00:00
|
|
|
|
2019-12-27 00:23:43 +00:00
|
|
|
r32 FrameBarHeight = 24;
|
2019-12-28 19:31:21 +00:00
|
|
|
v2 FrameBarMin = v2{PanelBounds.Min.x, PanelBounds.Max.y - FrameBarHeight};
|
|
|
|
v2 FrameBarMax = PanelBounds.Max;
|
2019-12-27 02:40:14 +00:00
|
|
|
|
2019-12-27 00:23:43 +00:00
|
|
|
PushRenderQuad2D(RenderBuffer, FrameBarMin, FrameBarMax, v4{.16f, .16f, .16f, 1.f});
|
2019-12-26 20:42:55 +00:00
|
|
|
|
2019-12-27 02:40:14 +00:00
|
|
|
// Mouse clicked inside frame nubmer bar -> change current frame on timeline
|
2019-12-28 22:14:00 +00:00
|
|
|
if (MouseButtonTransitionedDown(Mouse.LeftButtonState)
|
2019-12-27 00:23:43 +00:00
|
|
|
&& PointIsInRange(Mouse.DownPos, FrameBarMin, FrameBarMax))
|
|
|
|
{
|
2019-12-28 22:14:00 +00:00
|
|
|
StartDragTimeMarker(rect{FrameBarMin, FrameBarMax}, StartFrame, EndFrame, State);
|
2019-12-27 00:23:43 +00:00
|
|
|
}
|
|
|
|
|
2019-12-27 02:40:14 +00:00
|
|
|
// Frame Ticks
|
2019-12-27 00:23:43 +00:00
|
|
|
for (s32 f = 0; f < FrameCount; f += 10)
|
|
|
|
{
|
|
|
|
s32 Frame = StartFrame + f;
|
|
|
|
PrintF(&TempString, "%d", Frame);
|
|
|
|
|
|
|
|
r32 FramePercent = (r32)f / (r32)FrameCount;
|
2019-12-28 19:31:21 +00:00
|
|
|
r32 FrameX = GSLerp(PanelBounds.Min.x, PanelBounds.Max.x, FramePercent);
|
2019-12-27 00:23:43 +00:00
|
|
|
v2 FrameTextPos = v2{FrameX, FrameBarMin.y + 2};
|
2019-12-28 22:14:00 +00:00
|
|
|
DrawString(RenderBuffer, TempString, State->Interface.Font, FrameTextPos, WhiteV4);
|
2019-12-27 00:23:43 +00:00
|
|
|
|
|
|
|
// Frame Vertical Slices
|
|
|
|
v2 LineTop = v2{FrameX, FrameBarMin.y};
|
2019-12-28 19:31:21 +00:00
|
|
|
v2 LineBottom = v2{FrameX + 1, PanelBounds.Min.y};
|
2019-12-27 00:23:43 +00:00
|
|
|
PushRenderQuad2D(RenderBuffer, LineTop, LineBottom, v4{.16f, .16f, .16f, 1.f});
|
|
|
|
}
|
|
|
|
|
2019-12-27 02:40:14 +00:00
|
|
|
return FrameBarMin.y;
|
|
|
|
}
|
|
|
|
|
|
|
|
internal rect
|
2020-03-01 01:11:15 +00:00
|
|
|
DrawAnimationBlock (animation_block AnimationBlock, v4 BlockColor, s32 FrameCount, s32 StartFrame, rect TimelineBounds, render_command_buffer* RenderBuffer)
|
2019-12-27 02:40:14 +00:00
|
|
|
{
|
|
|
|
rect BlockBounds = {};
|
|
|
|
|
2019-12-29 00:01:34 +00:00
|
|
|
r32 TimelineWidth = Width(TimelineBounds);
|
2019-12-27 02:40:14 +00:00
|
|
|
|
2020-03-01 01:11:15 +00:00
|
|
|
r32 StartFramePercent = (r32)(AnimationBlock.StartFrame - StartFrame) / (r32)FrameCount;
|
2019-12-27 02:40:14 +00:00
|
|
|
r32 StartPosition = TimelineWidth * StartFramePercent;
|
|
|
|
|
2020-03-01 01:11:15 +00:00
|
|
|
r32 EndFramePercent = (r32)(AnimationBlock.EndFrame - StartFrame) / (r32)FrameCount;
|
2019-12-27 02:40:14 +00:00
|
|
|
r32 EndPosition = TimelineWidth * EndFramePercent;
|
|
|
|
|
2019-12-29 00:01:34 +00:00
|
|
|
BlockBounds.Min = TimelineBounds.Min + v2{StartPosition, 25};
|
|
|
|
BlockBounds.Max = TimelineBounds.Min + v2{EndPosition, 75};
|
2019-12-27 02:40:14 +00:00
|
|
|
|
|
|
|
PushRenderQuad2D(RenderBuffer, BlockBounds.Min, BlockBounds.Max, BlockColor);
|
|
|
|
PushRenderBoundingBox2D(RenderBuffer, BlockBounds.Min, BlockBounds.Max, 1, WhiteV4);
|
|
|
|
|
|
|
|
return BlockBounds;
|
|
|
|
}
|
|
|
|
|
2019-12-31 04:26:28 +00:00
|
|
|
internal gs_list_handle
|
2020-03-01 01:11:15 +00:00
|
|
|
DrawAnimationTimeline (animation_system* AnimationSystem, s32 VisibleStartFrame, s32 VisibleEndFrame, rect PanelBounds, gs_list_handle SelectedBlockHandle, render_command_buffer* RenderBuffer, app_state* State, mouse_state Mouse)
|
2019-12-27 02:40:14 +00:00
|
|
|
{
|
|
|
|
string TempString = MakeString(PushArray(&State->Transient, char, 256), 256);
|
2020-03-01 01:11:15 +00:00
|
|
|
s32 VisibleFrameCount = VisibleEndFrame - VisibleStartFrame;
|
2019-12-27 02:40:14 +00:00
|
|
|
|
2019-12-31 04:26:28 +00:00
|
|
|
gs_list_handle Result = SelectedBlockHandle;
|
2019-12-27 02:40:14 +00:00
|
|
|
|
2019-12-28 19:31:21 +00:00
|
|
|
r32 AnimationPanelHeight = PanelBounds.Max.y - PanelBounds.Min.y;
|
|
|
|
r32 AnimationPanelWidth = PanelBounds.Max.x - PanelBounds.Min.x;
|
2019-12-27 02:40:14 +00:00
|
|
|
|
|
|
|
{
|
2020-03-01 01:11:15 +00:00
|
|
|
r32 FirstPlayablePercentX = ((r32)(AnimationSystem->StartFrame - VisibleStartFrame) / (r32)VisibleFrameCount);
|
|
|
|
r32 LastPlayablePercentX = ((r32)(AnimationSystem->EndFrame - VisibleStartFrame) / (r32)VisibleFrameCount);
|
2019-12-27 02:40:14 +00:00
|
|
|
|
2019-12-28 19:31:21 +00:00
|
|
|
v2 PlayableMin = v2{(FirstPlayablePercentX * AnimationPanelWidth) + PanelBounds.Min.x, PanelBounds.Min.y };
|
|
|
|
v2 PlayableMax = v2{(LastPlayablePercentX * AnimationPanelWidth) + PanelBounds.Min.x, PanelBounds.Max.y };
|
2019-12-27 02:40:14 +00:00
|
|
|
|
2019-12-28 19:31:21 +00:00
|
|
|
PushRenderQuad2D(RenderBuffer, PanelBounds.Min, PanelBounds.Max, v4{.16f, .16f, .16f, 1.f});
|
2019-12-27 02:40:14 +00:00
|
|
|
PushRenderQuad2D(RenderBuffer, PlayableMin, PlayableMax, v4{.22f, .22f, .22f, 1.f});
|
|
|
|
}
|
|
|
|
|
2020-03-01 01:11:15 +00:00
|
|
|
r32 FrameBarBottom = DrawFrameBar(AnimationSystem, RenderBuffer, VisibleStartFrame, VisibleEndFrame, PanelBounds, Mouse, State);
|
2019-12-27 02:40:14 +00:00
|
|
|
|
2019-12-27 00:23:43 +00:00
|
|
|
// Animation Blocks
|
2019-12-29 00:01:34 +00:00
|
|
|
rect TimelineBounds = rect{ PanelBounds.Min, v2{PanelBounds.Max.x, FrameBarBottom} };
|
2019-12-27 00:23:43 +00:00
|
|
|
b32 MouseDownAndNotHandled = MouseButtonTransitionedDown(Mouse.LeftButtonState);
|
2019-12-31 04:26:28 +00:00
|
|
|
for (u32 i = 0; i < AnimationSystem->Blocks.Used; i++)
|
2019-12-27 00:23:43 +00:00
|
|
|
{
|
2019-12-31 04:26:28 +00:00
|
|
|
gs_list_entry<animation_block>* AnimationBlockEntry = AnimationSystem->Blocks.GetEntryAtIndex(i);
|
|
|
|
if (AnimationBlockEntry->Free.NextFreeEntry != 0) { continue; }
|
2019-12-26 20:42:55 +00:00
|
|
|
|
2019-12-31 04:26:28 +00:00
|
|
|
gs_list_handle CurrentBlockHandle = AnimationBlockEntry->Handle;
|
|
|
|
animation_block AnimationBlockAt = AnimationBlockEntry->Value;
|
2019-12-27 00:23:43 +00:00
|
|
|
|
2019-12-26 20:42:55 +00:00
|
|
|
v4 BlockColor = BlackV4;
|
2019-12-31 04:26:28 +00:00
|
|
|
if (GSListHandlesAreEqual(SelectedBlockHandle, CurrentBlockHandle))
|
2019-12-26 20:42:55 +00:00
|
|
|
{
|
|
|
|
BlockColor = PinkV4;
|
|
|
|
}
|
|
|
|
|
2020-03-01 01:11:15 +00:00
|
|
|
rect BlockBounds = DrawAnimationBlock(AnimationBlockAt, BlockColor, VisibleFrameCount, VisibleStartFrame, TimelineBounds, RenderBuffer);
|
2019-12-26 20:42:55 +00:00
|
|
|
|
2019-12-27 02:40:14 +00:00
|
|
|
if (PointIsInRange(Mouse.Pos, BlockBounds.Min, BlockBounds.Max)
|
2019-12-26 20:42:55 +00:00
|
|
|
&& MouseButtonTransitionedDown(Mouse.LeftButtonState))
|
|
|
|
{
|
|
|
|
MouseDownAndNotHandled = false;
|
2020-03-01 01:11:15 +00:00
|
|
|
SelectAndBeginDragAnimationBlock(CurrentBlockHandle, VisibleStartFrame, VisibleEndFrame, TimelineBounds, State);
|
2019-12-26 20:42:55 +00:00
|
|
|
}
|
2019-12-27 00:23:43 +00:00
|
|
|
}
|
2019-12-26 20:42:55 +00:00
|
|
|
|
2019-12-27 00:23:43 +00:00
|
|
|
// Time Slider
|
2020-03-01 01:11:15 +00:00
|
|
|
r32 TimePercent = (r32)(AnimationSystem->CurrentFrame - VisibleStartFrame) / (r32)VisibleFrameCount;
|
2019-12-28 19:31:21 +00:00
|
|
|
r32 SliderX = PanelBounds.Min.x + (AnimationPanelWidth * TimePercent);
|
|
|
|
v2 SliderMin = v2{SliderX, PanelBounds.Min.y};
|
|
|
|
v2 SliderMax = v2{SliderX + 1, PanelBounds.Max.y - 25};
|
2019-12-27 00:23:43 +00:00
|
|
|
v4 TimeSliderColor = v4{.36f, .52f, .78f, 1.f};
|
|
|
|
|
|
|
|
PushRenderQuad2D(RenderBuffer, SliderMin, SliderMax, TimeSliderColor);
|
|
|
|
|
|
|
|
r32 SliderHalfWidth = 10;
|
|
|
|
v2 HeadMin = v2{SliderX - SliderHalfWidth, SliderMax.y};
|
2019-12-28 19:31:21 +00:00
|
|
|
v2 HeadMax = v2{SliderX + SliderHalfWidth, PanelBounds.Max.y};
|
2019-12-27 00:23:43 +00:00
|
|
|
PushRenderQuad2D(RenderBuffer, HeadMin, HeadMax, TimeSliderColor);
|
2019-12-26 20:42:55 +00:00
|
|
|
|
2020-03-01 01:11:15 +00:00
|
|
|
PrintF(&TempString, "%d", AnimationSystem->CurrentFrame);
|
2019-12-27 00:23:43 +00:00
|
|
|
DrawString(RenderBuffer, TempString, State->Interface.Font, HeadMin + v2{4, 4}, WhiteV4);
|
|
|
|
|
2019-12-29 00:01:34 +00:00
|
|
|
if (MouseDownAndNotHandled && PointIsInRect(Mouse.Pos, TimelineBounds))
|
2019-12-26 20:42:55 +00:00
|
|
|
{
|
2019-12-28 18:51:47 +00:00
|
|
|
DeselectCurrentAnimationBlock(State);
|
2019-12-26 20:42:55 +00:00
|
|
|
}
|
|
|
|
return Result;
|
2019-12-27 00:23:43 +00:00
|
|
|
}
|
2019-12-26 20:42:55 +00:00
|
|
|
|
2019-12-29 00:01:34 +00:00
|
|
|
struct animation_clip
|
|
|
|
{
|
|
|
|
char* Name;
|
|
|
|
s32 NameLength;
|
|
|
|
animation_proc* Proc;
|
|
|
|
};
|
|
|
|
|
|
|
|
s32 GlobalAnimationClipsCount = 3;
|
|
|
|
animation_clip GlobalAnimationClips[] = {
|
|
|
|
{ "Test Pattern One", 16, TestPatternOne },
|
|
|
|
{ "Test Pattern Two", 16, TestPatternTwo },
|
|
|
|
{ "Test Pattern Three", 18, TestPatternThree },
|
|
|
|
};
|
|
|
|
|
|
|
|
internal void
|
|
|
|
DrawAnimationClipsList(rect PanelBounds, mouse_state Mouse, render_command_buffer* RenderBuffer, app_state* State)
|
|
|
|
{
|
|
|
|
v4 LineBGColors[] = {
|
|
|
|
{ .16f, .16f, .16f, 1.f },
|
|
|
|
{ .18f, .18f, .18f, 1.f },
|
|
|
|
};
|
|
|
|
|
|
|
|
interface_list List = {};
|
|
|
|
|
|
|
|
List.LineBGColors = LineBGColors;
|
|
|
|
List.LineBGColorsCount = sizeof(LineBGColors) / sizeof(LineBGColors[0]);
|
|
|
|
List.LineBGHoverColor = v4{ .22f, .22f, .22f, 1.f };
|
|
|
|
List.TextColor = WhiteV4;
|
|
|
|
List.ListBounds = PanelBounds;
|
|
|
|
List.ListElementDimensions = v2{
|
|
|
|
Width(PanelBounds),
|
|
|
|
(r32)(State->Interface.Font->PixelHeight + 8),
|
|
|
|
};
|
|
|
|
List.ElementLabelIndent = v2{10, 4};
|
|
|
|
|
|
|
|
string TitleString = MakeStringLiteral("Animation Clips");
|
|
|
|
DrawListElement(TitleString, &List, Mouse, RenderBuffer, State->Interface);
|
|
|
|
|
|
|
|
for (s32 i = 0; i < GlobalAnimationClipsCount; i++)
|
|
|
|
{
|
|
|
|
animation_clip Clip = GlobalAnimationClips[i];
|
|
|
|
string ClipName = MakeString(Clip.Name, Clip.NameLength);
|
|
|
|
rect ElementBounds = DrawListElement(ClipName, &List, Mouse, RenderBuffer, State->Interface);
|
|
|
|
|
|
|
|
if (MouseButtonTransitionedDown(Mouse.LeftButtonState)
|
|
|
|
&& PointIsInRect(Mouse.DownPos, ElementBounds))
|
|
|
|
{
|
2020-02-05 06:50:12 +00:00
|
|
|
AddAnimationBlockAtCurrentTime(i + 1, &State->AnimationSystem);
|
2019-12-29 00:01:34 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2020-02-02 03:15:04 +00:00
|
|
|
GSMetaTag(panel_render);
|
2020-02-29 22:23:46 +00:00
|
|
|
GSMetaTag(panel_type_animation_timeline);
|
2020-02-02 03:15:04 +00:00
|
|
|
internal void
|
|
|
|
AnimationTimeline_Render(panel Panel, rect PanelBounds, render_command_buffer* RenderBuffer, app_state* State, context Context, mouse_state Mouse)
|
2019-12-26 20:42:55 +00:00
|
|
|
{
|
2019-12-31 04:26:28 +00:00
|
|
|
gs_list_handle SelectedBlockHandle = State->SelectedAnimationBlockHandle;
|
2019-12-26 20:42:55 +00:00
|
|
|
|
2019-12-27 00:23:43 +00:00
|
|
|
r32 OptionsRowHeight = 25;
|
2019-12-29 00:01:34 +00:00
|
|
|
rect AnimationClipListBounds = rect{
|
2019-12-28 19:31:21 +00:00
|
|
|
PanelBounds.Min,
|
2019-12-29 00:01:34 +00:00
|
|
|
v2{PanelBounds.Min.x + 300, PanelBounds.Max.y - OptionsRowHeight},
|
|
|
|
};
|
|
|
|
rect TimelineBounds = rect{
|
|
|
|
v2{AnimationClipListBounds.Max.x, PanelBounds.Min.y},
|
|
|
|
v2{PanelBounds.Max.x, PanelBounds.Max.y - OptionsRowHeight},
|
2019-12-28 19:31:21 +00:00
|
|
|
};
|
|
|
|
if (Height(TimelineBounds) > 0)
|
2019-12-26 20:42:55 +00:00
|
|
|
{
|
2019-12-29 00:01:34 +00:00
|
|
|
DrawAnimationClipsList(AnimationClipListBounds, Mouse, RenderBuffer, State);
|
|
|
|
|
2019-12-26 20:42:55 +00:00
|
|
|
SelectedBlockHandle = DrawAnimationTimeline(&State->AnimationSystem,
|
2020-03-01 01:11:15 +00:00
|
|
|
State->AnimationSystem.StartFrame - 20,
|
|
|
|
State->AnimationSystem.EndFrame + 20,
|
2019-12-28 19:31:21 +00:00
|
|
|
TimelineBounds,
|
2019-12-27 00:23:43 +00:00
|
|
|
SelectedBlockHandle,
|
|
|
|
RenderBuffer, State, Mouse);
|
2019-12-26 20:42:55 +00:00
|
|
|
}
|
|
|
|
|
2019-12-28 19:31:21 +00:00
|
|
|
v2 OptionsRowMin = v2{ PanelBounds.Min.x, TimelineBounds.Max.y };
|
|
|
|
v2 OptionsRowMax = PanelBounds.Max;
|
2020-02-15 23:06:51 +00:00
|
|
|
panel_result AnimationPanel = EvaluatePanel(RenderBuffer, OptionsRowMin, OptionsRowMax, State->Interface);
|
2019-12-26 20:42:55 +00:00
|
|
|
|
|
|
|
r32 ButtonWidth = 35;
|
|
|
|
v2 ButtonMin = v2{0, 0};
|
|
|
|
v2 ButtonMax = v2{35, OptionsRowHeight - 2};
|
|
|
|
v2 ButtonAt = v2{OptionsRowMin.x + 1, OptionsRowMin.y + 1};
|
|
|
|
|
|
|
|
button_result PauseResult = EvaluateButton(RenderBuffer,
|
|
|
|
ButtonAt + ButtonMin, ButtonAt + ButtonMax,
|
|
|
|
MakeStringLiteral("Pause"),
|
|
|
|
State->Interface, Mouse);
|
|
|
|
ButtonAt.x += ButtonWidth + 2;
|
2019-12-27 00:23:43 +00:00
|
|
|
button_result PlayResult = EvaluateButton(RenderBuffer,
|
|
|
|
ButtonAt + ButtonMin, ButtonAt + ButtonMax,
|
|
|
|
MakeStringLiteral("Play"),
|
2019-12-26 20:42:55 +00:00
|
|
|
State->Interface, Mouse);
|
|
|
|
ButtonAt.x += ButtonWidth + 2;
|
2019-12-27 00:23:43 +00:00
|
|
|
button_result StopResult = EvaluateButton(RenderBuffer,
|
|
|
|
ButtonAt + ButtonMin, ButtonAt + ButtonMax,
|
|
|
|
MakeStringLiteral("Stop"),
|
2019-12-26 20:42:55 +00:00
|
|
|
State->Interface, Mouse);
|
|
|
|
|
|
|
|
if (PauseResult.Pressed)
|
|
|
|
{
|
|
|
|
State->AnimationSystem.TimelineShouldAdvance = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (PlayResult.Pressed)
|
|
|
|
{
|
|
|
|
State->AnimationSystem.TimelineShouldAdvance = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (StopResult.Pressed)
|
|
|
|
{
|
|
|
|
State->AnimationSystem.TimelineShouldAdvance = false;
|
2020-03-01 01:11:15 +00:00
|
|
|
State->AnimationSystem.CurrentFrame = 0;
|
2019-12-26 20:42:55 +00:00
|
|
|
}
|
|
|
|
}
|
2020-01-02 02:41:43 +00:00
|
|
|
|
|
|
|
#define FOLDHAUS_PANEL_ANIMATION_TIMELINE_H
|
|
|
|
#endif // FOLDHAUS_PANEL_ANIMATION_TIMELINE_H
|