Initial commit. Not even a game yet :P
[cToan.git] / src / SDLWrap_FontSurface.hpp
blobba0e8b6f8b476b8eeefc12c628b98b2de516d005
1 #ifndef _SDLWRAP_FONTSURFACE_H_
2 #define _SDLWRAP_FONTSURFACE_H_
4 #include <string>
6 #include "SDL/SDL.h"
7 #include "boost/shared_ptr.hpp"
9 #include "SDLWrap_Surface.hpp"
10 #include "SDLWrap_Font.hpp"
11 #include "SDLWrap_Color.hpp"
13 namespace SDLWrap {
15 typedef boost::shared_ptr<Font> Font_SPtr;
17 /* The FontSurface class represents a Surface with some rendered text on it using a TTF font, and so therefore it makes
18 * use of the Surface and Font classes. The reason for this class is that creating a surface with some text on it is a
19 * common process so keeping it all nice and tidy in one class with it's related functions is a good idea.
21 class FontSurface : public Surface
23 public:
24 // TODO: Should the RenderText* functions throw an exception if it fails to render or...?
25 // maybe depends on whether I render text every frame or only upon creation...
26 /* The constructor takes a std::string so that it knows what text to render on the surface. It is of type
27 * std::string even when SDL uses C style null terminated strings (and therefore internally in this class) but
28 * I want to have more flexible access and usage over the string, and using a std::string doesn't really incure
29 * that huge of an overhead so why not? We'll just use std::string::c_str() whenever we're dealing with SDL
30 * calls.
32 * It also takes a boost shared_ptr to a Font object, which means it has to already exist.
34 FontSurface(std::string Text, Font_SPtr Font, Color ColorOfText);
36 /* Is there even a use for this lol? The Surface will automatically destruct and free itself and the shared_ptr
37 * is taking care of the Font, so really, what is there to do xD
39 ~FontSurface();
41 /* Renders a surface with text on it. The SurfaceText becomes the text, rendered in the font pointed to by
42 * meFont and you can specify a color to render it in.
44 * Create an 8-bit palettized surface and render the given text at fast quality with the given font and color.
45 * The pixel value of 0 is the colorkey, giving a transparent background when blitted. Pixel and colormap value
46 * 1 is set to the text foreground color. This allows you to change the color without having to render the text
47 * again. Palette index 0 is of course not drawn when blitted to another surface, since it is the colorkey, and
48 * thus transparent, though its actual color is 255 minus each of the RGB components of the foreground color.
49 * This is the fastest rendering speed of all the rendering modes. This results in no box around the text, but
50 * the text is not as smooth. The resulting surface should blit faster than the Blended one. Use this mode for
51 * FPS and other fast changing updating text displays.
53 * This and Blended/Shaded descriptions from: http://jcatki.no-ip.org/SDL_ttf/SDL_ttf_42.html#SEC42
55 void RenderTextSolid();
57 private:
58 Font_SPtr meFont;
59 std::string SurfaceText;
60 Color TextColor;
65 #endif