diff options
Diffstat (limited to 'my_imgui_widgets.cpp')
-rw-r--r-- | my_imgui_widgets.cpp | 194 |
1 files changed, 70 insertions, 124 deletions
diff --git a/my_imgui_widgets.cpp b/my_imgui_widgets.cpp index 36bc79e..f267f67 100644 --- a/my_imgui_widgets.cpp +++ b/my_imgui_widgets.cpp @@ -578,9 +578,22 @@ ImGui_DebugMemoryViewer(memory *Memory, project_state *State) } static void +ImGui_DebugRenderQueue(project_state *State) +{ + ImGui::Begin("debug_queue"); + for (int i = 0; i < State->Queue.CurrentIdx; i++) { + v2 Pos = State->Queue.Item[i].Pos; + char size[20]; + sprintf(size, "Type %i: %.2f, %.2f", State->Queue.Item[i].Type, Pos.x, Pos.y); + ImGui::MenuItem(size, NULL, (i == State->Queue.Playhead)); + } + ImGui::End(); +} + +static void ImGui_DebugUndoTree(memory *Memory, project_state *State) { - ImGui::Begin("undotree"); + ImGui::Begin("debug_undotree"); for (int i = 0; i < Memory->History.NumberOfEntries; i++) { history_entry Entry = Memory->History.Entry[i]; bool32 CurrentPos = (i < Memory->History.EntryPlayhead); @@ -666,8 +679,7 @@ ImGui_File(project_data *File, project_state *State, memory *Memory, ImGuiIO io, if (ImGui::BeginPopup("sourcecontext")) { if (ImGui::MenuItem("Create layer from source")) { - Source_UICreateButton(File, State, Memory, SortedCompArray, SortedLayerArray); - State->UpdateKeyframes = true; + State->HotkeyInput = hotkey_newlayerfromsource; } ImGui::EndPopup(); } @@ -761,8 +773,7 @@ ImGui_SD_Thumbnail(project_data *File, project_state *State, ui *UI, memory *Mem } if (ImGui::BeginPopup("temptosource")) { if (ImGui::MenuItem("Create layer from source")) { - Source_UICreateButton(File, State, Memory, SortedCompArray, SortedLayerArray); - State->UpdateKeyframes = true; + State->HotkeyInput = hotkey_newlayerfromsource; } ImGui::EndPopup(); } @@ -990,6 +1001,12 @@ ImGui_RenderUIBrush(project_state *State, memory *Memory, ImVec2 ViewportMin, Im ImVec2 MinBounds = State->Brush.UIPos - BrushSize/2; ImVec2 MaxBounds = MinBounds + BrushSize; + // if (io.KeyCtrl) { + // ImGui::SetCursorScreenPos(State->Brush.UIPos); + // char buf[256]; + // sprintf(buf, "RGBA: %.1f, %.1f, %.1f, %.1f", State->Brush.Size, State->Brush.Hardness); + // } + if (io.KeyAlt) { draw_list->PushClipRect(ViewportMin, ViewportMax, true); draw_list->AddImage((void *)(intptr_t)State->Brush.GLTexture, MinBounds, MaxBounds, ImVec2(0, 0), ImVec2(1, 1), 1); @@ -1354,42 +1371,16 @@ ImGui_LayerViewportUI(project_state *State, memory *Memory, ui *UI, ImDrawList * UI->CompPos.y + CompUV.y * UI->CompZoom.y); } - draw_list->AddNgon(ScreenPoint[0], 20, wcol, 8, 10.0f); + if (State->Tool != tool_brush) { + ImU32 wcol2 = IM_COL32(10, 10, 10, 255); + draw_list->AddNgon(ScreenPoint[0], 10, wcol2, 8, 9.0f); + draw_list->AddNgon(ScreenPoint[0], 10, wcol, 8, 5.0f); + } draw_list->AddLine(ScreenPoint[1], ScreenPoint[2], wcol, 2.0f); draw_list->AddLine(ScreenPoint[2], ScreenPoint[4], wcol, 2.0f); draw_list->AddLine(ScreenPoint[1], ScreenPoint[3], wcol, 2.0f); draw_list->AddLine(ScreenPoint[3], ScreenPoint[4], wcol, 2.0f); } - /* - if (Layer->IsSelected) { - uint32 Width = 0, Height = 0; - if (!Layer->IsPrecomp) { - block_source *Source = (block_source *)Memory_Block_AddressAtIndex(Memory, F_Sources, Layer->Block_Source_Index); - Width = Source->Width; - Height = Source->Height; - } else { - block_composition *Comp = (block_composition *)Memory_Block_AddressAtIndex(Memory, F_Precomps, Layer->Block_Source_Index); - Width = Comp->Width; - Height = Comp->Height; - } - // Anchor point UI - v2 CenterPoint = V2(Width*Layer->ax.CurrentValue, Height*Layer->ay.CurrentValue); - ImVec2 ScreenAP = Layer_LocalToScreenSpace(State, Memory, Layer, UI, File->PrincipalCompIndex, CenterPoint); - draw_list->AddNgon(ScreenAP, 20, wcol, 8, 10.0f); - - // Bounding box UI - ImVec2 P1 = Layer_LocalToScreenSpace(State, Memory, Layer, UI, File->PrincipalCompIndex, V2(0, 0)); - ImVec2 P2 = Layer_LocalToScreenSpace(State, Memory, Layer, UI, File->PrincipalCompIndex, V2(Width, 0)); - ImVec2 P3 = Layer_LocalToScreenSpace(State, Memory, Layer, UI, File->PrincipalCompIndex, V2(0, Height)); - ImVec2 P4 = Layer_LocalToScreenSpace(State, Memory, Layer, UI, File->PrincipalCompIndex, V2(Width, Height)); - draw_list->AddLine(P1, P2, wcol, 2.0f); - draw_list->AddLine(P2, P4, wcol, 2.0f); - draw_list->AddLine(P1, P3, wcol, 2.0f); - draw_list->AddLine(P3, P4, wcol, 2.0f); - - } - */ - } } @@ -1480,6 +1471,7 @@ ImGui_Viewport(project_data *File, project_state *State, ui *UI, memory *Memory, if (!Layer->IsPrecomp) { block_source *Source = (block_source *)Memory_Block_AddressAtIndex(Memory, F_Sources, Layer->Block_Source_Index); if (Layer->IsSelected && Source->Type == source_type_principal) { + Assert(Source->BytesPerPixel == 4); Arbitrary_Zero((uint8 *)State->Brush.TransientBitmap, 2048*2048*4); State->Interact_Active = interact_type_brush; State->Brush.LayerToPaint_Index = i; @@ -1489,31 +1481,7 @@ ImGui_Viewport(project_data *File, project_state *State, ui *UI, memory *Memory, } } if (State->Brush.LayerToPaint_Index == -1) { - Arbitrary_Zero((uint8 *)State->Brush.TransientBitmap, 2048*2048*4); - State->Interact_Active = interact_type_brush; - Layer_DeselectAll(File, State, Memory); - History_Entry_Commit(Memory,"Paint new layer"); - uint16 i = Source_Generate_Blank(File, State, Memory, MainComp->Width, MainComp->Height, MainComp->BytesPerPixel); - block_layer *Layer = Layer_Init(File, Memory); - block_source *Source = (block_source *)Memory_Block_AddressAtIndex(Memory, F_Sources, Layer->Block_Source_Index); - State->Brush.LayerToPaint_Index = Memory_Block_LazyIndexAtAddress(Memory, F_Layers, (void *)Layer); - Layer->Block_Source_Index = i; - Layer->x.CurrentValue = MainComp->Width / 2; - Layer->y.CurrentValue = MainComp->Height / 2; - int TopOffset = (File->Layer_Count == 1) ? 11 : 0; - sorted_comp_info SortedCompInfo = SortedCompArray[File->PrincipalCompIndex]; - if (SortedCompInfo.LayerCount) - { - sorted_layer *SortedLayerInfo = Layer_GetSortedArray(SortedLayerArray, SortedCompArray, File->PrincipalCompIndex); - block_layer *TopLayer = (block_layer *)Memory_Block_AddressAtIndex(Memory, F_Layers, SortedLayerInfo[SortedCompInfo.LayerCount - 1].Block_Layer_Index); - TopOffset = TopLayer->Vertical_Offset; - } - Layer->Vertical_Offset = TopOffset - 1; - Layer->Frame_Start = MainComp->Frame_Start; - Layer->Frame_End = MainComp->Frame_End; - Layer->IsSelected = true; - History_Entry_End(Memory); - State->UpdateFrame = true; + State->HotkeyInput = hotkey_newpaintlayer; } } @@ -1553,44 +1521,23 @@ ImGui_Viewport(project_data *File, project_state *State, ui *UI, memory *Memory, block_source *Source = (block_source *)Memory_Block_AddressAtIndex(Memory, F_Sources, Layer->Block_Source_Index); ImVec2 MouseDelta = io.MouseDelta; real32 Delta = MouseDelta.x + MouseDelta.y; - if (Delta != 0.0f) { - real32 DeltaDistance = sqrt(MouseDelta.x * MouseDelta.x + MouseDelta.y * MouseDelta.y); - 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); - v2 PrincipalCompUV = ImGui_ScreenPointToCompUV(ViewportMin, UI->CompPos, UI->CompZoom, io.MousePos); - v2 LayerPos = Layer_TraverseForPoint(File, State, Memory, PrincipalCompUV, SortedCompArray, SortedLayerArray); - Brush_Render(State, UI, T_Layer, MainComp, Source, State->Brush.TransientBitmap, ViewportMin, LayerPos); + v2 PrincipalCompUV = ImGui_ScreenPointToCompUV(ViewportMin, UI->CompPos, UI->CompZoom, io.MousePos); + v2 LayerPos = Layer_TraverseForPoint(File, State, Memory, PrincipalCompUV, SortedCompArray, SortedLayerArray); + if (IsActivated) { + RenderQueue_AddBrush(State, LayerPos); + } else if (Delta != 0.0f) { + v2 PrevPos = State->Brush.PrevPos; + v2 Delta = PrevPos - LayerPos; + real32 Dist = sqrt(LengthSq(Delta)); + if (Dist > State->Brush.Spacing) { + RenderQueue_AddBrush(State, LayerPos); } - } else if (IsActivated) { - ImVec2 MousePos = io.MousePos; - v2 PrincipalCompUV = ImGui_ScreenPointToCompUV(ViewportMin, UI->CompPos, UI->CompZoom, io.MousePos); - v2 LayerPos = Layer_TraverseForPoint(File, State, Memory, PrincipalCompUV, SortedCompArray, SortedLayerArray); - Brush_Render(State, UI, T_Layer, MainComp, Source, State->Brush.TransientBitmap, ViewportMin, LayerPos); } State->UpdateFrame = true; } if (IsDeactivated) { - block_layer *Layer = (block_layer *)Memory_Block_AddressAtIndex(Memory, F_Layers, State->Brush.LayerToPaint_Index); - 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, 0); - rectangle RenderRegion = { 0, 0, Source->Width, Source->Height }; - direct_info Info = { (real32)Source->Width, (real32)Source->Height, (real32)Source->BytesPerPixel, (real32)Source->Width * Source->BytesPerPixel, - Bitmap_ByteInfo(Source->BytesPerPixel), blend_normal, - RenderRegion, State->Brush.TransientBitmap, 1}; - Render_Main((void *)&Info, SourceBitmapAddress, render_type_notransform_swap, State->Brush.CacheBounds); - - uint64 BitmapSize = Source->Width * Source->Height * Source->BytesPerPixel; - - // History_Entry_Commit(Memory, "Paintbrush stroke"); - // History_Action_BitmapPaint(Memory, BitmapSize, SourceBitmapAddress, State->Brush.TransientBitmap, Source->BytesPerPixel); - // History_Entry_End(Memory); - - State->Brush.LayerToPaint_Index = -1; - State->Interact_Active = interact_type_none; - State->Interact_Modifier = 0; - State->UpdateFrame = true; + RenderQueue_AddBlit(State); } } @@ -1751,7 +1698,7 @@ ImGui_GraphInfo(project_data *File, project_state *State, memory *Memory, ui *UI sorted_property_info *InfoLocation = Property_GetSortedInfo(SortedPropertyInfo, i, h); uint16 *ArrayLocation = Property_GetSortedArray(SortedPropertyArray, i, h); ImGui::PushID(Property); - if (ImGui::Selectable(DefaultChannel[h], InfoLocation->IsGraphSelected)) { + if (ImGui::Selectable(DefaultChannel[h], Property_IsGraphSelected(Memory, Property, ArrayLocation))) { Property_DeselectAll(File, State, Memory, SortedCompArray, SortedLayerArray, SortedPropertyInfo, SortedPropertyArray); for (int p = 0; p < Property->Keyframe_Count; p++) { int k = ArrayLocation[p]; @@ -1933,7 +1880,8 @@ ImGui_Timeline_DrawGraph(project_data *File, project_state *State, memory *Memor real32 GraphMoveHeight = TimelineMoveSize.y + (TimelineZoomSize.y * GraphPos); real32 GraphZoomHeight = TimelineZoomSize.y * GraphScale; - uint32 GraphCol = InfoLocation->IsGraphSelected ? IM_COL32(255, 180, 150, 255) : IM_COL32(255, 255, 255, 70); + bool32 IsGraphSelected = Property_IsGraphSelected(Memory, Property, ArrayLocation); + uint32 GraphCol = IsGraphSelected ? IM_COL32(255, 180, 150, 255) : IM_COL32(255, 255, 255, 70); bezier_point *PointAddress[2] = {}; ImVec2 Keyframe_ScreenPos[6] = {}; @@ -1995,7 +1943,7 @@ ImGui_Timeline_DrawGraph(project_data *File, project_state *State, memory *Memor if (b == 0) { draw_list->AddCircleFilled(Keyframe_ScreenPos[NewIdx + b], 4, PointCol); - if (InfoLocation->IsGraphSelected) { + if (IsGraphSelected) { char buf[8]; sprintf(buf, "%.2f", Keyframe_LocalPos[0].y); draw_list->AddText(Keyframe_ScreenPos[NewIdx + b], 0xFFFFFFFF, buf); @@ -2220,6 +2168,10 @@ ImGui_Timeline_DrawPrecomp(project_data *File, project_state *State, memory *Mem if (ImGui::MenuItem("Duplicate layer")) { Precomp_UIDuplicate(File, State, Memory, CompIndex, SortedCompInfo, SortedLayerInfo); } + if (ImGui::MenuItem("Delete layer")) { + Precomp_UICreateButton(File, State, Memory, CompIndex, SortedCompInfo, SortedLayerInfo); + State->UpdateKeyframes = true; + } if (ImGui::BeginMenu("Layer color")) { ImGui::PushStyleVar(ImGuiStyleVar_ItemSpacing, ImVec2(0.0f, 0.0f)); @@ -2869,7 +2821,7 @@ ImGui_Popups(project_data *File, project_state *State, ui *UI, memory *Memory, I } static void -ImGui_ProcessInputs(project_data *File, project_state *State, ui *UI, memory *Memory, ImGuiIO io) +ImGui_ProcessInputs(project_data *File, project_state *State, ui *UI, memory *Memory, ImGuiIO io, sorted_file Sorted) { if (ImGui::IsKeyPressed(ImGuiKey_Q)) { State->IsRunning = false; @@ -2891,7 +2843,7 @@ ImGui_ProcessInputs(project_data *File, project_state *State, ui *UI, memory *Me } } if (ImGui::IsKeyPressed(ImGuiKey_U)) { - State->HotkeyInput = hotkey_togglechannels; + Project_ToggleAllChannels(File, State, Memory, Sorted.CompArray, Sorted.LayerArray, Sorted.PropertyInfo, Sorted.PropertyArray); } if (ImGui::IsKeyPressed(ImGuiKey_X)) { if (State->TimelineMode == timeline_mode_graph && State->Interact_Active == interact_type_keyframe_move) { @@ -2976,7 +2928,8 @@ ImGui_ProcessInputs(project_data *File, project_state *State, ui *UI, memory *Me } } else if (State->FocusedWindow == focus_viewport) { if (ImGui::IsKeyPressed(ImGuiKey_T)) { - State->HotkeyInput = hotkey_transform; + Interact_Transform_Begin(File, Memory, State, io.MousePos, Sorted.CompArray, Sorted.LayerArray); + State->Tool = tool_default; } } } @@ -3011,24 +2964,7 @@ ImGui_ProcessInputs(project_data *File, project_state *State, ui *UI, memory *Me if (ImGui::IsKeyPressed(ImGuiKey_Delete)) { - bool32 CommitAction = 0; - int h = 0, c = 0, i = 0; - int LayerCount = File->Layer_Count; - while (Block_Loop(Memory, F_Layers, LayerCount, &h, &c, &i)) { - block_layer *Layer = (block_layer *)Memory_Block_AddressAtIndex(Memory, F_Layers, i); - if (Layer->IsSelected) { - if (!CommitAction) { - History_Entry_Commit(Memory, "Delete source"); - CommitAction = 1; - } - Layer_Delete(File, Memory, i); - } - } - if (CommitAction) { - History_Entry_End(Memory); - State->UpdateFrame = true; - State->MostRecentlySelectedLayer = -1; - } + State->HotkeyInput = hotkey_deletelayer; } if (io.KeyShift && ImGui::IsKeyPressed(ImGuiKey_Slash)) @@ -3039,7 +2975,19 @@ ImGui_ProcessInputs(project_data *File, project_state *State, ui *UI, memory *Me #if DEBUG if (ImGui::IsKeyPressed(ImGuiKey_3)) { - State->ImGuiPopups = popup_keybinds; + // State->ImGuiPopups = popup_keybinds; + Debug.DisableAlpha = 0; + State->UpdateFrame = true; + } + if (ImGui::IsKeyPressed(ImGuiKey_4)) + { + Debug.DisableAlpha = 1; + State->UpdateFrame = true; + } + if (ImGui::IsKeyPressed(ImGuiKey_5)) + { + Debug.DisableAlpha = 2; + State->UpdateFrame = true; } if (ImGui::IsKeyPressed(ImGuiKey_F)) { @@ -3072,18 +3020,16 @@ ImGui_ProcessInputs(project_data *File, project_state *State, ui *UI, memory *Me } } if (ImGui::IsKeyPressed(ImGuiKey_C)) { - State->HotkeyInput = hotkey_copy; + Clipboard_Store(File, State, Memory, Sorted.CompArray, Sorted.LayerArray, Sorted.PropertyInfo, Sorted.PropertyArray); } if (ImGui::IsKeyPressed(ImGuiKey_V)) { - State->HotkeyInput = hotkey_paste; + Clipboard_Paste(File, State, Memory, Sorted.CompArray, Sorted.LayerArray, Sorted.PropertyArray); } if (ImGui::IsKeyPressed(ImGuiKey_Z)) { if (io.KeyShift) { - History_Redo(Memory); - State->UpdateFrame = true; + State->HotkeyInput = hotkey_redo; } else { - History_Undo(Memory); - State->UpdateFrame = true; + State->HotkeyInput = hotkey_undo; } } } |