summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorFox Caminiti <fox@foxcam.net>2023-03-05 13:29:14 -0500
committerFox Caminiti <fox@foxcam.net>2023-03-05 13:29:14 -0500
commitf7a194270e25deeb3ce9c9b9fbce0da8b6be71ca (patch)
tree3a9716248df5a2da58546e29c1b476c67500d621 /src
parentd0410bddcd7ea43c51b6bf2442a99e58710e70eb (diff)
Diffstat (limited to 'src')
-rw-r--r--src/createcalls.cpp78
-rw-r--r--src/imgui_ui.cpp14
-rw-r--r--src/imgui_ui_timeline.cpp16
-rw-r--r--src/imgui_ui_viewport.cpp12
-rw-r--r--src/include/all.h2
-rw-r--r--src/include/main.h4
-rw-r--r--src/main.cpp33
-rw-r--r--src/sorted.cpp28
8 files changed, 111 insertions, 76 deletions
diff --git a/src/createcalls.cpp b/src/createcalls.cpp
index ffb4c0f..c082bda 100644
--- a/src/createcalls.cpp
+++ b/src/createcalls.cpp
@@ -789,9 +789,46 @@ Property_IsGraphSelected(memory *Memory, uint16 *Block_Bezier_Index, uint16 *Arr
}
static void
-Sort_OffsetDupes(memory *Memory, sorted_layer_array *SortedLayerStart, block_layer *StartLayer,
- int i, int FauxIncrement, int LayerCount, int Mode)
+Sort_OffsetDupes(project_state *State, memory *Memory, sorted_layer_array *SortedLayerStart,
+ int Direction, int FirstDupeIdx, int LayerCount, int FakeLayerCount)
{
+ int FauxIncrement = 0;
+ int FurthestMark = -1;
+ {
+ sorted_layer_array SortEntry = SortedLayerStart[FirstDupeIdx];
+ uint32 Index_Physical = SortEntry.Block_Layer_Index;
+ block_layer *Layer = (block_layer *)Memory_Block_AddressAtIndex(Memory, F_Layers, Index_Physical);
+ FurthestMark = Layer->Vertical_Offset;
+ }
+ // TODO(fox): make this less ghetto
+ if (State->DuplicateMode & sortflag_furthest && !(State->DuplicateMode & sortflag_up))
+ {
+ FauxIncrement = -FakeLayerCount;
+ }
+ int i = (Direction > 0) ? 0 : LayerCount - 1;
+ int Test = 0;
+ for (;;)
+ {
+ sorted_layer_array SortEntry = SortedLayerStart[i];
+ uint32 Index_Physical = SortEntry.Block_Layer_Index;
+ block_layer *Layer = (block_layer *)Memory_Block_AddressAtIndex(Memory, F_Layers, Index_Physical);
+ if (Layer->IsSelected)
+ Test = 1;
+ if (Test)
+ History_Action_Swap(Memory, F_Layers, sizeof(Layer->Vertical_Offset), &Layer->Vertical_Offset);
+ if (Layer->IsSelected) {
+ if (State->DuplicateMode & sortflag_furthest)
+ Layer->Vertical_Offset = FurthestMark;
+ FauxIncrement += Direction;
+ if (State->DuplicateMode & sortflag_furthest && !(State->DuplicateMode & sortflag_up))
+ Layer->Vertical_Offset += 1;
+ }
+ Layer->Vertical_Offset -= FauxIncrement;
+ int a = 0;
+ i += Direction;
+ if ((Direction > 0) ? (i >= LayerCount) : (i < 0))
+ break;
+ }
}
// NOTE(fox): PrecompLayer is assumed to be untouched from the layer it was duplicated from!
@@ -853,7 +890,7 @@ Project_Layer_Duplicate(project_data *File, project_state *State, memory *Memory
int LayerCount = SortedCompStart.LayerCount + SortedCompStart.FakeLayerCount;
int FirstDupe = -1;
int DupeCount = 0;
- int Direction = (State->DuplicateMode & sortflag_up) ? 1 : -1;
+ int Direction = (State->DuplicateMode & sortflag_up) ? -1 : -1;
if (State->DuplicateMode & sortflag_furthest && !(State->DuplicateMode & sortflag_up))
Direction *= -1;
int i = (Direction > 0) ? 0 : LayerCount - 1;
@@ -905,39 +942,10 @@ Project_Layer_Duplicate(project_data *File, project_state *State, memory *Memory
break;
i += Direction;
}
+ if (State->DuplicateMode & sortflag_up)
+ Direction *= -1;
if (FirstDupe > -1) {
- int FauxIncrement = 0;
- int FurthestMark = -1;
- {
- sorted_layer_array SortEntry = SortedLayerStart[FirstDupe];
- uint32 Index_Physical = SortEntry.Block_Layer_Index;
- block_layer *Layer = (block_layer *)Memory_Block_AddressAtIndex(Memory, F_Layers, Index_Physical);
- FurthestMark = Layer->Vertical_Offset;
- }
- if (State->DuplicateMode & sortflag_furthest && !(State->DuplicateMode & sortflag_up))
- {
- FauxIncrement = -SortedCompStart.FakeLayerCount;
- }
- int i = (Direction > 0) ? 0 : LayerCount - 1;
- for (;;)
- {
- sorted_layer_array SortEntry = SortedLayerStart[i];
- uint32 Index_Physical = SortEntry.Block_Layer_Index;
- block_layer *Layer = (block_layer *)Memory_Block_AddressAtIndex(Memory, F_Layers, Index_Physical);
- History_Action_Swap(Memory, F_Layers, sizeof(Layer->Vertical_Offset), &Layer->Vertical_Offset);
- if (Layer->IsSelected) {
- if (State->DuplicateMode & sortflag_furthest)
- Layer->Vertical_Offset = FurthestMark;
- FauxIncrement += Direction;
- if (State->DuplicateMode & sortflag_furthest && !(State->DuplicateMode & sortflag_up))
- Layer->Vertical_Offset += 1;
- }
- Layer->Vertical_Offset -= FauxIncrement;
- int a = 0;
- if ((Direction > 0) ? !(i < LayerCount) : (i <= 0))
- break;
- i += Direction;
- }
+ Sort_OffsetDupes(State, Memory, SortedLayerStart, Direction, FirstDupe, LayerCount, SortedCompArray->FakeLayerCount);
}
}
}
diff --git a/src/imgui_ui.cpp b/src/imgui_ui.cpp
index aa09bfb..6bc6d85 100644
--- a/src/imgui_ui.cpp
+++ b/src/imgui_ui.cpp
@@ -749,6 +749,20 @@ ImGui_Menu(project_data *File, project_state *State, ui *UI, memory *Memory, ImG
}
if (ImGui::BeginMenu("Window"))
{
+ if (ImGui::BeginMenu("Background viewport color"))
+ {
+ ImGuiColorEditFlags flags_primary = ImGuiColorEditFlags_AlphaPreview |
+ ImGuiColorEditFlags_Float;
+ ImGuiColorEditFlags flags_picker = ImGuiColorEditFlags_PickerHueBar |
+ ImGuiColorEditFlags_AlphaBar |
+ ImGuiColorEditFlags_NoSmallPreview |
+ ImGuiColorEditFlags_NoSidePreview |
+ ImGuiColorEditFlags_DisplayRGB |
+ ImGuiColorEditFlags_DisplayHSV |
+ ImGuiColorEditFlags_DisplayHex;
+ ImGui::ColorPicker4("##bgcolorpicker", &UI->BGColor.r, flags_primary | flags_picker);
+ ImGui::EndMenu();
+ }
if (ImGui::Selectable("Standard view", UI->Mode == 0))
UI->Mode = 0;
if (ImGui::Selectable("Vector view", UI->Mode == 1))
diff --git a/src/imgui_ui_timeline.cpp b/src/imgui_ui_timeline.cpp
index 8b8ca36..ab38bae 100644
--- a/src/imgui_ui_timeline.cpp
+++ b/src/imgui_ui_timeline.cpp
@@ -513,7 +513,7 @@ ImGui_Timeline_DrawPrecomp(project_data *File, project_state *State, memory *Mem
Test &= (Layer_ScreenPos_Min.x <= io.MouseClickedPos[0].x && Layer_ScreenPos_Max.x >= io.MousePos.x);
if (Test) {
- if (!(Layer->IsSelected & 0x01) && !(Layer->IsSelected & 0x02) && !Layer->IsLocked) {
+ if (!(Layer->IsSelected & 0x01) && !(Layer->IsSelected & 0x02) && (!Layer->IsLocked || io.KeyCtrl)) {
Layer_Select(Memory, State, Index_Physical);
}
} else if (!io.KeyShift) {
@@ -599,15 +599,16 @@ ImGui_Timeline_DrawPrecomp(project_data *File, project_state *State, memory *Mem
if (ImGui::MenuItem("Visible", NULL, Layer->IsVisible)) {
bool32 Commit = false;
int h = 0, z = 0, i = 0;
+ bool32 Val = Layer->IsVisible ^ 1;
while (Block_Loop(Memory, F_Layers, File->Layer_Count, &h, &z, &i)) {
- block_layer *Layer = (block_layer *)Memory_Block_AddressAtIndex(Memory, F_Layers, i);
- if (Layer->IsSelected & 0x01) {
+ block_layer *CurLayer = (block_layer *)Memory_Block_AddressAtIndex(Memory, F_Layers, i);
+ if (CurLayer->IsVisible != Val && CurLayer->IsSelected & 0x01) {
if (!Commit) {
History_Entry_Commit(Memory, "Toggle visibility");
Commit = true;
}
- History_Action_Swap(Memory, F_Layers, sizeof(Layer->IsVisible), &Layer->IsVisible);
- Layer->IsVisible ^= 1;
+ History_Action_Swap(Memory, F_Layers, sizeof(CurLayer->IsVisible), &CurLayer->IsVisible);
+ CurLayer->IsVisible = Val;
}
}
if (Commit) {
@@ -618,15 +619,16 @@ ImGui_Timeline_DrawPrecomp(project_data *File, project_state *State, memory *Mem
if (ImGui::MenuItem("Lock", NULL, Layer->IsLocked)) {
bool32 Commit = false;
int h = 0, z = 0, i = 0;
+ bool32 Val = Layer->IsLocked ^ 1;
while (Block_Loop(Memory, F_Layers, File->Layer_Count, &h, &z, &i)) {
block_layer *CurLayer = (block_layer *)Memory_Block_AddressAtIndex(Memory, F_Layers, i);
- if ((CurLayer->IsSelected & 0x01) || (Layer == CurLayer)) {
+ if (CurLayer->IsLocked != Val && ((CurLayer->IsSelected & 0x01) || (Layer == CurLayer))) {
if (!Commit) {
History_Entry_Commit(Memory, "Toggle lock");
Commit = true;
}
History_Action_Swap(Memory, F_Layers, sizeof(CurLayer->IsLocked), &CurLayer->IsLocked);
- CurLayer->IsLocked ^= 1;
+ CurLayer->IsLocked = Val;
}
}
if (Commit) {
diff --git a/src/imgui_ui_viewport.cpp b/src/imgui_ui_viewport.cpp
index 0cfc7da..9b9942a 100644
--- a/src/imgui_ui_viewport.cpp
+++ b/src/imgui_ui_viewport.cpp
@@ -648,6 +648,8 @@ ImGui_Viewport_TransformUI2(project_data *File, project_state *State, memory *Me
// mouse's transform.
History_Entry_Commit(Memory, "Transform layers");
+ State->Interact_Transform_Prev = State->Interact_Transform;
+
interact_transform Interact = State->Interact_Transform;
v2 BoxLength = Interact.Max - Interact.Min;
v2 Center = Interact.Max - (BoxLength/2);
@@ -663,7 +665,7 @@ ImGui_Viewport_TransformUI2(project_data *File, project_state *State, memory *Me
layer_transforms T = {};
T.scale = 1.0f;
- LayerIterate(State, Memory, File->PrincipalCompIndex, T, Center, SortedCompArray, SortedLayerArray);
+ LayerIterate(State, Memory, File->PrincipalCompIndex, State->Interact_Transform, T, Center, SortedCompArray, SortedLayerArray);
History_Entry_End(Memory);
State->UpdateFrame = true;
State->UncommitedKeyframe = 1;
@@ -828,8 +830,8 @@ ImGui_Viewport_SelectedLayerUI(project_state *State, memory *Memory, ui *UI, ImG
if (State->Interact_Active != interact_type_viewport_transform_gizmo) {
if (State->Tool != tool_brush) {
ImU32 wcol2 = IM_COL32(10, 10, 10, 128);
- draw_list->AddNgon(ScreenPoint[0], 10, wcol2, 8, 9.0f);
- draw_list->AddNgon(ScreenPoint[0], 10, wcol, 8, 5.0f);
+ draw_list->AddNgonFilled(ScreenPoint[0], 5, wcol2, 6);
+ draw_list->AddNgonFilled(ScreenPoint[0], 3, wcol, 6);
}
draw_list->AddLine(ScreenPoint[1], ScreenPoint[2], wcol, 1.0f);
draw_list->AddLine(ScreenPoint[2], ScreenPoint[4], wcol, 1.0f);
@@ -901,7 +903,7 @@ ImGui_Viewport(project_data *File, project_state *State, ui *UI, memory *Memory,
Data += sizeof(gl_viewport_data);
*RenderData = { ViewportMin, ViewportMax, ImGui::GetMainViewport()->Size, State->ViewportEnabled,
Comp->Width, Comp->Height, Comp->BytesPerPixel,
- UI->CompPos, UI->CompZoom, UI->CompZoom.x / Comp->Width, {} };
+ UI->CompPos, UI->CompZoom, UI->CompZoom.x / Comp->Width, UI->BGColor, {} };
layer_transforms ExtraT = {};
Render_UI(File, State, Memory, UI, draw_list, Data, RenderData,
SortedCompArray, SortedLayerArray, ExtraT,
@@ -1307,6 +1309,8 @@ ImGui_Viewport(project_data *File, project_state *State, ui *UI, memory *Memory,
State->Interact_Offset[0] = 0;
State->Interact_Offset[1] = 0;
State->Interact_Transform = {};
+ State->Interact_Transform_Prev = {};
+ State->Interact_Transform_Prev.Position = Offset;
History_Entry_End(Memory);
} else {
Assert(IsActive);
diff --git a/src/include/all.h b/src/include/all.h
index 8182b26..4382d17 100644
--- a/src/include/all.h
+++ b/src/include/all.h
@@ -526,7 +526,7 @@ static void
Transform_ApplyInteractive(interact_transform Interact, real32 *OutputX, real32 *OutputY, real32 *OutputRotation, real32 *OutputScale);
static void
-LayerIterate(project_state *State, memory *Memory, uint32 CompIndex, layer_transforms ExtraT, v2 Center,
+LayerIterate(project_state *State, memory *Memory, uint32 CompIndex, interact_transform Interact_Transform, layer_transforms ExtraT, v2 Center,
sorted_comp_array *SortedCompArray, sorted_layer_array *SortedLayerArray);
static void
diff --git a/src/include/main.h b/src/include/main.h
index 8debbb0..375d8da 100644
--- a/src/include/main.h
+++ b/src/include/main.h
@@ -441,6 +441,7 @@ struct gl_viewport_data
ImVec2 UIPos;
ImVec2 UIZoom;
real32 UIScale;
+ v4 BGColor;
gl_data *LayerEntry[MAX_LAYERS];
int LayerCount;
};
@@ -563,6 +564,7 @@ struct project_state
selection_type RecentSelectionType = selection_type_none;
interact_transform Interact_Transform;
+ interact_transform Interact_Transform_Prev;
interact_type Interact_Active;
int32 Interact_Modifier;
bool32 Interact_OutOfDrag; // TODO(fox): replace this
@@ -612,6 +614,7 @@ struct project_state
focused_window FocusedWindow; // Convenience for adding window-specific hotkeys.
bool32 SetFocus;
v2 LastClickedPoint = V2(1, 1);
+
};
// UI info that's saved to the file and is not part of the history tree
@@ -632,6 +635,7 @@ struct ui
v4 Color = {1, 1, 1, 1};
v4 AltColor = {0, 0, 0, 1};
bool32 IsPrimary;
+ v4 BGColor = {0, 0, 0, 1};
#if STABLE
sd_state SD;
diff --git a/src/main.cpp b/src/main.cpp
index 42c07a9..7cc4745 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -329,7 +329,7 @@ GL_Test(const ImDrawList* parent_list, const ImDrawCmd* cmd)
GL_UpdateTexture2(&MSBuffer2, NULL, A[2], A[3], RenderData->BytesPerPixel, 0);
glBindFramebuffer(GL_FRAMEBUFFER, MSBuffer.FramebufferObject);
glBindTexture(GL_TEXTURE_2D, 0);
- glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
+ glClearColor(RenderData->BGColor.r, RenderData->BGColor.g, RenderData->BGColor.b, 0.0f);
glClear(GL_COLOR_BUFFER_BIT);
glUseProgram(DefaultShaderProgram);
@@ -565,7 +565,7 @@ LayerIterate_TestSelection(project_state *State, memory *Memory, uint32 Principa
// finding the inverse transform-- i.e. transforming the layers locally rather
// than transforming them in comp space.
static void
-LayerIterate(project_state *State, memory *Memory, uint32 CompIndex, layer_transforms ExtraT, v2 Center,
+LayerIterate(project_state *State, memory *Memory, uint32 CompIndex, interact_transform Interact_Transform, layer_transforms ExtraT, v2 Center,
sorted_comp_array *SortedCompArray, sorted_layer_array *SortedLayerArray)
{
block_composition *Comp = (block_composition *)Memory_Block_AddressAtIndex(Memory, F_Precomps, CompIndex);
@@ -585,14 +585,14 @@ LayerIterate(project_state *State, memory *Memory, uint32 CompIndex, layer_trans
v2 NewCenter = T_CompPosToLayerPos(NewExtraT, Comp->Width, Comp->Height, Width, Height, Center.x, Center.y);
NewExtraT.rotation = ExtraT.rotation - NewExtraT.rotation;
NewExtraT.scale = ExtraT.scale / NewExtraT.scale;
- LayerIterate(State, Memory, Layer->Block_Source_Index, NewExtraT, NewCenter, SortedCompArray, SortedLayerArray);
+ LayerIterate(State, Memory, Layer->Block_Source_Index, Interact_Transform, NewExtraT, NewCenter, SortedCompArray, SortedLayerArray);
}
if (Layer->IsSelected & 0x01) {
#if DEBUG
if (Layer->IsPrecomp)
PostMsg(State, "DEBUG: Precomp transformed!");
#endif
- v2 Position = State->Interact_Transform.Position;
+ v2 Position = Interact_Transform.Position;
real32 Rad = (ExtraT.rotation * (PI / 180));
v2 XAxis = Position.x * ExtraT.scale * V2(cos(Rad), sin(Rad));
v2 YAxis = Position.y * -ExtraT.scale * V2(sin(Rad), -cos(Rad));
@@ -602,7 +602,7 @@ LayerIterate(project_state *State, memory *Memory, uint32 CompIndex, layer_trans
History_Action_Swap(Memory, F_Layers, sizeof(Layer->y.CurrentValue), &Layer->y.CurrentValue);
History_Action_Swap(Memory, F_Layers, sizeof(Layer->scale.CurrentValue), &Layer->scale.CurrentValue);
History_Action_Swap(Memory, F_Layers, sizeof(Layer->rotation.CurrentValue), &Layer->rotation.CurrentValue);
- Transform_ApplyLocal(State->Interact_Transform, Position, Center,
+ Transform_ApplyLocal(Interact_Transform, Position, Center,
&Layer->x.CurrentValue, &Layer->y.CurrentValue, &Layer->rotation.CurrentValue, &Layer->scale.CurrentValue);
}
}
@@ -1242,6 +1242,8 @@ int main(int argc, char *argv[]) {
File->Comp_Count = 1;
+ File->UI.BGColor= V4(0.1, 0.1, 0.1, 0.0);
+
SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO);
SDL_AudioSpec Audio = {0};
@@ -1508,8 +1510,25 @@ int main(int argc, char *argv[]) {
State->Interact_Active = interact_type_viewport_duplicate;
sorted_file Sorted = File_Sort_Push(File, State, &Memory);
History_Entry_Commit(&Memory, "Duplicate layers");
- v2 Offset = V2(State->Interact_Dup_Previous[0], State->Interact_Dup_Previous[1]);
- Project_Layer_Duplicate(File, State, &Memory, Sorted.CompArray, Sorted.LayerArray, Offset, io.KeyCtrl);
+ Project_Layer_Duplicate(File, State, &Memory, Sorted.CompArray, Sorted.LayerArray, V2(0, 0), 0);
+ if (!io.KeyCtrl)
+ {
+ interact_transform Interact = State->Interact_Transform_Prev;
+ v2 BoxLength = Interact.Max - Interact.Min;
+ v2 Center = Interact.Max - (BoxLength/2);
+ if (Interact.RadianOffset != 0.0f) {
+ v2 LocalCenter = Interact.NewCenter;
+ real32 Rad = Interact.RadianOffset;
+ real32 Point0X = Center.x - Interact.OGCenter.x;
+ real32 Point0Y = Center.y - Interact.OGCenter.y;
+ v2 XAxis = (Point0X * 1.0f)*V2(cos(Rad), sin(Rad));
+ v2 YAxis = (Point0Y * 1.0f)*V2(sin(Rad), -cos(Rad));
+ Center = Interact.OGCenter + XAxis + YAxis;
+ }
+ layer_transforms T = {};
+ T.scale = 1.0f;
+ LayerIterate(State, &Memory, File->PrincipalCompIndex, Interact, T, Center, Sorted.CompArray, Sorted.LayerArray);
+ }
State->Interact_Transform = {};
History_Entry_End(&Memory);
File_Sort_Pop(&Memory, Sorted.Layer_SortSize, Sorted.Property_SortSize, Sorted.Source_SortSize);
diff --git a/src/sorted.cpp b/src/sorted.cpp
index c039c08..b9bbb25 100644
--- a/src/sorted.cpp
+++ b/src/sorted.cpp
@@ -314,7 +314,8 @@ Layer_SortAll(project_state *State, memory *Memory,
Arbitrary_ShiftData(Address_Start, Address_End, sizeof(sorted_layer_array) * SortedCompStart->FakeLayerCount, 1);
FurthestMark = i + ((Direction > 0) ? 0 : -Direction);
}
- sorted_layer_array *FakeLayerEntry = &SortedLayerStart[FurthestMark + (FauxIncrement * ((Direction > 0) ? 1 : -Direction))];
+ int FakeIdx = FurthestMark + ((Direction > 0) ? FauxIncrement : (SortedCompStart->FakeLayerCount - 1) - FauxIncrement);
+ sorted_layer_array *FakeLayerEntry = &SortedLayerStart[FakeIdx];
*FakeLayerEntry = *LayerEntry;
FakeLayerEntry->IsFake = true;
FauxIncrement++;
@@ -329,30 +330,13 @@ Layer_SortAll(project_state *State, memory *Memory,
FauxIncrement++;
}
}
- if ((Direction > 0) ? !(i < SortedCompStart->LayerCount) : (i <= 0))
- break;
i += Direction;
- }
- if (Furthest) { Direction *= -1; }
- i = FauxIncrement = 0;
- int LayerCount = SortedCompStart->LayerCount + SortedCompStart->FakeLayerCount;
- FurthestMark = -1;
- i = (Direction > 0) ? 0 : LayerCount - 1;
- for (;;) {
- sorted_layer_array *LayerEntry = &SortedLayerStart[i];
- block_layer *Layer = (block_layer *)Memory_Block_AddressAtIndex(Memory, F_Layers, LayerEntry->Block_Layer_Index);
- if (LayerEntry->IsFake) {
- if (FurthestMark == -1)
- FurthestMark = Layer->Vertical_Offset;
- if (Furthest)
- LayerEntry->SortedOffset = FurthestMark;
- FauxIncrement += Direction;
- }
- LayerEntry->SortedOffset -= FauxIncrement;
- if ((Direction > 0) ? !(i < LayerCount) : (i <= 0))
+ if ((Direction > 0) ? (i >= SortedCompStart->LayerCount) : (i < 0))
break;
- i += Direction;
}
+ // TODO(fox): Intermediate offset?
+ // Sort_OffsetDupes(State, Memory, SortedLayerStart,
+ // Direction, DupeIdx, LayerCount, SortedCompStart->FakeLayerCount)
}
}
}