1 /*
2 FXiTe - The Free eXtensIble Text Editor
3 Copyright (c) 2009-2010 Jeffrey Pohlmeyer <yetanothergeek@gmail.com>
4
5 This program is free software; you can redistribute it and/or modify it
6 under the terms of the GNU General Public License version 3 as
7 published by the Free Software Foundation.
8
9 This software is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
13
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
17 */
18
19
20
21 #include <fx.h>
22 #include "prefs_base.h"
23 #include "color_funcs.h"
24
25
26
27
InvertColor(long rgb)28 static long InvertColor(long rgb)
29 {
30 long r,g,b;
31 r=FXREDVAL(rgb);
32 g=FXGREENVAL(rgb);
33 b=FXBLUEVAL(rgb);
34 r=255-r;
35 g=255-g;
36 b=255-b;
37 if ((r>0)&&(r<0x80)) { r+=0x40; }
38 if ((g>0)&&(g<0x80)) { g+=0x40; }
39 if ((b>0)&&(b<0x80)) { b+=0x40; }
40 return FXRGB(r,g,b);
41 }
42
43
44
45 #define invert ( SettingsBase::instance()? SettingsBase::instance()->InvertColors : false )
46
47
RgbToHex(FXColor rgb,ColorName & clr)48 void RgbToHex(FXColor rgb, ColorName &clr)
49 {
50 if (invert) { rgb=InvertColor(rgb); }
51 snprintf(clr, 8, "#%02x%02x%02x", FXREDVAL(rgb), FXGREENVAL(rgb), FXBLUEVAL(rgb));
52 }
53
54
55
HexToRGB(const char * rgb)56 long HexToRGB(const char* rgb)
57 {
58 int r=0, g=0, b=0;
59 sscanf(rgb+1,"%2x%2x%2x",&r,&g,&b);
60 return invert? InvertColor(FXRGB(r, g, b)) : FXRGB(r, g, b);
61 }
62
63