diff --git a/Source/Core/Rendering/IRenderer2D.cs b/Source/Core/Rendering/IRenderer2D.cs
index 261b6883..0819576d 100644
--- a/Source/Core/Rendering/IRenderer2D.cs
+++ b/Source/Core/Rendering/IRenderer2D.cs
@@ -37,7 +37,8 @@ namespace CodeImp.DoomBuilder.Rendering
float Scale { get; }
int VertexSize { get; }
ViewMode ViewMode { get; }
-
+ Size ViewportSize { get; } //mxd
+
// View methods
Vector2D DisplayToMap(Vector2D mousepos);
Vector2D MapToDisplay(Vector2D mappos);
diff --git a/Source/Core/Rendering/Renderer.cs b/Source/Core/Rendering/Renderer.cs
index 36e72132..ce8eac55 100644
--- a/Source/Core/Rendering/Renderer.cs
+++ b/Source/Core/Rendering/Renderer.cs
@@ -17,6 +17,7 @@
#region ================== Namespaces
using System;
+using System.Drawing;
using CodeImp.DoomBuilder.Map;
using CodeImp.DoomBuilder.Geometry;
@@ -46,6 +47,7 @@ namespace CodeImp.DoomBuilder.Rendering
// Disposing
public bool IsDisposed { get { return isdisposed; } }
public static bool FullBrightness { get { return fullbrightness; } set { fullbrightness = value; } } //mxd
+ public Size ViewportSize { get { return graphics.RenderTarget.Size; } } //mxd
#endregion
diff --git a/Source/Plugins/BuilderModes/BuilderModes.csproj b/Source/Plugins/BuilderModes/BuilderModes.csproj
index 5f9e8676..b9e693b0 100644
--- a/Source/Plugins/BuilderModes/BuilderModes.csproj
+++ b/Source/Plugins/BuilderModes/BuilderModes.csproj
@@ -225,6 +225,7 @@
+
@@ -236,6 +237,7 @@
+
diff --git a/Source/Plugins/BuilderModes/ClassicModes/DrawCurveMode.cs b/Source/Plugins/BuilderModes/ClassicModes/DrawCurveMode.cs
index d96cda68..bd8555cb 100644
--- a/Source/Plugins/BuilderModes/ClassicModes/DrawCurveMode.cs
+++ b/Source/Plugins/BuilderModes/ClassicModes/DrawCurveMode.cs
@@ -74,9 +74,16 @@ namespace CodeImp.DoomBuilder.BuilderModes
DrawnVertex curp = GetCurrentPosition();
float vsize = (renderer.VertexSize + 1.0f) / renderer.Scale;
- // Update active label position (mxd)
- if(labels.Count > 0)
+ // Update label positions (mxd)
+ if(labels.Count > 0)
+ {
+ // Update labels for already drawn lines
+ for(int i = 0; i < labels.Count - 1; i++)
+ SetLabelPosition(labels[i], points[i].pos, points[i + 1].pos);
+
+ // Update label for active line
SetLabelPosition(labels[labels.Count - 1], points[points.Count - 1].pos, curp.pos);
+ }
// Render drawing lines
if(renderer.StartOverlay(true))
diff --git a/Source/Plugins/BuilderModes/ClassicModes/DrawGeometryMode.cs b/Source/Plugins/BuilderModes/ClassicModes/DrawGeometryMode.cs
index 2c516d7b..5faa5df6 100644
--- a/Source/Plugins/BuilderModes/ClassicModes/DrawGeometryMode.cs
+++ b/Source/Plugins/BuilderModes/ClassicModes/DrawGeometryMode.cs
@@ -138,9 +138,16 @@ namespace CodeImp.DoomBuilder.BuilderModes
DrawnVertex curp = GetCurrentPosition();
float vsize = (renderer.VertexSize + 1.0f) / renderer.Scale;
- // Update active label position (mxd)
- if (labels.Count > 0)
+ // Update label positions (mxd)
+ if(labels.Count > 0)
+ {
+ // Update labels for already drawn lines
+ for(int i = 0; i < labels.Count - 1; i++)
+ SetLabelPosition(labels[i], points[i].pos, points[i + 1].pos);
+
+ // Update label for active line
SetLabelPosition(labels[labels.Count - 1], points[points.Count - 1].pos, curp.pos);
+ }
// Render drawing lines
if(renderer.StartOverlay(true))
@@ -209,6 +216,43 @@ namespace CodeImp.DoomBuilder.BuilderModes
//mxd
protected void SetLabelPosition(LineLengthLabel label, Vector2D start, Vector2D end)
{
+ // Check if start/end point is on screen...
+ Vector2D lt = General.Map.Renderer2D.DisplayToMap(new Vector2D(0.0f, General.Map.Renderer2D.ViewportSize.Height));
+ Vector2D rb = General.Map.Renderer2D.DisplayToMap(new Vector2D(General.Map.Renderer2D.ViewportSize.Width, 0.0f));
+ RectangleF viewport = new RectangleF(lt.x, lt.y, rb.x - lt.x, rb.y - lt.y);
+ bool startvisible = viewport.Contains(start.x, start.y);
+ bool endvisible = viewport.Contains(end.x, end.y);
+
+ // Do this only when one point is visible, an the other isn't
+ if((!startvisible && endvisible) || (startvisible && !endvisible))
+ {
+ Line2D drawnline = new Line2D(start, end);
+ Line2D[] viewportsides = new[] {
+ new Line2D(lt, rb.x, lt.y), // top
+ new Line2D(lt.x, rb.y, rb.x, rb.y), // bottom
+ new Line2D(lt, lt.x, rb.y), // left
+ new Line2D(rb.x, lt.y, rb.x, rb.y), // right
+ };
+
+ float u;
+ foreach(Line2D side in viewportsides)
+ {
+ // Modify the start point so it stays on screen
+ if(!startvisible && side.GetIntersection(drawnline, out u))
+ {
+ start = drawnline.GetCoordinatesAt(u);
+ break;
+ }
+
+ // Modify the end point so it stays on screen
+ if(!endvisible && side.GetIntersection(drawnline, out u))
+ {
+ end = drawnline.GetCoordinatesAt(u);
+ break;
+ }
+ }
+ }
+
Vector2D perpendicular = (end - start).GetPerpendicular();
float angle = perpendicular.GetAngle();
float offset = label.TextLabel.TextSize.Width * Math.Abs((float)Math.Sin(angle)) + label.TextLabel.TextSize.Height * Math.Abs((float)Math.Cos(angle));
@@ -560,7 +604,8 @@ namespace CodeImp.DoomBuilder.BuilderModes
// Render things
if(renderer.StartThings(true))
{
- renderer.RenderThingSet(General.Map.Map.Things, Presentation.THINGS_ALPHA);
+ renderer.RenderThingSet(General.Map.ThingsFilter.SortedHiddenThings, Presentation.THINGS_HIDDEN_ALPHA);
+ renderer.RenderThingSet(General.Map.ThingsFilter.SortedVisibleThings, Presentation.THINGS_ALPHA);
renderer.Finish();
}
@@ -572,7 +617,7 @@ namespace CodeImp.DoomBuilder.BuilderModes
public override void OnMouseMove(MouseEventArgs e)
{
base.OnMouseMove(e);
- if(panning) return; //mxd. Skip all this jass while panning
+ if(panning) return; //mxd. Skip all this jazz while panning
Update();
}
diff --git a/Source/Plugins/BuilderModes/ErrorChecks/CheckMapSize.cs b/Source/Plugins/BuilderModes/ErrorChecks/CheckMapSize.cs
new file mode 100644
index 00000000..dc6322f4
--- /dev/null
+++ b/Source/Plugins/BuilderModes/ErrorChecks/CheckMapSize.cs
@@ -0,0 +1,57 @@
+using CodeImp.DoomBuilder.Geometry;
+using CodeImp.DoomBuilder.Map;
+using System.Threading;
+
+namespace CodeImp.DoomBuilder.BuilderModes.ErrorChecks
+{
+ [ErrorChecker("Check map size", true, 50)]
+ public class CheckMapSize : ErrorChecker
+ {
+ private const int PROGRESS_STEP = 1000;
+ internal const int MAXIMUM_DISTANCE = 32767;
+
+ // Constructor
+ public CheckMapSize()
+ {
+ // Total progress is done when all vertices are checked
+ SetTotalProgress(General.Map.Map.Vertices.Count / PROGRESS_STEP);
+ }
+
+ // This runs the check
+ public override void Run()
+ {
+ int progress = 0;
+ int stepprogress = 0;
+
+ float minx = int.MaxValue;
+ float maxx = int.MinValue;
+ float miny = int.MaxValue;
+ float maxy = int.MinValue;
+
+ // Go for all vertices
+ foreach(Vertex v in General.Map.Map.Vertices)
+ {
+ if(v.Position.x < minx) minx = v.Position.x;
+ if(v.Position.x > maxx) maxx = v.Position.x;
+ if(v.Position.y < miny) miny = v.Position.y;
+ if(v.Position.y > maxy) maxy = v.Position.y;
+
+ // Handle thread interruption
+ try { Thread.Sleep(0); } catch(ThreadInterruptedException) { return; }
+
+ // We are making progress!
+ if((++progress / PROGRESS_STEP) > stepprogress)
+ {
+ stepprogress = (progress / PROGRESS_STEP);
+ AddProgress(1);
+ }
+ }
+
+ // Map elements should not be more than 32767 mu apart
+ if(maxx - minx > MAXIMUM_DISTANCE || maxy - miny > MAXIMUM_DISTANCE)
+ {
+ SubmitResult(new ResultMapTooBig(new Vector2D(minx, miny), new Vector2D(maxx, maxy)));
+ }
+ }
+ }
+}
diff --git a/Source/Plugins/BuilderModes/ErrorChecks/ErrorResult.cs b/Source/Plugins/BuilderModes/ErrorChecks/ErrorResult.cs
index ef0040a4..916b82cc 100644
--- a/Source/Plugins/BuilderModes/ErrorChecks/ErrorResult.cs
+++ b/Source/Plugins/BuilderModes/ErrorChecks/ErrorResult.cs
@@ -62,8 +62,6 @@ namespace CodeImp.DoomBuilder.BuilderModes
#endregion
#region ================== Methods
-
-
// When the first button is clicked
// Return true when map geometry or things have been added/removed so that the checker can restart
@@ -93,22 +91,18 @@ namespace CodeImp.DoomBuilder.BuilderModes
}
// This is called for rendering
- public virtual void PlotSelection(IRenderer2D renderer)
+ public virtual void PlotSelection(IRenderer2D renderer) { }
+
+ // This is called for rendering (mxd. And never used!)
+ /*public virtual void RenderThingsSelection(IRenderer2D renderer)
{
- }
+ }*/
// This is called for rendering
- public virtual void RenderThingsSelection(IRenderer2D renderer)
- {
- }
-
- // This is called for rendering
- public virtual void RenderOverlaySelection(IRenderer2D renderer)
- {
- }
+ public virtual void RenderOverlaySelection(IRenderer2D renderer) { }
// Call this to zoom in on the given selection
- public RectangleF GetZoomArea()
+ public virtual RectangleF GetZoomArea()
{
List points = new List();
RectangleF area = MapSet.CreateEmptyArea();
diff --git a/Source/Plugins/BuilderModes/ErrorChecks/ResultMapTooBig.cs b/Source/Plugins/BuilderModes/ErrorChecks/ResultMapTooBig.cs
new file mode 100644
index 00000000..977d0ba5
--- /dev/null
+++ b/Source/Plugins/BuilderModes/ErrorChecks/ResultMapTooBig.cs
@@ -0,0 +1,65 @@
+#region ================== Namespaces
+
+using System.Drawing;
+using CodeImp.DoomBuilder.Geometry;
+
+#endregion
+
+namespace CodeImp.DoomBuilder.BuilderModes.ErrorChecks
+{
+ public class ResultMapTooBig : ErrorResult
+ {
+ #region ================== Variables
+
+ private readonly bool toowide;
+ private readonly bool toohigh;
+ private readonly Vector2D min;
+ private readonly Vector2D max;
+
+ #endregion
+
+ #region ================== Properties
+
+ public override int Buttons { get { return 0; } }
+
+ #endregion
+
+ #region ================== Constructor / Destructor
+
+ public ResultMapTooBig(Vector2D min, Vector2D max)
+ {
+ // Initialize
+ this.min = min;
+ this.max = max;
+ this.toowide = max.x - min.x > CheckMapSize.MAXIMUM_DISTANCE;
+ this.toohigh = max.y - min.y > CheckMapSize.MAXIMUM_DISTANCE;
+ description = "Map is too big.";
+ }
+
+ #endregion
+
+ #region ================== Methods
+
+ public override RectangleF GetZoomArea()
+ {
+ const float scaler = 0.5f;
+ return new RectangleF(min.x * scaler, min.y * scaler, (max.x - min.x) * scaler, (max.y - min.y) * scaler);
+ }
+
+ // This sets if this result is displayed in ErrorCheckForm (mxd)
+ internal override void Hide(bool hide)
+ {
+ hidden = hide;
+ }
+
+ // This must return the string that is displayed in the listbox
+ public override string ToString()
+ {
+ if(toowide && toohigh) return "Map's width and height is bigger than " + CheckMapSize.MAXIMUM_DISTANCE + " m.u. This can cause rendering and physics issues.";
+ if(toowide) return "Map is wider than than " + CheckMapSize.MAXIMUM_DISTANCE + " m.u. This can cause rendering and physics issues.";
+ return "Map is taller than " + CheckMapSize.MAXIMUM_DISTANCE + " m.u. This can cause rendering and physics issues.";
+ }
+
+ #endregion
+ }
+}