comparison engine/core/video/fonts/imagefontbase.cpp @ 0:4a0efb7baf70

* Datasets becomes the new trunk and retires after that :-)
author mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
date Sun, 29 Jun 2008 18:44:17 +0000
parents
children 90005975cdbb
comparison
equal deleted inserted replaced
-1:000000000000 0:4a0efb7baf70
1 /***************************************************************************
2 * Copyright (C) 2005-2008 by the FIFE team *
3 * http://www.fifengine.de *
4 * This file is part of FIFE. *
5 * *
6 * FIFE is free software; you can redistribute it and/or modify *
7 * it under the terms of the GNU General Public License as published by *
8 * the Free Software Foundation; either version 2 of the License, or *
9 * (at your option) any later version. *
10 * *
11 * This program is distributed in the hope that it will be useful, *
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
14 * GNU General Public License for more details. *
15 * *
16 * You should have received a copy of the GNU General Public License *
17 * along with this program; if not, write to the *
18 * Free Software Foundation, Inc., *
19 * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA *
20 ***************************************************************************/
21
22 // Standard C++ library includes
23 #include <algorithm>
24
25 // 3rd party library includes
26 #include <boost/filesystem/convenience.hpp>
27 #include <boost/scoped_array.hpp>
28 #include <SDL.h>
29 #include <SDL_image.h>
30
31 // FIFE includes
32 // These includes are split up in two parts, separated by one empty line
33 // First block: files included from the FIFE root src directory
34 // Second block: files included from the same folder
35 #include "util/base/exception.h"
36 #include "util/structures/rect.h"
37 #include "video/image.h"
38 #include "video/renderbackend.h"
39
40 #include "imagefontbase.h"
41
42 namespace FIFE {
43
44 ImageFontBase::ImageFontBase() : FontBase() {
45 }
46
47 ImageFontBase::~ImageFontBase() {
48 type_glyphs::iterator i = m_glyphs.begin();
49 for(; i != m_glyphs.end(); ++i) {
50 SDL_FreeSurface(i->second.surface);
51 }
52
53 }
54
55 int ImageFontBase::getWidth(const std::string& text) const {
56 int w = 0;
57
58 for(size_t i=0; i!= text.size(); ++i) {
59 type_glyphs::const_iterator it = m_glyphs.find( text[i] );
60
61 if( it != m_glyphs.end() ) {
62 w += it->second.surface->w + getGlyphSpacing();
63 continue;
64 }
65
66 if( m_placeholder.surface ) {
67 w += m_placeholder.surface->w + getGlyphSpacing();
68 }
69 }
70 return w;
71 }
72
73 int ImageFontBase::getHeight() const {
74 return mHeight;
75 }
76
77 SDL_Surface *ImageFontBase::renderString(const std::string& text) {
78 SDL_Surface *surface = SDL_CreateRGBSurface(SDL_SWSURFACE,
79 getWidth(text),getHeight(),32,
80 RMASK, GMASK, BMASK ,AMASK);
81
82 SDL_FillRect(surface,0,0x00000000);
83
84 SDL_Rect dst;
85 dst.x = dst.y = 0;
86 s_glyph *glyph = 0;
87
88 for(size_t i=0; i!= text.size(); ++i) {
89 type_glyphs::iterator it = m_glyphs.find( text[i] );
90
91 if( it == m_glyphs.end() ) {
92 if( !m_placeholder.surface ) {
93 continue;
94 }
95 glyph = &m_placeholder;
96 } else {
97 glyph = &(it->second);
98 }
99 dst.y = glyph->offset.y;
100 dst.x += glyph->offset.x;
101
102 SDL_BlitSurface(glyph->surface,0,surface,&dst);
103 dst.x += glyph->surface->w + getGlyphSpacing();
104 }
105
106 return surface;
107 }
108
109 void ImageFontBase::setColor(Uint8 r, Uint8 g, Uint8 b) {
110 }
111 }