src/object/gradient.cpp

Go to the documentation of this file.
00001 //  SuperTux
00002 //  Copyright (C) 2006 Matthias Braun <matze@braunis.de>
00003 //
00004 //  This program is free software: you can redistribute it and/or modify
00005 //  it under the terms of the GNU General Public License as published by
00006 //  the Free Software Foundation, either version 3 of the License, or
00007 //  (at your option) any later version.
00008 //
00009 //  This program is distributed in the hope that it will be useful,
00010 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
00011 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012 //  GNU General Public License for more details.
00013 //
00014 //  You should have received a copy of the GNU General Public License
00015 //  along with this program.  If not, see <http://www.gnu.org/licenses/>.
00016 
00017 #include "object/gradient.hpp"
00018 #include "supertux/object_factory.hpp"
00019 #include "util/reader.hpp"
00020 
00021 #include <stdexcept>
00022 
00023 Gradient::Gradient() :
00024   layer(LAYER_BACKGROUND0),
00025   gradient_top(),
00026   gradient_bottom()
00027 {
00028 }
00029 
00030 Gradient::Gradient(const Reader& reader) :
00031   layer(LAYER_BACKGROUND0),
00032   gradient_top(),
00033   gradient_bottom()
00034 {
00035   layer = reader_get_layer (reader, /* default = */ LAYER_BACKGROUND0);
00036   std::vector<float> bkgd_top_color, bkgd_bottom_color;
00037   if(!reader.get("top_color", bkgd_top_color) ||
00038      !reader.get("bottom_color", bkgd_bottom_color))
00039     throw std::runtime_error("Must specify top_color and bottom_color in gradient");
00040 
00041   gradient_top = Color(bkgd_top_color);
00042   gradient_bottom = Color(bkgd_bottom_color);
00043 }
00044 
00045 Gradient::~Gradient()
00046 {
00047 }
00048 
00049 void
00050 Gradient::update(float)
00051 {
00052 }
00053 
00054 void
00055 Gradient::set_gradient(Color top, Color bottom)
00056 {
00057   gradient_top = top;
00058   gradient_bottom = bottom;
00059 
00060   if (gradient_top.red > 1.0 || gradient_top.green > 1.0
00061       || gradient_top.blue > 1.0 || gradient_top.alpha > 1.0)
00062     log_warning << "top gradient color has values above 1.0" << std::endl;
00063   if (gradient_bottom.red > 1.0 || gradient_bottom.green > 1.0
00064       || gradient_bottom.blue > 1.0 || gradient_bottom.alpha > 1.0)
00065     log_warning << "bottom gradient color has values above 1.0" << std::endl;
00066 }
00067 
00068 void
00069 Gradient::draw(DrawingContext& context)
00070 {
00071   context.push_transform();
00072   context.set_translation(Vector(0, 0));
00073   context.draw_gradient(gradient_top, gradient_bottom, layer);
00074   context.pop_transform();
00075 }
00076 
00077 /* EOF */

Generated on Mon Jun 9 03:38:19 2014 for SuperTux by  doxygen 1.5.1