HoverRace  2.0
Color.h
Go to the documentation of this file.
1 
2 // Color.h
3 //
4 // Copyright (c) 2013, 2015 Michael Imamura.
5 //
6 // Licensed under GrokkSoft HoverRace SourceCode License v1.0(the "License");
7 // you may not use this file except in compliance with the License.
8 //
9 // A copy of the license should have been attached to the package from which
10 // you have taken this file. If you can not find the license you can not use
11 // this file.
12 //
13 //
14 // The author makes no representations about the suitability of
15 // this software for any purpose. It is provided "as is" "AS IS",
16 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
17 // implied.
18 //
19 // See the License for the specific language governing permissions
20 // and limitations under the License.
21 
22 #pragma once
23 
24 #include "../Util/MR_Types.h"
25 #include "../Util/SelFmt.h"
26 
27 #if defined(_WIN32) && defined(HR_ENGINE_SHARED)
28 # ifdef MR_ENGINE
29 # define MR_DllDeclare __declspec( dllexport )
30 # else
31 # define MR_DllDeclare __declspec( dllimport )
32 # endif
33 #else
34 # define MR_DllDeclare
35 #endif
36 
37 namespace HoverRace {
38 namespace Display {
39 
41 {
42  constexpr Color() noexcept : argb(0) { }
43  constexpr Color(MR_UInt32 argb) noexcept : argb(argb) { }
44  constexpr Color(MR_UInt8 a, MR_UInt8 r, MR_UInt8 g, MR_UInt8 b) noexcept :
45  argb(((MR_UInt32)a << 24) +
46  ((MR_UInt32)r << 16) +
47  ((MR_UInt32)g << 8) +
48  (MR_UInt32)b)
49  { }
50 
51  Color &operator=(MR_UInt32 argb) noexcept
52  {
53  this->argb = argb;
54  return *this;
55  }
56 
58  struct
59  {
60  MR_UInt8 b, g, r, a;
61  } bits;
62 };
63 
64 constexpr Color COLOR_WHITE{ 0xff, 0xff, 0xff, 0xff };
65 constexpr Color COLOR_BLACK{ 0xff, 0x00, 0x00, 0x00 };
66 
67 MR_DllDeclare inline constexpr bool operator==(const Color &a, const Color &b) noexcept
68 {
69  return a.argb == b.argb;
70 }
71 
72 MR_DllDeclare inline constexpr bool operator!=(const Color &a, const Color &b) noexcept
73 {
74  return !operator==(a, b);
75 }
76 
77 MR_DllDeclare std::istream &operator>>(std::istream &is, Color &c);
78 
79 MR_DllDeclare std::ostream &operator<<(std::ostream &os, const Color &c);
80 
81 } // namespace Display
82 } // namespace HoverRace
83 
84 #undef MR_DllDeclare
Definition: Color.h:40
MR_UInt8 r
Definition: Color.h:60
constexpr Color COLOR_WHITE
Definition: Color.h:64
std::istream & operator>>(std::istream &is, Color &c)
Definition: Color.cpp:33
constexpr Color(MR_UInt32 argb) noexcept
Definition: Color.h:43
MR_DllDeclare constexpr bool operator!=(const Color &a, const Color &b) noexcept
Definition: Color.h:72
std::ostream & operator<<(std::ostream &os, const Color &c)
Definition: Color.cpp:61
constexpr Color() noexcept
Definition: Color.h:42
MR_DllDeclare constexpr bool operator==(const Color &a, const Color &b) noexcept
Definition: Color.h:67
constexpr Color(MR_UInt8 a, MR_UInt8 r, MR_UInt8 g, MR_UInt8 b) noexcept
Definition: Color.h:44
Definition: Announcement.h:24
constexpr Color COLOR_BLACK
Definition: Color.h:65
#define MR_DllDeclare
Definition: Color.h:34
uint32_t MR_UInt32
Definition: MR_Types.h:44
MR_UInt32 argb
Definition: Color.h:57
Color & operator=(MR_UInt32 argb) noexcept
Definition: Color.h:51
uint8_t MR_UInt8
Definition: MR_Types.h:40