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"
21 Gradient::Gradient() :
22 layer(LAYER_BACKGROUND0),
28 Gradient::Gradient(const Reader& reader) :
29 layer(LAYER_BACKGROUND0),
33 reader.get("layer", layer);
34 std::vector<float> bkgd_top_color, bkgd_bottom_color;
35 if(!reader.get("top_color", bkgd_top_color) ||
36 !reader.get("bottom_color", bkgd_bottom_color))
37 throw std::runtime_error("Must specify top_color and bottom_color in gradient");
39 gradient_top = Color(bkgd_top_color);
40 gradient_bottom = Color(bkgd_bottom_color);
48 Gradient::update(float)
53 Gradient::set_gradient(Color top, Color bottom)
56 gradient_bottom = bottom;
58 if (gradient_top.red > 1.0 || gradient_top.green > 1.0
59 || gradient_top.blue > 1.0 || gradient_top.alpha > 1.0)
60 log_warning << "top gradient color has values above 1.0" << std::endl;
61 if (gradient_bottom.red > 1.0 || gradient_bottom.green > 1.0
62 || gradient_bottom.blue > 1.0 || gradient_bottom.alpha > 1.0)
63 log_warning << "bottom gradient color has values above 1.0" << std::endl;
67 Gradient::draw(DrawingContext& context)
69 context.push_transform();
70 context.set_translation(Vector(0, 0));
71 context.draw_gradient(gradient_top, gradient_bottom, layer);
72 context.pop_transform();
75 IMPLEMENT_FACTORY(Gradient, "gradient");