feat: Refactor color handling in NoGameDataScreen and ColorPalette for improved clarity and maintainability
Signed-off-by: Hans Kokx <hans.d.kokx@gmail.com>
This commit is contained in:
@@ -262,6 +262,19 @@ abstract class ColorPalette {
|
||||
0xFF890099,
|
||||
]);
|
||||
|
||||
/// Converts a VGA palette index to a packed 32-bit ARGB color.
|
||||
///
|
||||
/// Internally, [vga32Bit] stores channel bytes in ABGR order for renderer
|
||||
/// pipelines that write raw bytes directly. This helper returns standard
|
||||
/// ARGB (`0xAARRGGBB`) for APIs that expect Flutter/Dart UI color packing.
|
||||
static int argbFromVgaIndex(int index) {
|
||||
final int packed = vga32Bit[index];
|
||||
final int r = packed & 0xFF;
|
||||
final int g = (packed >> 8) & 0xFF;
|
||||
final int b = (packed >> 16) & 0xFF;
|
||||
return (0xFF << 24) | (r << 16) | (g << 8) | b;
|
||||
}
|
||||
|
||||
static int findClosestPaletteIndex(int argb) {
|
||||
final int targetR = (argb >> 16) & 0xFF;
|
||||
final int targetG = (argb >> 8) & 0xFF;
|
||||
|
||||
@@ -49,6 +49,13 @@ abstract class WolfMenuPic {
|
||||
/// Keep menu color choices centralized so renderers don't duplicate
|
||||
/// hard-coded palette slots or RGB conversion logic.
|
||||
abstract class WolfMenuPalette {
|
||||
static const int backgroundIndex = 111;
|
||||
static const int panelIndex = 103;
|
||||
static const int borderIndex = 87;
|
||||
static const int emphasisIndex = 10;
|
||||
static const int warningIndex = 14;
|
||||
static const int mutedIndex = 8;
|
||||
|
||||
static const int selectedTextIndex = 19;
|
||||
static const int unselectedTextIndex = 23;
|
||||
static const int disabledTextIndex = 4;
|
||||
@@ -56,8 +63,8 @@ abstract class WolfMenuPalette {
|
||||
|
||||
static int? _cachedHeaderTextIndex;
|
||||
|
||||
static int get headerTextIndex =>
|
||||
_cachedHeaderTextIndex ??= _nearestPaletteIndex(_headerTargetRgb);
|
||||
static int get headerTextIndex => _cachedHeaderTextIndex ??=
|
||||
ColorPalette.findClosestPaletteIndex(_headerTargetRgb);
|
||||
|
||||
static int get selectedTextColor => ColorPalette.vga32Bit[selectedTextIndex];
|
||||
|
||||
@@ -67,33 +74,6 @@ abstract class WolfMenuPalette {
|
||||
static int get disabledTextColor => ColorPalette.vga32Bit[disabledTextIndex];
|
||||
|
||||
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.
|
||||
|
||||
Reference in New Issue
Block a user