The Battle for Wesnoth  1.15.0-dev
font_id.hpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2016 - 2018 by Chris Beck<render787@gmail.com>
3  Part of the Battle for Wesnoth Project http://www.wesnoth.org/
4 
5  This program is free software; you can redistribute it and/or modify
6  it under the terms of the GNU General Public License as published by
7  the Free Software Foundation; either version 2 of the License, or
8  (at your option) any later version.
9  This program is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY.
11 
12  See the COPYING file for more details.
13 */
14 
15 /***
16  * Note: Specific to SDL_TTF code path
17  */
18 
19 #pragma once
20 
21 #include <string>
22 #include <tuple>
23 
24 #include <SDL_ttf.h>
25 
26 /***
27  * Note: This is specific to SDL_TTF code path
28  */
29 
30 namespace font {
31 
32 // Signed int. Negative values mean "no subset".
33 typedef int subset_id;
34 
35 // Used as a key in the font table, which caches the get_font results.
36 struct font_id
37 {
38  explicit font_id(subset_id subset, int size) : subset(subset), size(size), style(TTF_STYLE_NORMAL) {}
39  explicit font_id(subset_id subset, int size, int style) : subset(subset), size(size), style(style) {}
40 
41  bool operator==(const font_id& o) const
42  {
43  return subset == o.subset && size == o.size && style == o.style;
44  }
45  bool operator<(const font_id& o) const
46  {
47  return std::tie(subset, size, style) < std::tie(o.subset, o.size, o.style);
48  }
49 
50  subset_id subset;
51  int size;
52  int style;
53 };
54 
55 /***
56  * Text chunk is used by text_surfaces and these are cached sometimes.
57  */
58 struct text_chunk
59 {
60  text_chunk(subset_id subset)
61  : subset(subset)
62  , text()
63  {
64  }
65 
66  bool operator==(const text_chunk& t) const { return subset == t.subset && text == t.text; }
67  bool operator!=(const text_chunk& t) const { return !operator==(t); }
68 
69  subset_id subset;
71 };
72 
73 } // end namespace font
std::vector< char_t > string
subset_id subset
Definition: font_id.hpp:50
Note: Specific to sdl_ttf.
int subset_id
Definition: font_id.hpp:33
std::string text
Definition: font_id.hpp:70
bool operator==(const font_id &o) const
Definition: font_id.hpp:41
bool operator!=(const text_chunk &t) const
Definition: font_id.hpp:67
subset_id subset
Definition: font_id.hpp:69
double t
Definition: astarsearch.cpp:64
font_id(subset_id subset, int size, int style)
Definition: font_id.hpp:39
text_chunk(subset_id subset)
Definition: font_id.hpp:60
font_id(subset_id subset, int size)
Definition: font_id.hpp:38
bool operator==(const text_chunk &t) const
Definition: font_id.hpp:66
bool operator<(const font_id &o) const
Definition: font_id.hpp:45