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