mirror of
https://git.do.srb2.org/STJr/UltimateZoneBuilder.git
synced 2024-11-26 22:01:45 +00:00
Draw Rectangle Mode: now works correctly with grid transformation
This commit is contained in:
parent
57b184a9e6
commit
323a990144
2 changed files with 39 additions and 16 deletions
|
@ -232,9 +232,17 @@ namespace CodeImp.DoomBuilder.BuilderModes
|
|||
renderer.Present();
|
||||
}
|
||||
|
||||
//mxd
|
||||
protected void RenderGuidelines(Vector2D start, Vector2D end, PixelColor c)
|
||||
{
|
||||
RenderGuidelines(start, end, c, 0.0);
|
||||
}
|
||||
|
||||
//mxd
|
||||
protected void RenderGuidelines(Vector2D start, Vector2D end, PixelColor c, double angle)
|
||||
{
|
||||
start = start.GetRotated(angle);
|
||||
end = end.GetRotated(angle);
|
||||
|
||||
if(end.x != start.x && end.y != start.y)
|
||||
{
|
||||
Vector2D tr = new Vector2D(Math.Max(end.x, start.x), Math.Max(end.y, start.y));
|
||||
|
@ -242,10 +250,10 @@ namespace CodeImp.DoomBuilder.BuilderModes
|
|||
|
||||
// Create guidelines
|
||||
Line3D[] lines = new Line3D[5];
|
||||
lines[0] = new Line3D(new Vector2D(tr.x, General.Map.Config.TopBoundary), new Vector2D(tr.x, General.Map.Config.BottomBoundary), c, false);
|
||||
lines[1] = new Line3D(new Vector2D(bl.x, General.Map.Config.TopBoundary), new Vector2D(bl.x, General.Map.Config.BottomBoundary), c, false);
|
||||
lines[2] = new Line3D(new Vector2D(General.Map.Config.LeftBoundary, tr.y), new Vector2D(General.Map.Config.RightBoundary, tr.y), c, false);
|
||||
lines[3] = new Line3D(new Vector2D(General.Map.Config.LeftBoundary, bl.y), new Vector2D(General.Map.Config.RightBoundary, bl.y), c, false);
|
||||
lines[0] = new Line3D(new Vector2D(tr.x, General.Map.Config.TopBoundary).GetRotated(-angle), new Vector2D(tr.x, General.Map.Config.BottomBoundary).GetRotated(-angle), c, false);
|
||||
lines[1] = new Line3D(new Vector2D(bl.x, General.Map.Config.TopBoundary).GetRotated(-angle), new Vector2D(bl.x, General.Map.Config.BottomBoundary).GetRotated(-angle), c, false);
|
||||
lines[2] = new Line3D(new Vector2D(General.Map.Config.LeftBoundary, tr.y).GetRotated(-angle), new Vector2D(General.Map.Config.RightBoundary, tr.y).GetRotated(-angle), c, false);
|
||||
lines[3] = new Line3D(new Vector2D(General.Map.Config.LeftBoundary, bl.y).GetRotated(-angle), new Vector2D(General.Map.Config.RightBoundary, bl.y).GetRotated(-angle), c, false);
|
||||
|
||||
// Create current line extent. Make sure v1 is to the left of v2
|
||||
Line2D current = (end.x < start.x ? new Line2D(end, start) : new Line2D(start, end));
|
||||
|
|
|
@ -141,21 +141,31 @@ namespace CodeImp.DoomBuilder.BuilderModes
|
|||
snaptonearest = General.Interface.CtrlState ^ General.Interface.AutoMerge;
|
||||
|
||||
DrawnVertex curp = GetCurrentPosition();
|
||||
Vector2D curvertexpos = curp.pos;
|
||||
float vsize = (renderer.VertexSize + 1.0f) / renderer.Scale;
|
||||
|
||||
curp.pos = curp.pos.GetRotated(-General.Map.Grid.GridRotate);
|
||||
|
||||
// Render drawing lines
|
||||
if(renderer.StartOverlay(true))
|
||||
{
|
||||
PixelColor color = snaptonearest ? stitchcolor : losecolor;
|
||||
|
||||
if(points.Count == 1)
|
||||
Vector2D startrotated = start.GetRotated(General.Map.Grid.GridRotate);
|
||||
Vector2D endrotated = end.GetRotated(General.Map.Grid.GridRotate);
|
||||
|
||||
if (points.Count == 1)
|
||||
{
|
||||
UpdateReferencePoints(points[0], curp);
|
||||
|
||||
Vector2D[] shape = GetShape(start, end);
|
||||
|
||||
// Rotate the shape to fit the grid rotation
|
||||
for (int i = 0; i < shape.Length; i++)
|
||||
shape[i] = shape[i].GetRotated(General.Map.Grid.GridRotate);
|
||||
|
||||
// Render guidelines
|
||||
if(showguidelines)
|
||||
RenderGuidelines(start, end, General.Colors.Guideline.WithAlpha(80));
|
||||
RenderGuidelines(startrotated, endrotated, General.Colors.Guideline.WithAlpha(80), -General.Map.Grid.GridRotate);
|
||||
|
||||
//render shape
|
||||
for(int i = 1; i < shape.Length; i++)
|
||||
|
@ -169,14 +179,15 @@ namespace CodeImp.DoomBuilder.BuilderModes
|
|||
if(shape.Length == 2)
|
||||
{
|
||||
// Render label for line
|
||||
labels[0].Move(start, end);
|
||||
labels[0].Move(startrotated, endrotated);
|
||||
renderer.RenderText(labels[0].TextLabel);
|
||||
}
|
||||
else if(shape.Length > 3)
|
||||
{
|
||||
// Render labels for rectangle
|
||||
Vector2D[] labelCoords = { start, new Vector2D(end.x, start.y), end, new Vector2D(start.x, end.y), start };
|
||||
for(int i = 1; i < 5; i++)
|
||||
Vector2D[] labelCoords = { startrotated, new Vector2D(end.x, start.y).GetRotated(General.Map.Grid.GridRotate), endrotated, new Vector2D(start.x, end.y).GetRotated(General.Map.Grid.GridRotate), startrotated };
|
||||
|
||||
for (int i = 1; i < 5; i++)
|
||||
{
|
||||
labels[i - 1].Move(labelCoords[i], labelCoords[i - 1]);
|
||||
renderer.RenderText(labels[i - 1].TextLabel);
|
||||
|
@ -188,7 +199,7 @@ namespace CodeImp.DoomBuilder.BuilderModes
|
|||
//render hint
|
||||
if(width > 64 * vsize && height > 16 * vsize)
|
||||
{
|
||||
hintlabel.Move(start, end);
|
||||
hintlabel.Move(startrotated, endrotated);
|
||||
hintlabel.Text = GetHintText();
|
||||
renderer.RenderText(hintlabel.TextLabel);
|
||||
}
|
||||
|
@ -207,7 +218,7 @@ namespace CodeImp.DoomBuilder.BuilderModes
|
|||
else
|
||||
{
|
||||
// Render vertex at cursor
|
||||
renderer.RenderRectangleFilled(new RectangleF((float)(curp.pos.x - vsize), (float)(curp.pos.y - vsize), vsize * 2.0f, vsize * 2.0f), color, true);
|
||||
renderer.RenderRectangleFilled(new RectangleF((float)(curvertexpos.x - vsize), (float)(curvertexpos.y - vsize), vsize * 2.0f, vsize * 2.0f), color, true);
|
||||
}
|
||||
|
||||
// Done
|
||||
|
@ -306,7 +317,7 @@ namespace CodeImp.DoomBuilder.BuilderModes
|
|||
if(!p1.pos.IsFinite() || !p2.pos.IsFinite()) return;
|
||||
|
||||
// Make sure start always stays at left and up from the end
|
||||
if(p1.pos.x < p2.pos.x)
|
||||
if (p1.pos.x < p2.pos.x)
|
||||
{
|
||||
start.x = p1.pos.x;
|
||||
end.x = p2.pos.x;
|
||||
|
@ -341,12 +352,12 @@ namespace CodeImp.DoomBuilder.BuilderModes
|
|||
return false;
|
||||
|
||||
DrawnVertex newpoint = new DrawnVertex();
|
||||
newpoint.pos = pos;
|
||||
newpoint.pos = pos.GetRotated(-General.Map.Grid.GridRotate);
|
||||
newpoint.stitch = true; //stitch
|
||||
newpoint.stitchline = stitchline;
|
||||
points.Add(newpoint);
|
||||
|
||||
if(points.Count == 1) //add point and labels
|
||||
if (points.Count == 1) //add point and labels
|
||||
{
|
||||
labels.AddRange(new[] { new LineLengthLabel(false, true), new LineLengthLabel(false, true), new LineLengthLabel(false, true), new LineLengthLabel(false, true) });
|
||||
hintlabel = new HintLabel(General.Colors.InfoLine);
|
||||
|
@ -364,6 +375,10 @@ namespace CodeImp.DoomBuilder.BuilderModes
|
|||
points = new List<DrawnVertex>(); //clear points
|
||||
Vector2D[] shape = GetShape(start, end);
|
||||
|
||||
// Rotate the shape to fit the grid rotation
|
||||
for (int i = 0; i < shape.Length; i++)
|
||||
shape[i] = shape[i].GetRotated(General.Map.Grid.GridRotate);
|
||||
|
||||
// We don't want base.DrawPointAt to call Update() here, because it will mess labels[]
|
||||
// and trigger shape.Count number of display redraws...
|
||||
blockupdate = true;
|
||||
|
|
Loading…
Reference in a new issue