2 // Copyright (C) 2006 Matthias Braun <matze@braunis.de>
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.
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.
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/>.
17 #include "object/gradient.hpp"
18 #include "supertux/object_factory.hpp"
19 #include "util/reader.hpp"
23 Gradient::Gradient() :
24 layer(LAYER_BACKGROUND0),
30 Gradient::Gradient(const Reader& reader) :
31 layer(LAYER_BACKGROUND0),
35 layer = reader_get_layer (reader, /* default = */ LAYER_BACKGROUND0);
36 std::vector<float> bkgd_top_color, bkgd_bottom_color;
37 if(!reader.get("top_color", bkgd_top_color) ||
38 !reader.get("bottom_color", bkgd_bottom_color))
39 throw std::runtime_error("Must specify top_color and bottom_color in gradient");
41 gradient_top = Color(bkgd_top_color);
42 gradient_bottom = Color(bkgd_bottom_color);
50 Gradient::update(float)
55 Gradient::set_gradient(Color top, Color bottom)
58 gradient_bottom = bottom;
60 if (gradient_top.red > 1.0 || gradient_top.green > 1.0 ||
61 gradient_top.blue > 1.0 || gradient_top.alpha > 1.0)
63 log_warning << "top gradient color has values above 1.0" << std::endl;
66 if (gradient_bottom.red > 1.0 || gradient_bottom.green > 1.0 ||
67 gradient_bottom.blue > 1.0 || gradient_bottom.alpha > 1.0)
69 log_warning << "bottom gradient color has values above 1.0" << std::endl;
74 Gradient::draw(DrawingContext& context)
76 context.push_transform();
77 context.set_translation(Vector(0, 0));
78 context.draw_gradient(gradient_top, gradient_bottom, layer);
79 context.pop_transform();