--- /dev/null
+// $Id$
+//
+// SuperTux - A Jump'n Run
+// Copyright (C) 2004 Matthias Braun <matze@braunis.de
+//
+// This program is free software; you can redistribute it and/or
+// modify it under the terms of the GNU General Public License
+// as published by the Free Software Foundation; either version 2
+// of the License, or (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+#ifndef __AMBIENT_LIGHT_HPP__
+#define __AMBIENT_LIGHT_HPP__
+
+#include "game_object.hpp"
+#include "lisp/lisp.hpp"
+
+class Sprite;
+
+class AmbientLight : public GameObject
+{
+public:
+ AmbientLight(const lisp::Lisp& reader);
+ virtual ~AmbientLight();
+
+ void update(float elapsed_time);
+ void draw(DrawingContext& context);
+};
+
+#endif
+
--- /dev/null
+#include <config.h>
+
+#include <stdexcept>
+#include <sstream>
+#include "anchor_point.hpp"
+#include "math/rect.hpp"
+
+std::string anchor_point_to_string(AnchorPoint point)
+{
+ switch(point) {
+ case ANCHOR_TOP_LEFT:
+ return "topleft";
+ case ANCHOR_TOP:
+ return "top";
+ case ANCHOR_TOP_RIGHT:
+ return "topright";
+ case ANCHOR_LEFT:
+ return "left";
+ case ANCHOR_MIDDLE:
+ return "middle";
+ case ANCHOR_RIGHT:
+ return "right";
+ case ANCHOR_BOTTOM_LEFT:
+ return "bottomleft";
+ case ANCHOR_BOTTOM:
+ return "bottom";
+ case ANCHOR_BOTTOM_RIGHT:
+ return "bottomright";
+ default:
+ throw std::runtime_error("Invalid anchor point");
+ }
+}
+
+AnchorPoint string_to_anchor_point(const std::string& str)
+{
+ if(str == "topleft")
+ return ANCHOR_TOP_LEFT;
+ else if(str == "top")
+ return ANCHOR_TOP;
+ else if(str == "topright")
+ return ANCHOR_TOP_RIGHT;
+ else if(str == "left")
+ return ANCHOR_LEFT;
+ else if(str == "middle")
+ return ANCHOR_MIDDLE;
+ else if(str == "right")
+ return ANCHOR_RIGHT;
+ else if(str == "bottomleft")
+ return ANCHOR_BOTTOM_LEFT;
+ else if(str == "bottom")
+ return ANCHOR_BOTTOM;
+ else if(str == "bottomright")
+ return ANCHOR_BOTTOM_RIGHT;
+
+ std::ostringstream msg;
+ msg << "Unknown anchor '" << str << "'";
+ throw std::runtime_error(msg.str());
+}
+
+Vector get_anchor_pos(const Rect& rect, AnchorPoint point)
+{
+ Vector result;
+
+ switch(point & ANCHOR_V_MASK) {
+ case ANCHOR_LEFT:
+ result.x = rect.get_left();
+ break;
+ case ANCHOR_MIDDLE:
+ result.x = rect.get_left() + (rect.get_right() - rect.get_left()) / 2.0;
+ break;
+ case ANCHOR_RIGHT:
+ result.x = rect.get_right();
+ break;
+ default:
+#ifdef DEBUG
+ throw new std::runtime_error("Invalid anchor point found");
+#endif
+ printf("Invalid anchor point found");
+ result.x = rect.get_left();
+ break;
+ }
+
+ switch(point & ANCHOR_H_MASK) {
+ case ANCHOR_TOP:
+ result.y = rect.get_top();
+ break;
+ case ANCHOR_MIDDLE:
+ result.y = rect.get_top() + (rect.get_bottom() - rect.get_top()) / 2.0;
+ break;
+ case ANCHOR_BOTTOM:
+ result.y = rect.get_bottom();
+ break;
+ default:
+#ifdef DEBUG
+ throw new std::runtime_error("Invalid anchor point found");
+#endif
+ printf("Invalid anchor point found");
+ result.y = rect.get_top();
+ break;
+ }
+
+ return result;
+}
+
+Vector get_anchor_pos(const Rect& destrect, float width, float height,
+ AnchorPoint point)
+{
+ Vector result;
+
+ switch(point & ANCHOR_V_MASK) {
+ case ANCHOR_LEFT:
+ result.x = destrect.get_left();
+ break;
+ case ANCHOR_MIDDLE:
+ result.x = destrect.get_middle().x - width/2.0;
+ break;
+ case ANCHOR_RIGHT:
+ result.x = destrect.get_right() - width;
+ break;
+ default:
+#ifdef DEBUG
+ throw new std::runtime_error("Invalid anchor point found");
+#endif
+ printf("Invalid anchor point found");
+ result.x = destrect.get_left();
+ break;
+ }
+
+ switch(point & ANCHOR_H_MASK) {
+ case ANCHOR_TOP:
+ result.y = destrect.get_top();
+ break;
+ case ANCHOR_MIDDLE:
+ result.y = destrect.get_middle().y - height/2.0;
+ break;
+ case ANCHOR_BOTTOM:
+ result.y = destrect.get_bottom() - height;
+ break;
+ default:
+#ifdef DEBUG
+ throw new std::runtime_error("Invalid anchor point found");
+#endif
+ printf("Invalid anchor point found");
+ result.y = destrect.get_top();
+ break;
+ }
+
+ return result;
+}
+
--- /dev/null
+#ifndef __ANCHOR_POINT_HPP__
+#define __ANCHOR_POINT_HPP__
+
+#include <string>
+#include "math/vector.hpp"
+
+class Rect;
+
+enum AnchorPoint {
+ ANCHOR_H_MASK = 0x00f0,
+ ANCHOR_TOP = 0x0010,
+ ANCHOR_BOTTOM = 0x0020,
+ ANCHOR_V_MASK = 0x000f,
+ ANCHOR_LEFT = 0x0001,
+ ANCHOR_RIGHT = 0x0002,
+ ANCHOR_MIDDLE = 0x0000,
+
+ ANCHOR_TOP_LEFT = ANCHOR_TOP | ANCHOR_LEFT,
+ ANCHOR_TOP_RIGHT = ANCHOR_TOP | ANCHOR_RIGHT,
+ ANCHOR_BOTTOM_LEFT = ANCHOR_BOTTOM | ANCHOR_LEFT,
+ ANCHOR_BOTTOM_RIGHT = ANCHOR_BOTTOM | ANCHOR_RIGHT,
+};
+
+std::string anchor_point_to_string(AnchorPoint point);
+AnchorPoint string_to_anchor_point(const std::string& str);
+Vector get_anchor_pos(const Rect& rect, AnchorPoint point);
+Vector get_anchor_pos(const Rect& destrect, float width, float height,
+ AnchorPoint point);
+
+#endif
+
--- /dev/null
+#include <config.h>
+
+#include <stdexcept>
+#include "resources.hpp"
+#include "main.hpp"
+#include "math/rect.hpp"
+#include "sprite/sprite_manager.hpp"
+#include "sprite/sprite.hpp"
+#include "video/drawing_context.hpp"
+#include "lisp/lisp.hpp"
+#include "floating_image.hpp"
+
+FloatingImage::FloatingImage(const std::string& spritefile)
+ : sprite(NULL), layer(LAYER_FOREGROUND1 + 1), visible(false),
+ anchor(ANCHOR_MIDDLE)
+{
+ sprite = sprite_manager->create(spritefile);
+}
+
+FloatingImage::~FloatingImage()
+{
+ delete sprite;
+}
+
+void
+FloatingImage::update(float elapsed_time)
+{
+ (void) elapsed_time;
+}
+
+void
+FloatingImage::draw(DrawingContext& context)
+{
+ if(!visible)
+ return;
+
+ context.push_transform();
+ context.set_translation(Vector(0, 0));
+
+ Vector pos = get_anchor_pos(Rect(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT),
+ sprite->get_width(), sprite->get_height(), anchor);
+
+ sprite->draw(context, pos, layer);
+
+ context.pop_transform();
+}
--- /dev/null
+#ifndef __FLOATING_IMAGE_H__
+#define __FLOATING_IMAGE_H__
+
+#include "game_object.hpp"
+#include "math/vector.hpp"
+#include "anchor_point.hpp"
+
+class Sprite;
+
+class FloatingImage : public GameObject
+{
+public:
+ FloatingImage(const std::string& sprite);
+ virtual ~FloatingImage();
+
+ void set_layer(int layer) {
+ this->layer = layer;
+ }
+
+ int get_layer() const {
+ return layer;
+ }
+
+ void set_pos(const Vector& pos) {
+ this->pos = pos;
+ }
+ const Vector& get_pos() const {
+ return pos;
+ }
+
+ void set_anchor_point(AnchorPoint anchor) {
+ this->anchor = anchor;
+ }
+ AnchorPoint get_anchor_point() const {
+ return anchor;
+ }
+
+ void set_visible(bool visible) {
+ this->visible = visible;
+ }
+ bool get_visible() const {
+ return visible;
+ }
+
+ void update(float elapsed_time);
+ void draw(DrawingContext& context);
+
+private:
+ Sprite* sprite;
+ int layer;
+ bool visible;
+ AnchorPoint anchor;
+ Vector pos;
+};
+
+#endif
+
--- /dev/null
+#ifndef __ANCHOR_POINTS_HPP__
+#define __ANCHOR_POINTS_HPP__
+
+namespace Scripting {
+
+// TODO get these from the definitions in anchor.h (needs miniswig update)
+static const int ANCHOR_TOP = 0x0010;
+static const int ANCHOR_BOTTOM = 0x0020;
+static const int ANCHOR_LEFT = 0x0001;
+static const int ANCHOR_RIGHT = 0x0002;
+static const int ANCHOR_MIDDLE = 0x0000;
+static const int ANCHOR_TOP_LEFT = 0x0011;
+static const int ANCHOR_TOP_RIGHT = 0x0012;
+static const int ANCHOR_BOTTOM_LEFT = 0x0021;
+static const int ANCHOR_BOTTOM_RIGHT = 0x0022;
+
+}
+
+#endif
+
--- /dev/null
+#include <config.h>
+
+#include "floating_image.hpp"
+#include "sector.hpp"
+#include "object/floating_image.hpp"
+
+namespace Scripting
+{
+
+FloatingImage::FloatingImage(const std::string& spritefile)
+{
+ floating_image = new _FloatingImage(spritefile);
+ Sector::current()->add_object(floating_image);
+}
+
+FloatingImage::~FloatingImage()
+{
+ floating_image->remove_me();
+ // no delete here, Sector will do that
+}
+
+void
+FloatingImage::set_layer(int layer)
+{
+ floating_image->set_layer(layer);
+}
+
+int
+FloatingImage::get_layer()
+{
+ return floating_image->get_layer();
+}
+
+void
+FloatingImage::set_pos(float x, float y)
+{
+ floating_image->set_pos(Vector(x, y));
+}
+
+float
+FloatingImage::get_pos_x()
+{
+ return floating_image->get_pos().x;
+}
+
+float
+FloatingImage::get_pos_y()
+{
+ return floating_image->get_pos().y;
+}
+
+void
+FloatingImage::set_anchor_point(int anchor)
+{
+ floating_image->set_anchor_point((AnchorPoint) anchor);
+}
+
+int
+FloatingImage::get_anchor_point()
+{
+ return (int) floating_image->get_anchor_point();
+}
+
+bool
+FloatingImage::get_visible()
+{
+ return floating_image->get_visible();
+}
+
+void
+FloatingImage::set_visible(bool visible)
+{
+ floating_image->set_visible(visible);
+}
+
+}
--- /dev/null
+#ifndef __FLOATING_IMAGE_HPP__
+#define __FLOATING_IMAGE_HPP__
+
+#ifndef SCRIPTING_API
+#define __suspend
+#include <string>
+
+class FloatingImage;
+typedef FloatingImage _FloatingImage;
+#endif
+
+namespace Scripting
+{
+
+class FloatingImage
+{
+public:
+ FloatingImage(const std::string& spritefile);
+ ~FloatingImage();
+
+ void set_layer(int layer);
+ int get_layer();
+ void set_pos(float x, float y);
+ float get_pos_x();
+ float get_pos_y();
+ void set_anchor_point(int anchor);
+ int get_anchor_point();
+ void set_visible(bool visible);
+ bool get_visible();
+
+#ifndef SCRIPTING_API
+private:
+ _FloatingImage* floating_image;
+#endif
+};
+
+}
+
+#endif
+