]> git.lyx.org Git - lyx.git/blob - src/frontends/xforms/Color.h
Tiny clean-ups.
[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 #include <string>
20
21
22 class LColor_color;
23
24
25 /** Given col, fills r, g, b in the range 0-255.
26     The function returns true if successful.
27     It returns false on failure and sets r, g, b to 0. */
28 bool getRGBColor(LColor_color col,
29                  unsigned int & r, unsigned int & g, unsigned int & b);
30
31 struct RGBColor;
32 /// returns a string of form #rrggbb, given an RGBColor struct
33 std::string const X11hexname(RGBColor const & col);
34
35 struct HSVColor {
36         double h;
37         double s;
38         double v;
39         HSVColor() : h(0.0), s(0.0), v(0.0) {}
40         HSVColor(double hue, double sat, double val)
41                 : h(hue), s(sat), v(val) {}
42         HSVColor(RGBColor const &);
43 };
44
45 struct RGBColor {
46         unsigned int r;
47         unsigned int g;
48         unsigned int b;
49         RGBColor() : r(0), g(0), b(0) {}
50         RGBColor(unsigned int red, unsigned int green, unsigned int blue)
51                 : r(red), g(green), b(blue) {}
52         RGBColor(HSVColor const &);
53         /// \param x11hexname is of the form "#ffa071"
54         RGBColor(std::string const & x11hexname);
55 };
56
57 struct NamedColor : public RGBColor {
58         std::string name;
59         NamedColor() : RGBColor() {}
60         NamedColor(std::string const & n, RGBColor const & c)
61                 : RGBColor(c), name(n) {}
62         RGBColor const & color() const { return *this; }
63         std::string const & getname() const { return name; }
64 };
65
66 inline
67 bool operator==(RGBColor const & c1, RGBColor const & c2)
68 {
69         return (c1.r == c2.r && c1.g == c2.g && c1.b == c2.b);
70 }
71
72
73 inline
74 bool operator!=(RGBColor const & c1, RGBColor const & c2)
75 {
76         return !(c1 == c2);
77 }
78
79 #endif