- Worldmap scripts have their own roottable now (like sectors already have)
[supertux.git] / src / scripting / floating_image.cpp
1 //  $Id$
2 //
3 //  SuperTux
4 //  Copyright (C) 2006 Matthias Braun <matze@braunis.de>
5 //
6 //  This program is free software; you can redistribute it and/or
7 //  modify it under the terms of the GNU General Public License
8 //  as published by the Free Software Foundation; either version 2
9 //  of the License, or (at your option) any later version.
10 //
11 //  This program is distributed in the hope that it will be useful,
12 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
13 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 //  GNU General Public License for more details.
15 //
16 //  You should have received a copy of the GNU General Public License
17 //  along with this program; if not, write to the Free Software
18 //  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
19
20 #include <config.h>
21
22 #include <assert.h>
23 #include <stdexcept>
24 #include "floating_image.hpp"
25 #include "sector.hpp"
26 #include "object/floating_image.hpp"
27 #include "worldmap/worldmap.hpp"
28
29 namespace Scripting
30 {
31
32 FloatingImage::FloatingImage(const std::string& spritefile)
33 {
34   using namespace WorldMapNS;
35   
36   floating_image = new _FloatingImage(spritefile); 
37   if(Sector::current() != NULL) {
38     Sector::current()->add_object(floating_image);
39   } else if(WorldMap::current() != NULL) {
40     WorldMap::current()->add_object(floating_image);
41   } else {
42     delete floating_image;
43     throw new std::runtime_error("Neither sector nor worldmap active");
44   }
45 }
46
47 FloatingImage::~FloatingImage()
48 {
49   floating_image->remove_me();
50   // no delete here, Sector will do that
51 }
52
53 void
54 FloatingImage::set_layer(int layer)
55 {
56   floating_image->set_layer(layer);
57 }
58
59 int
60 FloatingImage::get_layer()
61 {
62   return floating_image->get_layer();
63 }
64
65 void
66 FloatingImage::set_pos(float x, float y)
67 {
68   floating_image->set_pos(Vector(x, y));
69 }
70
71 float
72 FloatingImage::get_pos_x()
73 {
74   return floating_image->get_pos().x;
75 }
76
77 float
78 FloatingImage::get_pos_y()
79 {
80   return floating_image->get_pos().y;
81 }
82
83 void
84 FloatingImage::set_anchor_point(int anchor)
85 {
86   floating_image->set_anchor_point((AnchorPoint) anchor);
87 }
88
89 int
90 FloatingImage::get_anchor_point()
91 {
92   return (int) floating_image->get_anchor_point();
93 }
94
95 bool
96 FloatingImage::get_visible()
97 {
98   return floating_image->get_visible();
99 }
100
101 void
102 FloatingImage::set_visible(bool visible)
103 {
104   floating_image->set_visible(visible);
105 }
106
107 void
108 FloatingImage::set_action(const std::string& action)
109 {
110   floating_image->set_action(action);
111 }
112
113 std::string
114 FloatingImage::get_action()
115 {
116   return floating_image->get_action();
117 }
118
119 }