tastudio: move screenshot popup to yet another control to allow fading

avoid false branch 0 hover when entering branch view from the top

todo: hide screenshot when moving upwards to header cell
This commit is contained in:
feos 2017-03-08 16:18:15 +03:00
parent 7127c130bc
commit 0ec0910207
9 changed files with 355 additions and 150 deletions

View File

@ -1088,7 +1088,12 @@
<Compile Include="tools\TAStudio\PatternsForm.Designer.cs">
<DependentUpon>PatternsForm.cs</DependentUpon>
</Compile>
<Compile Include="tools\TAStudio\ScreenshotPopup.cs" />
<Compile Include="tools\TAStudio\ScreenshotForm.cs">
<SubType>Form</SubType>
</Compile>
<Compile Include="tools\TAStudio\ScreenshotForm.Designer.cs">
<DependentUpon>ScreenshotForm.cs</DependentUpon>
</Compile>
<Compile Include="tools\TAStudio\TAStudio.Callbacks.cs">
<DependentUpon>TAStudio.cs</DependentUpon>
<SubType>Form</SubType>
@ -1606,6 +1611,9 @@
<EmbeddedResource Include="tools\TAStudio\PlaybackBox.resx">
<DependentUpon>PlaybackBox.cs</DependentUpon>
</EmbeddedResource>
<EmbeddedResource Include="tools\TAStudio\ScreenshotForm.resx">
<DependentUpon>ScreenshotForm.cs</DependentUpon>
</EmbeddedResource>
<EmbeddedResource Include="tools\TAStudio\TAStudio.resx">
<DependentUpon>TAStudio.cs</DependentUpon>
</EmbeddedResource>

View File

@ -1680,7 +1680,7 @@ namespace BizHawk.Client.EmuHawk
/// <summary>
/// Bool that indicates if CurrentCell is a Column Cell.
/// </summary>
private bool IsHoveringOnColumnCell
public bool IsHoveringOnColumnCell
{
get
{
@ -1761,7 +1761,7 @@ namespace BizHawk.Client.EmuHawk
}
}
if (!(IsPaintDown || RightButtonHeld) && newCell.RowIndex == -1)
if (!(IsPaintDown || RightButtonHeld) && newCell.RowIndex <= -1) // -2 if we're entering from the top
newCell.RowIndex = null;
return newCell;

View File

@ -36,6 +36,7 @@
this.AddWithTextBranchButton = new System.Windows.Forms.Button();
this.AddBranchButton = new System.Windows.Forms.Button();
this.LoadBranchButton = new System.Windows.Forms.Button();
this.BranchView = new BizHawk.Client.EmuHawk.InputRoll();
this.BranchesContextMenu = new System.Windows.Forms.ContextMenuStrip(this.components);
this.AddBranchContextMenu = new System.Windows.Forms.ToolStripMenuItem();
this.AddBranchWithTextContextMenuItem = new System.Windows.Forms.ToolStripMenuItem();
@ -45,8 +46,6 @@
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();
this.SuspendLayout();
@ -146,6 +145,40 @@
this.LoadBranchButton.UseVisualStyleBackColor = true;
this.LoadBranchButton.Click += new System.EventHandler(this.LoadBranchToolStripMenuItem_Click);
//
// 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.FullRowSelect = true;
this.BranchView.HideWasLagFrames = false;
this.BranchView.HorizontalOrientation = false;
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);
this.BranchView.MouseDoubleClick += new System.Windows.Forms.MouseEventHandler(this.BranchView_MouseDoubleClick);
this.BranchView.MouseDown += new System.Windows.Forms.MouseEventHandler(this.BranchView_MouseDown);
this.BranchView.MouseLeave += new System.EventHandler(this.BranchView_MouseLeave);
this.BranchView.MouseMove += new System.Windows.Forms.MouseEventHandler(this.BranchView_MouseMove);
this.BranchView.MouseUp += new System.Windows.Forms.MouseEventHandler(this.BranchView_MouseUp);
//
// BranchesContextMenu
//
this.BranchesContextMenu.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
@ -213,54 +246,6 @@
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.FullRowSelect = true;
this.BranchView.HideWasLagFrames = false;
this.BranchView.HorizontalOrientation = false;
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);
this.BranchView.MouseDoubleClick += new System.Windows.Forms.MouseEventHandler(this.BranchView_MouseDoubleClick);
this.BranchView.MouseDown += new System.Windows.Forms.MouseEventHandler(this.BranchView_MouseDown);
this.BranchView.MouseLeave += new System.EventHandler(this.BranchView_MouseLeave);
this.BranchView.MouseMove += new System.Windows.Forms.MouseEventHandler(this.BranchView_MouseMove);
this.BranchView.MouseUp += new System.Windows.Forms.MouseEventHandler(this.BranchView_MouseUp);
//
// BookmarksBranchesBox
//
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Inherit;
@ -292,6 +277,5 @@
private System.Windows.Forms.Button LoadBranchButton;
private System.Windows.Forms.ToolTip toolTip1;
private System.Windows.Forms.ToolStripSeparator toolStripSeparator2;
private System.Windows.Forms.ToolTip ScreenshotTooltip;
}
}

View File

