| 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 | |
| 22 | namespace scripting { |
| 23 | |
| 24 | void |
| 25 | TextArray::add_text_duration(const std::string& text, float duration) |
| 26 | { |
| 27 | SCRIPT_GUARD_VOID; |
| 28 | object.add_text(text, duration); |
| 29 | } |
| 30 | |
| 31 | void |
| 32 | TextArray::add_text(const std::string& text) |
| 33 | { |
| 34 | SCRIPT_GUARD_VOID; |
| 35 | object.add_text(text); |
| 36 | } |
| 37 | |
| 38 | void |
| 39 | TextArray::clear() |
| 40 | { |
| 41 | SCRIPT_GUARD_VOID; |
| 42 | object.clear(); |
| 43 | } |
| 44 | |
| 45 | void |
| 46 | TextArray::set_fade_transition(bool fade_transition) |
| 47 | { |
| 48 | SCRIPT_GUARD_VOID; |
| 49 | object.set_fade_transition(fade_transition); |
| 50 | } |
| 51 | |
| 52 | void |
| 53 | TextArray::set_fade_time(float fadetime) |
| 54 | { |
| 55 | SCRIPT_GUARD_VOID; |
| 56 | object.set_fade_time(fadetime); |
| 57 | } |
| 58 | |
| 59 | void |
| 60 | TextArray::set_text_index(int index_) |
| 61 | { |
| 62 | SCRIPT_GUARD_VOID; |
| 63 | object.set_text_index(index_); |
| 64 | } |
| 65 | |
| 66 | void |
| 67 | TextArray::next_text() |
| 68 | { |
| 69 | SCRIPT_GUARD_VOID; |
| 70 | object.next_text(); |
| 71 | } |
| 72 | |
| 73 | void |
| 74 | TextArray::prev_text() |
| 75 | { |
| 76 | SCRIPT_GUARD_VOID; |
| 77 | object.prev_text(); |
| 78 | } |
| 79 | |
| 80 | void |
| 81 | TextArray::set_keep_visible(bool keep_visible_) |
| 82 | { |
| 83 | SCRIPT_GUARD_VOID; |
| 84 | object.set_keep_visible(keep_visible_); |
| 85 | } |
| 86 | |
| 87 | void |
| 88 | TextArray::set_done(bool done) |
| 89 | { |
| 90 | SCRIPT_GUARD_VOID; |
| 91 | object.set_done(done); |
| 92 | } |
| 93 | |
| 94 | void |
| 95 | TextArray::set_auto(bool is_auto) |
| 96 | { |
| 97 | SCRIPT_GUARD_VOID; |
| 98 | object.set_auto(is_auto); |
| 99 | } |
| 100 | |
| 101 | /////////// text api |
| 102 | |
| 103 | void |
| 104 | TextArray::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 | |
| 113 | void |
| 114 | TextArray::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 | |
| 123 | void |
| 124 | TextArray::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 | |
| 133 | void |
| 134 | TextArray::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 | |
| 143 | void |
| 144 | TextArray::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 | |
| 153 | void |
| 154 | TextArray::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 | |
| 163 | void |
| 164 | TextArray::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 | |
| 173 | float |
| 174 | TextArray::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 | |
| 186 | float |
| 187 | TextArray::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 | |
| 199 | void |
| 200 | TextArray::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 | |
| 209 | int |
| 210 | TextArray::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 | |