File: font.h

package info (click to toggle)
btanks 0.9.8083-6
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 43,584 kB
  • sloc: cpp: 46,423; ansic: 12,005; xml: 4,262; python: 313; sh: 13; makefile: 13
file content (84 lines) | stat: -rw-r--r-- 2,552 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#ifndef __SDLX_FONT_H__
#define __SDLX_FONT_H__

/* sdlx - c++ wrapper for libSDL
 * Copyright (C) 2005-2007 Vladimir Menshakov
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.

 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 * 
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/

#include <string>
#include <vector>
#include <functional>
#include <map>
#include "export_sdlx.h"

namespace mrt {
	class Chunk;
}

namespace sdlx {

class Surface;
class SDLXAPI Font {
public:
	enum Type { Undefined, AZ09, Ascii };
	enum Align { Center, Left, Right };
	Font();
	~Font();
	
	void add_page(const unsigned base, const mrt::Chunk &data, const bool alpha = true);
	
	void load(const mrt::Chunk &data, const Type type, const bool alpha = true);
	void load(const std::string &file, const Type type, const bool alpha = true);
	const int get_height() const;
	const int get_width() const; //fixme! returns height ;)

	const int render(sdlx::Surface *window, int x, int y, const std::string &str) const;
	inline const int render(sdlx::Surface &window, int x, int y, const std::string &str) const {
		return render(&window, x, y, str);
	}
	
	//extend it with maximum_width argument and spacing
	//window == NULL, output in w/h
	//window != NULL: you must provide w/h (align == Center / Right)
	void render_multiline(int &w, int &h, sdlx::Surface *window, int x, int y, const std::string &str, Align align = Center) const;

	//frees window!
	const int render(sdlx::Surface &window, const std::string &str) const;
	void clear();

private:
	static const unsigned to_upper(const unsigned page, const unsigned c);

	Type _type;
	
	Font(const Font &);
	const Font& operator=(const Font &);
	
	struct Page {
		Page(bool alpha) : width_map(), surface(NULL), alpha(alpha) {}
		std::vector<std::pair<int, int> > width_map;
		sdlx::Surface *surface;
		bool alpha;
	};
	typedef std::map<const unsigned int, Page, std::greater<const unsigned int> > Pages;
	Pages _pages;
};

}

#endif