From d8d0c62adf2d79606bb5361e3ae66501c758d620 Mon Sep 17 00:00:00 2001 From: feos Date: Sun, 22 Jan 2017 17:46:54 +0300 Subject: [PATCH] tastodio: completely redo branch screenshot popup just to avoid cropping moved it to ToolTip, which feels like the proper way to do it --- .../BizHawk.Client.EmuHawk.csproj | 12 +- .../TAStudio/BookmarksBranchesBox.Designer.cs | 22 +++- .../tools/TAStudio/BookmarksBranchesBox.cs | 65 ++++++---- .../tools/TAStudio/BookmarksBranchesBox.resx | 7 +- .../tools/TAStudio/ScreenshotPopup.cs | 74 +++++++++++ .../ScreenshotPopupControl.Designer.cs | 47 ------- .../tools/TAStudio/ScreenshotPopupControl.cs | 77 ----------- .../TAStudio/ScreenshotPopupControl.resx | 120 ------------------ .../tools/TAStudio/TAStudio.cs | 66 +++------- 9 files changed, 159 insertions(+), 331 deletions(-) create mode 100644 BizHawk.Client.EmuHawk/tools/TAStudio/ScreenshotPopup.cs delete mode 100644 BizHawk.Client.EmuHawk/tools/TAStudio/ScreenshotPopupControl.Designer.cs delete mode 100644 BizHawk.Client.EmuHawk/tools/TAStudio/ScreenshotPopupControl.cs delete mode 100644 BizHawk.Client.EmuHawk/tools/TAStudio/ScreenshotPopupControl.resx diff --git a/BizHawk.Client.EmuHawk/BizHawk.Client.EmuHawk.csproj b/BizHawk.Client.EmuHawk/BizHawk.Client.EmuHawk.csproj index 3a0220059a..c992a9299d 100644 --- a/BizHawk.Client.EmuHawk/BizHawk.Client.EmuHawk.csproj +++ b/BizHawk.Client.EmuHawk/BizHawk.Client.EmuHawk.csproj @@ -1082,12 +1082,7 @@ PatternsForm.cs - - UserControl - - - ScreenshotPopupControl.cs - + TAStudio.cs Form @@ -1579,6 +1574,7 @@ BookmarksBranchesBox.cs + Designer DefaultGreenzoneSettings.cs @@ -1601,9 +1597,6 @@ PlaybackBox.cs - - ScreenshotPopupControl.cs - TAStudio.cs @@ -2106,6 +2099,7 @@ + diff --git a/BizHawk.Client.EmuHawk/tools/TAStudio/BookmarksBranchesBox.Designer.cs b/BizHawk.Client.EmuHawk/tools/TAStudio/BookmarksBranchesBox.Designer.cs index bf495f7744..83dc8144c3 100644 --- a/BizHawk.Client.EmuHawk/tools/TAStudio/BookmarksBranchesBox.Designer.cs +++ b/BizHawk.Client.EmuHawk/tools/TAStudio/BookmarksBranchesBox.Designer.cs @@ -45,6 +45,7 @@ this.toolStripSeparator2 = new System.Windows.Forms.ToolStripSeparator(); this.RemoveBranchContextMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.toolTip1 = new System.Windows.Forms.ToolTip(this.components); + this.ScreenshotTooltip = new System.Windows.Forms.ToolTip(this.components); this.BranchView = new BizHawk.Client.EmuHawk.InputRoll(); this.BookmarksBranchesGroupBox.SuspendLayout(); this.BranchesContextMenu.SuspendLayout(); @@ -212,29 +213,45 @@ this.RemoveBranchContextMenuItem.Text = "Remove"; this.RemoveBranchContextMenuItem.Click += new System.EventHandler(this.RemoveBranchToolStripMenuItem_Click); // + // ScreenshotTooltip + // + this.ScreenshotTooltip.AutomaticDelay = 0; + this.ScreenshotTooltip.AutoPopDelay = 34952; + this.ScreenshotTooltip.BackColor = System.Drawing.SystemColors.Control; + this.ScreenshotTooltip.InitialDelay = 0; + this.ScreenshotTooltip.OwnerDraw = true; + this.ScreenshotTooltip.ReshowDelay = 0; + this.ScreenshotTooltip.ShowAlways = true; + this.ScreenshotTooltip.UseAnimation = false; + this.ScreenshotTooltip.UseFading = false; + this.ScreenshotTooltip.Draw += new System.Windows.Forms.DrawToolTipEventHandler(this.Screenshot_Draw); + this.ScreenshotTooltip.Popup += new System.Windows.Forms.PopupEventHandler(this.Screenshot_Popup); + // // BranchView // this.BranchView.AllowColumnReorder = false; this.BranchView.AllowColumnResize = false; + this.BranchView.allowRightClickSelecton = true; this.BranchView.AlwaysScroll = false; this.BranchView.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) | System.Windows.Forms.AnchorStyles.Left) | System.Windows.Forms.AnchorStyles.Right))); this.BranchView.CellHeightPadding = 0; this.BranchView.ContextMenuStrip = this.BranchesContextMenu; - this.BranchView.allowRightClickSelecton = true; this.BranchView.FullRowSelect = true; this.BranchView.HideWasLagFrames = false; this.BranchView.HorizontalOrientation = false; - this.BranchView.HoverInterval = 1; this.BranchView.LagFramesToHide = 0; + this.BranchView.letKeysModifySelection = false; this.BranchView.Location = new System.Drawing.Point(6, 19); this.BranchView.MaxCharactersInHorizontal = 1; this.BranchView.MultiSelect = false; this.BranchView.Name = "BranchView"; this.BranchView.RowCount = 0; this.BranchView.ScrollSpeed = 13; + this.BranchView.SeekingCutoffInterval = 0; this.BranchView.Size = new System.Drawing.Size(186, 224); + this.BranchView.suspendHotkeys = false; this.BranchView.TabIndex = 0; this.BranchView.CellHovered += new BizHawk.Client.EmuHawk.InputRoll.HoverEventHandler(this.BranchView_CellHovered); this.BranchView.CellDropped += new BizHawk.Client.EmuHawk.InputRoll.CellDroppedEvent(this.BranchView_CellDropped); @@ -275,5 +292,6 @@ private System.Windows.Forms.Button LoadBranchButton; private System.Windows.Forms.ToolTip toolTip1; private System.Windows.Forms.ToolStripSeparator toolStripSeparator2; + private System.Windows.Forms.ToolTip ScreenshotTooltip; } } diff --git a/BizHawk.Client.EmuHawk/tools/TAStudio/BookmarksBranchesBox.cs b/BizHawk.Client.EmuHawk/tools/TAStudio/BookmarksBranchesBox.cs index 98da633dff..dd4e085a1b 100644 --- a/BizHawk.Client.EmuHawk/tools/TAStudio/BookmarksBranchesBox.cs +++ b/BizHawk.Client.EmuHawk/tools/TAStudio/BookmarksBranchesBox.cs @@ -19,8 +19,8 @@ namespace BizHawk.Client.EmuHawk private const string BranchNumberColumnName = "BranchNumberColumn"; private const string FrameColumnName = "FrameColumn"; private const string UserTextColumnName = "TextColumn"; - private readonly PlatformFrameRates FrameRates = new PlatformFrameRates(); + private ScreenshotPopup Screenshot = new ScreenshotPopup(); private TasMovie Movie { get { return Tastudio.CurrentTasMovie; } } public TAStudio Tastudio { get; set; } @@ -64,6 +64,8 @@ namespace BizHawk.Client.EmuHawk BranchView.QueryItemBkColor += QueryItemBkColor; } + #region Query callbacks + private void QueryItemText(int index, InputRoll.RollColumn column, out string text, ref int offsetX, ref int offsetY) { text = string.Empty; @@ -119,6 +121,10 @@ namespace BizHawk.Client.EmuHawk } } + #endregion + + #region Actions + public void Branch() { TasBranch branch = CreateBranch(); @@ -405,27 +411,9 @@ namespace BizHawk.Client.EmuHawk } } - private void ScreenShotPopUp(TasBranch branch, int index) - { - Point locationOnForm = this.FindForm().PointToClient( - this.Parent.PointToScreen(this.Location)); + #endregion - int x = locationOnForm.X - Tastudio.ScreenshotControl.Width; - int y = locationOnForm.Y; // keep consistent height, helps when conparing screenshots - - if (x < 1) x = 1; - - Tastudio.ScreenshotControl.Location = new Point(x, y); - Tastudio.ScreenshotControl.Visible = true; - Tastudio.ScreenshotControl.Branch = branch; - Tastudio.ScreenshotControl.RecalculateHeight(); - Tastudio.ScreenshotControl.Refresh(); - } - - private void CloseScreenShotPopUp() - { - Tastudio.ScreenshotControl.Visible = false; - } + #region Events private void BranchView_MouseDown(object sender, MouseEventArgs e) { @@ -464,7 +452,7 @@ namespace BizHawk.Client.EmuHawk { if (BranchView.CurrentCell == null || !BranchView.CurrentCell.RowIndex.HasValue || BranchView.CurrentCell.Column == null) { - CloseScreenShotPopUp(); + //not sure if we need to explicitly hide the screenshot here as well } else if (BranchView.CurrentCell.Column.Name == BranchNumberColumnName) { @@ -474,25 +462,36 @@ namespace BizHawk.Client.EmuHawk private void BranchView_MouseLeave(object sender, EventArgs e) { - // Tastudio.ScreenshotControl.Visible = false; + ScreenshotTooltip.Hide(this); } private void BranchView_CellHovered(object sender, InputRoll.CellEventArgs e) { if (e.NewCell != null && e.NewCell.RowIndex.HasValue && e.NewCell.Column != null && e.NewCell.RowIndex < Movie.BranchCount) { - if (e.NewCell.Column.Name == BranchNumberColumnName) + if (BranchView.CurrentCell.Column.Name == BranchNumberColumnName && + BranchView.CurrentCell.RowIndex.HasValue && + BranchView.CurrentCell.RowIndex < Movie.BranchCount) { - ScreenShotPopUp(GetBranch(e.NewCell.RowIndex.Value), e.NewCell.RowIndex.Value); + TasBranch branch = GetBranch(BranchView.CurrentCell.RowIndex.Value); + int width = Tastudio.VideoProvider.BufferWidth; + int height = Tastudio.VideoProvider.BufferHeight; + Screenshot.UpdateValues(branch, width, height, + (int)Graphics.FromHwnd(this.Handle).MeasureString( + branch.UserText, Screenshot.Font, width).Height); + + Point location = Location; + location.Offset(-Screenshot.Width, 0); + ScreenshotTooltip.Show(" ", this, location); } else { - CloseScreenShotPopUp(); + ScreenshotTooltip.Hide(this); } } else { - CloseScreenShotPopUp(); + ScreenshotTooltip.Hide(this); } } @@ -503,5 +502,17 @@ namespace BizHawk.Client.EmuHawk Movie.SwapBranches(e.OldCell.RowIndex.Value, e.NewCell.RowIndex.Value); } } + + private void Screenshot_Popup(object sender, PopupEventArgs e) + { + Screenshot.Popup(sender, e); + } + + private void Screenshot_Draw(object sender, DrawToolTipEventArgs e) + { + Screenshot.Draw(sender, e); + } + + #endregion } } diff --git a/BizHawk.Client.EmuHawk/tools/TAStudio/BookmarksBranchesBox.resx b/BizHawk.Client.EmuHawk/tools/TAStudio/BookmarksBranchesBox.resx index 4c3d7ab49c..b03be4818d 100644 --- a/BizHawk.Client.EmuHawk/tools/TAStudio/BookmarksBranchesBox.resx +++ b/BizHawk.Client.EmuHawk/tools/TAStudio/BookmarksBranchesBox.resx @@ -118,9 +118,12 @@ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - 179, 17 + 297, 18 - 17, 17 + 23, 17 + + + 171, 17 \ No newline at end of file diff --git a/BizHawk.Client.EmuHawk/tools/TAStudio/ScreenshotPopup.cs b/BizHawk.Client.EmuHawk/tools/TAStudio/ScreenshotPopup.cs new file mode 100644 index 0000000000..102e9c96b5 --- /dev/null +++ b/BizHawk.Client.EmuHawk/tools/TAStudio/ScreenshotPopup.cs @@ -0,0 +1,74 @@ +using System; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Windows.Forms; +using BizHawk.Client.Common; + +namespace BizHawk.Client.EmuHawk +{ + public class ScreenshotPopup + { + public TasBranch Branch { get; set; } + public Font Font; + public FontStyle FontStyle; + public int Width; + public int Height; + public int FontSize; + public int DrawingHeight; + public int Padding; + public string Text; + + public ScreenshotPopup() + { + Width = 0; + Height = 0; + FontSize = 10; + FontStyle = FontStyle.Regular; + Font = new Font(FontFamily.GenericMonospace, FontSize, FontStyle); + DrawingHeight = 0; + Padding = 0; + } + + public void UpdateValues(TasBranch branch, int width, int height, int padding) + { + Branch = branch; + Width = width; + Padding = padding; + DrawingHeight = height; + Text = Branch.UserText; + + // Set the screenshot to "1x" resolution of the core + // cores like n64 and psx are going to still have sizes too big for the control, so cap them + if (Width > 320) + { + double ratio = 320.0 / (double)Width; + Width = 320; + DrawingHeight = (int)((double)(DrawingHeight) * ratio); + } + + if (Padding > 0) + Padding += 2; + Height = DrawingHeight + Padding; + } + + public void Popup(object sender, PopupEventArgs e) + { + e.ToolTipSize = new Size(Width, Height); + } + + public void Draw(object sender, DrawToolTipEventArgs e) + { + Branch.OSDFrameBuffer.DiscardAlpha(); + var bitmap = Branch.OSDFrameBuffer.ToSysdrawingBitmap(); + + e.DrawBackground(); + e.DrawBorder(); + e.Graphics.DrawImage(bitmap, e.Bounds.Left, e.Bounds.Top); + + if (Padding > 0) + e.Graphics.DrawString(Text, Font, Brushes.Black, + new Rectangle(3, DrawingHeight, Width - 3, Height)); + } + } +} diff --git a/BizHawk.Client.EmuHawk/tools/TAStudio/ScreenshotPopupControl.Designer.cs b/BizHawk.Client.EmuHawk/tools/TAStudio/ScreenshotPopupControl.Designer.cs deleted file mode 100644 index 3a6174ac5e..0000000000 --- a/BizHawk.Client.EmuHawk/tools/TAStudio/ScreenshotPopupControl.Designer.cs +++ /dev/null @@ -1,47 +0,0 @@ -namespace BizHawk.Client.EmuHawk -{ - partial class ScreenshotPopupControl - { - /// - /// Required designer variable. - /// - private System.ComponentModel.IContainer components = null; - - /// - /// Clean up any resources being used. - /// - /// true if managed resources should be disposed; otherwise, false. - protected override void Dispose(bool disposing) - { - if (disposing && (components != null)) - { - components.Dispose(); - } - base.Dispose(disposing); - } - - #region Component Designer generated code - - /// - /// Required method for Designer support - do not modify - /// the contents of this method with the code editor. - /// - private void InitializeComponent() - { - this.SuspendLayout(); - // - // ScreenshotPopupControl - // - this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); - this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.Name = "ScreenshotPopupControl"; - this.Size = new System.Drawing.Size(237, 255); - this.Load += new System.EventHandler(this.ScreenshotPopupControl_Load); - this.ResumeLayout(false); - this.MouseLeave += new System.EventHandler(ScreenshotPopupControl_MouseLeave); - this.MouseHover += new System.EventHandler(ScreenshotPopupControl_MouseHover); - } - - #endregion - } -} diff --git a/BizHawk.Client.EmuHawk/tools/TAStudio/ScreenshotPopupControl.cs b/BizHawk.Client.EmuHawk/tools/TAStudio/ScreenshotPopupControl.cs deleted file mode 100644 index 877da461a3..0000000000 --- a/BizHawk.Client.EmuHawk/tools/TAStudio/ScreenshotPopupControl.cs +++ /dev/null @@ -1,77 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Drawing; -using System.Linq; -using System.Windows.Forms; -using BizHawk.Client.Common; - -namespace BizHawk.Client.EmuHawk -{ - public partial class ScreenshotPopupControl : UserControl - { - public TasBranch Branch { get; set; } - public int DrawingHeight = 0; - public int UserPadding = 0; - public int UserFontSize = 10; // because why not? - public FontStyle UserFontStyle = FontStyle.Regular; - public string UserText; - private Font UserFont; - - public ScreenshotPopupControl() - { - //SetStyle(ControlStyles.SupportsTransparentBackColor, true); - //SetStyle(ControlStyles.Opaque, true); - //this.BackColor = Color.Transparent; - - InitializeComponent(); - } - - protected override void OnPaint(PaintEventArgs e) - { - Branch.OSDFrameBuffer.DiscardAlpha(); - var bitmap = Branch.OSDFrameBuffer.ToSysdrawingBitmap(); - e.Graphics.DrawImage(bitmap, new Rectangle(0, 0, Width, DrawingHeight)); - if (UserPadding > 0) - { - e.Graphics.DrawRectangle(new Pen(Brushes.Black), new Rectangle(new Point(0, DrawingHeight), new Size(Width - 1, UserPadding - 1))); - e.Graphics.DrawString(UserText, UserFont, Brushes.Black, new Rectangle(2, DrawingHeight, Width - 2, Height)); - } - base.OnPaint(e); - } - - public void SetFontStyle(FontStyle style) - { - UserFontStyle = style; - } - - public void SetFontSize(int size) - { - UserFontSize = size; - } - - public void RecalculateHeight() - { - UserFont = new Font(FontFamily.GenericMonospace, UserFontSize, UserFontStyle); - UserText = Branch.UserText; - UserPadding = (int)Graphics.FromHwnd(this.Handle).MeasureString(UserText, UserFont, Width).Height; - if (UserPadding > 0) - UserPadding += 2; - Height = DrawingHeight + UserPadding; - } - - private void ScreenshotPopupControl_MouseLeave(object sender, EventArgs e) - { - Visible = false; - } - - private void ScreenshotPopupControl_MouseHover(object sender, EventArgs e) - { - // todo: switch screenshots by hotkey - } - - private void ScreenshotPopupControl_Load(object sender, EventArgs e) - { - - } - } -} diff --git a/BizHawk.Client.EmuHawk/tools/TAStudio/ScreenshotPopupControl.resx b/BizHawk.Client.EmuHawk/tools/TAStudio/ScreenshotPopupControl.resx deleted file mode 100644 index 1af7de150c..0000000000 --- a/BizHawk.Client.EmuHawk/tools/TAStudio/ScreenshotPopupControl.resx +++ /dev/null @@ -1,120 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - text/microsoft-resx - - - 2.0 - - - System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - \ No newline at end of file diff --git a/BizHawk.Client.EmuHawk/tools/TAStudio/TAStudio.cs b/BizHawk.Client.EmuHawk/tools/TAStudio/TAStudio.cs index 21839f4cf5..9c17f2c9b7 100644 --- a/BizHawk.Client.EmuHawk/tools/TAStudio/TAStudio.cs +++ b/BizHawk.Client.EmuHawk/tools/TAStudio/TAStudio.cs @@ -22,13 +22,12 @@ namespace BizHawk.Client.EmuHawk // TODO: UI flow that conveniently allows to start from savestate private const string CursorColumnName = "CursorColumn"; private const string FrameColumnName = "FrameColumn"; - - private readonly List _tasClipboard = new List(); - private BackgroundWorker _saveBackgroundWorker; private BackgroundWorker _seekBackgroundWorker; - private MovieEndAction _originalEndAction; // The movie end behavior selected by the user (that is overridden by TAStudio) + private UndoHistoryForm _undoForm; + private Timer _autosaveTimer = new Timer(); + private readonly List _tasClipboard = new List(); private Dictionary GenerateColumnNames() { var lg = Global.MovieSession.LogGeneratorInstance(); @@ -36,20 +35,28 @@ namespace BizHawk.Client.EmuHawk return (lg as Bk2LogEntryGenerator).Map(); } - private UndoHistoryForm _undoForm; - private Timer _autosaveTimer = new Timer(); - - public ScreenshotPopupControl ScreenshotControl = new ScreenshotPopupControl - { - Size = new Size(256, 240), - }; + public bool IsInMenuLoop { get; private set; } public string statesPath { get { return PathManager.MakeAbsolutePath(Global.Config.PathEntries["Global", "TAStudio states"].Path, null); } } - public bool IsInMenuLoop { get; private set; } + public TasMovie CurrentTasMovie + { + get { return Global.MovieSession.Movie as TasMovie; } + } + + public MainForm Mainform + { + get { return GlobalWin.MainForm; } + } + + /// + /// Separates "restore last position" logic from seeking caused by navigation. + /// TASEditor never kills LastPositionFrame, and it only pauses on it, if it hasn't been greenzoned beforehand and middle mouse button was pressed. + /// + public int LastPositionFrame { get; set; } [ConfigPersist] public TAStudioSettings Settings { get; set; } @@ -105,23 +112,6 @@ namespace BizHawk.Client.EmuHawk public int BranchMarkerSplitDistance { get; set; } } - public TasMovie CurrentTasMovie - { - get { return Global.MovieSession.Movie as TasMovie; } - } - - public MainForm Mainform - { - get { return GlobalWin.MainForm; } - } - - /// - /// Separates "restore last position" logic from seeking caused by navigation. - /// TASEditor never kills LastPositionFrame, and it only pauses on it, - /// if it hasn't been greenzoned beforehand and middle mouse button was pressed. - /// - public int LastPositionFrame { get; set; } - #region "Initializing" public TAStudio() @@ -270,24 +260,6 @@ namespace BizHawk.Client.EmuHawk return; } - // Set the screenshot to "1x" resolution of the core - // cores like n64 and psx are going to still have sizes too big for the control, so cap them - int width = VideoProvider.BufferWidth; - int height = VideoProvider.BufferHeight; - if (width > 320) - { - double ratio = 320.0 / (double)width; - width = 320; - height = (int)((double)(height) * ratio); - } - ScreenshotControl.DrawingHeight = height; - ScreenshotControl.Size = new Size(width, ScreenshotControl.DrawingHeight + ScreenshotControl.UserPadding); - - - ScreenshotControl.Visible = false; - Controls.Add(ScreenshotControl); - ScreenshotControl.BringToFront(); - SetColumnsFromCurrentStickies(); if (VersionInfo.DeveloperBuild)