1 /**
2 Internationalized font and text drawing support.
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.font;
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.resource;
23 import godot.reference;
24 /**
25 Internationalized font and text drawing support.
26 
27 Font contains a unicode compatible character set, as well as the ability to draw it with variable width, ascent, descent and kerning. For creating fonts from TTF files (or other font formats), see the editor support for fonts. TODO check wikipedia for graph of ascent/baseline/descent/height/etc.
28 */
29 @GodotBaseClass struct Font
30 {
31 	enum string _GODOT_internal_name = "Font";
32 public:
33 @nogc nothrow:
34 	union { godot_object _godot_object; Resource _GODOT_base; }
35 	alias _GODOT_base this;
36 	alias BaseClasses = AliasSeq!(typeof(_GODOT_base), typeof(_GODOT_base).BaseClasses);
37 	package(godot) __gshared bool _classBindingInitialized = false;
38 	package(godot) static struct _classBinding
39 	{
40 		__gshared:
41 		@GodotName("draw") GodotMethod!(void, RID, Vector2, String, Color, long, Color) draw;
42 		@GodotName("get_ascent") GodotMethod!(double) getAscent;
43 		@GodotName("get_descent") GodotMethod!(double) getDescent;
44 		@GodotName("get_height") GodotMethod!(double) getHeight;
45 		@GodotName("is_distance_field_hint") GodotMethod!(bool) isDistanceFieldHint;
46 		@GodotName("get_string_size") GodotMethod!(Vector2, String) getStringSize;
47 		@GodotName("has_outline") GodotMethod!(bool) hasOutline;
48 		@GodotName("draw_char") GodotMethod!(double, RID, Vector2, long, long, Color, bool) drawChar;
49 		@GodotName("update_changes") GodotMethod!(void) updateChanges;
50 	}
51 	bool opEquals(in Font other) const { return _godot_object.ptr is other._godot_object.ptr; }
52 	Font opAssign(T : typeof(null))(T n) { _godot_object.ptr = null; }
53 	bool opEquals(typeof(null) n) const { return _godot_object.ptr is null; }
54 	mixin baseCasts;
55 	static Font _new()
56 	{
57 		static godot_class_constructor constructor;
58 		if(constructor is null) constructor = _godot_api.godot_get_class_constructor("Font");
59 		if(constructor is null) return typeof(this).init;
60 		return cast(Font)(constructor());
61 	}
62 	@disable new(size_t s);
63 	/**
64 	Draw "string" into a canvas item using the font at a given position, with "modulate" color, and optionally clipping the width. "position" specifies the baseline, not the top. To draw from the top, $(I ascent) must be added to the Y axis.
65 	*/
66 	void draw(StringArg2)(in RID canvas_item, in Vector2 position, in StringArg2 string, in Color modulate = Color(1,1,1,1), in long clip_w = -1, in Color outline_modulate = Color(1,1,1,1)) const
67 	{
68 		checkClassBinding!(typeof(this))();
69 		ptrcall!(void)(_classBinding.draw, _godot_object, canvas_item, position, string, modulate, clip_w, outline_modulate);
70 	}
71 	/**
72 	Return the font ascent (number of pixels above the baseline).
73 	*/
74 	double getAscent() const
75 	{
76 		checkClassBinding!(typeof(this))();
77 		return ptrcall!(double)(_classBinding.getAscent, _godot_object);
78 	}
79 	/**
80 	Return the font descent (number of pixels below the baseline).
81 	*/
82 	double getDescent() const
83 	{
84 		checkClassBinding!(typeof(this))();
85 		return ptrcall!(double)(_classBinding.getDescent, _godot_object);
86 	}
87 	/**
88 	Return the total font height (ascent plus descent) in pixels.
89 	*/
90 	double getHeight() const
91 	{
92 		checkClassBinding!(typeof(this))();
93 		return ptrcall!(double)(_classBinding.getHeight, _godot_object);
94 	}
95 	/**
96 	
97 	*/
98 	bool isDistanceFieldHint() const
99 	{
100 		checkClassBinding!(typeof(this))();
101 		return ptrcall!(bool)(_classBinding.isDistanceFieldHint, _godot_object);
102 	}
103 	/**
104 	Return the size of a string, taking kerning and advance into account.
105 	*/
106 	Vector2 getStringSize(StringArg0)(in StringArg0 string) const
107 	{
108 		checkClassBinding!(typeof(this))();
109 		return ptrcall!(Vector2)(_classBinding.getStringSize, _godot_object, string);
110 	}
111 	/**
112 	
113 	*/
114 	bool hasOutline() const
115 	{
116 		checkClassBinding!(typeof(this))();
117 		return ptrcall!(bool)(_classBinding.hasOutline, _godot_object);
118 	}
119 	/**
120 	Draw character "char" into a canvas item using the font at a given position, with "modulate" color, and optionally kerning if "next" is passed. clipping the width. "position" specifies the baseline, not the top. To draw from the top, $(I ascent) must be added to the Y axis. The width used by the character is returned, making this function useful for drawing strings character by character.
121 	*/
122 	double drawChar(in RID canvas_item, in Vector2 position, in long _char, in long next = -1, in Color modulate = Color(1,1,1,1), in bool outline = false) const
123 	{
124 		checkClassBinding!(typeof(this))();
125 		return ptrcall!(double)(_classBinding.drawChar, _godot_object, canvas_item, position, _char, next, modulate, outline);
126 	}
127 	/**
128 	After editing a font (changing size, ascent, char rects, etc.). Call this function to propagate changes to controls that might use it.
129 	*/
130 	void updateChanges()
131 	{
132 		checkClassBinding!(typeof(this))();
133 		ptrcall!(void)(_classBinding.updateChanges, _godot_object);
134 	}
135 }