]> git.lyx.org Git - lyx.git/blob - src/frontends/xforms/Color.h
Refactor xforms' colour handling code.
[lyx.git] / src / frontends / xforms / Color.h
1 // -*- C++ -*-
2 /**
3  * \file Color.h
4  * Copyright 1995 Matthias Ettrich
5  * This file is part of LyX, the document processor.
6  * Licence details can be found in the file COPYING.
7  *
8  * \author Angus Leeming
9  *
10  * Full author contact details are available in file CREDITS
11  */
12
13 /* structs RGBColor and HSVColor to enable simple conversion between
14  * color spaces.
15  */
16
17 #ifndef COLOR_H
18 #define COLOR_H
19
20 #ifdef __GNUG__
21 #pragma interface
22 #endif
23
24 #include "LString.h"
25 #include "LColor.h"
26
27 /** Given col, fills r, g, b in the range 0-255.
28     The function returns true if successful.
29     It returns false on failure and sets r, g, b to 0. */
30 bool getRGBColor(LColor::color col,
31                  unsigned int & r, unsigned int & g, unsigned int & b);
32
33 struct RGBColor;
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 };
54
55 struct NamedColor : public RGBColor {
56         string name;
57         NamedColor() : RGBColor() {}
58         NamedColor(string const & n, RGBColor const & c)
59                 : RGBColor(c), name(n) {}
60         RGBColor const & color() const { return *this; }
61         string const & getname() const { return name; }
62 };
63
64 inline
65 bool operator==(RGBColor const & c1, RGBColor const & c2)
66 {
67         return (c1.r == c2.r && c1.g == c2.g && c1.b == c2.b);
68 }
69
70
71 inline
72 bool operator!=(RGBColor const & c1, RGBColor const & c2)
73 {
74         return !(c1 == c2);
75 }
76
77 #endif