| 1 | // SuperTux |
| 2 | // Copyright (C) 2016 Hume2 <teratux.mail@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/gradient.hpp" |
| 18 | |
| 19 | #include "object/gradient.hpp" |
| 20 | |
| 21 | namespace scripting { |
| 22 | |
| 23 | void |
| 24 | Gradient::set_direction(const std::string& direction) |
| 25 | { |
| 26 | SCRIPT_GUARD_VOID; |
| 27 | |
| 28 | if (direction == "horizontal" ) |
| 29 | object.set_direction(GradientDirection::HORIZONTAL); |
| 30 | else if (direction == "vertical" ) |
| 31 | object.set_direction(GradientDirection::VERTICAL); |
| 32 | else if (direction == "horizontal_sector" ) |
| 33 | object.set_direction(GradientDirection::HORIZONTAL_SECTOR); |
| 34 | else if (direction == "vertical_sector" ) |
| 35 | object.set_direction(GradientDirection::VERTICAL_SECTOR); |
| 36 | else |
| 37 | log_info << "Invalid direction for gradient \"" << direction << "\"" ; |
| 38 | } |
| 39 | |
| 40 | std::string |
| 41 | Gradient::get_direction() const |
| 42 | { |
| 43 | SCRIPT_GUARD_DEFAULT; |
| 44 | |
| 45 | auto direction = object.get_direction(); |
| 46 | |
| 47 | if (direction == GradientDirection::HORIZONTAL) |
| 48 | return "horizontal" ; |
| 49 | if (direction == GradientDirection::VERTICAL) |
| 50 | return "vertical" ; |
| 51 | if (direction == GradientDirection::HORIZONTAL_SECTOR) |
| 52 | return "horizontal_sector" ; |
| 53 | if (direction == GradientDirection::VERTICAL_SECTOR) |
| 54 | return "vertical_sector" ; |
| 55 | |
| 56 | return nullptr; |
| 57 | } |
| 58 | |
| 59 | void |
| 60 | Gradient::set_color1(float red, float green, float blue) |
| 61 | { |
| 62 | SCRIPT_GUARD_VOID; |
| 63 | object.set_gradient(Color(red, green, blue), object.get_gradient_bottom()); |
| 64 | } |
| 65 | |
| 66 | void |
| 67 | Gradient::set_color2(float red, float green, float blue) |
| 68 | { |
| 69 | SCRIPT_GUARD_VOID; |
| 70 | object.set_gradient(object.get_gradient_top(), Color(red, green, blue)); |
| 71 | } |
| 72 | |
| 73 | void |
| 74 | Gradient::swap_colors() |
| 75 | { |
| 76 | SCRIPT_GUARD_VOID; |
| 77 | object.set_gradient(object.get_gradient_bottom(), object.get_gradient_top()); |
| 78 | } |
| 79 | |
| 80 | } // namespace scripting |
| 81 | |
| 82 | /* EOF */ |
| 83 | |