00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
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, 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