From 1d053a5e2b2ff07ac8abe4e02dad4d5413b4ac4d Mon Sep 17 00:00:00 2001 From: codeimp Date: Fri, 21 Aug 2009 14:11:18 +0000 Subject: [PATCH] @ Renamed GetMapCoordinates function to DisplayToMap and added MapToDisplay function @ Exposed the RenderTargetDisplay to plugins --- Source/Core/Controls/RenderTargetControl.cs | 4 ++-- Source/Core/Editing/ClassicMode.cs | 8 +++---- Source/Core/Rendering/IRenderer2D.cs | 4 ++++ Source/Core/Rendering/Renderer2D.cs | 24 +++++++++++++++------ Source/Core/Windows/IMainForm.cs | 1 + Source/Core/Windows/MainForm.cs | 2 +- 6 files changed, 29 insertions(+), 14 deletions(-) diff --git a/Source/Core/Controls/RenderTargetControl.cs b/Source/Core/Controls/RenderTargetControl.cs index f80b1e5e..fb0eb610 100644 --- a/Source/Core/Controls/RenderTargetControl.cs +++ b/Source/Core/Controls/RenderTargetControl.cs @@ -32,7 +32,7 @@ using CodeImp.DoomBuilder.Editing; namespace CodeImp.DoomBuilder.Controls { - internal class RenderTargetControl : Panel + public class RenderTargetControl : Panel { #region ================== Constants @@ -52,7 +52,7 @@ namespace CodeImp.DoomBuilder.Controls #region ================== Constructor / Disposer // Constructor - public RenderTargetControl() + internal RenderTargetControl() { // Initialize this.SetStyle(ControlStyles.FixedWidth, true); diff --git a/Source/Core/Editing/ClassicMode.cs b/Source/Core/Editing/ClassicMode.cs index f36c4b28..ef583682 100644 --- a/Source/Core/Editing/ClassicMode.cs +++ b/Source/Core/Editing/ClassicMode.cs @@ -207,7 +207,7 @@ namespace CodeImp.DoomBuilder.Editing General.MainWindow.RedrawDisplay(); // Determine new unprojected mouse coordinates - mousemappos = renderer2d.GetMapCoordinates(mousepos); + mousemappos = renderer2d.DisplayToMap(mousepos); General.MainWindow.UpdateCoordinates(mousemappos); } @@ -222,7 +222,7 @@ namespace CodeImp.DoomBuilder.Editing General.MainWindow.RedrawDisplay(); // Determine new unprojected mouse coordinates - mousemappos = renderer2d.GetMapCoordinates(mousepos); + mousemappos = renderer2d.DisplayToMap(mousepos); General.MainWindow.UpdateCoordinates(mousemappos); } @@ -478,7 +478,7 @@ namespace CodeImp.DoomBuilder.Editing mouseinside = true; mouselastpos = mousepos; mousepos = new Vector2D(e.X, e.Y); - mousemappos = renderer2d.GetMapCoordinates(mousepos); + mousemappos = renderer2d.DisplayToMap(mousepos); mousebuttons = e.Button; // Update labels in main window @@ -692,7 +692,7 @@ namespace CodeImp.DoomBuilder.Editing if(mouseinside && !float.IsNaN(mouselastpos.x) && !float.IsNaN(mouselastpos.y)) { // Get the map coordinates of the last mouse posision (before it moved) - Vector2D lastmappos = renderer2d.GetMapCoordinates(mouselastpos); + Vector2D lastmappos = renderer2d.DisplayToMap(mouselastpos); // Do the scroll ScrollBy(lastmappos.x - mousemappos.x, lastmappos.y - mousemappos.y); diff --git a/Source/Core/Rendering/IRenderer2D.cs b/Source/Core/Rendering/IRenderer2D.cs index b3bac356..ff729934 100644 --- a/Source/Core/Rendering/IRenderer2D.cs +++ b/Source/Core/Rendering/IRenderer2D.cs @@ -49,6 +49,10 @@ namespace CodeImp.DoomBuilder.Rendering int VertexSize { get; } ViewMode ViewMode { get; } + // View methods + Vector2D DisplayToMap(Vector2D mousepos); + Vector2D MapToDisplay(Vector2D mappos); + // Color methods PixelColor DetermineLinedefColor(Linedef l); PixelColor DetermineThingColor(Thing t); diff --git a/Source/Core/Rendering/Renderer2D.cs b/Source/Core/Rendering/Renderer2D.cs index a4cc0fa1..57e15c2e 100644 --- a/Source/Core/Rendering/Renderer2D.cs +++ b/Source/Core/Rendering/Renderer2D.cs @@ -546,12 +546,22 @@ namespace CodeImp.DoomBuilder.Rendering } } - // This unprojects mouse coordinates into map coordinates - public Vector2D GetMapCoordinates(Vector2D mousepos) + /// + /// This unprojects display coordinates (screen space) to map coordinates + /// + public Vector2D DisplayToMap(Vector2D mousepos) { return mousepos.GetInvTransformed(-translatex, -translatey, scaleinv, -scaleinv); } - + + /// + /// This projects map coordinates to display coordinates (screen space) + /// + public Vector2D MapToDisplay(Vector2D mappos) + { + return mappos.GetTransformed(translatex, translatey, scale, -scale); + } + #endregion #region ================== Colors @@ -759,8 +769,8 @@ namespace CodeImp.DoomBuilder.Rendering backimageverts = CreateScreenVerts(windowsize); // Determine map coordinates for view window - ltpos = GetMapCoordinates(new Vector2D(0f, 0f)); - rbpos = GetMapCoordinates(new Vector2D(windowsize.Width, windowsize.Height)); + ltpos = DisplayToMap(new Vector2D(0f, 0f)); + rbpos = DisplayToMap(new Vector2D(windowsize.Width, windowsize.Height)); // Offset by given background offset ltpos -= backoffset; @@ -828,8 +838,8 @@ namespace CodeImp.DoomBuilder.Rendering if((size * scale) > 6f) { // Determine map coordinates for view window - ltpos = GetMapCoordinates(new Vector2D(0, 0)); - rbpos = GetMapCoordinates(new Vector2D(windowsize.Width, windowsize.Height)); + ltpos = DisplayToMap(new Vector2D(0, 0)); + rbpos = DisplayToMap(new Vector2D(windowsize.Width, windowsize.Height)); // Clip to nearest grid ltpos = GridSetup.SnappedToGrid(ltpos, size, sizeinv); diff --git a/Source/Core/Windows/IMainForm.cs b/Source/Core/Windows/IMainForm.cs index 5d3587a4..cabc6bab 100644 --- a/Source/Core/Windows/IMainForm.cs +++ b/Source/Core/Windows/IMainForm.cs @@ -52,6 +52,7 @@ namespace CodeImp.DoomBuilder.Windows bool MouseExclusive { get; } MouseButtons MouseButtons { get; } bool IsActiveWindow { get; } + RenderTargetControl Display { get; } // Methods void DisplayReady(); diff --git a/Source/Core/Windows/MainForm.cs b/Source/Core/Windows/MainForm.cs index 1bbb1d05..ebc805a2 100644 --- a/Source/Core/Windows/MainForm.cs +++ b/Source/Core/Windows/MainForm.cs @@ -164,7 +164,7 @@ namespace CodeImp.DoomBuilder.Windows public bool AltState { get { return alt; } } public MouseButtons MouseButtons { get { return mousebuttons; } } public bool MouseInDisplay { get { return mouseinside; } } - internal RenderTargetControl Display { get { return display; } } + public RenderTargetControl Display { get { return display; } } public bool SnapToGrid { get { return buttonsnaptogrid.Checked; } } public bool AutoMerge { get { return buttonautomerge.Checked; } } public bool MouseExclusive { get { return mouseexclusive; } }