OpenXcom  1.0
Open-source clone of the original X-Com
Font.h
1 #pragma once
2 /*
3  * Copyright 2010-2016 OpenXcom Developers.
4  *
5  * This file is part of OpenXcom.
6  *
7  * OpenXcom is free software: you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation, either version 3 of the License, or
10  * (at your option) any later version.
11  *
12  * OpenXcom is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with OpenXcom. If not, see <http://www.gnu.org/licenses/>.
19  */
20 #include <map>
21 #include <vector>
22 #include <utility>
23 #include <string>
24 #include <SDL.h>
25 #include <yaml-cpp/yaml.h>
26 #include "Unicode.h"
27 
28 namespace OpenXcom
29 {
30 
31 class Surface;
32 class Palette;
33 
34 struct FontImage
35 {
36  int width, height, spacing;
37  Surface *surface;
38 };
39 
46 class Font
47 {
48 private:
49  std::vector<FontImage> _images;
50  std::map< UCode, std::pair<size_t, SDL_Rect> > _chars;
51  bool _monospace;
53  void init(size_t index, const UString &str);
54 public:
55 
57  Font();
59  ~Font();
61  void load(const YAML::Node& node);
63  void loadTerminal();
65  Surface *getChar(UCode c);
67  int getWidth() const;
69  int getHeight() const;
71  int getSpacing() const;
73  SDL_Rect getCharSize(UCode c);
75  SDL_Color *getPalette() const;
77  void setPalette(SDL_Color *colors, int firstcolor, int ncolors);
78 };
79 
80 }
void setPalette(SDL_Color *colors, int firstcolor, int ncolors)
Sets the font&#39;s palette.
Definition: Font.cpp:259
~Font()
Cleans up the font.
Definition: Font.cpp:38
int getHeight() const
Gets the font&#39;s character height.
Definition: Font.cpp:193
SDL_Color * getPalette() const
Gets the font&#39;s palette.
Definition: Font.cpp:248
void loadTerminal()
Generate the terminal font.
Definition: Font.cpp:74
Takes care of loading and storing each character in a sprite font.
Definition: Font.h:46
int getWidth() const
Gets the font&#39;s character width.
Definition: Font.cpp:184
SDL_Rect getCharSize(UCode c)
Gets the size of a particular character;.
Definition: Font.cpp:214
Element that is blit (rendered) onto the screen.
Definition: Surface.h:38
Definition: Font.h:34
int getSpacing() const
Gets the spacing between characters.
Definition: Font.cpp:204
Font()
Creates a blank font.
Definition: Font.cpp:31
void load(const YAML::Node &node)
Loads the font from YAML.
Definition: Font.cpp:50
Surface * getChar(UCode c)
Gets a particular character from the font, with its real size.
Definition: Font.cpp:171
Definition: BaseInfoState.cpp:40