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