Ardour  9.2-304-g0ff80a8d9a
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 <ydkmm/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 extern LIBGTKMM2EXT_API double color_to_luminance (uint32_t c);
64 
66 
67 struct LIBGTKMM2EXT_API HSV;
68 
70 {
71 public:
72  enum Type {
73  Add,
75  Assign
76  };
77 
78  SVAModifier (std::string const &);
79  SVAModifier (Type t, double ss, double vv, double aa) : type (t), _s (ss) , _v (vv) , _a (aa) {}
80  SVAModifier () : type (Add), _s (0), _v (0), _a (0) {} /* no-op modifier */
81 
82  double s() const { return _s; }
83  double v() const { return _v; }
84  double a() const { return _a; }
85 
86  HSV operator () (HSV& hsv) const;
87  std::string to_string () const;
88  void from_string (std::string const &);
89 
90 private:
92  double _s;
93  double _v;
94  double _a;
95 };
96 
98 {
99  HSV ();
100  HSV (double h, double s, double v, double a = 1.0);
102 
103  double h;
104  double s;
105  double v;
106  double a;
107 
108  std::string to_string() const;
109  bool is_gray() const;
110 
111  Color color() const { return hsva_to_color (h,s, v, a); }
112  operator Color() const { return color(); }
113 
114  HSV mod (SVAModifier const & svam);
115 
116  HSV operator+ (const HSV&) const;
117  HSV operator- (const HSV&) const;
118 
120  HSV& operator=(const std::string&);
121 
122  bool operator== (const HSV& other);
123 
124  double distance (const HSV& other) const;
125  HSV delta (const HSV& other) const;
126 
127  HSV darker (double factor = 1.3) const;
128  HSV lighter (double factor = 0.7) const;
129 
130  HSV shade (double factor) const;
131  HSV mix (const HSV& other, double amt) const;
132 
133  HSV opposite() const;
134  HSV complement() const { return opposite(); }
135 
136  HSV bw_text () const;
137  HSV text() const;
138  HSV selected () const;
139  HSV outline() const;
140 
141  void print (std::ostream&) const;
142 
143 protected:
144  void clamp ();
145 };
146 
147 } /* namespace */
148 
149 std::ostream& operator<<(std::ostream& o, const Gtkmm2ext::HSV& hsv);
150 
151 #endif
double v() const
Definition: colors.h:83
void from_string(std::string const &)
std::string to_string() const
SVAModifier(Type t, double ss, double vv, double aa)
Definition: colors.h:79
SVAModifier(std::string const &)
double s() const
Definition: colors.h:82
double a() const
Definition: colors.h:84
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)
double color_to_luminance(uint32_t c)
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:111
HSV darker(double factor=1.3) const
double s
Definition: colors.h:104
bool is_gray() const
double a
Definition: colors.h:106
HSV & operator=(const std::string &)
HSV opposite() const
double h
Definition: colors.h:103
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:105
HSV complement() const
Definition: colors.h:134
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