1 /* Copyright (C) 2001 by Alex Kompel <shurikk@pacbell.net> */
2 /* NetHack may be freely redistributed. See license for details. */
4 /* color management and such */
9 #define TOTAL_BRUSHES 10
10 #define NHBRUSH_CODE(win, type) ((((win)&0xFF)<<8)|((type)&0xFF))
12 struct t_brush_table {
17 static struct t_brush_table brush_table[TOTAL_BRUSHES];
18 static int max_brush = 0;
20 static struct t_brush_table default_brush_table[] =
22 { NHBRUSH_CODE(NHW_STATUS, MSWIN_COLOR_FG), NULL, RGB(0, 0, 0) },
23 { NHBRUSH_CODE(NHW_MESSAGE, MSWIN_COLOR_FG), NULL, RGB(0, 0, 0) },
24 { NHBRUSH_CODE(NHW_STATUS, MSWIN_COLOR_FG), NULL, RGB(0, 0, 0) },
25 { NHBRUSH_CODE(NHW_TEXT, MSWIN_COLOR_FG), NULL, RGB(0, 0, 0) },
26 { NHBRUSH_CODE(NHW_KEYPAD, MSWIN_COLOR_FG), NULL, RGB(0, 0, 0) },
27 { NHBRUSH_CODE(NHW_MAP, MSWIN_COLOR_FG), NULL, RGB(96, 96, 96) },
29 { NHBRUSH_CODE(NHW_MENU, MSWIN_COLOR_BG), NULL, RGB(255, 255, 255) },
30 { NHBRUSH_CODE(NHW_MESSAGE, MSWIN_COLOR_BG), NULL, RGB(192, 192, 192) },
31 { NHBRUSH_CODE(NHW_STATUS, MSWIN_COLOR_BG), NULL, RGB(192, 192, 192) },
32 { NHBRUSH_CODE(NHW_TEXT, MSWIN_COLOR_BG), NULL, RGB(255, 255, 255) },
33 { NHBRUSH_CODE(NHW_KEYPAD, MSWIN_COLOR_BG), NULL, RGB(255, 255, 255) },
34 { NHBRUSH_CODE(NHW_MAP, MSWIN_COLOR_BG), NULL, RGB(192, 192, 192) },
35 { -1, NULL, RGB(0, 0, 0) }
38 static void mswin_color_from_string(char *colorstring, HBRUSH* brushptr, COLORREF *colorptr);
42 const char *colorstring;
47 * The color list here is a combination of:
48 * NetHack colors. (See mhmap.c)
49 * HTML colors. (See http://www.w3.org/TR/REC-html40/types.html#h-6.5 )
52 static color_table_value color_table[] = {
54 { "black", RGB(0x55, 0x55, 0x55)},
55 { "red", RGB(0xFF, 0x00, 0x00)},
56 { "green", RGB(0x00, 0x80, 0x00)},
57 { "brown", RGB(0xA5, 0x2A, 0x2A)},
58 { "blue", RGB(0x00, 0x00, 0xFF)},
59 { "magenta", RGB(0xFF, 0x00, 0xFF)},
60 { "cyan", RGB(0x00, 0xFF, 0xFF)},
61 { "orange", RGB(0xFF, 0xA5, 0x00)},
62 { "brightgreen", RGB(0x00, 0xFF, 0x00)},
63 { "yellow", RGB(0xFF, 0xFF, 0x00)},
64 { "brightblue", RGB(0x00, 0xC0, 0xFF)},
65 { "brightmagenta", RGB(0xFF, 0x80, 0xFF)},
66 { "brightcyan", RGB(0x80, 0xFF, 0xFF)},
67 { "white", RGB(0xFF, 0xFF, 0xFF)},
68 /* Remaining HTML colors */
69 { "trueblack", RGB(0x00, 0x00, 0x00)},
70 { "gray", RGB(0x80, 0x80, 0x80)},
71 { "grey", RGB(0x80, 0x80, 0x80)},
72 { "purple", RGB(0x80, 0x00, 0x80)},
73 { "silver", RGB(0xC0, 0xC0, 0xC0)},
74 { "maroon", RGB(0x80, 0x00, 0x00)},
75 { "fuchsia", RGB(0xFF, 0x00, 0xFF)}, /* = NetHack magenta */
76 { "lime", RGB(0x00, 0xFF, 0x00)}, /* = NetHack bright green */
77 { "olive", RGB(0x80, 0x80, 0x00)},
78 { "navy", RGB(0x00, 0x00, 0x80)},
79 { "teal", RGB(0x00, 0x80, 0x80)},
80 { "aqua", RGB(0x00, 0xFF, 0xFF)}, /* = NetHack cyan */
81 { "", RGB(0x00, 0x00, 0x00)},
88 } color_table_brush_value;
90 static color_table_brush_value color_table_brush[] = {
91 { "activeborder", COLOR_ACTIVEBORDER },
92 { "activecaption", COLOR_ACTIVECAPTION },
93 { "appworkspace", COLOR_APPWORKSPACE },
94 { "background", COLOR_BACKGROUND },
95 { "btnface", COLOR_BTNFACE },
96 { "btnshadow", COLOR_BTNSHADOW },
97 { "btntext", COLOR_BTNTEXT },
98 { "captiontext", COLOR_CAPTIONTEXT },
99 { "graytext", COLOR_GRAYTEXT },
100 { "greytext", COLOR_GRAYTEXT },
101 { "highlight", COLOR_HIGHLIGHT },
102 { "highlighttext", COLOR_HIGHLIGHTTEXT },
103 { "inactiveborder", COLOR_INACTIVEBORDER },
104 { "inactivecaption", COLOR_INACTIVECAPTION },
105 { "menu", COLOR_MENU },
106 { "menutext", COLOR_MENUTEXT },
107 { "scrollbar", COLOR_SCROLLBAR },
108 { "window", COLOR_WINDOW },
109 { "windowframe", COLOR_WINDOWFRAME },
110 { "windowtext", COLOR_WINDOWTEXT },
114 void mswin_init_color_table()
117 struct t_brush_table* p;
120 for( i=0; i<max_brush; i++ )
121 DeleteObject(brush_table[i].brush);
124 /* initialize brush table */
125 #define BRUSHTABLE_ENTRY(opt, win, type) \
126 brush_table[max_brush].code = NHBRUSH_CODE((win), (type)); \
127 mswin_color_from_string((opt), &brush_table[max_brush].brush, &brush_table[max_brush].color); \
130 BRUSHTABLE_ENTRY(iflags.wc_foregrnd_menu, NHW_MENU, MSWIN_COLOR_FG);
131 BRUSHTABLE_ENTRY(iflags.wc_foregrnd_message, NHW_MESSAGE, MSWIN_COLOR_FG);
132 BRUSHTABLE_ENTRY(iflags.wc_foregrnd_status, NHW_STATUS, MSWIN_COLOR_FG);
133 BRUSHTABLE_ENTRY(iflags.wc_foregrnd_text, NHW_TEXT, MSWIN_COLOR_FG);
134 BRUSHTABLE_ENTRY(iflags.wc_foregrnd_message, NHW_KEYPAD, MSWIN_COLOR_FG);
136 BRUSHTABLE_ENTRY(iflags.wc_backgrnd_menu, NHW_MENU, MSWIN_COLOR_BG);
137 BRUSHTABLE_ENTRY(iflags.wc_backgrnd_message, NHW_MESSAGE, MSWIN_COLOR_BG);
138 BRUSHTABLE_ENTRY(iflags.wc_backgrnd_status, NHW_STATUS, MSWIN_COLOR_BG);
139 BRUSHTABLE_ENTRY(iflags.wc_backgrnd_text, NHW_TEXT, MSWIN_COLOR_BG);
140 BRUSHTABLE_ENTRY(iflags.wc_backgrnd_message, NHW_KEYPAD, MSWIN_COLOR_BG);
141 #undef BRUSHTABLE_ENTRY
143 /* go through the values and fill in "blanks" (use default values) */
144 for( i=0; i<max_brush; i++ ) {
145 if( !brush_table[i].brush ) {
146 for( p = default_brush_table; p->code != -1; p++ ) {
147 if( p->code==brush_table[i].code ) {
148 brush_table[i].brush = CreateSolidBrush(p->color);
149 brush_table[i].color = p->color;
156 HBRUSH mswin_get_brush(int win_type, int color_index)
159 for(i=0; i<max_brush; i++)
160 if( brush_table[i].code == NHBRUSH_CODE(win_type, color_index) )
161 return brush_table[i].brush;
165 COLORREF mswin_get_color(int win_type, int color_index)
168 for(i=0; i<max_brush; i++)
169 if( brush_table[i].code == NHBRUSH_CODE(win_type, color_index) )
170 return brush_table[i].color;
174 static void mswin_color_from_string(char *colorstring, HBRUSH* brushptr, COLORREF *colorptr)
176 color_table_value *ctv_ptr = color_table;
177 color_table_brush_value *ctbv_ptr = color_table_brush;
178 int red_value, blue_value, green_value;
179 static char *hexadecimals = "0123456789abcdef";
182 *colorptr = RGB(0, 0, 0);
184 if (colorstring == NULL) return;
185 if (*colorstring == '#') {
186 if (strlen(++colorstring) != 6) return;
188 red_value = index(hexadecimals, tolower(*colorstring++)) - hexadecimals;
190 red_value += index(hexadecimals, tolower(*colorstring++)) - hexadecimals;
192 green_value = index(hexadecimals, tolower(*colorstring++)) - hexadecimals;
194 green_value += index(hexadecimals, tolower(*colorstring++)) - hexadecimals;
196 blue_value = index(hexadecimals, tolower(*colorstring++)) - hexadecimals;
198 blue_value += index(hexadecimals, tolower(*colorstring++)) - hexadecimals;
200 *colorptr = RGB(red_value, blue_value, green_value);
202 while (*ctv_ptr->colorstring && _stricmp(ctv_ptr->colorstring, colorstring))
204 if (*ctv_ptr->colorstring) {
205 *colorptr = ctv_ptr->colorvalue;
207 while (*ctbv_ptr->colorstring && _stricmp(ctbv_ptr->colorstring, colorstring))
209 if (*ctbv_ptr->colorstring) {
210 *brushptr = SYSCLR_TO_BRUSH(ctbv_ptr->syscolorvalue);
211 *colorptr = GetSysColor(ctbv_ptr->syscolorvalue);
215 if (max_brush > TOTAL_BRUSHES) panic("Too many colors!");
216 *brushptr = CreateSolidBrush(*colorptr);