Implemented removing panels by right clicking on the border.

This commit is contained in:
Peter Slattery 2019-12-28 15:01:02 -08:00
parent 19727da391
commit 20636acdce
5 changed files with 151 additions and 52 deletions

View File

@ -133,6 +133,14 @@ FOLDHAUS_INPUT_COMMAND_PROC(OpenUniverseView)
// //
/////////////////////////////////////// ///////////////////////////////////////
enum panel_edit_mode
{
PanelEdit_Modify,
PanelEdit_Destroy,
PanelEdit_Count,
};
// //
// Drag Panel Border Operation Mode // Drag Panel Border Operation Mode
@ -144,12 +152,16 @@ OPERATION_STATE_DEF(drag_panel_border_operation_state)
// it stores the value calculated when the operation mode is kicked off. // it stores the value calculated when the operation mode is kicked off.
rect InitialPanelBounds; rect InitialPanelBounds;
panel_split_direction PanelEdgeDirection; panel_split_direction PanelEdgeDirection;
panel_edit_mode PanelEditMode;
}; };
OPERATION_RENDER_PROC(UpdateAndRenderDragPanelBorder) OPERATION_RENDER_PROC(UpdateAndRenderDragPanelBorder)
{ {
drag_panel_border_operation_state* OpState = (drag_panel_border_operation_state*)Operation.OpStateMemory; drag_panel_border_operation_state* OpState = (drag_panel_border_operation_state*)Operation.OpStateMemory;
rect PanelBounds = OpState->InitialPanelBounds; rect PanelBounds = OpState->InitialPanelBounds;
if (OpState->PanelEditMode == PanelEdit_Modify)
{
v4 EdgePreviewColor = v4{.3f, .3f, .3f, 1.f}; v4 EdgePreviewColor = v4{.3f, .3f, .3f, 1.f};
v2 EdgePreviewMin = {}; v2 EdgePreviewMin = {};
@ -166,6 +178,37 @@ OPERATION_RENDER_PROC(UpdateAndRenderDragPanelBorder)
} }
PushRenderQuad2D(RenderBuffer, EdgePreviewMin, EdgePreviewMax, EdgePreviewColor); PushRenderQuad2D(RenderBuffer, EdgePreviewMin, EdgePreviewMax, EdgePreviewColor);
}
else if (OpState->PanelEditMode == PanelEdit_Destroy)
{
rect PanelToDeleteBounds = {};
if (OpState->PanelEdgeDirection == PanelSplit_Horizontal)
{
r32 SplitY = GSLerp(PanelBounds.Min.y, PanelBounds.Max.y, OpState->Panel->SplitPercent);
if (Mouse.Pos.y > SplitY)
{
PanelToDeleteBounds = GetTopPanelBounds(OpState->Panel, PanelBounds);
}
else
{
PanelToDeleteBounds = GetBottomPanelBounds(OpState->Panel, PanelBounds);
}
}
else if (OpState->PanelEdgeDirection == PanelSplit_Vertical)
{
r32 SplitX = GSLerp(PanelBounds.Min.x, PanelBounds.Max.x, OpState->Panel->SplitPercent);
if (Mouse.Pos.x > SplitX)
{
PanelToDeleteBounds = GetRightPanelBounds(OpState->Panel, PanelBounds);
}
else
{
PanelToDeleteBounds = GetLeftPanelBounds(OpState->Panel, PanelBounds);
}
}
v4 OverlayColor = v4{0, 0, 0, .3f};
PushRenderQuad2D(RenderBuffer, PanelToDeleteBounds.Min, PanelToDeleteBounds.Max, OverlayColor);
}
} }
FOLDHAUS_INPUT_COMMAND_PROC(EndDragPanelBorderOperation) FOLDHAUS_INPUT_COMMAND_PROC(EndDragPanelBorderOperation)
@ -174,6 +217,8 @@ FOLDHAUS_INPUT_COMMAND_PROC(EndDragPanelBorderOperation)
panel* Panel = OpState->Panel; panel* Panel = OpState->Panel;
rect PanelBounds = OpState->InitialPanelBounds; rect PanelBounds = OpState->InitialPanelBounds;
if (OpState->PanelEditMode == PanelEdit_Modify)
{
if (Panel->SplitDirection == PanelSplit_Horizontal) if (Panel->SplitDirection == PanelSplit_Horizontal)
{ {
r32 NewSplitY = Mouse.Pos.y; r32 NewSplitY = Mouse.Pos.y;
@ -206,22 +251,52 @@ FOLDHAUS_INPUT_COMMAND_PROC(EndDragPanelBorderOperation)
Panel->SplitPercent = (NewSplitX - PanelBounds.Min.x) / Width(PanelBounds); Panel->SplitPercent = (NewSplitX - PanelBounds.Min.x) / Width(PanelBounds);
} }
} }
}
else // PanelEdit_Destroy
{
if (OpState->PanelEdgeDirection == PanelSplit_Horizontal)
{
r32 SplitY = GSLerp(PanelBounds.Min.y, PanelBounds.Max.y, OpState->Panel->SplitPercent);
if (Mouse.Pos.y > SplitY)
{
ConsolidatePanelsKeepOne(Panel, Panel->Bottom, &State->PanelSystem);
}
else
{
ConsolidatePanelsKeepOne(Panel, Panel->Top, &State->PanelSystem);
}
}
else if (OpState->PanelEdgeDirection == PanelSplit_Vertical)
{
r32 SplitX = GSLerp(PanelBounds.Min.x, PanelBounds.Max.x, OpState->Panel->SplitPercent);
if (Mouse.Pos.x > SplitX)
{
ConsolidatePanelsKeepOne(Panel, Panel->Left, &State->PanelSystem);
}
else
{
ConsolidatePanelsKeepOne(Panel, Panel->Right, &State->PanelSystem);
}
}
}
DeactivateCurrentOperationMode(&State->Modes); DeactivateCurrentOperationMode(&State->Modes);
} }
input_command DragPanelBorderCommands[] = { input_command DragPanelBorderCommands[] = {
{ KeyCode_MouseLeftButton, KeyCode_Invalid, Command_Ended, EndDragPanelBorderOperation }, { KeyCode_MouseLeftButton, KeyCode_Invalid, Command_Ended, EndDragPanelBorderOperation },
{ KeyCode_MouseRightButton, KeyCode_Invalid, Command_Ended, EndDragPanelBorderOperation },
}; };
internal void internal void
BeginDragPanelBorder(panel* Panel, rect PanelBounds, panel_split_direction PanelEdgeDirection, mouse_state Mouse, app_state* State) BeginDragPanelBorder(panel* Panel, panel_edit_mode PanelEditMode, rect PanelBounds, panel_split_direction PanelEdgeDirection, mouse_state Mouse, app_state* State)
{ {
operation_mode* DragPanelBorder = ActivateOperationModeWithCommands(&State->Modes, DragPanelBorderCommands, UpdateAndRenderDragPanelBorder); operation_mode* DragPanelBorder = ActivateOperationModeWithCommands(&State->Modes, DragPanelBorderCommands, UpdateAndRenderDragPanelBorder);
drag_panel_border_operation_state* OpState = CreateOperationState(DragPanelBorder, &State->Modes, drag_panel_border_operation_state); drag_panel_border_operation_state* OpState = CreateOperationState(DragPanelBorder, &State->Modes, drag_panel_border_operation_state);
OpState->Panel = Panel; OpState->Panel = Panel;
OpState->InitialPanelBounds = PanelBounds; OpState->InitialPanelBounds = PanelBounds;
OpState->PanelEdgeDirection = PanelEdgeDirection; OpState->PanelEdgeDirection = PanelEdgeDirection;
OpState->PanelEditMode = PanelEditMode;
} }
// ---------------- // ----------------
@ -306,7 +381,7 @@ BeginSplitPanelOperation(panel* Panel, rect PanelBounds, mouse_state Mouse, app_
#define PANEL_EDGE_CLICK_MAX_DISTANCE 6 #define PANEL_EDGE_CLICK_MAX_DISTANCE 6
internal b32 internal b32
HandleMouseDownPanelInteractionOrRecurse(panel* Panel, rect PanelBounds, mouse_state Mouse, app_state* State) HandleMouseDownPanelInteractionOrRecurse(panel* Panel, panel_edit_mode PanelEditMode, rect PanelBounds, mouse_state Mouse, app_state* State)
{ {
b32 HandledMouseInput = false; b32 HandledMouseInput = false;
@ -314,6 +389,7 @@ HandleMouseDownPanelInteractionOrRecurse(panel* Panel, rect PanelBounds, mouse_s
&& PointIsInRange(Mouse.DownPos, PanelBounds.Min, PanelBounds.Min + v2{25, 25})) && PointIsInRange(Mouse.DownPos, PanelBounds.Min, PanelBounds.Min + v2{25, 25}))
{ {
BeginSplitPanelOperation(Panel, PanelBounds, Mouse, State); BeginSplitPanelOperation(Panel, PanelBounds, Mouse, State);
HandledMouseInput = true;
} }
else if (Panel->SplitDirection == PanelSplit_Horizontal) else if (Panel->SplitDirection == PanelSplit_Horizontal)
{ {
@ -321,15 +397,21 @@ HandleMouseDownPanelInteractionOrRecurse(panel* Panel, rect PanelBounds, mouse_s
r32 ClickDistanceFromSplit = GSAbs(Mouse.DownPos.y - SplitY); r32 ClickDistanceFromSplit = GSAbs(Mouse.DownPos.y - SplitY);
if (ClickDistanceFromSplit < PANEL_EDGE_CLICK_MAX_DISTANCE) if (ClickDistanceFromSplit < PANEL_EDGE_CLICK_MAX_DISTANCE)
{ {
BeginDragPanelBorder(Panel, PanelBounds, PanelSplit_Horizontal, Mouse, State); BeginDragPanelBorder(Panel, PanelEditMode, PanelBounds, PanelSplit_Horizontal, Mouse, State);
HandledMouseInput = true; HandledMouseInput = true;
} }
else else
{ {
rect TopPanelBounds = GetTopPanelBounds(Panel, PanelBounds); rect TopPanelBounds = GetTopPanelBounds(Panel, PanelBounds);
rect BottomPanelBounds = GetBottomPanelBounds(Panel, PanelBounds); rect BottomPanelBounds = GetBottomPanelBounds(Panel, PanelBounds);
HandleMouseDownPanelInteractionOrRecurse(&Panel->Bottom->Panel, BottomPanelBounds, Mouse, State); if (PointIsInRect(Mouse.DownPos, BottomPanelBounds))
HandleMouseDownPanelInteractionOrRecurse(&Panel->Top->Panel, TopPanelBounds, Mouse, State); {
HandleMouseDownPanelInteractionOrRecurse(&Panel->Bottom->Panel, PanelEditMode, BottomPanelBounds, Mouse, State);
}
if (PointIsInRect(Mouse.DownPos, TopPanelBounds))
{
HandleMouseDownPanelInteractionOrRecurse(&Panel->Top->Panel, PanelEditMode, TopPanelBounds, Mouse, State);
}
} }
} }
else if (Panel->SplitDirection == PanelSplit_Vertical) else if (Panel->SplitDirection == PanelSplit_Vertical)
@ -338,15 +420,21 @@ HandleMouseDownPanelInteractionOrRecurse(panel* Panel, rect PanelBounds, mouse_s
r32 ClickDistanceFromSplit = GSAbs(Mouse.DownPos.x - SplitX); r32 ClickDistanceFromSplit = GSAbs(Mouse.DownPos.x - SplitX);
if (ClickDistanceFromSplit < PANEL_EDGE_CLICK_MAX_DISTANCE) if (ClickDistanceFromSplit < PANEL_EDGE_CLICK_MAX_DISTANCE)
{ {
BeginDragPanelBorder(Panel, PanelBounds, PanelSplit_Vertical, Mouse, State); BeginDragPanelBorder(Panel, PanelEditMode, PanelBounds, PanelSplit_Vertical, Mouse, State);
HandledMouseInput = true; HandledMouseInput = true;
} }
else else
{ {
rect LeftPanelBounds = GetLeftPanelBounds(Panel, PanelBounds); rect LeftPanelBounds = GetLeftPanelBounds(Panel, PanelBounds);
rect RightPanelBounds = GetRightPanelBounds(Panel, PanelBounds); rect RightPanelBounds = GetRightPanelBounds(Panel, PanelBounds);
HandleMouseDownPanelInteractionOrRecurse(&Panel->Left->Panel, LeftPanelBounds, Mouse, State); if (PointIsInRect(Mouse.DownPos, LeftPanelBounds))
HandleMouseDownPanelInteractionOrRecurse(&Panel->Right->Panel, RightPanelBounds, Mouse, State); {
HandleMouseDownPanelInteractionOrRecurse(&Panel->Left->Panel, PanelEditMode, LeftPanelBounds, Mouse, State);
}
if (PointIsInRect(Mouse.DownPos, RightPanelBounds))
{
HandleMouseDownPanelInteractionOrRecurse(&Panel->Right->Panel, PanelEditMode, RightPanelBounds, Mouse, State);
}
} }
} }
@ -358,10 +446,14 @@ HandleMousePanelInteraction(panel_system* PanelSystem, rect WindowBounds, mouse_
{ {
b32 HandledMouseInput = false; b32 HandledMouseInput = false;
panel* FirstPanel = &PanelSystem->Panels[0].Panel;
if (MouseButtonTransitionedDown(Mouse.LeftButtonState)) if (MouseButtonTransitionedDown(Mouse.LeftButtonState))
{ {
panel* FirstPanel = &PanelSystem->Panels[0].Panel; HandledMouseInput = HandleMouseDownPanelInteractionOrRecurse(FirstPanel, PanelEdit_Modify, WindowBounds, Mouse, State);
HandledMouseInput = HandleMouseDownPanelInteractionOrRecurse(FirstPanel, WindowBounds, Mouse, State); }
else if (MouseButtonTransitionedDown(Mouse.RightButtonState))
{
HandledMouseInput = HandleMouseDownPanelInteractionOrRecurse(FirstPanel, PanelEdit_Destroy, WindowBounds, Mouse, State);
} }
return HandledMouseInput; return HandledMouseInput;

View File

@ -133,6 +133,17 @@ FreePanelEntry(panel_entry* Entry, panel_system* PanelSystem)
PanelSystem->FreeList.Free.Next = Entry; PanelSystem->FreeList.Free.Next = Entry;
} }
internal void
FreePanelEntryRecursive(panel_entry* Entry, panel_system* PanelSystem)
{
if (Entry->Panel.SplitDirection != PanelSplit_NoSplit)
{
FreePanelEntryRecursive(Entry->Panel.Left, PanelSystem);
FreePanelEntryRecursive(Entry->Panel.Right, PanelSystem);
}
FreePanelEntry(Entry, PanelSystem);
}
internal void internal void
FreePanelAtIndex(s32 Index, panel_system* PanelSystem) FreePanelAtIndex(s32 Index, panel_system* PanelSystem)
{ {
@ -182,11 +193,12 @@ ConsolidatePanelsKeepOne(panel* Parent, panel_entry* PanelEntryToKeep, panel_sys
panel_entry* LeftChild = Parent->Left; panel_entry* LeftChild = Parent->Left;
panel_entry* RightChild = Parent->Right; panel_entry* RightChild = Parent->Right;
*Parent = PanelEntryToKeep->Panel; panel_entry* PanelEntryToDestroy = PanelEntryToKeep == LeftChild ? RightChild : LeftChild;
Parent->SplitDirection = PanelSplit_NoSplit;
FreePanelEntry(LeftChild, PanelSystem); *Parent = PanelEntryToKeep->Panel;
FreePanelEntry(RightChild, PanelSystem);
FreePanelEntry(PanelEntryToKeep, PanelSystem);
FreePanelEntryRecursive(PanelEntryToDestroy, PanelSystem);
} }
internal void internal void

View File

@ -5,7 +5,6 @@
// [x] - play, pause, stop, // [x] - play, pause, stop,
// [] - setting the start and end of the animation system // [] - setting the start and end of the animation system
// [] - displaying multiple layers // [] - displaying multiple layers
// [] -
inline r32 inline r32
GetTimeFromPointInAnimationPanel(v2 Point, rect PanelBounds, s32 StartFrame, s32 EndFrame, r32 SecondsPerFrame) GetTimeFromPointInAnimationPanel(v2 Point, rect PanelBounds, s32 StartFrame, s32 EndFrame, r32 SecondsPerFrame)

View File

@ -370,6 +370,7 @@ HandleWindowMessage (MSG Message, window* Window, input_queue* InputQueue, mouse
AddInputEventEntry(InputQueue, KeyCode_MouseRightButton, false, true, AddInputEventEntry(InputQueue, KeyCode_MouseRightButton, false, true,
ShiftDown, AltDown, CtrlDown, false); ShiftDown, AltDown, CtrlDown, false);
Mouse->RightButtonState = KeyState_IsDown & ~KeyState_WasDown; Mouse->RightButtonState = KeyState_IsDown & ~KeyState_WasDown;
Mouse->DownPos = Mouse->Pos;
}break; }break;
case WM_LBUTTONUP: case WM_LBUTTONUP:

View File

@ -36,14 +36,13 @@ Switch To Nodes
- evaluation step (one node at a time) - evaluation step (one node at a time)
Hardening Hardening
- turn the default sculpture view into an operation mode ? (have to think about this) x turn the default sculpture view into an operation mode ? (have to think about this)
- Then we want to think about separating out mode render functions from mode update functions. Not sure its necessary but having something that operates like an update funciton but is called render is weird. Might want some sort of coroutine functionality in place, where modes can add and remove optional, parallel - Then we want to think about separating out mode render functions from mode update functions. Not sure its necessary but having something that operates like an update funciton but is called render is weird. Might want some sort of coroutine functionality in place, where modes can add and remove optional, parallel
update functions update functions
- memory visualization - memory visualization
- x Log memory allocations - x Log memory allocations
- separate rendering thread - separate rendering thread
- cache led positions. Only update if they are moving - cache led positions. Only update if they are moving
- :HotCodeReloading
UI Improvements UI Improvements
- highlight node field under active edit - highlight node field under active edit
@ -92,10 +91,6 @@ Animation
x timeline x timeline
x create clips that play x create clips that play
- clips can have parameters that drive them? - clips can have parameters that drive them?
- clips should have prerequesites
- - channels active
- - patterns active in the channel
- - when a clip is playing, it should just take over the whole structure
Optimization Optimization
- investigate the memory access pattern of the SACN / LED systems. Guessing they are very slow - investigate the memory access pattern of the SACN / LED systems. Guessing they are very slow