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.cpp183
1 files changed, 85 insertions, 98 deletions
diff --git a/my_imgui_widgets.cpp b/my_imgui_widgets.cpp
index 16be2e1..cd23b98 100644
--- a/my_imgui_widgets.cpp
+++ b/my_imgui_widgets.cpp
@@ -1004,8 +1004,10 @@ ImGui_Viewport(project_data *File, project_state *State, ui *UI, memory *Memory,
bool open = true;
ImGui::Begin("Viewport", &open, ImGuiWindowFlags_NoScrollbar | ImGuiWindowFlags_NoScrollWithMouse);
- if (ImGui::IsWindowFocused(ImGuiFocusedFlags_ChildWindows))
+ if (ImGui::IsWindowHovered(ImGuiFocusedFlags_ChildWindows)) {
+ State->SetFocus = true;
State->FocusedWindow = focus_viewport;
+ }
block_composition *MainComp = (block_composition *)Memory_Block_AddressAtIndex(Memory, F_Precomps, File->PrincipalCompIndex);
@@ -1138,6 +1140,7 @@ ImGui_Viewport(project_data *File, project_state *State, ui *UI, memory *Memory,
UI->CompPos.y += io.MouseDelta.y;
}
+
bool32 OtherActions = ImGui::IsKeyDown(ImGuiKey_Z) || ImGui::IsMouseDown(ImGuiMouseButton_Right);
if (State->Tool == tool_brush && State->Interact_Active == interact_type_brush) {
Assert(State->Brush.LayerToPaint_Index != -1);
@@ -1184,6 +1187,13 @@ ImGui_Viewport(project_data *File, project_state *State, ui *UI, memory *Memory,
}
}
+ if (ImGui::IsKeyDown(ImGuiKey_Z)) {
+ if (IsActive)
+ ImGui::SetMouseCursor(ImGuiMouseCursor_ResizeAll);
+ else
+ ImGui::SetMouseCursor(ImGuiMouseCursor_Hand);
+ }
+
real32 Distance = 0;
if (IsActive) {
if (ImGui::IsMouseDragging(ImGuiMouseButton_Left, -1.0f))
@@ -1312,7 +1322,7 @@ static void
ImGui_GraphInfo(project_data *File, project_state *State, memory *Memory, ui *UI, ImGuiIO io, sorted_property_info *SortedPropertyInfo, uint16 *SortedPropertyArray)
{
bool open = true;
- ImGui::Begin("Graph info", &open, ImGuiWindowFlags_NoScrollbar | ImGuiWindowFlags_NoScrollWithMouse);
+ ImGui::Begin("Graph info");
int h = 0, c = 0, i = 0;
while (Block_Loop(Memory, F_Layers, File->Layer_Count, &h, &c, &i))
@@ -1348,10 +1358,11 @@ ImGui_GraphInfo(project_data *File, project_state *State, memory *Memory, ui *UI
static void
ImGui_Timeline_DrawKeySheet(project_data *File, project_state *State, memory *Memory, ui *UI, ImGuiIO io, ImDrawList *draw_list, property_channel *Property, uint16 *ArrayLocation,
- ImVec2 Increment, ImVec2 TimelineAbsolutePos, ImVec2 TimelineMoveSize, ImVec2 TimelineZoomSize,
+ ImVec2 Increment, ImVec2 TimelineAbsolutePos, ImVec2 GraphPos, ImVec2 TimelineMoveSize, ImVec2 TimelineZoomSize,
ImVec2 TimelineSize, ImVec2 TimelineSizeWithBorder, real32 LayerIncrement)
{
ImGui::PushID(Property);
+
for (int p = 0; p < Property->Keyframe_Count; p++) {
int k = ArrayLocation[p];
bezier_point *PointAddress = Bezier_LookupAddress(Memory, Property, k);
@@ -1360,48 +1371,60 @@ ImGui_Timeline_DrawKeySheet(project_data *File, project_state *State, memory *Me
Bezier_EvaluateValue(State, PointAddress, PointPos);
real32 LocalPos_Ratio_X = PointPos[0].x * Increment.x;
- real32 Keyframe_ScreenPos_X = TimelineAbsolutePos.x + TimelineMoveSize.x + LocalPos_Ratio_X * TimelineZoomSize.x;
-
- ImVec2 Keyframe_ScreenPos(Keyframe_ScreenPos_X, TimelineAbsolutePos.y);
-
- 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;
- real32 X_Right = (io.MouseClickedPos[0].x > io.MousePos.x) ? io.MouseClickedPos[0].x : io.MousePos.x;
-
- if (Keyframe_ScreenPos.y >= Y_Top && Keyframe_ScreenPos.y <= Y_Bottom &&
- Keyframe_ScreenPos.x >= X_Left && Keyframe_ScreenPos.x <= X_Right)
- {
- if (!PointAddress->IsSelected) {
- PointAddress->IsSelected = 1;
- }
- } else if (!io.KeyShift) {
- PointAddress->IsSelected = 0;
- }
- }
-
- ImVec2 ButtonSize(16, 16);
-
- ImGui::PushID(p);
-
- ImU32 PointCol = (PointAddress->IsSelected) ? ImColor(0.8f, 0.5f, 0.0f, 1.0f) : ImColor(0.1f, 0.1f, 0.1f, 1.0f);
- ImU32 LineCol = (PointAddress->IsSelected) ? ImColor(0.8f, 0.5f, 0.5f, 1.0f) : ImColor(0.4f, 0.4f, 0.4f, 1.0f);
- ImGui::SetCursorScreenPos(Keyframe_ScreenPos - (ButtonSize * 0.5));
- ImGui::InvisibleButton("##keyframemover", ButtonSize, ImGuiMouseButton_Left);
- bool32 IsHovered = ImGui::IsItemHovered();
- bool32 IsItemActive = ImGui::IsItemActive();
- bool32 IsItemActivated = ImGui::IsItemActivated();
- bool32 IsItemDeactivated = ImGui::IsItemDeactivated();
- bool32 LeftClick = ImGui::IsMouseDown(ImGuiMouseButton_Left);
- bool32 RightClick = ImGui::IsMouseDown(ImGuiMouseButton_Right);
-
- if (IsHovered)
- PointCol = ImColor(1.0f, 0.8f, 0.8f, 1.0f);
-
- if (IsItemActivated) {
- PointAddress->IsSelected = 1;
- }
+ real32 Keyframe_ScreenPos_X = GraphPos.x + TimelineMoveSize.x + LocalPos_Ratio_X * TimelineZoomSize.x;
+
+ ImVec2 Keyframe_ScreenPos(Keyframe_ScreenPos_X, GraphPos.y);
+
+ if (State->BoxSelect) {
+ ImGui_TestBoxSelection_Point(Keyframe_ScreenPos, io, &PointAddress->IsSelected);
+ }
+
+ ImVec2 ButtonSize(16, 16);
+
+ ImGui::PushID(p);
+
+ ImU32 PointCol = (PointAddress->IsSelected) ? ImColor(0.8f, 0.5f, 0.0f, 1.0f) : ImColor(0.1f, 0.1f, 0.1f, 1.0f);
+ ImU32 LineCol = (PointAddress->IsSelected) ? ImColor(0.8f, 0.5f, 0.5f, 1.0f) : ImColor(0.4f, 0.4f, 0.4f, 1.0f);
+ ImGui::SetCursorScreenPos(Keyframe_ScreenPos - (ButtonSize * 0.5));
+ ImGui::InvisibleButton("##keyframemover", ButtonSize, ImGuiMouseButton_Left);
+ bool32 IsHovered = ImGui::IsItemHovered();
+ bool32 IsItemActive = ImGui::IsItemActive();
+ bool32 IsItemActivated = ImGui::IsItemActivated();
+ bool32 IsItemDeactivated = ImGui::IsItemDeactivated();
+ bool32 LeftClick = ImGui::IsMouseDown(ImGuiMouseButton_Left);
+ bool32 RightClick = ImGui::IsMouseDown(ImGuiMouseButton_Right);
+
+ if (IsHovered) {
+ PointCol = ImColor(1.0f, 0.8f, 0.8f, 1.0f);
+ ImGui::SetMouseCursor(ImGuiMouseCursor_Hand);
+ }
+
+ if (IsItemActivated) {
+ PointAddress->IsSelected = 1;
+ }
+
+ if (IsItemActive) {
+ if (State->Interact_Active == interact_type_none) {
+ State->Interact_Offset[2] = io.MousePos.x;
+ State->Interact_Offset[3] = io.MousePos.y;
+ State->Interact_Active = interact_type_keyframe_move;
+ } else {
+ Assert(State->Interact_Active == interact_type_keyframe_move);
+ ImGui_WarpMouse(State, io.MousePos, TimelineAbsolutePos, TimelineAbsolutePos + TimelineSizeWithBorder);
+ ImVec2 DragDelta = io.MousePos - ImVec2(State->Interact_Offset[2], State->Interact_Offset[3]);
+ DragDelta = DragDelta + (ImVec2(State->Warp_X, State->Warp_Y) * TimelineSize);
+ if (io.MouseDelta.x || io.MouseDelta.y) {
+ State->UpdateFrame = true;
+ }
+ if (State->Interact_Active == interact_type_keyframe_move) {
+ State->Interact_Offset[0] = (DragDelta.x / TimelineZoomSize.x) / Increment.x;
+ State->Interact_Offset[1] = DragDelta.y;
+ }
+ }
+ }
+
+ if (IsItemDeactivated) {
+ }
draw_list->AddCircleFilled(Keyframe_ScreenPos, 4, PointCol);
@@ -1453,6 +1476,7 @@ ImGui_Timeline_DrawGraph(project_data *File, project_state *State, memory *Memor
State->Interact_Offset[0] = atan((Slope_Old - Slope_New) / (1 + Slope_Old * Slope_New));
*/
}
+ ImGui::SetMouseCursor(ImGuiMouseCursor_ResizeAll);
}
for (int h = 0; h < AmountOf(Layer->Property); h++) {
@@ -1505,20 +1529,7 @@ ImGui_Timeline_DrawGraph(project_data *File, project_state *State, memory *Memor
}
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;
- real32 X_Right = (io.MouseClickedPos[0].x > io.MousePos.x) ? io.MouseClickedPos[0].x : io.MousePos.x;
-
- if (Keyframe_ScreenPos[NewIdx].y >= Y_Top && Keyframe_ScreenPos[NewIdx].y <= Y_Bottom &&
- Keyframe_ScreenPos[NewIdx].x >= X_Left && Keyframe_ScreenPos[NewIdx].x <= X_Right)
- {
- if (!PointAddress[Idx]->IsSelected) {
- PointAddress[Idx]->IsSelected = 1;
- }
- } else if (!io.KeyShift) {
- PointAddress[Idx]->IsSelected = 0;
- }
+ ImGui_TestBoxSelection_Point(Keyframe_ScreenPos[NewIdx], io, &PointAddress[Idx]->IsSelected);
}
State->Test.SetCurrentChannel(draw_list, 1);
@@ -1540,8 +1551,10 @@ ImGui_Timeline_DrawGraph(project_data *File, project_state *State, memory *Memor
bool32 LeftClick = ImGui::IsMouseDown(ImGuiMouseButton_Left);
bool32 RightClick = ImGui::IsMouseDown(ImGuiMouseButton_Right);
- if (IsHovered)
+ if (IsHovered) {
PointCol = ImColor(1.0f, 0.8f, 0.8f, 1.0f);
+ ImGui::SetMouseCursor(ImGuiMouseCursor_Hand);
+ }
if (IsItemActivated) {
PointAddress[Idx]->IsSelected = b+1;
@@ -1862,7 +1875,7 @@ ImGui_Timeline_DrawPrecomp(project_data *File, project_state *State, memory *Mem
uint16 *ArrayLocation = Property_GetSortedArray(SortedPropertyArray, i, h);
ImVec2 GraphPos(TimelineAbsolutePos.x, Layer_ScreenPos_Min.y + (Layer_ScreenSize.y * 2) + (Layer_ScreenSize.y * Channel));
ImGui_Timeline_DrawKeySheet(File, State, Memory, UI, io, draw_list, Property, ArrayLocation,
- Increment, GraphPos, TimelineMoveSize, TimelineZoomSize,
+ Increment, TimelineAbsolutePos, GraphPos, TimelineMoveSize, TimelineZoomSize,
TimelineSize, TimelineSizeWithBorder, LayerIncrement);
Channel++;
}
@@ -1917,17 +1930,19 @@ 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 (State->TimelineMode == timeline_mode_graph)
- ImGui_GraphInfo(File, State, Memory, UI, io, SortedPropertyInfo, SortedPropertyArray);
-
ImVec2 FramePadding = ImGui::GetStyle().FramePadding;
ImVec2 ItemSpacing = ImGui::GetStyle().ItemSpacing;
ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, ImVec2(0, 0));
ImGui::PushStyleVar(ImGuiStyleVar_ItemSpacing, ImVec2(0, 0)); // makes setting up the layout easier
ImGui::Begin("Timeline", NULL);
- if (ImGui::IsWindowFocused(ImGuiFocusedFlags_ChildWindows))
+ if (ImGui::IsWindowHovered(ImGuiFocusedFlags_ChildWindows)) {
+ State->SetFocus = true;
State->FocusedWindow = focus_timeline;
+ }
+
+ if (State->TimelineMode == timeline_mode_graph)
+ ImGui_GraphInfo(File, State, Memory, UI, io, SortedPropertyInfo, SortedPropertyArray);
real32 FontHeight = ImGui::GetFontSize();
@@ -2188,36 +2203,7 @@ ImGui_Timeline(project_data *File, project_state *State, memory *Memory, ui *UI,
if (State->Interact_Active == interact_type_keyframe_move ||
State->Interact_Active == interact_type_keyframe_rotate ||
State->Interact_Active == interact_type_keyframe_scale) {
- History_Entry_Commit(Memory, "Move keyframe");
- int h = 0, c = 0, i = 0;
- while (Block_Loop(Memory, F_Layers, File->Layer_Count, &h, &c, &i)) {
- block_layer *Layer = (block_layer *)Memory_Block_AddressAtIndex(Memory, F_Layers, i);
- if (!Layer->IsSelected)
- continue;
- for (int h = 0; h < AmountOf(Layer->Property); h++) {
- uint16 *ArrayLocation = Property_GetSortedArray(SortedPropertyArray, i, h);
- property_channel *Property = &Layer->Property[h];
- for (int p = 0; p < Property->Keyframe_Count; p++) {
- int k = ArrayLocation[p];
- bezier_point *PointAddress = Bezier_LookupAddress(Memory, Property, k);
- if (PointAddress->IsSelected) {
- v2 NewPos[3];
- Bezier_EvaluateValue(State, PointAddress, NewPos);
- History_Action_Swap(Memory, F_Bezier, sizeof(PointAddress->Pos), &PointAddress->Pos);
- PointAddress->Pos[0] = NewPos[0];
- PointAddress->Pos[1] = NewPos[1];
- PointAddress->Pos[2] = NewPos[2];
- }
- }
- }
- }
- History_Entry_End(Memory);
- State->Interact_Offset[0] = 0;
- State->Interact_Offset[1] = 0;
- State->Interact_Offset[2] = 0;
- State->Interact_Offset[3] = 0;
- State->Interact_Active = interact_type_none;
- State->Interact_Modifier = 0;
+ Bezier_Commit(File, State, Memory, SortedPropertyArray);
}
State->BoxSelect = true;
}
@@ -2393,15 +2379,16 @@ ImGui_Popups(project_data *File, project_state *State, ui *UI, memory *Memory, I
{
ImGui::OpenPopup("Save as");
ImVec2 Size(300, 300);
- Assert(0);
- ImGui::SetNextWindowPos(ImVec2(300, 800));
+ ImGuiViewport *Viewport = ImGui::GetMainViewport();
+ ImGui::SetNextWindowPos(Viewport->GetCenter(), 0, ImVec2(0.5, 0.5));
ImGui::SetNextWindowSize(Size);
ImGui::SetKeyboardFocusHere();
} break;
case popup_keybinds:
{
ImGui::OpenPopup("Keybinds");
- ImGui::SetNextWindowPos(ImVec2(300, 800));
+ ImGuiViewport *Viewport = ImGui::GetMainViewport();
+ ImGui::SetNextWindowPos(Viewport->GetCenter(), 0, ImVec2(0.5, 0.5));
ImGui::SetNextWindowSize(ImVec2(500, 300));
ImGui::SetKeyboardFocusHere();
} break;