diff --git a/TBO/UI/tboTK/Application.cs b/TBO/UI/tboTK/Application.cs index efee5fc..0213831 100644 --- a/TBO/UI/tboTK/Application.cs +++ b/TBO/UI/tboTK/Application.cs @@ -65,7 +65,7 @@ public void Paint(Graphics g, Rectangle clip) { foreach (Control c in controls.Values) - if (c.Clips(clip)) + if (c.Visible && c.Clips(clip)) c.Paint(g, clip); } diff --git a/TBO/UI/tboTK/Button.cs b/TBO/UI/tboTK/Button.cs index 82df159..df30079 100644 --- a/TBO/UI/tboTK/Button.cs +++ b/TBO/UI/tboTK/Button.cs @@ -4,17 +4,21 @@ { class Button : Control { - bool hover=false; + private bool hover = false; + private bool pressed = false; public Button(string id) : base(id) { - Width = 75; - Height = 75; + Width = 50; + Height = 50; } public override void Paint(Graphics g, Rectangle clip) { - g.DrawImageKeepRatioEx(Image, Left, Top, Width, Height, hover ? 1f : 0.5f); + if (pressed) + g.DrawImageKeepRatioEx(Image, Left + 1, Top + 1, Width - 2, Height - 2); + else + g.DrawImageKeepRatioEx(Image, Left, Top, Width, Height, hover ? 1f : 0.5f); } public override void Handle(Event e) @@ -32,6 +36,16 @@ hover = false; Invalidate(); break; + case Event.EventType.MouseDown: + if ((int)e[Event.EventParam.Button] == Event.MouseButtonLeft) + pressed = true; + Invalidate(); + break; + case Event.EventType.MouseUp: + if ((int)e[Event.EventParam.Button] == Event.MouseButtonLeft) + pressed = false; + Invalidate(); + break; } } diff --git a/TBO/UI/tboTK/Control.cs b/TBO/UI/tboTK/Control.cs index e42e282..943457c 100644 --- a/TBO/UI/tboTK/Control.cs +++ b/TBO/UI/tboTK/Control.cs @@ -7,6 +7,12 @@ public delegate void EventDelegate(Control c, Event e); public EventDelegate DoEvent; + public EventDelegate DoMouseEnter; + public EventDelegate DoMouseLeave; + public EventDelegate DoMouseDown; + public EventDelegate DoMouseUp; + public EventDelegate DoClick; + public EventDelegate DoScroll; public Control(string id) { @@ -22,12 +28,40 @@ public virtual void Handle(Event e) { + if (!Visible) + { + e.Done = true; + return; + } DoEvent?.Invoke(this, e); + if (e.Done) + return; + switch (e.Id) + { + case Event.EventType.MouseEnter: + DoMouseEnter?.Invoke(this, e); + break; + case Event.EventType.MouseLeave: + DoMouseLeave?.Invoke(this, e); + break; + case Event.EventType.MouseDown: + DoMouseDown?.Invoke(this, e); + break; + case Event.EventType.MouseUp: + DoMouseUp?.Invoke(this, e); + break; + case Event.EventType.Click: + DoClick?.Invoke(this, e); + break; + case Event.EventType.Scroll: + DoScroll?.Invoke(this, e); + break; + } } public void Invalidate() { - Shell.InvalidateRegion(new Rectangle(Left, Top, Width, Height)); + Shell.Invalidate(new Rectangle(Left, Top, Width, Height)); } public string Id { get; } @@ -35,6 +69,7 @@ public int Left { get; set; } public int Width { get; set; } public int Height { get; set; } + public bool Visible { get; set; } = true; public Rectangle Bounds => new Rectangle(Left, Top, Width, Height); } } diff --git a/TBO/UI/tboTK/Event.cs b/TBO/UI/tboTK/Event.cs index ade4abf..99d1d87 100644 --- a/TBO/UI/tboTK/Event.cs +++ b/TBO/UI/tboTK/Event.cs @@ -4,10 +4,16 @@ { class Event { + public const int MouseButtonLeft = 1; + public const int MouseButtonMiddle = 2; + public const int MouseButtonRight = 3; + public enum EventType { MouseEnter, MouseLeave, + MouseDown, + MouseUp, Click, Scroll, } @@ -15,6 +21,7 @@ public enum EventParam { Delta, + Button, } #region Constructors @@ -29,6 +36,15 @@ return new Event(EventType.MouseLeave); } + public static Event AtMouseDown(int button) + { + return new Event(EventType.MouseDown).Set(EventParam.Button, button); + } + + public static Event AtMouseUp(int button) + { + return new Event(EventType.MouseUp).Set(EventParam.Button, button); + } public static Event AtClick() { return new Event(EventType.Click);