From 761b44ca3eafba009f0f1f978c25e5c57c6194a8 Mon Sep 17 00:00:00 2001 From: MaxED Date: Wed, 6 Jun 2012 13:37:19 +0000 Subject: [PATCH] GZDoom Builder 1.07c: Added Draw Ellipse Mode. --- Build/GZBuilder.cfg | 1 + Source/Core/Builder.sln | 27 ++++++ .../Plugins/BuilderModes/BuilderModes.csproj | 1 + .../ClassicModes/DrawEllipseMode.cs | 85 +++++++++++++++++++ .../ClassicModes/DrawRectangleMode.cs | 85 ++++++++++--------- .../BuilderModes/Resources/Actions.cfg | 14 ++- 6 files changed, 173 insertions(+), 40 deletions(-) create mode 100644 Source/Plugins/BuilderModes/ClassicModes/DrawEllipseMode.cs diff --git a/Build/GZBuilder.cfg b/Build/GZBuilder.cfg index 4867436f..00109f4a 100644 --- a/Build/GZBuilder.cfg +++ b/Build/GZBuilder.cfg @@ -152,6 +152,7 @@ shortcuts buildermodes_togglehighlight = 72; buildermodes_classicpasteproperties = 196694; buildermodes_drawrectanglemode = 196676; + buildermodes_drawellipsemode = 327748; buildermodes_decreasebevel = 196603; buildermodes_increasesubdivlevel = 131066; buildermodes_increasebevel = 196602; diff --git a/Source/Core/Builder.sln b/Source/Core/Builder.sln index f9758a07..e219fd98 100644 --- a/Source/Core/Builder.sln +++ b/Source/Core/Builder.sln @@ -5,6 +5,13 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Builder", "Builder.csproj", EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BuilderModes", "..\Plugins\BuilderModes\BuilderModes.csproj", "{B42D5AA0-F9A6-4234-9C4B-A05B11A64851}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "StairSectorBuilder", "..\Plugins\StairSectorBuilder\StairSectorBuilder.csproj", "{3F365121-906B-409D-BB1E-37E0A78056C2}" + ProjectSection(ProjectDependencies) = postProject + {818B3D10-F791-4C3F-9AF5-BB2D0079B63C} = {818B3D10-F791-4C3F-9AF5-BB2D0079B63C} + EndProjectSection +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "GZDoomEditing", "..\Plugins\GZDoomEditing\GZDoomEditing.csproj", "{760A9BC7-CB73-4C36-858B-994C14996FCD}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -35,6 +42,26 @@ Global {B42D5AA0-F9A6-4234-9C4B-A05B11A64851}.Release|Mixed Platforms.Build.0 = Release|x86 {B42D5AA0-F9A6-4234-9C4B-A05B11A64851}.Release|x86.ActiveCfg = Release|x86 {B42D5AA0-F9A6-4234-9C4B-A05B11A64851}.Release|x86.Build.0 = Release|x86 + {3F365121-906B-409D-BB1E-37E0A78056C2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {3F365121-906B-409D-BB1E-37E0A78056C2}.Debug|Any CPU.Build.0 = Debug|Any CPU + {3F365121-906B-409D-BB1E-37E0A78056C2}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU + {3F365121-906B-409D-BB1E-37E0A78056C2}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU + {3F365121-906B-409D-BB1E-37E0A78056C2}.Debug|x86.ActiveCfg = Debug|Any CPU + {3F365121-906B-409D-BB1E-37E0A78056C2}.Release|Any CPU.ActiveCfg = Release|Any CPU + {3F365121-906B-409D-BB1E-37E0A78056C2}.Release|Any CPU.Build.0 = Release|Any CPU + {3F365121-906B-409D-BB1E-37E0A78056C2}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU + {3F365121-906B-409D-BB1E-37E0A78056C2}.Release|Mixed Platforms.Build.0 = Release|Any CPU + {3F365121-906B-409D-BB1E-37E0A78056C2}.Release|x86.ActiveCfg = Release|Any CPU + {760A9BC7-CB73-4C36-858B-994C14996FCD}.Debug|Any CPU.ActiveCfg = Debug|x86 + {760A9BC7-CB73-4C36-858B-994C14996FCD}.Debug|Mixed Platforms.ActiveCfg = Debug|x86 + {760A9BC7-CB73-4C36-858B-994C14996FCD}.Debug|Mixed Platforms.Build.0 = Debug|x86 + {760A9BC7-CB73-4C36-858B-994C14996FCD}.Debug|x86.ActiveCfg = Debug|x86 + {760A9BC7-CB73-4C36-858B-994C14996FCD}.Debug|x86.Build.0 = Debug|x86 + {760A9BC7-CB73-4C36-858B-994C14996FCD}.Release|Any CPU.ActiveCfg = Release|x86 + {760A9BC7-CB73-4C36-858B-994C14996FCD}.Release|Mixed Platforms.ActiveCfg = Release|x86 + {760A9BC7-CB73-4C36-858B-994C14996FCD}.Release|Mixed Platforms.Build.0 = Release|x86 + {760A9BC7-CB73-4C36-858B-994C14996FCD}.Release|x86.ActiveCfg = Release|x86 + {760A9BC7-CB73-4C36-858B-994C14996FCD}.Release|x86.Build.0 = Release|x86 EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/Source/Plugins/BuilderModes/BuilderModes.csproj b/Source/Plugins/BuilderModes/BuilderModes.csproj index 2745ffa6..5be9879e 100644 --- a/Source/Plugins/BuilderModes/BuilderModes.csproj +++ b/Source/Plugins/BuilderModes/BuilderModes.csproj @@ -238,6 +238,7 @@ + diff --git a/Source/Plugins/BuilderModes/ClassicModes/DrawEllipseMode.cs b/Source/Plugins/BuilderModes/ClassicModes/DrawEllipseMode.cs new file mode 100644 index 00000000..be114e76 --- /dev/null +++ b/Source/Plugins/BuilderModes/ClassicModes/DrawEllipseMode.cs @@ -0,0 +1,85 @@ +using System; +using System.Collections.Generic; +using System.Text; +using System.Drawing; +using System.Windows.Forms; + +using CodeImp.DoomBuilder.Editing; +using CodeImp.DoomBuilder.Rendering; +using CodeImp.DoomBuilder.Geometry; +using CodeImp.DoomBuilder.Actions; +using CodeImp.DoomBuilder.Windows; +using CodeImp.DoomBuilder.Map; + +namespace CodeImp.DoomBuilder.BuilderModes.ClassicModes { + [EditMode(DisplayName = "Draw Ellipse Mode", + SwitchAction = "drawellipsemode", + AllowCopyPaste = false, + Volatile = true, + Optional = false)] + + public class DrawEllipseMode : DrawRectangleMode { + public DrawEllipseMode() : base() { + maxSubdivisions = 32; + minSubdivisions = 6; + undoName = "Ellipse draw"; + shapeName = "ellipse"; + + subdivisions = minSubdivisions; + } + + override protected Vector2D[] getShape(Vector2D pStart, Vector2D pEnd) { + //no shape + if (pEnd.x == pStart.x && pEnd.y == pStart.y) + return new Vector2D[0]; + + //got shape + int bevelSign = (bevelWidth > 0 ? 1 : -1); + int bevel = Math.Min(Math.Abs(bevelWidth), Math.Min(width, height) / 2) * bevelSign; + + Vector2D[] shape = new Vector2D[subdivisions + 1]; + + bool doBevel = false; + int hw = width / 2; + int hh = height / 2; + + if (bevel != bevelWidth) bevelWidth = bevel; + + Vector2D center = new Vector2D(pStart.x + hw, pStart.y + hh); + float curAngle = 0; + float angleStep = -(float)Math.PI / subdivisions * 2; + int px, py; + + for (int i = 0; i < subdivisions; i++) { + if (doBevel) { + px = (int)(center.x - (float)Math.Sin(curAngle) * (hw + bevel)); + py = (int)(center.y - (float)Math.Cos(curAngle) * (hh + bevel)); + } else { + px = (int)(center.x - (float)Math.Sin(curAngle) * hw); + py = (int)(center.y - (float)Math.Cos(curAngle) * hh); + } + doBevel = !doBevel; + shape[i] = new Vector2D(px, py); + curAngle += angleStep; + } + //add final point + shape[subdivisions] = shape[0]; + return shape; + } + +//ACTIONS + override protected void increaseSubdivLevel() { + if (subdivisions < maxSubdivisions) { + subdivisions += 2; + Update(); + } + } + + override protected void decreaseSubdivLevel() { + if (subdivisions > minSubdivisions) { + subdivisions -= 2; + Update(); + } + } + } +} diff --git a/Source/Plugins/BuilderModes/ClassicModes/DrawRectangleMode.cs b/Source/Plugins/BuilderModes/ClassicModes/DrawRectangleMode.cs index 9321409b..81f55433 100644 --- a/Source/Plugins/BuilderModes/ClassicModes/DrawRectangleMode.cs +++ b/Source/Plugins/BuilderModes/ClassicModes/DrawRectangleMode.cs @@ -22,15 +22,19 @@ namespace CodeImp.DoomBuilder.BuilderModes.ClassicModes public class DrawRectangleMode : DrawGeometryMode { //private LineLengthLabel hintLabel; - private int bevelWidth; - private int subdivisions; + protected int bevelWidth; + protected int subdivisions; - private const int MAX_SUBDIVISIONS = 16; + protected int maxSubdivisions = 16; + protected int minSubdivisions = 0; - private Vector2D start; - private Vector2D end; - private int width; - private int height; + protected string undoName = "Rectangle draw"; + protected string shapeName = "rectangle"; + + protected Vector2D start; + protected Vector2D end; + protected int width; + protected int height; public DrawRectangleMode() : base() { snaptogrid = true; @@ -49,7 +53,7 @@ namespace CodeImp.DoomBuilder.BuilderModes.ClassicModes // Render drawing lines if (renderer.StartOverlay(true)) { - color = snaptogrid ? stitchcolor : losecolor; + color = snaptonearest ? stitchcolor : losecolor; if (points.Count == 1) { updateReferencePoints(points[0], curp); @@ -91,29 +95,7 @@ namespace CodeImp.DoomBuilder.BuilderModes.ClassicModes renderer.Present(); } - //update top-left and bottom-right points, which define drawing shape - private void updateReferencePoints(DrawnVertex p1, DrawnVertex p2) { - if (p1.pos.x < p2.pos.x) { - start.x = p1.pos.x; - end.x = p2.pos.x; - } else { - start.x = p2.pos.x; - end.x = p1.pos.x; - } - - if (p1.pos.y < p2.pos.y) { - start.y = p1.pos.y; - end.y = p2.pos.y; - } else { - start.y = p2.pos.y; - end.y = p1.pos.y; - } - - width = (int)(end.x - start.x); - height = (int)(end.y - start.y); - } - - private Vector2D[] getShape(Vector2D pStart, Vector2D pEnd) { + protected virtual Vector2D[] getShape(Vector2D pStart, Vector2D pEnd) { //no shape if (pEnd.x == pStart.x && pEnd.y == pStart.y) return new Vector2D[0]; @@ -125,11 +107,14 @@ namespace CodeImp.DoomBuilder.BuilderModes.ClassicModes //got corners bool reverse = false; int bevel = Math.Min(Math.Abs(bevelWidth), Math.Min(width, height) / 2); + if (subdivisions > 0 && bevelWidth < 0) { bevel *= -1; reverse = true; } + if (bevel != bevelWidth) bevelWidth = bevel; + List l_points = new List(); //top-left corner @@ -179,6 +164,28 @@ namespace CodeImp.DoomBuilder.BuilderModes.ClassicModes return points; } + //update top-left and bottom-right points, which define drawing shape + private void updateReferencePoints(DrawnVertex p1, DrawnVertex p2) { + if (p1.pos.x < p2.pos.x) { + start.x = p1.pos.x; + end.x = p2.pos.x; + } else { + start.x = p2.pos.x; + end.x = p1.pos.x; + } + + if (p1.pos.y < p2.pos.y) { + start.y = p1.pos.y; + end.y = p2.pos.y; + } else { + start.y = p2.pos.y; + end.y = p1.pos.y; + } + + width = (int)(end.x - start.x); + height = (int)(end.y - start.y); + } + // This draws a point at a specific location override public bool DrawPointAt(Vector2D pos, bool stitch, bool stitchline) { if (pos.x < General.Map.Config.LeftBoundary || pos.x > General.Map.Config.RightBoundary || @@ -226,14 +233,14 @@ namespace CodeImp.DoomBuilder.BuilderModes.ClassicModes // When we have a rectangle if (points.Count > 4) { // Make undo for the draw - General.Map.UndoRedo.CreateUndo("Rectangle draw"); + General.Map.UndoRedo.CreateUndo(undoName); // Make an analysis and show info string[] adjectives = new string[] { "gloomy", "sad", "unhappy", "lonely", "troubled", "depressed", "heartsick", "glum", "pessimistic", "bitter", "downcast" }; // aaand my english vocabulary ends here :) string word = adjectives[new Random().Next(adjectives.Length - 1)]; string a = ((word[0] == 'a') || (word[0] == 'e') || (word[0] == 'o')) ? "an " : "a "; - General.Interface.DisplayStatus(StatusType.Action, "Created " + a + word + " rectangle."); + General.Interface.DisplayStatus(StatusType.Action, "Created " + a + word + " " + shapeName+"."); // Make the drawing if (!Tools.DrawLines(points)) { @@ -274,29 +281,29 @@ namespace CodeImp.DoomBuilder.BuilderModes.ClassicModes //ACTIONS [BeginAction("increasesubdivlevel")] - private void increaseSubdivLevel() { - if (subdivisions < MAX_SUBDIVISIONS) { + protected virtual void increaseSubdivLevel() { + if (subdivisions < maxSubdivisions) { subdivisions++; Update(); } } [BeginAction("decreasesubdivlevel")] - private void decreaseSubdivLevel() { - if (subdivisions > 0) { + protected virtual void decreaseSubdivLevel() { + if (subdivisions > minSubdivisions) { subdivisions--; Update(); } } [BeginAction("increasebevel")] - private void increaseBevel() { + protected virtual void increaseBevel() { bevelWidth += General.Map.Grid.GridSize; Update(); } [BeginAction("decreasebevel")] - private void decreaseBevel() { + protected virtual void decreaseBevel() { bevelWidth -= General.Map.Grid.GridSize; Update(); } diff --git a/Source/Plugins/BuilderModes/Resources/Actions.cfg b/Source/Plugins/BuilderModes/Resources/Actions.cfg index ad2480fc..3ca7f8fc 100644 --- a/Source/Plugins/BuilderModes/Resources/Actions.cfg +++ b/Source/Plugins/BuilderModes/Resources/Actions.cfg @@ -104,13 +104,25 @@ drawrectanglemode { title = "Start Rectangle Drawing"; category = "drawing"; - description = "Starts drawing rectangle. See the Drawing category for actions available during drawing mode."; + description = "Starts drawing rectangle. Increase / Decrease Sudivision Level and Increase /Decrease Corners Bevel actions are avaliable in this mode."; allowkeys = true; allowmouse = true; allowscroll = true; default = 196676; } +//mxd +drawellipsemode +{ + title = "Start Ellipse Drawing"; + category = "drawing"; + description = "Starts drawing ellipse. Increase / Decrease Sudivision Level and Increase /Decrease Corners Bevel actions are avaliable in this mode."; + allowkeys = true; + allowmouse = true; + allowscroll = true; + default = 327748; +} + //mxd increasesubdivlevel {