diff --git a/Source/Plugins/BuilderModes/ClassicModes/DrawGridMode.cs b/Source/Plugins/BuilderModes/ClassicModes/DrawGridMode.cs index 1e114a7f..369e96eb 100644 --- a/Source/Plugins/BuilderModes/ClassicModes/DrawGridMode.cs +++ b/Source/Plugins/BuilderModes/ClassicModes/DrawGridMode.cs @@ -28,13 +28,17 @@ namespace CodeImp.DoomBuilder.BuilderModes private static int horizontalSlices = 3; private static int verticalSlices = 3; - private bool triangulate = true; + private static bool triangulate; + private static bool gridlock; private List gridpoints; private HintLabel hintLabel; private int width; private int height; + private int slicesH; + private int slicesV; + private int initialGridSize; private Vector2D start; private Vector2D end; @@ -52,6 +56,7 @@ namespace CodeImp.DoomBuilder.BuilderModes //Options docker panel = new DrawGridOptionsPanel(); panel.OnValueChanged += OptionsPanelOnValueChanged; + panel.OnGridLockChanged += OptionsPanelOnOnGridLockChanged; settingsdocker = new Docker("drawgrid", "Draw Grid Settings", panel); } @@ -63,8 +68,11 @@ namespace CodeImp.DoomBuilder.BuilderModes base.OnEngage(); General.Interface.AddDocker(settingsdocker); General.Interface.SelectDocker(settingsdocker); + initialGridSize = General.Map.Grid.GridSize; + //setup settings panel panel.Triangulate = triangulate; + panel.LockToGrid = gridlock; panel.HorizontalSlices = horizontalSlices - 1; panel.VerticalSlices = verticalSlices - 1; } @@ -138,6 +146,11 @@ namespace CodeImp.DoomBuilder.BuilderModes Update(); } + private void OptionsPanelOnOnGridLockChanged(object sender, EventArgs eventArgs) { + gridlock = panel.LockToGrid; + Update(); + } + #endregion #region ================== Methods @@ -181,11 +194,11 @@ namespace CodeImp.DoomBuilder.BuilderModes //render hint if (horizontalSlices > 1 || verticalSlices > 1) { - if(width > 64 * vsize && height > 16 * vsize) { + hintLabel.Text = "H: " + (slicesH - 1) + "; V: " + (slicesV - 1); + if(width > hintLabel.Text.Length * vsize && height > 16 * vsize) { float vPos = start.y + height / 2.0f; hintLabel.Start = new Vector2D(start.x, vPos); hintLabel.End = new Vector2D(end.x, vPos); - hintLabel.Text = "H: " + (horizontalSlices - 1) + "; V: " + (verticalSlices - 1); renderer.RenderText(hintLabel.TextLabel); } } @@ -253,35 +266,48 @@ namespace CodeImp.DoomBuilder.BuilderModes if (e.x == s.x || e.y == s.y) return new List{ new[] {s, e} }; //rectangles - float rectWidth = Math.Max(1, (horizontalSlices > 0 ? (float)width / horizontalSlices : width)); - float rectHeight = Math.Max(1, (verticalSlices > 0 ? (float)height / verticalSlices : height)); + if(gridlock) { + //rendering will be screwed if start point is not aligned to current grid size + if (General.Map.Grid.GridSize > initialGridSize && General.Map.Grid.SnappedToGrid(start) == start) { + initialGridSize = General.Map.Grid.GridSize; + } + + int gs = (General.Map.Grid.GridSize > initialGridSize && General.Map.Grid.SnappedToGrid(start) != start ? initialGridSize : General.Map.Grid.GridSize); + slicesH = width / gs; + slicesV = height / gs; + } else { + slicesH = horizontalSlices; + slicesV = verticalSlices; + } + + float rectWidth = Math.Max(1, (slicesH > 0 ? (float)width / slicesH : width)); + float rectHeight = Math.Max(1, (slicesV > 0 ? (float)height / slicesV : height)); //create shape List rect = new List { s, new Vector2D((int)e.x, (int)s.y), e, new Vector2D((int)s.x, (int)e.y), s }; - if(horizontalSlices == 1 && verticalSlices == 1) { + if(!gridlock && slicesH == 1 && slicesV == 1) { if(triangulate) rect.AddRange(new[] { s, e }); return new List{ rect.ToArray() }; } //create blocks - List shapes = new List() { rect.ToArray() }; - RectangleF[,] blocks = new RectangleF[horizontalSlices, verticalSlices]; - - for(int w = 0; w < horizontalSlices; w++) { - for(int h = 0; h < verticalSlices; h++) { + List shapes = new List { rect.ToArray() }; + RectangleF[,] blocks = new RectangleF[slicesH, slicesV]; + for(int w = 0; w < slicesH; w++) { + for(int h = 0; h < slicesV; h++) { blocks[w, h] = RectangleF.FromLTRB((int)Math.Round(s.x + rectWidth * w), (int)Math.Round(s.y + rectHeight * h), (int)Math.Round(s.x + rectWidth * (w + 1)), (int)Math.Round(s.y + rectHeight * (h + 1))); } } //add subdivisions - if (horizontalSlices > 1) { - for (int w = 1; w < horizontalSlices; w++) { + if(slicesH > 1) { + for(int w = 1; w < slicesH; w++) { int px = (int) Math.Round(blocks[w, 0].X); shapes.Add(new[] {new Vector2D(px, s.y), new Vector2D(px, e.y)}); } } - if (verticalSlices > 1) { - for (int h = 1; h < verticalSlices; h++) { + if(slicesV > 1) { + for(int h = 1; h < slicesV; h++) { int py = (int) Math.Round(blocks[0, h].Y); shapes.Add(new[] { new Vector2D(s.x, py), new Vector2D(e.x, py) }); } @@ -292,8 +318,8 @@ namespace CodeImp.DoomBuilder.BuilderModes bool startflip = false; bool flip = false; - for (int w = 0; w < horizontalSlices; w++) { - for (int h = 0; h < verticalSlices; h++) { + for(int w = 0; w < slicesH; w++) { + for(int h = 0; h < slicesV; h++) { if (flip) { shapes.Add(new[] { new Vector2D(blocks[w, h].X, blocks[w, h].Y), new Vector2D(blocks[w, h].Right, blocks[w, h].Bottom) }); } else { @@ -313,6 +339,8 @@ namespace CodeImp.DoomBuilder.BuilderModes //update top-left and bottom-right points, which define drawing shape private void updateReferencePoints(DrawnVertex p1, DrawnVertex p2) { + if(!p1.pos.IsFinite() || !p2.pos.IsFinite()) return; + if(p1.pos.x < p2.pos.x) { start.x = p1.pos.x; end.x = p2.pos.x; @@ -339,7 +367,7 @@ namespace CodeImp.DoomBuilder.BuilderModes [BeginAction("increasebevel")] protected void increaseBevel() { - if(points.Count < 2 || horizontalSlices < width - 2) { + if(!gridlock && (points.Count < 2 || horizontalSlices < width - 2)) { horizontalSlices++; panel.HorizontalSlices = horizontalSlices - 1; Update(); @@ -348,7 +376,7 @@ namespace CodeImp.DoomBuilder.BuilderModes [BeginAction("decreasebevel")] protected void decreaseBevel() { - if(horizontalSlices > 1) { + if(!gridlock && horizontalSlices > 1) { horizontalSlices--; panel.HorizontalSlices = horizontalSlices - 1; Update(); @@ -357,7 +385,7 @@ namespace CodeImp.DoomBuilder.BuilderModes [BeginAction("increasesubdivlevel")] protected void increaseSubdivLevel() { - if(points.Count < 2 || verticalSlices < height - 2) { + if(!gridlock && (points.Count < 2 || verticalSlices < height - 2)) { verticalSlices++; panel.VerticalSlices = verticalSlices - 1; Update(); @@ -366,7 +394,7 @@ namespace CodeImp.DoomBuilder.BuilderModes [BeginAction("decreasesubdivlevel")] protected void decreaseSubdivLevel() { - if(verticalSlices > 1) { + if(!gridlock && verticalSlices > 1) { verticalSlices--; panel.VerticalSlices = verticalSlices - 1; Update(); diff --git a/Source/Plugins/BuilderModes/ClassicModes/DrawRectangleMode.cs b/Source/Plugins/BuilderModes/ClassicModes/DrawRectangleMode.cs index 67df3266..e7018034 100644 --- a/Source/Plugins/BuilderModes/ClassicModes/DrawRectangleMode.cs +++ b/Source/Plugins/BuilderModes/ClassicModes/DrawRectangleMode.cs @@ -234,6 +234,8 @@ namespace CodeImp.DoomBuilder.BuilderModes //update top-left and bottom-right points, which define drawing shape protected void updateReferencePoints(DrawnVertex p1, DrawnVertex p2) { + if(!p1.pos.IsFinite() || !p2.pos.IsFinite()) return; + if (p1.pos.x < p2.pos.x) { start.x = p1.pos.x; end.x = p2.pos.x; diff --git a/Source/Plugins/BuilderModes/General/HintLabel.cs b/Source/Plugins/BuilderModes/General/HintLabel.cs index d2f465f4..c127ad64 100644 --- a/Source/Plugins/BuilderModes/General/HintLabel.cs +++ b/Source/Plugins/BuilderModes/General/HintLabel.cs @@ -1,5 +1,4 @@ -using System; -using System.Drawing; +using System.Drawing; using CodeImp.DoomBuilder.Geometry; namespace CodeImp.DoomBuilder.BuilderModes @@ -7,15 +6,7 @@ namespace CodeImp.DoomBuilder.BuilderModes public class HintLabel : LineLengthLabel { private string text = ""; - public string Text { - get { - return text; - } - set { - text = value; - Update(); - } - } + public string Text { get { return text; } set { text = value; Update(); } } public HintLabel() : base(false) { label.Color = General.Colors.InfoLine; diff --git a/Source/Plugins/BuilderModes/General/LineLengthLabel.cs b/Source/Plugins/BuilderModes/General/LineLengthLabel.cs index 296b6b03..1344621d 100644 --- a/Source/Plugins/BuilderModes/General/LineLengthLabel.cs +++ b/Source/Plugins/BuilderModes/General/LineLengthLabel.cs @@ -100,7 +100,7 @@ namespace CodeImp.DoomBuilder.BuilderModes //mxd if(showAngle) { - int angle = (int)Math.Round(Angle2D.RadToDeg(delta.GetAngle()));// * 180 / Math.PI); + int angle = (int)Math.Round(Angle2D.RadToDeg(delta.GetAngle())); label.Text = "l:" + length.ToString(VALUE_FORMAT) + "; a:" + angle; } else { label.Text = length.ToString(VALUE_FORMAT); diff --git a/Source/Plugins/BuilderModes/Interface/DrawGridOptionsPanel.Designer.cs b/Source/Plugins/BuilderModes/Interface/DrawGridOptionsPanel.Designer.cs index 17992290..c9b19c78 100644 --- a/Source/Plugins/BuilderModes/Interface/DrawGridOptionsPanel.Designer.cs +++ b/Source/Plugins/BuilderModes/Interface/DrawGridOptionsPanel.Designer.cs @@ -33,6 +33,7 @@ this.triangulate = new System.Windows.Forms.CheckBox(); this.groupBox2 = new System.Windows.Forms.GroupBox(); this.hints = new System.Windows.Forms.RichTextBox(); + this.gridlock = new System.Windows.Forms.CheckBox(); this.groupBox1.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)(this.slicesV)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.slicesH)).BeginInit(); @@ -43,6 +44,7 @@ // this.groupBox1.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) | System.Windows.Forms.AnchorStyles.Right))); + this.groupBox1.Controls.Add(this.gridlock); this.groupBox1.Controls.Add(this.slicesV); this.groupBox1.Controls.Add(this.slicesH); this.groupBox1.Controls.Add(this.label2); @@ -50,7 +52,7 @@ this.groupBox1.Controls.Add(this.triangulate); this.groupBox1.Location = new System.Drawing.Point(3, 3); this.groupBox1.Name = "groupBox1"; - this.groupBox1.Size = new System.Drawing.Size(243, 106); + this.groupBox1.Size = new System.Drawing.Size(243, 125); this.groupBox1.TabIndex = 1; this.groupBox1.TabStop = false; this.groupBox1.Text = "Draw Options:"; @@ -102,7 +104,7 @@ // triangulate // this.triangulate.AutoSize = true; - this.triangulate.Location = new System.Drawing.Point(9, 78); + this.triangulate.Location = new System.Drawing.Point(9, 101); this.triangulate.Name = "triangulate"; this.triangulate.Size = new System.Drawing.Size(79, 18); this.triangulate.TabIndex = 0; @@ -115,7 +117,7 @@ this.groupBox2.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) | System.Windows.Forms.AnchorStyles.Right))); this.groupBox2.Controls.Add(this.hints); - this.groupBox2.Location = new System.Drawing.Point(3, 115); + this.groupBox2.Location = new System.Drawing.Point(3, 134); this.groupBox2.Name = "groupBox2"; this.groupBox2.Size = new System.Drawing.Size(243, 115); this.groupBox2.TabIndex = 2; @@ -137,6 +139,17 @@ this.hints.TabIndex = 0; this.hints.Text = ""; // + // gridlock + // + this.gridlock.AutoSize = true; + this.gridlock.Location = new System.Drawing.Point(9, 77); + this.gridlock.Name = "gridlock"; + this.gridlock.Size = new System.Drawing.Size(113, 18); + this.gridlock.TabIndex = 5; + this.gridlock.Text = "Lock slices to grid"; + this.gridlock.UseVisualStyleBackColor = true; + this.gridlock.CheckedChanged += new System.EventHandler(this.gridlock_CheckedChanged); + // // DrawGridOptionsPanel // this.AutoScaleDimensions = new System.Drawing.SizeF(96F, 96F); @@ -145,7 +158,7 @@ this.Controls.Add(this.groupBox1); this.Font = new System.Drawing.Font("Arial", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(204))); this.Name = "DrawGridOptionsPanel"; - this.Size = new System.Drawing.Size(249, 240); + this.Size = new System.Drawing.Size(249, 332); this.groupBox1.ResumeLayout(false); this.groupBox1.PerformLayout(); ((System.ComponentModel.ISupportInitialize)(this.slicesV)).EndInit(); @@ -165,5 +178,6 @@ private System.Windows.Forms.Label label2; private System.Windows.Forms.GroupBox groupBox2; private System.Windows.Forms.RichTextBox hints; + private System.Windows.Forms.CheckBox gridlock; } } diff --git a/Source/Plugins/BuilderModes/Interface/DrawGridOptionsPanel.cs b/Source/Plugins/BuilderModes/Interface/DrawGridOptionsPanel.cs index 52d88c4f..e81c31bc 100644 --- a/Source/Plugins/BuilderModes/Interface/DrawGridOptionsPanel.cs +++ b/Source/Plugins/BuilderModes/Interface/DrawGridOptionsPanel.cs @@ -7,9 +7,14 @@ namespace CodeImp.DoomBuilder.BuilderModes public partial class DrawGridOptionsPanel : UserControl { public event EventHandler OnValueChanged; + public event EventHandler OnGridLockChanged; private bool blockEvents; + private readonly string help; + private readonly string gridlockhelp; + public bool Triangulate { get { return triangulate.Checked; } set { blockEvents = true; triangulate.Checked = value; blockEvents = false; } } + public bool LockToGrid { get { return gridlock.Checked; } set { blockEvents = true; gridlock.Checked = value; blockEvents = false; } } public int HorizontalSlices { get { return (int)slicesH.Value; } set { blockEvents = true; slicesH.Value = value; blockEvents = false; } } public int VerticalSlices { get { return (int)slicesV.Value; } set { blockEvents = true; slicesV.Value = value; blockEvents = false; } } @@ -17,9 +22,10 @@ namespace CodeImp.DoomBuilder.BuilderModes InitializeComponent(); //set hints - string help = "Use " + Actions.Action.GetShortcutKeyDesc("buildermodes_increasebevel") + " and " + Actions.Action.GetShortcutKeyDesc("buildermodes_decreasebevel") + " to change the number of horizontal slices
" - + "Use " + Actions.Action.GetShortcutKeyDesc("buildermodes_increasesubdivlevel") + " and " + Actions.Action.GetShortcutKeyDesc("buildermodes_decreasesubdivlevel") + " to change the number of vertical slices"; - hints.SelectedRtf = HintsManager.GetRtfString(help); + help = HintsManager.GetRtfString("Use " + Actions.Action.GetShortcutKeyDesc("buildermodes_increasebevel") + " and " + Actions.Action.GetShortcutKeyDesc("buildermodes_decreasebevel") + " to change the number of horizontal slices
" + + "Use " + Actions.Action.GetShortcutKeyDesc("buildermodes_increasesubdivlevel") + " and " + Actions.Action.GetShortcutKeyDesc("buildermodes_decreasesubdivlevel") + " to change the number of vertical slices"); + gridlockhelp = HintsManager.GetRtfString("Use " + Actions.Action.GetShortcutKeyDesc("builder_griddec") + " and " + Actions.Action.GetShortcutKeyDesc("builder_gridinc") + " to change grid size."); + hints.SelectedRtf = help; } private void ValueChanged(object sender, EventArgs e) { @@ -27,5 +33,15 @@ namespace CodeImp.DoomBuilder.BuilderModes if(OnValueChanged != null) OnValueChanged(this, EventArgs.Empty); } + private void gridlock_CheckedChanged(object sender, EventArgs e) { + slicesH.Enabled = !gridlock.Checked; + slicesV.Enabled = !gridlock.Checked; + hints.Clear(); + hints.SelectedRtf = (gridlock.Checked ? gridlockhelp : help); + + if(blockEvents) return; + if(OnGridLockChanged != null) OnGridLockChanged(this, EventArgs.Empty); + } + } }