1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116
|
// $Id: Colors.cc,v 1.3 2002/07/10 20:46:40 flaterco Exp $
/* Colors Manage XTide colors without X.
Copyright (C) 1998 David Flater.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#include "common.hh"
#include "rgb.hh"
char *colordesc[numcolors] = {
"Background color for text windows and location chooser.",
"Color of text and other notations.",
"Color of mark line in graphs and of stations in the location chooser.",
"Background color of buttons.",
"Daytime background color in tide graphs.",
"Nighttime background color in tide graphs.",
"Foreground in tide graphs during incoming tide.",
"Foreground in tide graphs during outgoing tide.",
"Color of datum line in tide graphs.",
"Color of Mean Tide Level line in tide graphs."
};
char *colorarg[numcolors] = {
"bg", "fg", "mc", "bc", "dc", "nc", "fc", "ec", "Dc", "Mc"
};
Colors::Colors (const Settings &settings) {
int a;
for (a=0; a<numcolors; a++)
parseColor (settings.colors[a], cmap[a][0], cmap[a][1], cmap[a][2]);
}
int
Colors::parseColor (const Dstr &colorname, unsigned char &r, unsigned char &g,
unsigned char &b, int fatal) {
#ifdef SUPER_ULTRA_VERBOSE_DEBUGGING
cerr << "Colors::parseColor asked to parse " << colorname << endl;
#endif
unsigned int rr=0, gg=0, bb=0;
if (sscanf (colorname.aschar(), "rgb:%x/%x/%x", &rr, &gg, &bb) == 3) {
r = (unsigned char)rr;
g = (unsigned char)gg;
b = (unsigned char)bb;
// Kludge for default fg and bg colors under the CDE
} else if (colorname[0] == '#' && colorname.length() == 13) {
char temp[3];
temp[2] = '\0';
temp[0] = colorname[1];
temp[1] = colorname[2];
sscanf (temp, "%x", &rr);
temp[0] = colorname[5];
temp[1] = colorname[6];
sscanf (temp, "%x", &gg);
temp[0] = colorname[9];
temp[1] = colorname[10];
sscanf (temp, "%x", &bb);
r = (unsigned char)rr;
g = (unsigned char)gg;
b = (unsigned char)bb;
// Kludge for default fg and bg colors under Debian
} else if (colorname[0] == '#' && colorname.length() == 7) {
char temp[3];
temp[2] = '\0';
temp[0] = colorname[1];
temp[1] = colorname[2];
sscanf (temp, "%x", &rr);
temp[0] = colorname[3];
temp[1] = colorname[4];
sscanf (temp, "%x", &gg);
temp[0] = colorname[5];
temp[1] = colorname[6];
sscanf (temp, "%x", &bb);
r = (unsigned char)rr;
g = (unsigned char)gg;
b = (unsigned char)bb;
} else {
rr = 0;
while (rgbtxt[rr].name) {
if (dstrcasecmp (colorname, rgbtxt[rr].name) == 0) {
r = rgbtxt[rr].r;
g = rgbtxt[rr].g;
b = rgbtxt[rr].b;
return 1;
}
rr++;
}
Dstr details ("The offending color spec was ");
details += colorname;
details += ".";
barf (BADCOLORSPEC, details, fatal);
return 0;
}
return 1;
}
int
Colors::parseColor (char *colorname, unsigned char &r, unsigned char &g,
unsigned char &b, int fatal) {
assert (colorname);
Dstr temp (colorname);
return parseColor (temp, r, g, b, fatal);
}
|