From 35224936899cace8a9d0960f20c1372631573624 Mon Sep 17 00:00:00 2001 From: Stone_Red <56473591+Stone-Red-Code@users.noreply.github.com> Date: Mon, 8 Jun 2026 13:34:42 +0200 Subject: [PATCH] Move window input handling logic from Kernel to WindowManager --- Kernel.cs | 58 +-------------------------------- UI/GUI/Windows/WindowManager.cs | 37 +++++++++++++++++++++ 2 files changed, 38 insertions(+), 57 deletions(-) diff --git a/Kernel.cs b/Kernel.cs index feb15e0..8790e52 100644 --- a/Kernel.cs +++ b/Kernel.cs @@ -20,14 +20,6 @@ namespace RemSox; /// public class Kernel : Sys.Kernel { - private static Window? activeInteractWindow = null; - - private static Point lastPointerPosition = Point.Empty; - - private static bool wasLeftButtonDown = false; - - private static int mousePollCounter = 0; - protected override void BeforeRun() { Console.WriteLine("Cosmos booted successfully!"); @@ -61,55 +53,7 @@ public class Kernel : Sys.Kernel protected override void Run() { - WindowInputTick(); - return; - - Console.Write("> "); - - string? input = Console.ReadLine(); - - if (string.IsNullOrEmpty(input)) - { - return; - } - - if (CommandManager.TryExecute(input)) - { - return; - } - - Console.WriteLine($"\"{input}\" is not a command"); - } - - private static void WindowInputTick() - { - mousePollCounter++; - Sys.Mouse.MouseManager.Poll(); - - Point pointerPosition = new(Sys.Mouse.MouseManager.X, Sys.Mouse.MouseManager.Y); - bool leftButtonDown = Sys.Mouse.MouseManager.LeftButton; - - if (leftButtonDown && !wasLeftButtonDown) - { - activeInteractWindow = WindowManager.TryBeginInteract(pointerPosition); - } - else if (leftButtonDown && activeInteractWindow is not null) - { - activeInteractWindow.UpdateInteraction(pointerPosition); - } - else if (!leftButtonDown && activeInteractWindow is not null) - { - activeInteractWindow.EndInteraction(); - activeInteractWindow = null; - } - - wasLeftButtonDown = leftButtonDown; - - // Render all canvases and cursor every tick, or if changed - Canvas canvas = FullScreenCanvas.GetFullScreenCanvas(); - CanvasRenderSource.CompositeAndDisplay(canvas, pointerPosition); - - lastPointerPosition = pointerPosition; + WindowManager.Update(); } } diff --git a/UI/GUI/Windows/WindowManager.cs b/UI/GUI/Windows/WindowManager.cs index c9bd21e..c1eec6c 100644 --- a/UI/GUI/Windows/WindowManager.cs +++ b/UI/GUI/Windows/WindowManager.cs @@ -3,6 +3,8 @@ using System.Collections.Concurrent; using System.Collections.Generic; using System.Drawing; using System.Linq; +using Cosmos.Kernel.System.Graphics; +using Cosmos.Kernel.System.Mouse; using RemSox.Processing; using RemSox.UI.GUI.Rendering; @@ -18,8 +20,43 @@ public static class WindowManager private static Window? focusedWindow; + private static Window? activeInteractWindow = null; + private static Point lastPointerPosition = Point.Empty; + private static bool wasLeftButtonDown = false; + private static int mousePollCounter = 0; + private static readonly MuliRenderSource renderSource = new([]); + public static void Update() + { + mousePollCounter++; + MouseManager.Poll(); + + Point pointerPosition = new((int)MouseManager.X, (int)MouseManager.Y); + bool leftButtonDown = MouseManager.LeftButton; + + if (leftButtonDown && !wasLeftButtonDown) + { + activeInteractWindow = TryBeginInteract(pointerPosition); + } + else if (leftButtonDown && activeInteractWindow is not null) + { + activeInteractWindow.UpdateInteraction(pointerPosition); + } + else if (!leftButtonDown && activeInteractWindow is not null) + { + activeInteractWindow.EndInteraction(); + activeInteractWindow = null; + } + + wasLeftButtonDown = leftButtonDown; + + Canvas canvas = FullScreenCanvas.GetFullScreenCanvas(); + CanvasRenderSource.CompositeAndDisplay(canvas, pointerPosition); + + lastPointerPosition = pointerPosition; + } + public static void AddRenderSource(IRenderSource source) => renderSource.AddSource(source); public static void RemoveRenderSource(IRenderSource source) => renderSource.RemoveSource(source);