summaryrefslogtreecommitdiff
path: root/my_imgui_widgets.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'my_imgui_widgets.cpp')
-rw-r--r--my_imgui_widgets.cpp198
1 files changed, 149 insertions, 49 deletions
diff --git a/my_imgui_widgets.cpp b/my_imgui_widgets.cpp
index 0b1e017..cf33666 100644
--- a/my_imgui_widgets.cpp
+++ b/my_imgui_widgets.cpp
@@ -8,13 +8,13 @@ ImGui_InteractSliderProperty(project_state *State, memory *Memory, property_chan
{
ImGui::DragScalar(Property->Name, ImGuiDataType_Float, &Property->CurrentValue,
Property->ScrubVal, &Property->MinVal, &Property->MaxVal, "%f");
+ if (ImGui::IsItemActive()) {
+ State->UpdateFrame = true;
+ }
/*
if (ImGui::IsItemActivated()) {
State->InteractCache[0] = Property->CurrentValue.f;
}
- if (ImGui::IsItemActive()) {
- State->UpdateFrame = true;
- }
if (ImGui::IsItemDeactivatedAfterEdit()) {
if (ImGui::IsKeyPressed(ImGuiKey_Escape)) {
Property->CurrentValue.f = State->InteractCache[0];
@@ -62,6 +62,17 @@ ImGui_PropertiesPanel(project_data *File, project_state *State, ui *UI, memory *
ImGui_InteractSliderProperty(State, Memory, Property);
ImGui::PopID();
}
+ if (Layer->IsPrecomp) {
+ block_composition *Comp = (block_composition *)Memory_Block_AddressAtIndex(Memory, F_Precomps, Layer->Block_Source_Index);
+ ImGui::DragScalar("Width", ImGuiDataType_U16, &Comp->Width);
+ if (ImGui::IsItemActive()) {
+ State->UpdateFrame = true;
+ }
+ ImGui::DragScalar("Height", ImGuiDataType_U16, &Comp->Height);
+ if (ImGui::IsItemActive()) {
+ State->UpdateFrame = true;
+ }
+ }
ImGui::End();
} else {
ImGui::Begin("Properties: empty###Properties");
@@ -214,6 +225,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;
}
ImGui::EndPopup();
}
@@ -236,9 +248,10 @@ ImGui_File(project_data *File, project_state *State, memory *Memory, ImGuiIO io,
ImGui::End();
}
-#if SD
+#if STABLE
static void
-ImGui_SD_Thumbnail(project_data *File, project_state *State, ui *UI, memory *Memory, ImGuiIO io, uint16 *SourceArray, uint16 SourceCount, GLuint textureID)
+ImGui_SD_Thumbnail(project_data *File, project_state *State, ui *UI, memory *Memory, ImGuiIO io,
+ sorted_comp_info *SortedCompArray, sorted_layer *SortedLayerArray, uint16 *SourceArray, uint16 SourceCount)
{
ImGui::Begin("SD gallery");
ImDrawList* draw_list = ImGui::GetWindowDrawList();
@@ -252,43 +265,72 @@ ImGui_SD_Thumbnail(project_data *File, project_state *State, ui *UI, memory *Mem
int test[16];
int count = 0;
// draw_list->AddImage((void *)(intptr_t)textureID, ViewportMin, ViewportMax);
- uint32 T_Height = 256;
+ uint32 T_Height = 128;
real32 RowPercent = (real32)ViewportScale.x / T_Height;
uint32 PerRow = (uint32)RowPercent;
uint32 UI_Size = T_Height;
+ bool32 Active = false;
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);
+ ImVec2 ImgMin = ViewportMin + ImVec2(X * UI_Size, Y * UI_Size);
+ ImVec2 ImgMax = ImgMin + ImVec2(UI_Size * Ratio, UI_Size);
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));
+ ImGui::Button("##thumbnail", 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);
+ if (ImGui::IsItemHovered()) {
+ int h = 0, c = 0, a = 0;
+ while (Block_Loop(Memory, F_Layers, File->Layer_Count, &h, &c, &a)) {
+ block_layer *Layer = (block_layer *)Memory_Block_AddressAtIndex(Memory, F_Layers, a);
+ if (Layer->Block_Source_Index == SourceArray[i] && Layer->IsSelected) {
+ State->PreviewLayer = a;
+ break;
+ }
+ }
+ State->PreviewSource = SourceArray[i];
+ State->UpdateFrame = true;
+ Active = true;
+ }
+
+ if (ImGui::IsItemClicked() || ImGui::IsItemClicked(ImGuiMouseButton_Right)) {
+ if (!io.KeyShift && !Source->IsSelected) {
+ Source_DeselectAll(File, Memory);
+ }
+ Source->IsSelected = 1;
+ }
+ ImGui::OpenPopupOnItemClick("temptosource", ImGuiPopupFlags_MouseButtonRight);
+ }
+ if (State->PreviewSource != -1 && !Active) {
+ State->PreviewSource = -1;
+ State->PreviewLayer = -1;
+ State->UpdateFrame = true;
}
+ if (ImGui::BeginPopup("temptosource")) {
+ if (ImGui::MenuItem("Create layer from source")) {
+ Source_UICreateButton(File, State, Memory, SortedCompArray, SortedLayerArray);
+ State->UpdateKeyframes = true;
+ }
+ ImGui::EndPopup();
+ }
+
ImGui::End();
}
static void
-ImGui_SD_Prompt(project_data *File, project_state *State, ui *UI, memory *Memory, ImGuiIO io)
+ImGui_SD_Prompt(project_data *File, project_state *State, ui *UI, memory *Memory, ImGuiIO io,
+ sorted_comp_info *SortedCompArray, sorted_layer *SortedLayerArray)
{
+ 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;
int Size = ImGui::GetFontSize();
@@ -296,35 +338,54 @@ ImGui_SD_Prompt(project_data *File, project_state *State, ui *UI, memory *Memory
if (ImGui::Button("Generate!", ImVec2(Size*8, Size*2))) {
if (!State->CurlActive) {
if (SD->Mode) {
- block_layer *Layer = (block_layer *)Memory_Block_AddressAtIndex(Memory, F_Layers, 0);
- block_source *Source = (block_source *)Memory_Block_AddressAtIndex(Memory, F_Sources, Layer->Block_Source_Index);
- cache_entry *Entry = Memory_Cache_Search(State, Memory, cache_entry_type_source, Layer->Block_Source_Index, 0);
- Assert(Entry->IsCached);
- void *BitmapAddress = Memory_Block_Bitmap_AddressAtIndex(Memory, Entry->Block_StartIndex);
- uint64 Size = Source->Width * Source->Height * Source->BytesPerPixel;
+ block_layer *Layer = NULL;
+ for (int i = SortedCompInfo->LayerCount - 1; i >= 0; i--) {
+ sorted_layer SortEntry = SortedLayerInfo[i];
+ uint32 Index_Physical = SortEntry.Block_Layer_Index;
+ block_layer *TestLayer = (block_layer *)Memory_Block_AddressAtIndex(Memory, F_Layers, Index_Physical);
+ if (TestLayer->IsSelected) {
+ Layer = TestLayer;
+ break;
+ }
+ }
+ if (Layer) {
+ block_source *Source = (block_source *)Memory_Block_AddressAtIndex(Memory, F_Sources, Layer->Block_Source_Index);
+ void *BitmapAddress;
+ if (Source->Type == source_type_principal) {
+ block_source *Source = (block_source *)Memory_Block_AddressAtIndex(Memory, F_Sources, Layer->Block_Source_Index);
+ BitmapAddress = Memory_Block_AddressAtIndex(Memory, F_PrincipalBitmaps, Source->Bitmap_Index, 0);
+ }
+ else if (Source->Type == source_type_file) {
+ cache_entry *Entry = Memory_Cache_Search(State, Memory, cache_entry_type_source, Layer->Block_Source_Index, 0);
+ Assert(Entry->IsCached);
+ BitmapAddress = Memory_Block_Bitmap_AddressAtIndex(Memory, Entry->Block_StartIndex);
+ }
+ uint64 Size = Source->Width * Source->Height * Source->BytesPerPixel;
- int32 len = 0;
- uint8 *PNGBitmap = stbi_write_png_to_mem((uint8 *)BitmapAddress, Source->Width * Source->BytesPerPixel,
- Source->Width, Source->Height, Source->BytesPerPixel, &len);
- Assert(PNGBitmap);
+ int32 len = 0;
+ uint8 *PNGBitmap = stbi_write_png_to_mem((uint8 *)BitmapAddress, Source->Width * Source->BytesPerPixel,
+ Source->Width, Source->Height, Source->BytesPerPixel, &len);
+ Assert(PNGBitmap);
- uint64 EncodedEstimateSize = base64_encode_size(Size);
- uint8 *EncodedOutput = (uint8 *)Memory_PushScratch(Memory, EncodedEstimateSize);
- uint64 EncodedTrueSize = 0;
+ uint64 EncodedEstimateSize = base64_encode_size(Size);
+ uint8 *EncodedOutput = (uint8 *)Memory_PushScratch(Memory, EncodedEstimateSize);
+ uint64 EncodedTrueSize = 0;
- base64_encode((uint8 *)PNGBitmap, len, EncodedOutput, &EncodedTrueSize);
- Assert(EncodedOutput[EncodedTrueSize] == '\0');
- // printf("%s", EncodedOutput);
+ base64_encode((uint8 *)PNGBitmap, len, EncodedOutput, &EncodedTrueSize);
+ Assert(EncodedOutput[EncodedTrueSize] == '\0');
+ // printf("%s", EncodedOutput);
- STBIW_FREE(PNGBitmap);
+ STBIW_FREE(PNGBitmap);
- SD_AssembleJSON(SD, (char *)State->JSONPayload, EncodedOutput);
- Memory_PopScratch(Memory, EncodedEstimateSize);
+ SD_AssembleJSON(SD, (char *)State->JSONPayload, EncodedOutput);
+ Memory_PopScratch(Memory, EncodedEstimateSize);
+ State->CurlActive = -1;
+ }
} else {
SD_AssembleJSON(SD, State->JSONPayload);
// SD_AssembleJSON(SD, (char *)State->Dump2);
+ State->CurlActive = -1;
}
- State->CurlActive = -1;
}
}
ImGui::PopStyleColor();
@@ -932,7 +993,7 @@ ImGui_Viewport(project_data *File, project_state *State, ui *UI, memory *Memory,
// Point to zoom in on if Z is held
UI->TempZoomRatio = ImGui_ScreenPointToCompUV(ViewportMin, UI->CompPos, UI->CompZoom, io.MousePos);
- if (State->Tool == tool_brush) {
+ if (State->Tool == tool_brush && State->Interact_Active != interact_type_brush) {
sorted_layer *SortedLayerInfo = Layer_GetSortedArray(SortedLayerArray, SortedCompArray, File->PrincipalCompIndex);
sorted_comp_info SortedCompInfo = SortedCompArray[File->PrincipalCompIndex];
if (!io.KeyCtrl) {
@@ -942,6 +1003,7 @@ ImGui_Viewport(project_data *File, project_state *State, ui *UI, memory *Memory,
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) {
+ Arbitrary_Zero((uint8 *)State->Brush.TransientBitmap, 2048*2048*4);
State->Interact_Active = interact_type_brush;
State->Brush.LayerToPaint_Index = Index_Physical;
break;
@@ -949,9 +1011,9 @@ 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);
- Arbitrary_Zero((uint8 *)State->Brush.TransientBitmap, 2048*2048*4);
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);
@@ -1010,7 +1072,6 @@ 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, 0);
ImVec2 MouseDelta = io.MouseDelta;
real32 Delta = MouseDelta.x + MouseDelta.y;
if (Delta != 0.0f) {
@@ -1024,13 +1085,29 @@ ImGui_Viewport(project_data *File, project_state *State, ui *UI, memory *Memory,
ImVec2 MousePos = io.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;
}
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->UpdateFrame = true;
}
}
@@ -1136,8 +1213,8 @@ ImGui_GraphInfo(project_data *File, project_state *State, memory *Memory, ui *UI
for (int h = 0; h < AmountOf(Layer->Property); h++) {
property_channel *Property = &Layer->Property[h];
if (Property->Block_Bezier_Count) {
- sorted_property_info *InfoLocation = SortedPropertyInfo + (i * 7) + h;
- uint16 *ArrayLocation = SortedPropertyArray + (i * 7 * MAX_KEYFRAMES_PER_BLOCK) + (h * MAX_KEYFRAMES_PER_BLOCK);
+ sorted_property_info *InfoLocation = Property_GetSortedInfo(SortedPropertyInfo, i, h);
+ uint16 *ArrayLocation = Property_GetSortedArray(SortedPropertyArray, i, h);
ImGui::PushID(Property);
if (ImGui::Selectable(Property->Name, InfoLocation->IsGraphSelected)) {
Property_DeselectAll(File, Memory, SortedPropertyArray);
@@ -1265,8 +1342,8 @@ ImGui_Timeline_DrawGraph(project_data *File, project_state *State, memory *Memor
for (int h = 0; h < AmountOf(Layer->Property); h++) {
property_channel *Property = &Layer->Property[h];
- sorted_property_info *InfoLocation = SortedPropertyInfo + (i * 7) + h;
- uint16 *ArrayLocation = SortedPropertyArray + (i * 7 * MAX_KEYFRAMES_PER_BLOCK) + (h * MAX_KEYFRAMES_PER_BLOCK);
+ sorted_property_info *InfoLocation = Property_GetSortedInfo(SortedPropertyInfo, i, h);
+ uint16 *ArrayLocation = Property_GetSortedArray(SortedPropertyArray, i, h);
ImGui::PushID(Property);
if (Property->Block_Bezier_Count) {
real32 MinY, MaxY;
@@ -1548,6 +1625,7 @@ ImGui_Timeline_DrawPrecomp(project_data *File, project_state *State, memory *Mem
if (ImGui::BeginPopup("layerpopup")) {
if (ImGui::MenuItem("Pre-compose layer")) {
Precomp_UICreateButton(File, State, Memory, CompIndex, SortedCompInfo, SortedLayerInfo);
+ State->UpdateKeyframes = true;
}
if (ImGui::BeginMenu("Layer color"))
{
@@ -1565,6 +1643,23 @@ ImGui_Timeline_DrawPrecomp(project_data *File, project_state *State, memory *Mem
ImGui::PopStyleVar();
ImGui::EndMenu();
}
+ uint32 *item_current_idx = (uint32 *)&Layer->BlendMode; // Here we store our selection data as an index.
+ if (ImGui::BeginListBox("Blend mode"))
+ {
+ for (int n = 0; n < IM_ARRAYSIZE(BlendmodeNames); n++)
+ {
+ const bool is_selected = (*item_current_idx == n);
+ if (ImGui::Selectable(BlendmodeNames[n], is_selected)) {
+ *item_current_idx = n;
+ State->UpdateFrame = true;
+ }
+
+ // Set the initial focus when opening the combo (scrolling + keyboard navigation focus)
+ if (is_selected)
+ ImGui::SetItemDefaultFocus();
+ }
+ ImGui::EndListBox();
+ }
ImGui::EndPopup();
}
@@ -1618,9 +1713,9 @@ ImGui_Timeline_DrawPrecomp(project_data *File, project_state *State, memory *Mem
for (int h = 0; h < AmountOf(Layer->Property); h++) {
property_channel *Property = &Layer->Property[h];
if (Property->IsToggled) {
- // sorted_property_info *InfoLocation = SortedPropertyInfo + (i * 7) + h;
+ sorted_property_info *InfoLocation = Property_GetSortedInfo(SortedPropertyInfo, i, h);
+ uint16 *ArrayLocation = Property_GetSortedArray(SortedPropertyArray, i, h);
ImVec2 GraphPos(TimelineAbsolutePos.x, Layer_ScreenPos_Min.y + (Layer_ScreenSize.y * 2) + (Layer_ScreenSize.y * Channel));
- uint16 *ArrayLocation = SortedPropertyArray + (i * 7 * MAX_KEYFRAMES_PER_BLOCK) + (h * MAX_KEYFRAMES_PER_BLOCK);
ImGui_Timeline_DrawKeySheet(File, State, Memory, UI, io, draw_list, Property, ArrayLocation,
Increment, GraphPos, TimelineMoveSize, TimelineZoomSize,
TimelineSize, TimelineSizeWithBorder, LayerIncrement);
@@ -2019,12 +2114,14 @@ ImGui_ProcessInputs(project_data *File, project_state *State, ui *UI, memory *Me
block_composition *MainComp = (block_composition *)Memory_Block_AddressAtIndex(Memory, F_Precomps, File->PrincipalCompIndex);
State->Frame_Current = ((State->Frame_Current - 1) < 0) ? 0 : State->Frame_Current - 1;
State->UpdateFrame = true;
+ State->UpdateKeyframes = true;
}
if (ImGui::IsKeyPressed(ImGuiKey_E)) {
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;
+ State->UpdateKeyframes = true;
} else {
State->Brush.EraseMode ^= 1;
}
@@ -2140,6 +2237,9 @@ 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_S)) {
+ File_SaveAs(File, State, Memory, "test");
+ }
if (ImGui::IsKeyPressed(ImGuiKey_C)) {
State->HotkeyInput = hotkey_copy;
}