HoverRace  2.0
SdlTypeCase.h
Go to the documentation of this file.
1 
2 // SdlTypeCase.h
3 //
4 // Copyright (c) 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 "../TypeCase.h"
25 
26 #if defined(_WIN32) && defined(HR_ENGINE_SHARED)
27 # ifdef MR_ENGINE
28 # define MR_DllDeclare __declspec( dllexport )
29 # else
30 # define MR_DllDeclare __declspec( dllimport )
31 # endif
32 #else
33 # define MR_DllDeclare
34 #endif
35 
36 namespace HoverRace {
37  namespace Display {
38  namespace SDL {
39  class SdlDisplay;
40  class SdlDynamicTexture;
41  }
42  }
43 }
44 
45 namespace HoverRace {
46 namespace Display {
47 namespace SDL {
48 
54  public TypeCase,
55  public std::enable_shared_from_this<SdlTypeCase>
56 {
57  using SUPER = TypeCase;
58 
59 public:
60  SdlTypeCase(SdlDisplay &display, const UiFont &font, int width, int height);
61  SdlTypeCase(const SdlTypeCase&) = delete;
62  virtual ~SdlTypeCase();
63 
64  SdlTypeCase &operator=(const SdlTypeCase&) = delete;
65 
66 public:
67  MR_UInt32 CountTextures() const override;
68 
69 private:
70  GlyphEntry &AddGlyph(GlyphEntry &ent, const std::string &s,
71  MR_UInt32 cp, std::string &added);
72  GlyphEntry &FindGlyph(const std::string &s, MR_UInt32 cp,
73  std::string &added);
74 
75 public:
76  void Prepare(const std::string &s, TypeLine *rects = nullptr) override;
77  void Render(const TypeLine &s, const Color color, int x, int y,
78  boost::optional<size_t> caret = {}) override;
79  void RenderTexture(MR_UInt32 idx, int x, int y,
80  double scale = 1.0) override;
81 
82 protected:
84 private:
85  struct Metrics
86  {
87  Metrics(SdlDisplay &display, const UiFont &font);
88 
89  int fontHeight;
90  int lineHeight;
91  int spaceWidth;
92  } metrics;
93  using glyphPage_t = std::array<GlyphEntry, 256>;
94  std::array<std::unique_ptr<glyphPage_t>, 256> glyphs;
95  std::vector<std::unique_ptr<SdlDynamicTexture>> maps;
97  int curX, curY;
98 };
99 
100 } // namespace SDL
101 } // namespace Display
102 } // namespace HoverRace
103 
104 #undef MR_DllDeclare
#define MR_DllDeclare
Definition: SdlTypeCase.h:33
Definition: Color.h:40
Describes a font used for the UI.
Definition: UiFont.h:44
Character-by-character text renderer.
Definition: TypeCase.h:69
MR_UInt32 curMap
Definition: SdlTypeCase.h:96
SDL implementation of TypeCase.
Definition: SdlTypeCase.h:53
int spaceWidth
The width of a space character.
Definition: SdlTypeCase.h:91
std::array< GlyphEntry, 256 > glyphPage_t
Definition: SdlTypeCase.h:93
int fontHeight
The maximum height of a glyph.
Definition: SdlTypeCase.h:89
SdlDisplay & display
Definition: SdlTypeCase.h:83
int lineHeight
Total height of a line (including line spacing).
Definition: SdlTypeCase.h:90
std::array< std::unique_ptr< glyphPage_t >, 256 > glyphs
Definition: SdlTypeCase.h:94
int curY
Definition: SdlTypeCase.h:97
A line of text, prepared by a TypeCase.
Definition: TypeCase.h:156
int idx
Definition: SdlDisplay.cpp:254
Definition: Announcement.h:24
uint32_t MR_UInt32
Definition: MR_Types.h:44
SDL-based software rendering.
Definition: SdlDisplay.h:60
A single glyph in the backing texture.
Definition: TypeCase.h:50
std::vector< std::unique_ptr< SdlDynamicTexture > > maps
Definition: SdlTypeCase.h:95