2007-06-15 18:30:55 +00:00
|
|
|
|
|
|
|
#region ================== Copyright (c) 2007 Pascal vd Heiden
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Copyright (c) 2007 Pascal vd Heiden, www.codeimp.com
|
|
|
|
* This program is released under GNU General Public License
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
#region ================== Namespaces
|
|
|
|
|
|
|
|
using System;
|
|
|
|
using System.Collections;
|
|
|
|
using System.Collections.Generic;
|
|
|
|
using System.Globalization;
|
|
|
|
using System.Text;
|
|
|
|
using System.Windows.Forms;
|
|
|
|
using System.IO;
|
|
|
|
using System.Reflection;
|
|
|
|
using CodeImp.DoomBuilder.Interface;
|
|
|
|
using CodeImp.DoomBuilder.IO;
|
|
|
|
using CodeImp.DoomBuilder.Map;
|
2007-06-15 22:38:42 +00:00
|
|
|
using CodeImp.DoomBuilder.Rendering;
|
2007-06-26 06:01:52 +00:00
|
|
|
using CodeImp.DoomBuilder.Controls;
|
2007-07-07 09:40:34 +00:00
|
|
|
using CodeImp.DoomBuilder.Geometry;
|
|
|
|
using System.Drawing;
|
2007-06-15 18:30:55 +00:00
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
namespace CodeImp.DoomBuilder.Editing
|
|
|
|
{
|
2007-10-20 01:04:47 +00:00
|
|
|
internal abstract class ClassicMode : EditMode
|
2007-06-15 18:30:55 +00:00
|
|
|
{
|
|
|
|
#region ================== Constants
|
|
|
|
|
2007-10-21 12:58:56 +00:00
|
|
|
private const float SCALE_MAX = 20f;
|
|
|
|
private const float SCALE_MIN = 0.01f;
|
|
|
|
|
2007-06-15 18:30:55 +00:00
|
|
|
#endregion
|
|
|
|
|
|
|
|
#region ================== Variables
|
|
|
|
|
2007-06-15 22:38:42 +00:00
|
|
|
// Graphics
|
|
|
|
protected Renderer2D renderer;
|
|
|
|
|
2007-07-07 09:40:34 +00:00
|
|
|
// Mouse status
|
|
|
|
protected Vector2D mousepos;
|
|
|
|
protected Vector2D mousemappos;
|
2007-10-20 19:50:03 +00:00
|
|
|
protected MouseButtons mousebuttons;
|
2007-07-07 09:40:34 +00:00
|
|
|
protected bool mouseinside;
|
|
|
|
|
2007-06-15 18:30:55 +00:00
|
|
|
#endregion
|
|
|
|
|
|
|
|
#region ================== Properties
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
#region ================== Constructor / Disposer
|
|
|
|
|
|
|
|
// Constructor
|
2007-10-20 01:04:47 +00:00
|
|
|
public ClassicMode()
|
2007-06-15 18:30:55 +00:00
|
|
|
{
|
|
|
|
// Initialize
|
2007-09-24 19:54:47 +00:00
|
|
|
this.renderer = General.Map.Graphics.Renderer2D;
|
2007-06-15 18:30:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Diposer
|
|
|
|
public override void Dispose()
|
|
|
|
{
|
|
|
|
// Not already disposed?
|
|
|
|
if(!isdisposed)
|
|
|
|
{
|
|
|
|
// Clean up
|
2007-06-15 22:38:42 +00:00
|
|
|
|
2007-06-15 18:30:55 +00:00
|
|
|
// Dispose base
|
|
|
|
base.Dispose();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
2007-06-26 06:01:52 +00:00
|
|
|
#region ================== Scroll / Zoom
|
2007-06-15 18:30:55 +00:00
|
|
|
|
2007-06-26 06:01:52 +00:00
|
|
|
// This scrolls the view north
|
|
|
|
[Action(Action.SCROLLNORTH)]
|
2007-09-23 22:01:21 +00:00
|
|
|
public virtual void ScrollNorth()
|
2007-06-26 06:01:52 +00:00
|
|
|
{
|
|
|
|
// Scroll
|
|
|
|
ScrollBy(0f, 100f / renderer.Scale);
|
|
|
|
}
|
|
|
|
|
|
|
|
// This scrolls the view south
|
|
|
|
[Action(Action.SCROLLSOUTH)]
|
2007-09-23 22:01:21 +00:00
|
|
|
public virtual void ScrollSouth()
|
2007-06-26 06:01:52 +00:00
|
|
|
{
|
|
|
|
// Scroll
|
|
|
|
ScrollBy(0f, -100f / renderer.Scale);
|
|
|
|
}
|
|
|
|
|
|
|
|
// This scrolls the view west
|
|
|
|
[Action(Action.SCROLLWEST)]
|
2007-09-23 22:01:21 +00:00
|
|
|
public virtual void ScrollWest()
|
2007-06-26 06:01:52 +00:00
|
|
|
{
|
|
|
|
// Scroll
|
|
|
|
ScrollBy(-100f / renderer.Scale, 0f);
|
|
|
|
}
|
|
|
|
|
|
|
|
// This scrolls the view east
|
|
|
|
[Action(Action.SCROLLEAST)]
|
2007-09-23 22:01:21 +00:00
|
|
|
public virtual void ScrollEast()
|
2007-06-26 06:01:52 +00:00
|
|
|
{
|
|
|
|
// Scroll
|
|
|
|
ScrollBy(100f / renderer.Scale, 0f);
|
|
|
|
}
|
|
|
|
|
|
|
|
// This zooms in
|
|
|
|
[Action(Action.ZOOMIN)]
|
2007-09-23 22:01:21 +00:00
|
|
|
public virtual void ZoomIn()
|
2007-06-26 06:01:52 +00:00
|
|
|
{
|
|
|
|
// Zoom
|
2007-10-20 19:50:03 +00:00
|
|
|
ZoomBy(1.3f);
|
2007-06-26 06:01:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// This zooms out
|
|
|
|
[Action(Action.ZOOMOUT)]
|
2007-09-23 22:01:21 +00:00
|
|
|
public virtual void ZoomOut()
|
2007-06-26 06:01:52 +00:00
|
|
|
{
|
|
|
|
// Zoom
|
2007-10-20 19:50:03 +00:00
|
|
|
ZoomBy(0.7f);
|
2007-06-26 06:01:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// This scrolls anywhere
|
|
|
|
private void ScrollBy(float deltax, float deltay)
|
|
|
|
{
|
|
|
|
// Scroll now
|
|
|
|
renderer.PositionView(renderer.OffsetX + deltax, renderer.OffsetY + deltay);
|
2007-10-05 10:00:15 +00:00
|
|
|
General.MainWindow.RedrawDisplay();
|
2007-07-07 09:40:34 +00:00
|
|
|
|
|
|
|
// Determine new unprojected mouse coordinates
|
|
|
|
mousemappos = renderer.GetMapCoordinates(mousepos);
|
|
|
|
General.MainWindow.UpdateCoordinates(mousemappos);
|
2007-06-26 06:01:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// This zooms
|
|
|
|
private void ZoomBy(float deltaz)
|
|
|
|
{
|
2007-07-07 09:40:34 +00:00
|
|
|
Vector2D zoompos, clientsize, diff;
|
|
|
|
float newscale;
|
|
|
|
|
|
|
|
// This will be the new zoom scale
|
|
|
|
newscale = renderer.Scale * deltaz;
|
|
|
|
|
2007-10-21 12:58:56 +00:00
|
|
|
// Limit scale
|
|
|
|
if(newscale > SCALE_MAX) newscale = SCALE_MAX;
|
|
|
|
if(newscale < SCALE_MIN) newscale = SCALE_MIN;
|
|
|
|
|
2007-07-07 09:40:34 +00:00
|
|
|
// Get the dimensions of the display
|
2007-09-24 19:54:47 +00:00
|
|
|
clientsize = new Vector2D(General.Map.Graphics.RenderTarget.ClientSize.Width,
|
|
|
|
General.Map.Graphics.RenderTarget.ClientSize.Height);
|
2007-07-07 09:40:34 +00:00
|
|
|
|
|
|
|
// When mouse is inside display
|
|
|
|
if(mouseinside)
|
|
|
|
{
|
|
|
|
// Zoom into or from mouse position
|
|
|
|
zoompos = (mousepos / clientsize) - new Vector2D(0.5f, 0.5f);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// Zoom into or from center
|
|
|
|
zoompos = new Vector2D(0f, 0f);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Calculate view position difference
|
|
|
|
diff = ((clientsize / newscale) - (clientsize / renderer.Scale)) * zoompos;
|
2007-09-24 19:54:47 +00:00
|
|
|
|
2007-06-26 06:01:52 +00:00
|
|
|
// Zoom now
|
2007-07-07 09:40:34 +00:00
|
|
|
renderer.PositionView(renderer.OffsetX - diff.x, renderer.OffsetY + diff.y);
|
|
|
|
renderer.ScaleView(newscale);
|
2007-10-20 13:06:05 +00:00
|
|
|
//General.Map.Map.Update();
|
2007-10-05 10:00:15 +00:00
|
|
|
General.MainWindow.RedrawDisplay();
|
2007-09-24 19:54:47 +00:00
|
|
|
|
2007-10-20 19:50:03 +00:00
|
|
|
// Give a new mousemove event to update coordinates
|
|
|
|
if(mouseinside) MouseMove(new MouseEventArgs(mousebuttons, 0, (int)mousepos.x, (int)mousepos.y, 0));
|
2007-09-24 19:54:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// This zooms to a specific level
|
|
|
|
public void SetZoom(float newscale)
|
|
|
|
{
|
|
|
|
// Zoom now
|
|
|
|
renderer.ScaleView(newscale);
|
2007-10-20 13:06:05 +00:00
|
|
|
//General.Map.Map.Update();
|
2007-10-05 10:00:15 +00:00
|
|
|
General.MainWindow.RedrawDisplay();
|
2007-07-07 09:40:34 +00:00
|
|
|
|
2007-10-20 19:50:03 +00:00
|
|
|
// Give a new mousemove event to update coordinates
|
|
|
|
if(mouseinside) MouseMove(new MouseEventArgs(mousebuttons, 0, (int)mousepos.x, (int)mousepos.y, 0));
|
2007-09-24 19:54:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// This zooms and scrolls to fit the map in the window
|
|
|
|
public void CenterInScreen()
|
|
|
|
{
|
|
|
|
float left = float.MaxValue;
|
|
|
|
float top = float.MaxValue;
|
|
|
|
float right = float.MinValue;
|
|
|
|
float bottom = float.MinValue;
|
|
|
|
float scalew, scaleh, scale;
|
|
|
|
float width, height;
|
|
|
|
|
|
|
|
// Go for all vertices
|
2007-10-05 11:17:58 +00:00
|
|
|
foreach(Vertex v in General.Map.Map.Vertices)
|
2007-09-24 19:54:47 +00:00
|
|
|
{
|
|
|
|
// Adjust boundaries by vertices
|
|
|
|
if(v.Position.x < left) left = v.Position.x;
|
|
|
|
if(v.Position.x > right) right = v.Position.x;
|
|
|
|
if(v.Position.y < top) top = v.Position.y;
|
|
|
|
if(v.Position.y > bottom) bottom = v.Position.y;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Calculate width/height
|
|
|
|
width = (right - left);
|
|
|
|
height = (bottom - top);
|
|
|
|
|
|
|
|
// Calculate scale to view map at
|
|
|
|
scalew = (float)General.Map.Graphics.RenderTarget.ClientSize.Width / (width * 1.1f);
|
|
|
|
scaleh = (float)General.Map.Graphics.RenderTarget.ClientSize.Height / (height * 1.1f);
|
|
|
|
if(scalew < scaleh) scale = scalew; else scale = scaleh;
|
|
|
|
|
|
|
|
// Change the view to see the whole map
|
|
|
|
renderer.ScaleView(scale);
|
|
|
|
renderer.PositionView(left + (right - left) * 0.5f, top + (bottom - top) * 0.5f);
|
2007-10-20 13:06:05 +00:00
|
|
|
//General.Map.Map.Update();
|
2007-10-05 10:00:15 +00:00
|
|
|
General.MainWindow.RedrawDisplay();
|
2007-10-20 19:50:03 +00:00
|
|
|
|
|
|
|
// Give a new mousemove event to update coordinates
|
|
|
|
if(mouseinside) MouseMove(new MouseEventArgs(mousebuttons, 0, (int)mousepos.x, (int)mousepos.y, 0));
|
2007-06-26 06:01:52 +00:00
|
|
|
}
|
|
|
|
|
2007-06-15 18:30:55 +00:00
|
|
|
#endregion
|
2007-07-07 09:40:34 +00:00
|
|
|
|
|
|
|
#region ================== Mouse input
|
|
|
|
|
|
|
|
// Mouse leaves the display
|
|
|
|
public override void MouseLeave(EventArgs e)
|
|
|
|
{
|
|
|
|
// Mouse is outside the display
|
|
|
|
mouseinside = false;
|
|
|
|
mousepos = new Vector2D(float.NaN, float.NaN);
|
|
|
|
mousemappos = mousepos;
|
2007-10-20 19:50:03 +00:00
|
|
|
mousebuttons = MouseButtons.None;
|
2007-07-07 09:40:34 +00:00
|
|
|
|
|
|
|
// Determine new unprojected mouse coordinates
|
|
|
|
General.MainWindow.UpdateCoordinates(mousemappos);
|
|
|
|
|
|
|
|
// Let the base class know
|
|
|
|
base.MouseLeave(e);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Mouse moved inside the display
|
|
|
|
public override void MouseMove(MouseEventArgs e)
|
|
|
|
{
|
|
|
|
// Record last position
|
|
|
|
mouseinside = true;
|
|
|
|
mousepos = new Vector2D(e.X, e.Y);
|
|
|
|
mousemappos = renderer.GetMapCoordinates(mousepos);
|
2007-10-20 19:50:03 +00:00
|
|
|
mousebuttons = e.Button;
|
2007-07-07 09:40:34 +00:00
|
|
|
|
|
|
|
// Update labels in main window
|
|
|
|
General.MainWindow.UpdateCoordinates(mousemappos);
|
|
|
|
|
|
|
|
// Let the base class know
|
|
|
|
base.MouseMove(e);
|
|
|
|
}
|
|
|
|
|
|
|
|
#endregion
|
2007-10-20 01:04:47 +00:00
|
|
|
|
|
|
|
#region ================== Display
|
|
|
|
|
|
|
|
// This just refreshes the display
|
|
|
|
public override void RefreshDisplay()
|
|
|
|
{
|
|
|
|
renderer.Present();
|
|
|
|
}
|
|
|
|
|
|
|
|
#endregion
|
2007-06-15 18:30:55 +00:00
|
|
|
}
|
|
|
|
}
|