Round dual terrain tile corners
This commit is contained in:
@@ -4,6 +4,7 @@ using Windows.Storage;
|
||||
using Windows.Storage.Pickers;
|
||||
using Windows.UI;
|
||||
using Microsoft.Graphics.Canvas;
|
||||
using Microsoft.Graphics.Canvas.Geometry;
|
||||
using Microsoft.Graphics.Canvas.Text;
|
||||
using Microsoft.Graphics.Canvas.UI.Xaml;
|
||||
using Microsoft.UI;
|
||||
@@ -228,22 +229,52 @@ public sealed partial class MainWindow
|
||||
var halfWidth = rect.Width / 2;
|
||||
var halfHeight = rect.Height / 2;
|
||||
if ((floorMask & c_TopLeftFloor) != 0)
|
||||
drawing.FillRectangle(new(rect.X, rect.Y, halfWidth, halfHeight), floorColor);
|
||||
DrawFloorCorner(drawing, rect, floorColor, c_TopLeftFloor);
|
||||
|
||||
if ((floorMask & c_TopRightFloor) != 0)
|
||||
drawing.FillRectangle(new(rect.X + halfWidth, rect.Y, halfWidth, halfHeight), floorColor);
|
||||
DrawFloorCorner(drawing, rect, floorColor, c_TopRightFloor);
|
||||
|
||||
if ((floorMask & c_BottomLeftFloor) != 0)
|
||||
drawing.FillRectangle(new(rect.X, rect.Y + halfHeight, halfWidth, halfHeight), floorColor);
|
||||
DrawFloorCorner(drawing, rect, floorColor, c_BottomLeftFloor);
|
||||
|
||||
if ((floorMask & c_BottomRightFloor) != 0)
|
||||
drawing.FillRectangle(new(rect.X + halfWidth, rect.Y + halfHeight, halfWidth, halfHeight), floorColor);
|
||||
DrawFloorCorner(drawing, rect, floorColor, c_BottomRightFloor);
|
||||
|
||||
var center = new Vector2((float)(rect.X + halfWidth), (float)(rect.Y + halfHeight));
|
||||
if (floorMask is c_TopLeftFloor or c_TopRightFloor or c_BottomLeftFloor or c_BottomRightFloor)
|
||||
drawing.FillCircle(center, (float)Math.Min(rect.Width, rect.Height) * 0.18f, floorColor);
|
||||
}
|
||||
|
||||
private static void DrawFloorCorner(CanvasDrawingSession drawing, Rect rect, Color color, int corner)
|
||||
{
|
||||
var center = new Vector2((float)(rect.X + rect.Width / 2), (float)(rect.Y + rect.Height / 2));
|
||||
var radiusX = (float)rect.Width / 2;
|
||||
var radiusY = (float)rect.Height / 2;
|
||||
var start = corner switch {
|
||||
c_TopLeftFloor => new Vector2(center.X, (float)rect.Y),
|
||||
c_TopRightFloor => new Vector2((float)(rect.X + rect.Width), center.Y),
|
||||
c_BottomRightFloor => new Vector2(center.X, (float)(rect.Y + rect.Height)),
|
||||
c_BottomLeftFloor => new Vector2((float)rect.X, center.Y),
|
||||
_ => center
|
||||
};
|
||||
var end = corner switch {
|
||||
c_TopLeftFloor => new Vector2((float)rect.X, center.Y),
|
||||
c_TopRightFloor => new Vector2(center.X, (float)rect.Y),
|
||||
c_BottomRightFloor => new Vector2((float)(rect.X + rect.Width), center.Y),
|
||||
c_BottomLeftFloor => new Vector2(center.X, (float)(rect.Y + rect.Height)),
|
||||
_ => center
|
||||
};
|
||||
|
||||
using var builder = new CanvasPathBuilder(drawing);
|
||||
builder.BeginFigure(center);
|
||||
builder.AddLine(start);
|
||||
builder.AddArc(end, radiusX, radiusY, 0, CanvasSweepDirection.CounterClockwise, CanvasArcSize.Small);
|
||||
builder.EndFigure(CanvasFigureLoop.Closed);
|
||||
|
||||
using var geometry = CanvasGeometry.CreatePath(builder);
|
||||
drawing.FillGeometry(geometry, color);
|
||||
}
|
||||
|
||||
private int GetDualTileMask(int x, int y)
|
||||
{
|
||||
var mask = 0;
|
||||
|
||||
Reference in New Issue
Block a user