@ -20,7 +20,7 @@ namespace BizHawk.Client.EmuHawk
private const string FrameColumnName = "FrameColumn";
private const string UserTextColumnName = "TextColumn";
private readonly PlatformFrameRates FrameRates = new PlatformFrameRates();
private ScreenshotPopup Screenshot = new ScreenshotPopup();
private ScreenshotForm Screenshot = new ScreenshotForm();
private TasMovie Movie { get { return Tastudio.CurrentTasMovie; } }
public TAStudio Tastudio { get; set; }
@ -462,7 +462,7 @@ namespace BizHawk.Client.EmuHawk
private void BranchView_MouseLeave(object sender, EventArgs e)
{
ScreenshotTooltip.Hide(this);
Screenshot.FadeOut();
}
private void BranchView_CellHovered(object sender, InputRoll.CellEventArgs e)
@ -474,24 +474,25 @@ namespace BizHawk.Client.EmuHawk
BranchView.CurrentCell.RowIndex < Movie.BranchCount)
{
TasBranch branch = GetBranch(BranchView.CurrentCell.RowIndex.Value);
Point location = Location;
location.Offset(-Screenshot.Width, 0);
int width = Tastudio.VideoProvider.BufferWidth;
int height = Tastudio.VideoProvider.BufferHeight;
Screenshot.UpdateValues(branch, width, height,
Screenshot.UpdateValues(branch, PointToScreen(location), 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);
Screenshot.FadeIn();
}
else
{
ScreenshotTooltip.Hide(this);
Screenshot.FadeOut();
}
}
else
{
ScreenshotTooltip.Hide(this);
Screenshot.FadeOut();
}
}
@ -503,16 +504,6 @@ namespace BizHawk.Client.EmuHawk
}
}
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
}
}

View File

@ -118,12 +118,9 @@
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<metadata name="toolTip1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>297, 18</value>
<value>185, 17</value>
</metadata>
<metadata name="BranchesContextMenu.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>23, 17</value>
</metadata>
<metadata name="ScreenshotTooltip.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>171, 17</value>
</metadata>
</root>

View File

@ -0,0 +1,51 @@
namespace BizHawk.Client.EmuHawk
{
partial class ScreenshotForm
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.SuspendLayout();
//
// ScreenshotForm
//
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.None;
this.ClientSize = new System.Drawing.Size(314, 234);
this.ControlBox = false;
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;
this.MaximizeBox = false;
this.MinimizeBox = false;
this.Name = "ScreenshotForm";
this.ShowIcon = false;
this.ShowInTaskbar = false;
this.StartPosition = System.Windows.Forms.FormStartPosition.Manual;
this.ResumeLayout(false);
}
#endregion
}
}

View File

@ -0,0 +1,128 @@
// We pretend it's a tooltip kind of thing, so show only the actual contents
// and avoid stealing forcus, while still being topmost
// http://stackoverflow.com/a/25219399/2792852
// This is not an actual tooltip, because they can't reliably fade in and out with trasparency
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using BizHawk.Client.Common;
namespace BizHawk.Client.EmuHawk
{
public partial class ScreenshotForm : Form
{
private Timer _showTimer = new Timer();
private Timer _hideTimer = new Timer();
public TasBranch Branch { get; set; }
public Font Font;
public FontStyle FontStyle;
public int FontSize;
public int DrawingHeight;
public int Padding;
public string Text;
public ScreenshotForm()
{
InitializeComponent();
Width = 320;
Height = 240;
FontSize = 10;
FontStyle = FontStyle.Regular;
Font = new Font(FontFamily.GenericMonospace, FontSize, FontStyle);
DrawingHeight = 0;
Padding = 0;
Opacity = 0;
_showTimer.Interval = 1;
_showTimer.Tick += new EventHandler((sender, e) =>
{
if ((Opacity += 0.05d) >= 1)
_showTimer.Stop();
});
_hideTimer.Interval = 1;
_hideTimer.Tick += new EventHandler((sender, e) =>
{
if ((Opacity -= 0.05d) <= 0)
{
_hideTimer.Stop();
Hide();
}
});
}
public void UpdateValues(TasBranch branch, Point location , int width, int height, int padding)
{
Branch = branch;
Width = width;
Padding = padding;
DrawingHeight = height;
Text = Branch.UserText;
Location = location;
// 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;
}
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 (Padding > 0)
{
e.Graphics.DrawRectangle(new Pen(Brushes.Black), new Rectangle(new Point(0, DrawingHeight), new Size(Width - 1, Padding - 1)));
e.Graphics.DrawString(Text, Font, Brushes.Black, new Rectangle(2, DrawingHeight, Width - 2, Height));
}
base.OnPaint(e);
}
public void FadeIn()
{
_showTimer.Stop();
_hideTimer.Stop();
_showTimer.Start();
Show();
}
public void FadeOut()
{
_showTimer.Stop();
_hideTimer.Stop();
_hideTimer.Start();
}
protected override bool ShowWithoutActivation
{
get { return true; }
}
private const int WS_EX_TOPMOST = 0x00000008;
protected override CreateParams CreateParams
{
get
{
CreateParams createParams = base.CreateParams;
createParams.ExStyle |= WS_EX_TOPMOST;
return createParams;
}
}
}
}

View File

@ -0,0 +1,120 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
</root>

View File

@ -1,74 +0,0 @@
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, Width, DrawingHeight);
if (Padding > 0)
e.Graphics.DrawString(Text, Font, Brushes.Black,
new Rectangle(3, DrawingHeight, Width - 3, Height));
}
}
}