diff --git a/TBO/ApplicationLibrary.cs b/TBO/ApplicationLibrary.cs index 92e762f..573bb4e 100644 --- a/TBO/ApplicationLibrary.cs +++ b/TBO/ApplicationLibrary.cs @@ -7,7 +7,7 @@ class ApplicationLibrary : Application { Button btFullscreen = new Button("btFullscreen") { Image = Properties.Resources.screen_full_256, Top = 5 }; - + Panel pLib = new Panel("pLib") { Width = 500 }; public ApplicationLibrary() { Add(btFullscreen); @@ -16,6 +16,8 @@ public override void ResizeTo(Size size) { btFullscreen.Left = size.Width - (btFullscreen.Width + 5); + pLib.Height = size.Height; + pLib.Left = (size.Width - pLib.Width) / 2; } public static string ApplicationId = "Library"; diff --git a/TBO/TBO.csproj b/TBO/TBO.csproj index c4ce75e..d5e359c 100644 --- a/TBO/TBO.csproj +++ b/TBO/TBO.csproj @@ -64,6 +64,7 @@ + Form diff --git a/TBO/UI/Shell.cs b/TBO/UI/Shell.cs index 8f38129..81c3af3 100644 --- a/TBO/UI/Shell.cs +++ b/TBO/UI/Shell.cs @@ -53,7 +53,7 @@ g.DrawImage(bgImage, 0, 0); // Compose application - + current?.Paint(g,clip); } public static Size Size { get => size; set => SetSize(value); } diff --git a/TBO/UI/tboTK/Application.cs b/TBO/UI/tboTK/Application.cs index 19f63ed..577fbc1 100644 --- a/TBO/UI/tboTK/Application.cs +++ b/TBO/UI/tboTK/Application.cs @@ -45,6 +45,12 @@ #endregion public abstract void ResizeTo(Size size); + public void Paint(Graphics g, Rectangle clip) + { + foreach (Control c in controls.Values) + if (c.Clips(clip)) + c.Paint(g, clip); + } public abstract string Id { get; } public abstract string Title { get; } diff --git a/TBO/UI/tboTK/Button.cs b/TBO/UI/tboTK/Button.cs index e301875..68df901 100644 --- a/TBO/UI/tboTK/Button.cs +++ b/TBO/UI/tboTK/Button.cs @@ -6,8 +6,13 @@ { public Button(string id) : base(id) { - Width = 100; - Height = 100; + Width = 75; + Height = 75; + } + + public override void Paint(Graphics g, Rectangle clip) + { + g.DrawImageKeepRatio(Image, Left, Top, Width, Height); } public Image Image { get; set; } diff --git a/TBO/UI/tboTK/Control.cs b/TBO/UI/tboTK/Control.cs index 1fdf6b8..70028f9 100644 --- a/TBO/UI/tboTK/Control.cs +++ b/TBO/UI/tboTK/Control.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.Drawing; using System.Linq; using System.Text; @@ -13,10 +14,18 @@ Id = id; } + public bool Clips(Rectangle clip) + { + return Bounds.IntersectsWith(clip); + } + + public abstract void Paint(Graphics g, Rectangle clip); + public string Id { get; } public int Top { get; set; } public int Left { get; set; } public int Width { get; set; } public int Height { get; set; } + public Rectangle Bounds => new Rectangle(Left, Top, Width, Height); } } diff --git a/TBO/UI/tboTK/Panel.cs b/TBO/UI/tboTK/Panel.cs index 03f9d1f..484a4b1 100644 --- a/TBO/UI/tboTK/Panel.cs +++ b/TBO/UI/tboTK/Panel.cs @@ -1,4 +1,5 @@ using System.Collections.Generic; +using System.Drawing; namespace TBO.UI.tboTK { @@ -47,6 +48,13 @@ } #endregion + public override void Paint(Graphics g, Rectangle clip) + { + foreach (Control c in controls.Values) + if (c.Clips(clip)) + c.Paint(g, clip); + } + public bool Scrollable { get; set; } = false; } } diff --git a/TBO/UI/tboTK/UIExtension.cs b/TBO/UI/tboTK/UIExtension.cs new file mode 100644 index 0000000..c4e2631 --- /dev/null +++ b/TBO/UI/tboTK/UIExtension.cs @@ -0,0 +1,25 @@ +using System.Drawing; + +namespace TBO.UI.tboTK +{ + static class UIExtension + { + public static void DrawImageKeepRatio(this Graphics g, Image i, int x, int y, int width, int height) + { + int ww, hh, xx, yy; + xx = 0; + ww = width; + hh = i.Height * width / i.Width; + if (hh > height) + { + yy = 0; + hh = height; + ww = i.Width * height / i.Height; + xx = (width - ww) / 2; + } + else + yy = (height - hh) / 2; + g.DrawImage(i, x + xx, y + yy, ww, hh); + } + } +}