1 | /**************************************************************************/ |
2 | /* label_settings.cpp */ |
3 | /**************************************************************************/ |
4 | /* This file is part of: */ |
5 | /* GODOT ENGINE */ |
6 | /* https://godotengine.org */ |
7 | /**************************************************************************/ |
8 | /* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */ |
9 | /* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */ |
10 | /* */ |
11 | /* Permission is hereby granted, free of charge, to any person obtaining */ |
12 | /* a copy of this software and associated documentation files (the */ |
13 | /* "Software"), to deal in the Software without restriction, including */ |
14 | /* without limitation the rights to use, copy, modify, merge, publish, */ |
15 | /* distribute, sublicense, and/or sell copies of the Software, and to */ |
16 | /* permit persons to whom the Software is furnished to do so, subject to */ |
17 | /* the following conditions: */ |
18 | /* */ |
19 | /* The above copyright notice and this permission notice shall be */ |
20 | /* included in all copies or substantial portions of the Software. */ |
21 | /* */ |
22 | /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ |
23 | /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ |
24 | /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */ |
25 | /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ |
26 | /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ |
27 | /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ |
28 | /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ |
29 | /**************************************************************************/ |
30 | |
31 | #include "label_settings.h" |
32 | |
33 | void LabelSettings::_font_changed() { |
34 | emit_changed(); |
35 | } |
36 | |
37 | void LabelSettings::_bind_methods() { |
38 | ClassDB::bind_method(D_METHOD("set_line_spacing" , "spacing" ), &LabelSettings::set_line_spacing); |
39 | ClassDB::bind_method(D_METHOD("get_line_spacing" ), &LabelSettings::get_line_spacing); |
40 | |
41 | ClassDB::bind_method(D_METHOD("set_font" , "font" ), &LabelSettings::set_font); |
42 | ClassDB::bind_method(D_METHOD("get_font" ), &LabelSettings::get_font); |
43 | |
44 | ClassDB::bind_method(D_METHOD("set_font_size" , "size" ), &LabelSettings::set_font_size); |
45 | ClassDB::bind_method(D_METHOD("get_font_size" ), &LabelSettings::get_font_size); |
46 | |
47 | ClassDB::bind_method(D_METHOD("set_font_color" , "color" ), &LabelSettings::set_font_color); |
48 | ClassDB::bind_method(D_METHOD("get_font_color" ), &LabelSettings::get_font_color); |
49 | |
50 | ClassDB::bind_method(D_METHOD("set_outline_size" , "size" ), &LabelSettings::set_outline_size); |
51 | ClassDB::bind_method(D_METHOD("get_outline_size" ), &LabelSettings::get_outline_size); |
52 | |
53 | ClassDB::bind_method(D_METHOD("set_outline_color" , "color" ), &LabelSettings::set_outline_color); |
54 | ClassDB::bind_method(D_METHOD("get_outline_color" ), &LabelSettings::get_outline_color); |
55 | |
56 | ClassDB::bind_method(D_METHOD("set_shadow_size" , "size" ), &LabelSettings::set_shadow_size); |
57 | ClassDB::bind_method(D_METHOD("get_shadow_size" ), &LabelSettings::get_shadow_size); |
58 | |
59 | ClassDB::bind_method(D_METHOD("set_shadow_color" , "color" ), &LabelSettings::set_shadow_color); |
60 | ClassDB::bind_method(D_METHOD("get_shadow_color" ), &LabelSettings::get_shadow_color); |
61 | |
62 | ClassDB::bind_method(D_METHOD("set_shadow_offset" , "offset" ), &LabelSettings::set_shadow_offset); |
63 | ClassDB::bind_method(D_METHOD("get_shadow_offset" ), &LabelSettings::get_shadow_offset); |
64 | |
65 | ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "line_spacing" , PROPERTY_HINT_NONE, "suffix:px" ), "set_line_spacing" , "get_line_spacing" ); |
66 | |
67 | ADD_GROUP("Font" , "font_" ); |
68 | ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "font" , PROPERTY_HINT_RESOURCE_TYPE, "Font" ), "set_font" , "get_font" ); |
69 | ADD_PROPERTY(PropertyInfo(Variant::INT, "font_size" , PROPERTY_HINT_RANGE, "1,1024,1,or_greater,suffix:px" ), "set_font_size" , "get_font_size" ); |
70 | ADD_PROPERTY(PropertyInfo(Variant::COLOR, "font_color" ), "set_font_color" , "get_font_color" ); |
71 | |
72 | ADD_GROUP("Outline" , "outline_" ); |
73 | ADD_PROPERTY(PropertyInfo(Variant::INT, "outline_size" , PROPERTY_HINT_RANGE, "0,127,1,or_greater,suffix:px" ), "set_outline_size" , "get_outline_size" ); |
74 | ADD_PROPERTY(PropertyInfo(Variant::COLOR, "outline_color" ), "set_outline_color" , "get_outline_color" ); |
75 | |
76 | ADD_GROUP("Shadow" , "shadow_" ); |
77 | ADD_PROPERTY(PropertyInfo(Variant::INT, "shadow_size" , PROPERTY_HINT_RANGE, "0,127,1,or_greater,suffix:px" ), "set_shadow_size" , "get_shadow_size" ); |
78 | ADD_PROPERTY(PropertyInfo(Variant::COLOR, "shadow_color" ), "set_shadow_color" , "get_shadow_color" ); |
79 | ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "shadow_offset" , PROPERTY_HINT_NONE, "suffix:px" ), "set_shadow_offset" , "get_shadow_offset" ); |
80 | } |
81 | |
82 | void LabelSettings::set_line_spacing(real_t p_spacing) { |
83 | if (line_spacing != p_spacing) { |
84 | line_spacing = p_spacing; |
85 | emit_changed(); |
86 | } |
87 | } |
88 | |
89 | real_t LabelSettings::get_line_spacing() const { |
90 | return line_spacing; |
91 | } |
92 | |
93 | void LabelSettings::set_font(const Ref<Font> &p_font) { |
94 | if (font != p_font) { |
95 | if (font.is_valid()) { |
96 | font->disconnect_changed(callable_mp(this, &LabelSettings::_font_changed)); |
97 | } |
98 | font = p_font; |
99 | if (font.is_valid()) { |
100 | font->connect_changed(callable_mp(this, &LabelSettings::_font_changed), CONNECT_REFERENCE_COUNTED); |
101 | } |
102 | emit_changed(); |
103 | } |
104 | } |
105 | |
106 | Ref<Font> LabelSettings::get_font() const { |
107 | return font; |
108 | } |
109 | |
110 | void LabelSettings::set_font_size(int p_size) { |
111 | if (font_size != p_size) { |
112 | font_size = p_size; |
113 | emit_changed(); |
114 | } |
115 | } |
116 | |
117 | int LabelSettings::get_font_size() const { |
118 | return font_size; |
119 | } |
120 | |
121 | void LabelSettings::set_font_color(const Color &p_color) { |
122 | if (font_color != p_color) { |
123 | font_color = p_color; |
124 | emit_changed(); |
125 | } |
126 | } |
127 | |
128 | Color LabelSettings::get_font_color() const { |
129 | return font_color; |
130 | } |
131 | |
132 | void LabelSettings::set_outline_size(int p_size) { |
133 | if (outline_size != p_size) { |
134 | outline_size = p_size; |
135 | emit_changed(); |
136 | } |
137 | } |
138 | |
139 | int LabelSettings::get_outline_size() const { |
140 | return outline_size; |
141 | } |
142 | |
143 | void LabelSettings::set_outline_color(const Color &p_color) { |
144 | if (outline_color != p_color) { |
145 | outline_color = p_color; |
146 | emit_changed(); |
147 | } |
148 | } |
149 | |
150 | Color LabelSettings::get_outline_color() const { |
151 | return outline_color; |
152 | } |
153 | |
154 | void LabelSettings::set_shadow_size(int p_size) { |
155 | if (shadow_size != p_size) { |
156 | shadow_size = p_size; |
157 | emit_changed(); |
158 | } |
159 | } |
160 | |
161 | int LabelSettings::get_shadow_size() const { |
162 | return shadow_size; |
163 | } |
164 | |
165 | void LabelSettings::set_shadow_color(const Color &p_color) { |
166 | if (shadow_color != p_color) { |
167 | shadow_color = p_color; |
168 | emit_changed(); |
169 | } |
170 | } |
171 | |
172 | Color LabelSettings::get_shadow_color() const { |
173 | return shadow_color; |
174 | } |
175 | |
176 | void LabelSettings::set_shadow_offset(const Vector2 &p_offset) { |
177 | if (shadow_offset != p_offset) { |
178 | shadow_offset = p_offset; |
179 | emit_changed(); |
180 | } |
181 | } |
182 | |
183 | Vector2 LabelSettings::get_shadow_offset() const { |
184 | return shadow_offset; |
185 | } |
186 | |