1// SuperTux
2// Copyright (C) 2018 Nir <goproducti@gmail.com>
3//
4// This program is free software: you can redistribute it and/or modify
5// it under the terms of the GNU General Public License as published by
6// the Free Software Foundation, either version 3 of the License, or
7// (at your option) any later version.
8//
9// This program is distributed in the hope that it will be useful,
10// but WITHOUT ANY WARRANTY; without even the implied warranty of
11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12// GNU General Public License for more details.
13//
14// You should have received a copy of the GNU General Public License
15// along with this program. If not, see <http://www.gnu.org/licenses/>.
16
17#include "scripting/text_array.hpp"
18#include "object/text_array_object.hpp"
19
20#include "object/text_object.hpp"
21
22namespace scripting {
23
24void
25TextArray::add_text_duration(const std::string& text, float duration)
26{
27 SCRIPT_GUARD_VOID;
28 object.add_text(text, duration);
29}
30
31void
32TextArray::add_text(const std::string& text)
33{
34 SCRIPT_GUARD_VOID;
35 object.add_text(text);
36}
37
38void
39TextArray::clear()
40{
41 SCRIPT_GUARD_VOID;
42 object.clear();
43}
44
45void
46TextArray::set_fade_transition(bool fade_transition)
47{
48 SCRIPT_GUARD_VOID;
49 object.set_fade_transition(fade_transition);
50}
51
52void
53TextArray::set_fade_time(float fadetime)
54{
55 SCRIPT_GUARD_VOID;
56 object.set_fade_time(fadetime);
57}
58
59void
60TextArray::set_text_index(int index_)
61{
62 SCRIPT_GUARD_VOID;
63 object.set_text_index(index_);
64}
65
66void
67TextArray::next_text()
68{
69 SCRIPT_GUARD_VOID;
70 object.next_text();
71}
72
73void
74TextArray::prev_text()
75{
76 SCRIPT_GUARD_VOID;
77 object.prev_text();
78}
79
80void
81TextArray::set_keep_visible(bool keep_visible_)
82{
83 SCRIPT_GUARD_VOID;
84 object.set_keep_visible(keep_visible_);
85}
86
87void
88TextArray::set_done(bool done)
89{
90 SCRIPT_GUARD_VOID;
91 object.set_done(done);
92}
93
94void
95TextArray::set_auto(bool is_auto)
96{
97 SCRIPT_GUARD_VOID;
98 object.set_auto(is_auto);
99}
100
101/////////// text api
102
103void
104TextArray::set_text(const std::string& text)
105{
106 SCRIPT_GUARD_VOID;
107
108 if (auto* textItem = object.get_current_text_item()) {
109 textItem->text_object.set_text(text);
110 }
111}
112
113void
114TextArray::set_font(const std::string& fontname)
115{
116 SCRIPT_GUARD_VOID;
117
118 if (auto* textItem = object.get_current_text_item()) {
119 textItem->text_object.set_font(fontname);
120 }
121}
122
123void
124TextArray::fade_in(float fadetime)
125{
126 SCRIPT_GUARD_VOID;
127
128 if (auto* textItem = object.get_current_text_item()) {
129 textItem->text_object.fade_in(fadetime);
130 }
131}
132
133void
134TextArray::fade_out(float fadetime)
135{
136 SCRIPT_GUARD_VOID;
137
138 if (auto* textItem = object.get_current_text_item()) {
139 textItem->text_object.fade_out(fadetime);
140 }
141}
142
143void
144TextArray::set_visible(bool visible)
145{
146 SCRIPT_GUARD_VOID;
147
148 if (auto* textItem = object.get_current_text_item()) {
149 textItem->text_object.set_visible(visible);
150 }
151}
152
153void
154TextArray::set_centered(bool centered)
155{
156 SCRIPT_GUARD_VOID;
157
158 if (auto* textItem = object.get_current_text_item()) {
159 textItem->text_object.set_centered(centered);
160 }
161}
162
163void
164TextArray::set_pos(float x, float y)
165{
166 SCRIPT_GUARD_VOID;
167
168 if (auto* textItem = object.get_current_text_item()) {
169 textItem->text_object.set_pos(Vector(x, y));
170 }
171}
172
173float
174TextArray::get_pos_x() const
175{
176 SCRIPT_GUARD_DEFAULT;
177
178 if (auto* textItem = object.get_current_text_item()) {
179 return textItem->text_object.get_pos().x;
180 } else {
181 log_warning << "TextArray position is not set. Assuming (0,0)" << std::endl;
182 return 0;
183 }
184}
185
186float
187TextArray::get_pos_y() const
188{
189 SCRIPT_GUARD_DEFAULT;
190
191 if (auto* textItem = object.get_current_text_item()) {
192 return textItem->text_object.get_pos().y;
193 } else {
194 log_warning << "TextArray position is not set. Assuming (0,0)" << std::endl;
195 return 0;
196 }
197}
198
199void
200TextArray::set_anchor_point(int anchor)
201{
202 SCRIPT_GUARD_VOID;
203
204 if (auto* textItem = object.get_current_text_item()) {
205 textItem->text_object.set_anchor_point(static_cast<AnchorPoint>(anchor));
206 }
207}
208
209int
210TextArray::get_anchor_point() const
211{
212 SCRIPT_GUARD_DEFAULT;
213
214 if (auto* textItem = object.get_current_text_item()) {
215 return textItem->text_object.get_anchor_point();
216 } else {
217 return -1;
218 }
219}
220
221} // namespace scripting
222
223/* EOF */
224