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