]> git.lyx.org Git - features.git/blobdiff - src/frontends/xforms/Color.h
Replace LString.h with support/std_string.h,
[features.git] / src / frontends / xforms / Color.h
index 50ca142571c72a73f26cc0a88f220fe360b935eb..86a8de28813ae3dee25b420fc52efb8e521ab274 100644 (file)
@@ -1,66 +1,75 @@
 // -*- C++ -*-
-/* This file is part of
- * ======================================================
- * 
- *           LyX, The Document Processor
- *      
- *         Copyright 1995 Matthias Ettrich
- *          Copyright 1995-2000 The LyX Team.
+/**
+ * \file Color.h
+ * This file is part of LyX, the document processor.
+ * Licence details can be found in the file COPYING.
  *
- *======================================================*/
+ * \author Angus Leeming
+ *
+ * Full author contact details are available in file CREDITS.
+ */
+
+/* structs RGBColor and HSVColor to enable simple conversion between
+ * color spaces.
+ */
 
 #ifndef COLOR_H
 #define COLOR_H
 
-#include<utility> // for pair
 
-#ifdef __GNUG_
-#pragma interface
-#endif
+#include "support/std_string.h"
+#include "LColor.h"
 
-#include "LString.h"
+/** Given col, fills r, g, b in the range 0-255.
+    The function returns true if successful.
+    It returns false on failure and sets r, g, b to 0. */
+bool getRGBColor(LColor::color col,
+                unsigned int & r, unsigned int & g, unsigned int & b);
 
-class HSV;
-class RGB;
+struct RGBColor;
+/// returns a string of form #rrggbb, given an RGBColor struct
+string const X11hexname(RGBColor const & col);
 
-struct HSV {
+struct HSVColor {
        double h;
        double s;
        double v;
-       HSV() : h(0.0), s(0.0), v(0.0) {}
-       HSV(double hue, double sat, double val) : h(hue), s(sat), v(val) {}
-       HSV( RGB const & );
+       HSVColor() : h(0.0), s(0.0), v(0.0) {}
+       HSVColor(double hue, double sat, double val)
+               : h(hue), s(sat), v(val) {}
+       HSVColor(RGBColor const &);
 };
 
-struct RGB {
-       int r;
-       int g;
-       int b;
-       RGB() : r(0), g(0), b(0) {}
-       RGB(int red, int green, int blue) : r(red), g(green), b(blue) {}
-       RGB( HSV const & );
+struct RGBColor {
+       unsigned int r;
+       unsigned int g;
+       unsigned int b;
+       RGBColor() : r(0), g(0), b(0) {}
+       RGBColor(unsigned int red, unsigned int green, unsigned int blue)
+               : r(red), g(green), b(blue) {}
+       RGBColor(HSVColor const &);
+       /// \param x11hexname is of the form "#ffa071"
+       RGBColor(string const & x11hexname);
 };
 
-typedef std::pair<string, RGB> X11Color;
-
-/// struct holding xform-specific colors
-struct XFormColor {
+struct NamedColor : public RGBColor {
        string name;
-       int colorID;
-       RGB col;
-       XFormColor() : colorID(0) {}
-       string const getname() { return name; }
+       NamedColor() : RGBColor() {}
+       NamedColor(string const & n, RGBColor const & c)
+               : RGBColor(c), name(n) {}
+       RGBColor const & color() const { return *this; }
+       string const & getname() const { return name; }
 };
 
 inline
-bool operator==(RGB const & c1, RGB const & c2)
+bool operator==(RGBColor const & c1, RGBColor const & c2)
 {
        return (c1.r == c2.r && c1.g == c2.g && c1.b == c2.b);
 }
 
 
 inline
-bool operator!=(RGB const & c1, RGB const & c2)
+bool operator!=(RGBColor const & c1, RGBColor const & c2)
 {
        return !(c1 == c2);
 }