tmxparser  2.1.0
 All Classes Functions Variables Pages
TmxColor.h
1 //-----------------------------------------------------------------------------
2 // TmxColor.h
3 //
4 // Copyright (c) 2017, Guillaume Bertholon
5 // All rights reserved.
6 //
7 // Redistribution and use in source and binary forms, with or without
8 // modification, are permitted provided that the following conditions are met:
9 // * Redistributions of source code must retain the above copyright
10 // notice, this list of conditions and the following disclaimer.
11 // * Redistributions in binary form must reproduce the above copyright
12 // notice, this list of conditions and the following disclaimer in the
13 // documentation and/or other materials provided with the distribution.
14 //
15 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
16 // ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
17 // WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
18 // DISCLAIMED. IN NO EVENT SHALL TAMIR ATIAS BE LIABLE FOR ANY
19 // DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
20 // (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
21 // LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
22 // ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
24 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25 //
26 // Author: Guillaume Bertholon
27 //-----------------------------------------------------------------------------
28 #pragma once
29 
30 #include <string>
31 #include <cstdint>
32 
33 namespace Tmx
34 {
35  //-------------------------------------------------------------------------
37  //-------------------------------------------------------------------------
38  class Color
39  {
40  public:
42  Color();
43 
45  Color(uint32_t color);
46 
48  Color(uint8_t r, uint8_t g, uint8_t b, uint8_t a = 255);
49 
51  explicit Color(const std::string& str);
52 
53  ~Color();
54 
56  Color(const Color&) = default;
57 
59  Color& operator=(const Color&) = default;
60 
62  bool operator==(const Color& o) { return color == o.color; }
63 
65  bool operator!=(const Color& o) { return color != o.color; }
66 
68  uint8_t GetAlpha() const;
69 
71  uint8_t GetRed() const;
72 
74  uint8_t GetGreen() const;
75 
77  uint8_t GetBlue() const;
78 
80  bool IsTransparent() const;
81 
83  uint32_t ToInt() const { return color; }
84 
86  std::string ToString() const;
87 
88  private:
89  uint32_t color;
90  };
91 }
uint8_t GetBlue() const
Get the blue component of the color.
Definition: TmxColor.cpp:85
uint8_t GetGreen() const
Get the green component of the color.
Definition: TmxColor.cpp:80
bool operator==(const Color &o)
Check if two colors have the exact same four components.
Definition: TmxColor.h:62
bool operator!=(const Color &o)
Check if two colors are different.
Definition: TmxColor.h:65
Color & operator=(const Color &)=default
Default asignment operator.
uint8_t GetAlpha() const
Get the alpha component of the color.
Definition: TmxColor.cpp:70
uint32_t ToInt() const
Get the 32 bits integer representing the color. The 8 highest bits are for the alpha channel...
Definition: TmxColor.h:83
uint8_t GetRed() const
Get the red component of the color.
Definition: TmxColor.cpp:75
std::string ToString() const
Get a string representation of the color in the format "#AARRGGBB".
Definition: TmxColor.cpp:95
Color()
Default constructor for a fully transparent black color.
Definition: TmxColor.cpp:34
A class used for storing information about a color.
Definition: TmxColor.h:38
bool IsTransparent() const
Return true if the color is fully transparent (ie alpha value is 0).
Definition: TmxColor.cpp:90