(svn r6222) Remove struct ColorList, because the names of its attributes are plain confusing

All the struct holds is a simple colour gradient, so using a simple array with 8 entries is more clear
Also add the names of colour the gradients as enum
pull/155/head
tron 18 years ago
parent 7ea68d68a6
commit dae76ce67e

33
gfx.h

@ -5,13 +5,6 @@
typedef byte Pixel; typedef byte Pixel;
typedef struct ColorList {
byte unk0, unk1, unk2;
byte window_color_1a, window_color_1b;
byte window_color_bga, window_color_bgb;
byte window_color_2;
} ColorList;
struct DrawPixelInfo { struct DrawPixelInfo {
Pixel *dst_ptr; Pixel *dst_ptr;
int left, top, width, height; int left, top, width, height;
@ -122,9 +115,33 @@ static inline byte GetCharacterHeight(FontSize size)
VARDEF DrawPixelInfo _screen; VARDEF DrawPixelInfo _screen;
VARDEF DrawPixelInfo *_cur_dpi; VARDEF DrawPixelInfo *_cur_dpi;
VARDEF ColorList _color_list[16];
VARDEF CursorVars _cursor; VARDEF CursorVars _cursor;
enum {
COLOUR_DARK_BLUE,
COLOUR_PALE_GREEN,
COLOUR_PINK,
COLOUR_YELLOW,
COLOUR_RED,
COLOUR_LIGHT_BLUE,
COLOUR_GREEN,
COLOUR_DARK_GREEN,
COLOUR_BLUE,
COLOUR_CREAM,
COLOUR_MAUVE,
COLOUR_PURPLE,
COLOUR_ORANGE,
COLOUR_BROWN,
COLOUR_GREY,
COLOUR_WHITE
};
/**
* All 16 colour gradients
* 8 colours per gradient from darkest (0) to lightest (7)
*/
VARDEF byte _colour_gradient[16][8];
VARDEF int _pal_first_dirty; VARDEF int _pal_first_dirty;
VARDEF int _pal_last_dirty; VARDEF int _pal_last_dirty;

@ -65,7 +65,7 @@ static void DrawGraph(const GraphDrawer *gw)
* both values for cargo and players. So if any are higher, quit */ * both values for cargo and players. So if any are higher, quit */
assert(GRAPH_NUM >= NUM_CARGO && GRAPH_NUM >= MAX_PLAYERS); assert(GRAPH_NUM >= NUM_CARGO && GRAPH_NUM >= MAX_PLAYERS);
color = _color_list[gw->bg_line_color].window_color_1b; color = _colour_gradient[gw->bg_line_color][4];
/* draw the vertical lines */ /* draw the vertical lines */
i = gw->num_vert_lines; assert(i > 0); i = gw->num_vert_lines; assert(i > 0);
@ -344,7 +344,7 @@ static void OperatingProfitWndProc(Window *w, WindowEvent *e)
numd = 0; numd = 0;
FOR_ALL_PLAYERS(p) { FOR_ALL_PLAYERS(p) {
if (p->is_active) { if (p->is_active) {
gd.colors[numd] = _color_list[p->player_color].window_color_bgb; gd.colors[numd] = _colour_gradient[p->player_color][6];
for (j = gd.num_on_x_axis, i = 0; --j >= 0;) { for (j = gd.num_on_x_axis, i = 0; --j >= 0;) {
gd.cost[numd][i] = (j >= p->num_valid_stat_ent) ? INVALID_VALUE : (uint64)(p->old_economy[j].income + p->old_economy[j].expenses); gd.cost[numd][i] = (j >= p->num_valid_stat_ent) ? INVALID_VALUE : (uint64)(p->old_economy[j].income + p->old_economy[j].expenses);
i++; i++;
@ -417,7 +417,7 @@ static void IncomeGraphWndProc(Window *w, WindowEvent *e)
numd = 0; numd = 0;
FOR_ALL_PLAYERS(p) { FOR_ALL_PLAYERS(p) {
if (p->is_active) { if (p->is_active) {
gd.colors[numd] = _color_list[p->player_color].window_color_bgb; gd.colors[numd] = _colour_gradient[p->player_color][6];
for (j = gd.num_on_x_axis, i = 0; --j >= 0;) { for (j = gd.num_on_x_axis, i = 0; --j >= 0;) {
gd.cost[numd][i] = (j >= p->num_valid_stat_ent) ? INVALID_VALUE : (uint64)p->old_economy[j].income; gd.cost[numd][i] = (j >= p->num_valid_stat_ent) ? INVALID_VALUE : (uint64)p->old_economy[j].income;
i++; i++;
@ -490,7 +490,7 @@ static void DeliveredCargoGraphWndProc(Window *w, WindowEvent *e)
numd = 0; numd = 0;
FOR_ALL_PLAYERS(p) { FOR_ALL_PLAYERS(p) {
if (p->is_active) { if (p->is_active) {
gd.colors[numd] = _color_list[p->player_color].window_color_bgb; gd.colors[numd] = _colour_gradient[p->player_color][6];
for (j = gd.num_on_x_axis, i = 0; --j >= 0;) { for (j = gd.num_on_x_axis, i = 0; --j >= 0;) {
gd.cost[numd][i] = (j >= p->num_valid_stat_ent) ? INVALID_VALUE : (uint64)p->old_economy[j].delivered_cargo; gd.cost[numd][i] = (j >= p->num_valid_stat_ent) ? INVALID_VALUE : (uint64)p->old_economy[j].delivered_cargo;
i++; i++;
@ -563,7 +563,7 @@ static void PerformanceHistoryWndProc(Window *w, WindowEvent *e)
numd = 0; numd = 0;
FOR_ALL_PLAYERS(p) { FOR_ALL_PLAYERS(p) {
if (p->is_active) { if (p->is_active) {
gd.colors[numd] = _color_list[p->player_color].window_color_bgb; gd.colors[numd] = _colour_gradient[p->player_color][6];
for (j = gd.num_on_x_axis, i = 0; --j >= 0;) { for (j = gd.num_on_x_axis, i = 0; --j >= 0;) {
gd.cost[numd][i] = (j >= p->num_valid_stat_ent) ? INVALID_VALUE : (uint64)p->old_economy[j].performance_history; gd.cost[numd][i] = (j >= p->num_valid_stat_ent) ? INVALID_VALUE : (uint64)p->old_economy[j].performance_history;
i++; i++;
@ -639,7 +639,7 @@ static void CompanyValueGraphWndProc(Window *w, WindowEvent *e)
numd = 0; numd = 0;
FOR_ALL_PLAYERS(p) { FOR_ALL_PLAYERS(p) {
if (p->is_active) { if (p->is_active) {
gd.colors[numd] = _color_list[p->player_color].window_color_bgb; gd.colors[numd] = _colour_gradient[p->player_color][6];
for (j = gd.num_on_x_axis, i = 0; --j >= 0;) { for (j = gd.num_on_x_axis, i = 0; --j >= 0;) {
gd.cost[numd][i] = (j >= p->num_valid_stat_ent) ? INVALID_VALUE : (uint64)p->old_economy[j].company_value; gd.cost[numd][i] = (j >= p->num_valid_stat_ent) ? INVALID_VALUE : (uint64)p->old_economy[j].company_value;
i++; i++;
@ -923,8 +923,8 @@ static void PerformanceRatingDetailWndProc(Window *w, WindowEvent *e)
} }
// The colors used to show how the progress is going // The colors used to show how the progress is going
color_done = _color_list[6].window_color_1b; color_done = _colour_gradient[COLOUR_GREEN][4];
color_notdone = _color_list[4].window_color_1b; color_notdone = _colour_gradient[COLOUR_RED][4];
// Draw all the score parts // Draw all the score parts
for (i = 0; i < NUM_SCORE; i++) { for (i = 0; i < NUM_SCORE; i++) {

@ -2349,7 +2349,7 @@ void SetupColorsAndInitialWindow(void)
const byte *b = GetNonSprite(PALETTE_RECOLOR_START + i); const byte *b = GetNonSprite(PALETTE_RECOLOR_START + i);
assert(b); assert(b);
_color_list[i] = *(const ColorList*)(b + 0xC6); memcpy(_colour_gradient[i], b + 0xC6, sizeof(_colour_gradient[i]));
} }
width = _screen.width; width = _screen.width;

@ -34,7 +34,7 @@ uint16 GetDrawStringPlayerColor(PlayerID player)
* player * player
*/ */
if (player == OWNER_SPECTATOR || player == OWNER_SPECTATOR - 1) return 1; if (player == OWNER_SPECTATOR || player == OWNER_SPECTATOR - 1) return 1;
return (_color_list[_player_colors[player]].window_color_1b) | IS_PALETTE_COLOR; return (_colour_gradient[_player_colors[player]][4]) | IS_PALETTE_COLOR;
} }

@ -413,7 +413,7 @@ static void GameDifficultyWndProc(Window *w, WindowEvent *e)
DrawFrameRect( 5, y, 5 + 8, y + 8, 3, GetBitAndShift(&click_a) ? FR_LOWERED : 0); DrawFrameRect( 5, y, 5 + 8, y + 8, 3, GetBitAndShift(&click_a) ? FR_LOWERED : 0);
DrawFrameRect(15, y, 15 + 8, y + 8, 3, GetBitAndShift(&click_b) ? FR_LOWERED : 0); DrawFrameRect(15, y, 15 + 8, y + 8, 3, GetBitAndShift(&click_b) ? FR_LOWERED : 0);
if (GetBitAndShift(&disabled) || (_networking && !_network_server)) { if (GetBitAndShift(&disabled) || (_networking && !_network_server)) {
int color = PALETTE_MODIFIER_GREYOUT | _color_list[3].unk2; int color = PALETTE_MODIFIER_GREYOUT | _colour_gradient[COLOUR_YELLOW][2];
GfxFillRect( 6, y + 1, 6 + 8, y + 8, color); GfxFillRect( 6, y + 1, 6 + 8, y + 8, color);
GfxFillRect(16, y + 1, 16 + 8, y + 8, color); GfxFillRect(16, y + 1, 16 + 8, y + 8, color);
} }
@ -1061,7 +1061,7 @@ void ShowNewgrf(void)
*/ */
void DrawArrowButtons(int x, int y, int ctab, byte state, bool clickable_left, bool clickable_right) void DrawArrowButtons(int x, int y, int ctab, byte state, bool clickable_left, bool clickable_right)
{ {
int color = PALETTE_MODIFIER_GREYOUT | _color_list[3].unk2; int color = PALETTE_MODIFIER_GREYOUT | _colour_gradient[COLOUR_YELLOW][2];
DrawFrameRect(x, y + 1, x + 9, y + 9, ctab, (state == 1) ? FR_LOWERED : 0); DrawFrameRect(x, y + 1, x + 9, y + 9, ctab, (state == 1) ? FR_LOWERED : 0);
DrawFrameRect(x + 10, y + 1, x + 19, y + 9, ctab, (state == 2) ? FR_LOWERED : 0); DrawFrameRect(x + 10, y + 1, x + 19, y + 9, ctab, (state == 2) ? FR_LOWERED : 0);

@ -1166,7 +1166,7 @@ static void ViewportDrawStrings(DrawPixelInfo *dpi, const StringSpriteToDraw *ss
* otherwise colors from _string_colormap are assumed. */ * otherwise colors from _string_colormap are assumed. */
DrawString( DrawString(
ss->x >> zoom, (ss->y >> zoom) - (ss->width & 0x8000 ? 2 : 0), ss->x >> zoom, (ss->y >> zoom) - (ss->width & 0x8000 ? 2 : 0),
ss->string, (_color_list[ss->color].window_color_bgb | IS_PALETTE_COLOR) ss->string, _colour_gradient[ss->color][6] | IS_PALETTE_COLOR
); );
} else { } else {
DrawString( DrawString(

@ -152,10 +152,10 @@ int GetWidgetFromPos(const Window *w, int x, int y)
void DrawFrameRect(int left, int top, int right, int bottom, int ctab, FrameFlags flags) void DrawFrameRect(int left, int top, int right, int bottom, int ctab, FrameFlags flags)
{ {
uint dark = _color_list[ctab].window_color_1a; uint dark = _colour_gradient[ctab][3];
uint medium_dark = _color_list[ctab].window_color_bga; uint medium_dark = _colour_gradient[ctab][5];
uint medium_light = _color_list[ctab].window_color_bgb; uint medium_light = _colour_gradient[ctab][6];
uint light = _color_list[ctab].window_color_2; uint light = _colour_gradient[ctab][7];
if (flags & FR_TRANSPARENT) { if (flags & FR_TRANSPARENT) {
GfxFillRect(left, top, right, bottom, 0x322 | USE_COLORTABLE); GfxFillRect(left, top, right, bottom, 0x322 | USE_COLORTABLE);
@ -261,7 +261,7 @@ void DrawWindowWidgets(const Window *w)
d = GB(wi->unkA, 8, 8); d = GB(wi->unkA, 8, 8);
amt2 = (wi->bottom - wi->top + 1) / d; amt2 = (wi->bottom - wi->top + 1) / d;
color = _color_list[wi->color & 0xF].window_color_bgb; color = _colour_gradient[wi->color & 0xF][6];
x = r.left; x = r.left;
for (ctr = c; ctr > 1; ctr--) { for (ctr = c; ctr > 1; ctr--) {
@ -275,7 +275,7 @@ void DrawWindowWidgets(const Window *w)
GfxFillRect(r.left + 1, x, r.right - 1, x, color); GfxFillRect(r.left + 1, x, r.right - 1, x, color);
} }
color = _color_list[wi->color&0xF].window_color_1b; color = _colour_gradient[wi->color&0xF][4];
x = r.left - 1; x = r.left - 1;
for (ctr = c; ctr > 1; ctr--) { for (ctr = c; ctr > 1; ctr--) {
@ -308,8 +308,8 @@ void DrawWindowWidgets(const Window *w)
DrawFrameRect(r.left, r.bottom - 9, r.right, r.bottom, wi->color, (clicked) ? FR_LOWERED : 0); DrawFrameRect(r.left, r.bottom - 9, r.right, r.bottom, wi->color, (clicked) ? FR_LOWERED : 0);
DoDrawString(DOWNARROW, r.left + 2 + clicked, r.bottom - 9 + clicked, 0x10); DoDrawString(DOWNARROW, r.left + 2 + clicked, r.bottom - 9 + clicked, 0x10);
c1 = _color_list[wi->color&0xF].window_color_1a; c1 = _colour_gradient[wi->color&0xF][3];
c2 = _color_list[wi->color&0xF].window_color_2; c2 = _colour_gradient[wi->color&0xF][7];
// draw "shaded" background // draw "shaded" background
GfxFillRect(r.left, r.top+10, r.right, r.bottom-10, c2); GfxFillRect(r.left, r.top+10, r.right, r.bottom-10, c2);
@ -340,8 +340,8 @@ void DrawWindowWidgets(const Window *w)
DrawFrameRect(r.left, r.bottom - 9, r.right, r.bottom, wi->color, (clicked) ? FR_LOWERED : 0); DrawFrameRect(r.left, r.bottom - 9, r.right, r.bottom, wi->color, (clicked) ? FR_LOWERED : 0);
DoDrawString(DOWNARROW, r.left + 2 + clicked, r.bottom - 9 + clicked, 0x10); DoDrawString(DOWNARROW, r.left + 2 + clicked, r.bottom - 9 + clicked, 0x10);
c1 = _color_list[wi->color&0xF].window_color_1a; c1 = _colour_gradient[wi->color&0xF][3];
c2 = _color_list[wi->color&0xF].window_color_2; c2 = _colour_gradient[wi->color&0xF][7];
// draw "shaded" background // draw "shaded" background
GfxFillRect(r.left, r.top+10, r.right, r.bottom-10, c2); GfxFillRect(r.left, r.top+10, r.right, r.bottom-10, c2);
@ -373,8 +373,8 @@ void DrawWindowWidgets(const Window *w)
DrawFrameRect(r.right-9, r.top, r.right, r.bottom, wi->color, (clicked) ? FR_LOWERED : 0); DrawFrameRect(r.right-9, r.top, r.right, r.bottom, wi->color, (clicked) ? FR_LOWERED : 0);
DrawSprite(SPR_ARROW_RIGHT, r.right - 8 + clicked, r.top + 1 + clicked); DrawSprite(SPR_ARROW_RIGHT, r.right - 8 + clicked, r.top + 1 + clicked);
c1 = _color_list[wi->color&0xF].window_color_1a; c1 = _colour_gradient[wi->color&0xF][3];
c2 = _color_list[wi->color&0xF].window_color_2; c2 = _colour_gradient[wi->color&0xF][7];
// draw "shaded" background // draw "shaded" background
GfxFillRect(r.left+10, r.top, r.right-10, r.bottom, c2); GfxFillRect(r.left+10, r.top, r.right-10, r.bottom, c2);
@ -399,8 +399,8 @@ void DrawWindowWidgets(const Window *w)
if (wi->unkA != 0) x2 = DrawString(r.left + 6, r.top, wi->unkA, 0); if (wi->unkA != 0) x2 = DrawString(r.left + 6, r.top, wi->unkA, 0);
c1 = _color_list[wi->color].window_color_1a; c1 = _colour_gradient[wi->color][3];
c2 = _color_list[wi->color].window_color_2; c2 = _colour_gradient[wi->color][7];
//Line from upper left corner to start of text //Line from upper left corner to start of text
GfxFillRect(r.left, r.top+4, r.left+4,r.top+4, c1); GfxFillRect(r.left, r.top+4, r.left+4,r.top+4, c1);
@ -456,13 +456,13 @@ void DrawWindowWidgets(const Window *w)
DrawFrameRect(r.left+1, r.top+1, r.right-1, r.bottom-1, wi->color, (w->caption_color == 0xFF) ? FR_LOWERED | FR_DARKENED : FR_LOWERED | FR_DARKENED | FR_BORDERONLY); DrawFrameRect(r.left+1, r.top+1, r.right-1, r.bottom-1, wi->color, (w->caption_color == 0xFF) ? FR_LOWERED | FR_DARKENED : FR_LOWERED | FR_DARKENED | FR_BORDERONLY);
if (w->caption_color != 0xFF) { if (w->caption_color != 0xFF) {
GfxFillRect(r.left+2, r.top+2, r.right-2, r.bottom-2, _color_list[_player_colors[w->caption_color]].window_color_1b); GfxFillRect(r.left+2, r.top+2, r.right-2, r.bottom-2, _colour_gradient[_player_colors[w->caption_color]][4]);
} }
DrawStringCentered( (r.left+r.right+1)>>1, r.top+2, wi->unkA, 0x84); DrawStringCentered( (r.left+r.right+1)>>1, r.top+2, wi->unkA, 0x84);
draw_default:; draw_default:;
if (cur_disabled & 1) { if (cur_disabled & 1) {
GfxFillRect(r.left+1, r.top+1, r.right-1, r.bottom-1, _color_list[wi->color&0xF].unk2 | PALETTE_MODIFIER_GREYOUT); GfxFillRect(r.left+1, r.top+1, r.right-1, r.bottom-1, _colour_gradient[wi->color&0xF][2] | PALETTE_MODIFIER_GREYOUT);
} }
} }
} }
@ -530,12 +530,12 @@ static void DropdownMenuWndProc(Window *w, WindowEvent *e)
if (HASBIT(WP(w,dropdown_d).disabled_state, i)) { if (HASBIT(WP(w,dropdown_d).disabled_state, i)) {
GfxFillRect(x, y, x + w->width - 3, y + 9, GfxFillRect(x, y, x + w->width - 3, y + 9,
PALETTE_MODIFIER_GREYOUT | _color_list[_dropdown_menu_widgets[0].color].window_color_bga PALETTE_MODIFIER_GREYOUT | _colour_gradient[_dropdown_menu_widgets[0].color][5]
); );
} }
} else { } else {
int c1 = _color_list[_dropdown_menu_widgets[0].color].window_color_1a; int c1 = _colour_gradient[_dropdown_menu_widgets[0].color][3];
int c2 = _color_list[_dropdown_menu_widgets[0].color].window_color_2; int c2 = _colour_gradient[_dropdown_menu_widgets[0].color][7];
GfxFillRect(x + 1, y + 3, x + w->width - 5, y + 3, c1); GfxFillRect(x + 1, y + 3, x + w->width - 5, y + 3, c1);
GfxFillRect(x + 1, y + 4, x + w->width - 5, y + 4, c2); GfxFillRect(x + 1, y + 4, x + w->width - 5, y + 4, c2);

Loading…
Cancel
Save