Ardour  9.0-pre0-582-g084a23a80d
colors.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2017 Paul Davis <paul@linuxaudiosystems.com>
3  * Copyright (C) 2017 Robin Gareus <robin@gareus.org>
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 2 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License along
16  * with this program; if not, write to the Free Software Foundation, Inc.,
17  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18  */
19 
20 #ifndef _GTKMM2EXT_COLORS_H_
21 #define _GTKMM2EXT_COLORS_H_
22 
23 #include<stdint.h>
24 
25 #include <gdkmm/types.h>
26 #include <cairomm/context.h>
27 
28 #include "gtkmm2ext/visibility.h"
29 
30 namespace Gtkmm2ext
31 {
32 
33 typedef uint32_t Color;
34 
36 
37 /* conventient way to use Gtkmm2ext::Color with libcairo */
38 extern LIBGTKMM2EXT_API void set_source_rgba (Cairo::RefPtr<Cairo::Context>, Gtkmm2ext::Color);
39 extern LIBGTKMM2EXT_API void set_source_rgb_a (Cairo::RefPtr<Cairo::Context>, Gtkmm2ext::Color, float alpha); //override the color's alpha
40 
42 extern LIBGTKMM2EXT_API void set_source_rgb_a (cairo_t*, Gtkmm2ext::Color, float alpha); //override the color's alpha
43 
47 
50 
51 
52 struct LIBGTKMM2EXT_API HSV;
53 struct LIBGTKMM2EXT_API HSVA;
54 
55 extern LIBGTKMM2EXT_API Color change_alpha (Color, double alpha);
56 
57 extern LIBGTKMM2EXT_API Color hsva_to_color (double h, double s, double v, double a = 1.0);
58 extern LIBGTKMM2EXT_API void color_to_hsva (Color color, double& h, double& s, double& v, double& a);
60 extern LIBGTKMM2EXT_API void color_to_hsv (Color color, double& h, double& s, double& v);
61 extern LIBGTKMM2EXT_API void color_to_rgba (Color, double& r, double& g, double& b, double& a);
62 extern LIBGTKMM2EXT_API Color rgba_to_color (double r, double g, double b, double a);
63 
65 
66 struct LIBGTKMM2EXT_API HSV;
67 
69 {
70 public:
71  enum Type {
72  Add,
74  Assign
75  };
76 
77  SVAModifier (std::string const &);
78  SVAModifier (Type t, double ss, double vv, double aa) : type (t), _s (ss) , _v (vv) , _a (aa) {}
79  SVAModifier () : type (Add), _s (0), _v (0), _a (0) {} /* no-op modifier */
80 
81  double s() const { return _s; }
82  double v() const { return _v; }
83  double a() const { return _a; }
84 
85  HSV operator () (HSV& hsv) const;
86  std::string to_string () const;
87  void from_string (std::string const &);
88 
89 private:
91  double _s;
92  double _v;
93  double _a;
94 };
95 
97 {
98  HSV ();
99  HSV (double h, double s, double v, double a = 1.0);
101 
102  double h;
103  double s;
104  double v;
105  double a;
106 
107  std::string to_string() const;
108  bool is_gray() const;
109 
110  Color color() const { return hsva_to_color (h,s, v, a); }
111  operator Color() const { return color(); }
112 
113  HSV mod (SVAModifier const & svam);
114 
115  HSV operator+ (const HSV&) const;
116  HSV operator- (const HSV&) const;
117 
119  HSV& operator=(const std::string&);
120 
121  bool operator== (const HSV& other);
122 
123  double distance (const HSV& other) const;
124  HSV delta (const HSV& other) const;
125 
126  HSV darker (double factor = 1.3) const;
127  HSV lighter (double factor = 0.7) const;
128 
129  HSV shade (double factor) const;
130  HSV mix (const HSV& other, double amt) const;
131 
132  HSV opposite() const;
133  HSV complement() const { return opposite(); }
134 
135  HSV bw_text () const;
136  HSV text() const;
137  HSV selected () const;
138  HSV outline() const;
139 
140  void print (std::ostream&) const;
141 
142 protected:
143  void clamp ();
144 };
145 
146 } /* namespace */
147 
148 std::ostream& operator<<(std::ostream& o, const Gtkmm2ext::HSV& hsv);
149 
150 #endif
double v() const
Definition: colors.h:82
void from_string(std::string const &)
std::string to_string() const
SVAModifier(Type t, double ss, double vv, double aa)
Definition: colors.h:78
SVAModifier(std::string const &)
double s() const
Definition: colors.h:81
double a() const
Definition: colors.h:83
std::ostream & operator<<(std::ostream &o, const Gtkmm2ext::HSV &hsv)
#define LIBGTKMM2EXT_API
PBD::PropertyDescriptor< uint32_t > color
void color_to_hsv(Color color, double &h, double &s, double &v)
void set_source_rgb_a(Cairo::RefPtr< Cairo::Context >, Gtkmm2ext::Color, float alpha)
uint32_t contrasting_text_color(uint32_t c)
Color change_alpha(Color, double alpha)
Color rgba_to_color(double r, double g, double b, double a)
Gdk::Color gdk_color_from_rgb(uint32_t)
Color hsva_to_color(double h, double s, double v, double a=1.0)
uint32_t Color
Definition: colors.h:33
Gdk::Color gdk_color_from_rgba(uint32_t)
Color color_at_alpha(Color, double a)
uint32_t gdk_color_to_rgba(Gdk::Color const &)
void set_color_from_rgb(Gdk::Color &, uint32_t)
void color_to_rgba(Color, double &r, double &g, double &b, double &a)
void set_source_rgba(Cairo::RefPtr< Cairo::Context >, Gtkmm2ext::Color)
void set_color_from_rgba(Gdk::Color &, uint32_t)
Color random_color()
void color_to_hsva(Color color, double &h, double &s, double &v, double &a)
bool operator==(const ProcessorSelection &a, const ProcessorSelection &b)
std::string to_string() const
HSV delta(const HSV &other) const
HSV lighter(double factor=0.7) const
Color color() const
Definition: colors.h:110
HSV darker(double factor=1.3) const
double s
Definition: colors.h:103
bool is_gray() const
double a
Definition: colors.h:105
HSV & operator=(const std::string &)
HSV opposite() const
double h
Definition: colors.h:102
HSV outline() const
HSV selected() const
HSV mix(const HSV &other, double amt) const
HSV & operator=(Color)
HSV bw_text() const
double v
Definition: colors.h:104
HSV complement() const
Definition: colors.h:133
void print(std::ostream &) const
double distance(const HSV &other) const
HSV(double h, double s, double v, double a=1.0)
HSV mod(SVAModifier const &svam)
HSV text() const
HSV shade(double factor) const