Refactor ASCII rasterizer to support terminal ANSI mode and improve menu text rendering
Signed-off-by: Hans Kokx <hans.d.kokx@gmail.com>
This commit is contained in:
@@ -43,6 +43,55 @@ abstract class WolfMenuPic {
|
||||
];
|
||||
}
|
||||
|
||||
/// Shared menu text colors resolved from the VGA palette.
|
||||
///
|
||||
/// Keep menu color choices centralized so renderers don't duplicate
|
||||
/// hard-coded palette slots or RGB conversion logic.
|
||||
abstract class WolfMenuPalette {
|
||||
static const int selectedTextIndex = 19;
|
||||
static const int unselectedTextIndex = 23;
|
||||
static const int _headerTargetRgb = 0xFFF700;
|
||||
|
||||
static int? _cachedHeaderTextIndex;
|
||||
|
||||
static int get headerTextIndex =>
|
||||
_cachedHeaderTextIndex ??= _nearestPaletteIndex(_headerTargetRgb);
|
||||
|
||||
static int get selectedTextColor => ColorPalette.vga32Bit[selectedTextIndex];
|
||||
|
||||
static int get unselectedTextColor =>
|
||||
ColorPalette.vga32Bit[unselectedTextIndex];
|
||||
|
||||
static int get headerTextColor => ColorPalette.vga32Bit[headerTextIndex];
|
||||
|
||||
static int _nearestPaletteIndex(int rgb) {
|
||||
final int targetR = (rgb >> 16) & 0xFF;
|
||||
final int targetG = (rgb >> 8) & 0xFF;
|
||||
final int targetB = rgb & 0xFF;
|
||||
|
||||
int bestIndex = 0;
|
||||
int bestDistance = 1 << 30;
|
||||
|
||||
for (int i = 0; i < 256; i++) {
|
||||
final int color = ColorPalette.vga32Bit[i];
|
||||
final int r = color & 0xFF;
|
||||
final int g = (color >> 8) & 0xFF;
|
||||
final int b = (color >> 16) & 0xFF;
|
||||
|
||||
final int dr = targetR - r;
|
||||
final int dg = targetG - g;
|
||||
final int db = targetB - b;
|
||||
final int distance = (dr * dr) + (dg * dg) + (db * db);
|
||||
if (distance < bestDistance) {
|
||||
bestDistance = distance;
|
||||
bestIndex = i;
|
||||
}
|
||||
}
|
||||
|
||||
return bestIndex;
|
||||
}
|
||||
}
|
||||
|
||||
/// Structured accessors for classic Wolf3D menu art.
|
||||
class WolfClassicMenuArt {
|
||||
final WolfensteinData data;
|
||||
|
||||
Reference in New Issue
Block a user