CXX peace: src/pre-grn/hgraph.cpp
[s-roff.git] / include / color.h
blob5080f9c99199e603dc5c6e9454a9baf75196ddc4
1 /*@
2 * Copyright (c) 2014 - 2017 Steffen (Daode) Nurpmeso <steffen@sdaoden.eu>.
4 * Copyright (C) 2001, 2002, 2003 Free Software Foundation, Inc.
5 * Written by Gaius Mulley <gaius@glam.ac.uk>
7 * This is free software; you can redistribute it and/or modify it under
8 * the terms of the GNU General Public License as published by the Free
9 * Software Foundation; either version 2, or (at your option) any later
10 * version.
12 * This is distributed in the hope that it will be useful, but WITHOUT ANY
13 * WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
15 * for more details.
17 * You should have received a copy of the GNU General Public License along
18 * with groff; see the file COPYING. If not, write to the Free Software
19 * Foundation, 51 Franklin St - Fifth Floor, Boston, MA 02110-1301, USA.
21 #ifndef _COLOR_H
22 #define _COLOR_H
24 #include "config.h"
26 #include <stddef.h>
28 #include "symbol.h"
30 enum color_scheme {DEFAULT, CMY, CMYK, RGB, GRAY};
32 class color
34 color_scheme scheme;
35 unsigned int components[4];
36 color *next;
37 static color *free_list;
39 int read_encoding(const color_scheme, const char * const,
40 const size_t);
42 public:
43 symbol nm;
44 enum {MAX_COLOR_VAL = 0xffff};
45 color(symbol s = default_symbol) : scheme(DEFAULT), nm(s) {}
46 color(const color * const);
47 ~color();
48 void *operator new(size_t);
49 void operator delete(void *);
51 int operator==(const color & c) const;
52 int operator!=(const color & c) const;
54 int is_default() { return scheme == DEFAULT; }
56 // set color from given color component values
57 void set_default();
58 void set_rgb(const unsigned int r, const unsigned int g,
59 const unsigned int b);
60 void set_cmy(const unsigned int c, const unsigned int m,
61 const unsigned int y);
62 void set_cmyk(const unsigned int c, const unsigned int m,
63 const unsigned int y, const unsigned int k);
64 void set_gray(const unsigned int g);
66 // set color from a color string
67 int read_rgb(const char * const s);
68 int read_cmy(const char * const s);
69 int read_cmyk(const char * const s);
70 int read_gray(const char * const s);
72 // Return the actual color scheme and retrieve the color components
73 // into a predefined vector (of length at least 4).
74 color_scheme get_components(unsigned int *c) const;
76 // retrieve the components of a color
77 void get_rgb(unsigned int *r, unsigned int *g, unsigned int *b) const;
78 void get_cmy(unsigned int *c, unsigned int *m, unsigned int *y) const;
79 void get_cmyk(unsigned int *c, unsigned int *m,
80 unsigned int *y, unsigned int *k) const;
81 void get_gray(unsigned int *g) const;
83 char *print_color();
86 #define Cyan components[0]
87 #define Magenta components[1]
88 #define Yellow components[2]
89 #define Black components[3]
91 #define Red components[0]
92 #define Green components[1]
93 #define Blue components[2]
95 #define Gray components[0]
97 extern color default_color; /* FIXME class-global static? (access fun?!) */
99 #endif // _COLOR_H
100 // s-it2-mode