2 /* This file is part of
3 * ======================================================
5 * LyX, The Document Processor
7 * Copyright 1995 Matthias Ettrich
8 * Copyright 1995-2000 The LyX Team.
10 *======================================================*/
13 #include FORMS_H_LOCATION
16 #pragma implementation
19 #include <algorithm> // max
20 #include <cmath> // floor
21 #include <fstream> // ofstream
29 static int const nohue = -1;
31 RGBColor::RGBColor( HSVColor const & hsv )
39 if( h == nohue || s == 0.0 ) {
42 if( h == 360.0 ) h = 0.0;
45 int j = static_cast<int>( ::floor(h) );
49 double p = v * (1.0 - s);
50 double q = v * (1.0 - (s*f));
51 double t = v * (1.0 - (s*(1.0 - f)));
88 break; // should never happen.
92 r = static_cast<int>( ::floor((rd * 255.0) + 0.5) );
93 g = static_cast<int>( ::floor((gd * 255.0) + 0.5) );
94 b = static_cast<int>( ::floor((bd * 255.0) + 0.5) );
98 HSVColor::HSVColor( RGBColor const & rgb )
100 // r, g, b lie in the range 0-1, not 0-255.
101 double r = rgb.r / 255.0;
102 double g = rgb.g / 255.0;
103 double b = rgb.b / 255.0;
105 double maxval = max( max( r, g ), b );
106 double minval = max( min( r, g ), b );
110 double diff = maxval - minval;
118 double rc = (maxval - r) / diff;
119 double gc = (maxval - g) / diff;
120 double bc = (maxval - b) / diff;
124 else if( g == maxval )
126 else if( b == maxval )
136 // sorted by hand to prevent LyXLex from complaining on read().
138 keyword_item xformTags[] = {
139 // { "\\gui_active_tab", FL_LIGHTER_COL1 },
140 { "\\gui_background", FL_COL1 },
141 { "\\gui_buttonbottom", FL_BOTTOM_BCOL },
142 { "\\gui_buttonleft", FL_LEFT_BCOL },
143 { "\\gui_buttonright", FL_RIGHT_BCOL },
144 { "\\gui_buttontop", FL_TOP_BCOL },
145 { "\\gui_inactive", FL_INACTIVE },
146 { "\\gui_push_button", FL_YELLOW },
147 { "\\gui_selected", FL_MCOL },
148 { "\\gui_text", FL_BLACK }
152 static const int xformCount = sizeof(xformTags) / sizeof(keyword_item);
155 bool XformColor::read(string const & filename)
157 LyXLex lexrc( xformTags, xformCount );
158 if( !lexrc.setFile( filename ) )
161 while( lexrc.IsOK() ) {
162 int le = lexrc.lex();
165 case LyXLex::LEX_UNDEF:
166 lexrc.printError("Unknown tag `$$Token'");
168 case LyXLex::LEX_FEOF:
175 if( !lexrc.next() ) break;
176 col.r = lexrc.GetInteger();
178 if( !lexrc.next() ) break;
179 col.g = lexrc.GetInteger();
181 if( !lexrc.next() ) break;
182 col.b = lexrc.GetInteger();
184 fl_mapcolor(le, col.r, col.g, col.b);
191 bool XformColor::write(string const & filename)
193 ofstream os(filename.c_str());
197 os << "### This file is part of\n"
198 << "### ========================================================\n"
199 << "### LyX, The Document Processor\n"
201 << "### Copyright 1995 Matthias Ettrich\n"
202 << "### Copyright 1995-2000 The LyX Team.\n"
204 << "### ========================================================\n"
206 << "# This file is written by LyX, if you want to make your own\n"
207 << "# modifications you should do them from inside LyX and save\n"
210 for( int i = 0; i < xformCount; ++i ) {
211 string tag = xformTags[i].tag;
212 int colorID = xformTags[i].code;
215 fl_getmcolor(colorID, &color.r, &color.g, &color.b);
218 << color.r << " " << color.g << " " << color.b << "\n";