added grid controls

This commit is contained in:
codeimp 2008-06-10 08:35:14 +00:00
parent 8e47c9939e
commit 66052a82f7
7 changed files with 146 additions and 23 deletions

View file

@ -1,5 +1,3 @@
- Controls to increase/decrease grid size
- "Insert Thing" control
- Make "Make Sector" mode

View file

@ -61,6 +61,9 @@ namespace CodeImp.DoomBuilder.Editing
private ImageData backimage = new NullImage();
private int backoffsetx, backoffsety;
// Disposing
private bool isdisposed;
#endregion
#region ================== Properties
@ -72,7 +75,8 @@ namespace CodeImp.DoomBuilder.Editing
internal ImageData Background { get { return backimage; } }
internal int BackgroundX { get { return backoffsetx; } }
internal int BackgroundY { get { return backoffsety; } }
internal bool Disposed { get { return isdisposed; } }
#endregion
#region ================== Constructor / Disposer
@ -82,11 +86,30 @@ namespace CodeImp.DoomBuilder.Editing
{
// Initialize
SetGridSize(DEFAULT_GRID_SIZE);
// Register actions
General.Actions.BindMethods(this);
// We have no destructor
GC.SuppressFinalize(this);
}
// Disposer
internal void Dispose()
{
if(!isdisposed)
{
// Clean up
backimage = null;
// Unregister actions
General.Actions.UnbindMethods(this);
// Done
isdisposed = true;
}
}
#endregion
#region ================== Methods
@ -170,5 +193,55 @@ namespace CodeImp.DoomBuilder.Editing
}
#endregion
#region ================== Actions
// This shows the grid setup dialog
[BeginAction("gridsetup")]
internal void ShowGridSetup()
{
// Show preferences dialog
GridSetupForm gridform = new GridSetupForm();
if(gridform.ShowDialog(General.MainWindow) == DialogResult.OK)
{
// Redraw display
General.MainWindow.RedrawDisplay();
}
// Done
gridform.Dispose();
}
// This changes grid size
[BeginAction("gridinc")]
internal void IncreaseGrid()
{
// Not lower than 2
if(gridsize >= 4)
{
// Change grid
SetGridSize(gridsize >> 1);
// Redraw display
General.MainWindow.RedrawDisplay();
}
}
// This changes grid size
[BeginAction("griddec")]
internal void DecreaseGrid()
{
// Not higher than 1024
if(gridsize <= 512)
{
// Change grid
SetGridSize(gridsize << 1);
// Redraw display
General.MainWindow.RedrawDisplay();
}
}
#endregion
}
}

View file

@ -149,6 +149,7 @@ namespace CodeImp.DoomBuilder
General.Actions.UnbindMethods(this);
// Dispose
if(grid != null) grid.Dispose();
if(launcher != null) launcher.Dispose();
if(undoredo != null) undoredo.Dispose();
General.WriteLogLine("Unloading data resources...");

View file

@ -118,6 +118,7 @@ namespace CodeImp.DoomBuilder.Rendering
private float translatey;
private float linenormalsize;
private float lastgridscale = -1f;
private int lastgridsize;
private float lastgridx;
private float lastgridy;
@ -366,6 +367,7 @@ namespace CodeImp.DoomBuilder.Rendering
numthings = 0;
maxthings = 0;
lastgridscale = -1f;
lastgridsize = 0;
// Trash font
if(font != null) font.Dispose();
@ -748,7 +750,8 @@ namespace CodeImp.DoomBuilder.Rendering
DataRectangle lockedrect;
// Do we need to redraw grid?
if((lastgridscale != scale) || (lastgridx != offsetx) || (lastgridy != offsety))
if((lastgridsize != General.Map.Grid.GridSize) || (lastgridscale != scale) ||
(lastgridx != offsetx) || (lastgridy != offsety))
{
// Lock background rendertarget memory
lockedrect = backtex.LockRectangle(0, LockFlags.NoSystemLock);
@ -767,6 +770,7 @@ namespace CodeImp.DoomBuilder.Rendering
backtex.UnlockRectangle(0);
lockedrect.Data.Dispose();
lastgridscale = scale;
lastgridsize = General.Map.Grid.GridSize;
lastgridx = offsetx;
lastgridy = offsety;
}

View file

