ScummVM API documentation
TextManager.h
1 /* ScummVM - Graphic Adventure Engine
2  *
3  * ScummVM is the legal property of its developers, whose names
4  * are too numerous to list here. Please refer to the COPYRIGHT
5  * file distributed with this source distribution.
6  *
7  * This program 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  * This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
19  *
20  */
21 
22 /*
23  * This code is based on the CRAB engine
24  *
25  * Copyright (c) Arvind Raja Yadav
26  *
27  * Licensed under MIT
28  *
29  */
30 
31 #ifndef CRAB_TEXTMANAGER_H
32 #define CRAB_TEXTMANAGER_H
33 
34 #include "crab/vectors.h"
35 #include "crab/image/Image.h"
36 #include "crab/text/color.h"
37 
38 namespace Graphics {
39 class Font;
40 } // End of namespace Graphics
41 
42 namespace Crab {
43 
44 // We use this object as the key for all fonts
45 typedef uint FontKey;
46 
47 // Since we use uint as a key for images, our loadImgKey function is loadNum
48 #define LoadFontKey loadNum
49 
50 namespace pyrodactyl {
51 namespace text {
52 class TextManager {
53  // The collection of stored fonts
55 
56  // The size of the cache
57  int _cacheSize;
58 
59  // The padding at the end of the background - this needs to be loaded from file later
60  Vector2i _padBg;
61 
62  // The data stored in our cache - text and texture
63  struct TextCacheUnit {
64  Common::String _text;
65  int _col;
66  FontKey _font;
67 
69  bool _empty;
70 
71  TextCacheUnit() {
72  _empty = true;
73  _col = 0;
74  _font = 0;
75  }
76  ~TextCacheUnit() {
77  _img.deleteImage();
78  }
79 
80  bool EqualCol(int color) {
81  return _col == color;
82  }
83  };
84 
85  // Text Cache - done to avoid having to render a texture every time text is drawn
87 
88  // The oldest element in the text cache
89  int _oldest;
90 
91  // The place to store all colors
92  ColorPool _colpool;
93 
94  // The rectangle used to store the darkened rectangle coordinates
95  Rect _rect;
96 
97  int search(const Common::String &text, int col, FontKey fontid);
98  int findFreeSlot();
99 
100 public:
101  TextManager() {
102  _oldest = 0;
103  _cacheSize = 30;
104  }
105 
106  ~TextManager() {}
107 
108  void init();
109  void quit();
110  void reset();
111 
112  Graphics::Font *getFont(const FontKey &fontid) {
113  return _font[fontid];
114  }
115 
116  Graphics::ManagedSurface *renderTextBlended(const FontKey &font, const Common::String &text, const int &color);
117 
118  void draw(const int &x, const int &y, const Common::String &text, const int &color,
119  const FontKey &font = 0, const Align &align = ALIGN_LEFT, const bool &background = false);
120 
121  void draw(const int &x, int y, const Common::String &text, const int &color, const FontKey &font, const Align &align,
122  const uint &lineWidth, const uint &lineHeight, const bool &background = false);
123 };
124 
125 } // End of namespace text
126 } // End of namespace pyrodactyl
127 
128 } // End of namespace Crab
129 
130 #endif // CRAB_TEXTMANAGER_H
Definition: managed_surface.h:51
Definition: color.h:43
Definition: str.h:59
Definition: font.h:83
Definition: Rectangle.h:42
Definition: array.h:52
Definition: Image.h:51
Definition: TextManager.h:52
Definition: formatinfo.h:28
Definition: moveeffect.h:37