mirror of
https://github.com/Stone-Red-Code/RemSox.git
synced 2026-09-04 00:56:19 +02:00
Add button click and checkbox toggle handlers for UI controls
This commit is contained in:
@@ -1,5 +1,6 @@
|
|||||||
using RemSox.Processing;
|
using RemSox.Processing;
|
||||||
using RemSox.UI.GUI.Rendering;
|
using RemSox.UI.GUI.Rendering;
|
||||||
|
using RemSox.UI.GUI.UIEelements.Controls;
|
||||||
using RemSox.UI.GUI.Windows;
|
using RemSox.UI.GUI.Windows;
|
||||||
|
|
||||||
namespace RemSox.Processes;
|
namespace RemSox.Processes;
|
||||||
@@ -21,8 +22,9 @@ internal class DesktopProcess() : Process("Desktop Manager")
|
|||||||
|
|
||||||
// Create a test window for new UI controls
|
// Create a test window for new UI controls
|
||||||
Window testWindow = WindowManager.CreateWindow(this, "UI Controls Test", new System.Drawing.Size(200, 180));
|
Window testWindow = WindowManager.CreateWindow(this, "UI Controls Test", new System.Drawing.Size(200, 180));
|
||||||
|
testWindow.AutoFlush = true;
|
||||||
|
|
||||||
_ = testWindow.CreateUIElement<UI.GUI.UIEelements.Controls.Button>(b =>
|
Button button = testWindow.CreateUIElement<UI.GUI.UIEelements.Controls.Button>(b =>
|
||||||
{
|
{
|
||||||
b.Position = new System.Drawing.Point(20, 30);
|
b.Position = new System.Drawing.Point(20, 30);
|
||||||
b.Size = new System.Drawing.Size(100, 30);
|
b.Size = new System.Drawing.Size(100, 30);
|
||||||
@@ -30,22 +32,31 @@ internal class DesktopProcess() : Process("Desktop Manager")
|
|||||||
b.BackgroundColor = System.Drawing.Color.LightBlue;
|
b.BackgroundColor = System.Drawing.Color.LightBlue;
|
||||||
});
|
});
|
||||||
|
|
||||||
_ = testWindow.CreateUIElement<UI.GUI.UIEelements.Controls.CheckBox>(c =>
|
button.OnClick += (s, e) =>
|
||||||
|
{
|
||||||
|
button.Text = "Clicked!";
|
||||||
|
button.BackgroundColor = System.Drawing.Color.LightGreen;
|
||||||
|
};
|
||||||
|
|
||||||
|
CheckBox check = testWindow.CreateUIElement<UI.GUI.UIEelements.Controls.CheckBox>(c =>
|
||||||
{
|
{
|
||||||
c.Position = new System.Drawing.Point(20, 80);
|
c.Position = new System.Drawing.Point(20, 80);
|
||||||
|
c.Size = new System.Drawing.Size(100, 30);
|
||||||
c.Text = "Check Me";
|
c.Text = "Check Me";
|
||||||
c.IsChecked = true;
|
c.IsChecked = true;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
check.OnCheckedChanged += (s, e) =>
|
||||||
|
{
|
||||||
|
check.Text = check.IsChecked ? "Checked!" : "Unchecked!";
|
||||||
|
};
|
||||||
|
|
||||||
_ = testWindow.CreateUIElement<UI.GUI.UIEelements.Shapes.Line>(l =>
|
_ = testWindow.CreateUIElement<UI.GUI.UIEelements.Shapes.Line>(l =>
|
||||||
{
|
{
|
||||||
l.Position = new System.Drawing.Point(20, 130);
|
l.Position = new System.Drawing.Point(20, 130);
|
||||||
l.EndPosition = new System.Drawing.Point(180, 130);
|
l.EndPosition = new System.Drawing.Point(180, 130);
|
||||||
l.Color = System.Drawing.Color.Red;
|
l.Color = System.Drawing.Color.Red;
|
||||||
});
|
});
|
||||||
|
|
||||||
testWindow.AutoFlush = true;
|
|
||||||
testWindow.Flush();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
internal override void Tick()
|
internal override void Tick()
|
||||||
|
|||||||
@@ -18,8 +18,11 @@ public class Button() : Control("Button")
|
|||||||
set => SetProperty(nameof(TextColor), ref field, value);
|
set => SetProperty(nameof(TextColor), ref field, value);
|
||||||
} = Color.Black;
|
} = Color.Black;
|
||||||
|
|
||||||
public void Click()
|
public override void HandleMouseEvent(MouseEvent mouseEvent)
|
||||||
{
|
{
|
||||||
OnClick?.Invoke(this, EventArgs.Empty);
|
if (mouseEvent.Type == MouseEventType.ButtonDown && mouseEvent.Button == MouseButton.Left)
|
||||||
|
{
|
||||||
|
OnClick?.Invoke(this, EventArgs.Empty);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -27,4 +27,12 @@ public class CheckBox() : Control("CheckBox")
|
|||||||
get;
|
get;
|
||||||
set => SetProperty(nameof(TextColor), ref field, value);
|
set => SetProperty(nameof(TextColor), ref field, value);
|
||||||
} = Color.White;
|
} = Color.White;
|
||||||
|
|
||||||
|
public override void HandleMouseEvent(MouseEvent mouseEvent)
|
||||||
|
{
|
||||||
|
if (mouseEvent.Type == MouseEventType.ButtonDown && mouseEvent.Button == MouseButton.Left)
|
||||||
|
{
|
||||||
|
IsChecked = !IsChecked;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -107,9 +107,9 @@ public sealed class Window(string title, int processId, int id, IRenderSource re
|
|||||||
uiElements.Add(uiElementId, uiElement);
|
uiElements.Add(uiElementId, uiElement);
|
||||||
}
|
}
|
||||||
|
|
||||||
lock (controlsLock)
|
if (uiElement is Control control)
|
||||||
{
|
{
|
||||||
if (uiElement is Control control)
|
lock (controlsLock)
|
||||||
{
|
{
|
||||||
controls.Add(uiElementId, control);
|
controls.Add(uiElementId, control);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -57,20 +57,20 @@ public static class WindowManager
|
|||||||
activeInteractWindow = null;
|
activeInteractWindow = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
wasLeftButtonDown = leftButtonDown;
|
|
||||||
wasRightButtonDown = rightButtonDown;
|
|
||||||
wasMiddleButtonDown = middleButtonDown;
|
|
||||||
|
|
||||||
while (KeyboardManager.TryReadKey(out KeyEvent? keyEvent) && keyEvent is not null)
|
while (KeyboardManager.TryReadKey(out KeyEvent? keyEvent) && keyEvent is not null)
|
||||||
{
|
{
|
||||||
focusedWindow?.HandleKeyEvent(keyEvent);
|
focusedWindow?.HandleKeyEvent(keyEvent);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (focusedWindow is not null && activeInteractWindow is null)
|
if (focusedWindow is not null)
|
||||||
{
|
{
|
||||||
DispatchMouseEvents(focusedWindow, pointerPosition);
|
DispatchMouseEvents(focusedWindow, pointerPosition);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
wasLeftButtonDown = leftButtonDown;
|
||||||
|
wasRightButtonDown = rightButtonDown;
|
||||||
|
wasMiddleButtonDown = middleButtonDown;
|
||||||
|
|
||||||
CanvasRenderSource.CompositeAndDisplay(canvas, pointerPosition);
|
CanvasRenderSource.CompositeAndDisplay(canvas, pointerPosition);
|
||||||
|
|
||||||
lastPointerPosition = pointerPosition;
|
lastPointerPosition = pointerPosition;
|
||||||
|
|||||||
Reference in New Issue
Block a user