Editor/UI/ArchSlotIcon.cs

Editor UI helper that draws small hand-drawn style glyph icons for architectural slot types. It maps an ArchSurface enum to drawing primitives (lines, solid and translucent rects, pitched roof, steps) using Paint API into a given Rect and Color.

Native Interop
using System;
using Editor;
using Sandbox;

namespace Sunless.Architecture;

// Hand-drawn glyphs: no icon font reads a soffit, reveal or gutter section at 18 px.
public static class ArchSlotIcon
{
	public static void Draw( Rect box, ArchSurface slot, Color color )
	{
		var pen = MathF.Max( 1.4f, box.Width * 0.085f );

		Vector2 At( float x, float y ) => new( box.Left + box.Width * x, box.Top + box.Height * y );

		void Line( float x1, float y1, float x2, float y2 )
		{
			Paint.SetPen( color, pen );
			Paint.DrawLine( At( x1, y1 ), At( x2, y2 ) );
		}

		void Solid( float x1, float y1, float x2, float y2 )
		{
			Paint.ClearPen();
			Paint.SetBrush( color );
			Paint.DrawRect( new Rect( At( x1, y1 ), At( x2, y2 ) - At( x1, y1 ) ) );
		}

		void Ghost( float x1, float y1, float x2, float y2 )
		{
			Paint.ClearPen();
			Paint.SetBrush( color.WithAlpha( 0.32f ) );
			Paint.DrawRect( new Rect( At( x1, y1 ), At( x2, y2 ) - At( x1, y1 ) ) );
		}

		void Pitch( float apexX )
		{
			Paint.SetPen( color, pen );
			Paint.DrawLine( At( 0.06f, 0.74f ), At( apexX, 0.24f ) );
			Paint.DrawLine( At( apexX, 0.24f ), At( 0.94f, 0.74f ) );
		}

		void Steps( bool treads )
		{
			for ( var i = 0; i < 3; i++ )
			{
				var x = 0.1f + i * 0.27f;
				var y = 0.76f - i * 0.22f;

				if ( treads )
				{
					Solid( x, y - 0.06f, x + 0.28f, y );
					Ghost( x, y, x + 0.055f, y + 0.22f );
				}
				else
				{
					Ghost( x, y - 0.06f, x + 0.28f, y );
					Solid( x, y, x + 0.055f, y + 0.22f );
				}
			}
		}

		switch ( slot )
		{
			case ArchSurface.WallExterior:
				Solid( 0.1f, 0.2f, 0.46f, 0.36f );
				Solid( 0.52f, 0.2f, 0.9f, 0.36f );
				Solid( 0.1f, 0.42f, 0.34f, 0.58f );
				Solid( 0.4f, 0.42f, 0.9f, 0.58f );
				Solid( 0.1f, 0.64f, 0.46f, 0.8f );
				Solid( 0.52f, 0.64f, 0.9f, 0.8f );
				break;

			case ArchSurface.WallInterior:
				Paint.ClearBrush();
				Paint.SetPen( color, pen );
				Paint.DrawRect( new Rect( At( 0.12f, 0.2f ), At( 0.88f, 0.8f ) - At( 0.12f, 0.2f ) ) );
				Line( 0.12f, 0.5f, 0.88f, 0.5f );
				break;

			case ArchSurface.Reveal:
				Ghost( 0.1f, 0.16f, 0.9f, 0.84f );
				Paint.ClearBrush();
				Paint.SetPen( color, pen );
				Paint.DrawRect( new Rect( At( 0.32f, 0.3f ), At( 0.68f, 0.84f ) - At( 0.32f, 0.3f ) ) );
				break;

			case ArchSurface.Pillar:
				Solid( 0.18f, 0.16f, 0.82f, 0.26f );
				Solid( 0.34f, 0.26f, 0.66f, 0.74f );
				Solid( 0.18f, 0.74f, 0.82f, 0.84f );
				break;

			case ArchSurface.Floor:
				Solid( 0.08f, 0.6f, 0.92f, 0.72f );
				Ghost( 0.2f, 0.72f, 0.8f, 0.84f );
				Line( 0.3f, 0.32f, 0.3f, 0.58f );
				Line( 0.7f, 0.32f, 0.7f, 0.58f );
				break;

			case ArchSurface.Ceiling:
				Solid( 0.08f, 0.26f, 0.92f, 0.38f );
				Ghost( 0.2f, 0.14f, 0.8f, 0.26f );
				Line( 0.3f, 0.4f, 0.3f, 0.68f );
				Line( 0.7f, 0.4f, 0.7f, 0.68f );
				break;

			case ArchSurface.StairTread:
				Steps( true );
				break;

			case ArchSurface.StairRiser:
				Steps( false );
				break;

			case ArchSurface.Roof:
				Pitch( 0.5f );
				Line( 0.5f, 0.24f, 0.5f, 0.74f );
				break;

			case ArchSurface.RoofEdge:
				Ghost( 0.06f, 0.3f, 0.94f, 0.56f );
				Pitch( 0.5f );
				Solid( 0.04f, 0.7f, 0.96f, 0.84f );
				break;

			case ArchSurface.Soffit:
				Pitch( 0.5f );
				Solid( 0.14f, 0.74f, 0.86f, 0.84f );
				Line( 0.14f, 0.74f, 0.14f, 0.84f );
				break;

			case ArchSurface.Gutter:
				Paint.ClearBrush();
				Paint.SetPen( color, pen * 1.5f );
				Paint.DrawLine( At( 0.2f, 0.26f ), At( 0.2f, 0.72f ) );
				Paint.DrawLine( At( 0.2f, 0.72f ), At( 0.8f, 0.72f ) );
				Paint.DrawLine( At( 0.8f, 0.72f ), At( 0.8f, 0.26f ) );
				Ghost( 0.24f, 0.5f, 0.76f, 0.68f );
				break;

			case ArchSurface.Trim:
				Ghost( 0.08f, 0.16f, 0.92f, 0.42f );
				Solid( 0.04f, 0.44f, 0.96f, 0.58f );
				Ghost( 0.08f, 0.6f, 0.92f, 0.84f );
				break;

			case ArchSurface.Baseboard:
				Ghost( 0.14f, 0.14f, 0.86f, 0.64f );
				Solid( 0.08f, 0.66f, 0.92f, 0.8f );
				Solid( 0.08f, 0.8f, 0.92f, 0.86f );
				break;

			default:
				Paint.ClearBrush();
				Paint.SetPen( color, pen );
				Paint.DrawRect( new Rect( At( 0.16f, 0.24f ), At( 0.84f, 0.76f ) - At( 0.16f, 0.24f ) ) );
				break;
		}
	}
}