From e89dc91182a94e48ca9220a2fe075db680ddff04 Mon Sep 17 00:00:00 2001 From: Fox Caminiti Date: Tue, 16 Aug 2022 15:06:45 -0400 Subject: undo functional --- createcalls.cpp | 130 +++++++++++++++++++++++++++++++++----------------------- 1 file changed, 77 insertions(+), 53 deletions(-) (limited to 'createcalls.cpp') diff --git a/createcalls.cpp b/createcalls.cpp index 4564d59..f2a173f 100644 --- a/createcalls.cpp +++ b/createcalls.cpp @@ -31,9 +31,11 @@ Source_Generate(project_data *File, memory *Memory, void *Path) } if (Found) { - Action_Change_Commit(Memory, &Source->Path, &Path, action_change_ptr); + Action_Entry_Begin(Memory, action_entry_default, "Add source"); + Action_Change_Commit(Memory, &Source->Path, &Source->Path, &Path, action_change_ptr); uint32 i = File->NumberOfSources + 1; - Action_Change_Commit(Memory, &File->NumberOfSources, &i, action_change_u16); + Action_Change_Commit(Memory, &File->NumberOfSources, &File->NumberOfSources, &i, action_change_u16); + Action_Entry_End(Memory); return 1; } else { // PostMsg(State, "File open fail..."); @@ -132,29 +134,44 @@ void * Layer_AllocateBitmap(memory *Memory, uint16 Width, uint16 Height, uint16 project_layer * Layer_Init(project_data *File, memory *Memory) { - int16 a = File->NumberOfLayers++; - Assert(a < MAX_LAYERS); - - File->Layer[a] = (project_layer *)AllocateMemory(Memory, sizeof(project_layer), F_Layers); - - File->Layer[a]->Name = (char *)AllocateMemory(Memory, STRING_SIZE, F_Strings); - sprintf(File->Layer[a]->Name, "Layer %i", a); - File->Layer[a]->x = InitFloatProperty("X Position", 0.0f, 1.0f); - File->Layer[a]->y = InitFloatProperty("Y Position", 0.0f, 1.0f); - File->Layer[a]->ax = InitFloatProperty("Anchor X", 0.5f, 0.005f); - File->Layer[a]->ay = InitFloatProperty("Anchor Y", 0.5f, 0.005f); - File->Layer[a]->scale = InitFloatProperty("Scale", 1.0f, 0.005f); - File->Layer[a]->rotation = InitFloatProperty("Rotation", 0.0f, 1.0f); - File->Layer[a]->opacity = InitFloatProperty("Opacity", 1.0f, 0.005f, 0.0f, 1.0f); - File->Layer[a]->time = InitFloatProperty("Frame Number", 0.0f, 1.0f, 0, 100000); - File->Layer[a]->EndFrame = File->NumberOfFrames; - - return File->Layer[a]; + int16 Index = File->NumberOfLayers; + int16 NextIndex = File->NumberOfLayers + 1; + + // NOTE(fox): We don't have to record any values that get set here aside + // from this index in the Action tree since all we need to do to "delete" + // the layer is to unset this. The layer that gets made here is always at + // the top of the index. + Action_Entry_Begin(Memory, action_entry_layerinit, "Create layer"); + Action_Change_Commit(Memory, &File->NumberOfLayers, &Index, &NextIndex, action_change_u16); + + File->Layer[Index] = (project_layer *)AllocateMemory(Memory, sizeof(project_layer), F_Layers); + + project_layer *Layer = File->Layer[Index]; + + Action_Entry_SetPointer(Memory, &Layer->BitmapInfo.AVInfo); + + Action_Entry_End(Memory); + + Layer->Name = (char *)AllocateMemory(Memory, STRING_SIZE, F_Strings); + sprintf(Layer->Name, "Layer %i", NextIndex); // CSbros... + Layer->x = InitFloatProperty("X Position", 0.0f, 1.0f); + Layer->y = InitFloatProperty("Y Position", 0.0f, 1.0f); + Layer->ax = InitFloatProperty("Anchor X", 0.5f, 0.005f); + Layer->ay = InitFloatProperty("Anchor Y", 0.5f, 0.005f); + Layer->scale = InitFloatProperty("Scale", 1.0f, 0.005f); + Layer->rotation = InitFloatProperty("Rotation", 0.0f, 1.0f); + Layer->opacity = InitFloatProperty("Opacity", 1.0f, 0.005f, 0.0f, 1.0f); + Layer->time = InitFloatProperty("Frame Number", 0.0f, 1.0f, 0, 100000); + Layer->EndFrame = File->NumberOfFrames; + + return Layer; } static cached_bitmap * Cache_CheckBitmap(source *Source, layer_bitmap_info *BitmapInfo, memory *Memory, int32 TimelineFrame) { + if (!Source || !BitmapInfo) + return 0; memory_table *Table = &Memory->Slot[B_LoadedBitmaps]; int32 FrameToSeek = TimelineFrame - BitmapInfo->FrameOffset; // Stills have a frame index of zero. @@ -293,11 +310,47 @@ Mask_TriangulateAndRasterize(memory *Memory, project_layer *Layer, mask *Mask) glBindFramebuffer(GL_FRAMEBUFFER, 0); } +static void +Layer_InitSource(project_layer *Layer, source *Source, memory *Memory) +{ + uint16 Width = Source->Info.Width; + uint16 Height = Source->Info.Height; + uint16 BytesPerPixel = Source->Info.BytesPerPixel; + Layer->BitmapInfo.BitmapBuffer = Layer_AllocateBitmap(Memory, Width, Height, BytesPerPixel); +} + +static void +Layer_PositionCenter(project_layer *Layer, uint16 Width, uint16 Height) { + Layer->x.CurrentValue.f = Width/2; + Layer->y.CurrentValue.f = Height/2; +} + +static void +Layer_CreateFromSource(project_data *File, project_state *State, memory *Memory, source *Source) +{ + if (File->NumberOfLayers + 1 > MAX_LAYERS) { + // TODO(fox): Output! + } + project_layer *Layer = Layer_Init(File, Memory); + Layer->Source = Source; + State->UpdateFrame = true; +} + static void -Layer_UpdateBitmap(project_layer *Layer, memory *Memory, int32 CurrentFrame) { +Layer_UpdateBitmap(project_data *File, project_layer *Layer, memory *Memory, int32 CurrentFrame) { source *Source = Layer->Source; layer_bitmap_info *BitmapInfo = &Layer->BitmapInfo; + + // AVInfo is created here instead of on layer creation so we can save + // having to keep some state in the undo/delete commands. + if (!BitmapInfo->AVInfo) { + BitmapInfo->AVInfo = AllocateMemory(Memory, sizeof(av_info), P_AVInfo); + AV_Init(Source, (av_info *)BitmapInfo->AVInfo, Memory); + Layer_InitSource(Layer, Source, Memory); + Layer_PositionCenter(Layer, File->Width, File->Height); + } + cached_bitmap *Bitmap = Cache_CheckBitmap(Source, BitmapInfo, Memory, CurrentFrame); if (!Bitmap) { if (Source->SourceType == source_type_image) { @@ -332,32 +385,6 @@ Layer_UpdateBitmap(project_layer *Layer, memory *Memory, int32 CurrentFrame) { Bitmap_CopyToPointer(Memory->Scratch, DestBuffer, BytesPerPixel, PackedSize); } -static void -Layer_InitSource(project_layer *Layer, source *Source, memory *Memory) -{ - Layer->Source = Source; - uint16 Width = Source->Info.Width; - uint16 Height = Source->Info.Height; - uint16 BytesPerPixel = Source->Info.BytesPerPixel; - Layer->BitmapInfo.BitmapBuffer = Layer_AllocateBitmap(Memory, Width, Height, BytesPerPixel); -} - -static void -Layer_PositionCenter(project_layer *Layer, uint16 Width, uint16 Height) { - Layer->x.CurrentValue.f = Width/2; - Layer->y.CurrentValue.f = Height/2; -} - -static void -Layer_CreateFromSource(project_data *File, project_state *State, memory *Memory, source *Source) -{ - project_layer *Layer = Layer_Init(File, Memory); - AV_Init(Source, &Layer->BitmapInfo, Memory); - Layer_InitSource(Layer, Source, Memory); - Layer_PositionCenter(Layer, File->Width, File->Height); - State->UpdateFrame = true; -} - static ImVec2 Layer_LocalToScreenSpace(project_layer *Layer, ui *UI, comp_buffer CompBuffer, v2 Point) { @@ -392,13 +419,10 @@ LoadTestFootage(project_data *File, project_state *State, memory *Memory) { void *SourceString = String_GenerateFromChar(Memory, "../asset/24.mp4"); Source_Generate(File, Memory, SourceString); - Layer_CreateFromSource(File, State, Memory, Source); - Action_Undo(Memory); - Action_Undo(Memory); - Action_Redo(Memory); - Action_Redo(Memory); - Assert(0); source *Source = &File->Source[0]; + Layer_CreateFromSource(File, State, Memory, Source); + // Action_Undo(Memory); + // Action_Redo(Memory); SelectLayer(File->Layer[0], State, 0); // AddEffect(File->Layer[0], Memory, 3); -- cgit v1.2.3