1 /**
2 Renders text using `*.fnt` fonts.
3 
4 Copyright:
5 Copyright (c) 2007-2018 Juan Linietsky, Ariel Manzur.  
6 Copyright (c) 2014-2018 Godot Engine contributors (cf. AUTHORS.md)  
7 Copyright (c) 2017-2018 Godot-D contributors  
8 
9 License: $(LINK2 https://opensource.org/licenses/MIT, MIT License)
10 
11 
12 */
13 module godot.bitmapfont;
14 import std.meta : AliasSeq, staticIndexOf;
15 import std.traits : Unqual;
16 import godot.d.meta;
17 import godot.core;
18 import godot.c;
19 import godot.d.bind;
20 import godot.d.reference;
21 import godot.object;
22 import godot.classdb;
23 import godot.font;
24 import godot.texture;
25 import godot.resource;
26 import godot.reference;
27 /**
28 Renders text using `*.fnt` fonts.
29 
30 Renders text using `*.fnt` fonts containing texture atlases. Supports distance fields. For using vector font files like TTF directly, see $(D DynamicFont).
31 */
32 @GodotBaseClass struct BitmapFont
33 {
34 	enum string _GODOT_internal_name = "BitmapFont";
35 public:
36 @nogc nothrow:
37 	union { godot_object _godot_object; Font _GODOT_base; }
38 	alias _GODOT_base this;
39 	alias BaseClasses = AliasSeq!(typeof(_GODOT_base), typeof(_GODOT_base).BaseClasses);
40 	package(godot) __gshared bool _classBindingInitialized = false;
41 	package(godot) static struct _classBinding
42 	{
43 		__gshared:
44 		@GodotName("create_from_fnt") GodotMethod!(GodotError, String) createFromFnt;
45 		@GodotName("set_height") GodotMethod!(void, double) setHeight;
46 		@GodotName("set_ascent") GodotMethod!(void, double) setAscent;
47 		@GodotName("add_kerning_pair") GodotMethod!(void, long, long, long) addKerningPair;
48 		@GodotName("get_kerning_pair") GodotMethod!(long, long, long) getKerningPair;
49 		@GodotName("add_texture") GodotMethod!(void, Texture) addTexture;
50 		@GodotName("add_char") GodotMethod!(void, long, long, Rect2, Vector2, double) addChar;
51 		@GodotName("get_texture_count") GodotMethod!(long) getTextureCount;
52 		@GodotName("get_texture") GodotMethod!(Texture, long) getTexture;
53 		@GodotName("get_char_size") GodotMethod!(Vector2, long, long) getCharSize;
54 		@GodotName("set_distance_field_hint") GodotMethod!(void, bool) setDistanceFieldHint;
55 		@GodotName("clear") GodotMethod!(void) clear;
56 		@GodotName("_set_chars") GodotMethod!(void, PoolIntArray) _setChars;
57 		@GodotName("_get_chars") GodotMethod!(PoolIntArray) _getChars;
58 		@GodotName("_set_kernings") GodotMethod!(void, PoolIntArray) _setKernings;
59 		@GodotName("_get_kernings") GodotMethod!(PoolIntArray) _getKernings;
60 		@GodotName("_set_textures") GodotMethod!(void, Array) _setTextures;
61 		@GodotName("_get_textures") GodotMethod!(Array) _getTextures;
62 		@GodotName("set_fallback") GodotMethod!(void, BitmapFont) setFallback;
63 		@GodotName("get_fallback") GodotMethod!(BitmapFont) getFallback;
64 	}
65 	bool opEquals(in BitmapFont other) const { return _godot_object.ptr is other._godot_object.ptr; }
66 	BitmapFont opAssign(T : typeof(null))(T n) { _godot_object.ptr = null; }
67 	bool opEquals(typeof(null) n) const { return _godot_object.ptr is null; }
68 	mixin baseCasts;
69 	static BitmapFont _new()
70 	{
71 		static godot_class_constructor constructor;
72 		if(constructor is null) constructor = _godot_api.godot_get_class_constructor("BitmapFont");
73 		if(constructor is null) return typeof(this).init;
74 		return cast(BitmapFont)(constructor());
75 	}
76 	@disable new(size_t s);
77 	/**
78 	Creates a BitmapFont from the `*.fnt` file at `path`.
79 	*/
80 	GodotError createFromFnt(StringArg0)(in StringArg0 path)
81 	{
82 		checkClassBinding!(typeof(this))();
83 		return ptrcall!(GodotError)(_classBinding.createFromFnt, _godot_object, path);
84 	}
85 	/**
86 	
87 	*/
88 	void setHeight(in double px)
89 	{
90 		checkClassBinding!(typeof(this))();
91 		ptrcall!(void)(_classBinding.setHeight, _godot_object, px);
92 	}
93 	/**
94 	
95 	*/
96 	void setAscent(in double px)
97 	{
98 		checkClassBinding!(typeof(this))();
99 		ptrcall!(void)(_classBinding.setAscent, _godot_object, px);
100 	}
101 	/**
102 	Adds a kerning pair to the `BitmapFont` as a difference. Kerning pairs are special cases where a typeface advance is determined by the next character.
103 	*/
104 	void addKerningPair(in long char_a, in long char_b, in long kerning)
105 	{
106 		checkClassBinding!(typeof(this))();
107 		ptrcall!(void)(_classBinding.addKerningPair, _godot_object, char_a, char_b, kerning);
108 	}
109 	/**
110 	Returns a kerning pair as a difference.
111 	*/
112 	long getKerningPair(in long char_a, in long char_b) const
113 	{
114 		checkClassBinding!(typeof(this))();
115 		return ptrcall!(long)(_classBinding.getKerningPair, _godot_object, char_a, char_b);
116 	}
117 	/**
118 	Adds a texture to the `BitmapFont`.
119 	*/
120 	void addTexture(Texture texture)
121 	{
122 		checkClassBinding!(typeof(this))();
123 		ptrcall!(void)(_classBinding.addTexture, _godot_object, texture);
124 	}
125 	/**
126 	Adds a character to the font, where `character` is the unicode value, `texture` is the texture index, `rect` is the region in the texture (in pixels!), `align` is the (optional) alignment for the character and `advance` is the (optional) advance.
127 	*/
128 	void addChar(in long character, in long texture, in Rect2 rect, in Vector2 _align = Vector2(0, 0), in double advance = -1)
129 	{
130 		checkClassBinding!(typeof(this))();
131 		ptrcall!(void)(_classBinding.addChar, _godot_object, character, texture, rect, _align, advance);
132 	}
133 	/**
134 	Returns the number of textures in the BitmapFont atlas.
135 	*/
136 	long getTextureCount() const
137 	{
138 		checkClassBinding!(typeof(this))();
139 		return ptrcall!(long)(_classBinding.getTextureCount, _godot_object);
140 	}
141 	/**
142 	Returns the font atlas texture at index `idx`.
143 	*/
144 	Ref!Texture getTexture(in long idx) const
145 	{
146 		checkClassBinding!(typeof(this))();
147 		return ptrcall!(Texture)(_classBinding.getTexture, _godot_object, idx);
148 	}
149 	/**
150 	Returns the size of a character, optionally taking kerning into account if the next character is provided.
151 	*/
152 	Vector2 getCharSize(in long _char, in long next = 0) const
153 	{
154 		checkClassBinding!(typeof(this))();
155 		return ptrcall!(Vector2)(_classBinding.getCharSize, _godot_object, _char, next);
156 	}
157 	/**
158 	
159 	*/
160 	void setDistanceFieldHint(in bool enable)
161 	{
162 		checkClassBinding!(typeof(this))();
163 		ptrcall!(void)(_classBinding.setDistanceFieldHint, _godot_object, enable);
164 	}
165 	/**
166 	Clears all the font data and settings.
167 	*/
168 	void clear()
169 	{
170 		checkClassBinding!(typeof(this))();
171 		ptrcall!(void)(_classBinding.clear, _godot_object);
172 	}
173 	/**
174 	
175 	*/
176 	void _setChars(in PoolIntArray arg0)
177 	{
178 		Array _GODOT_args = Array.empty_array;
179 		_GODOT_args.append(arg0);
180 		String _GODOT_method_name = String("_set_chars");
181 		this.callv(_GODOT_method_name, _GODOT_args);
182 	}
183 	/**
184 	
185 	*/
186 	PoolIntArray _getChars() const
187 	{
188 		Array _GODOT_args = Array.empty_array;
189 		String _GODOT_method_name = String("_get_chars");
190 		return this.callv(_GODOT_method_name, _GODOT_args).as!(RefOrT!PoolIntArray);
191 	}
192 	/**
193 	
194 	*/
195 	void _setKernings(in PoolIntArray arg0)
196 	{
197 		Array _GODOT_args = Array.empty_array;
198 		_GODOT_args.append(arg0);
199 		String _GODOT_method_name = String("_set_kernings");
200 		this.callv(_GODOT_method_name, _GODOT_args);
201 	}
202 	/**
203 	
204 	*/
205 	PoolIntArray _getKernings() const
206 	{
207 		Array _GODOT_args = Array.empty_array;
208 		String _GODOT_method_name = String("_get_kernings");
209 		return this.callv(_GODOT_method_name, _GODOT_args).as!(RefOrT!PoolIntArray);
210 	}
211 	/**
212 	
213 	*/
214 	void _setTextures(in Array arg0)
215 	{
216 		Array _GODOT_args = Array.empty_array;
217 		_GODOT_args.append(arg0);
218 		String _GODOT_method_name = String("_set_textures");
219 		this.callv(_GODOT_method_name, _GODOT_args);
220 	}
221 	/**
222 	
223 	*/
224 	Array _getTextures() const
225 	{
226 		Array _GODOT_args = Array.empty_array;
227 		String _GODOT_method_name = String("_get_textures");
228 		return this.callv(_GODOT_method_name, _GODOT_args).as!(RefOrT!Array);
229 	}
230 	/**
231 	
232 	*/
233 	void setFallback(BitmapFont fallback)
234 	{
235 		checkClassBinding!(typeof(this))();
236 		ptrcall!(void)(_classBinding.setFallback, _godot_object, fallback);
237 	}
238 	/**
239 	
240 	*/
241 	Ref!BitmapFont getFallback() const
242 	{
243 		checkClassBinding!(typeof(this))();
244 		return ptrcall!(BitmapFont)(_classBinding.getFallback, _godot_object);
245 	}
246 	/**
247 	
248 	*/
249 	@property Array textures()
250 	{
251 		return _getTextures();
252 	}
253 	/// ditto
254 	@property void textures(Array v)
255 	{
256 		_setTextures(v);
257 	}
258 	/**
259 	
260 	*/
261 	@property PoolIntArray chars()
262 	{
263 		return _getChars();
264 	}
265 	/// ditto
266 	@property void chars(PoolIntArray v)
267 	{
268 		_setChars(v);
269 	}
270 	/**
271 	
272 	*/
273 	@property PoolIntArray kernings()
274 	{
275 		return _getKernings();
276 	}
277 	/// ditto
278 	@property void kernings(PoolIntArray v)
279 	{
280 		_setKernings(v);
281 	}
282 	/**
283 	Total font height (ascent plus descent) in pixels.
284 	*/
285 	@property double height()
286 	{
287 		return getHeight();
288 	}
289 	/// ditto
290 	@property void height(double v)
291 	{
292 		setHeight(v);
293 	}
294 	/**
295 	Ascent (number of pixels above the baseline).
296 	*/
297 	@property double ascent()
298 	{
299 		return getAscent();
300 	}
301 	/// ditto
302 	@property void ascent(double v)
303 	{
304 		setAscent(v);
305 	}
306 	/**
307 	If `true` distance field hint is enabled.
308 	*/
309 	@property bool distanceField()
310 	{
311 		return isDistanceFieldHint();
312 	}
313 	/// ditto
314 	@property void distanceField(bool v)
315 	{
316 		setDistanceFieldHint(v);
317 	}
318 	/**
319 	The fallback font.
320 	*/
321 	@property BitmapFont fallback()
322 	{
323 		return getFallback();
324 	}
325 	/// ditto
326 	@property void fallback(BitmapFont v)
327 	{
328 		setFallback(v);
329 	}
330 }