diff --git a/ZeroSpace/ZeroSpace.MapEditor/Views/MapDrawable.cs b/ZeroSpace/ZeroSpace.MapEditor/Views/MapDrawable.cs
index 1add6d8..d37c07a 100644
--- a/ZeroSpace/ZeroSpace.MapEditor/Views/MapDrawable.cs
+++ b/ZeroSpace/ZeroSpace.MapEditor/Views/MapDrawable.cs
@@ -1,5 +1,6 @@
using Microsoft.Maui.Graphics;
using ZeroSpace.MapEditor.Models;
+using ZeroSpace.MapEditor.Services;
namespace ZeroSpace.MapEditor.Views;
@@ -25,11 +26,19 @@ public sealed class MapDrawable : IDrawable
public RectF? SelectionBox { get; set; }
+ /// In-game galaxy map screenshot, drawn under the nodes.
+ public IImage? BackgroundImage { get; set; }
+
+ /// Whether the galaxy map background is shown.
+ public bool ShowBackground { get; set; } = true;
+
public void Draw(ICanvas canvas, RectF dirtyRect)
{
canvas.FillColor = Color.FromArgb("#1e2430");
canvas.FillRectangle(dirtyRect);
+ DrawBackground(canvas);
+
PointF ToScreen(double worldX, double worldY) =>
new((float)(worldX * Scale + OffsetX), (float)(worldY * Scale + OffsetY));
@@ -85,6 +94,39 @@ public sealed class MapDrawable : IDrawable
}
}
+ ///
+ /// Draws the galaxy map screenshot fitted inside the world square,
+ /// preserving aspect ratio so node world coordinates line up exactly
+ /// with the map underneath.
+ ///
+ private void DrawBackground(ICanvas canvas)
+ {
+ if (!ShowBackground || BackgroundImage is null)
+ {
+ return;
+ }
+
+ var imageWidth = BackgroundImage.Width;
+ var imageHeight = BackgroundImage.Height;
+ if (imageWidth <= 0 || imageHeight <= 0)
+ {
+ return;
+ }
+
+ const double world = StarSystemDocStore.WorldSize;
+ var fit = Math.Min(world / imageWidth, world / imageHeight);
+ var drawWidth = imageWidth * fit;
+ var drawHeight = imageHeight * fit;
+ var originX = (world - drawWidth) / 2;
+ var originY = (world - drawHeight) / 2;
+
+ canvas.DrawImage(BackgroundImage,
+ (float)(originX * Scale + OffsetX),
+ (float)(originY * Scale + OffsetY),
+ (float)(drawWidth * Scale),
+ (float)(drawHeight * Scale));
+ }
+
public static Color ColorForOwner(string owner) => owner switch
{
"The Eden Accord" => Color.FromArgb("#10b981"),