From 09c6cb9e3be2655b842e13dd68879cb10cf52acf Mon Sep 17 00:00:00 2001 From: Fox Caminiti Date: Mon, 21 Nov 2022 13:56:37 -0500 Subject: things --- my_imgui_widgets.cpp | 395 +++++++++++++++++---------------------------------- 1 file changed, 130 insertions(+), 265 deletions(-) (limited to 'my_imgui_widgets.cpp') diff --git a/my_imgui_widgets.cpp b/my_imgui_widgets.cpp index b3339d2..0b1e017 100644 --- a/my_imgui_widgets.cpp +++ b/my_imgui_widgets.cpp @@ -236,10 +236,53 @@ ImGui_File(project_data *File, project_state *State, memory *Memory, ImGuiIO io, ImGui::End(); } +#if SD static void -ImGui_SD_Thumbnail(project_data *File, project_state *State, ui *UI, memory *Memory, ImGuiIO io) +ImGui_SD_Thumbnail(project_data *File, project_state *State, ui *UI, memory *Memory, ImGuiIO io, uint16 *SourceArray, uint16 SourceCount, GLuint textureID) { ImGui::Begin("SD gallery"); + ImDrawList* draw_list = ImGui::GetWindowDrawList(); + ImVec2 ViewportMin = ImGui::GetCursorScreenPos(); + ImVec2 ViewportScale = ImGui::GetContentRegionAvail(); + ImVec2 ViewportMax = ImVec2(ViewportMin.x + ViewportScale.x, ViewportMin.y + ViewportScale.y); + if (!SourceCount) { + ImGui::End(); + return; + } + int test[16]; + int count = 0; + // draw_list->AddImage((void *)(intptr_t)textureID, ViewportMin, ViewportMax); + uint32 T_Height = 256; + real32 RowPercent = (real32)ViewportScale.x / T_Height; + uint32 PerRow = (uint32)RowPercent; + uint32 UI_Size = T_Height; + for (int i = 0; i < SourceCount; i++) { + int32 Y = i / PerRow; + int32 X = i % PerRow; + ImVec2 ImgMin = ViewportMin + ImVec2(X * UI_Size, Y * UI_Size); + ImVec2 ImgMax = ImgMin + ImVec2(UI_Size, UI_Size); + block_source *Source = (block_source *)Memory_Block_AddressAtIndex(Memory, F_Sources, SourceArray[i]); + // ImGui::Text("Count: %i", Source->RelativeTimestamp); + real32 Ratio = (real32)Source->Width / Source->Height; + uint32 T_Width = (uint32)(Ratio * T_Height); + if (Source->ThumbnailTex == 0) { + Source_DumpThumbnail(Memory, Source, T_Width, T_Height); + } + // draw_list->AddRect(ImgMin, ImgMax, IM_COL32(255, 255, 255, 64)); + ImGui::SetCursorScreenPos(ImgMin); + ImGui::Button("asda", ImVec2(UI_Size, UI_Size)); + draw_list->AddImage((void *)(intptr_t)Source->ThumbnailTex, ImgMin, ImgMax); + + // block_string *String = (block_string *)Memory_Block_AddressAtIndex(Memory, F_Strings, Source->Path_String_Index); + // ImGui::Selectable(String->Char, Source->IsSelected); + // if (ImGui::IsItemClicked() || ImGui::IsItemClicked(ImGuiMouseButton_Right)) { + // if (!io.KeyShift && !Source->IsSelected) { + // Source_DeselectAll(File, Memory); + // } + // Source->IsSelected = 1; + // } + // ImGui::OpenPopupOnItemClick("sourcecontext", ImGuiPopupFlags_MouseButtonRight); + } ImGui::End(); } @@ -265,18 +308,18 @@ ImGui_SD_Prompt(project_data *File, project_state *State, ui *UI, memory *Memory Source->Width, Source->Height, Source->BytesPerPixel, &len); Assert(PNGBitmap); - uint64 EncodedLength = 0; - uint64 EncodedAllocSize = base64_encode_size(Size); - uint8 *EncodedOutput = (uint8 *)Memory_PushScratch(Memory, EncodedAllocSize); - uint64 EncodedTrueSize; + uint64 EncodedEstimateSize = base64_encode_size(Size); + uint8 *EncodedOutput = (uint8 *)Memory_PushScratch(Memory, EncodedEstimateSize); + uint64 EncodedTrueSize = 0; - base64_encode((uint8 *)BitmapAddress, Size, EncodedOutput, &EncodedTrueSize); + base64_encode((uint8 *)PNGBitmap, len, EncodedOutput, &EncodedTrueSize); Assert(EncodedOutput[EncodedTrueSize] == '\0'); + // printf("%s", EncodedOutput); STBIW_FREE(PNGBitmap); - SD_AssembleJSON(SD, (char *)State->Dump1, EncodedOutput); - Memory_PopScratch(Memory, EncodedAllocSize); + SD_AssembleJSON(SD, (char *)State->JSONPayload, EncodedOutput); + Memory_PopScratch(Memory, EncodedEstimateSize); } else { SD_AssembleJSON(SD, State->JSONPayload); // SD_AssembleJSON(SD, (char *)State->Dump2); @@ -317,6 +360,7 @@ ImGui_SD_Prompt(project_data *File, project_state *State, ui *UI, memory *Memory ImGui::InputInt("Seed", &SD->Seed); ImGui::End(); } +#endif static void ImGui_ColorPanel(project_data *File, project_state *State, ui *UI, memory *Memory, ImGuiIO io) @@ -833,7 +877,6 @@ ImGui_Viewport(project_data *File, project_state *State, ui *UI, memory *Memory, block_composition *MainComp = (block_composition *)Memory_Block_AddressAtIndex(Memory, F_Precomps, File->PrincipalCompIndex); - ImVec2 ViewportMin = ImGui::GetCursorScreenPos(); ImVec2 ViewportScale = ImGui::GetContentRegionAvail(); ImVec2 ViewportMax = ImVec2(ViewportMin.x + ViewportScale.x, ViewportMin.y + ViewportScale.y); @@ -874,14 +917,15 @@ ImGui_Viewport(project_data *File, project_state *State, ui *UI, memory *Memory, ImGui::InvisibleButton("canvas", ViewportScale, ImGuiButtonFlags_MouseButtonLeft | ImGuiButtonFlags_MouseButtonRight); bool32 IsHovered = ImGui::IsItemHovered(); -#if 1 +#if 0 bool32 IsActive = ImGui::IsItemActive(); bool32 IsActivated = ImGui::IsItemActivated(); + bool32 IsDeactivated = ImGui::IsItemDeactivated(); #else bool32 IsActive = ImGui::IsKeyDown(ImGuiKey_3); bool32 IsActivated = ImGui::IsKeyPressed(ImGuiKey_3); + bool32 IsDeactivated = ImGui::IsKeyReleased(ImGuiKey_3); #endif - bool32 IsDeactivated = ImGui::IsItemDeactivated(); if (IsHovered && IsActivated && !ImGui::IsMouseDown(ImGuiMouseButton_Right)) { @@ -891,14 +935,17 @@ ImGui_Viewport(project_data *File, project_state *State, ui *UI, memory *Memory, if (State->Tool == tool_brush) { sorted_layer *SortedLayerInfo = Layer_GetSortedArray(SortedLayerArray, SortedCompArray, File->PrincipalCompIndex); sorted_comp_info SortedCompInfo = SortedCompArray[File->PrincipalCompIndex]; - for (int i = SortedCompInfo.LayerCount - 1; i >= 0; i--) { - sorted_layer SortEntry = SortedLayerInfo[i]; - uint32 Index_Physical = SortEntry.Block_Layer_Index; - block_layer *Layer = (block_layer *)Memory_Block_AddressAtIndex(Memory, F_Layers, Index_Physical); - block_source *Source = (block_source *)Memory_Block_AddressAtIndex(Memory, F_Sources, Layer->Block_Source_Index); - if (Layer->IsSelected && Source->Type == source_type_principal) { - State->Interact_Active = interact_type_brush; - State->Brush.LayerToPaint_Index = Layer->Block_Source_Index; + if (!io.KeyCtrl) { + for (int i = SortedCompInfo.LayerCount - 1; i >= 0; i--) { + sorted_layer SortEntry = SortedLayerInfo[i]; + uint32 Index_Physical = SortEntry.Block_Layer_Index; + block_layer *Layer = (block_layer *)Memory_Block_AddressAtIndex(Memory, F_Layers, Index_Physical); + block_source *Source = (block_source *)Memory_Block_AddressAtIndex(Memory, F_Sources, Layer->Block_Source_Index); + if (Layer->IsSelected && Source->Type == source_type_principal) { + State->Interact_Active = interact_type_brush; + State->Brush.LayerToPaint_Index = Index_Physical; + break; + } } } if (State->Brush.LayerToPaint_Index == -1) { @@ -963,7 +1010,7 @@ ImGui_Viewport(project_data *File, project_state *State, ui *UI, memory *Memory, block_layer *Layer = (block_layer *)Memory_Block_AddressAtIndex(Memory, F_Layers, State->Brush.LayerToPaint_Index); layer_transforms T_Layer = Layer_GetTransforms(Layer); block_source *Source = (block_source *)Memory_Block_AddressAtIndex(Memory, F_Sources, Layer->Block_Source_Index); - void *SourceBitmapAddress = Memory_Block_AddressAtIndex(Memory, F_PrincipalBitmaps, Source->Bitmap_Index); + void *SourceBitmapAddress = Memory_Block_AddressAtIndex(Memory, F_PrincipalBitmaps, Source->Bitmap_Index, 0); ImVec2 MouseDelta = io.MouseDelta; real32 Delta = MouseDelta.x + MouseDelta.y; if (Delta != 0.0f) { @@ -971,11 +1018,11 @@ ImGui_Viewport(project_data *File, project_state *State, ui *UI, memory *Memory, real32 DeltaSlope = MouseDelta.y / MouseDelta.x; for (real32 i = 0; i < DeltaDistance; i += State->Brush.Spacing) { ImVec2 MousePos = ImGui_Brush_CalcMousePos(State, io, MouseDelta, i, DeltaDistance, DeltaSlope); - Brush_Render(State, UI, T_Layer, MainComp, Source, SourceBitmapAddress, ViewportMin, MousePos); + Brush_Render(State, UI, T_Layer, MainComp, Source, State->Brush.TransientBitmap, ViewportMin, MousePos); } } else if (IsActivated) { ImVec2 MousePos = io.MousePos; - Brush_Render(State, UI, T_Layer, MainComp, Source, SourceBitmapAddress, ViewportMin, MousePos); + Brush_Render(State, UI, T_Layer, MainComp, Source, State->Brush.TransientBitmap, ViewportMin, MousePos); } // Memory_Cache_Invalidate(State, Memory, cache_entry_type_comp, Layer->Block_Composition_Index, 0); State->UpdateFrame = true; @@ -1974,16 +2021,19 @@ ImGui_ProcessInputs(project_data *File, project_state *State, ui *UI, memory *Me State->UpdateFrame = true; } if (ImGui::IsKeyPressed(ImGuiKey_E)) { - block_composition *MainComp = (block_composition *)Memory_Block_AddressAtIndex(Memory, F_Precomps, File->PrincipalCompIndex); - State->Frame_Current = ((State->Frame_Current + 1) >= MainComp->Frame_Count) ? 0 : State->Frame_Current + 1; - State->UpdateFrame = true; + if (!io.KeyShift) { + block_composition *MainComp = (block_composition *)Memory_Block_AddressAtIndex(Memory, F_Precomps, File->PrincipalCompIndex); + State->Frame_Current = ((State->Frame_Current + 1) >= MainComp->Frame_Count) ? 0 : State->Frame_Current + 1; + State->UpdateFrame = true; + } else { + State->Brush.EraseMode ^= 1; + } } if (ImGui::IsKeyPressed(ImGuiKey_X)) { v4 Temp = UI->Color; UI->Color = UI->AltColor; UI->AltColor = Temp; } - if (ImGui::IsKeyPressed(ImGuiKey_V)) { State->Tool = tool_default; } @@ -1995,19 +2045,43 @@ ImGui_ProcessInputs(project_data *File, project_state *State, ui *UI, memory *Me UI->GraphZoomSize = ImVec2(0, 0); UI->GraphMoveSize = ImVec2(0, 0); } - if (UI->TimelineMode == timeline_mode_graph) { - if (ImGui::IsKeyPressed(ImGuiKey_G)) { - State->Interact_Offset[2] = io.MousePos.x; - State->Interact_Offset[3] = io.MousePos.y; - State->Interact_Active = interact_type_keyframe_move; - } else if (ImGui::IsKeyPressed(ImGuiKey_R)) { - // State->Interact_Offset[2] = io.MousePos.x; - // State->Interact_Offset[3] = io.MousePos.y; - // State->Interact_Active = interact_type_keyframe_rotate; - } else if (ImGui::IsKeyPressed(ImGuiKey_S)) { - State->Interact_Offset[2] = io.MousePos.x; - State->Interact_Offset[3] = io.MousePos.y; - State->Interact_Active = interact_type_keyframe_scale; + if (UI->FocusedWindow == focus_timeline) { + if (UI->TimelineMode == timeline_mode_default) { + if (ImGui::IsKeyPressed(ImGuiKey_G)) { + Layer_ToggleChannel(File, Memory, 0); + Layer_ToggleChannel(File, Memory, 1); + } else if (ImGui::IsKeyPressed(ImGuiKey_A)) { + Layer_ToggleChannel(File, Memory, 2); + Layer_ToggleChannel(File, Memory, 3); + } else if (ImGui::IsKeyPressed(ImGuiKey_R)) { + Layer_ToggleChannel(File, Memory, 4); + } else if (ImGui::IsKeyPressed(ImGuiKey_S)) { + Layer_ToggleChannel(File, Memory, 5); + } else if (ImGui::IsKeyPressed(ImGuiKey_T)) { + if (io.KeyShift) { + Layer_ToggleChannel(File, Memory, 6); + } else { + Layer_ToggleChannel(File, Memory, 7); + } + } + } else if (UI->TimelineMode == timeline_mode_graph) { + if (ImGui::IsKeyPressed(ImGuiKey_G)) { + State->Interact_Offset[2] = io.MousePos.x; + State->Interact_Offset[3] = io.MousePos.y; + State->Interact_Active = interact_type_keyframe_move; + } else if (ImGui::IsKeyPressed(ImGuiKey_R)) { + // State->Interact_Offset[2] = io.MousePos.x; + // State->Interact_Offset[3] = io.MousePos.y; + // State->Interact_Active = interact_type_keyframe_rotate; + } else if (ImGui::IsKeyPressed(ImGuiKey_S)) { + State->Interact_Offset[2] = io.MousePos.x; + State->Interact_Offset[3] = io.MousePos.y; + State->Interact_Active = interact_type_keyframe_scale; + } + } + } else if (UI->FocusedWindow == focus_viewport) { + if (ImGui::IsKeyPressed(ImGuiKey_T)) { + State->HotkeyInput = hotkey_transform; } } if (ImGui::IsKeyPressed(ImGuiKey_Escape)) { @@ -2066,6 +2140,23 @@ ImGui_ProcessInputs(project_data *File, project_state *State, ui *UI, memory *Me bool32 mod_key = io.ConfigMacOSXBehaviors ? io.KeySuper : io.KeyCtrl; if (mod_key) { + if (ImGui::IsKeyPressed(ImGuiKey_C)) { + State->HotkeyInput = hotkey_copy; + } + if (ImGui::IsKeyPressed(ImGuiKey_V)) { + State->HotkeyInput = hotkey_paste; + } + if (ImGui::IsKeyPressed(ImGuiKey_Z)) { + if (io.KeyShift) { + History_Redo(Memory); + State->UpdateFrame = true; + } else { + History_Undo(Memory); + State->UpdateFrame = true; + } + } + } + /* if (ImGui::IsKeyPressed(ImGuiKey_S)) { if (io.KeyShift) { @@ -2089,16 +2180,6 @@ ImGui_ProcessInputs(project_data *File, project_state *State, ui *UI, memory *Me State->ImGuiPopups = popup_newlayer; } */ - if (ImGui::IsKeyPressed(ImGuiKey_Z)) { - if (io.KeyShift) { - History_Redo(Memory); - State->UpdateFrame = true; - } else { - History_Undo(Memory); - State->UpdateFrame = true; - } - } - } } @@ -3562,222 +3643,6 @@ ImGui_EffectsPanel(project_data *File, project_state *State, memory *Memory, ui -static void -ImGui_ProcessInputs(project_data *File, project_state *State, comp_buffer *CompBuffer, memory *Memory, ui *UI, ImGuiIO io) -{ - if (io.KeysData[ImGuiKey_Q].Down) { - State->IsRunning = false; - } -#if DEBUG - // 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 = -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)) { - IncrementFrame(File, -1); - State->UpdateFrame = true; - State->UpdateKeyframes = true; - } - - if (ImGui::IsKeyPressed(ImGuiKey_F)) { - IncrementFrame(File, 1); - State->UpdateFrame = true; - State->UpdateKeyframes = true; - } - - if (ImGui::IsKeyPressed(ImGuiKey_Z)) { - if (io.KeyCtrl && io.KeyShift) { - History_Redo(Memory); - } else if (io.KeyCtrl) { - History_Undo(Memory); - } - State->UpdateFrame = true; - State->UpdateKeyframes = true; - } - - if (ImGui::IsKeyPressed(ImGuiKey_V)) { - if (State->Tool == tool_pen) { - State->Tool = tool_default; - } else { - State->Tool = tool_pen; - } - } - - if (ImGui::IsKeyPressed(ImGuiKey_Space)) { - if (io.KeyShift) { - State->RerouteEffects = true; - } else { - State->IsPlaying ^= 1; - } - } - - - if (State->IsPlaying && !IsRendering) { - IncrementFrame(File, 1); - State->UpdateFrame = true; - State->UpdateKeyframes = true; - } - - // if (ImGui::IsKeyPressed(ImGuiKey_R) && State->NumberOfSelectedLayers) - // TransformsInteract(File, State, Memory, UI, sliding_rotation); - if (ImGui::IsKeyPressed(ImGuiKey_S) && State->NumberOfSelectedLayers) - TransformsInteract(File, State, Memory, UI, sliding_scale); - if (ImGui::IsKeyPressed(ImGuiKey_G) && State->NumberOfSelectedLayers) - TransformsInteract(File, State, Memory, UI, sliding_position); - if (ImGui::IsKeyPressed(ImGuiKey_A) && State->NumberOfSelectedLayers) - TransformsInteract(File, State, Memory, UI, sliding_anchorpoint); - - if (ImGui::IsKeyPressed(ImGuiKey_1)) - LoadTestFootage(File, State, Memory); - - if (ImGui::IsKeyPressed(ImGuiKey_D) && io.KeyCtrl) - { - } - - if (ImGui::IsKeyPressed(ImGuiKey_Delete)) - { - switch (State->RecentSelectionType) - { - case selection_none: - { - } break; - case selection_layer: - { - } break; - case selection_effect: - { - } break; - case selection_keyframe: - { - DeleteSelectedKeyframes(File, Memory); - State->UpdateKeyframes = true; - State->UpdateFrame = true; - } - case selection_maskpoint: - { - } - case selection_source: - { - } - break; - } - } - - if (State->IsInteracting) { - ImVec2 MouseIncrement = io.MouseDelta * (ImVec2(CompBuffer->Width, CompBuffer->Height) / UI->CompZoom); - project_layer *Layer = File->Layer[State->MostRecentlySelectedLayer]; - switch (State->TransformsHotkeyInteract) - { - case sliding_position: - { - Layer->x.CurrentValue.f += MouseIncrement.x; - Layer->y.CurrentValue.f += MouseIncrement.y; - } break; - case sliding_anchorpoint: - { - source *Source = Layer->Source; - Layer->x.CurrentValue.f += MouseIncrement.x; - Layer->y.CurrentValue.f += MouseIncrement.y; - Layer_CalcRotatedOffset(Layer, V2(MouseIncrement), V2(Source->Info.Width, Source->Info.Height), - &Layer->ax.CurrentValue.f, &Layer->ay.CurrentValue.f); - } break; - case sliding_rotation: - { - Layer->rotation.CurrentValue.f += MouseIncrement.x / 10.0; - } break; - case sliding_scale: - { - Layer->scale.CurrentValue.f += MouseIncrement.x / 200.0; - } break; - } - if (ImGui::IsKeyPressed(ImGuiKey_Escape)) { - switch (State->TransformsHotkeyInteract) - { - case sliding_position: - { - Layer->x.CurrentValue.f = State->InteractCache[0]; - Layer->y.CurrentValue.f = State->InteractCache[1]; - } break; - case sliding_anchorpoint: - { - Layer->x.CurrentValue.f = State->InteractCache[0]; - Layer->y.CurrentValue.f = State->InteractCache[1]; - Layer->ax.CurrentValue.f = State->InteractCache[2]; - Layer->ay.CurrentValue.f = State->InteractCache[3]; - } break; - case sliding_rotation: - { - Layer->rotation.CurrentValue.f = State->InteractCache[0]; - } break; - case sliding_scale: - { - Layer->scale.CurrentValue.f = State->InteractCache[0]; - } break; - } - State->IsInteracting = false; - State->UpdateFrame = true; - } - if (ImGui::IsMouseDown(ImGuiMouseButton_Left)) { - History_Entry_Commit(Memory, action_entry_default, "Tranforms interact"); - switch (State->TransformsHotkeyInteract) - { - case sliding_position: - { - History_Action_Change(Memory, &Layer->x.CurrentValue.f, &State->InteractCache[0], - &Layer->x.CurrentValue.f, action_type_change_r32); - History_Action_Change(Memory, &Layer->y.CurrentValue.f, &State->InteractCache[1], - &Layer->y.CurrentValue.f, action_type_change_r32); - } break; - case sliding_anchorpoint: - { - History_Action_Change(Memory, &Layer->x.CurrentValue.f, &State->InteractCache[0], - &Layer->x.CurrentValue.f, action_type_change_r32); - History_Action_Change(Memory, &Layer->y.CurrentValue.f, &State->InteractCache[1], - &Layer->y.CurrentValue.f, action_type_change_r32); - History_Action_Change(Memory, &Layer->ax.CurrentValue.f, &State->InteractCache[2], - &Layer->ax.CurrentValue.f, action_type_change_r32); - History_Action_Change(Memory, &Layer->ay.CurrentValue.f, &State->InteractCache[3], - &Layer->ay.CurrentValue.f, action_type_change_r32); - } break; - case sliding_rotation: - { - History_Action_Change(Memory, &Layer->rotation.CurrentValue.f, &State->InteractCache[0], - &Layer->rotation.CurrentValue.f, action_type_change_r32); - } break; - case sliding_scale: - { - History_Action_Change(Memory, &Layer->scale.CurrentValue.f, &State->InteractCache[0], - &Layer->scale.CurrentValue.f, action_type_change_r32); - } break; - } - History_Entry_End(Memory); - State->IsInteracting = false; - } - State->UpdateFrame = true; - } - - if (!ImGui::IsMouseDown(ImGuiMouseButton_Left)) { - UI->DraggingLayerThreshold = 0; - UI->DraggingTimelineThreshold = 0; - UI->DraggingKeyframeThreshold = 0; - } -} - static char ImGuiPrefs[] = "[Window][DockSpaceViewport_11111111]" "\nPos=0,0" "\nSize=3200,1800" -- cgit v1.2.3