]> git.lyx.org Git - lyx.git/blob - src/frontends/xforms/Color.h
The EnumLColor patch, free of macros.
[lyx.git] / src / frontends / xforms / Color.h
1 // -*- C++ -*-
2 /**
3  * \file Color.h
4  * This file is part of LyX, the document processor.
5  * Licence details can be found in the file COPYING.
6  *
7  * \author Angus Leeming
8  *
9  * Full author contact details are available in file CREDITS.
10  */
11
12 /* structs RGBColor and HSVColor to enable simple conversion between
13  * color spaces.
14  */
15
16 #ifndef COLOR_H
17 #define COLOR_H
18
19
20 #include "support/std_string.h"
21
22
23 class EnumLColor;
24
25
26 /** Given col, fills r, g, b in the range 0-255.
27     The function returns true if successful.
28     It returns false on failure and sets r, g, b to 0. */
29 bool getRGBColor(EnumLColor col,
30                  unsigned int & r, unsigned int & g, unsigned int & b);
31
32 struct RGBColor;
33 /// returns a string of form #rrggbb, given an RGBColor struct
34 string const X11hexname(RGBColor const & col);
35
36 struct HSVColor {
37         double h;
38         double s;
39         double v;
40         HSVColor() : h(0.0), s(0.0), v(0.0) {}
41         HSVColor(double hue, double sat, double val)
42                 : h(hue), s(sat), v(val) {}
43         HSVColor(RGBColor const &);
44 };
45
46 struct RGBColor {
47         unsigned int r;
48         unsigned int g;
49         unsigned int b;
50         RGBColor() : r(0), g(0), b(0) {}
51         RGBColor(unsigned int red, unsigned int green, unsigned int blue)
52                 : r(red), g(green), b(blue) {}
53         RGBColor(HSVColor const &);
54         /// \param x11hexname is of the form "#ffa071"
55         RGBColor(string const & x11hexname);
56 };
57
58 struct NamedColor : public RGBColor {
59         string name;
60         NamedColor() : RGBColor() {}
61         NamedColor(string const & n, RGBColor const & c)
62                 : RGBColor(c), name(n) {}
63         RGBColor const & color() const { return *this; }
64         string const & getname() const { return name; }
65 };
66
67 inline
68 bool operator==(RGBColor const & c1, RGBColor const & c2)
69 {
70         return (c1.r == c2.r && c1.g == c2.g && c1.b == c2.b);
71 }
72
73
74 inline
75 bool operator!=(RGBColor const & c1, RGBColor const & c2)
76 {
77         return !(c1 == c2);
78 }
79
80 #endif