Fixed compiler warnings due to new loglevel aware log macro
[supertux.git] / src / object / gradient.cpp
1 //  SuperTux
2 //  Copyright (C) 2006 Matthias Braun <matze@braunis.de>
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 "object/gradient.hpp"
18 #include "supertux/object_factory.hpp"
19 #include "util/reader.hpp"
20
21 #include <stdexcept>
22
23 Gradient::Gradient() :
24   layer(LAYER_BACKGROUND0),
25   gradient_top(),
26   gradient_bottom()
27 {
28 }
29
30 Gradient::Gradient(const Reader& reader) :
31   layer(LAYER_BACKGROUND0),
32   gradient_top(),
33   gradient_bottom()
34 {
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");
40
41   gradient_top = Color(bkgd_top_color);
42   gradient_bottom = Color(bkgd_bottom_color);
43 }
44
45 Gradient::~Gradient()
46 {
47 }
48
49 void
50 Gradient::update(float)
51 {
52 }
53
54 void
55 Gradient::set_gradient(Color top, Color bottom)
56 {
57   gradient_top = top;
58   gradient_bottom = bottom;
59
60   if (gradient_top.red > 1.0 || gradient_top.green > 1.0 ||
61       gradient_top.blue > 1.0 || gradient_top.alpha > 1.0)
62   {
63     log_warning << "top gradient color has values above 1.0" << std::endl;
64   }
65
66   if (gradient_bottom.red > 1.0 || gradient_bottom.green > 1.0 ||
67        gradient_bottom.blue > 1.0 || gradient_bottom.alpha > 1.0)
68   {
69     log_warning << "bottom gradient color has values above 1.0" << std::endl;
70   }
71 }
72
73 void
74 Gradient::draw(DrawingContext& context)
75 {
76   context.push_transform();
77   context.set_translation(Vector(0, 0));
78   context.draw_gradient(gradient_top, gradient_bottom, layer);
79   context.pop_transform();
80 }
81
82 /* EOF */