]> git.lyx.org Git - lyx.git/blobdiff - src/frontends/xforms/Color.C
Introduce LFUN_PRINT.
[lyx.git] / src / frontends / xforms / Color.C
index bbf9d5708752df19c5f5c5ba6c62e22cd03bfaca..fdb6ed963b7d84066bd8fc99e1970dd034695f8c 100644 (file)
 /**
  * \file Color.C
- * Copyright 2002 the LyX Team
- * Read the file COPYING
+ * This file is part of LyX, the document processor.
+ * Licence details can be found in the file COPYING.
  *
- * \author Angus Leeming, a.leeming@ic.ac.uk
+ * \author Angus Leeming
+ *
+ * Full author contact details are available in file CREDITS.
  */
 
 #include <config.h>
 
-#ifdef __GNUG__
-#pragma implementation
-#endif
-
 #include "Color.h"
-#include <algorithm> // max
-#include <cmath> // floor
-#include FORMS_H_LOCATION
+
+#include "lyx_forms.h"
+
+#include "LColor.h"
+
+#include "support/std_sstream.h"
+
+#include <cmath>
+#include <iomanip>
+
+
+#ifndef CXX_GLOBAL_CSTD
+using std::floor;
+#endif
 
 using std::max;
 using std::min;
+using std::setw;
+
+using std::istringstream;
+using std::ostringstream;
+using std::string;
+
 
 namespace {
 
 int const nohue = -1;
 
+int hexstrToInt(string const & str)
+{
+        int val = 0;
+        istringstream is(str);
+        is >> std::setbase(16) >> val;
+        return val;
+}
+
 } // namespace anon
 
+
+
+bool getRGBColor(LColor_color col,
+                unsigned int & r, unsigned int & g, unsigned int & b)
+{
+       string const name = lcolor.getX11Name(col);
+       Display * const display = fl_get_display();
+       Colormap const cmap = fl_state[fl_get_vclass()].colormap;
+       XColor xcol, ccol;
+
+       if (XLookupColor(display, cmap, name.c_str(), &xcol, &ccol) == 0) {
+               r = 0;
+               g = 0;
+               b = 0;
+               return false;
+       }
+
+       r = xcol.red   / 256;
+       g = xcol.green / 256;
+       b = xcol.blue  / 256;
+       return true;
+}
+
+
+string const X11hexname(RGBColor const & col)
+{
+       ostringstream ostr;
+
+       ostr << '#' << std::setbase(16) << std::setfill('0')
+            << setw(2) << col.r
+            << setw(2) << col.g
+            << setw(2) << col.b;
+
+       return ostr.str();
+}
+
+
+RGBColor::RGBColor(string const & x11hexname)
+       : r(0), g(0), b(0)
+{
+       BOOST_ASSERT(x11hexname.size() == 7 && x11hexname[0] == '#');
+       r = hexstrToInt(x11hexname.substr(1,2));
+       g = hexstrToInt(x11hexname.substr(3,2));
+       b = hexstrToInt(x11hexname.substr(5,2));
+}
+
+
 RGBColor::RGBColor(HSVColor const & hsv)
 {
        double h = hsv.h;
@@ -99,8 +169,8 @@ HSVColor::HSVColor(RGBColor const & rgb)
        double const g = rgb.g / 255.0;
        double const b = rgb.b / 255.0;
 
-       double const maxval = max( max( r, g), b);
-       double const minval = min( min( r, g), b);
+       double const maxval = max(max(r, g), b);
+       double const minval = min(min(r, g), b);
 
        v = maxval;