/
resources.cpp
115 lines (101 loc) · 3.39 KB
/
resources.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
// SuperTux
// Copyright (C) 2003 Tobias Glaesser <tobi.web@gmx.de>
// Copyright (C) 2006 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 3 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, see <http://www.gnu.org/licenses/>.
#include "supertux/resources.hpp"
#include "gui/mousecursor.hpp"
#include "sprite/sprite_manager.hpp"
#include "supertux/player_status.hpp"
#include "supertux/tile_manager.hpp"
#include "video/font.hpp"
MouseCursor* Resources::mouse_cursor = NULL;
FontPtr Resources::fixed_font;
FontPtr Resources::normal_font;
FontPtr Resources::small_font;
FontPtr Resources::big_font;
SurfacePtr Resources::checkbox;
SurfacePtr Resources::checkbox_checked;
SurfacePtr Resources::back;
SurfacePtr Resources::arrow_left;
SurfacePtr Resources::arrow_right;
/* Load graphics/sounds shared between all levels: */
void
Resources::load_shared()
{
/* Load the mouse-cursor */
mouse_cursor = new MouseCursor("images/engine/menu/mousecursor.png",
"images/engine/menu/mousecursor-click.png",
"images/engine/menu/mousecursor-link.png");
MouseCursor::set_current(mouse_cursor);
/* Load global images: */
fixed_font.reset(new Font(Font::FIXED, "fonts/white.stf"));
normal_font.reset(new Font(Font::VARIABLE, "fonts/white.stf"));
small_font.reset(new Font(Font::VARIABLE, "fonts/white-small.stf", 1));
big_font.reset(new Font(Font::VARIABLE, "fonts/white-big.stf", 3));
/* Load menu images */
checkbox = Surface::create("images/engine/menu/checkbox-unchecked.png");
checkbox_checked = Surface::create("images/engine/menu/checkbox-checked.png");
back = Surface::create("images/engine/menu/arrow-back.png");
arrow_left = Surface::create("images/engine/menu/arrow-left.png");
arrow_right = Surface::create("images/engine/menu/arrow-right.png");
tile_manager = new TileManager();
sprite_manager = new SpriteManager();
}
/* Free shared data: */
void
Resources::unload_shared()
{
/* Free menu images */
if(checkbox != NULL)
checkbox.reset();
if(checkbox_checked != NULL)
checkbox_checked.reset();
if(back != NULL)
back.reset();
if(arrow_left != NULL)
arrow_left.reset();
if(arrow_right != NULL)
arrow_right.reset();
/* Free global images: */
if(fixed_font != NULL)
fixed_font.reset();
if(normal_font != NULL)
normal_font.reset();
if(small_font != NULL)
small_font.reset();
if(big_font != NULL)
big_font.reset();
/* Free tilesets */
if(tile_manager != NULL)
{
for(TileManager::TileSets::iterator it = tile_manager->tilesets.begin();
it != tile_manager->tilesets.end(); ++it)
{
delete it->second;
it->second = NULL;
}
}
if(sprite_manager != NULL)
{
delete sprite_manager;
sprite_manager = NULL;
}
/* Free mouse-cursor */
if(mouse_cursor != NULL)
{
delete mouse_cursor;
}
}
/* EOF */