diff --git a/src/foldhaus_app.cpp b/src/foldhaus_app.cpp index 2746c5c..e4ebbed 100644 --- a/src/foldhaus_app.cpp +++ b/src/foldhaus_app.cpp @@ -352,8 +352,7 @@ RELOAD_STATIC_DATA(ReloadStaticData) { RegisterKeyPressCommand(&State->InputCommandRegistry, KeyCode_MouseLeftButton, true, KeyCode_Invalid, CameraMouseControl); - RegisterKeyPressCommand(&State->InputCommandRegistry, KeyCode_U, false, KeyCode_Invalid, ToggleUniverseDebugView); - RegisterMouseWheelCommand(&State->InputCommandRegistry, CameraMouseZoom); + RegisterKeyPressCommand(&State->InputCommandRegistry, KeyCode_U, false, KeyCode_Invalid, OpenUniverseView); RegisterKeyPressCommand(&State->InputCommandRegistry, KeyCode_A, false, KeyCode_Invalid, OpenNodeLister); RegisterKeyPressCommand(&State->InputCommandRegistry, KeyCode_Tab, false, KeyCode_Invalid, ToggleNodeDisplay); @@ -475,9 +474,6 @@ INITIALIZE_APPLICATION(InitializeApplication) State->PixelsToWorldScale = .01f; - State->UniverseOutputDisplayOffset = v2{0, 0}; - State->UniverseOutputDisplayZoom = 1.0f; - GlobalDebugServices->Interface.RenderSculpture = true; State->NodeList = AllocateNodeList(State->Permanent, Kilobytes(64)); @@ -719,57 +715,6 @@ UPDATE_AND_RENDER(UpdateAndRender) PushRenderOrthographic(RenderBuffer, 0, 0, Context.WindowWidth, Context.WindowHeight); - // Universe Data View - if (State->DrawUniverseOutputDisplay) - { - DEBUG_TRACK_SCOPE(DrawUniverseOutputDisplay); - - string TitleBarString = InitializeEmptyString(PushArray(State->Transient, char, 64), 64); - - v2 DisplayArea_Dimension = v2{600, 600}; - v2 DisplayContents_Offset = State->UniverseOutputDisplayOffset; - v2 DisplayArea_TopLeft = v2{300, Context.WindowHeight - 50} + DisplayContents_Offset; - v2 UniverseDisplayDimension = v2{100, 100} * State->UniverseOutputDisplayZoom; - v2 Padding = v2{25, 50} * State->UniverseOutputDisplayZoom; - - v2 UniverseDisplayTopLeft = DisplayArea_TopLeft; - - sacn_universe_buffer* UniverseList = State->SACN.UniverseBuffer; - while(UniverseList) - { - for (s32 UniverseIdx = 0; - UniverseIdx < UniverseList->Used; - UniverseIdx++) - { - sacn_universe* Universe = UniverseList->Universes + UniverseIdx; - - DrawSACNUniversePixels(RenderBuffer, Universe, - UniverseDisplayTopLeft, UniverseDisplayDimension); - - if (State->UniverseOutputDisplayZoom > .5f) - { - v2 TitleDisplayStart = UniverseDisplayTopLeft + v2{0, 12}; - PrintF(&TitleBarString, "Universe %d", Universe->Universe); - DrawString(RenderBuffer, TitleBarString, State->Interface.Font, 12, - TitleDisplayStart, WhiteV4); - } - - UniverseDisplayTopLeft.x += UniverseDisplayDimension.x + Padding.x; - if (UniverseDisplayTopLeft.x > DisplayArea_TopLeft.x + DisplayArea_Dimension.x) - { - UniverseDisplayTopLeft.x = DisplayArea_TopLeft.x; - UniverseDisplayTopLeft.y -= UniverseDisplayDimension.y + Padding.y; - } - - if (UniverseDisplayTopLeft.y < DisplayArea_TopLeft.y - DisplayArea_Dimension.y) - { - break; - } - } - UniverseList = UniverseList->Next; - } - } - /////////////////////////////////////// // Menu Bar ////////////////////////////////////// diff --git a/src/foldhaus_app.h b/src/foldhaus_app.h index 8e36416..913baa7 100644 --- a/src/foldhaus_app.h +++ b/src/foldhaus_app.h @@ -97,12 +97,6 @@ struct app_state r32 PixelsToWorldScale; v4 Camera_StartDragPos; - b32 DrawUniverseOutputDisplay; - v2 UniverseOutputDisplayOffset; - r32 UniverseOutputDisplayZoom; - - v2 NodeListMenuPosition; - node_list* NodeList; node_interaction NodeInteraction; node_render_settings NodeRenderSettings; diff --git a/src/foldhaus_interface.cpp b/src/foldhaus_interface.cpp index 64a631c..76568c9 100644 --- a/src/foldhaus_interface.cpp +++ b/src/foldhaus_interface.cpp @@ -7,35 +7,13 @@ FOLDHAUS_INPUT_COMMAND_PROC(CameraMouseControl) State->Camera_StartDragPos = V4(State->Camera.Position, 1); } - if (!State->DrawUniverseOutputDisplay) - { - v2 TotalDeltaPos = Mouse.Pos - Mouse.DownPos; - - m44 XRotation = GetXRotation(-TotalDeltaPos.y * State->PixelsToWorldScale); - m44 YRotation = GetYRotation(TotalDeltaPos.x * State->PixelsToWorldScale); - m44 Combined = XRotation * YRotation; - - State->Camera.Position = V3(Combined * State->Camera_StartDragPos); - } - else - { - State->UniverseOutputDisplayOffset += Mouse.DeltaPos; - } -} - -FOLDHAUS_INPUT_COMMAND_PROC(CameraMouseZoom) -{ - if (State->DrawUniverseOutputDisplay) - { - r32 DeltaZoom = (r32)(Mouse.Scroll) / 120; - State->UniverseOutputDisplayZoom = GSClamp(0.1f, State->UniverseOutputDisplayZoom + DeltaZoom, 4.f); - } + v2 TotalDeltaPos = Mouse.Pos - Mouse.DownPos; -} - -FOLDHAUS_INPUT_COMMAND_PROC(ToggleUniverseDebugView) -{ - State->DrawUniverseOutputDisplay = !State->DrawUniverseOutputDisplay; + m44 XRotation = GetXRotation(-TotalDeltaPos.y * State->PixelsToWorldScale); + m44 YRotation = GetYRotation(TotalDeltaPos.x * State->PixelsToWorldScale); + m44 Combined = XRotation * YRotation; + + State->Camera.Position = V3(Combined * State->Camera_StartDragPos); } FOLDHAUS_INPUT_COMMAND_PROC(ToggleNodeDisplay) @@ -49,9 +27,107 @@ FOLDHAUS_INPUT_COMMAND_PROC(ToggleNodeDisplay) // /////////////////////////////////////// +struct universe_view_operation_state +{ + v2 DisplayOffset; + r32 Zoom; +}; + OPERATION_RENDER_PROC(RenderUniverseView) { + DEBUG_TRACK_SCOPE(DrawUniverseOutputDisplay); + // TODO(Peter): Pass this in as a parameter + operation_mode Mode = State->Modes.ActiveModes[State->Modes.ActiveModesCount - 1]; + universe_view_operation_state* OpState = (universe_view_operation_state*)Mode.OpStateMemory; + + string TitleBarString = InitializeEmptyString(PushArray(State->Transient, char, 64), 64); + + v2 DisplayArea_Dimension = v2{600, 600}; + v2 DisplayContents_Offset = OpState->DisplayOffset; + v2 DisplayArea_TopLeft = v2{300, (r32)RenderBuffer->ViewHeight - 50} + DisplayContents_Offset; + v2 UniverseDisplayDimension = v2{100, 100} * OpState->Zoom; + v2 Padding = v2{25, 50} * OpState->Zoom; + + v2 UniverseDisplayTopLeft = DisplayArea_TopLeft; + + sacn_universe_buffer* UniverseList = State->SACN.UniverseBuffer; + while(UniverseList) + { + for (s32 UniverseIdx = 0; + UniverseIdx < UniverseList->Used; + UniverseIdx++) + { + sacn_universe* Universe = UniverseList->Universes + UniverseIdx; + + DrawSACNUniversePixels(RenderBuffer, Universe, + UniverseDisplayTopLeft, UniverseDisplayDimension); + + if (OpState->Zoom > .5f) + { + v2 TitleDisplayStart = UniverseDisplayTopLeft + v2{0, 12}; + PrintF(&TitleBarString, "Universe %d", Universe->Universe); + DrawString(RenderBuffer, TitleBarString, State->Interface.Font, 12, + TitleDisplayStart, WhiteV4); + } + + UniverseDisplayTopLeft.x += UniverseDisplayDimension.x + Padding.x; + if (UniverseDisplayTopLeft.x > DisplayArea_TopLeft.x + DisplayArea_Dimension.x) + { + UniverseDisplayTopLeft.x = DisplayArea_TopLeft.x; + UniverseDisplayTopLeft.y -= UniverseDisplayDimension.y + Padding.y; + } + + if (UniverseDisplayTopLeft.y < DisplayArea_TopLeft.y - DisplayArea_Dimension.y) + { + break; + } + } + UniverseList = UniverseList->Next; + } +} + +// TODO(Peter): Something isn't working with my laptop trackpad's zoom +FOLDHAUS_INPUT_COMMAND_PROC(UniverseZoom) +{ + // TODO(Peter): Pass this in as a parameter + operation_mode Mode = State->Modes.ActiveModes[State->Modes.ActiveModesCount - 1]; + universe_view_operation_state* OpState = (universe_view_operation_state*)Mode.OpStateMemory; + r32 DeltaZoom = (r32)(Mouse.Scroll) / 120; + OpState->Zoom = GSClamp(0.1f, OpState->Zoom + DeltaZoom, 4.f); +} + +FOLDHAUS_INPUT_COMMAND_PROC(UniverseViewPan) +{ + // TODO(Peter): Pass this in as a parameter + operation_mode Mode = State->Modes.ActiveModes[State->Modes.ActiveModesCount - 1]; + universe_view_operation_state* OpState = (universe_view_operation_state*)Mode.OpStateMemory; + OpState->DisplayOffset += Mouse.DeltaPos; +} + +FOLDHAUS_INPUT_COMMAND_PROC(CloseUniverseView) +{ + DeactivateCurrentOperationMode(&State->Modes); +} + +FOLDHAUS_INPUT_COMMAND_PROC(OpenUniverseView) +{ + operation_mode* UniverseViewMode = ActivateOperationMode(&State->Modes); + UniverseViewMode->Render = RenderUniverseView; + + { // Mode Commands + InitializeInputCommandRegistry(&UniverseViewMode->Commands, 3, &State->Modes.Arena); + RegisterKeyPressCommand(&UniverseViewMode->Commands, KeyCode_MouseLeftButton, true, KeyCode_Invalid, UniverseViewPan); + RegisterKeyPressCommand(&UniverseViewMode->Commands, KeyCode_U, false, KeyCode_Invalid, CloseUniverseView); + RegisterMouseWheelCommand(&UniverseViewMode->Commands, UniverseZoom); + } + + // State Setup + universe_view_operation_state* OpState = CreateOperationState(UniverseViewMode, + &State->Modes, + universe_view_operation_state); + OpState->DisplayOffset = v2{0, 0}; + OpState->Zoom = 1.0f; } //////////////////////////////////////// @@ -63,13 +139,14 @@ OPERATION_RENDER_PROC(RenderUniverseView) struct node_lister_operation_state { search_lister SearchLister; + v2 ListPosition; }; OPERATION_RENDER_PROC(RenderNodeLister) { node_lister_operation_state* OpState = (node_lister_operation_state*)Operation.OpStateMemory; - v2 TopLeft = State->NodeListMenuPosition; + v2 TopLeft = OpState->ListPosition; v2 Dimension = v2{300, 30}; // Filter the lister @@ -139,8 +216,9 @@ FOLDHAUS_INPUT_COMMAND_PROC(OpenNodeLister) AddNodeOperation->Render = RenderNodeLister; - node_lister_operation_state* OpState = PushStruct(&State->Modes.Arena, node_lister_operation_state); - AddNodeOperation->OpStateMemory = (u8*)OpState; + node_lister_operation_state* OpState = CreateOperationState(AddNodeOperation, + &State->Modes, + node_lister_operation_state); { OpState->SearchLister.SourceListCount = NodeSpecificationsCount; OpState->SearchLister.SourceList = PushArray(&State->Modes.Arena, string, OpState->SearchLister.SourceListCount); @@ -160,6 +238,6 @@ FOLDHAUS_INPUT_COMMAND_PROC(OpenNodeLister) OpState->SearchLister.FilteredIndexLUT = PushArray(&State->Modes.Arena, s32, OpState->SearchLister.SourceListCount); } - State->NodeListMenuPosition = Mouse.Pos; + OpState->ListPosition = Mouse.Pos; SetTextInputDestinationToString(&State->ActiveTextEntry, &State->GeneralPurposeSearchString); } diff --git a/src/foldhaus_operation_mode.h b/src/foldhaus_operation_mode.h index 15535dc..cc11ec1 100644 --- a/src/foldhaus_operation_mode.h +++ b/src/foldhaus_operation_mode.h @@ -38,4 +38,14 @@ DeactivateCurrentOperationMode (operation_mode_system* System) Assert(System->ActiveModesCount > 0); s32 ModeIndex = --System->ActiveModesCount; ClearArenaToSnapshot(&System->Arena, System->ModeMemorySnapshots[ModeIndex]); +} + +#define CreateOperationState(mode, modeSystem, stateType) \ +(stateType*)CreateOperationState_(mode, modeSystem, sizeof(stateType)) + +internal u8* +CreateOperationState_ (operation_mode* Mode, operation_mode_system* System, s32 StateSize) +{ + Mode->OpStateMemory = PushSize(&System->Arena, StateSize); + return Mode->OpStateMemory; } \ No newline at end of file diff --git a/src/win32_foldhaus.cpp b/src/win32_foldhaus.cpp index 1d2fdd1..87a6feb 100644 --- a/src/win32_foldhaus.cpp +++ b/src/win32_foldhaus.cpp @@ -628,8 +628,11 @@ INT NCmdShow // TODO(Peter): We shouldn't need to do this translation. the platform layer knows about win32_windows. We should just make that the interface // to all windows. + // TODO(Peter): Decide which we want to use, context or renderbuffer. Should only be one Context.WindowWidth = MainWindow.Width; Context.WindowHeight = MainWindow.Height; + RenderBuffer.ViewWidth = MainWindow.Width; + RenderBuffer.ViewHeight = MainWindow.Height; Context.DeltaTime = LastFrameSecondsElapsed; Context.UpdateAndRender(Context, InputQueue, Mouse, &RenderBuffer); diff --git a/todo.txt b/todo.txt index 7c8e92d..b142ae3 100644 --- a/todo.txt +++ b/todo.txt @@ -1,7 +1,7 @@ TODO FOLDHAUS Intermediate Lifetime Memory & Operations -- Intermediate lifetime memory arena +x Intermediate lifetime memory arena - Temporary memory region = a multi frame operation - Concept of an operation - temporary memory + interface command registry - Allow one operation at a time at first @@ -9,7 +9,7 @@ Intermediate Lifetime Memory & Operations - Current Operations: - - View Sculpture - - View/Edit Nodes -- - Add Node (needs nesting) +- x Add Node (needs nesting) - - View SACN - Why does backspacing in text entry not save when you close and reopen the node lister?