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:
@@ -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