themes: Workaround for bug where a background color of RGB 0,0,0 in Black color schem...
[ntk.git] / src / fl_color_mac.cxx
blobc6351c098e828ffe1401d13e39164021bb296e70
1 //
2 // "$Id: fl_color_mac.cxx 8384 2011-02-06 12:32:23Z manolo $"
3 //
4 // MacOS color functions for the Fast Light Tool Kit (FLTK).
5 //
6 // Copyright 1998-2010 by Bill Spitzak and others.
7 //
8 // This library is free software; you can redistribute it and/or
9 // modify it under the terms of the GNU Library General Public
10 // License as published by the Free Software Foundation; either
11 // version 2 of the License, or (at your option) any later version.
13 // This library is distributed in the hope that it will be useful,
14 // but WITHOUT ANY WARRANTY; without even the implied warranty of
15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 // Library General Public License for more details.
18 // You should have received a copy of the GNU Library General Public
19 // License along with this library; if not, write to the Free Software
20 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
21 // USA.
23 // Please report all bugs and problems on the following page:
25 // http://www.fltk.org/str.php
28 // The fltk "colormap". This allows ui colors to be stored in 8-bit
29 // locations, and provides a level of indirection so that global color
30 // changes can be made. Not to be confused with the X colormap, which
31 // I try to hide completely.
33 // matt: Neither Quartz nor Quickdraw support colormaps in this implementation
34 // matt: Quartz support done
36 #include <config.h>
37 #include <FL/Fl.H>
38 #include <FL/x.H>
39 #include <FL/fl_draw.H>
41 static unsigned fl_cmap[256] = {
42 #include "fl_cmap.h" // this is a file produced by "cmap.cxx":
45 // Translations to mac data structures:
46 Fl_XMap fl_xmap[256];
48 Fl_XMap* fl_current_xmap;
50 void Fl_Quartz_Graphics_Driver::color(Fl_Color i) {
51 Fl_Graphics_Driver::color(i);
52 int index;
53 uchar r, g, b;
54 if (i & 0xFFFFFF00) {
55 // translate rgb colors into color index
56 r = i>>24;
57 g = i>>16;
58 b = i>> 8;
59 } else {
60 // translate index into rgb:
61 index = i;
62 unsigned c = fl_cmap[i];
63 r = c>>24;
64 g = c>>16;
65 b = c>> 8;
67 if (!fl_gc) return; // no context yet? We will assign the color later.
68 float fr = r/255.0f;
69 float fg = g/255.0f;
70 float fb = b/255.0f;
71 CGContextSetRGBFillColor(fl_gc, fr, fg, fb, 1.0f);
72 CGContextSetRGBStrokeColor(fl_gc, fr, fg, fb, 1.0f);
75 void Fl_Quartz_Graphics_Driver::color(uchar r, uchar g, uchar b) {
76 Fl_Graphics_Driver::color( fl_rgb_color(r, g, b) );
77 float fr = r/255.0f;
78 float fg = g/255.0f;
79 float fb = b/255.0f;
80 CGContextSetRGBFillColor(fl_gc, fr, fg, fb, 1.0f);
81 CGContextSetRGBStrokeColor(fl_gc, fr, fg, fb, 1.0f);
84 void Fl::set_color(Fl_Color i, unsigned c) {
85 if (fl_cmap[i] != c) {
86 fl_cmap[i] = c;
91 // End of "$Id: fl_color_mac.cxx 8384 2011-02-06 12:32:23Z manolo $".