The Battle for Wesnoth  1.13.10+dev
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
font_id.hpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2016 - 2017 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 <SDL_ttf.h>
23 
24 /***
25  * Note: This is specific to SDL_TTF code path
26  */
27 
28 namespace font {
29 
30 // Signed int. Negative values mean "no subset".
31 typedef int subset_id;
32 
33 // Used as a key in the font table, which caches the get_font results.
34 struct font_id
35 {
36  explicit font_id(subset_id subset, int size) : subset(subset), size(size), style(TTF_STYLE_NORMAL) {}
37  explicit font_id(subset_id subset, int size, int style) : subset(subset), size(size), style(style) {}
38 
39  bool operator==(const font_id& o) const
40  {
41  return subset == o.subset && size == o.size && style == o.style;
42  }
43  bool operator<(const font_id& o) const
44  {
45  return subset < o.subset || (subset == o.subset && size < o.size) || (subset == o.subset && size == o.size && style < o.style);
46  }
47 
48  subset_id subset;
49  int size;
50  int style;
51 };
52 
53 /***
54  * Text chunk is used by text_surfaces and these are cached sometimes.
55  */
56 struct text_chunk
57 {
58  text_chunk(subset_id subset)
59  : subset(subset)
60  , text()
61  {
62  }
63 
64  bool operator==(text_chunk const & t) const { return subset == t.subset && text == t.text; }
65  bool operator!=(text_chunk const & t) const { return !operator==(t); }
66 
67  subset_id subset;
69 };
70 
71 } // end namespace font
bool operator==(text_chunk const &t) const
Definition: font_id.hpp:64
std::vector< char_t > string
bool operator==(const font_id &o) const
Definition: font_id.hpp:39
subset_id subset
Definition: font_id.hpp:48
Note: Specific to sdl_ttf.
bool operator<(const font_id &o) const
Definition: font_id.hpp:43
int subset_id
Definition: font_id.hpp:31
std::string text
Definition: font_id.hpp:68
bool operator!=(text_chunk const &t) const
Definition: font_id.hpp:65
subset_id subset
Definition: font_id.hpp:67
double t
Definition: astarsearch.cpp:64
font_id(subset_id subset, int size, int style)
Definition: font_id.hpp:37
text_chunk(subset_id subset)
Definition: font_id.hpp:58
font_id(subset_id subset, int size)
Definition: font_id.hpp:36