Newer
Older
#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.Generic;
using System.Linq;
using System.Windows.Forms;
using CodeImp.DoomBuilder.Actions;
using CodeImp.DoomBuilder.BuilderModes.Interface;
using CodeImp.DoomBuilder.Data;
using CodeImp.DoomBuilder.Editing;
using CodeImp.DoomBuilder.Geometry;
using CodeImp.DoomBuilder.Map;
using CodeImp.DoomBuilder.Rendering;
using CodeImp.DoomBuilder.Windows;
#endregion
namespace CodeImp.DoomBuilder.BuilderModes
{
[EditMode(DisplayName = "Linedefs Mode",
SwitchAction = "linedefsmode", // Action name used to switch to this mode
ButtonImage = "LinesMode.png", // Image resource name for the button
ButtonOrder = int.MinValue + 100, // Position of the button (lower is more to the left)
ButtonGroup = "000_editing",
UseByDefault = true,
SafeStartMode = true)]
public class LinedefsMode : BaseClassicMode
{
#region ================== Constants
private const int MAX_LINEDEF_LABELS = 256; //mxd
#endregion
#region ================== Variables
// Highlighted item
private Linedef highlighted;
private Vector2D insertpreview = new Vector2D(float.NaN, float.NaN); //mxd
//mxd. Text labels
MaxED
committed
private Dictionary<Linedef, SelectionLabel> labels;
private Dictionary<Sector, TextLabel[]> sectorlabels;
private Dictionary<Sector, string[]> sectortexts;
// The blockmap makes is used to make finding lines faster
BlockMap<BlockEntry> blockmap;
// Stores sizes of the text for text labels so that they only have to be computed once
private Dictionary<string, float> textlabelsizecache;
// Linedefs that will be edited
ICollection<Linedef> editlines;
#endregion
#region ================== Properties
public override object HighlightedObject { get { return highlighted; } }
public override bool AlwaysShowVertices { get { return true; } }
#endregion
#region ================== Constructor / Disposer
public LinedefsMode()
{
//mxd. Associations now requre initializing...
textlabelsizecache = new Dictionary<string, float>();
}
//mxd
public override void Dispose()
{
// Not already disposed?
if(!isdisposed)
{
// Dispose old labels
MaxED
committed
if(labels != null) foreach(SelectionLabel l in labels.Values) l.Dispose();
if(sectorlabels != null)
{
foreach(TextLabel[] lbl in sectorlabels.Values)
foreach(TextLabel l in lbl) l.Dispose();
}
// Dispose base
base.Dispose();
}
}
#endregion
#region ================== Methods
// This highlights a new item
MaxED
committed
private void Highlight(Linedef l)
{
bool completeredraw = false;
// Often we can get away by simply undrawing the previous
// highlight and drawing the new highlight. But if associations
// are or were drawn we need to redraw the entire display.
if(highlighted != null)
{
//mxd. Update label color?
if(labels.ContainsKey(highlighted))
{
labels[highlighted].Color = General.Colors.Highlight;
completeredraw = true;
}
// Previous association highlights something?
}
// Set highlight association
if(l != null)
{
//mxd. Update label color?
if(labels.ContainsKey(l))
{
labels[l].Color = General.Colors.Selection;
completeredraw = true;
}
// New association highlights something?
// Only need a complete redraw if the association contains elements
if (!highlightasso.IsEmpty) completeredraw = true;
// Only need a complete redraw if the old association wasn't empty
if (!highlightasso.IsEmpty) completeredraw = true;
highlightasso.Clear();
// If we're changing associations, then we
// need to redraw the entire display
if(completeredraw)
{
// Set new highlight and redraw completely
highlighted = l;
General.Interface.RedrawDisplay();
}
else
{
// Update display
if(renderer.StartPlotter(false))
{
// Undraw previous highlight
Linedef possiblecommentline = l ?? highlighted; //mxd
if((highlighted != null) && !highlighted.IsDisposed)
{
renderer.PlotLinedef(highlighted, renderer.DetermineLinedefColor(highlighted));
renderer.PlotVertex(highlighted.Start, renderer.DetermineVertexColor(highlighted.Start));
renderer.PlotVertex(highlighted.End, renderer.DetermineVertexColor(highlighted.End));
}
// Set new highlight
highlighted = l;
// Render highlighted item
if((highlighted != null) && !highlighted.IsDisposed)
{
renderer.PlotLinedef(highlighted, General.Colors.Highlight);
renderer.PlotVertex(highlighted.Start, renderer.DetermineVertexColor(highlighted.Start));
renderer.PlotVertex(highlighted.End, renderer.DetermineVertexColor(highlighted.End));
}
Loading
Loading full blame...