1 // $Id: background.cpp 3144 2006-03-31 10:31:03Z matzebraun $
3 // SuperTux - A Jump'n Run
4 // Copyright (C) 2004 Matthias Braun <matze@braunis.de
6 // This program is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU General Public License
8 // as published by the Free Software Foundation; either version 2
9 // of the License, or (at your option) any later version.
11 // This program is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
16 // You should have received a copy of the GNU General Public License
17 // along with this program; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
22 #include "gradient.hpp"
24 #include "video/drawing_context.hpp"
25 #include "lisp/lisp.hpp"
26 #include "lisp/writer.hpp"
27 #include "object_factory.hpp"
28 #include "resources.hpp"
33 : layer(LAYER_BACKGROUND0)
37 Gradient::Gradient(const lisp::Lisp& reader)
38 : layer(LAYER_BACKGROUND0)
40 reader.get("layer", layer);
41 std::vector<float> bkgd_top_color, bkgd_bottom_color;
42 if(!reader.get_vector("top_color", bkgd_top_color) ||
43 !reader.get_vector("bottom_color", bkgd_bottom_color))
44 throw std::runtime_error("Must specify top_color and bottom_color in gradient");
46 gradient_top = Color(bkgd_top_color);
47 gradient_bottom = Color(bkgd_bottom_color);
55 Gradient::write(lisp::Writer& writer)
57 writer.start_list("gradient");
59 std::vector<float> bkgd_top_color, bkgd_bottom_color;
60 bkgd_top_color.push_back(gradient_top.red);
61 bkgd_top_color.push_back(gradient_top.green);
62 bkgd_top_color.push_back(gradient_top.blue);
63 bkgd_bottom_color.push_back(gradient_bottom.red);
64 bkgd_bottom_color.push_back(gradient_bottom.green);
65 bkgd_bottom_color.push_back(gradient_bottom.blue);
66 writer.write_float_vector("top_color", bkgd_top_color);
67 writer.write_float_vector("bottom_color", bkgd_bottom_color);
69 writer.write_int("layer", layer);
71 writer.end_list("gradient");
75 Gradient::update(float)
80 Gradient::set_gradient(Color top, Color bottom)
83 gradient_bottom = bottom;
85 if (gradient_top.red > 1.0 || gradient_top.green > 1.0
86 || gradient_top.blue > 1.0 || gradient_top.alpha > 1.0)
87 msg_warning("top gradient color has values above 1.0");
88 if (gradient_bottom.red > 1.0 || gradient_bottom.green > 1.0
89 || gradient_bottom.blue > 1.0 || gradient_bottom.alpha > 1.0)
90 msg_warning("bottom gradient color has values above 1.0");
94 Gradient::draw(DrawingContext& context)
96 context.push_transform();
97 context.set_translation(Vector(0, 0));
98 context.draw_gradient(gradient_top, gradient_bottom, layer);
99 context.pop_transform();
102 IMPLEMENT_FACTORY(Gradient, "gradient");