011393c54f0a630430a844d692fe8e5bcf68af6c
[supertux.git] / src / supertux / resources.cpp
1 //  SuperTux
2 //  Copyright (C) 2003 Tobias Glaesser <tobi.web@gmx.de>
3 //  Copyright (C) 2006 Matthias Braun <matze@braunis.de>
4 //
5 //  This program is free software: you can redistribute it and/or modify
6 //  it under the terms of the GNU General Public License as published by
7 //  the Free Software Foundation, either version 3 of the License, or
8 //  (at your option) any later version.
9 //
10 //  This program is distributed in the hope that it will be useful,
11 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
12 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 //  GNU General Public License for more details.
14 //
15 //  You should have received a copy of the GNU General Public License
16 //  along with this program.  If not, see <http://www.gnu.org/licenses/>.
17
18 #include "supertux/resources.hpp"
19
20 #include "gui/mousecursor.hpp"
21 #include "sprite/sprite_manager.hpp"
22 #include "supertux/player_status.hpp"
23 #include "supertux/tile_manager.hpp"
24 #include "video/font.hpp"
25
26 MouseCursor* Resources::mouse_cursor = NULL;
27
28 FontPtr Resources::fixed_font;
29 FontPtr Resources::normal_font;
30 FontPtr Resources::small_font;
31 FontPtr Resources::big_font;
32
33 SurfacePtr Resources::checkbox;
34 SurfacePtr Resources::checkbox_checked;
35 SurfacePtr Resources::back;
36 SurfacePtr Resources::arrow_left;
37 SurfacePtr Resources::arrow_right;
38
39 /* Load graphics/sounds shared between all levels: */
40 void
41 Resources::load_shared()
42 {
43   /* Load the mouse-cursor */
44   mouse_cursor = new MouseCursor("images/engine/menu/mousecursor.png");
45   MouseCursor::set_current(mouse_cursor);
46
47   /* Load global images: */
48   fixed_font.reset(new Font(Font::FIXED, "fonts/white.stf"));
49   normal_font.reset(new Font(Font::VARIABLE, "fonts/white.stf"));
50   small_font.reset(new Font(Font::VARIABLE, "fonts/white-small.stf", 1));
51   big_font.reset(new Font(Font::VARIABLE, "fonts/white-big.stf", 3));
52
53   /* Load menu images */
54   checkbox = Surface::create("images/engine/menu/checkbox-unchecked.png");
55   checkbox_checked = Surface::create("images/engine/menu/checkbox-checked.png");
56   back = Surface::create("images/engine/menu/arrow-back.png");
57   arrow_left = Surface::create("images/engine/menu/arrow-left.png");
58   arrow_right = Surface::create("images/engine/menu/arrow-right.png");
59
60   tile_manager   = new TileManager();
61   sprite_manager = new SpriteManager();
62 }
63
64 /* Free shared data: */
65 void
66 Resources::unload_shared()
67 {
68   /* Free menu images */
69   if(checkbox != NULL)
70     checkbox.reset();
71   if(checkbox_checked != NULL)
72     checkbox_checked.reset();
73   if(back != NULL)
74     back.reset();
75   if(arrow_left != NULL)
76     arrow_left.reset();
77   if(arrow_right != NULL)
78     arrow_right.reset();
79
80   /* Free global images: */
81   if(fixed_font != NULL)
82     fixed_font.reset();
83   if(normal_font != NULL)
84     normal_font.reset();
85   if(small_font != NULL)
86     small_font.reset();
87   if(big_font != NULL)
88     big_font.reset();
89   
90   /* Free tilesets */
91   if(tile_manager != NULL)
92   {
93     for(TileManager::TileSets::iterator it = tile_manager->tilesets.begin();
94         it != tile_manager->tilesets.end(); ++it)
95     {
96       delete it->second;
97       it->second = NULL;
98     }
99   }
100   if(sprite_manager != NULL)
101   {
102     delete sprite_manager;
103     sprite_manager = NULL;
104   }
105
106   /* Free mouse-cursor */
107   if(mouse_cursor != NULL)
108   {
109     mouse_cursor->cursor.reset();
110     delete mouse_cursor;
111   }
112 }
113
114 /* EOF */