From 5fd7ae520900ca8a756ced84033fc392ef014d6e Mon Sep 17 00:00:00 2001 From: Matthias Braun Date: Fri, 31 Mar 2006 22:49:36 +0000 Subject: [PATCH] forgot 2 files SVN-Revision: 3162 --- src/object/gradient.cpp | 102 ++++++++++++++++++++++++++++++++++++++++++++++++ src/object/gradient.hpp | 61 +++++++++++++++++++++++++++++ 2 files changed, 163 insertions(+) create mode 100644 src/object/gradient.cpp create mode 100644 src/object/gradient.hpp diff --git a/src/object/gradient.cpp b/src/object/gradient.cpp new file mode 100644 index 000000000..a2c9a030a --- /dev/null +++ b/src/object/gradient.cpp @@ -0,0 +1,102 @@ +// $Id: background.cpp 3144 2006-03-31 10:31:03Z matzebraun $ +// +// SuperTux - A Jump'n Run +// Copyright (C) 2004 Matthias Braun + +#include +#include "gradient.hpp" +#include "camera.hpp" +#include "video/drawing_context.hpp" +#include "lisp/lisp.hpp" +#include "lisp/writer.hpp" +#include "object_factory.hpp" +#include "resources.hpp" +#include "main.hpp" +#include "msg.hpp" + +Gradient::Gradient() + : layer(LAYER_BACKGROUND0) +{ +} + +Gradient::Gradient(const lisp::Lisp& reader) + : layer(LAYER_BACKGROUND0) +{ + reader.get("layer", layer); + std::vector bkgd_top_color, bkgd_bottom_color; + if(!reader.get_vector("top_color", bkgd_top_color) || + !reader.get_vector("bottom_color", bkgd_bottom_color)) + throw std::runtime_error("Must specify top_color and bottom_color in gradient"); + + gradient_top = Color(bkgd_top_color); + gradient_bottom = Color(bkgd_bottom_color); +} + +Gradient::~Gradient() +{ +} + +void +Gradient::write(lisp::Writer& writer) +{ + writer.start_list("gradient"); + + std::vector bkgd_top_color, bkgd_bottom_color; + bkgd_top_color.push_back(gradient_top.red); + bkgd_top_color.push_back(gradient_top.green); + bkgd_top_color.push_back(gradient_top.blue); + bkgd_bottom_color.push_back(gradient_bottom.red); + bkgd_bottom_color.push_back(gradient_bottom.green); + bkgd_bottom_color.push_back(gradient_bottom.blue); + writer.write_float_vector("top_color", bkgd_top_color); + writer.write_float_vector("bottom_color", bkgd_bottom_color); + + writer.write_int("layer", layer); + + writer.end_list("gradient"); +} + +void +Gradient::update(float) +{ +} + +void +Gradient::set_gradient(Color top, Color bottom) +{ + gradient_top = top; + gradient_bottom = bottom; + + if (gradient_top.red > 1.0 || gradient_top.green > 1.0 + || gradient_top.blue > 1.0 || gradient_top.alpha > 1.0) + msg_warning("top gradient color has values above 1.0"); + if (gradient_bottom.red > 1.0 || gradient_bottom.green > 1.0 + || gradient_bottom.blue > 1.0 || gradient_bottom.alpha > 1.0) + msg_warning("bottom gradient color has values above 1.0"); +} + +void +Gradient::draw(DrawingContext& context) +{ + context.push_transform(); + context.set_translation(Vector(0, 0)); + context.draw_gradient(gradient_top, gradient_bottom, layer); + context.pop_transform(); +} + +IMPLEMENT_FACTORY(Gradient, "gradient"); diff --git a/src/object/gradient.hpp b/src/object/gradient.hpp new file mode 100644 index 000000000..e43eb956e --- /dev/null +++ b/src/object/gradient.hpp @@ -0,0 +1,61 @@ +// $Id: background.hpp 3144 2006-03-31 10:31:03Z matzebraun $ +// +// SuperTux - A Jump'n Run +// Copyright (C) 2006 Matthias Braun +#include "video/surface.hpp" +#include "video/drawing_context.hpp" +#include "game_object.hpp" +#include "serializable.hpp" + +class DisplayManager; + +namespace lisp { +class Lisp; +} + +class Gradient : public GameObject, public Serializable +{ +public: + Gradient(); + Gradient(const lisp::Lisp& reader); + virtual ~Gradient(); + + virtual void write(lisp::Writer& writer); + + void set_gradient(Color top, Color bottom); + + Color get_gradient_top() const + { return gradient_top; } + + Color get_gradient_bottom() const + { return gradient_bottom; } + + virtual void update(float elapsed_time); + + virtual void draw(DrawingContext& context); + +private: + int layer; + Color gradient_top, gradient_bottom; +}; + +#endif /*SUPERTUX_BACKGROUND_H*/ + -- 2.11.0