From c5a60e71f9ed869467e2090f4b343641b021386a Mon Sep 17 00:00:00 2001 From: Fox Caminiti Date: Sat, 26 Nov 2022 23:52:57 -0500 Subject: keybind refinement --- createcalls.cpp | 66 +----------- imgui_helper_widgets.cpp | 52 ++++----- main.cpp | 17 ++- main.h | 122 ++++++++++----------- my_imgui_widgets.cpp | 271 ++++++++++++++++++++++++++++++++++++++--------- stable_diffusion.cpp | 4 +- 6 files changed, 322 insertions(+), 210 deletions(-) diff --git a/createcalls.cpp b/createcalls.cpp index 1eac4cc..de81c1e 100644 --- a/createcalls.cpp +++ b/createcalls.cpp @@ -5,67 +5,6 @@ PostMsg(project_state *State, char *msg) State->Msg = msg; } -/* -static bool32 -File_Open(project_state *State, memory *Memory, char *Filename) -{ - // uint16 ContextIndex = State->NumberOfOpenFiles; - // State->CurrentFileIndex = State->NumberOfOpenFiles; - uint16 ContextIndex = 0; - State->CurrentFileIndex = 0; - - if (!State->NumberOfOpenFiles) { - Memory_AddPartition(Memory, P_UndoBuffer); - Memory_AddPartition(Memory, F_Data); - Memory_AddPartition(Memory, F_BitmapData); - } - - state_file_context *Context = &State->Context[ContextIndex]; - file_data *File = (file_data *)Memory_PartitionAtIndex(Memory, F_Data, ContextIndex); - - SDL_RWops *FileHandle = SDL_RWFromFile(Filename, "r+b"); - - if (!FileHandle) { - return 0; - } - - int64 FileSize = SDL_RWsize(FileHandle); - - IO_ReadFromStream((void *)File, sizeof(file_data), FileHandle); - SDL_RWseek(FileHandle, 0, RW_SEEK_SET); - IO_ReadFromStream((void *)File, File->Bitmap_ByteOffset, FileHandle); - - void *CompressedLocation = Memory_PushScratch(Memory, File->CompressedSize); - void *BitmapLocation = Memory_PartitionAtIndex(Memory, F_BitmapData, ContextIndex); - - IO_ReadFromStream(CompressedLocation, File->CompressedSize, FileHandle); - - uint64 Bitmap_Size = Source_GetByteOffset(File, File->NumberOfSources); - - Data_Decompress(Memory, CompressedLocation, File->CompressedSize, BitmapLocation, Bitmap_Size); - - Memory_PopScratch(Memory, File->CompressedSize); - - SDL_RWclose(FileHandle); - - Context->UI.Initializing = 4; - - if (!State->NumberOfOpenFiles) { - History_Entry_Commit(Memory, ContextIndex, "Open file"); - History_Action_State_Swap(Memory, sizeof(State->NumberOfOpenFiles), &State->NumberOfOpenFiles); - State->NumberOfOpenFiles++; - History_Entry_End(Memory, ContextIndex); - } - - sprintf(State->Context[0].Filename, "%s", Filename); - Memory->IsFileSaved = true; - Memory->History[0].NumberOfEntries = 0; - Memory->History[0].EntryPlayhead = 0; - - return 1; -} -*/ - static bool32 File_Open(project_data *File, project_state *State, memory *Memory, char *Filename) { @@ -92,6 +31,9 @@ File_Open(project_data *File, project_state *State, memory *Memory, char *Filena } } String_Copy(State->Filename, State->DummyName, 512); + State->Initializing = 4; + Memory->History.NumberOfEntries = 0; + Memory->History.EntryPlayhead = 0; return 1; } @@ -608,7 +550,7 @@ int32 Layer_TestSelection(memory *Memory, project_state *State, ui *UI, sorted_c 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); layer_transforms T = Layer_GetTransforms(Layer); - v2 UV = T_CompUVToLayerUV(T, Comp->Width, Comp->Height, Source->Width, Source->Height, UI->TempZoomRatio); + v2 UV = T_CompUVToLayerUV(T, Comp->Width, Comp->Height, Source->Width, Source->Height, State->TempZoomRatio); if (UV.x <= 1.0f && UV.x >= 0.0f && UV.y <= 1.0f && UV.y >= 0.0f && !Layer->IsSelected) { LayerIndex = Index_Physical; diff --git a/imgui_helper_widgets.cpp b/imgui_helper_widgets.cpp index 17a9193..c27e947 100644 --- a/imgui_helper_widgets.cpp +++ b/imgui_helper_widgets.cpp @@ -16,34 +16,34 @@ ImGui_ScreenPointToCompUV(ImVec2 ViewportMin, ImVec2 CompPos, ImVec2 CompZoom, I // on SDL_WarpMouseGlobal to update on the first frame of a WantSetPos request. static void -ImGui_WarpMouse(ui *UI, ImVec2 MousePos, ImVec2 Min, ImVec2 Max, int Direction = 3) +ImGui_WarpMouse(project_state *State, ImVec2 MousePos, ImVec2 Min, ImVec2 Max, int Direction = 3) { if (Direction & 1) { if (MousePos.x < Min.x) { - UI->Warp_WantSetPos = true; - UI->Warp_PositionToSet = ImVec2(Max.x - 5, MousePos.y); - UI->Warp_PositionInitial = MousePos.x; - UI->Warp_Direction = 0; + State->Warp_WantSetPos = true; + State->Warp_PositionToSet = ImVec2(Max.x - 5, MousePos.y); + State->Warp_PositionInitial = MousePos.x; + State->Warp_Direction = 0; } if (MousePos.x > Max.x) { - UI->Warp_WantSetPos = true; - UI->Warp_PositionToSet = ImVec2(Min.x + 5, MousePos.y); - UI->Warp_PositionInitial = MousePos.x; - UI->Warp_Direction = 1; + State->Warp_WantSetPos = true; + State->Warp_PositionToSet = ImVec2(Min.x + 5, MousePos.y); + State->Warp_PositionInitial = MousePos.x; + State->Warp_Direction = 1; } } if (Direction & 2) { if (MousePos.y < Min.y) { - UI->Warp_WantSetPos = true; - UI->Warp_PositionToSet = ImVec2(MousePos.x, Max.y - 5); - UI->Warp_PositionInitial = MousePos.y; - UI->Warp_Direction = 2; + State->Warp_WantSetPos = true; + State->Warp_PositionToSet = ImVec2(MousePos.x, Max.y - 5); + State->Warp_PositionInitial = MousePos.y; + State->Warp_Direction = 2; } if (MousePos.y > Max.y) { - UI->Warp_WantSetPos = true; - UI->Warp_PositionToSet = ImVec2(MousePos.x, Min.y + 5); - UI->Warp_PositionInitial = MousePos.y; - UI->Warp_Direction = 3; + State->Warp_WantSetPos = true; + State->Warp_PositionToSet = ImVec2(MousePos.x, Min.y + 5); + State->Warp_PositionInitial = MousePos.y; + State->Warp_Direction = 3; } } } @@ -52,16 +52,16 @@ ImGui_WarpMouse(ui *UI, ImVec2 MousePos, ImVec2 Min, ImVec2 Max, int Direction = // increment the wrap amount when MousePos actually is measured to be what we expect. static void -ImGui_WarpMouseFinish(ui *UI, ImVec2 MousePos) +ImGui_WarpMouseFinish(project_state *State, ImVec2 MousePos) { - if (UI->Warp_Direction == 0) { - if (MousePos.x < UI->Warp_PositionInitial) UI->Warp_X--; - } else if (UI->Warp_Direction == 1) { - if (MousePos.x > UI->Warp_PositionInitial) UI->Warp_X++; - } else if (UI->Warp_Direction == 2) { - if (MousePos.y < UI->Warp_PositionInitial) UI->Warp_Y--; - } else if (UI->Warp_Direction == 3) { - if (MousePos.y > UI->Warp_PositionInitial) UI->Warp_Y++; + if (State->Warp_Direction == 0) { + if (MousePos.x < State->Warp_PositionInitial) State->Warp_X--; + } else if (State->Warp_Direction == 1) { + if (MousePos.x > State->Warp_PositionInitial) State->Warp_X++; + } else if (State->Warp_Direction == 2) { + if (MousePos.y < State->Warp_PositionInitial) State->Warp_Y--; + } else if (State->Warp_Direction == 3) { + if (MousePos.y > State->Warp_PositionInitial) State->Warp_Y++; } else { Assert(0); } diff --git a/main.cpp b/main.cpp index 83d3dcb..61bdd03 100644 --- a/main.cpp +++ b/main.cpp @@ -121,9 +121,9 @@ Main_InputTest(project_data *File, project_state *State, memory *Memory, ui *UI, State->IsRunning = false; } - if (UI->Warp_WantSetPos) { + if (State->Warp_WantSetPos) { ImGui::GetIO().WantSetMousePos = true; - io.MousePos = UI->Warp_PositionToSet; + io.MousePos = State->Warp_PositionToSet; } ImGui_ImplOpenGL3_NewFrame(); @@ -131,10 +131,10 @@ Main_InputTest(project_data *File, project_state *State, memory *Memory, ui *UI, ImGui::NewFrame(); - if (UI->Warp_WantSetPos) { - ImGui_WarpMouseFinish(UI, io.MousePos); + if (State->Warp_WantSetPos) { + ImGui_WarpMouseFinish(State, io.MousePos); io.MouseDelta = {}; - UI->Warp_WantSetPos = false; + State->Warp_WantSetPos = false; } if (!io.WantCaptureKeyboard) @@ -184,7 +184,7 @@ Main_InputTest(project_data *File, project_state *State, memory *Memory, ui *UI, ImGui_ColorPanel(File, State, UI, Memory, io); // ImGui_EffectsPanel(File, State, Memory, UI, io); #if STABLE - if (State->StableEnabled) { + if (UI->StableEnabled) { ImGui_SD_Prompt(File, State, UI, Memory, io, Sorted.CompArray, Sorted.LayerArray); ImGui_SD_Thumbnail(File, State, UI, Memory, io, Sorted.CompArray, Sorted.LayerArray, Sorted.SourceArray, Sorted.TempSourceCount); } @@ -645,8 +645,7 @@ int main(int argc, char *argv[]) { State->ClipboardSize = 1024*1024; Memory.ScratchPos += State->ClipboardSize; - ui UI = {}; - UI.Test = ImDrawListSplitter(); + State->Test = ImDrawListSplitter(); block_composition *MainComp = (block_composition *)Memory_Block_AllocateAddress(&Memory, F_Precomps); @@ -794,7 +793,7 @@ int main(int argc, char *argv[]) { } #endif - Main_InputTest(File, State, &Memory, &UI, window, textureID); + Main_InputTest(File, State, &Memory, &File->UI, window, textureID); if (State->IsPlaying) { block_composition *MainComp = (block_composition *)Memory_Block_AddressAtIndex(&Memory, F_Precomps, File->PrincipalCompIndex); diff --git a/main.h b/main.h index b4f5cb5..b2f2ed3 100644 --- a/main.h +++ b/main.h @@ -176,61 +176,6 @@ enum timeline_mode timeline_mode_graph }; -struct ui -{ - ImVec2 CompZoom; // In screen pixels, not percentage. - ImVec2 CompPos; - - ImDrawListSplitter Test; - - // Under 1 is zoomed in! - ImVec2 TimelinePercentZoomed; - ImVec2 TimelinePercentOffset; - - ImVec2 GraphZoomSize; - ImVec2 GraphMoveSize; - - uint32 InteractTransformMode; // Whether a drag on the Shift+T UI is scale (1), rotation (2), or position (3). - - timeline_mode TimelineMode; - - bool32 BoxSelect; - - focused_window FocusedWindow; // Convenience for adding window-specific hotkeys. - - v2 TempZoomRatio = V2(1, 1); - - int32 Warp_X = 0; - int32 Warp_Y = 0; - bool32 Warp_WantSetPos = false; - ImVec2 Warp_PositionToSet; - real32 Warp_PositionInitial; - int32 Warp_Direction; - - v4 Color = {1, 1, 1, 1}; - v4 AltColor = {0, 0, 0, 1}; - bool32 IsPrimary; - - ImU32 LayerColors[16] = { - 0xff8b1f1f, - 0xffc25909, - 0xff57c20a, - 0xff8ee6da, - 0xffa48fb7, - 0xffd14061, - 0xff38b683, - 0xff3fdbe5, - 0xffc9c9c9, - 0xff978489, - 0xfffaf5ab, - 0xff101010, - 0xffa024ca, - 0xfffae920, - 0xff208dfa, - 0xfffa2051 - }; -}; - struct pen_state { bool32 IsActive; }; @@ -371,7 +316,8 @@ struct header_effect enum imgui_popups { popup_none, - popup_saveas + popup_saveas, + popup_keybinds }; struct project_state @@ -389,10 +335,8 @@ struct project_state brush_state Brush; #if STABLE - bool32 StableEnabled = 0; - sd_state SD; - char JSONPayload[1024*1024*4]; int32 CurlActive = 0; + char JSONPayload[1024*1024*4]; real32 SDPercentDone; real32 SDTimeEstimate; real64 SDTimer; @@ -439,8 +383,67 @@ struct project_state ImGuiTextFilter filter; // This filter API is pretty ballin'. bool32 RerouteEffects; // Allows shift+space hotkey to gain focus on the effects panel. + + ImDrawListSplitter Test; + + int32 Warp_X = 0; + int32 Warp_Y = 0; + bool32 Warp_WantSetPos = false; + ImVec2 Warp_PositionToSet; + real32 Warp_PositionInitial; + int32 Warp_Direction; + + uint32 InteractTransformMode; // Whether a drag on the Shift+T UI is scale (1), rotation (2), or position (3). + + timeline_mode TimelineMode; + + bool32 BoxSelect; + + focused_window FocusedWindow; // Convenience for adding window-specific hotkeys. + v2 TempZoomRatio = V2(1, 1); +}; + +// UI info that's saved to the file and is not part of the history tree +struct ui +{ + ImVec2 CompZoom; // In screen pixels, not percentage. + ImVec2 CompPos; + + // Under 1 is zoomed in! + ImVec2 TimelinePercentZoomed; + ImVec2 TimelinePercentOffset; + + ImVec2 GraphZoomSize; + ImVec2 GraphMoveSize; + + v4 Color = {1, 1, 1, 1}; + v4 AltColor = {0, 0, 0, 1}; + bool32 IsPrimary; + + sd_state SD; + bool32 StableEnabled = 0; + + ImU32 LayerColors[16] = { + 0xff8b1f1f, + 0xffc25909, + 0xff57c20a, + 0xff8ee6da, + 0xffa48fb7, + 0xffd14061, + 0xff38b683, + 0xff3fdbe5, + 0xffc9c9c9, + 0xff978489, + 0xfffaf5ab, + 0xff101010, + 0xffa024ca, + 0xfffae920, + 0xff208dfa, + 0xfffa2051 + }; }; + struct project_data { uint8 Occupied; @@ -448,6 +451,7 @@ struct project_data uint16 Source_Count; uint16 Comp_Count; uint16 PrincipalCompIndex; + ui UI; }; struct block_composition diff --git a/my_imgui_widgets.cpp b/my_imgui_widgets.cpp index c8971c2..16be2e1 100644 --- a/my_imgui_widgets.cpp +++ b/my_imgui_widgets.cpp @@ -47,7 +47,7 @@ ImGui_PropertiesPanel(project_data *File, project_state *State, ui *UI, memory * sprintf(buf, "Properties: %s###Properties", String->Char); ImGui::Begin(buf); if (ImGui::IsWindowFocused(ImGuiFocusedFlags_ChildWindows)) - UI->FocusedWindow = focus_properties; + State->FocusedWindow = focus_properties; ImGui::Text("Transform"); for (int h = 0; h < AmountOf(Layer->Property); h++) { property_channel *Property = &Layer->Property[h]; @@ -127,7 +127,7 @@ ImGui_PropertiesPanel(project_data *File, project_state *State, ui *UI, memory * } else { ImGui::Begin("Properties: empty###Properties"); if (ImGui::IsWindowFocused(ImGuiFocusedFlags_ChildWindows)) - UI->FocusedWindow = focus_properties; + State->FocusedWindow = focus_properties; ImGui::End(); } } @@ -385,7 +385,7 @@ ImGui_SD_Prompt(project_data *File, project_state *State, ui *UI, memory *Memory sorted_comp_info *SortedCompInfo = &SortedCompArray[File->PrincipalCompIndex]; sorted_layer *SortedLayerInfo = Layer_GetSortedArray(SortedLayerArray, SortedCompArray,File->PrincipalCompIndex); ImGui::Begin("SD prompt input"); - sd_state *SD = &State->SD; + sd_state *SD = &File->UI.SD; int Size = ImGui::GetFontSize(); ImGui::PushStyleColor(ImGuiCol_Button, IM_COL32(200, 80, 0, 255)); if (ImGui::Button("Generate!", ImVec2(Size*8, Size*2))) { @@ -447,9 +447,9 @@ ImGui_SD_Prompt(project_data *File, project_state *State, ui *UI, memory *Memory ImGui::Text("Est. time: %.1f sec, %.2f", State->SDTimeEstimate, State->SDPercentDone*100); } ImGui::InputText("Address", SD->ServerAddress, SD_LEN_ADDRESS); - if (State->Initializing && (SD->ServerAddress[0] == '\0')) { - sprintf(SD->Prompt, "%s", "scan, highres, monochrome, traditional medium, (sketch:1.2), flat shading, earth, globe, effects, clouds, lightning, fire"); - sprintf(SD->NegPrompt, "%s", "nsfw, bad anatomy, bad hands, text, error, missing fingers, extra digit, fewer digits, cropped, worst quality, low quality, normal quality, jpeg artifacts, signature, watermark"); + if (SD->ServerAddress[0] == '\0' && SD->Prompt[0] == '\0') { + sprintf(SD->Prompt, "%s", "highres"); + sprintf(SD->NegPrompt, "%s", "nsfw, \ntext, \ncropped, \nworst quality, \nlow quality, \nnormal quality, \njpeg artifacts, \nsignature, \nwatermark"); sprintf(SD->ServerAddress, "%s", "http://127.0.0.1:7860"); } if (ImGui::Selectable("txt2img", !SD->Mode)) @@ -710,10 +710,10 @@ ImGui_TransformUI(project_data *File, project_state *State, memory *Memory, ui * ImGui::PopStyleColor(); if (ImGui::IsItemActivated() && !OtherActions) { - UI->InteractTransformMode = 1; + State->InteractTransformMode = 1; } - if (UI->InteractTransformMode == 1 && ImGui::IsItemActive()) + if (State->InteractTransformMode == 1 && ImGui::IsItemActive()) { uint32 side = i; if (side == 0) { @@ -748,13 +748,13 @@ ImGui_TransformUI(project_data *File, project_state *State, memory *Memory, ui * if (ImGui::IsItemActivated() && !OtherActions) { if (InBounds) - UI->InteractTransformMode = 1; + State->InteractTransformMode = 1; else - UI->InteractTransformMode = 2; + State->InteractTransformMode = 2; } // Scale part - if (UI->InteractTransformMode == 1 && ImGui::IsItemActive()) + if (State->InteractTransformMode == 1 && ImGui::IsItemActive()) { // TODO(fox): Corner dragging scale only works in the X // axis. Mostly feels right when dragged how you expect, @@ -780,7 +780,7 @@ ImGui_TransformUI(project_data *File, project_state *State, memory *Memory, ui * } // Rotation part - if (UI->InteractTransformMode == 2 && ImGui::IsItemActive()) + if (State->InteractTransformMode == 2 && ImGui::IsItemActive()) { real32 LocalX = (io.MousePos.x - UI->CompPos.x)/CompScale.x - InteractMin.x - (BoxLength.x/2); real32 LocalY = (io.MousePos.y - UI->CompPos.y)/CompScale.y - InteractMin.y - (BoxLength.y/2); @@ -834,20 +834,20 @@ ImGui_TransformUI(project_data *File, project_state *State, memory *Memory, ui * ImGui::PopID(); } - if (!UI->InteractTransformMode && ImGui::IsMouseClicked(ImGuiMouseButton_Left) && InBounds && !OtherActions) - UI->InteractTransformMode = 3; + if (!State->InteractTransformMode && ImGui::IsMouseClicked(ImGuiMouseButton_Left) && InBounds && !OtherActions) + State->InteractTransformMode = 3; - if (UI->InteractTransformMode == 3) { + if (State->InteractTransformMode == 3) { Interact->Position.x += (real32)io.MouseDelta.x/CompScale.x; Interact->Position.y += (real32)io.MouseDelta.y/CompScale.y; } - if (UI->InteractTransformMode) + if (State->InteractTransformMode) { if (io.MouseDelta.x || io.MouseDelta.y) State->UpdateFrame = true; if (!ImGui::IsMouseDown(ImGuiMouseButton_Left)) - UI->InteractTransformMode = 0; + State->InteractTransformMode = 0; } if (ImGui::IsKeyPressed(ImGuiKey_Escape)) { @@ -1005,7 +1005,7 @@ ImGui_Viewport(project_data *File, project_state *State, ui *UI, memory *Memory, ImGui::Begin("Viewport", &open, ImGuiWindowFlags_NoScrollbar | ImGuiWindowFlags_NoScrollWithMouse); if (ImGui::IsWindowFocused(ImGuiFocusedFlags_ChildWindows)) - UI->FocusedWindow = focus_viewport; + State->FocusedWindow = focus_viewport; block_composition *MainComp = (block_composition *)Memory_Block_AddressAtIndex(Memory, F_Precomps, File->PrincipalCompIndex); @@ -1062,7 +1062,7 @@ ImGui_Viewport(project_data *File, project_state *State, ui *UI, memory *Memory, if (IsHovered && IsActivated && !ImGui::IsMouseDown(ImGuiMouseButton_Right)) { // Point to zoom in on if Z is held - UI->TempZoomRatio = ImGui_ScreenPointToCompUV(ViewportMin, UI->CompPos, UI->CompZoom, io.MousePos); + State->TempZoomRatio = ImGui_ScreenPointToCompUV(ViewportMin, UI->CompPos, UI->CompZoom, io.MousePos); if (State->Tool == tool_brush && State->Interact_Active != interact_type_brush) { sorted_layer *SortedLayerInfo = Layer_GetSortedArray(SortedLayerArray, SortedCompArray, File->PrincipalCompIndex); @@ -1197,8 +1197,8 @@ ImGui_Viewport(project_data *File, project_state *State, ui *UI, memory *Memory, Distance *= -1; UI->CompZoom.x += (Distance)*(real32)MainComp->Width/MainComp->Height; UI->CompZoom.y += (Distance); - UI->CompPos.x -= ((Distance)*(real32)MainComp->Width/MainComp->Height)*UI->TempZoomRatio.x; - UI->CompPos.y -= Distance*UI->TempZoomRatio.y; + UI->CompPos.x -= ((Distance)*(real32)MainComp->Width/MainComp->Height)*State->TempZoomRatio.x; + UI->CompPos.y -= Distance*State->TempZoomRatio.y; } ImGui::SetCursorScreenPos(ImVec2(ViewportMin.x, ViewportMin.y + ViewportScale.y - ImGui::GetFontSize()*1.5)); @@ -1364,7 +1364,7 @@ ImGui_Timeline_DrawKeySheet(project_data *File, project_state *State, memory *Me ImVec2 Keyframe_ScreenPos(Keyframe_ScreenPos_X, TimelineAbsolutePos.y); - if (UI->BoxSelect) { + if (State->BoxSelect) { real32 Y_Top = (io.MouseClickedPos[0].y < io.MousePos.y) ? io.MouseClickedPos[0].y : io.MousePos.y; real32 Y_Bottom = (io.MouseClickedPos[0].y > io.MousePos.y) ? io.MouseClickedPos[0].y : io.MousePos.y; real32 X_Left = (io.MouseClickedPos[0].x < io.MousePos.x) ? io.MouseClickedPos[0].x : io.MousePos.x; @@ -1416,7 +1416,7 @@ ImGui_Timeline_DrawGraph(project_data *File, project_state *State, memory *Memor ImVec2 TimelineSize, ImVec2 TimelineSizeWithBorder, real32 LayerIncrement, sorted_property_info *SortedPropertyInfo, uint16 *SortedPropertyArray) { // I'm using the draw splitter here to be able to draw the dots on top of the graph lines. - UI->Test.Split(draw_list, 2); + State->Test.Split(draw_list, 2); int h = 0, c = 0, i = 0; while (Block_Loop(Memory, F_Layers, File->Layer_Count, &h, &c, &i)) @@ -1433,9 +1433,9 @@ ImGui_Timeline_DrawGraph(project_data *File, project_state *State, memory *Memor State->Interact_Active == interact_type_keyframe_rotate || State->Interact_Active == interact_type_keyframe_scale)) { - ImGui_WarpMouse(UI, io.MousePos, TimelineAbsolutePos, TimelineAbsolutePos + TimelineSizeWithBorder); + ImGui_WarpMouse(State, io.MousePos, TimelineAbsolutePos, TimelineAbsolutePos + TimelineSizeWithBorder); ImVec2 DragDelta = io.MousePos - ImVec2(State->Interact_Offset[2], State->Interact_Offset[3]); - DragDelta = DragDelta + (ImVec2(UI->Warp_X, UI->Warp_Y) * TimelineSize); + DragDelta = DragDelta + (ImVec2(State->Warp_X, State->Warp_Y) * TimelineSize); if (io.MouseDelta.x || io.MouseDelta.y) { State->UpdateFrame = true; } @@ -1504,7 +1504,7 @@ ImGui_Timeline_DrawGraph(project_data *File, project_state *State, memory *Memor Keyframe_ScreenPos[NewIdx + b] = TimelineAbsolutePos + ImVec2(TimelineMoveSize.x, GraphMoveHeight) + ((ImVec2(1, -1) * Keyframe_LocalPos_Ratio[b] + ImVec2(0, 1)) * ImVec2(TimelineZoomSize.x, GraphZoomHeight)); } - if (UI->BoxSelect) { + if (State->BoxSelect) { real32 Y_Top = (io.MouseClickedPos[0].y < io.MousePos.y) ? io.MouseClickedPos[0].y : io.MousePos.y; real32 Y_Bottom = (io.MouseClickedPos[0].y > io.MousePos.y) ? io.MouseClickedPos[0].y : io.MousePos.y; real32 X_Left = (io.MouseClickedPos[0].x < io.MousePos.x) ? io.MouseClickedPos[0].x : io.MousePos.x; @@ -1521,7 +1521,7 @@ ImGui_Timeline_DrawGraph(project_data *File, project_state *State, memory *Memor } } - UI->Test.SetCurrentChannel(draw_list, 1); + State->Test.SetCurrentChannel(draw_list, 1); ImVec2 ButtonSize(16, 16); @@ -1565,7 +1565,7 @@ ImGui_Timeline_DrawGraph(project_data *File, project_state *State, memory *Memor } ImGui::PopID(); - UI->Test.SetCurrentChannel(draw_list, 0); + State->Test.SetCurrentChannel(draw_list, 0); if (p != 0) { if (PointAddress[0]->Type == interpolation_type_bezier && PointAddress[1]->Type == interpolation_type_bezier) { @@ -1582,7 +1582,7 @@ ImGui_Timeline_DrawGraph(project_data *File, project_state *State, memory *Memor ImGui::PopID(); } - UI->Test.Merge(draw_list); + State->Test.Merge(draw_list); } @@ -1651,9 +1651,9 @@ ImGui_Timeline_DrawPrecomp(project_data *File, project_state *State, memory *Mem // Main interaction ImGui::PushID(i); - if (UI->TimelineMode == timeline_mode_default) { + if (State->TimelineMode == timeline_mode_default) { - if (UI->BoxSelect && UI->TimelineMode == timeline_mode_default) { + if (State->BoxSelect && State->TimelineMode == timeline_mode_default) { bool32 Test = 0; if (io.MouseClickedPos[0].y < io.MousePos.y) Test = (Layer_ScreenPos_Min.y >= io.MouseClickedPos[0].y && Layer_ScreenPos_Min.y <= io.MousePos.y); @@ -1696,7 +1696,7 @@ ImGui_Timeline_DrawPrecomp(project_data *File, project_state *State, memory *Mem Assert(Layer->IsSelected); State->Interact_Active = interact_type_layer_timeadjust; ImVec2 DragDelta = ImGui::GetMouseDragDelta(); - DragDelta = DragDelta + (ImVec2(UI->Warp_X, UI->Warp_Y) * TimelineSize); + DragDelta = DragDelta + (ImVec2(State->Warp_X, State->Warp_Y) * TimelineSize); State->Interact_Offset[0] = (DragDelta.x / TimelineSizeWithBorder.x * UI->TimelinePercentZoomed.x) * Comp->Frame_Count; State->Interact_Offset[1] = b; @@ -1818,7 +1818,7 @@ ImGui_Timeline_DrawPrecomp(project_data *File, project_state *State, memory *Mem Layer_RecursiveDeselect(Memory, SortedCompArray, SortedLayerArray, Layer->Block_Composition_Index, File->PrincipalCompIndex); } ImVec2 DragDelta = ImGui::GetMouseDragDelta(); - DragDelta = DragDelta + (ImVec2(UI->Warp_X, UI->Warp_Y) * TimelineSize); + DragDelta = DragDelta + (ImVec2(State->Warp_X, State->Warp_Y) * TimelineSize); ImVec2 Offset_Old = ImVec2(State->Interact_Offset[0], State->Interact_Offset[1]); ImVec2 Offset_New = (DragDelta / TimelineSizeWithBorder * UI->TimelinePercentZoomed) * ImVec2(Comp->Frame_Count, -LayerIncrement); @@ -1917,7 +1917,7 @@ static void ImGui_Timeline(project_data *File, project_state *State, memory *Memory, ui *UI, ImGuiIO io, sorted_comp_info *SortedCompArray, sorted_layer *SortedLayerArray, sorted_property_info *SortedPropertyInfo, uint16 *SortedPropertyArray) { - if (UI->TimelineMode == timeline_mode_graph) + if (State->TimelineMode == timeline_mode_graph) ImGui_GraphInfo(File, State, Memory, UI, io, SortedPropertyInfo, SortedPropertyArray); ImVec2 FramePadding = ImGui::GetStyle().FramePadding; @@ -1927,7 +1927,7 @@ ImGui_Timeline(project_data *File, project_state *State, memory *Memory, ui *UI, ImGui::Begin("Timeline", NULL); if (ImGui::IsWindowFocused(ImGuiFocusedFlags_ChildWindows)) - UI->FocusedWindow = focus_timeline; + State->FocusedWindow = focus_timeline; real32 FontHeight = ImGui::GetFontSize(); @@ -1999,7 +1999,7 @@ ImGui_Timeline(project_data *File, project_state *State, memory *Memory, ui *UI, TimelineSize, TimelineSizeWithBorder, LayerIncrement, SortedCompArray, SortedLayerArray, SortedPropertyInfo, SortedPropertyArray); - if (UI->TimelineMode == timeline_mode_graph) { + if (State->TimelineMode == timeline_mode_graph) { if (UI->GraphMoveSize.y == 0) { UI->GraphZoomSize = ImVec2(1, UI->TimelinePercentZoomed.y ); @@ -2087,7 +2087,7 @@ ImGui_Timeline(project_data *File, project_state *State, memory *Memory, ui *UI, } if (BarHeld) { - ImGui_WarpMouse(UI, io.MousePos, TimelineAbsolutePos, TimelineAbsolutePos + TimelineSizeWithBorder, 1); + ImGui_WarpMouse(State, io.MousePos, TimelineAbsolutePos, TimelineAbsolutePos + TimelineSizeWithBorder, 1); } Assert(ActivePercentZoomed->x > BarMinZoom); @@ -2150,7 +2150,7 @@ ImGui_Timeline(project_data *File, project_state *State, memory *Memory, ui *UI, ActivePercentZoomed->y = Max(ActivePercentZoomed->y, 0.01); if (BarHeld) { - ImGui_WarpMouse(UI, io.MousePos, TimelineAbsolutePos, TimelineAbsolutePos + TimelineSizeWithBorder, 2); + ImGui_WarpMouse(State, io.MousePos, TimelineAbsolutePos, TimelineAbsolutePos + TimelineSizeWithBorder, 2); } ImGui::SetCursorScreenPos(TimelineAbsolutePos); @@ -2184,7 +2184,7 @@ ImGui_Timeline(project_data *File, project_state *State, memory *Memory, ui *UI, if (LeftClick) { if (IsItemActivated) { - if (!io.KeyShift && UI->TimelineMode == timeline_mode_default) Layer_DeselectAll(File, State, Memory); + if (!io.KeyShift && State->TimelineMode == timeline_mode_default) Layer_DeselectAll(File, State, Memory); if (State->Interact_Active == interact_type_keyframe_move || State->Interact_Active == interact_type_keyframe_rotate || State->Interact_Active == interact_type_keyframe_scale) { @@ -2219,20 +2219,20 @@ ImGui_Timeline(project_data *File, project_state *State, memory *Memory, ui *UI, State->Interact_Active = interact_type_none; State->Interact_Modifier = 0; } - UI->BoxSelect = true; + State->BoxSelect = true; } if (IsItemActive) { - Assert(UI->BoxSelect); + Assert(State->BoxSelect); draw_list->AddRectFilled(io.MouseClickedPos[0], io.MousePos, IM_COL32(0, 0, 200, 50)); } } else { - UI->Warp_X = 0; - UI->Warp_Y = 0; + State->Warp_X = 0; + State->Warp_Y = 0; } if (IsItemDeactivated) { - UI->BoxSelect = false; + State->BoxSelect = false; } draw_list->PopClipRect(); @@ -2247,6 +2247,140 @@ ImGui_Timeline(project_data *File, project_state *State, memory *Memory, ui *UI, ImGui::End(); } + +struct key_entry { + ImGuiKey_ KeyIndex; + char *Name; + char *ShiftName; + uint32 Sector; + ImVec2 Offset; + real32 WidthRatio; +}; + +struct shortcut_entry { + ImGuiKey_ Key; + ImGuiModFlags_ Mods; + char *Name; +}; + +#if 0 +static key_entry KeyEntries[] { + { ImGuiKey_Tab, "Tab", "\0", 0, ImVec2(0, 1), 1.5f }, + { ImGuiKey_LeftArrow, "<-", "\0", 2, ImVec2(0, 5), 1.0f }, + { ImGuiKey_RightArrow, "->", "", 2, ImVec2(2, 5), 1.0f }, + { ImGuiKey_UpArrow, "/\\", "", 2, ImVec2(1, 4), 1.0f }, + { ImGuiKey_DownArrow, "\\/", "", 2, ImVec2(1, 5), 1.0f }, + { ImGuiKey_PageUp, "Pg Up", "", 2, ImVec2(2, 0), 1.0f }, + { ImGuiKey_PageDown, "Pg Dn", "", 2, ImVec2(2, 1), 1.0f }, + { ImGuiKey_Home, "Home", "", 2, ImVec2(1, 0), 1.0f }, + { ImGuiKey_End, "End", "", 2, ImVec2(0, 1), 1.0f }, + { ImGuiKey_Insert, "Insert", "", 2, ImVec2(0, 0), 1.0f }, + { ImGuiKey_Delete, "Delete", "", 2, ImVec2(0, 1), 1.0f }, + { ImGuiKey_Backspace, "Backspace", "", 0, ImVec2(13, 1), 2.0f }, + { ImGuiKey_Space, "Space", "", 0, ImVec2(4, 3), 6.5f }, + { ImGuiKey_Enter, "Enter", "", 0, ImVec2(2, 12), 1.5f}, + { ImGuiKey_Escape, "Esc", "", 1, ImVec2(0, 0), 1.0f }, + { ImGuiKey_LeftCtrl, + { ImGuiKey_LeftShift, "L_Shift", "", 0, + { ImGuiKey_LeftAlt, + { ImGuiKey_LeftSuper, + { ImGuiKey_RightCtrl, + { ImGuiKey_RightShift, + { ImGuiKey_RightAlt, + { ImGuiKey_RightSuper, + { ImGuiKey_Menu, + { ImGuiKey_0, "0", ")", 0, ImVec2(10, 0), 1.0f }, + { ImGuiKey_1, "1", "!", 0, ImVec2(1, 0), 1.0f }, + { ImGuiKey_2, "2", "@", 0, ImVec2(2, 0), 1.0f }, + { ImGuiKey_3, "3", "$", 0, ImVec2(3, 0), 1.0f }, + { ImGuiKey_4, "4", "%", 0, ImVec2(4, 0), 1.0f }, + { ImGuiKey_5, "5", "%", 0, ImVec2(5, 0), 1.0f }, + { ImGuiKey_6, "6", "^", 0, ImVec2(6, 0), 1.0f }, + { ImGuiKey_7, "7", "&", 0, ImVec2(7, 0), 1.0f }, + { ImGuiKey_8, "8", "*", 0, ImVec2(8, 0), 1.0f }, + { ImGuiKey_9, "9", "(", 0, ImVec2(9, 0), 1.0f }, + { ImGuiKey_A, "a", "A", 0, ImVec2(1, 2), 1.0f }, + { ImGuiKey_B, "b", "B", 0, ImVec2(5, 3), 1.0f }, + { ImGuiKey_C, "c", "C", 0, ImVec2(3, 3), 1.0f }, + { ImGuiKey_D, "d", "D", 0, ImVec2(3, 2), 1.0f }, + { ImGuiKey_E, "e", "E", 0, ImVec2(0, 2), 1.0f }, + { ImGuiKey_F, "f", "F", 0, ImVec2(4, 2), 1.0f }, + { ImGuiKey_G, "g", "G", 0, ImVec2(5, 2), 1.0f }, + { ImGuiKey_H, "h", "H", 0, ImVec2(6, 2), 1.0f }, + { ImGuiKey_I, "i", "I", 0, ImVec2(0, 7), 1.0f }, + { ImGuiKey_J, "j", "J", 0, ImVec2(7, 2), 1.0f }, + { ImGuiKey_K, "k", "K", 0, ImVec2(8, 2), 1.0f }, + { ImGuiKey_L, "l", "L", 0, ImVec2(9, 2), 1.0f }, + { ImGuiKey_M, "m", "M", 0, ImVec2(7, 3), 1.0f }, + { ImGuiKey_N, "n", "N", 0, ImVec2(6, 3), 1.0f }, + { ImGuiKey_O, "o", "O", 0, ImVec2(8, 1), 1.0f }, + { ImGuiKey_P, "p", "P", 0, ImVec2(9, 1), 1.0f }, + { ImGuiKey_Q, "q", "Q", 0, ImVec2(1, 1), 1.0f }, + { ImGuiKey_R, "r", "R", 0, ImVec2(3, 1), 1.0f }, + { ImGuiKey_S, "s", "S", 0, ImVec2(2, 1), 1.0f }, + { ImGuiKey_T, "t", "T", 0, ImVec2(4, 1), 1.0f }, + { ImGuiKey_U, "u", "U", 0, ImVec2(6, 1), 1.0f }, + { ImGuiKey_V, "v", "V", 0, ImVec2(4, 3), 1.0f }, + { ImGuiKey_W, "w", "W", 0, ImVec2(1, 1), 1.0f }, + { ImGuiKey_X, "x", "X", 0, ImVec2(2, 3), 1.0f }, + { ImGuiKey_Y, "y", "Y", 0, ImVec2(0, 5), 1.0f }, + { ImGuiKey_Z, "z", "Z", 0, ImVec2(1, 3), 1.0f }, + { ImGuiKey_F1, "F1", "", 1, ImVec2(2, 0), 1.0f }, + { ImGuiKey_F2, "F2", "", 1, ImVec2(3, 0), 1.0f }, + { ImGuiKey_F3, "F3", "", 1, ImVec2(4, 0), 1.0f }, + { ImGuiKey_F4, "F4", "", 1, ImVec2(5, 0), 1.0f }, + { ImGuiKey_F5, "F5", "", 1, ImVec2(6.5, 0), 1.0f }, + { ImGuiKey_F6, "F6", "", 1, ImVec2(7.5, 0), 1.0f }, + { ImGuiKey_F7, "F7", "", 1, ImVec2(8.5, 0), 1.0f }, + { ImGuiKey_F8, "F8", "", 1, ImVec2(9.5, 0), 1.0f }, + { ImGuiKey_F9, "F9", "", 1, ImVec2(11, 0), 1.0f }, + { ImGuiKey_F10 "F10","", 1, ImVec2(12, 0), 1.0f }, + { ImGuiKey_F11 "F11","", 1, ImVec2(13, 0), 1.0f }, + { ImGuiKey_F12 "F12","", 1, ImVec2(14, 0), 1.0f }, + { ImGuiKey_Apostrophe, "\'", "\"", 1, ImVec2(11, 2), 1.0f }, + { ImGuiKey_Comma, ",", "<", 0, ImVec2(8, 3), 1.0f }, + { ImGuiKey_Minus, "-", "_", 0, ImVec2(11, 1), 1.0f}; + { ImGuiKey_Period, ".", ">", 0, ImVec2(9, 3), 1.0f }, + { ImGuiKey_Slash, "/", "?", 0, ImVec2(10, 3), 1.0f }, + { ImGuiKey_Semicolon, ";", ":", 0, ImVec2(10, 2), 1.0f }, + { ImGuiKey_Equal, "=", "+", 0, ImVec2(12, 1), 1.0f }, + { ImGuiKey_LeftBracket, "[", "{", 0, ImVec2(0, 10), 1.0f }, + { ImGuiKey_Backslash, "\\","|", 0, ImVec2(0, 12), 1.5f }, + { ImGuiKey_RightBracket,"]", "}", 0, ImVec2(0, 11), 1.0f }, + { ImGuiKey_GraveAccent, "`", "~", 0, ImVec2(0, 0), 1.0f }, + { ImGuiKey_CapsLock, "Caps lock", "", 1, ImVec2(0, 2), 1.75f }; + { ImGuiKey_ScrollLock, + { ImGuiKey_NumLock, + { ImGuiKey_PrintScreen, + { ImGuiKey_Pause, + { ImGuiKey_Keypad0, + { ImGuiKey_Keypad1, + { ImGuiKey_Keypad2, + { ImGuiKey_Keypad3, + { ImGuiKey_Keypad4, + { ImGuiKey_Keypad5, + { ImGuiKey_Keypad6, + { ImGuiKey_Keypad7, + { ImGuiKey_Keypad8, + { ImGuiKey_Keypad9, + { ImGuiKey_KeypadDecimal, + { ImGuiKey_KeypadDivide, + { ImGuiKey_KeypadMultiply, + { ImGuiKey_KeypadSubtract, + { ImGuiKey_KeypadAdd, + { ImGuiKey_KeypadEnter, + { ImGuiKey_KeypadEqual, +}; +#endif + + +static shortcut_entry ShortcutArray[] { + { ImGuiKey_1, ImGuiModFlags_None, "Enable debug UI" }, + { ImGuiKey_2, ImGuiModFlags_None, "Toggle precomp view" } +}; + +static ImVec2 SectorOffset[] = { ImVec2(0, 1.5), ImVec2(0, 0) }; + static void ImGui_Popups(project_data *File, project_state *State, ui *UI, memory *Memory, ImGuiIO io) { @@ -2258,8 +2392,17 @@ ImGui_Popups(project_data *File, project_state *State, ui *UI, memory *Memory, I case popup_saveas: { ImGui::OpenPopup("Save as"); + ImVec2 Size(300, 300); + Assert(0); + ImGui::SetNextWindowPos(ImVec2(300, 800)); + ImGui::SetNextWindowSize(Size); + ImGui::SetKeyboardFocusHere(); + } break; + case popup_keybinds: + { + ImGui::OpenPopup("Keybinds"); ImGui::SetNextWindowPos(ImVec2(300, 800)); - ImGui::SetNextWindowSize(ImVec2(300, 300)); + ImGui::SetNextWindowSize(ImVec2(500, 300)); ImGui::SetKeyboardFocusHere(); } break; default: @@ -2282,6 +2425,15 @@ ImGui_Popups(project_data *File, project_state *State, ui *UI, memory *Memory, I } ImGui::EndPopup(); } + if (ImGui::BeginPopupModal("Keybinds")) { +#if 0 + real32 KeySize = 20; + for (int k = 0; k < AmountOf(KeyEntries); k++) { + key_entry KeyEntry = KeyArray[k]; + ImVec2 Offset_ScreenPos = ImVec2(KeySize, KeySize) * (SectorOffset[KeyEntry.Sector] + + } +#endif + } } static void @@ -2336,13 +2488,13 @@ ImGui_ProcessInputs(project_data *File, project_state *State, ui *UI, memory *Me MainComp->Frame_Start = State->Frame_Current; } if (ImGui::IsKeyPressed(ImGuiKey_Tab)) { - UI->TimelineMode = (UI->TimelineMode == timeline_mode_default) ? timeline_mode_graph : timeline_mode_default; + State->TimelineMode = (State->TimelineMode == timeline_mode_default) ? timeline_mode_graph : timeline_mode_default; UI->GraphZoomSize = ImVec2(0, 0); UI->GraphMoveSize = ImVec2(0, 0); } if (!io.KeyCtrl) { - if (UI->FocusedWindow == focus_timeline) { - if (UI->TimelineMode == timeline_mode_default) { + if (State->FocusedWindow == focus_timeline) { + if (State->TimelineMode == timeline_mode_default) { if (ImGui::IsKeyPressed(ImGuiKey_G)) { Layer_ToggleChannel(File, Memory, 0); Layer_ToggleChannel(File, Memory, 1); @@ -2360,7 +2512,7 @@ ImGui_ProcessInputs(project_data *File, project_state *State, ui *UI, memory *Me Layer_ToggleChannel(File, Memory, 7); } } - } else if (UI->TimelineMode == timeline_mode_graph) { + } else if (State->TimelineMode == timeline_mode_graph) { if (ImGui::IsKeyPressed(ImGuiKey_G)) { State->Interact_Offset[2] = io.MousePos.x; State->Interact_Offset[3] = io.MousePos.y; @@ -2375,7 +2527,7 @@ ImGui_ProcessInputs(project_data *File, project_state *State, ui *UI, memory *Me State->Interact_Active = interact_type_keyframe_scale; } } - } else if (UI->FocusedWindow == focus_viewport) { + } else if (State->FocusedWindow == focus_viewport) { if (ImGui::IsKeyPressed(ImGuiKey_T)) { State->HotkeyInput = hotkey_transform; } @@ -2431,7 +2583,22 @@ ImGui_ProcessInputs(project_data *File, project_state *State, ui *UI, memory *Me } } + if (io.KeyShift && ImGui::IsKeyPressed(ImGuiKey_Slash)) + { + State->ImGuiPopups = popup_keybinds; + } + #if DEBUG + if (ImGui::IsKeyPressed(ImGuiKey_3)) + { + State->ImGuiPopups = popup_keybinds; + } + if (ImGui::IsKeyPressed(ImGuiKey_F)) + { + sprintf(State->DummyName, "test2"); + File_Open(File, State, Memory, State->DummyName); + State->UpdateFrame = true; + } if (ImGui::IsKeyPressed(ImGuiKey_0)) { Debug.ReloadUI ^= 1; @@ -2523,8 +2690,8 @@ ImGui_Menu(project_data *File, project_state *State, ui *UI, memory *Memory, ImG if (ImGui::BeginMenu("Window")) { #if STABLE - if (ImGui::Selectable("Stable Diffusion tools", State->StableEnabled)) - State->StableEnabled ^= 1; + if (ImGui::Selectable("Stable Diffusion tools", UI->StableEnabled)) + UI->StableEnabled ^= 1; ImGui::EndMenu(); #endif } diff --git a/stable_diffusion.cpp b/stable_diffusion.cpp index 3d0c26b..4da327d 100644 --- a/stable_diffusion.cpp +++ b/stable_diffusion.cpp @@ -254,12 +254,12 @@ static void Curl_Main(project_data *File, project_state *State, memory *Memory, curl_state *MainHandle, curl_state *ProgHandle) { if (State->CurlActive == -1) { - Curl_GET_Init(MainHandle, State->Dump1, State->JSONPayload, State->SD.ServerAddress, State->SD.Mode); + Curl_GET_Init(MainHandle, State->Dump1, State->JSONPayload, File->UI.SD.ServerAddress, File->UI.SD.Mode); Curl_Prog_Init(ProgHandle, State->Dump2); State->CurlActive = 1; } else { if (Curl_Check(MainHandle) == 1) { - SD_JSONToSource(File, State, Memory, State->Dump1, State->SD.Height, State->SD.Width); + SD_JSONToSource(File, State, Memory, State->Dump1, File->UI.SD.Height, File->UI.SD.Width); Curl_StopAll(State, ProgHandle, MainHandle); } uint64 Time = ImGui::GetTime(); -- cgit v1.2.3