File: GriColor.hh

package info (click to toggle)
gri 2.12.26-1
  • links: PTS
  • area: main
  • in suites: buster
  • size: 5,952 kB
  • ctags: 2,396
  • sloc: cpp: 36,598; sh: 4,196; lisp: 3,764; perl: 1,362; ansic: 1,046; makefile: 606
file content (81 lines) | stat: -rw-r--r-- 2,611 bytes parent folder | download | duplicates (8)
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
/*
    Gri - A language for scientific graphics programming
    Copyright (C) 2008 Daniel Kelley

    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; version 3 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.,
    51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/

#ifndef _gricolor_h_
#define  _gricolor_h_

#include <string>
#include <stdio.h>
#include "types.hh"

class GriColor
{
public:
	enum type {rgb, hsv, cmyk};
	GriColor() { t = rgb; transparency = a = b = c = d = 0.0;};
	GriColor(const GriColor& c);
        ~GriColor();
	GriColor& operator=(const GriColor& c);
	void setHSV(double H, double S, double V);
	void setRGB(double R, double G, double B);
	void setCMYK(double C, double M, double Y, double K);
	bool isRGB() const {return t == rgb;}
	void set_type(type tt) {t = tt;}
	void set_transparency(double tr) {transparency = tr;}
	type get_type() const {return t;}
	void getRGB(double *R, double *G, double *B) const;
	void getCMYK(double *C, double *M, double *Y, double *K) const;
	double getT() const {return transparency;}
	void setT(double tr) { transparency = tr;}

	double getR() const {return a;}
	double getG() const {return b;}
	double getB() const {return c;}

	double getH() const {return a;}
	double getS() const {return b;}
	double getV() const {return c;}

	double getC() const {return a;}
	double getM() const {return b;}
	double getY() const {return c;}
	double getK() const {return d;}
	std::string get_hexcolor() const;
protected:
	type t;
	double transparency;	// transparency
	double a;		// red, hue, or cyan
	double b;		// green, saturation, or magenta
	double c;		// blue, brightness, or yellow
	double d;		// k=blackness
};
class GriNamedColor : public GriColor
{
public:
	GriNamedColor();
	~GriNamedColor();
	GriNamedColor(const char *n, double R, double G, double B);
	GriNamedColor(const GriNamedColor& C); 
	GriNamedColor& operator=(const GriNamedColor& C);
	void setNameRGB(const char *n, double R, double G, double B);
	const std::string get_name(void) const {return name;}
private:
	std::string name;
};
#endif