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;
|
2008-05-29 11:54:45 +00:00
|
|
|
using CodeImp.DoomBuilder.Windows;
|
2007-06-15 18:30:55 +00:00
|
|
|
using CodeImp.DoomBuilder.IO;
|
|
|
|
using CodeImp.DoomBuilder.Map;
|
2007-06-15 22:38:42 +00:00
|
|
|
using CodeImp.DoomBuilder.Rendering;
|
2008-05-29 11:34:01 +00:00
|
|
|
using CodeImp.DoomBuilder.Actions;
|
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
|
|
|
|
{
|
2008-01-05 18:11:29 +00:00
|
|
|
/// <summary>
|
|
|
|
/// Provides specialized functionality for a classic (2D) Doom Builder editing mode.
|
|
|
|
/// </summary>
|
2007-10-24 17:25:03 +00:00
|
|
|
public 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;
|
2008-04-13 11:51:09 +00:00
|
|
|
private const float SELECTION_BORDER_SIZE = 2f;
|
|
|
|
private const int SELECTION_ALPHA = 200;
|
2007-10-21 12:58:56 +00:00
|
|
|
|
2007-06-15 18:30:55 +00:00
|
|
|
#endregion
|
|
|
|
|
|
|
|
#region ================== Variables
|
|
|
|
|
2007-11-10 01:58:08 +00:00
|
|
|
// Cancelled?
|
|
|
|
protected bool cancelled;
|
|
|
|
|
2007-06-15 22:38:42 +00:00
|
|
|
// Graphics
|
2008-01-02 21:49:43 +00:00
|
|
|
protected IRenderer2D renderer;
|
|
|
|
private Renderer2D renderer2d;
|
2007-06-15 22:38:42 +00:00
|
|
|
|
2007-07-07 09:40:34 +00:00
|
|
|
// Mouse status
|
|
|
|
protected Vector2D mousepos;
|
2008-10-28 12:04:28 +00:00
|
|
|
protected Vector2D mouselastpos;
|
2007-07-07 09:40:34 +00:00
|
|
|
protected Vector2D mousemappos;
|
2007-11-07 21:14:27 +00:00
|
|
|
protected Vector2D mousedownpos;
|
|
|
|
protected Vector2D mousedownmappos;
|
2007-10-20 19:50:03 +00:00
|
|
|
protected MouseButtons mousebuttons;
|
2007-07-07 09:40:34 +00:00
|
|
|
protected bool mouseinside;
|
2007-11-10 19:24:52 +00:00
|
|
|
protected MouseButtons mousedragging = MouseButtons.None;
|
2007-07-07 09:40:34 +00:00
|
|
|
|
2008-04-13 11:51:09 +00:00
|
|
|
// Selection
|
|
|
|
protected bool selecting;
|
|
|
|
private Vector2D selectstart;
|
|
|
|
protected RectangleF selectionrect;
|
2008-10-28 12:04:28 +00:00
|
|
|
|
|
|
|
// View panning
|
|
|
|
protected bool panning;
|
2008-04-13 11:51:09 +00:00
|
|
|
|
2007-06-15 18:30:55 +00:00
|
|
|
#endregion
|
|
|
|
|
|
|
|
#region ================== Properties
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
#region ================== Constructor / Disposer
|
|
|
|
|
2008-01-05 18:11:29 +00:00
|
|
|
/// <summary>
|
|
|
|
/// Provides specialized functionality for a classic (2D) Doom Builder editing mode.
|
|
|
|
/// </summary>
|
2007-10-20 01:04:47 +00:00
|
|
|
public ClassicMode()
|
2007-06-15 18:30:55 +00:00
|
|
|
{
|
|
|
|
// Initialize
|
2007-10-31 20:34:09 +00:00
|
|
|
this.renderer = General.Map.Renderer2D;
|
2008-01-02 21:49:43 +00:00
|
|
|
this.renderer2d = (Renderer2D)General.Map.Renderer2D;
|
2008-05-17 08:00:25 +00:00
|
|
|
|
|
|
|
// If the current mode is a ClassicMode, copy mouse properties
|
|
|
|
if(General.Map.Mode is ClassicMode)
|
|
|
|
{
|
|
|
|
ClassicMode oldmode = General.Map.Mode as ClassicMode;
|
|
|
|
|
|
|
|
// Copy mouse properties
|
|
|
|
mousepos = oldmode.mousepos;
|
|
|
|
mousemappos = oldmode.mousemappos;
|
|
|
|
mousedownpos = oldmode.mousedownpos;
|
|
|
|
mousedownmappos = oldmode.mousedownmappos;
|
|
|
|
mousebuttons = oldmode.mousebuttons;
|
|
|
|
mouseinside = oldmode.mouseinside;
|
|
|
|
mousedragging = oldmode.mousedragging;
|
|
|
|
}
|
2007-06-15 18:30:55 +00:00
|
|
|
}
|
|
|
|
|
2008-01-02 21:49:43 +00:00
|
|
|
// Disposer
|
2007-06-15 18:30:55 +00:00
|
|
|
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
|
2008-04-27 12:07:26 +00:00
|
|
|
[BeginAction("scrollnorth", BaseAction = true)]
|
2007-09-23 22:01:21 +00:00
|
|
|
public virtual void ScrollNorth()
|
2007-06-26 06:01:52 +00:00
|
|
|
{
|
|
|
|
// Scroll
|
2008-01-02 21:49:43 +00:00
|
|
|
ScrollBy(0f, 100f / renderer2d.Scale);
|
2007-06-26 06:01:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// This scrolls the view south
|
2008-04-27 12:07:26 +00:00
|
|
|
[BeginAction("scrollsouth", BaseAction = true)]
|
2007-09-23 22:01:21 +00:00
|
|
|
public virtual void ScrollSouth()
|
2007-06-26 06:01:52 +00:00
|
|
|
{
|
|
|
|
// Scroll
|
2008-01-02 21:49:43 +00:00
|
|
|
ScrollBy(0f, -100f / renderer2d.Scale);
|
2007-06-26 06:01:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// This scrolls the view west
|
2008-04-27 12:07:26 +00:00
|
|
|
[BeginAction("scrollwest", BaseAction = true)]
|
2007-09-23 22:01:21 +00:00
|
|
|
public virtual void ScrollWest()
|
2007-06-26 06:01:52 +00:00
|
|
|
{
|
|
|
|
// Scroll
|
2008-01-02 21:49:43 +00:00
|
|
|
ScrollBy(-100f / renderer2d.Scale, 0f);
|
2007-06-26 06:01:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// This scrolls the view east
|
2008-04-27 12:07:26 +00:00
|
|
|
[BeginAction("scrolleast", BaseAction = true)]
|
2007-09-23 22:01:21 +00:00
|
|
|
public virtual void ScrollEast()
|
2007-06-26 06:01:52 +00:00
|
|
|
{
|
|
|
|
// Scroll
|
2008-01-02 21:49:43 +00:00
|
|
|
ScrollBy(100f / renderer2d.Scale, 0f);
|
2007-06-26 06:01:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// This zooms in
|
2008-04-27 12:07:26 +00:00
|
|
|
[BeginAction("zoomin", BaseAction = true)]
|
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
|
2008-04-27 12:07:26 +00:00
|
|
|
[BeginAction("zoomout", BaseAction = true)]
|
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
|
2008-01-02 21:49:43 +00:00
|
|
|
renderer2d.PositionView(renderer2d.OffsetX + deltax, renderer2d.OffsetY + deltay);
|
2008-05-15 08:10:29 +00:00
|
|
|
this.OnViewChanged();
|
2007-11-15 23:38:09 +00:00
|
|
|
|
|
|
|
// Redraw
|
2007-10-05 10:00:15 +00:00
|
|
|
General.MainWindow.RedrawDisplay();
|
2007-07-07 09:40:34 +00:00
|
|
|
|
|
|
|
// Determine new unprojected mouse coordinates
|
2008-01-02 21:49:43 +00:00
|
|
|
mousemappos = renderer2d.GetMapCoordinates(mousepos);
|
2007-07-07 09:40:34 +00:00
|
|
|
General.MainWindow.UpdateCoordinates(mousemappos);
|
2007-06-26 06:01:52 +00:00
|
|
|
}
|
|
|
|
|
2008-10-28 12:04:28 +00:00
|
|
|
// This sets the view to be centered at x,y
|
|
|
|
private void ScrollTo(float x, float y)
|
|
|
|
{
|
|
|
|
// Scroll now
|
|
|
|
renderer2d.PositionView(x, y);
|
|
|
|
this.OnViewChanged();
|
|
|
|
|
|
|
|
// Redraw
|
|
|
|
General.MainWindow.RedrawDisplay();
|
|
|
|
|
|
|
|
// Determine new unprojected mouse coordinates
|
|
|
|
mousemappos = renderer2d.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
|
2008-01-02 21:49:43 +00:00
|
|
|
newscale = renderer2d.Scale * deltaz;
|
2007-07-07 09:40:34 +00:00
|
|
|
|
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
|
2008-01-02 21:49:43 +00:00
|
|
|
diff = ((clientsize / newscale) - (clientsize / renderer2d.Scale)) * zoompos;
|
2007-09-24 19:54:47 +00:00
|
|
|
|
2007-06-26 06:01:52 +00:00
|
|
|
// Zoom now
|
2008-01-02 21:49:43 +00:00
|
|
|
renderer2d.PositionView(renderer2d.OffsetX - diff.x, renderer2d.OffsetY + diff.y);
|
|
|
|
renderer2d.ScaleView(newscale);
|
2008-05-15 08:10:29 +00:00
|
|
|
this.OnViewChanged();
|
2007-11-15 23:38:09 +00:00
|
|
|
|
|
|
|
// Redraw
|
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
|
2008-05-15 08:10:29 +00:00
|
|
|
if(mouseinside) OnMouseMove(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
|
2008-01-02 21:49:43 +00:00
|
|
|
renderer2d.ScaleView(newscale);
|
2008-05-15 08:10:29 +00:00
|
|
|
this.OnViewChanged();
|
2007-11-15 23:38:09 +00:00
|
|
|
|
|
|
|
// Redraw
|
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
|
2008-05-15 08:10:29 +00:00
|
|
|
if(mouseinside) OnMouseMove(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
|
2008-04-27 12:07:26 +00:00
|
|
|
[BeginAction("centerinscreen", BaseAction = true)]
|
2007-09-24 19:54:47 +00:00
|
|
|
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
|
|
|
{
|
2007-12-01 01:32:56 +00:00
|
|
|
// Vertex used?
|
|
|
|
if(v.Linedefs.Count > 0)
|
|
|
|
{
|
|
|
|
// 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;
|
|
|
|
}
|
2007-09-24 19:54:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// 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
|
2008-01-02 21:49:43 +00:00
|
|
|
renderer2d.ScaleView(scale);
|
|
|
|
renderer2d.PositionView(left + (right - left) * 0.5f, top + (bottom - top) * 0.5f);
|
2008-05-15 08:10:29 +00:00
|
|
|
this.OnViewChanged();
|
2007-11-15 23:38:09 +00:00
|
|
|
|
|
|
|
// Redraw
|
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
|
2008-05-15 08:10:29 +00:00
|
|
|
if(mouseinside) OnMouseMove(new MouseEventArgs(mousebuttons, 0, (int)mousepos.x, (int)mousepos.y, 0));
|
2007-06-26 06:01:52 +00:00
|
|
|
}
|
2007-11-15 23:38:09 +00:00
|
|
|
|
2008-05-15 08:10:29 +00:00
|
|
|
/// <summary>
|
|
|
|
/// This is called when the view changes (scroll/zoom), before the display is redrawn.
|
|
|
|
/// </summary>
|
|
|
|
protected virtual void OnViewChanged()
|
2007-11-15 23:38:09 +00:00
|
|
|
{
|
|
|
|
}
|
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
|
|
|
|
2007-11-14 22:53:48 +00:00
|
|
|
#region ================== Input
|
2007-07-07 09:40:34 +00:00
|
|
|
|
|
|
|
// Mouse leaves the display
|
2008-05-15 08:10:29 +00:00
|
|
|
public override void OnMouseLeave(EventArgs e)
|
2007-07-07 09:40:34 +00:00
|
|
|
{
|
|
|
|
// 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
|
2008-05-15 08:10:29 +00:00
|
|
|
base.OnMouseLeave(e);
|
2007-07-07 09:40:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Mouse moved inside the display
|
2008-05-15 08:10:29 +00:00
|
|
|
public override void OnMouseMove(MouseEventArgs e)
|
2007-07-07 09:40:34 +00:00
|
|
|
{
|
2007-11-07 21:14:27 +00:00
|
|
|
Vector2D delta;
|
|
|
|
|
2007-07-07 09:40:34 +00:00
|
|
|
// Record last position
|
|
|
|
mouseinside = true;
|
2008-10-28 12:04:28 +00:00
|
|
|
mouselastpos = mousepos;
|
2007-07-07 09:40:34 +00:00
|
|
|
mousepos = new Vector2D(e.X, e.Y);
|
2008-01-02 21:49:43 +00:00
|
|
|
mousemappos = renderer2d.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);
|
|
|
|
|
2007-11-10 19:24:52 +00:00
|
|
|
// Holding a button?
|
2008-04-27 12:07:26 +00:00
|
|
|
if(e.Button != MouseButtons.None)
|
2007-11-07 21:14:27 +00:00
|
|
|
{
|
|
|
|
// Not dragging?
|
2007-11-10 19:24:52 +00:00
|
|
|
if(mousedragging == MouseButtons.None)
|
2007-11-07 21:14:27 +00:00
|
|
|
{
|
|
|
|
// Check if moved enough pixels for dragging
|
|
|
|
delta = mousedownpos - mousepos;
|
|
|
|
if((Math.Abs(delta.x) > DRAG_START_MOVE_PIXELS) ||
|
|
|
|
(Math.Abs(delta.y) > DRAG_START_MOVE_PIXELS))
|
|
|
|
{
|
|
|
|
// Dragging starts now
|
2007-11-10 19:24:52 +00:00
|
|
|
mousedragging = e.Button;
|
2008-05-15 08:10:29 +00:00
|
|
|
OnDragStart(e);
|
2007-11-07 21:14:27 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-04-13 11:51:09 +00:00
|
|
|
// Selecting?
|
2008-05-15 08:10:29 +00:00
|
|
|
if(selecting) OnUpdateMultiSelection();
|
2008-10-28 12:04:28 +00:00
|
|
|
|
|
|
|
// Panning?
|
|
|
|
if (panning) OnUpdateViewPanning();
|
2008-04-13 11:51:09 +00:00
|
|
|
|
2007-07-07 09:40:34 +00:00
|
|
|
// Let the base class know
|
2008-05-15 08:10:29 +00:00
|
|
|
base.OnMouseMove(e);
|
2007-07-07 09:40:34 +00:00
|
|
|
}
|
|
|
|
|
2007-11-07 21:14:27 +00:00
|
|
|
// Mouse button pressed
|
2008-05-15 08:10:29 +00:00
|
|
|
public override void OnMouseDown(MouseEventArgs e)
|
2007-11-07 21:14:27 +00:00
|
|
|
{
|
|
|
|
// Save mouse down position
|
|
|
|
mousedownpos = mousepos;
|
|
|
|
mousedownmappos = mousemappos;
|
|
|
|
|
|
|
|
// Let the base class know
|
2008-05-15 08:10:29 +00:00
|
|
|
base.OnMouseDown(e);
|
2007-11-07 21:14:27 +00:00
|
|
|
}
|
|
|
|
|
2007-11-10 19:24:52 +00:00
|
|
|
// Mouse button released
|
2008-05-15 08:10:29 +00:00
|
|
|
public override void OnMouseUp(MouseEventArgs e)
|
2007-11-10 19:24:52 +00:00
|
|
|
{
|
|
|
|
// Releasing drag button?
|
|
|
|
if(e.Button == mousedragging)
|
|
|
|
{
|
|
|
|
// No longer dragging
|
2008-05-15 08:10:29 +00:00
|
|
|
OnDragStop(e);
|
2007-12-26 00:31:32 +00:00
|
|
|
mousedragging = MouseButtons.None;
|
2007-11-10 19:24:52 +00:00
|
|
|
}
|
2008-04-13 11:51:09 +00:00
|
|
|
|
2007-11-10 19:24:52 +00:00
|
|
|
// Let the base class know
|
2008-05-15 08:10:29 +00:00
|
|
|
base.OnMouseUp(e);
|
2007-11-10 19:24:52 +00:00
|
|
|
}
|
2008-04-27 12:07:26 +00:00
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Automatically called when dragging operation starts.
|
|
|
|
/// </summary>
|
2008-05-15 08:10:29 +00:00
|
|
|
protected virtual void OnDragStart(MouseEventArgs e)
|
2007-11-07 21:14:27 +00:00
|
|
|
{
|
2007-11-10 19:24:52 +00:00
|
|
|
}
|
|
|
|
|
2008-04-27 12:07:26 +00:00
|
|
|
/// <summary>
|
|
|
|
/// Automatically called when dragging operation stops.
|
|
|
|
/// </summary>
|
2008-05-15 08:10:29 +00:00
|
|
|
protected virtual void OnDragStop(MouseEventArgs e)
|
2007-11-10 19:24:52 +00:00
|
|
|
{
|
2007-11-07 21:14:27 +00:00
|
|
|
}
|
|
|
|
|
2007-07-07 09:40:34 +00:00
|
|
|
#endregion
|
2007-10-20 01:04:47 +00:00
|
|
|
|
|
|
|
#region ================== Display
|
|
|
|
|
|
|
|
// This just refreshes the display
|
2008-05-18 07:31:33 +00:00
|
|
|
public override void OnPresentDisplay()
|
2007-10-20 01:04:47 +00:00
|
|
|
{
|
2008-01-02 21:49:43 +00:00
|
|
|
renderer2d.Present();
|
2007-10-20 01:04:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#endregion
|
2007-11-07 21:14:27 +00:00
|
|
|
|
|
|
|
#region ================== Methods
|
|
|
|
|
2008-04-27 12:07:26 +00:00
|
|
|
/// <summary>
|
|
|
|
/// Automatically called by the core when this editing mode is engaged.
|
|
|
|
/// </summary>
|
2008-05-15 08:10:29 +00:00
|
|
|
public override void OnEngage()
|
2008-04-27 12:07:26 +00:00
|
|
|
{
|
|
|
|
// Clear display overlay
|
|
|
|
renderer.StartOverlay(true);
|
|
|
|
renderer.Finish();
|
2008-05-15 08:10:29 +00:00
|
|
|
base.OnEngage();
|
2008-04-27 12:07:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Called when the user requests to cancel this editing mode.
|
|
|
|
/// </summary>
|
2008-05-15 08:10:29 +00:00
|
|
|
public override void OnCancel()
|
2007-11-07 21:14:27 +00:00
|
|
|
{
|
2007-11-10 01:58:08 +00:00
|
|
|
cancelled = true;
|
2008-05-15 08:10:29 +00:00
|
|
|
base.OnCancel();
|
2007-11-07 21:14:27 +00:00
|
|
|
}
|
2008-04-27 12:07:26 +00:00
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// This is called automatically when the Edit button is pressed.
|
|
|
|
/// (in Doom Builder 1, this was always the right mousebutton)
|
|
|
|
/// </summary>
|
|
|
|
[BeginAction("classicedit", BaseAction = true)]
|
2008-10-08 14:19:09 +00:00
|
|
|
protected virtual void OnEditBegin()
|
2008-04-27 12:07:26 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// This is called automatically when the Edit button is released.
|
|
|
|
/// (in Doom Builder 1, this was always the right mousebutton)
|
|
|
|
/// </summary>
|
|
|
|
[EndAction("classicedit", BaseAction = true)]
|
2008-10-08 14:24:21 +00:00
|
|
|
protected virtual void OnEditEnd()
|
2008-04-27 12:07:26 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// This is called automatically when the Select button is pressed.
|
|
|
|
/// (in Doom Builder 1, this was always the left mousebutton)
|
|
|
|
/// </summary>
|
|
|
|
[BeginAction("classicselect", BaseAction = true)]
|
2008-10-08 14:19:09 +00:00
|
|
|
protected virtual void OnSelectBegin()
|
2008-04-27 12:07:26 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// This is called automatically when the Select button is released.
|
|
|
|
/// (in Doom Builder 1, this was always the left mousebutton)
|
|
|
|
/// </summary>
|
|
|
|
[EndAction("classicselect", BaseAction = true)]
|
2008-10-08 14:24:21 +00:00
|
|
|
protected virtual void OnSelectEnd()
|
2008-04-27 12:07:26 +00:00
|
|
|
{
|
2008-05-15 08:10:29 +00:00
|
|
|
if(selecting) OnEndMultiSelection();
|
2008-04-27 12:07:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// This is called automatically when a rectangular multi-selection ends.
|
|
|
|
/// </summary>
|
2008-05-15 08:10:29 +00:00
|
|
|
protected virtual void OnEndMultiSelection()
|
2008-04-27 12:07:26 +00:00
|
|
|
{
|
|
|
|
selecting = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Call this to initiate a rectangular multi-selection.
|
|
|
|
/// </summary>
|
|
|
|
protected virtual void StartMultiSelection()
|
2008-04-13 11:51:09 +00:00
|
|
|
{
|
|
|
|
selecting = true;
|
|
|
|
selectstart = mousemappos;
|
|
|
|
selectionrect = new RectangleF(selectstart.x, selectstart.y, 0, 0);
|
|
|
|
}
|
2008-04-27 12:07:26 +00:00
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// This is called automatically when a multi-selection is updated.
|
|
|
|
/// </summary>
|
2008-05-15 08:10:29 +00:00
|
|
|
protected virtual void OnUpdateMultiSelection()
|
2008-04-13 11:51:09 +00:00
|
|
|
{
|
|
|
|
selectionrect.X = selectstart.x;
|
|
|
|
selectionrect.Y = selectstart.y;
|
|
|
|
selectionrect.Width = mousemappos.x - selectstart.x;
|
|
|
|
selectionrect.Height = mousemappos.y - selectstart.y;
|
|
|
|
|
|
|
|
if(selectionrect.Width < 0f)
|
|
|
|
{
|
|
|
|
selectionrect.Width = -selectionrect.Width;
|
|
|
|
selectionrect.X -= selectionrect.Width;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(selectionrect.Height < 0f)
|
|
|
|
{
|
|
|
|
selectionrect.Height = -selectionrect.Height;
|
|
|
|
selectionrect.Y -= selectionrect.Height;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-04-27 12:07:26 +00:00
|
|
|
/// <summary>
|
|
|
|
/// Call this to draw the selection on the overlay layer.
|
|
|
|
/// Must call renderer.StartOverlay first!
|
|
|
|
/// </summary>
|
|
|
|
protected virtual void RenderMultiSelection()
|
2008-04-13 11:51:09 +00:00
|
|
|
{
|
|
|
|
renderer.RenderRectangle(selectionrect, SELECTION_BORDER_SIZE,
|
|
|
|
General.Colors.Highlight.WithAlpha(SELECTION_ALPHA), true);
|
|
|
|
}
|
2008-10-28 12:04:28 +00:00
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// This is called automatically when the mouse is moved while panning
|
|
|
|
/// </summary>
|
|
|
|
protected virtual void OnUpdateViewPanning()
|
|
|
|
{
|
2008-10-28 13:40:09 +00:00
|
|
|
// We can only drag the map when the mouse pointer is inside
|
|
|
|
// otherwise we don't have coordinates where to drag the map to
|
|
|
|
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);
|
|
|
|
|
|
|
|
// Do the scroll
|
|
|
|
ScrollBy(lastmappos.x - mousemappos.x, lastmappos.y - mousemappos.y);
|
|
|
|
}
|
2008-10-28 12:04:28 +00:00
|
|
|
}
|
2008-04-13 11:51:09 +00:00
|
|
|
|
2007-11-07 21:14:27 +00:00
|
|
|
#endregion
|
2008-05-16 21:48:23 +00:00
|
|
|
|
|
|
|
#region ================== Actions
|
|
|
|
|
2008-10-28 12:04:28 +00:00
|
|
|
[BeginAction("pan_view", BaseAction = true)]
|
|
|
|
protected virtual void BeginViewPan()
|
|
|
|
{
|
|
|
|
panning = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
[EndAction("pan_view", BaseAction = true)]
|
|
|
|
protected virtual void EndViewPan()
|
|
|
|
{
|
|
|
|
panning = false;
|
|
|
|
}
|
|
|
|
|
2008-05-16 21:48:23 +00:00
|
|
|
#endregion
|
2007-06-15 18:30:55 +00:00
|
|
|
}
|
|
|
|
}
|