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