1// SuperTux
2// Copyright (C) 2015 Hume2 <teratux.mail@gmail.com>
3//
4// This program is free software: you can redistribute it and/or modify
5// it under the terms of the GNU General Public License as published by
6// the Free Software Foundation, either version 3 of the License, or
7// (at your option) any later version.
8//
9// This program is distributed in the hope that it will be useful,
10// but WITHOUT ANY WARRANTY; without even the implied warranty of
11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12// GNU General Public License for more details.
13//
14// You should have received a copy of the GNU General Public License
15// along with this program. If not, see <http://www.gnu.org/licenses/>.
16
17#include "editor/layer_icon.hpp"
18
19#include <limits>
20
21#include "object/background.hpp"
22#include "object/gradient.hpp"
23#include "object/particlesystem.hpp"
24#include "object/particlesystem_interactive.hpp"
25#include "object/tilemap.hpp"
26#include "supertux/colorscheme.hpp"
27#include "supertux/game_object.hpp"
28#include "supertux/resources.hpp"
29#include "video/surface.hpp"
30
31LayerIcon::LayerIcon(GameObject* layer) :
32 ObjectIcon("", layer->get_icon_path()),
33 m_layer(layer),
34 m_selection()
35{
36 if (dynamic_cast<TileMap*>(layer)) {
37 m_selection = Surface::from_file("images/engine/editor/selection.png");
38 }
39}
40
41void
42LayerIcon::draw(DrawingContext& context, const Vector& pos)
43{
44 if (!is_valid()) return;
45
46 ObjectIcon::draw(context, pos);
47 int l = get_zpos();
48 if (l != std::numeric_limits<int>::min()) {
49 context.color().draw_text(Resources::small_font, std::to_string(l),
50 pos + Vector(16,16),
51 ALIGN_CENTER, LAYER_GUI, ColorScheme::Menu::default_color);
52 if (TileMap* tilemap = dynamic_cast<TileMap*>(m_layer)) {
53 if (tilemap->m_editor_active) {
54 context.color().draw_surface(m_selection, pos, LAYER_GUI - 1);
55 }
56 }
57 }
58}
59
60int
61LayerIcon::get_zpos() const
62{
63 if (!is_valid()) {
64 return std::numeric_limits<int>::min();
65 }
66
67 if (auto* tilemap = dynamic_cast<TileMap*>(m_layer)) {
68 return tilemap->get_layer();
69 } else if (auto* bkgrd = dynamic_cast<Background*>(m_layer)) {
70 return bkgrd->get_layer();
71 } else if (auto* grd = dynamic_cast<Gradient*>(m_layer)) {
72 return grd->get_layer();
73 } else if (auto* ps = dynamic_cast<ParticleSystem*>(m_layer)) {
74 return ps->get_layer();
75 } else if (auto* psi = dynamic_cast<ParticleSystem_Interactive*>(m_layer)) {
76 return psi->get_layer();
77 } else {
78 return std::numeric_limits<int>::min();
79 }
80}
81
82bool
83LayerIcon::is_tilemap() const
84{
85 return dynamic_cast<TileMap*>(m_layer) != nullptr;
86}
87
88bool
89LayerIcon::is_valid() const
90{
91 return m_layer && m_layer->is_valid();
92}
93
94/* EOF */
95