]> git.lyx.org Git - lyx.git/blob - src/Color.h
Allows editing when the Prefs dialog is opened; fix bug 3140:
[lyx.git] / src / 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 namespace lyx {
22
23 struct RGBColor;
24 /// returns a string of form #rrggbb, given an RGBColor struct
25 std::string const X11hexname(RGBColor const & col);
26
27 struct HSVColor {
28         double h;
29         double s;
30         double v;
31         HSVColor() : h(0.0), s(0.0), v(0.0) {}
32         HSVColor(double hue, double sat, double val)
33                 : h(hue), s(sat), v(val) {}
34         HSVColor(RGBColor const &);
35 };
36
37 struct RGBColor {
38         unsigned int r;
39         unsigned int g;
40         unsigned int b;
41         RGBColor() : r(0), g(0), b(0) {}
42         RGBColor(unsigned int red, unsigned int green, unsigned int blue)
43                 : r(red), g(green), b(blue) {}
44         RGBColor(HSVColor const &);
45         /// \param x11hexname is of the form "#ffa071"
46         RGBColor(std::string const & x11hexname);
47 };
48
49 struct NamedColor : public RGBColor {
50         std::string lyxname;
51         std::string guiname;
52         NamedColor() : RGBColor() {}
53         NamedColor(std::string const & lyx, std::string const & gui,
54                    RGBColor const & c)
55                 : RGBColor(c), lyxname(lyx), guiname(gui) {}
56         RGBColor const & color() const { return *this; }
57 };
58
59 inline
60 bool operator==(RGBColor const & c1, RGBColor const & c2)
61 {
62         return (c1.r == c2.r && c1.g == c2.g && c1.b == c2.b);
63 }
64
65
66 inline
67 bool operator!=(RGBColor const & c1, RGBColor const & c2)
68 {
69         return !(c1 == c2);
70 }
71
72 } // namespace lyx
73
74 #endif