mirror of
https://github.com/Stone-Red-Code/RemSox.git
synced 2026-09-04 09:06:23 +02:00
Move window input handling logic from Kernel to WindowManager
This commit is contained in:
@@ -20,14 +20,6 @@ namespace RemSox;
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public class Kernel : Sys.Kernel
|
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()
|
protected override void BeforeRun()
|
||||||
{
|
{
|
||||||
Console.WriteLine("Cosmos booted successfully!");
|
Console.WriteLine("Cosmos booted successfully!");
|
||||||
@@ -61,55 +53,7 @@ public class Kernel : Sys.Kernel
|
|||||||
|
|
||||||
protected override void Run()
|
protected override void Run()
|
||||||
{
|
{
|
||||||
WindowInputTick();
|
WindowManager.Update();
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -3,6 +3,8 @@ using System.Collections.Concurrent;
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Drawing;
|
using System.Drawing;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
using Cosmos.Kernel.System.Graphics;
|
||||||
|
using Cosmos.Kernel.System.Mouse;
|
||||||
using RemSox.Processing;
|
using RemSox.Processing;
|
||||||
using RemSox.UI.GUI.Rendering;
|
using RemSox.UI.GUI.Rendering;
|
||||||
|
|
||||||
@@ -18,8 +20,43 @@ public static class WindowManager
|
|||||||
|
|
||||||
private static Window? focusedWindow;
|
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([]);
|
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 AddRenderSource(IRenderSource source) => renderSource.AddSource(source);
|
||||||
|
|
||||||
public static void RemoveRenderSource(IRenderSource source) => renderSource.RemoveSource(source);
|
public static void RemoveRenderSource(IRenderSource source) => renderSource.RemoveSource(source);
|
||||||
|
|||||||
Reference in New Issue
Block a user