summaryrefslogtreecommitdiff
path: root/libs/canvas/canvas/colors.h
blob: 28fc2c079bf38c7735839bec799c029ad3d9ea63 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
/*
    Copyright (C) 2011-2013 Paul Davis
    Author: Carl Hetherington <cth@carlh.net>

    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 2 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program; if not, write to the Free Software
    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/

#ifndef __ardour_canvas_colors_h__
#define __ardour_canvas_colors_h__

#include <cairomm/context.h>

#include "canvas/visibility.h"
#include "canvas/types.h"

namespace ArdourCanvas 
{

struct LIBCANVAS_API HSV;
struct LIBCANVAS_API HSVA;

extern LIBCANVAS_API Color hsva_to_color (double h, double s, double v, double a = 1.0);
extern LIBCANVAS_API void  color_to_hsva (Color color, double& h, double& s, double& v, double& a);
extern LIBCANVAS_API void  color_to_hsv (Color color, double& h, double& s, double& v);
extern LIBCANVAS_API void  color_to_rgba (Color, double& r, double& g, double& b, double& a);
extern LIBCANVAS_API Color rgba_to_color (double r, double g, double b, double a);

uint32_t LIBCANVAS_API contrasting_text_color (uint32_t c);

struct LIBCANVAS_API HSV
{
	HSV ();
	HSV (double h, double s, double v, double a = 1.0);
	HSV (Color);
	HSV (const std::string&);
	
	double h;
	double s;
	double v;
	double a;

	std::string to_string() const;
	bool is_gray() const;
	
	Color color() const { return hsva_to_color (h,s, v, a); }
	operator Color() const { return color(); }

	HSV operator+ (const HSV&) const;
	HSV operator- (const HSV&) const;

	HSV& operator=(Color);
	HSV& operator=(const std::string&);

	bool operator== (const HSV& other);

	double distance (const HSV& other) const;
	HSV delta (const HSV& other) const;

	HSV darker (double factor = 1.3) const { return shade (factor); }
	HSV lighter (double factor = 0.7) const { return shade (factor); }

	HSV shade (double factor) const;
	HSV mix (const HSV& other, double amt) const;

	HSV opposite() const;
	HSV complement() const { return opposite(); }

	HSV bw_text () const;
	HSV text() const;
	HSV selected () const;
	HSV outline() const;

	void print (std::ostream&) const;

  protected:
	void clamp ();
};

}

std::ostream& operator<<(std::ostream& o, const ArdourCanvas::HSV& hsv);

#endif /* __ardour_canvas_colors_h__ */