summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFox Caminiti <fox@foxcam.net>2023-02-13 11:12:47 -0500
committerFox Caminiti <fox@foxcam.net>2023-02-13 11:12:47 -0500
commitfffb3474ee0321d73a47db01dbc4b6b19670ddc5 (patch)
treeaf4c14469a6a49c59785c426f149be43f3bd1147
parentbd25daeae033e4f905ae0145831a7d8fdd92e471 (diff)
drag and drop file loading
-rw-r--r--src/imgui_ui.cpp5
-rw-r--r--src/imgui_ui_timeline.cpp246
-rw-r--r--src/include/main.h2
-rw-r--r--src/main.cpp30
4 files changed, 156 insertions, 127 deletions
diff --git a/src/imgui_ui.cpp b/src/imgui_ui.cpp
index 62fcb2a..817fc1d 100644
--- a/src/imgui_ui.cpp
+++ b/src/imgui_ui.cpp
@@ -530,6 +530,7 @@ ImGui_ProcessInputs(project_data *File, project_state *State, ui *UI, memory *Me
}
}
} else if (State->FocusedWindow == focus_viewport) {
+ /*
if (ImGui::IsKeyPressed(ImGuiKey_S)) {
State->Interact_Offset[1] = SDL_GetPerformanceCounter();
State->Interact_Offset[2] = io.MousePos.x;
@@ -542,6 +543,7 @@ ImGui_ProcessInputs(project_data *File, project_state *State, ui *UI, memory *Me
State->Interact_Offset[3] = io.MousePos.y;
State->Interact_Active = interact_type_viewport_transform;
}
+ */
}
}
if (ImGui::IsKeyPressed(ImGuiKey_Escape)) {
@@ -672,6 +674,9 @@ ImGui_Menu(project_data *File, project_state *State, ui *UI, memory *Memory, ImG
{
if (ImGui::BeginMenu("File"))
{
+ if (ImGui::IsWindowFocused()) {
+ State->MenuFocused = 1;
+ }
if (ImGui::MenuItem("Save", "Ctrl+S"))
{
if (State->Filename[0] == '\0')
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);
diff --git a/src/include/main.h b/src/include/main.h
index 10604cb..ac1118d 100644
--- a/src/include/main.h
+++ b/src/include/main.h
@@ -490,6 +490,8 @@ struct project_state
uint32 CachedFrameCount;
int32 LastCachedFrame = -10000;
+ bool32 MenuFocused = 0;
+
uint64 HotFramePerf = 0;
uint32 AVCount;
diff --git a/src/main.cpp b/src/main.cpp
index 0bac544..3152156 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -78,12 +78,22 @@ Main_InputTest(project_data *File, project_state *State, memory *Memory, sorted_
ImGuiIO& io = ImGui::GetIO();
SDL_Event event = {};
int test = 0;
+ // printf("%i\n", State->MenuFocused);
while (SDL_PollEvent(&event))
{
ImGui_ImplSDL2_ProcessEvent(&event);
if (event.type == SDL_DROPFILE) {
char *DropFile = event.drop.file;
- Source_Generate(File, State, Memory, DropFile);
+ File_Open(File, State, Memory, DropFile);
+#if 0
+ if (State->MenuFocused) {
+ if (File_Open(File, State, Memory, DropFile)) {
+ State->UpdateFrame = true;
+ }
+ } else {
+ Source_Generate(File, State, Memory, DropFile);
+ }
+#endif
SDL_free(DropFile);
}
if (event.type == SDL_QUIT)
@@ -776,7 +786,7 @@ Render_Comp(project_data *File, project_state *State, memory *Memory, sorted_fil
Arbitrary_Zero((uint8 *)CompBuffer, Size);
- uint64 Comp_TimeStart = GetCPUTime();
+ // uint64 Comp_TimeStart = GetCPUTime();
for (int i = 0; i < SortedCompStart->LayerCount; i++) {
sorted_layer_array SortEntry = SortedLayerStart[i];
@@ -913,7 +923,7 @@ Render_Comp(project_data *File, project_state *State, memory *Memory, sorted_fil
}
}
- Entry_Main->CycleTime = GetCPUTime() - Comp_TimeStart;
+ // Entry_Main->CycleTime = GetCPUTime() - Comp_TimeStart;
Entry_Main->IsCached = true;
if (CompIndex == File->PrincipalCompIndex && State->LastCachedFrame != State->Frame_Current) {
@@ -1293,6 +1303,7 @@ int main(int argc, char *argv[]) {
while (State->IsRunning)
{
+ // uint64 StartTime = GetCPUTime();
uint64 PerfFrequency = SDL_GetPerformanceFrequency();
uint64 PerfStart = SDL_GetPerformanceCounter();
@@ -1378,12 +1389,14 @@ int main(int argc, char *argv[]) {
if (State->FirstFrame)
State->UpdateScreen = 2;
+ // State->UpdateScreen = 1;
+
// TODO(fox): Do the same thing with the timeline and viewport to
// reduce wasted rendering further; for now I am at least pausing all
// UI when no inputs happen.
- uint64 InputStart = SDL_GetPerformanceCounter();
+ // uint64 InputStart = GetCPUTime();
State->UpdateScreen += Main_InputTest(File, State, &Memory, Sorted, &File->UI, window, textureID);
- uint64 InputTime = SDL_GetPerformanceCounter() - InputStart;
+ // uint64 InputTime = GetCPUTime() - InputStart;
if (State->IsPlaying) {
block_composition *MainComp = (block_composition *)Memory_Block_AddressAtIndex(&Memory, F_Precomps, File->PrincipalCompIndex);
@@ -1484,7 +1497,7 @@ int main(int argc, char *argv[]) {
// frames, but we'd have to make sure the pop order stays the same in all scenarios.
Assert(Debug.ScratchState == 0);
- uint64 RenderStart = SDL_GetPerformanceCounter();
+ // uint64 RenderStart = GetCPUTime();
bool32 UpdateScreen = 0;
if (State->IsPlaying && State->HotFramePerf > 1 && FullyCached) {
uint64 RenderTime = SDL_GetPerformanceCounter() - State->HotFramePerf;
@@ -1501,7 +1514,7 @@ int main(int argc, char *argv[]) {
UpdateScreen = 1;
}
}
- uint64 RenderTime = SDL_GetPerformanceCounter() - RenderStart;
+ // uint64 RenderTime = GetCPUTime() - RenderStart;
if (State->HotFramePerf == 1) {
State->HotFramePerf = SDL_GetPerformanceCounter();
@@ -1522,7 +1535,10 @@ int main(int argc, char *argv[]) {
if (TargetMS > FrameMS)
SDL_Delay((uint64)(TargetMS - FrameMS));
}
+
+ // uint64 TotalTime = GetCPUTime() - StartTime;
// printf("TOTAL: %.2lu, (%.2f ms) - INPUTS: %.2lu - RENDERING: %.2lu\n", PerfTime, FrameMS, InputTime, RenderTime);
+ // printf("TOTAL: %.2lu - INPUTS: %.2lu (%.2f) - RENDERING: %.2lu (%.2f)\n", TotalTime, InputTime, (real64)InputTime / TotalTime, RenderTime, (real64)RenderTime / TotalTime);
// printf("TOTAL: %.2lu, (%.2f ms) - RENDERING: %.2lu\n", PerfTime, FrameMS, PerfTime);
}