62fec61661abfeaf5f4cc56d8e5ae98970b752fd
[supertux.git] / src / object / decal.cpp
1 //  $Id$
2 //
3 //  SuperTux - Decal
4 //  Copyright (C) 2008 Christoph Sommer <christoph.sommer@2008.expires.deltadevelopment.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 <stdexcept>
23 #include "decal.hpp"
24 #include "camera.hpp"
25 #include "video/drawing_context.hpp"
26 #include "lisp/lisp.hpp"
27 #include "lisp/writer.hpp"
28 #include "object_factory.hpp"
29 #include "resources.hpp"
30 #include "main.hpp"
31 #include "log.hpp"
32
33 Decal::Decal(const lisp::Lisp& reader)
34   : layer(LAYER_OBJECTS)
35 {
36   float px = 0;
37   float py = 0;
38   reader.get("x", px);
39   reader.get("y", py);
40   pos = Vector(px, py);
41
42   if(!reader.get("image", imagefile)) throw std::runtime_error("Must specify image for decal");
43   image.reset(new Surface(imagefile));
44
45   reader.get("layer", layer);
46 }
47
48 Decal::~Decal()
49 {
50 }
51
52 void
53 Decal::write(lisp::Writer& writer)
54 {
55   writer.start_list("decal");
56   writer.write("x", pos.x);
57   writer.write("y", pos.y);
58   writer.write("image", imagefile);
59   writer.write("layer", layer);
60   writer.end_list("decal");
61 }
62
63 void
64 Decal::update(float)
65 {
66 }
67
68 void
69 Decal::draw(DrawingContext& context)
70 {
71   if(!image.get()) return;
72   context.draw_surface(image.get(), pos, layer);
73 }
74
75 IMPLEMENT_FACTORY(Decal, "decal");
76