Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

properly compute colors for palette indexes above 15 in curses builds #76124

Merged
merged 1 commit into from
Sep 5, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 36 additions & 7 deletions src/cata_imgui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,39 @@ struct pairs {
short BG;
};

ImVec4 impalette[256] = {};
std::array<RGBTuple, color_loader<RGBTuple>::COLOR_NAMES_COUNT> rgbPalette;
std::array<pairs, 100> colorpairs; //storage for pair'ed colored
std::array<pairs, 100> colorpairs; //storage for paired colors

static ImVec4 compute_color( uint8_t index )
Maleclypse marked this conversation as resolved.
Show resolved Hide resolved
{
if( index < 16 ) {
RGBTuple &rgbCol = rgbPalette[index];
return { static_cast<float>( rgbCol.Red ) / 255.0f,
static_cast<float>( rgbCol.Green ) / 255.0f,
static_cast<float>( rgbCol.Blue ) / 255.0f,
1.0f };
} else if( index < 232 ) {
static uint8_t colors[6] = {0, 95, 135, 175, 215, 255};
Maleclypse marked this conversation as resolved.
Show resolved Hide resolved
int i = index - 16;
int r = i / 36;
i -= 36 * r;
int g = i / 6;
i -= 6 * g;
int b = i;
return { static_cast<float>( colors[r] ) / 255.0f,
static_cast<float>( colors[g] ) / 255.0f,
static_cast<float>( colors[b] ) / 255.0f,
1.0f };
} else {
static uint8_t gray[24] = {8, 18, 28, 38, 48, 58, 68, 78, 88, 98, 108, 118,
Maleclypse marked this conversation as resolved.
Show resolved Hide resolved
128, 138, 148, 158, 168, 178, 188, 198, 208, 218,
228, 238
};
float level = static_cast<float>( gray[index - 232] ) / 255.0f;
return { level, level, level, 1.0f };
}
}

ImVec4 cataimgui::imvec4_from_color( nc_color &color )
{
Expand All @@ -48,11 +79,7 @@ ImVec4 cataimgui::imvec4_from_color( nc_color &color )
if( color.is_bold() ) {
palette_index += color_loader<RGBTuple>::COLOR_NAMES_COUNT / 2;
}
RGBTuple &rgbCol = rgbPalette[palette_index];
return { static_cast<float>( rgbCol.Red / 255. ),
static_cast<float>( rgbCol.Green / 255. ),
static_cast<float>( rgbCol.Blue / 255. ),
static_cast<float>( 255. ) };
return impalette[palette_index];
}

std::vector<std::pair<int, ImTui::mouse_event>> imtui_events;
Expand Down Expand Up @@ -177,8 +204,10 @@ void cataimgui::client::process_input( void *input )

void cataimgui::load_colors()
{

color_loader<RGBTuple>().load( rgbPalette );
for( int i = 0; i < 256; i++ ) {
impalette[i] = compute_color( i );
}
}

void cataimgui::init_pair( int p, int f, int b )
Expand Down
Loading