HoverRace  2.0
UiFont.h
Go to the documentation of this file.
1 
2 // UiFont.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/Hash.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 
45 {
46  UiFont(const std::string &name, double size = 20.0, int style = 0) :
47  name(name), size(size), style(style) { }
48  UiFont(double size = 20.0, int style = 0) :
49  name(), size(size), style(style) { }
50 
51  UiFont(const UiFont &o) = default;
52  UiFont(UiFont &&o) noexcept = default;
53 
54  UiFont &operator=(const UiFont &o) = default;
55  UiFont &operator=(UiFont &&o) = default;
56 
57  void Set(const std::string &name, double size = 20.0, int style = 0)
58  {
59  this->name = name;
60  this->size = size;
61  this->style = style;
62  }
63 
64  void Set(double size = 20.0, int style = 0) noexcept
65  {
66  this->name.clear();
67  this->size = size;
68  this->style = style;
69  }
70 
71  bool isBold() const noexcept { return !!(style & BOLD); }
72  bool isItalic() const noexcept { return !!(style & ITALIC); }
73 
74  enum Style {
75  BOLD = 0x01,
76  ITALIC = 0x02,
77  BOLD_ITALIC = BOLD | ITALIC,
78  };
79 
80  std::string name;
81  double size;
82  int style;
83 };
84 
85 MR_DllDeclare inline bool operator==(const UiFont &a, const UiFont &b)
86 {
87  return
88  static_cast<int>(a.size) == static_cast<int>(b.size) &&
89  a.style == b.style &&
90  a.name == b.name;
91 }
92 
93 MR_DllDeclare inline bool operator!=(const UiFont &a, const UiFont &b)
94 {
95  return !operator==(a, b);
96 }
97 
98 MR_DllDeclare inline std::ostream &operator<<(std::ostream &os,
99  const UiFont &fs)
100 {
101  if (fs.name.empty()) {
102  os << "(default)";
103  }
104  else {
105  os << fs.name;
106  }
107  if (fs.isBold()) os << " Bold";
108  if (fs.isItalic()) os << " Italic";
109  os << ' ' << fs.size;
110 
111  return os;
112 }
113 
114 } // namespace Display
115 } // namespace HoverRace
116 
117 namespace std {
118 
119 template<>
120 struct hash<HoverRace::Display::UiFont>
121 {
122  std::size_t operator()(const HoverRace::Display::UiFont &font) const
123  {
124  using namespace HoverRace::Util;
125 
126  std::size_t seed = 0;
127  Hash::Combine(seed, font.name);
128  Hash::Combine(seed, static_cast<int>(font.size));
129  Hash::Combine(seed, font.style);
130  return seed;
131  }
132 };
133 
134 } // namespace std
135 
136 #undef MR_DllDeclare
#define MR_DllDeclare
Definition: UiFont.h:34
Definition: Symbol.h:216
bool isItalic() const noexcept
Definition: UiFont.h:72
Describes a font used for the UI.
Definition: UiFont.h:44
std::string name
Definition: UiFont.h:80
UiFont(double size=20.0, int style=0)
Definition: UiFont.h:48
STL namespace.
void Combine(std::size_t &seed, const T &v)
Mix in a value into a hash.
Definition: Hash.h:42
Style
Definition: UiFont.h:74
void Set(const std::string &name, double size=20.0, int style=0)
Definition: UiFont.h:57
MR_DllDeclare constexpr bool operator!=(const Color &a, const Color &b) noexcept
Definition: Color.h:72
UiFont(const std::string &name, double size=20.0, int style=0)
Definition: UiFont.h:46
std::ostream & operator<<(std::ostream &os, const Color &c)
Definition: Color.cpp:61
bool isBold() const noexcept
Definition: UiFont.h:71
Definition: ClientApp.h:64
int style
Definition: UiFont.h:82
Definition: Symbol.h:217
MR_DllDeclare constexpr bool operator==(const Color &a, const Color &b) noexcept
Definition: Color.h:67
double size
Definition: UiFont.h:81
Definition: Announcement.h:24
void Set(double size=20.0, int style=0) noexcept
Definition: UiFont.h:64