4 // Copyright (C) 2006 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.
23 #include "gradient.hpp"
25 #include "video/drawing_context.hpp"
26 #include "lisp/lisp.hpp"
27 #include "lisp/writer.hpp"
28 #include "object_factory.hpp"
29 #include "resources.hpp"
34 : layer(LAYER_BACKGROUND0)
38 Gradient::Gradient(const lisp::Lisp& reader)
39 : layer(LAYER_BACKGROUND0)
41 reader.get("layer", layer);
42 std::vector<float> bkgd_top_color, bkgd_bottom_color;
43 if(!reader.get_vector("top_color", bkgd_top_color) ||
44 !reader.get_vector("bottom_color", bkgd_bottom_color))
45 throw std::runtime_error("Must specify top_color and bottom_color in gradient");
47 gradient_top = Color(bkgd_top_color);
48 gradient_bottom = Color(bkgd_bottom_color);
56 Gradient::write(lisp::Writer& writer)
58 writer.start_list("gradient");
60 std::vector<float> bkgd_top_color, bkgd_bottom_color;
61 bkgd_top_color.push_back(gradient_top.red);
62 bkgd_top_color.push_back(gradient_top.green);
63 bkgd_top_color.push_back(gradient_top.blue);
64 bkgd_bottom_color.push_back(gradient_bottom.red);
65 bkgd_bottom_color.push_back(gradient_bottom.green);
66 bkgd_bottom_color.push_back(gradient_bottom.blue);
67 writer.write_float_vector("top_color", bkgd_top_color);
68 writer.write_float_vector("bottom_color", bkgd_bottom_color);
70 writer.write_int("layer", layer);
72 writer.end_list("gradient");
76 Gradient::update(float)
81 Gradient::set_gradient(Color top, Color bottom)
84 gradient_bottom = bottom;
86 if (gradient_top.red > 1.0 || gradient_top.green > 1.0
87 || gradient_top.blue > 1.0 || gradient_top.alpha > 1.0)
88 log_warning << "top gradient color has values above 1.0" << std::endl;
89 if (gradient_bottom.red > 1.0 || gradient_bottom.green > 1.0
90 || gradient_bottom.blue > 1.0 || gradient_bottom.alpha > 1.0)
91 log_warning << "bottom gradient color has values above 1.0" << std::endl;
95 Gradient::draw(DrawingContext& context)
97 context.push_transform();
98 context.set_translation(Vector(0, 0));
99 context.draw_gradient(gradient_top, gradient_bottom, layer);
100 context.pop_transform();
103 IMPLEMENT_FACTORY(Gradient, "gradient");