diff --git a/TBO/ApplicationLibrary.cs b/TBO/ApplicationLibrary.cs index 5982623..92e762f 100644 --- a/TBO/ApplicationLibrary.cs +++ b/TBO/ApplicationLibrary.cs @@ -1,7 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; +using System.Drawing; using TBO.i18n; using TBO.UI.tboTK; @@ -9,7 +6,20 @@ { class ApplicationLibrary : Application { - public override string Id => "Library"; + Button btFullscreen = new Button("btFullscreen") { Image = Properties.Resources.screen_full_256, Top = 5 }; + + public ApplicationLibrary() + { + Add(btFullscreen); + } + + public override void ResizeTo(Size size) + { + btFullscreen.Left = size.Width - (btFullscreen.Width + 5); + } + + public static string ApplicationId = "Library"; + public override string Id => ApplicationId; public override string Title => I18n.Lang.Library; } } diff --git a/TBO/TBO.csproj b/TBO/TBO.csproj index 1533047..c4ce75e 100644 --- a/TBO/TBO.csproj +++ b/TBO/TBO.csproj @@ -62,7 +62,8 @@ - + + Form @@ -122,7 +123,6 @@ - diff --git a/TBO/UI/Shell.cs b/TBO/UI/Shell.cs index aba0cb6..8f38129 100644 --- a/TBO/UI/Shell.cs +++ b/TBO/UI/Shell.cs @@ -1,8 +1,5 @@ -using System; -using System.Collections.Generic; +using System.Collections.Generic; using System.Drawing; -using System.Linq; -using System.Text; using TBO.UI.tboTK; namespace TBO.UI @@ -11,8 +8,12 @@ { private static Color bgColor = Color.FromArgb(255, 195, 0); private static Image bgImage = Properties.Resources.comicbg; - private static Dictionary applications = new Dictionary(); + private static Dictionary applications = new Dictionary(); private static Application current; + private static Size size; + + public delegate void InvalidateDelegate(); + public static InvalidateDelegate Invalidate; static Shell() { @@ -24,19 +25,37 @@ applications[app.Id] = app; } - public static void GoTo(string id) + private static void SetSize(Size s) + { + size = s; + current?.ResizeTo(s); + Invalidate(); + } + + public static bool GoTo(string id) { Application app; - if (applications.TryGetValue(id,out app)) + if (applications.TryGetValue(id, out app)) { current = app; - + current.ResizeTo(size); + Invalidate(); + return true; } + return false; } - public static void Paint(Graphics g, Rectangle clip, Size size) + public static void Paint(Graphics g, Rectangle clip) { + // Clipping and background + g.SetClip(clip); + g.Clear(bgColor); + g.DrawImage(bgImage, 0, 0); + + // Compose application } + + public static Size Size { get => size; set => SetSize(value); } } } diff --git a/TBO/UI/Windows/Reader.Designer.cs b/TBO/UI/Windows/Reader.Designer.cs index 7a591d4..d87fa5e 100644 --- a/TBO/UI/Windows/Reader.Designer.cs +++ b/TBO/UI/Windows/Reader.Designer.cs @@ -33,13 +33,12 @@ // // Reader // - this.AutoScaleDimensions = new System.Drawing.SizeF(9F, 20F); + this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.BackgroundImageLayout = System.Windows.Forms.ImageLayout.None; - this.ClientSize = new System.Drawing.Size(1200, 692); + this.ClientSize = new System.Drawing.Size(800, 450); this.DoubleBuffered = true; this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon"))); - this.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5); this.Name = "Reader"; this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen; this.Text = "TBO"; @@ -50,5 +49,6 @@ } #endregion + } } \ No newline at end of file diff --git a/TBO/UI/Windows/Reader.cs b/TBO/UI/Windows/Reader.cs index 349b45c..aed9484 100644 --- a/TBO/UI/Windows/Reader.cs +++ b/TBO/UI/Windows/Reader.cs @@ -1,11 +1,5 @@ using System; -using System.Collections.Generic; -using System.ComponentModel; -using System.Data; using System.Drawing; -using System.IO; -using System.Linq; -using System.Text; using System.Windows.Forms; namespace TBO.UI.Windows @@ -16,17 +10,36 @@ private bool inFS = true; //private bool inLibrary=true; - public Reader(string path) { InitializeComponent(); + Shell.Invalidate = ShellInvalidate; SwapFullScreen(); if (path != null) LoadTBO(path); + else + ShowLibrary(); + Shell.Size = ClientSize; + } + + private void ShellInvalidate() + { + Invalidate(); + } + + private void ShowLibrary() + { + Shell.GoTo(ApplicationLibrary.ApplicationId); + } + + private void ShowTBO() + { + Shell.GoTo(ApplicationLibrary.ApplicationId); } private void LoadTBO(string path) { + ShowTBO(); //try //{ // tbo = new TBOFile(path); @@ -80,13 +93,12 @@ private void Reader_Paint(object sender, PaintEventArgs e) { - e.Graphics.SetClip(e.ClipRectangle); - Shell.Paint(e.Graphics, e.ClipRectangle, ClientSize); + Shell.Paint(e.Graphics, e.ClipRectangle); } private void Reader_Resize(object sender, EventArgs e) { - Invalidate(); + Shell.Size = ClientSize; } } } diff --git a/TBO/UI/tboTK/Application.cs b/TBO/UI/tboTK/Application.cs index ba65b1a..19f63ed 100644 --- a/TBO/UI/tboTK/Application.cs +++ b/TBO/UI/tboTK/Application.cs @@ -1,12 +1,51 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; +using System.Collections.Generic; +using System.Drawing; namespace TBO.UI.tboTK { - abstract class Application + abstract class Application : IContiner { + + #region IContiner + private Dictionary controls = new Dictionary(); + + public bool Add(Control c) + { + if (c == null) + return false; + if (Get(c.Id, true) != null) + return false; + controls[c.Id] = c; + return true; + } + + public Control Get(string id, bool deep = false) + { + Control r; + if (controls.TryGetValue(id, out r)) + return r; + if (deep) + foreach (Control c in controls.Values) + if (c is IContiner) + return ((IContiner)c).Get(id, deep); + return null; + } + + public bool Remove(string id) + { + return Remove(Get(id)); + } + + public bool Remove(Control c) + { + if (c == null) + return false; + return controls.Remove(c.Id); + } + #endregion + + public abstract void ResizeTo(Size size); + 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 4170985..e301875 100644 --- a/TBO/UI/tboTK/Button.cs +++ b/TBO/UI/tboTK/Button.cs @@ -1,11 +1,15 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; +using System.Drawing; namespace TBO.UI.tboTK { - class Button:Control + class Button : Control { + public Button(string id) : base(id) + { + Width = 100; + Height = 100; + } + + public Image Image { get; set; } } } diff --git a/TBO/UI/tboTK/Control.cs b/TBO/UI/tboTK/Control.cs index 8eb2d79..1fdf6b8 100644 --- a/TBO/UI/tboTK/Control.cs +++ b/TBO/UI/tboTK/Control.cs @@ -5,8 +5,18 @@ namespace TBO.UI.tboTK { - class Control + abstract class Control { - public string Id; + + public Control(string id) + { + Id = id; + } + + public string Id { get; } + public int Top { get; set; } + public int Left { get; set; } + public int Width { get; set; } + public int Height { get; set; } } } diff --git a/TBO/UI/tboTK/IContiner.cs b/TBO/UI/tboTK/IContiner.cs new file mode 100644 index 0000000..b6a33e5 --- /dev/null +++ b/TBO/UI/tboTK/IContiner.cs @@ -0,0 +1,10 @@ +namespace TBO.UI.tboTK +{ + interface IContiner + { + bool Add(Control c); + Control Get(string id, bool deep = false); + bool Remove(string id); + bool Remove(Control c); + } +} diff --git a/TBO/UI/tboTK/Panel.cs b/TBO/UI/tboTK/Panel.cs new file mode 100644 index 0000000..03f9d1f --- /dev/null +++ b/TBO/UI/tboTK/Panel.cs @@ -0,0 +1,52 @@ +using System.Collections.Generic; + +namespace TBO.UI.tboTK +{ + class Panel : Control, IContiner + { + private Dictionary controls = new Dictionary(); + + public Panel(string id) : base(id) + { + + } + + #region IContiner + public bool Add(Control c) + { + if (c == null) + return false; + if (controls.ContainsKey(c.Id)) + return false; + controls[c.Id] = c; + return true; + } + + public Control Get(string id, bool deep = false) + { + Control r; + if (controls.TryGetValue(id, out r)) + return r; + if (deep) + foreach (Control c in controls.Values) + if (c is IContiner) + return ((IContiner)c).Get(id, deep); + return null; + } + + public bool Remove(string id) + { + return Remove(Get(id)); + } + + public bool Remove(Control c) + { + if (c == null) + return false; + return controls.Remove(c.Id); + } + #endregion + + public bool Scrollable { get; set; } = false; + } +} diff --git a/TBO/UI/tboTK/Renderer.cs b/TBO/UI/tboTK/Renderer.cs deleted file mode 100644 index 2eed2aa..0000000 --- a/TBO/UI/tboTK/Renderer.cs +++ /dev/null @@ -1,11 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; - -namespace TBO.UI.tboTK -{ - class Renderer - { - } -}