mirror of
https://github.com/Stone-Red-Code/RemSox.git
synced 2026-09-07 15:56:31 +02:00
Code cleanup
This commit is contained in:
@@ -58,7 +58,7 @@ internal class DesktopProcess() : Process("Desktop Manager")
|
|||||||
startButton = taskbar.CreateUIElement<Button>(b =>
|
startButton = taskbar.CreateUIElement<Button>(b =>
|
||||||
{
|
{
|
||||||
b.Position = new Point(2, 2);
|
b.Position = new Point(2, 2);
|
||||||
b.Size = new Size(50, taskbarH - 4);
|
b.Size = new Size(65, taskbarH - 4);
|
||||||
b.Text = "Start";
|
b.Text = "Start";
|
||||||
b.BackgroundColor = Color.FromArgb(0, 100, 180);
|
b.BackgroundColor = Color.FromArgb(0, 100, 180);
|
||||||
b.TextColor = Color.White;
|
b.TextColor = Color.White;
|
||||||
@@ -158,13 +158,13 @@ internal class DesktopProcess() : Process("Desktop Manager")
|
|||||||
|
|
||||||
// Build lookup of existing tracked windows
|
// Build lookup of existing tracked windows
|
||||||
Dictionary<int, Button> tracked = [];
|
Dictionary<int, Button> tracked = [];
|
||||||
foreach (var (winId, btn) in windowButtons)
|
foreach ((int winId, Button? btn) in windowButtons)
|
||||||
{
|
{
|
||||||
tracked[winId] = btn;
|
tracked[winId] = btn;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add new buttons and reposition everything in one pass
|
// Add new buttons and reposition everything in one pass
|
||||||
int btnX = 56;
|
int btnX = startButton.Size.Width + 6;
|
||||||
windowButtons.Clear();
|
windowButtons.Clear();
|
||||||
foreach (Window win in allWindows)
|
foreach (Window win in allWindows)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -94,9 +94,9 @@ public sealed class CanvasRenderSource : IRenderSource
|
|||||||
|
|
||||||
canvas.Clear(Color.Black);
|
canvas.Clear(Color.Black);
|
||||||
|
|
||||||
if (windowPrimitives.TryGetValue(winId, out var primitives))
|
if (windowPrimitives.TryGetValue(winId, out List<(int ElementId, RenderCommand Command)>? primitives))
|
||||||
{
|
{
|
||||||
foreach (var (_, cmd) in primitives)
|
foreach ((int _, RenderCommand? cmd) in primitives)
|
||||||
{
|
{
|
||||||
DrawPrimitive(canvas, cmd);
|
DrawPrimitive(canvas, cmd);
|
||||||
}
|
}
|
||||||
@@ -191,7 +191,7 @@ public sealed class CanvasRenderSource : IRenderSource
|
|||||||
|
|
||||||
private static void UpsertPrimitive(RenderCommand cmd)
|
private static void UpsertPrimitive(RenderCommand cmd)
|
||||||
{
|
{
|
||||||
if (!windowPrimitives.TryGetValue(cmd.WindowId, out var list))
|
if (!windowPrimitives.TryGetValue(cmd.WindowId, out List<(int ElementId, RenderCommand Command)>? list))
|
||||||
{
|
{
|
||||||
list = [];
|
list = [];
|
||||||
windowPrimitives[cmd.WindowId] = list;
|
windowPrimitives[cmd.WindowId] = list;
|
||||||
@@ -212,12 +212,12 @@ public sealed class CanvasRenderSource : IRenderSource
|
|||||||
|
|
||||||
private static void RemovePrimitives(int windowId, int baseElementId)
|
private static void RemovePrimitives(int windowId, int baseElementId)
|
||||||
{
|
{
|
||||||
if (!windowPrimitives.TryGetValue(windowId, out var list))
|
if (!windowPrimitives.TryGetValue(windowId, out List<(int ElementId, RenderCommand Command)>? list))
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
list.RemoveAll(p => p.ElementId >= 0
|
_ = list.RemoveAll(p => p.ElementId >= 0
|
||||||
? (p.ElementId >> UIElement.PrimitiveIdShift) == baseElementId
|
? (p.ElementId >> UIElement.PrimitiveIdShift) == baseElementId
|
||||||
: p.ElementId == baseElementId);
|
: p.ElementId == baseElementId);
|
||||||
|
|
||||||
|
|||||||
@@ -168,8 +168,10 @@ public class RenderCommand
|
|||||||
|
|
||||||
// --- Serialization helpers ---
|
// --- Serialization helpers ---
|
||||||
|
|
||||||
private T GetProp<T>(string key, T fallback) =>
|
private T GetProp<T>(string key, T fallback)
|
||||||
Properties.TryGetValue(key, out object? raw) && raw is T val ? val : fallback;
|
{
|
||||||
|
return Properties.TryGetValue(key, out object? raw) && raw is T val ? val : fallback;
|
||||||
|
}
|
||||||
|
|
||||||
private static void WriteVarint(Stream s, int value)
|
private static void WriteVarint(Stream s, int value)
|
||||||
{
|
{
|
||||||
@@ -209,7 +211,11 @@ public class RenderCommand
|
|||||||
{
|
{
|
||||||
byte b = data[offset++];
|
byte b = data[offset++];
|
||||||
result |= (uint)(b & 0x7F) << shift;
|
result |= (uint)(b & 0x7F) << shift;
|
||||||
if ((b & 0x80) == 0) return (int)result;
|
if ((b & 0x80) == 0)
|
||||||
|
{
|
||||||
|
return (int)result;
|
||||||
|
}
|
||||||
|
|
||||||
shift += 7;
|
shift += 7;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,5 @@
|
|||||||
using RemSox.UI.GUI.Rendering;
|
using RemSox.UI.GUI.Rendering;
|
||||||
|
|
||||||
using System.Drawing;
|
|
||||||
|
|
||||||
namespace RemSox.UI.GUI.UIEelements.Controls;
|
namespace RemSox.UI.GUI.UIEelements.Controls;
|
||||||
|
|
||||||
public class Panel() : Control("Panel")
|
public class Panel() : Control("Panel")
|
||||||
|
|||||||
@@ -1,7 +1,5 @@
|
|||||||
using RemSox.UI.GUI.Rendering;
|
using RemSox.UI.GUI.Rendering;
|
||||||
|
|
||||||
using System.Drawing;
|
|
||||||
|
|
||||||
namespace RemSox.UI.GUI.UIEelements.Shapes;
|
namespace RemSox.UI.GUI.UIEelements.Shapes;
|
||||||
|
|
||||||
public class Circle() : Shape("Circle")
|
public class Circle() : Shape("Circle")
|
||||||
|
|||||||
@@ -1,7 +1,5 @@
|
|||||||
using RemSox.UI.GUI.Rendering;
|
using RemSox.UI.GUI.Rendering;
|
||||||
|
|
||||||
using System.Drawing;
|
|
||||||
|
|
||||||
namespace RemSox.UI.GUI.UIEelements.Shapes;
|
namespace RemSox.UI.GUI.UIEelements.Shapes;
|
||||||
|
|
||||||
public class Pixel() : Shape("Pixel")
|
public class Pixel() : Shape("Pixel")
|
||||||
|
|||||||
@@ -23,5 +23,8 @@ public abstract class UIElement(string type) : ChangedPropertiesTracker
|
|||||||
public abstract IEnumerable<RenderCommand> ToPrimitives(int windowId);
|
public abstract IEnumerable<RenderCommand> ToPrimitives(int windowId);
|
||||||
|
|
||||||
/// <summary> Builds a stable primitive ID from element ID and sub-index. </summary>
|
/// <summary> Builds a stable primitive ID from element ID and sub-index. </summary>
|
||||||
protected int PrimitiveId(int subIndex) => (Id << PrimitiveIdShift) | subIndex;
|
protected int PrimitiveId(int subIndex)
|
||||||
|
{
|
||||||
|
return (Id << PrimitiveIdShift) | subIndex;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user