@ -244,13 +244,32 @@ deleteitem
gridsetup
{
title = "View: Grid Setup";
title = "Edit: Grid Setup";
description = "Shows the Custom Grid Setup dialog which allows you to set custom grid sizes and a background image.";
allowkeys = true;
allowmouse = true;
allowscroll = true;
}
griddec
{
title = "Edit: Grid Decrease";
description = "Decreases the grid density.";
unbind = 1;
mousebuttons = 0;
mousescroll = 1;
}
gridinc
{
title = "Edit: Grid Increase";
description = "Increases the grid density.";
unbind = 1;
mousebuttons = 0;
mousescroll = 1;
}
undo
{
title = "Edit: Undo";

View file

@ -63,6 +63,10 @@ namespace CodeImp.DoomBuilder.Windows
this.itemredo = new System.Windows.Forms.ToolStripMenuItem();
this.itemsnaptogrid = new System.Windows.Forms.ToolStripMenuItem();
this.itemautomerge = new System.Windows.Forms.ToolStripMenuItem();
this.toolStripMenuItem6 = new System.Windows.Forms.ToolStripSeparator();
this.itemgridinc = new System.Windows.Forms.ToolStripMenuItem();
this.itemgriddec = new System.Windows.Forms.ToolStripMenuItem();
this.itemgridsetup = new System.Windows.Forms.ToolStripMenuItem();
this.itemmapoptions = new System.Windows.Forms.ToolStripMenuItem();
this.menutools = new System.Windows.Forms.ToolStripMenuItem();
this.itemreloadresources = new System.Windows.Forms.ToolStripMenuItem();
@ -346,6 +350,10 @@ namespace CodeImp.DoomBuilder.Windows
this.itemeditmodesseperator,
this.itemsnaptogrid,
this.itemautomerge,
this.toolStripMenuItem6,
this.itemgridinc,
this.itemgriddec,
this.itemgridsetup,
toolStripSeparator11,
this.itemmapoptions});
this.menuedit.Name = "menuedit";
@ -392,6 +400,36 @@ namespace CodeImp.DoomBuilder.Windows
this.itemautomerge.Text = "Merge Geometry";
this.itemautomerge.Click += new System.EventHandler(this.InvokeTaggedAction);
//
// toolStripMenuItem6
//
this.toolStripMenuItem6.Name = "toolStripMenuItem6";
this.toolStripMenuItem6.Size = new System.Drawing.Size(162, 6);
//
// itemgridinc
//
this.itemgridinc.Name = "itemgridinc";
this.itemgridinc.Size = new System.Drawing.Size(165, 22);
this.itemgridinc.Tag = "builder_gridinc";
this.itemgridinc.Text = "Increase Grid";
this.itemgridinc.Click += new System.EventHandler(this.InvokeTaggedAction);
//
// itemgriddec
//
this.itemgriddec.Name = "itemgriddec";
this.itemgriddec.Size = new System.Drawing.Size(165, 22);
this.itemgriddec.Tag = "builder_griddec";
this.itemgriddec.Text = "Decrease Grid";
this.itemgriddec.Click += new System.EventHandler(this.InvokeTaggedAction);
//
// itemgridsetup
//
this.itemgridsetup.Image = global::CodeImp.DoomBuilder.Properties.Resources.Grid2;
this.itemgridsetup.Name = "itemgridsetup";
this.itemgridsetup.Size = new System.Drawing.Size(165, 22);
this.itemgridsetup.Tag = "builder_gridsetup";
this.itemgridsetup.Text = "Grid Setup...";
this.itemgridsetup.Click += new System.EventHandler(this.InvokeTaggedAction);
//
// itemmapoptions
//
this.itemmapoptions.Image = global::CodeImp.DoomBuilder.Properties.Resources.Properties;
@ -1070,5 +1108,9 @@ namespace CodeImp.DoomBuilder.Windows
private System.Windows.Forms.ToolStripSeparator toolStripMenuItem5;
private System.Windows.Forms.ToolStripMenuItem itemtestmap;
private System.Windows.Forms.ToolStripSeparator toolStripSeparator6;
private System.Windows.Forms.ToolStripSeparator toolStripMenuItem6;
private System.Windows.Forms.ToolStripMenuItem itemgridinc;
private System.Windows.Forms.ToolStripMenuItem itemgriddec;
private System.Windows.Forms.ToolStripMenuItem itemgridsetup;
}
}

View file

@ -505,26 +505,9 @@ namespace CodeImp.DoomBuilder.Windows
// Show grid setup
private void itemgridcustom_Click(object sender, EventArgs e)
{
ShowGridSetup();
}
// This shows the grid setup dialog
[BeginAction("gridsetup")]
internal void ShowGridSetup()
{
// Only when a map is open
if(General.Map == null) return;
// Show preferences dialog
GridSetupForm gridform = new GridSetupForm();
if(gridform.ShowDialog(this) == DialogResult.OK)
{
// Redraw display
RedrawDisplay();
}
// Done
gridform.Dispose();
General.Map.Grid.ShowGridSetup();
}
#endregion
@ -1363,6 +1346,9 @@ namespace CodeImp.DoomBuilder.Windows
itemmapoptions.Enabled = (General.Map != null);
itemsnaptogrid.Enabled = (General.Map != null);
itemautomerge.Enabled = (General.Map != null);
itemgridsetup.Enabled = (General.Map != null);
itemgridinc.Enabled = (General.Map != null);
itemgriddec.Enabled = (General.Map != null);
// Determine undo description
if(itemundo.Enabled)