diff --git a/TBO/ApplicationLibrary.cs b/TBO/ApplicationLibrary.cs index 22c27bf..aba92d6 100644 --- a/TBO/ApplicationLibrary.cs +++ b/TBO/ApplicationLibrary.cs @@ -7,17 +7,22 @@ { class ApplicationLibrary : Application { - Button btFullscreen = new Button("btFullscreen") { Image = Properties.Resources.screen_full, Top = 5 }; - Button btClose = new Button("btClose") { Image = Properties.Resources.x, Top = 5, Visible = Shell.FullScreen }; - Panel pLib = new Panel("pLib") { Width = 500 }; + public const string ApplicationId = "Library"; + + 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 }; public ApplicationLibrary() { Add(btFullscreen); Add(btClose); + Add(btOpen); btFullscreen.DoClick = btFullscreenClick; btClose.DoClick = btCloseClick; + btOpen.DoClick = btOpenClick; } public override void ResizeTo(Size size) @@ -33,6 +38,15 @@ pLib.Left = (size.Width - pLib.Width) / 2; } + public override void ProcessCommand(string cmd) + { + } + + public override void Shown() + { + btClose.Visible = Shell.FullScreen; + } + private void btFullscreenClick(Control c, Event e) { bool nfs = !Shell.FullScreen; @@ -45,7 +59,14 @@ Shell.DoClose?.Invoke(); } - public static string ApplicationId = "Library"; + private void btOpenClick(Control c, Event e) + { + string file = UIManager.Manager.OpenTBODialog(); + if (file == null) + return; + Shell.GoTo(ApplicationReader.ApplicationId, file); + } + public override string Id => ApplicationId; public override string Title => I18n.Lang.Library; } diff --git a/TBO/ApplicationReader.cs b/TBO/ApplicationReader.cs new file mode 100644 index 0000000..13125e6 --- /dev/null +++ b/TBO/ApplicationReader.cs @@ -0,0 +1,195 @@ +using System; +using System.Collections.Generic; +using System.Drawing; +using System.IO; +using System.Linq; +using System.Text; +using TBO.i18n; +using TBO.UI; +using TBO.UI.tboTK; + +namespace TBO +{ + class ApplicationReader : Application + { + public const string ApplicationId = "Reader"; + + private Canvas cvTebeo = new Canvas("cvTebeo"); + 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 btLib = new Button("btLib") { Image = Properties.Resources.repo, Top = 5, Left = 5 }; + private Button btPrev = new Button("btPrev") { Image = Properties.Resources.chevron_left }; + private Button btNext = new Button("btNext") { Image = Properties.Resources.chevron_right }; + private TBOFile tbo; + private int page; + private Image pageImage; + + public ApplicationReader() + { + Add(cvTebeo); + Add(btFullscreen); + Add(btClose); + Add(btLib); + Add(btPrev); + Add(btNext); + + cvTebeo.DoPaint = cvTebeoPaint; + btFullscreen.DoClick = btFullscreenClick; + btClose.DoClick = btCloseClick; + btLib.DoClick = btLibClick; + btPrev.DoClick = btPrevClick; + btNext.DoClick = btNextClick; + } + + public override void ResizeTo(Size size) + { + if (btClose.Visible) + { + btFullscreen.Left = size.Width - (btFullscreen.Width * 2 + 10); + btClose.Left = size.Width - (btClose.Width + 5); + } + else + btFullscreen.Left = size.Width - (btFullscreen.Width + 5); + switch (Conf.PageNavMode) + { + case Conf.PageNavModeType.None: + btPrev.Visible = false; + btNext.Visible = false; + break; + case Conf.PageNavModeType.Left: + btPrev.Visible = true; + btNext.Visible = true; + btPrev.Left = 5; + btPrev.Top = size.Height - ((btPrev.Height * 2) + 10); + btNext.Left = 5; + btNext.Top = size.Height - btNext.Height - 5; + break; + case Conf.PageNavModeType.Right: + btPrev.Visible = true; + btNext.Visible = true; + btPrev.Left = size.Width - btPrev.Width - 5; + btPrev.Top = size.Height - ((btPrev.Height * 2) + 10); + btNext.Left = size.Width - btNext.Width - 5; + btNext.Top = size.Height - btNext.Height - 5; + break; + case Conf.PageNavModeType.Both: + btPrev.Visible = true; + btNext.Visible = true; + btPrev.Left = 5; + btPrev.Top = size.Height - btPrev.Height - 5; + btNext.Left = size.Width - btNext.Width - 5; + btNext.Top = size.Height - btNext.Height - 5; + break; + case Conf.PageNavModeType.MiddleLeft: + btPrev.Visible = true; + btNext.Visible = true; + btPrev.Left = 5; + btPrev.Top = size.Height / 2 - ((btPrev.Height * 2) + 10); + btNext.Left = 5; + btNext.Top = size.Height / 2 - btNext.Height - 5; + break; + case Conf.PageNavModeType.MiddleRight: + btPrev.Visible = true; + btNext.Visible = true; + btPrev.Left = size.Width - btPrev.Width - 5; + btPrev.Top = size.Height / 2 - ((btPrev.Height * 2) + 10); + btNext.Left = size.Width - btNext.Width - 5; + btNext.Top = size.Height / 2 - btNext.Height - 5; + break; + case Conf.PageNavModeType.MiddleBoth: + btPrev.Visible = true; + btNext.Visible = true; + btPrev.Left = 5; + btPrev.Top = size.Height / 2 - btPrev.Height - 5; + btNext.Left = size.Width - btNext.Width - 5; + btNext.Top = size.Height / 2 - btNext.Height - 5; + break; + } + cvTebeo.Width = size.Width; + cvTebeo.Height = size.Height; + } + + public override void ProcessCommand(string cmd) + { + if (File.Exists(cmd)) + { + if (tbo != null) + tbo.Dispose(); + tbo = new TBOFile(cmd); + SetPage(tbo.CurrentPage); + Shell.Invalidate(); + } + } + + public override void Shown() + { + btClose.Visible = Shell.FullScreen; + } + + private void SetPage(int page) + { + if (tbo == null) + return; + this.page = page; + if (pageImage != null) + pageImage.Dispose(); + pageImage = tbo.GetImage(page); + if (!tbo.ReadOnly) try + { + tbo.CurrentPage = page; + tbo.SaveMetadata(); + } + catch { }; + } + + private void cvTebeoPaint(Graphics g, Rectangle clip) + { + if (tbo == null || pageImage == null) + return; + g.DrawImageKeepRatioEx(pageImage, cvTebeo.Left, cvTebeo.Top, cvTebeo.Width, cvTebeo.Height); + } + + private void btFullscreenClick(Control c, Event e) + { + bool nfs = !Shell.FullScreen; + btClose.Visible = nfs; + Shell.FullScreen = nfs; + } + + private void btCloseClick(Control c, Event e) + { + Shell.DoClose?.Invoke(); + } + + private void btLibClick(Control c, Event e) + { + if (tbo != null) + { + tbo.Dispose(); + tbo = null; + } + Shell.GoTo(ApplicationLibrary.ApplicationId); + } + + private void btPrevClick(Control c, Event e) + { + if (page > 0) + { + SetPage(page - 1); + cvTebeo.Invalidate(); + } + } + + private void btNextClick(Control c, Event e) + { + if (page < tbo.PageCount - 1) + { + SetPage(page + 1); + cvTebeo.Invalidate(); + } + } + + public override string Id => ApplicationId; + public override string Title => I18n.Lang.Reader; + } +} diff --git a/TBO/Conf.cs b/TBO/Conf.cs new file mode 100644 index 0000000..5974fd5 --- /dev/null +++ b/TBO/Conf.cs @@ -0,0 +1,18 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace TBO +{ + static class Conf + { + public enum PageNavModeType + { + None, Left, Right, Both, MiddleLeft, MiddleRight, MiddleBoth + } + + public static PageNavModeType PageNavMode = PageNavModeType.Right; + public static bool PagenavGestures = true; + } +} diff --git a/TBO/Properties/Resources.Designer.cs b/TBO/Properties/Resources.Designer.cs index 6213d96..a97b96e 100644 --- a/TBO/Properties/Resources.Designer.cs +++ b/TBO/Properties/Resources.Designer.cs @@ -93,6 +93,26 @@ /// /// Busca un recurso adaptado de tipo System.Drawing.Bitmap. /// + internal static System.Drawing.Bitmap file_directory { + get { + object obj = ResourceManager.GetObject("file_directory", 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); + return ((System.Drawing.Bitmap)(obj)); + } + } + + /// + /// Busca un recurso adaptado de tipo System.Drawing.Bitmap. + /// internal static System.Drawing.Bitmap screen_full { get { object obj = ResourceManager.GetObject("screen_full", resourceCulture); diff --git a/TBO/Properties/Resources.resx b/TBO/Properties/Resources.resx index a2c4958..48d1920 100644 --- a/TBO/Properties/Resources.resx +++ b/TBO/Properties/Resources.resx @@ -136,4 +136,10 @@ ..\Resources\x.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + + ..\Resources\file-directory.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + + + ..\Resources\repo.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/file-directory.png b/TBO/Resources/file-directory.png new file mode 100644 index 0000000..6dce1cb --- /dev/null +++ b/TBO/Resources/file-directory.png Binary files differ diff --git a/TBO/Resources/repo.png b/TBO/Resources/repo.png new file mode 100644 index 0000000..b1b9213 --- /dev/null +++ b/TBO/Resources/repo.png Binary files differ diff --git a/TBO/TBO.csproj b/TBO/TBO.csproj index 214cb5d..fb814aa 100644 --- a/TBO/TBO.csproj +++ b/TBO/TBO.csproj @@ -51,6 +51,8 @@ xIO2.cs + + @@ -61,6 +63,7 @@ + @@ -129,6 +132,8 @@ + + diff --git a/TBO/TBOFile.cs b/TBO/TBOFile.cs index 40b81df..5961585 100644 --- a/TBO/TBOFile.cs +++ b/TBO/TBOFile.cs @@ -334,6 +334,15 @@ metapos = fs.Position + sizeof(int); } + public Image GetImage(int index) + { + if (index < 0 || index >= pagepos.Count) + return null; + fs.Position = pagepos[index]; + MemoryStream ms = new MemoryStream(fs.ReadBlock()); + return Image.FromStream(ms); + } + /// /// Save the metadata of the file /// @@ -365,9 +374,13 @@ [xIO.Serializable("Com")] public string Comments { get; set; } + [xIO.Serializable("Page")] + public int CurrentPage { get; set; } + #endregion public long Size => fs.Length; public int PageCount => pagepos.Count; + public bool ReadOnly => readOnly; } } diff --git a/TBO/UI/Shell.cs b/TBO/UI/Shell.cs index 1acbd23..d8013ba 100644 --- a/TBO/UI/Shell.cs +++ b/TBO/UI/Shell.cs @@ -38,6 +38,7 @@ static Shell() { AddApp(new ApplicationLibrary()); + AddApp(new ApplicationReader()); } public static void Paint(Graphics g, Rectangle clip) @@ -56,25 +57,26 @@ g.InterpolationMode = InterpolationMode.High; g.ScaleTransform(BaseZoom.X, BaseZoom.Y); - //g.DrawImage(Properties.Resources.tbo_logo ); - //g.DrawImageKeepRatioEx(Properties.Resources.tbo_logo, size.Width - 138, size.Height - 98, 128, 88, 0.3f); // Compose application current?.Paint(g, UnZoom(clip)); } #region Public API - public static bool GoTo(string id) + public static Application GoTo(string id,params string[] commands) { Application app; if (applications.TryGetValue(id, out app)) { current = app; + current.Shown(); current.ResizeTo(size); DoInvalidate(); - return true; + foreach (string command in commands) + current.ProcessCommand(command); + return app; } - return false; + return null; } public static void Invalidate() @@ -179,5 +181,6 @@ public static Size Size { get => size; set => SetSize(value); } public static PointF DPI { get => new PointF(BaseZoom.X * STANDARD_DPI, BaseZoom.Y * STANDARD_DPI); set => SetDPI(value); } public static bool FullScreen { get => fullScreen; set => SetFullScreen(value); } + public static Application Application => current; } } diff --git a/TBO/UI/UIManager.cs b/TBO/UI/UIManager.cs index 4594156..c1eddf7 100644 --- a/TBO/UI/UIManager.cs +++ b/TBO/UI/UIManager.cs @@ -24,6 +24,7 @@ public abstract void EnterReader(string path); public abstract void EnterStudio(string path); public abstract void ShowAbout(); + public abstract string OpenTBODialog(); public static UIManager Manager => manager; } diff --git a/TBO/UI/Windows/UIManagerWindows.cs b/TBO/UI/Windows/UIManagerWindows.cs index b7c3e8d..543f94b 100644 --- a/TBO/UI/Windows/UIManagerWindows.cs +++ b/TBO/UI/Windows/UIManagerWindows.cs @@ -27,6 +27,15 @@ Application.Run(new Studio(path)); } + public override string OpenTBODialog() + { + OpenFileDialog ofd = new OpenFileDialog(); + ofd.Filter = "Tebeo|*.tebeo"; + if (ofd.ShowDialog() == DialogResult.OK) + return ofd.FileName; + return null; + } + public override void ShowAbout() { using (About a = new About()) diff --git a/TBO/UI/tboTK/Application.cs b/TBO/UI/tboTK/Application.cs index 0213831..8b4a4ef 100644 --- a/TBO/UI/tboTK/Application.cs +++ b/TBO/UI/tboTK/Application.cs @@ -62,12 +62,14 @@ #endregion public abstract void ResizeTo(Size size); - public void Paint(Graphics g, Rectangle clip) + public virtual void Paint(Graphics g, Rectangle clip) { foreach (Control c in controls.Values) if (c.Visible && c.Clips(clip)) c.Paint(g, clip); } + public abstract void ProcessCommand(string cmd); + public abstract void Shown(); public abstract string Id { get; } public abstract string Title { get; } diff --git a/TBO/UI/tboTK/Canvas.cs b/TBO/UI/tboTK/Canvas.cs new file mode 100644 index 0000000..b40787a --- /dev/null +++ b/TBO/UI/tboTK/Canvas.cs @@ -0,0 +1,20 @@ +using System; +using System.Collections.Generic; +using System.Drawing; +using System.Linq; +using System.Text; + +namespace TBO.UI.tboTK +{ + class Canvas : Control + { + public delegate void PaintDelegate(Graphics g, Rectangle clip); + public PaintDelegate DoPaint; + + public Canvas(string id) : base(id) { } + public override void Paint(Graphics g, Rectangle clip) + { + DoPaint?.Invoke(g, clip); + } + } +} diff --git a/TBO/i18n/English.cs b/TBO/i18n/English.cs index 9b1c3be..b852265 100644 --- a/TBO/i18n/English.cs +++ b/TBO/i18n/English.cs @@ -8,5 +8,6 @@ class English : I18n { public override string Library => "Library"; + public override string Reader => "Reader"; } } diff --git a/TBO/i18n/Spanish.cs b/TBO/i18n/Spanish.cs index 55472ca..b37655a 100644 --- a/TBO/i18n/Spanish.cs +++ b/TBO/i18n/Spanish.cs @@ -8,5 +8,6 @@ class Spanish : I18n { public override string Library => "Biblioteca"; + public override string Reader => "Lector"; } } diff --git a/TBO/i18n/i18n.cs b/TBO/i18n/i18n.cs index 3f008b7..4e9ad1c 100644 --- a/TBO/i18n/i18n.cs +++ b/TBO/i18n/i18n.cs @@ -26,5 +26,6 @@ public static I18n Lang => i18n; public abstract string Library { get; } + public abstract string Reader { get; } } } diff --git a/res/file-directory.png b/res/file-directory.png new file mode 100644 index 0000000..6dce1cb --- /dev/null +++ b/res/file-directory.png Binary files differ diff --git a/res/pencil.png b/res/pencil.png new file mode 100644 index 0000000..7a952cf --- /dev/null +++ b/res/pencil.png Binary files differ diff --git a/res/repo.png b/res/repo.png new file mode 100644 index 0000000..b1b9213 --- /dev/null +++ b/res/repo.png Binary files differ