1 /* aNetHack 0.0.1 mhcolor.c $ANH-Date: 1432512802 2015/05/25 00:13:22 $ $ANH-Branch: master $:$ANH-Revision: 1.7 $ */
2 /* Copyright (C) 2001 by Alex Kompel */
3 /* aNetHack may be freely redistributed. See license for details. */
5 /* color management and such */
10 #define TOTAL_BRUSHES 10
11 #define NHBRUSH_CODE(win, type) ((((win) &0xFF) << 8) | ((type) &0xFF))
13 struct t_brush_table
{
18 static struct t_brush_table brush_table
[TOTAL_BRUSHES
];
19 static int max_brush
= 0;
21 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
,
42 const char *colorstring
;
47 * The color list here is a combination of:
48 * aNetHack 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) }, /* = aNetHack magenta */
76 { "lime", RGB(0x00, 0xFF, 0x00) }, /* = aNetHack 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) }, /* = aNetHack cyan */
81 { "", RGB(0x00, 0x00, 0x00) },
87 } color_table_brush_value
;
89 static color_table_brush_value color_table_brush
[] = {
90 { "activeborder", COLOR_ACTIVEBORDER
},
91 { "activecaption", COLOR_ACTIVECAPTION
},
92 { "appworkspace", COLOR_APPWORKSPACE
},
93 { "background", COLOR_BACKGROUND
},
94 { "btnface", COLOR_BTNFACE
},
95 { "btnshadow", COLOR_BTNSHADOW
},
96 { "btntext", COLOR_BTNTEXT
},
97 { "captiontext", COLOR_CAPTIONTEXT
},
98 { "graytext", COLOR_GRAYTEXT
},
99 { "greytext", COLOR_GRAYTEXT
},
100 { "highlight", COLOR_HIGHLIGHT
},
101 { "highlighttext", COLOR_HIGHLIGHTTEXT
},
102 { "inactiveborder", COLOR_INACTIVEBORDER
},
103 { "inactivecaption", COLOR_INACTIVECAPTION
},
104 { "menu", COLOR_MENU
},
105 { "menutext", COLOR_MENUTEXT
},
106 { "scrollbar", COLOR_SCROLLBAR
},
107 { "window", COLOR_WINDOW
},
108 { "windowframe", COLOR_WINDOWFRAME
},
109 { "windowtext", COLOR_WINDOWTEXT
},
114 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, \
128 &brush_table[max_brush].color); \
131 BRUSHTABLE_ENTRY(iflags
.wc_foregrnd_menu
, NHW_MENU
, MSWIN_COLOR_FG
);
132 BRUSHTABLE_ENTRY(iflags
.wc_foregrnd_message
, NHW_MESSAGE
, MSWIN_COLOR_FG
);
133 BRUSHTABLE_ENTRY(iflags
.wc_foregrnd_status
, NHW_STATUS
, MSWIN_COLOR_FG
);
134 BRUSHTABLE_ENTRY(iflags
.wc_foregrnd_text
, NHW_TEXT
, MSWIN_COLOR_FG
);
135 BRUSHTABLE_ENTRY(iflags
.wc_foregrnd_message
, NHW_KEYPAD
, MSWIN_COLOR_FG
);
137 BRUSHTABLE_ENTRY(iflags
.wc_backgrnd_menu
, NHW_MENU
, MSWIN_COLOR_BG
);
138 BRUSHTABLE_ENTRY(iflags
.wc_backgrnd_message
, NHW_MESSAGE
, MSWIN_COLOR_BG
);
139 BRUSHTABLE_ENTRY(iflags
.wc_backgrnd_status
, NHW_STATUS
, MSWIN_COLOR_BG
);
140 BRUSHTABLE_ENTRY(iflags
.wc_backgrnd_text
, NHW_TEXT
, MSWIN_COLOR_BG
);
141 BRUSHTABLE_ENTRY(iflags
.wc_backgrnd_message
, NHW_KEYPAD
, MSWIN_COLOR_BG
);
142 #undef BRUSHTABLE_ENTRY
144 /* go through the values and fill in "blanks" (use default values) */
145 for (i
= 0; i
< max_brush
; i
++) {
146 if (!brush_table
[i
].brush
) {
147 for (p
= default_brush_table
; p
->code
!= -1; p
++) {
148 if (p
->code
== brush_table
[i
].code
) {
149 brush_table
[i
].brush
= CreateSolidBrush(p
->color
);
150 brush_table
[i
].color
= p
->color
;
158 mswin_get_brush(int win_type
, int color_index
)
161 for (i
= 0; i
< max_brush
; i
++)
162 if (brush_table
[i
].code
== NHBRUSH_CODE(win_type
, color_index
))
163 return brush_table
[i
].brush
;
168 mswin_get_color(int win_type
, int color_index
)
171 for (i
= 0; i
< max_brush
; i
++)
172 if (brush_table
[i
].code
== NHBRUSH_CODE(win_type
, color_index
))
173 return brush_table
[i
].color
;
178 mswin_color_from_string(char *colorstring
, HBRUSH
*brushptr
,
181 color_table_value
*ctv_ptr
= color_table
;
182 color_table_brush_value
*ctbv_ptr
= color_table_brush
;
183 int red_value
, blue_value
, green_value
;
184 static char *hexadecimals
= "0123456789abcdef";
187 *colorptr
= RGB(0, 0, 0);
189 if (colorstring
== NULL
)
191 if (*colorstring
== '#') {
192 if (strlen(++colorstring
) != 6)
196 index(hexadecimals
, tolower(*colorstring
++)) - hexadecimals
;
199 index(hexadecimals
, tolower(*colorstring
++)) - hexadecimals
;
202 index(hexadecimals
, tolower(*colorstring
++)) - hexadecimals
;
205 index(hexadecimals
, tolower(*colorstring
++)) - hexadecimals
;
208 index(hexadecimals
, tolower(*colorstring
++)) - hexadecimals
;
211 index(hexadecimals
, tolower(*colorstring
++)) - hexadecimals
;
213 *colorptr
= RGB(red_value
, blue_value
, green_value
);
215 while (*ctv_ptr
->colorstring
216 && _stricmp(ctv_ptr
->colorstring
, colorstring
))
218 if (*ctv_ptr
->colorstring
) {
219 *colorptr
= ctv_ptr
->colorvalue
;
221 while (*ctbv_ptr
->colorstring
222 && _stricmp(ctbv_ptr
->colorstring
, colorstring
))
224 if (*ctbv_ptr
->colorstring
) {
225 *brushptr
= SYSCLR_TO_BRUSH(ctbv_ptr
->syscolorvalue
);
226 *colorptr
= GetSysColor(ctbv_ptr
->syscolorvalue
);
230 if (max_brush
> TOTAL_BRUSHES
)
231 panic("Too many colors!");
232 *brushptr
= CreateSolidBrush(*colorptr
);