diff --git a/TBO/ApplicationLibrary.cs b/TBO/ApplicationLibrary.cs index aba92d6..7d2f43b 100644 --- a/TBO/ApplicationLibrary.cs +++ b/TBO/ApplicationLibrary.cs @@ -1,4 +1,6 @@ -using System.Drawing; +using System.Collections.Generic; +using System.Drawing; +using System.IO; using TBO.i18n; using TBO.UI; using TBO.UI.tboTK; @@ -12,17 +14,24 @@ private Button btFullscreen = new Button("btFullscreen") { Image = Properties.Resources.screen_full, Top = 5 }; private Button btClose = new Button("btClose") { Image = Properties.Resources.x, Top = 5, Visible = Shell.FullScreen }; private Button btOpen = new Button("btOpen") { Image = Properties.Resources.file_directory, Top = 5, Left = 5 }; - private Panel pLib = new Panel("pLib") { Width = 500 }; + private Button btStudio = new Button("btStudio") { Image = Properties.Resources.pencil, Left = 5 }; + private Panel pLib = new Panel("pLib") { Width = 500, Scrollable = true }; + + private List lib = new List(); public ApplicationLibrary() { Add(btFullscreen); Add(btClose); Add(btOpen); + Add(btStudio); + Add(pLib); btFullscreen.DoClick = btFullscreenClick; btClose.DoClick = btCloseClick; btOpen.DoClick = btOpenClick; + + btStudio.Top = btOpen.Height + 10; } public override void ResizeTo(Size size) @@ -40,6 +49,13 @@ public override void ProcessCommand(string cmd) { + if (File.Exists(cmd)) + { + using (TBOFile tbo = new TBOFile(cmd)) + lib.Add(new LibraryTBO(tbo)); + Sort(); + PopulateList(); + } } public override void Shown() @@ -47,6 +63,23 @@ btClose.Visible = Shell.FullScreen; } + private void Sort() + { + lib.Sort((a, b) => a.Title.CompareTo(b.Title)); + } + + private void PopulateList() + { + pLib.RemoveAll(); + int idx = 0; + foreach (LibraryTBO ltbo in lib) + { + Item i = new Item("tbo_" + idx++) { Image = ltbo.Image, Text = ltbo.Title }; + pLib.Add(i); + } + pLib.Invalidate(); + } + private void btFullscreenClick(Control c, Event e) { bool nfs = !Shell.FullScreen; diff --git a/TBO/LibraryTBO.cs b/TBO/LibraryTBO.cs new file mode 100644 index 0000000..2e874d0 --- /dev/null +++ b/TBO/LibraryTBO.cs @@ -0,0 +1,44 @@ +using System; +using System.Collections.Generic; +using System.Drawing; +using System.Linq; +using System.Text; +using TBO.UI.tboTK; + +namespace TBO +{ + class LibraryTBO + { + private string title; + private Image image; + private string path; + + public LibraryTBO(TBOFile tbo) + { + title = tbo.Title; + GenThumb(tbo); + path = tbo.FileName; + } + + private void GenThumb(TBOFile tbo) + { + using (Image page = tbo.GetImage(0)) { + if (page == null) + return; + image = new Bitmap(256, 256); + using (Graphics g = Graphics.FromImage(image)) + { + g.DrawImageKeepRatioEx(page, 0, 0, image.Width, image.Height); + } + } + } + + public TBOFile Open() + { + return new TBOFile(path); + } + + public string Title => title; + public Image Image => image; + } +} diff --git a/TBO/Properties/Resources.Designer.cs b/TBO/Properties/Resources.Designer.cs index a97b96e..8f0e93a 100644 --- a/TBO/Properties/Resources.Designer.cs +++ b/TBO/Properties/Resources.Designer.cs @@ -103,6 +103,16 @@ /// /// Busca un recurso adaptado de tipo System.Drawing.Bitmap. /// + internal static System.Drawing.Bitmap pencil { + get { + object obj = ResourceManager.GetObject("pencil", resourceCulture); + return ((System.Drawing.Bitmap)(obj)); + } + } + + /// + /// Busca un recurso adaptado de tipo System.Drawing.Bitmap. + /// internal static System.Drawing.Bitmap repo { get { object obj = ResourceManager.GetObject("repo", resourceCulture); diff --git a/TBO/Properties/Resources.resx b/TBO/Properties/Resources.resx index 48d1920..62d9996 100644 --- a/TBO/Properties/Resources.resx +++ b/TBO/Properties/Resources.resx @@ -142,4 +142,7 @@ ..\Resources\repo.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + + ..\Resources\pencil.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + \ No newline at end of file diff --git a/TBO/Resources/pencil.png b/TBO/Resources/pencil.png new file mode 100644 index 0000000..7a952cf --- /dev/null +++ b/TBO/Resources/pencil.png Binary files differ diff --git a/TBO/TBO.csproj b/TBO/TBO.csproj index fb814aa..a8702fe 100644 --- a/TBO/TBO.csproj +++ b/TBO/TBO.csproj @@ -57,6 +57,7 @@ + @@ -67,6 +68,7 @@ + @@ -134,6 +136,7 @@ + diff --git a/TBO/TBOFile.cs b/TBO/TBOFile.cs index 5961585..2540c12 100644 --- a/TBO/TBOFile.cs +++ b/TBO/TBOFile.cs @@ -382,5 +382,6 @@ public long Size => fs.Length; public int PageCount => pagepos.Count; public bool ReadOnly => readOnly; + public string FileName => fs.Name; } } diff --git a/TBO/UI/Windows/Reader.Designer.cs b/TBO/UI/Windows/Reader.Designer.cs index 6f05589..96eb82f 100644 --- a/TBO/UI/Windows/Reader.Designer.cs +++ b/TBO/UI/Windows/Reader.Designer.cs @@ -33,6 +33,7 @@ // // Reader // + this.AllowDrop = true; this.AutoScaleDimensions = new System.Drawing.SizeF(9F, 20F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.BackgroundImageLayout = System.Windows.Forms.ImageLayout.None; @@ -43,6 +44,8 @@ this.Name = "Reader"; this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen; this.Text = "TBO"; + this.DragDrop += new System.Windows.Forms.DragEventHandler(this.Reader_DragDrop); + this.DragEnter += new System.Windows.Forms.DragEventHandler(this.Reader_DragEnter); this.Paint += new System.Windows.Forms.PaintEventHandler(this.Reader_Paint); this.MouseDown += new System.Windows.Forms.MouseEventHandler(this.Reader_MouseDown); this.MouseMove += new System.Windows.Forms.MouseEventHandler(this.Reader_MouseMove); diff --git a/TBO/UI/Windows/Reader.cs b/TBO/UI/Windows/Reader.cs index f8f4b4d..99b0513 100644 --- a/TBO/UI/Windows/Reader.cs +++ b/TBO/UI/Windows/Reader.cs @@ -154,5 +154,17 @@ } Shell.NotifyMouseButton(bt, false); } + + private void Reader_DragEnter(object sender, DragEventArgs e) + { + if (e.Data.GetDataPresent(DataFormats.FileDrop)) e.Effect = DragDropEffects.Copy; + } + + private void Reader_DragDrop(object sender, DragEventArgs e) + { + string[] files = (string[])e.Data.GetData(DataFormats.FileDrop); + foreach (string file in files) + Shell.Application.ProcessCommand(file); + } } } diff --git a/TBO/UI/tboTK/Application.cs b/TBO/UI/tboTK/Application.cs index 8b4a4ef..b86b4ae 100644 --- a/TBO/UI/tboTK/Application.cs +++ b/TBO/UI/tboTK/Application.cs @@ -59,6 +59,13 @@ return false; return controls.Remove(c.Id); } + + public void RemoveAll() + { + controls.Clear(); + } + + public Control[] Controls => new List(controls.Values).ToArray(); #endregion public abstract void ResizeTo(Size size); diff --git a/TBO/UI/tboTK/Control.cs b/TBO/UI/tboTK/Control.cs index 943457c..0d2a1cc 100644 --- a/TBO/UI/tboTK/Control.cs +++ b/TBO/UI/tboTK/Control.cs @@ -71,5 +71,6 @@ public int Height { get; set; } public bool Visible { get; set; } = true; public Rectangle Bounds => new Rectangle(Left, Top, Width, Height); + public object Tag { get; set; } } } diff --git a/TBO/UI/tboTK/IContiner.cs b/TBO/UI/tboTK/IContiner.cs index d227200..ab3fa76 100644 --- a/TBO/UI/tboTK/IContiner.cs +++ b/TBO/UI/tboTK/IContiner.cs @@ -7,5 +7,7 @@ Control Get(int x, int y, bool deep = false); bool Remove(string id); bool Remove(Control c); + void RemoveAll(); + Control[] Controls { get; } } } diff --git a/TBO/UI/tboTK/Item.cs b/TBO/UI/tboTK/Item.cs new file mode 100644 index 0000000..51f8798 --- /dev/null +++ b/TBO/UI/tboTK/Item.cs @@ -0,0 +1,25 @@ +using System; +using System.Collections.Generic; +using System.Drawing; +using System.Linq; +using System.Text; + +namespace TBO.UI.tboTK +{ + class Item : Button + { + private Font fnt = new Font(FontFamily.GenericSansSerif, 10); + private Brush fg = new SolidBrush(Color.Black); + + public Item(string id) : base(id) { } + + public override void Paint(Graphics g, Rectangle clip) + { + if (Image != null) + g.DrawImageKeepRatioEx(Image, 0, 0, Height, Height); + g.DrawString(Text, fnt, fg, Height + 5, (Height / 2) - 5); + } + + public string Text { get; set; } + } +} diff --git a/TBO/UI/tboTK/Panel.cs b/TBO/UI/tboTK/Panel.cs index 2178e7f..4a4595e 100644 --- a/TBO/UI/tboTK/Panel.cs +++ b/TBO/UI/tboTK/Panel.cs @@ -6,6 +6,7 @@ class Panel : Control, IContiner { private Dictionary controls = new Dictionary(); + private Point scrollOffset; public Panel(string id) : base(id) { @@ -20,6 +21,7 @@ if (controls.ContainsKey(c.Id)) return false; controls[c.Id] = c; + Invalidate(); return true; } @@ -63,15 +65,33 @@ return false; return controls.Remove(c.Id); } + + public void RemoveAll() + { + controls.Clear(); + Invalidate(); + } + + public Control[] Controls => new List(controls.Values).ToArray(); #endregion public override void Paint(Graphics g, Rectangle clip) { + //g.FillRectangle(new SolidBrush(Color.Wheat), Left, Top, Width, Height); + // g.SetClip(new Rectangle(Left, Top, Width, Height)); + g.TranslateTransform(Left - scrollOffset.X, Top - scrollOffset.Y); foreach (Control c in controls.Values) if (c.Clips(clip)) c.Paint(g, clip); } + private void SetScrollOffset(Point o) + { + scrollOffset = o; + Invalidate(); + } + public bool Scrollable { get; set; } = false; + public Point ScrollOffset { get => scrollOffset; set => SetScrollOffset(value); } } }