NHDT->ANH, nethack->anethack, nhdat->anhdat
[aNetHack.git] / sys / wince / mhcolor.c
blob4a6e9ff7ae201fd5b7877ab0315c5b498e22261c
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 */
7 #include "winMS.h"
8 #include "mhcolor.h"
10 #define TOTAL_BRUSHES 10
11 #define NHBRUSH_CODE(win, type) ((((win) &0xFF) << 8) | ((type) &0xFF))
13 struct t_brush_table {
14 int code;
15 HBRUSH brush;
16 COLORREF color;
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,
39 COLORREF *colorptr);
41 typedef struct ctv {
42 const char *colorstring;
43 COLORREF colorvalue;
44 } color_table_value;
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[] = {
53 /* aNetHack colors */
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) },
84 typedef struct ctbv {
85 char *colorstring;
86 int syscolorvalue;
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 },
110 { "", -1 },
113 void
114 mswin_init_color_table()
116 int i;
117 struct t_brush_table *p;
119 /* cleanup */
120 for (i = 0; i < max_brush; i++)
121 DeleteObject(brush_table[i].brush);
122 max_brush = 0;
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); \
129 max_brush++;
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;
157 HBRUSH
158 mswin_get_brush(int win_type, int color_index)
160 int i;
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;
164 return NULL;
167 COLORREF
168 mswin_get_color(int win_type, int color_index)
170 int i;
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;
174 return RGB(0, 0, 0);
177 static void
178 mswin_color_from_string(char *colorstring, HBRUSH *brushptr,
179 COLORREF *colorptr)
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";
186 *brushptr = NULL;
187 *colorptr = RGB(0, 0, 0);
189 if (colorstring == NULL)
190 return;
191 if (*colorstring == '#') {
192 if (strlen(++colorstring) != 6)
193 return;
195 red_value =
196 index(hexadecimals, tolower(*colorstring++)) - hexadecimals;
197 red_value *= 16;
198 red_value +=
199 index(hexadecimals, tolower(*colorstring++)) - hexadecimals;
201 green_value =
202 index(hexadecimals, tolower(*colorstring++)) - hexadecimals;
203 green_value *= 16;
204 green_value +=
205 index(hexadecimals, tolower(*colorstring++)) - hexadecimals;
207 blue_value =
208 index(hexadecimals, tolower(*colorstring++)) - hexadecimals;
209 blue_value *= 16;
210 blue_value +=
211 index(hexadecimals, tolower(*colorstring++)) - hexadecimals;
213 *colorptr = RGB(red_value, blue_value, green_value);
214 } else {
215 while (*ctv_ptr->colorstring
216 && _stricmp(ctv_ptr->colorstring, colorstring))
217 ++ctv_ptr;
218 if (*ctv_ptr->colorstring) {
219 *colorptr = ctv_ptr->colorvalue;
220 } else {
221 while (*ctbv_ptr->colorstring
222 && _stricmp(ctbv_ptr->colorstring, colorstring))
223 ++ctbv_ptr;
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);