Improved the visuals of the hierarchy panel and the timeline panel
This commit is contained in:
parent
d9af0c6a36
commit
2c6adaeda2
|
@ -40,7 +40,11 @@ struct animation_system
|
|||
u32 BlocksCount;
|
||||
|
||||
r32 Time;
|
||||
s32 LastUpdatedFrame;
|
||||
r32 SecondsPerFrame;
|
||||
|
||||
b32 TimelineShouldAdvance;
|
||||
|
||||
// :Temporary
|
||||
r32 AnimationEnd;
|
||||
};
|
||||
|
|
|
@ -275,6 +275,7 @@ INITIALIZE_APPLICATION(InitializeApplication)
|
|||
|
||||
{ // MODES PLAYGROUND
|
||||
InitializeAnimationSystem(&State->AnimationSystem);
|
||||
State->AnimationSystem.SecondsPerFrame = 1.f / 24.f;
|
||||
|
||||
animation_block BlockZero = {0};
|
||||
BlockZero.StartTime = 0;
|
||||
|
@ -415,6 +416,13 @@ UPDATE_AND_RENDER(UpdateAndRender)
|
|||
{
|
||||
State->AnimationSystem.Time -= State->AnimationSystem.AnimationEnd;
|
||||
}
|
||||
}
|
||||
|
||||
s32 CurrentFrame = (s32)(State->AnimationSystem.Time / State->AnimationSystem.SecondsPerFrame);
|
||||
if (CurrentFrame != State->AnimationSystem.LastUpdatedFrame)
|
||||
{
|
||||
State->AnimationSystem.LastUpdatedFrame = CurrentFrame;
|
||||
r32 FrameTime = CurrentFrame * State->AnimationSystem.SecondsPerFrame;
|
||||
|
||||
for (u32 i = 0; i < State->AnimationSystem.BlocksCount; i++)
|
||||
{
|
||||
|
@ -425,7 +433,7 @@ UPDATE_AND_RENDER(UpdateAndRender)
|
|||
if (State->AnimationSystem.Time >= Block.StartTime
|
||||
&& State->AnimationSystem.Time <= Block.EndTime)
|
||||
{
|
||||
Block.Proc(State, State->AnimationSystem.Time - Block.StartTime);
|
||||
Block.Proc(State, FrameTime - Block.StartTime);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -105,5 +105,7 @@ MouseButtonTransitionedUp (b32 MouseButtonState)
|
|||
internal b32
|
||||
MouseButtonHeldDown (b32 MouseButtonState)
|
||||
{
|
||||
return (KeyWasDown(MouseButtonState) && KeyIsDown(MouseButtonState));
|
||||
b32 WasDown = KeyWasDown(MouseButtonState);
|
||||
b32 IsDown = KeyIsDown(MouseButtonState);
|
||||
return (WasDown && IsDown);
|
||||
}
|
|
@ -8,12 +8,14 @@ enum string_alignment
|
|||
internal void
|
||||
DrawCharacter_ (render_quad_batch_constructor* BatchConstructor, r32 MinX, r32 MinY, codepoint_bitmap CodepointInfo, v4 Color)
|
||||
{
|
||||
r32 MaxX = MinX + (CodepointInfo.Width);
|
||||
r32 MaxY = MinY + (CodepointInfo.Height);
|
||||
s32 AlignedMinX = (s32)(MinX);
|
||||
s32 AlignedMinY = (s32)(MinY);
|
||||
s32 AlignedMaxX = AlignedMinX + (CodepointInfo.Width);
|
||||
s32 AlignedMaxY = AlignedMinY + (CodepointInfo.Height);
|
||||
|
||||
PushQuad2DOnBatch(BatchConstructor,
|
||||
v2{MinX, MinY}, v2{MaxX, MinY},
|
||||
v2{MaxX, MaxY}, v2{MinX, MaxY},
|
||||
v2{(r32)AlignedMinX, (r32)AlignedMinY}, v2{(r32)AlignedMaxX, (r32)AlignedMinY},
|
||||
v2{(r32)AlignedMaxX, (r32)AlignedMaxY}, v2{(r32)AlignedMinX, (r32)AlignedMaxY},
|
||||
CodepointInfo.UVMin, CodepointInfo.UVMax,
|
||||
Color);
|
||||
}
|
||||
|
|
|
@ -18,17 +18,54 @@ PANEL_CLEANUP_PROC(AnimationTimeline_Cleanup)
|
|||
}
|
||||
|
||||
internal animation_block_handle
|
||||
DrawAnimationTimeline (animation_system* AnimationSystem, v2 PanelMin, v2 PanelMax, animation_block_handle SelectedBlockHandle, render_command_buffer* RenderBuffer, interface_config Interface, mouse_state Mouse)
|
||||
DrawAnimationTimeline (animation_system* AnimationSystem, s32 StartFrame, s32 EndFrame, v2 PanelMin, v2 PanelMax, animation_block_handle SelectedBlockHandle, render_command_buffer* RenderBuffer, app_state* State, mouse_state Mouse)
|
||||
{
|
||||
string TempString = MakeString(PushArray(&State->Transient, char, 256), 256);
|
||||
s32 FrameCount = EndFrame - StartFrame;
|
||||
|
||||
animation_block_handle Result = SelectedBlockHandle;
|
||||
|
||||
r32 AnimationPanelHeight = PanelMax.y - PanelMin.y;
|
||||
r32 AnimationPanelWidth = PanelMax.x - PanelMin.x;
|
||||
panel_result AnimationPanel = EvaluatePanel(RenderBuffer, PanelMin, PanelMax,
|
||||
0, Interface);
|
||||
PushRenderQuad2D(RenderBuffer, PanelMin, PanelMax, v4{.22f, .22f, .22f, 1.f});
|
||||
|
||||
// Frame Bar
|
||||
r32 FrameBarHeight = 24;
|
||||
v2 FrameBarMin = v2{PanelMin.x, PanelMax.y - FrameBarHeight};
|
||||
v2 FrameBarMax = PanelMax;
|
||||
PushRenderQuad2D(RenderBuffer, FrameBarMin, FrameBarMax, v4{.16f, .16f, .16f, 1.f});
|
||||
|
||||
// Mouse clicked inside frame nubmer bar -> change current frame on timeline
|
||||
if (MouseButtonHeldDown(Mouse.LeftButtonState)
|
||||
&& PointIsInRange(Mouse.DownPos, FrameBarMin, FrameBarMax))
|
||||
{
|
||||
r32 MouseX = Mouse.DownPos.x;
|
||||
r32 MousePercentX = (MouseX - FrameBarMin.x) / (FrameBarMax.x - FrameBarMin.y);
|
||||
s32 MouseFrame = (s32)((MousePercentX * FrameCount) + StartFrame);
|
||||
r32 MouseFrameTime = (r32)MouseFrame * AnimationSystem->SecondsPerFrame;
|
||||
AnimationSystem->Time = MouseFrameTime;
|
||||
}
|
||||
|
||||
for (s32 f = 0; f < FrameCount; f += 10)
|
||||
{
|
||||
s32 Frame = StartFrame + f;
|
||||
PrintF(&TempString, "%d", Frame);
|
||||
|
||||
r32 FramePercent = (r32)f / (r32)FrameCount;
|
||||
r32 FrameX = GSLerp(PanelMin.x, PanelMax.x, FramePercent);
|
||||
v2 FrameTextPos = v2{FrameX, FrameBarMin.y + 2};
|
||||
DrawString(RenderBuffer, TempString, State->Interface.Font, FrameTextPos, WhiteV4);
|
||||
|
||||
// Frame Vertical Slices
|
||||
v2 LineTop = v2{FrameX, FrameBarMin.y};
|
||||
v2 LineBottom = v2{FrameX + 1, PanelMin.y};
|
||||
PushRenderQuad2D(RenderBuffer, LineTop, LineBottom, v4{.16f, .16f, .16f, 1.f});
|
||||
}
|
||||
|
||||
// Animation Blocks
|
||||
v2 TimelineMin = PanelMin;
|
||||
v2 TimelineMax = v2{PanelMax.x, FrameBarMin.y};
|
||||
b32 MouseDownAndNotHandled = MouseButtonTransitionedDown(Mouse.LeftButtonState);
|
||||
|
||||
for (u32 i = 0; i < AnimationSystem->BlocksCount; i++)
|
||||
{
|
||||
animation_block_entry AnimationBlockEntry = AnimationSystem->Blocks[i];
|
||||
|
@ -40,14 +77,16 @@ r32 AnimationPanelHeight = PanelMax.y - PanelMin.y;
|
|||
|
||||
animation_block AnimationBlockAt = AnimationBlockEntry.Block;
|
||||
|
||||
r32 StartTimePercent = AnimationBlockAt.StartTime / AnimationSystem->AnimationEnd;
|
||||
r32 StartPosition = AnimationPanelWidth * StartTimePercent;
|
||||
s32 BlockStartFrame = AnimationBlockAt.StartTime / AnimationSystem->SecondsPerFrame;
|
||||
r32 StartFramePercent = (r32)(BlockStartFrame - StartFrame) / (r32)FrameCount;
|
||||
r32 StartPosition = AnimationPanelWidth * StartFramePercent;
|
||||
|
||||
r32 EndTimePercent = AnimationBlockAt.EndTime / AnimationSystem->AnimationEnd;
|
||||
r32 EndPosition = AnimationPanelWidth * EndTimePercent;
|
||||
s32 BlockEndFrame = AnimationBlockAt.EndTime / AnimationSystem->SecondsPerFrame;
|
||||
r32 EndFramePercent = (r32)(BlockEndFrame - StartFrame) / (r32)FrameCount;
|
||||
r32 EndPosition = AnimationPanelWidth * EndFramePercent;
|
||||
|
||||
v2 Min = PanelMin + v2{StartPosition, 25};
|
||||
v2 Max = PanelMin + v2{EndPosition, 75};
|
||||
v2 Min = TimelineMin + v2{StartPosition, 25};
|
||||
v2 Max = TimelineMin + v2{EndPosition, 75};
|
||||
|
||||
v4 BlockColor = BlackV4;
|
||||
if (AnimationBlockHandlesAreEqual(SelectedBlockHandle, CurrentBlockHandle))
|
||||
|
@ -74,13 +113,25 @@ Result = CurrentBlockHandle;
|
|||
}
|
||||
}
|
||||
|
||||
r32 TimePercent = AnimationSystem->Time / AnimationSystem->AnimationEnd;
|
||||
// Time Slider
|
||||
s32 SliderFrame = AnimationSystem->Time / AnimationSystem->SecondsPerFrame;
|
||||
r32 TimePercent = (r32)SliderFrame / (r32)EndFrame;
|
||||
r32 SliderX = PanelMin.x + (AnimationPanelWidth * TimePercent);
|
||||
v2 SliderMin = v2{SliderX, PanelMin.y};
|
||||
v2 SliderMax = v2{SliderX + 1, PanelMax.y - 25};
|
||||
PushRenderQuad2D(RenderBuffer, SliderMin, SliderMax, WhiteV4);
|
||||
v4 TimeSliderColor = v4{.36f, .52f, .78f, 1.f};
|
||||
|
||||
if (MouseDownAndNotHandled && PointIsInRange(Mouse.Pos, PanelMin, PanelMax))
|
||||
PushRenderQuad2D(RenderBuffer, SliderMin, SliderMax, TimeSliderColor);
|
||||
|
||||
r32 SliderHalfWidth = 10;
|
||||
v2 HeadMin = v2{SliderX - SliderHalfWidth, SliderMax.y};
|
||||
v2 HeadMax = v2{SliderX + SliderHalfWidth, SliderMax.y + FrameBarHeight};
|
||||
PushRenderQuad2D(RenderBuffer, HeadMin, HeadMax, TimeSliderColor);
|
||||
|
||||
PrintF(&TempString, "%d", SliderFrame);
|
||||
DrawString(RenderBuffer, TempString, State->Interface.Font, HeadMin + v2{4, 4}, WhiteV4);
|
||||
|
||||
if (MouseDownAndNotHandled && PointIsInRange(Mouse.Pos, TimelineMin, TimelineMax))
|
||||
{
|
||||
r32 MouseDownPositionPercent = (Mouse.Pos.x - PanelMin.x) / AnimationPanelWidth;
|
||||
r32 NewBlockTimeStart = MouseDownPositionPercent * AnimationSystem->AnimationEnd;
|
||||
|
@ -107,10 +158,12 @@ r32 OptionsRowHeight = 25;
|
|||
v2 TimelineMax = v2{PanelMax.x, PanelMax.y - OptionsRowHeight};
|
||||
if (TimelineMax.y - TimelineMin.y > 0)
|
||||
{
|
||||
s32 FrameEnd = (s32)(State->AnimationSystem.AnimationEnd / State->AnimationSystem.SecondsPerFrame);
|
||||
SelectedBlockHandle = DrawAnimationTimeline(&State->AnimationSystem,
|
||||
0, FrameEnd,
|
||||
TimelineMin, TimelineMax,
|
||||
SelectedBlockHandle,
|
||||
RenderBuffer, State->Interface, Mouse);
|
||||
RenderBuffer, State, Mouse);
|
||||
}
|
||||
|
||||
v2 OptionsRowMin = v2{ PanelMin.x, TimelineMax.y };
|
||||
|
|
|
@ -21,7 +21,7 @@ v4 LineBGColors[] = {
|
|||
v4 LineBGHoverColor = { .22f, .22f, .22f, 1.f };
|
||||
|
||||
r32 LineHeight = State->Interface.Font->PixelHeight + 8;
|
||||
v2 LineMin = v2{PanelMin.x + State->Interface.Margin.x, PanelMax.y - LineHeight};
|
||||
v2 LineMin = v2{PanelMin.x, PanelMax.y - LineHeight};
|
||||
v2 LineMax = LineMin + v2{PanelWidth, LineHeight};
|
||||
v2 TextOffset = v2{10, 4};
|
||||
string TempString = MakeString(PushArray(&State->Transient, char, 256), 256);
|
||||
|
|
Loading…
Reference in New Issue