public static IBitmap DrawText(this IBitmap bitmap, string text, int x = 0, int y = 0, TextSettings settings = null) { if (string.IsNullOrWhiteSpace(text)) { return(bitmap); } if (settings == null) { if (bitmap is IDefaultTextSettings) { settings = (bitmap as IDefaultTextSettings).DefaultTextSettings; } else { settings = new TextSettings(); } } Size textSize = Resources.GetTextSize(settings.FontId, text); Bytemap textLayer; if (settings.FirstLetterColour != 0) { textLayer = Resources.GetText(text, settings.FontId, settings.FirstLetterColour, settings.Colour).Bitmap; } else if (settings.TopColour != 0 && settings.BottomColour != 0) { textLayer = new Picture(textSize.Width, textSize.Height + 2) .AddLayer(Resources.GetText(text, settings.FontId, settings.TopColour)) .AddLayer(Resources.GetText(text, settings.FontId, settings.BottomColour), top: 2) .AddLayer(Resources.GetText(text, settings.FontId, settings.Colour), top: 1) .Bitmap; } else if (settings.BottomColour != 0) { textLayer = new Picture(textSize.Width, textSize.Height + 1) .AddLayer(Resources.GetText(text, settings.FontId, settings.BottomColour), top: 1) .AddLayer(Resources.GetText(text, settings.FontId, settings.Colour)) .Bitmap; } else { textLayer = Resources.GetText(text, settings.FontId, settings.Colour).Bitmap; } switch (settings.Alignment) { case Center: x -= (textLayer.Width + 1) / 2; break; case Right: x -= textLayer.Width; break; } if (settings.VerticalAlignment == Bottom) { y -= Resources.GetFontHeight(settings.FontId); } AddLayer(bitmap, textLayer, x, y, dispose: true); return(bitmap); }
public static IBitmap City(City city, bool smallFont = false) { IBitmap output = new Picture(16, 16); TextSettings settings = new TextSettings() { FontId = smallFont ? 1 : 0, Alignment = TextAlign.Center }; if (city.Tile.Units.Length > 0) { output.FillRectangle(0, 0, 16, 16, 5); } output.FillRectangle(1, 1, 14, 14, 15) .FillRectangle(2, 1, 13, 13, Common.ColourDark[city.Owner]) .FillRectangle(2, 2, 12, 12, Common.ColourLight[city.Owner]); IBitmap resource; if (Resources.Exists("SP257")) { resource = Resources["SP257"][192, 112, 16, 16]; } else { resource = new Picture(Free.Instance.City, Common.GetPalette256); } resource .ColourReplace(3, 0) .ColourReplace(5, Common.ColourDark[city.Owner]); if (city.IsInDisorder) { output.AddLayer(resource, 0, 0) .AddLayer(Icons.Citizen(Enums.Citizen.UnhappyMale), 5, 1); } else { output.AddLayer(resource, 0, 0) .DrawText($"{city.Size}", (smallFont ? 1 : 0), 5, 9, 5, TextAlign.Center); } resource?.Dispose(); if (city.HasBuilding <CityWalls>()) { output.AddLayer(Generic.Fortify, 0, 0); } return(output); }