From 9b6add0e4010a94cbaa5c6695c38e041fd9224cf Mon Sep 17 00:00:00 2001 From: zeromus Date: Fri, 10 Oct 2014 00:15:15 +0000 Subject: [PATCH] basic TransformPoint work --- .../DisplayManager/DisplayManager.cs | 14 ++++++++++++++ .../DisplayManager/FilterManager.cs | 13 +++++++++++++ .../DisplayManager/Filters/BaseFilter.cs | 14 ++++++++++++++ .../DisplayManager/Filters/Gui.cs | 11 +++++++++++ 4 files changed, 52 insertions(+) diff --git a/BizHawk.Client.EmuHawk/DisplayManager/DisplayManager.cs b/BizHawk.Client.EmuHawk/DisplayManager/DisplayManager.cs index de8f62cb36..e9faa6f9e9 100644 --- a/BizHawk.Client.EmuHawk/DisplayManager/DisplayManager.cs +++ b/BizHawk.Client.EmuHawk/DisplayManager/DisplayManager.cs @@ -247,6 +247,20 @@ namespace BizHawk.Client.EmuHawk return new Point((int)v.X, (int)v.Y); } + /// + /// Using the current filter program, turn a emulator screen space coordinat to a window coordinate (suitable for lua layer drawing) + /// + public Point TransformPoint(Point p) + { + //now, if theres no filter program active, just give up + if (CurrentFilterProgram == null) return p; + + //otherwise, have the filter program untransform it + Vector2 v = new Vector2(p.X, p.Y); + v = CurrentFilterProgram.TransformPoint("default", v); + return new Point((int)v.X, (int)v.Y); + } + /// /// This will receive an emulated output frame from an IVideoProvider and run it through the complete frame processing pipeline diff --git a/BizHawk.Client.EmuHawk/DisplayManager/FilterManager.cs b/BizHawk.Client.EmuHawk/DisplayManager/FilterManager.cs index 0c06df233c..a14c9ba05c 100644 --- a/BizHawk.Client.EmuHawk/DisplayManager/FilterManager.cs +++ b/BizHawk.Client.EmuHawk/DisplayManager/FilterManager.cs @@ -94,6 +94,19 @@ namespace BizHawk.Client.EmuHawk.FilterManager return point; } + /// + /// Receives a point in the input space of the filter program and transforms it through to output points + /// + public Vector2 TransformPoint(string channel, Vector2 point) + { + for (int i = 0; i < Filters.Count; i++) + { + var filter = Filters[i]; + point = filter.TransformPoint(channel, point); + } + return point; + } + public class ProgramStep { public ProgramStep(ProgramStepType type, object args, string comment = null) diff --git a/BizHawk.Client.EmuHawk/DisplayManager/Filters/BaseFilter.cs b/BizHawk.Client.EmuHawk/DisplayManager/Filters/BaseFilter.cs index 2eb011b61c..a4ce9304b7 100644 --- a/BizHawk.Client.EmuHawk/DisplayManager/Filters/BaseFilter.cs +++ b/BizHawk.Client.EmuHawk/DisplayManager/Filters/BaseFilter.cs @@ -51,6 +51,20 @@ namespace BizHawk.Client.EmuHawk.Filters } return point; } + + public virtual Vector2 TransformPoint(string channel, Vector2 point) + { + //base class behaviour here just uses the input and output sizes, if appropriate. few filters will have to do anything more complex + var input = FindInput(channel); + var output = FindOutput(channel); + if (input != null && output != null) + { + point.X *= ((float)output.SurfaceFormat.Size.Width) / (float)input.SurfaceFormat.Size.Width; + point.Y *= ((float)output.SurfaceFormat.Size.Height) / (float)input.SurfaceFormat.Size.Height; + } + return point; + } + public void SetInput(Texture2d tex) { InputTexture = tex; diff --git a/BizHawk.Client.EmuHawk/DisplayManager/Filters/Gui.cs b/BizHawk.Client.EmuHawk/DisplayManager/Filters/Gui.cs index b6a203457f..557ebee816 100644 --- a/BizHawk.Client.EmuHawk/DisplayManager/Filters/Gui.cs +++ b/BizHawk.Client.EmuHawk/DisplayManager/Filters/Gui.cs @@ -232,6 +232,17 @@ namespace BizHawk.Client.EmuHawk.Filters return point; } + public override Vector2 TransformPoint(string channel, Vector2 point) + { + if (nop) + return point; + point.X *= LL.WidthScale; + point.Y *= LL.HeightScale; + point.X += LL.vx; + point.Y += LL.vy; + return point; + } + public override void Run() { if (nop)