Current Version: 1.0.20
Project Name: csspp
color.h
Go to the documentation of this file.
1 #ifndef CSSPP_COLOR_H
2 #define CSSPP_COLOR_H
3 // CSS Preprocessor
4 // Copyright (c) 2015-2018 Made to Order Software Corp. All Rights Reserved
5 //
6 // This program is free software; you can redistribute it and/or modify
7 // it under the terms of the GNU General Public License as published by
8 // the Free Software Foundation; either version 2 of the License, or
9 // (at your option) any later version.
10 //
11 // This program is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
15 //
16 // You should have received a copy of the GNU General Public License
17 // along with this program; if not, write to the Free Software
18 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19 
20 #include <cstdint>
21 #include <string>
22 
23 namespace csspp
24 {
25 
26 typedef float color_component_t;
27 typedef uint8_t byte_component_t;
28 typedef uint32_t rgba_color_t;
29 
31 {
32  byte_component_t f_red = 0;
33  byte_component_t f_green = 0;
34  byte_component_t f_blue = 0;
35  byte_component_t f_alpha = 0;
36  char const * f_name = nullptr;
37 };
38 
39 class color
40 {
41 public:
42  void set_color(rgba_color_t const rgba);
43  void set_color(byte_component_t red, byte_component_t green, byte_component_t blue, byte_component_t alpha);
44  void set_color(unsigned int red, unsigned int green, unsigned int blue, unsigned int alpha);
45  void set_color(int red, int green, int blue, int alpha);
46  void set_color(color_component_t red, color_component_t green, color_component_t blue, color_component_t alpha);
47  void set_color(double red, double green, double blue, double alpha);
48  void set_hsl(color_component_t h, color_component_t s, color_component_t l, color_component_t alpha);
49  void get_hsl(color_component_t & hue, color_component_t & saturation, color_component_t & lightness, color_component_t & alpha) const;
50  void adjust_hue(float hue);
51  void adjust_saturation(float change);
52  void adjust_lightness(float change);
53  bool set_color(std::string const & name, bool name_only);
54  rgba_color_t get_color() const;
55  void get_color(color_component_t & red, color_component_t & green, color_component_t & blue, color_component_t & alpha) const;
56 
57  bool is_solid() const;
58  bool is_transparent() const;
59 
60  std::string to_string() const;
61 
62 private:
63  color_component_t f_red = 0.0;
64  color_component_t f_green = 0.0;
65  color_component_t f_blue = 0.0;
66  color_component_t f_alpha = 1.0;
67 };
68 
69 } // namespace csspp
70 #endif
71 // #ifndef CSSPP_COLOR_H
72 
73 // Local Variables:
74 // mode: cpp
75 // indent-tabs-mode: nil
76 // c-basic-offset: 4
77 // tab-width: 4
78 // End:
79 
80 // vim: ts=4 sw=4 et
byte_component_t f_blue
Definition: color.h:34
The namespace of all the classes in the CSS Preprocessor.
Definition: assembler.cpp:40
byte_component_t f_green
Definition: color.h:33
float color_component_t
Definition: color.h:26
uint32_t rgba_color_t
Definition: color.h:28
byte_component_t f_alpha
Definition: color.h:35
uint8_t byte_component_t
Definition: color.h:27
byte_component_t f_red
Definition: color.h:32
char const * f_name
Definition: color.h:36

Documentation of CSS Preprocessor.

This document is part of the Snap! Websites Project.

Copyright by Made to Order Software Corp.