summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xbuild.sh1
-rw-r--r--createcalls.cpp30
-rw-r--r--debug.h1
-rw-r--r--main.cpp37
-rw-r--r--main.h6
-rw-r--r--memory.cpp7
-rw-r--r--my_imgui_widgets.cpp67
-rw-r--r--stable_diffusion.h4
8 files changed, 107 insertions, 46 deletions
diff --git a/build.sh b/build.sh
index 8fbf980..69bb75d 100755
--- a/build.sh
+++ b/build.sh
@@ -89,6 +89,7 @@ GLAD_FLAGS="
-Ilib/glad/include
"
+[[ -d bin ]] || mkdir bin
clang $IMGUI_FLAGS -o bin/my_imgui_internal_widgets.o my_imgui_internal_widgets.cpp
diff --git a/createcalls.cpp b/createcalls.cpp
index d1d423b..d3da841 100644
--- a/createcalls.cpp
+++ b/createcalls.cpp
@@ -66,10 +66,13 @@ File_Open(project_state *State, memory *Memory, char *Filename)
}
*/
-static void
+static bool32
File_Open(project_data *File, project_state *State, memory *Memory, char *Filename)
{
SDL_RWops *FileHandle = SDL_RWFromFile(Filename, "r+b");
+ if (!FileHandle) {
+ return 0;
+ }
uint64 FileSize = SDL_RWseek(FileHandle, 0, RW_SEEK_END);
void *CompressedData = Memory_PushScratch(Memory, FileSize);
SDL_RWseek(FileHandle, 0, RW_SEEK_SET);
@@ -77,6 +80,18 @@ File_Open(project_data *File, project_state *State, memory *Memory, char *Filena
SDL_RWclose(FileHandle);
Data_Decompress(Memory, CompressedData, FileSize, File, 0);
Memory_PopScratch(Memory, FileSize);
+
+ // Temp sources aren't cleaned out on file close, so we do it here.
+ int h = 0, c = 0, i = 0;
+ int Count = File->Source_Count;
+ while (Block_Loop(Memory, F_Sources, Count, &h, &c, &i)) {
+ block_source *Source = (block_source *)Memory_Block_AddressAtIndex(Memory, F_Sources, i);
+ if (Source->Type == source_type_principal_temp) {
+ Source->Occupied = 0;
+ File->Source_Count--;
+ }
+ }
+ return 1;
}
static bool32
@@ -1215,7 +1230,7 @@ void Bitmap_SwapData(uint8 *Address_0, uint8 *Address_1, uint64 Size, uint16 Byt
uint64 RemainderBytes = Size % ByteOffset;
Assert(BytesPerPixel == 8);
-#if NEON
+#if ARM
Assert(InstructionMode != instruction_mode_neon);
#else
if (BytesPerPixel == 4) {
@@ -1306,9 +1321,12 @@ PaintTest(brush_info B, void *Buffer, rectangle RenderRegion)
if (!B.EraseMode) {
A_Blend = LayerAlpha + BrushAlpha;
- R_Blend = (R_Layer * (1.0f - BrushAlpha)) + (B.R_Brush * BrushAlpha);
- G_Blend = (G_Layer * (1.0f - BrushAlpha)) + (B.G_Brush * BrushAlpha);
- B_Blend = (B_Layer * (1.0f - BrushAlpha)) + (B.B_Brush * BrushAlpha);
+ // R_Blend = (R_Layer * (1.0f - BrushAlpha)) + (B.R_Brush * BrushAlpha);
+ // G_Blend = (G_Layer * (1.0f - BrushAlpha)) + (B.G_Brush * BrushAlpha);
+ // B_Blend = (B_Layer * (1.0f - BrushAlpha)) + (B.B_Brush * BrushAlpha);
+ R_Blend = B.R_Brush;
+ G_Blend = B.G_Brush;
+ B_Blend = B.B_Brush;
} else {
A_Blend = A_Layer * (1.0f - BrushAlpha);
R_Blend = R_Layer;
@@ -1407,6 +1425,7 @@ PaintTest_AVX2(brush_info B, void *Buffer, rectangle RenderRegion)
}
}
}
+#endif
static void
Brush_Render(project_state *State, ui *UI, layer_transforms T_Layer, block_composition *MainComp, block_source *Source, void *BitmapAddress, ImVec2 ViewportMin, ImVec2 MousePos)
@@ -1420,7 +1439,6 @@ Brush_Render(project_state *State, ui *UI, layer_transforms T_Layer, block_compo
PaintTest(B, BitmapAddress, B.LayerBounds);
}
}
-#endif
#if 0
diff --git a/debug.h b/debug.h
index 6860bdb..1935365 100644
--- a/debug.h
+++ b/debug.h
@@ -28,6 +28,7 @@ struct project_debug
{
debug_temp Temp;
bool32 ToggleWindow = 1;
+ bool32 ReloadUI = true;
bool32 NoThreading = 0;
uint64 PixelCountTransparent;
uint64 PixelCountRendered;
diff --git a/main.cpp b/main.cpp
index 950d548..10e74ec 100644
--- a/main.cpp
+++ b/main.cpp
@@ -184,13 +184,18 @@ Main_InputTest(project_data *File, project_state *State, memory *Memory, ui *UI,
ImGui_DebugUndoTree(Memory, State);
}
-#if 0
if (State->Initializing == 3) {
Source_UICreateButton(File, State, Memory, Sorted.CompArray, Sorted.LayerArray);
block_layer *Layer = (block_layer *)Memory_Block_AddressAtIndex(Memory, F_Layers, 0);
- Layer->Block_Effect_Index[0] = Effect_Init(State, Memory, 0, Layer->Block_Effect_Count);
- Layer->Block_Effect_Count = 1;
+ Layer->IsSelected = true;
+ // Layer->Block_Effect_Index[0] = Effect_Init(State, Memory, 0, Layer->Block_Effect_Count);
+ // Layer->Block_Effect_Count = 1;
}
+ // if (State->Initializing == 2) {
+ // block_composition *MainComp = (block_composition *)Memory_Block_AddressAtIndex(Memory, F_Precomps, File->PrincipalCompIndex);
+ // Precomp_UICreateButton(File, State, Memory, MainComp, *Sorted.CompArray, Sorted.LayerArray);
+ // }
+#if 0
// Layera->x.IsToggled = true;
// Layera->y.IsToggled = true;
// block_layer *Layerb = (block_layer *)Memory_Block_AddressAtIndex(Memory, F_Layers, 1);
@@ -588,6 +593,11 @@ int main(int argc, char *argv[]) {
File->Comp_Count = 1;
+ {
+ uint16 SourceIndex = Source_Generate(File, State, &Memory, (void *)"../asset/a_small.jpg");
+ block_source *Source = (block_source *)Memory_Block_AddressAtIndex(&Memory, F_Sources, File->Source_Count - 1);
+ Source->IsSelected = true;
+ }
#if 0
const char *myb[] = { "../asset/hand/IMG_4239.jpg", "../asset/hand/IMG_4242.jpg", "../asset/hand/IMG_4243.jpg",
"../asset/hand/IMG_4244.jpg", "../asset/hand/IMG_4248.jpg", "../asset/hand/IMG_4249.jpg" };
@@ -597,11 +607,6 @@ int main(int argc, char *argv[]) {
block_source *Source = (block_source *)Memory_Block_AddressAtIndex(&Memory, F_Sources, File->Source_Count - 1);
Source->IsSelected = true;
}
- {
- uint16 SourceIndex = Source_Generate(File, State, &Memory, (void *)"../asset/hand/a.png");
- block_source *Source = (block_source *)Memory_Block_AddressAtIndex(&Memory, F_Sources, File->Source_Count - 1);
- Source->IsSelected = true;
- }
{
uint16 SourceIndex = Source_Generate(File, State, &Memory, (void *)"../asset/hand/c.png");
@@ -717,16 +722,6 @@ int main(int argc, char *argv[]) {
Brush_CalcBitmapAlphaFromSize(&Memory, &State->Brush, 4);
State_BindBrushTexture(&Memory, &State->Brush, 4);
- File_Open(File, State, &Memory, "test");
- int h = 0, c = 0, i = 0;
- int Count = File->Source_Count;
- while (Block_Loop(&Memory, F_Sources, Count, &h, &c, &i)) {
- block_source *Source = (block_source *)Memory_Block_AddressAtIndex(&Memory, F_Sources, i);
- if (Source->Type == source_type_principal_temp) {
- Source->Occupied = 0;
- File->Source_Count--;
- }
- }
#if STABLE
curl_global_init(CURL_GLOBAL_ALL);
@@ -760,7 +755,13 @@ int main(int argc, char *argv[]) {
Assert(Debug.ScratchState == 0);
+#if DEBUG
+ if (Debug.ReloadUI) {
+ Main_RenderUI(io, clear_color, window);
+ }
+#else
Main_RenderUI(io, clear_color, window);
+#endif
if (State->Initializing)
State->Initializing--;
diff --git a/main.h b/main.h
index ed74fa6..f55e6fc 100644
--- a/main.h
+++ b/main.h
@@ -404,6 +404,7 @@ struct project_state
void *Dump1;
void *Dump2;
+ char DummyName[512];
char DummyName2[512];
bool32 IsRunning = 1;
@@ -496,7 +497,7 @@ struct block_source
struct property_channel {
uint8 Occupied;
- char *Name;
+ char *Name; // TODO(fox): Delete this.
uint16 Block_Bezier_Index[MAX_KEYFRAME_BLOCKS];
uint16 Block_Bezier_Count;
uint16 Keyframe_Count;
@@ -510,6 +511,9 @@ struct property_channel {
bool32 IsToggled;
};
+char *DefaultChannel[] = { "X Position", "Y Position", "Anchor X", "Anchor Y",
+ "Rotation", "Scale", "Opacity", "Frame Number" };
+
struct block_layer {
uint8 Occupied;
diff --git a/memory.cpp b/memory.cpp
index 28f1797..30574e9 100644
--- a/memory.cpp
+++ b/memory.cpp
@@ -107,11 +107,16 @@ Memory_Block_PrincipalBitmap_AllocateNew(project_data *File, project_state *Stat
{
int h = 0, c = 0, i = 0;
int MaxBlockIndex = -1;
+ int PrincipalCount = 0;
while (Block_Loop(Memory, F_Sources, File->Source_Count, &h, &c, &i)) {
block_source *Source = (block_source *)Memory_Block_AddressAtIndex(Memory, F_Sources, i);
- if (Source->Bitmap_Index > MaxBlockIndex && Source->Type == source_type_principal)
+ if (Source->Type == source_type_principal || Source->Type == source_type_principal_temp)
+ PrincipalCount++;
+ if (Source->Bitmap_Index > MaxBlockIndex)
MaxBlockIndex = i;
}
+ if (!PrincipalCount)
+ return 0;
block_source Source = *(block_source *)Memory_Block_AddressAtIndex(Memory, F_Sources, MaxBlockIndex);
uint32 LastBlock = Source.Bitmap_Index;
diff --git a/my_imgui_widgets.cpp b/my_imgui_widgets.cpp
index 70d4ffc..5bc78bd 100644
--- a/my_imgui_widgets.cpp
+++ b/my_imgui_widgets.cpp
@@ -4,9 +4,9 @@
#include "imgui_helper_widgets.cpp"
static void
-ImGui_InteractSliderProperty(project_state *State, memory *Memory, property_channel *Property)
+ImGui_InteractSliderProperty(project_state *State, memory *Memory, property_channel *Property, char *Name)
{
- ImGui::DragScalar(Property->Name, ImGuiDataType_Float, &Property->CurrentValue,
+ ImGui::DragScalar(Name, ImGuiDataType_Float, &Property->CurrentValue,
Property->ScrubVal, &Property->MinVal, &Property->MaxVal, "%f");
if (ImGui::IsItemActive()) {
State->UpdateFrame = true;
@@ -59,7 +59,8 @@ ImGui_PropertiesPanel(project_data *File, project_state *State, ui *UI, memory *
History_Entry_End(Memory);
}
ImGui::SameLine();
- ImGui_InteractSliderProperty(State, Memory, Property);
+ char *Name = DefaultChannel[h];
+ ImGui_InteractSliderProperty(State, Memory, Property, Name);
ImGui::PopID();
}
for (int i = 0; i < Layer->Block_Effect_Count; i++)
@@ -75,7 +76,7 @@ ImGui_PropertiesPanel(project_data *File, project_state *State, ui *UI, memory *
property_channel *Property = (property_channel *)Memory_Block_AddressAtIndex(Memory, F_Properties, Effect.Block_Property_Index[c]);
ImGui::PushID(Property);
if (ChannelHeader.DisplayType == property_display_type_standard) {
- ImGui_InteractSliderProperty(State, Memory, Property);
+ ImGui_InteractSliderProperty(State, Memory, Property, ChannelHeader.Name);
} else if (ChannelHeader.DisplayType == property_display_type_color) {
property_channel *Property1 = (property_channel *)Memory_Block_AddressAtIndex(Memory, F_Properties, Effect.Block_Property_Index[c+1]);
property_channel *Property2 = (property_channel *)Memory_Block_AddressAtIndex(Memory, F_Properties, Effect.Block_Property_Index[c+2]);
@@ -326,20 +327,32 @@ ImGui_SD_Thumbnail(project_data *File, project_state *State, ui *UI, memory *Mem
// 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));
+ ImVec2 ImgMin = ViewportMin + ImVec2(X * UI_Size, Y * UI_Size);
ImGui::SetCursorScreenPos(ImgMin);
- ImGui::Button("##thumbnail", ImVec2(UI_Size, UI_Size));
- draw_list->AddImage((void *)(intptr_t)Source->ThumbnailTex, ImgMin, ImgMax);
+ real32 ClosestSpacing = 0.2;
+ bool32 Wide = (Source->Width > Source->Height);
+ // ImVec2 Min = (Wide) ? ImVec2(0,ClosestSpacing) : ImVec2(ClosestSpacing,0);
+ // ImVec2 Max = (Wide) ? ImVec2(1-ClosestSpacing,1) : ImVec2(1,1-ClosestSpacing);
+ ImVec2 Min(0.2, 0.2);
+ ImVec2 Max(0.8, 0.8);
+ ImGui::ImageButton((void *)(intptr_t)Source->ThumbnailTex, ImVec2(UI_Size, UI_Size), Min, Max, 12);
+ // ImGui::ImageButton(user_texture_id, & sizeconst ImVec2& = ImVec2(0, 0), = ImVec2(1,1), int frame_padding = -1, const ImVec4& bg_col = ImVec4(0,0,0,0), const ImVec4& tint_col = ImVec4(1,1,1,1)); // <0 frame_padding uses default frame padding settings. 0 for no padding
+ // ImVec2 ImgMax = ImgMin + ImVec2(UI_Size * Ratio, UI_Size);
+ // ImGui::Button("##thumbnail", ImVec2(UI_Size, UI_Size));
+ // draw_list->AddImage((void *)(intptr_t)Source->ThumbnailTex, ImgMin, ImgMax);
if (ImGui::IsItemHovered()) {
State->PreviewSource = SourceArray[i];
State->UpdateFrame = true;
Active = true;
+ block_source *Source1 = (block_source *)Memory_Block_AddressAtIndex(Memory, F_Sources, 1);
+ block_source *Source2 = (block_source *)Memory_Block_AddressAtIndex(Memory, F_Sources, 2);
+ block_source *Source0 = (block_source *)Memory_Block_AddressAtIndex(Memory, F_Sources, 0);
+ real32 a = 0;
}
if (ImGui::IsItemClicked() || ImGui::IsItemClicked(ImGuiMouseButton_Right)) {
@@ -1036,7 +1049,7 @@ 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 0
+#if 1
bool32 IsActive = ImGui::IsItemActive();
bool32 IsActivated = ImGui::IsItemActivated();
bool32 IsDeactivated = ImGui::IsItemDeactivated();
@@ -1171,9 +1184,17 @@ ImGui_Viewport(project_data *File, project_state *State, ui *UI, memory *Memory,
}
}
- if (IsActive && ImGui::IsMouseDragging(ImGuiMouseButton_Left, -1.0f) && ImGui::IsKeyDown(ImGuiKey_Z))
+ real32 Distance = 0;
+ if (IsActive) {
+ if (ImGui::IsMouseDragging(ImGuiMouseButton_Left, -1.0f))
+ Distance = io.MouseDelta.x + io.MouseDelta.y;
+ if (ImGui::IsMouseDoubleClicked(ImGuiMouseButton_Left))
+ Distance = 200;
+ }
+ if (Distance && ImGui::IsKeyDown(ImGuiKey_Z))
{
- real32 Distance = io.MouseDelta.x + io.MouseDelta.y;
+ if (io.KeyShift)
+ 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;
@@ -2375,6 +2396,10 @@ ImGui_ProcessInputs(project_data *File, project_state *State, ui *UI, memory *Me
}
#if DEBUG
+ if (ImGui::IsKeyPressed(ImGuiKey_0))
+ {
+ Debug.ReloadUI ^= 1;
+ }
if (ImGui::IsKeyPressed(ImGuiKey_1))
{
Debug.ToggleWindow ^= 1;
@@ -2447,20 +2472,23 @@ ImGui_Menu(project_data *File, project_state *State, ui *UI, memory *Memory, ImG
PostMsg(State, "File save failed...");
}
}
- /*
- if (ImGui::MenuItem("New project file", "Ctrl+Shift+N"))
- {
- State->ImGuiPopups = popup_newfile;
- }
if (ImGui::BeginMenu("Open file"))
{
ImGui::InputText("Filename", State->DummyName, 512);
if (ImGui::IsItemDeactivated() && ImGui::IsKeyPressed(ImGuiKey_Enter)) {
- File_Open(State, Memory, State->DummyName);
- State->Context[Index].UpdateFrame = true;
+ if (File_Open(File, State, Memory, State->DummyName)) {
+ State->UpdateFrame = true;
+ } else {
+ PostMsg(State, "File not found.");
+ }
}
ImGui::EndMenu();
}
+ /*
+ if (ImGui::MenuItem("New project file", "Ctrl+Shift+N"))
+ {
+ State->ImGuiPopups = popup_newfile;
+ }
if (ImGui::MenuItem("Save as", "Ctrl+Shift+S"))
{
State->ImGuiPopups = popup_saveas;
@@ -3479,6 +3507,9 @@ ImGui_Viewport(project_data File, project_state *State, ui *UI, memory *Memory,
if (UI->Initializing) {
UI->CompZoom = ImVec2(CompBuffer.Width, CompBuffer.Height);
+#if DEBUG
+ UI->CompZoom = UI->CompZoom * ImVec(0.5, 0.5);
+#endif
UI->CompPos = ImVec2(ViewportMin.x + ((ViewportMax.x - ViewportMin.x)/2 - UI->CompZoom.x/2),
ViewportMin.y + ((ViewportMax.y - ViewportMin.y)/2 - UI->CompZoom.y/2));
}
diff --git a/stable_diffusion.h b/stable_diffusion.h
index 887b469..3335796 100644
--- a/stable_diffusion.h
+++ b/stable_diffusion.h
@@ -22,8 +22,8 @@ struct sd_state
char NegPrompt[256];
char ServerAddress[128];
int32 Steps = 10;
- int32 Width = 960;
- int32 Height = 640;
+ int32 Width = 512;
+ int32 Height = 512;
int32 SamplerIndex = 0;
real32 CFG = 7;
int32 BatchSize = 1;