HoverRace  2.0
SdlSurfaceText.h
Go to the documentation of this file.
1 
2 // SdlSurfaceText.h
3 //
4 // Copyright (c) 2013, 2014 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 <SDL2/SDL.h>
25 
26 #include "../UiFont.h"
27 
28 #include "SdlDisplay.h"
29 
30 #if defined(_WIN32) && defined(HR_ENGINE_SHARED)
31 # ifdef MR_ENGINE
32 # define MR_DllDeclare __declspec( dllexport )
33 # else
34 # define MR_DllDeclare __declspec( dllimport )
35 # endif
36 #else
37 # define MR_DllDeclare
38 #endif
39 
40 namespace HoverRace {
41 namespace Display {
42 namespace SDL {
43 
60 {
61 public:
62  SdlSurfaceText(SdlDisplay &display);
63  SdlSurfaceText(SdlDisplay &display, const UiFont &font,
64  const Color color = COLOR_WHITE);
66 
67  SdlSurfaceText &operator=(const SdlSurfaceText&) = delete;
68 
69 public:
70  // Properties to control rendering.
71  void SetFont(const UiFont &font) { this->font = font; }
72  void SetColor(const Color color) { this->color = color; }
73  void SetWrapWidth(int wrapWidth) { this->wrapWidth = wrapWidth; }
74  void SetFixedScale(bool fixedScale) { this->fixedScale = fixedScale; }
75 
76 public:
77  int MeasureLineHeight();
78  SDL_Surface *RenderToNewSurface(const std::string &s);
79  SDL_Surface *RenderToSurface(SDL_Surface *dest, int x, int y,
80  const std::string &s);
81 
82 public:
83  // Properties available after rendering.
84  int GetWidth() const { return width; }
85  int GetHeight() const { return height; }
86 
87 private:
89 
92  int wrapWidth;
93  bool fixedScale;
94 
95  int width;
96  int height;
97 };
98 
99 } // namespace SDL
100 } // namespace Display
101 } // namespace HoverRace
102 
103 #undef MR_DllDeclare
A fragment of text rendered on an SDL surface.
Definition: SdlSurfaceText.h:59
~SdlSurfaceText()
Definition: SdlSurfaceText.h:65
Definition: Color.h:40
Describes a font used for the UI.
Definition: UiFont.h:44
#define MR_DllDeclare
Definition: SdlSurfaceText.h:37
constexpr Color COLOR_WHITE
Definition: Color.h:64
Color color
Definition: SdlSurfaceText.h:91
int wrapWidth
Definition: SdlSurfaceText.h:92
void SetColor(const Color color)
Definition: SdlSurfaceText.h:72
SdlDisplay & display
Definition: SdlSurfaceText.h:88
void SetWrapWidth(int wrapWidth)
Definition: SdlSurfaceText.h:73
void SetFixedScale(bool fixedScale)
Definition: SdlSurfaceText.h:74
int width
Definition: SdlSurfaceText.h:95
int height
Definition: SdlSurfaceText.h:96
UiFont font
Definition: SdlSurfaceText.h:90
int GetHeight() const
Definition: SdlSurfaceText.h:85
Definition: Announcement.h:24
void SetFont(const UiFont &font)
Definition: SdlSurfaceText.h:71
int GetWidth() const
Definition: SdlSurfaceText.h:84
SDL-based software rendering.
Definition: SdlDisplay.h:60
bool fixedScale
Definition: SdlSurfaceText.h:93