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 | #ifndef HEADER_SUPERTUX_EDITOR_LAYERS_WIDGET_HPP |
18 | #define |
19 | |
20 | #include <stdexcept> |
21 | |
22 | #include "control/input_manager.hpp" |
23 | #include "editor/widget.hpp" |
24 | #include "supertux/screen.hpp" |
25 | |
26 | class DrawingContext; |
27 | class Editor; |
28 | class GameObject; |
29 | class LayerIcon; |
30 | class Tip; |
31 | class Vector; |
32 | |
33 | /** A widget at the bottom of the screen for switching between tilemap |
34 | layers and other non-movable GameObjects */ |
35 | class EditorLayersWidget final : public Widget |
36 | { |
37 | public: |
38 | enum class HoveredItem { |
39 | NONE, SPAWNPOINTS, SECTOR, LAYERS |
40 | }; |
41 | |
42 | public: |
43 | EditorLayersWidget(Editor& editor); |
44 | |
45 | virtual void draw(DrawingContext& context) override; |
46 | virtual void update(float dt_sec) override; |
47 | |
48 | virtual bool on_mouse_button_up(const SDL_MouseButtonEvent& button) override; |
49 | virtual bool on_mouse_button_down(const SDL_MouseButtonEvent& button) override; |
50 | virtual bool on_mouse_motion(const SDL_MouseMotionEvent& motion) override; |
51 | |
52 | virtual void setup() override; |
53 | virtual void resize() override; |
54 | |
55 | void refresh(); |
56 | |
57 | void refresh_sector_text(); |
58 | void sort_layers(); |
59 | void add_layer(GameObject* layer); |
60 | |
61 | GameObject* get_selected_tilemap() const { return m_selected_tilemap; } |
62 | |
63 | private: |
64 | Vector get_layer_coords(const int pos) const; |
65 | int get_layer_pos(const Vector& coords) const; |
66 | void update_tip(); |
67 | |
68 | private: |
69 | Editor& m_editor; |
70 | std::vector<std::unique_ptr<LayerIcon>> m_layer_icons; |
71 | GameObject* m_selected_tilemap; |
72 | |
73 | int m_Ypos; |
74 | const int m_Xpos = 32; |
75 | int m_Width; |
76 | |
77 | std::string m_sector_text; |
78 | int m_sector_text_width; |
79 | |
80 | HoveredItem m_hovered_item; |
81 | unsigned int m_hovered_layer; |
82 | |
83 | std::unique_ptr<Tip> m_object_tip; |
84 | |
85 | private: |
86 | EditorLayersWidget(const EditorLayersWidget&) = delete; |
87 | EditorLayersWidget& operator=(const EditorLayersWidget&) = delete; |
88 | }; |
89 | |
90 | #endif |
91 | |
92 | /* EOF */ |
93 | |