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.hpp"
22#include "sprite/sprite_manager.hpp"
23#include "supertux/debug.hpp"
24#include "supertux/gameconfig.hpp"
25#include "supertux/globals.hpp"
26#include "video/bitmap_font.hpp"
27#include "video/font.hpp"
28#include "video/surface.hpp"
29#include "video/ttf_font.hpp"
30
31std::unique_ptr<MouseCursor> Resources::mouse_cursor;
32
33FontPtr Resources::console_font;
34FontPtr Resources::fixed_font;
35FontPtr Resources::normal_font;
36FontPtr Resources::small_font;
37FontPtr Resources::big_font;
38
39SurfacePtr Resources::checkbox;
40SurfacePtr Resources::checkbox_checked;
41SurfacePtr Resources::back;
42SurfacePtr Resources::arrow_left;
43SurfacePtr Resources::arrow_right;
44SurfacePtr Resources::no_tile;
45
46std::string Resources::current_font;
47
48void
49Resources::load()
50{
51 // Load the mouse-cursor
52 mouse_cursor.reset(new MouseCursor(SpriteManager::current()->create("images/engine/menu/mousecursor.sprite")));
53 MouseCursor::set_current(mouse_cursor.get());
54
55 if (g_debug.get_use_bitmap_fonts())
56 {
57 console_font.reset(new BitmapFont(BitmapFont::FIXED, "fonts/andale12.stf", 1));
58 fixed_font.reset(new BitmapFont(BitmapFont::FIXED, "fonts/white.stf"));
59 normal_font.reset(new BitmapFont(BitmapFont::VARIABLE, "fonts/white.stf"));
60 small_font.reset(new BitmapFont(BitmapFont::VARIABLE, "fonts/white-small.stf", 1));
61 big_font.reset(new BitmapFont(BitmapFont::VARIABLE, "fonts/white-big.stf", 3));
62 }
63 else
64 {
65 console_font.reset(new TTFFont("fonts/SuperTux-Medium.ttf", 12, 1.25f, 0, 1));
66
67 auto font = get_font_for_locale(g_config->locale);
68 if(font != current_font)
69 {
70 current_font = font;
71 fixed_font.reset(new TTFFont(font, 18, 1.25f, 2, 1));
72 normal_font = fixed_font;
73 small_font.reset(new TTFFont(font, 10, 1.25f, 2, 1));
74 big_font.reset(new TTFFont(font, 22, 1.25f, 2, 1));
75 }
76 }
77
78 /* Load menu images */
79 checkbox = Surface::from_file("images/engine/menu/checkbox-unchecked.png");
80 checkbox_checked = Surface::from_file("images/engine/menu/checkbox-checked.png");
81 back = Surface::from_file("images/engine/menu/arrow-back.png");
82 arrow_left = Surface::from_file("images/engine/menu/arrow-left.png");
83 arrow_right = Surface::from_file("images/engine/menu/arrow-right.png");
84 no_tile = Surface::from_file("images/tiles/auxiliary/notile.png");
85}
86
87std::string
88Resources::get_font_for_locale(const std::string& locale)
89{
90 if(locale == "ne")
91 return "fonts/NotoSansDevanagari-Medium.ttf";
92 if(locale == "cmn" || locale == "ja" || locale == "zh_CN" || locale == "zh_TW")
93 return "fonts/NotoSansCJKjp-Medium.otf";
94 if(locale == "he")
95 return "fonts/NotoSansHebrew-Medium.ttf";
96 return "fonts/SuperTux-Medium.ttf";
97}
98
99void
100Resources::unload()
101{
102 // Free menu images
103 no_tile.reset();
104 checkbox.reset();
105 checkbox_checked.reset();
106 back.reset();
107 arrow_left.reset();
108 arrow_right.reset();
109
110 // Free global images:
111 console_font.reset();
112 fixed_font.reset();
113 normal_font.reset();
114 small_font.reset();
115 big_font.reset();
116
117 mouse_cursor.reset();
118}
119
120Resources::Resources()
121{
122 load();
123}
124
125Resources::~Resources()
126{
127 unload();
128}
129
130/* EOF */
131