From f53becef5bf50f211aea939430c2276cff707fc8 Mon Sep 17 00:00:00 2001 From: PS Date: Sat, 7 Nov 2020 23:43:41 -0800 Subject: [PATCH] Hot panel is passed to input event handlers --- src/app/editor/foldhaus_command_dispatch.h | 2 +- src/app/editor/foldhaus_editor.cpp | 32 +++++++++++-------- src/app/editor/foldhaus_interface.cpp | 2 -- .../foldhaus_panel_animation_timeline.h | 6 ++-- .../panels/foldhaus_panel_sculpture_view.h | 1 - src/app/foldhaus_app.h | 5 ++- 6 files changed, 26 insertions(+), 22 deletions(-) diff --git a/src/app/editor/foldhaus_command_dispatch.h b/src/app/editor/foldhaus_command_dispatch.h index bad6250..6c6cf1c 100644 --- a/src/app/editor/foldhaus_command_dispatch.h +++ b/src/app/editor/foldhaus_command_dispatch.h @@ -5,7 +5,7 @@ // #ifndef FOLDHAUS_COMMAND_DISPATCH_H -#define FOLDHAUS_INPUT_COMMAND_PROC(name) void name(app_state* State, input_entry Event, mouse_state Mouse, context Context) +#define FOLDHAUS_INPUT_COMMAND_PROC(name) void name(app_state* State, input_entry Event, mouse_state Mouse, context Context, panel* Panel) typedef FOLDHAUS_INPUT_COMMAND_PROC(input_command_proc); // NOTE(Peter): Helper function so I don't have to remember the parameters to this define diff --git a/src/app/editor/foldhaus_editor.cpp b/src/app/editor/foldhaus_editor.cpp index 5ad1dfe..ed01de2 100644 --- a/src/app/editor/foldhaus_editor.cpp +++ b/src/app/editor/foldhaus_editor.cpp @@ -10,10 +10,13 @@ Editor_HandleInput (app_state* State, rect2 WindowBounds, input_queue InputQueue { DEBUG_TRACK_FUNCTION; + panel* ActivePanel = PanelSystem_GetPanelContainingPoint(&State->PanelSystem, Mouse.Pos); b32 PanelSystemHandledInput = HandleMousePanelInteraction(&State->PanelSystem, State->WindowBounds, Mouse, State); - if (!PanelSystemHandledInput) + if (!PanelSystemHandledInput && ActivePanel) { + panel_definition ActiveDef = State->PanelSystem.PanelDefs[ActivePanel->TypeIndex]; + input_command_registry ActiveCommands = {}; if (State->Modes.ActiveModesCount > 0) { @@ -21,19 +24,15 @@ Editor_HandleInput (app_state* State, rect2 WindowBounds, input_queue InputQueue } else { - panel* PanelWithMouseOverIt = PanelSystem_GetPanelContainingPoint(&State->PanelSystem, Mouse.Pos); - if (!PanelWithMouseOverIt) { return; } - State->HotPanel = PanelWithMouseOverIt; - - s32 PanelTypeIndex = PanelWithMouseOverIt->TypeIndex; - panel_definition PanelDefinition = State->PanelSystem.PanelDefs[PanelTypeIndex]; - if (!PanelDefinition.InputCommands) { return; } - - ActiveCommands.Commands = PanelDefinition.InputCommands; - ActiveCommands.Size = sizeof(*PanelDefinition.InputCommands) / sizeof(PanelDefinition.InputCommands[0]); - ActiveCommands.Used = ActiveCommands.Size; + if (ActiveDef.InputCommands) + { + ActiveCommands.Commands = ActiveDef.InputCommands; + ActiveCommands.Size = sizeof(*ActiveDef.InputCommands) / sizeof(ActiveDef.InputCommands[0]); + ActiveCommands.Used = ActiveCommands.Size; + } } + // Fill up the command queue for (s32 EventIdx = 0; EventIdx < InputQueue.QueueUsed; EventIdx++) { input_entry Event = InputQueue.Entries[EventIdx]; @@ -60,7 +59,14 @@ Editor_HandleInput (app_state* State, rect2 WindowBounds, input_queue InputQueue for (s32 CommandIdx = State->CommandQueue.Used - 1; CommandIdx >= 0; CommandIdx--) { command_queue_entry* Entry = &State->CommandQueue.Commands[CommandIdx]; - Entry->Command.Proc(State, Entry->Event, Mouse, Context); + if (Entry->Command.Proc) + { + Entry->Command.Proc(State, Entry->Event, Mouse, Context, ActivePanel); + } + else + { + EndCurrentOperationMode(State); + } } ClearCommandQueue(&State->CommandQueue); diff --git a/src/app/editor/foldhaus_interface.cpp b/src/app/editor/foldhaus_interface.cpp index 0a33f8f..7a83912 100644 --- a/src/app/editor/foldhaus_interface.cpp +++ b/src/app/editor/foldhaus_interface.cpp @@ -94,7 +94,6 @@ OPERATION_RENDER_PROC(UpdateAndRenderDragPanelBorder) FOLDHAUS_INPUT_COMMAND_PROC(EndDragPanelBorderOperation) { drag_panel_border_operation_state* OpState = GetCurrentOperationState(State->Modes, drag_panel_border_operation_state); - panel* Panel = OpState->Panel; rect2 PanelBounds = OpState->InitialPanelBounds; if (OpState->PanelEditMode == PanelEdit_Modify) @@ -224,7 +223,6 @@ OPERATION_RENDER_PROC(UpdateAndRenderSplitPanel) FOLDHAUS_INPUT_COMMAND_PROC(EndSplitPanelOperation) { split_panel_operation_state* OpState = GetCurrentOperationState(State->Modes, split_panel_operation_state); - panel* Panel = OpState->Panel; rect2 PanelBounds = OpState->InitialPanelBounds; r32 XDistance = Abs(Mouse.Pos.x - Mouse.DownPos.x); diff --git a/src/app/editor/panels/foldhaus_panel_animation_timeline.h b/src/app/editor/panels/foldhaus_panel_animation_timeline.h index 38ea145..6210cfa 100644 --- a/src/app/editor/panels/foldhaus_panel_animation_timeline.h +++ b/src/app/editor/panels/foldhaus_panel_animation_timeline.h @@ -45,7 +45,6 @@ AddAnimationBlockAtCurrentTime (u32 AnimationProcHandle, u32 LayerHandle, animat FOLDHAUS_INPUT_COMMAND_PROC(DeleteAnimationBlockCommand) { - panel* Panel = PanelSystem_GetPanelContainingPoint(&State->PanelSystem, Context.Mouse.Pos); animation_timeline_state* PanelState = Panel_GetStateStruct(Panel, animation_timeline_state); handle SelectedBlockHandle = PanelState->SelectedBlockHandle; @@ -153,7 +152,7 @@ OPERATION_RENDER_PROC(UpdateDragAnimationClip) animation_block* AnimationBlock = Animation_GetBlockFromHandle(ActiveAnim, OpState->BlockHandle); if (!AnimationBlock) { - EndCurrentOperationMode(State, {}, Mouse, Context); + EndCurrentOperationMode(State); return; } @@ -230,7 +229,7 @@ OPERATION_RENDER_PROC(UpdateDragAnimationClip) } input_command DragAnimationClipCommands [] = { - { KeyCode_MouseLeftButton, KeyCode_Invalid, Command_Ended, EndCurrentOperationMode }, + { KeyCode_MouseLeftButton, KeyCode_Invalid, Command_Ended, 0 }, }; internal void @@ -255,7 +254,6 @@ SelectAndBeginDragAnimationBlock(animation_timeline_state* TimelineState, handle FOLDHAUS_INPUT_COMMAND_PROC(AddAnimationBlockCommand) { - panel* Panel = PanelSystem_GetPanelContainingPoint(&State->PanelSystem, Context.Mouse.Pos); animation_timeline_state* TimelineState = Panel_GetStateStruct(Panel, animation_timeline_state); animation* ActiveAnim = AnimationSystem_GetActiveAnimation(&State->AnimationSystem); diff --git a/src/app/editor/panels/foldhaus_panel_sculpture_view.h b/src/app/editor/panels/foldhaus_panel_sculpture_view.h index 4214261..ee4fecb 100644 --- a/src/app/editor/panels/foldhaus_panel_sculpture_view.h +++ b/src/app/editor/panels/foldhaus_panel_sculpture_view.h @@ -42,7 +42,6 @@ input_command MouseRotateViewCommands [] = { FOLDHAUS_INPUT_COMMAND_PROC(Begin3DViewMouseRotate) { - panel* Panel = PanelSystem_GetPanelContainingPoint(&State->PanelSystem, Context.Mouse.DownPos); sculpture_view_panel_state* PanelState = Panel_GetStateStruct(Panel, sculpture_view_panel_state); operation_mode* RotateViewMode = ActivateOperationModeWithCommands(&State->Modes, MouseRotateViewCommands, Update3DViewMouseRotate); diff --git a/src/app/foldhaus_app.h b/src/app/foldhaus_app.h index 3e6bf1f..66755c6 100644 --- a/src/app/foldhaus_app.h +++ b/src/app/foldhaus_app.h @@ -26,6 +26,8 @@ typedef struct app_state app_state; +typedef struct panel panel; + #include "editor/foldhaus_command_dispatch.h" #include "editor/foldhaus_operation_mode.h" @@ -201,7 +203,8 @@ TestPatternThree(led_buffer* Leds, assembly Assembly, r32 Time, gs_memory_arena* // END TEMPORARY PATTERNS -FOLDHAUS_INPUT_COMMAND_PROC(EndCurrentOperationMode) +internal void +EndCurrentOperationMode(app_state* State) { DeactivateCurrentOperationMode(&State->Modes); }