1647685cdc929a5221403856d949899fe4972841
[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 #include <config.h>
20
21 #include <assert.h>
22 #include <stdexcept>
23 #include "floating_image.hpp"
24 #include "sector.hpp"
25 #include "object/floating_image.hpp"
26 #include "worldmap/worldmap.hpp"
27
28 namespace Scripting
29 {
30
31 FloatingImage::FloatingImage(const std::string& spritefile)
32 {
33   using namespace WorldMapNS;
34   
35   floating_image = new _FloatingImage(spritefile);
36   if(Sector::current() != NULL) {
37     Sector::current()->add_object(floating_image.get());
38   } else if(WorldMap::current() != NULL) {
39     WorldMap::current()->add_object(floating_image.get());
40   } else {
41     throw new std::runtime_error("Neither sector nor worldmap active");
42   }
43 }
44
45 FloatingImage::~FloatingImage()
46 {
47   floating_image->remove_me();
48 }
49
50 void
51 FloatingImage::set_layer(int layer)
52 {
53   floating_image->set_layer(layer);
54 }
55
56 int
57 FloatingImage::get_layer()
58 {
59   return floating_image->get_layer();
60 }
61
62 void
63 FloatingImage::set_pos(float x, float y)
64 {
65   floating_image->set_pos(Vector(x, y));
66 }
67
68 float
69 FloatingImage::get_pos_x()
70 {
71   return floating_image->get_pos().x;
72 }
73
74 float
75 FloatingImage::get_pos_y()
76 {
77   return floating_image->get_pos().y;
78 }
79
80 void
81 FloatingImage::set_anchor_point(int anchor)
82 {
83   floating_image->set_anchor_point((AnchorPoint) anchor);
84 }
85
86 int
87 FloatingImage::get_anchor_point()
88 {
89   return (int) floating_image->get_anchor_point();
90 }
91
92 bool
93 FloatingImage::get_visible()
94 {
95   return floating_image->get_visible();
96 }
97
98 void
99 FloatingImage::set_visible(bool visible)
100 {
101   floating_image->set_visible(visible);
102 }
103
104 void
105 FloatingImage::set_action(const std::string& action)
106 {
107   floating_image->set_action(action);
108 }
109
110 std::string
111 FloatingImage::get_action()
112 {
113   return floating_image->get_action();
114 }
115
116 }