supertux
layers_widget.hpp
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 <memory>
21 #include <stdexcept>
22 #include <string>
23 #include <vector>
24 
25 #include "editor/widget.hpp"
26 
27 #include "editor/object_icon.hpp"
28 #include "editor/object_info.hpp"
29 #include "math/fwd.hpp"
30 #include "util/uid.hpp"
31 
32 class DrawingContext;
33 class Editor;
34 class EditorTilebox;
35 class GameObject;
36 class LayerIcon;
37 class TileMap;
38 class Tip;
39 
42 class EditorLayersWidget final : public Widget
43 {
44 public:
45  enum class HoveredItem {
46  NONE, SPAWNPOINTS, SECTOR, LAYERS
47  };
48 
49 public:
50  EditorLayersWidget(Editor& editor);
51 
52  virtual void draw(DrawingContext& context) override;
53  virtual void update(float dt_sec) override;
54 
55  virtual bool event(const SDL_Event& ev) override;
56  virtual bool on_mouse_button_up(const SDL_MouseButtonEvent& button) override;
57  virtual bool on_mouse_button_down(const SDL_MouseButtonEvent& button) override;
58  virtual bool on_mouse_motion(const SDL_MouseMotionEvent& motion) override;
59  virtual bool on_mouse_wheel(const SDL_MouseWheelEvent& wheel) override;
60 
61  virtual void setup() override;
62  virtual void resize() override;
63 
64  void refresh();
65 
66  void refresh_sector_text();
67  void refresh_layers();
68  void sort_layers();
69  void add_layer(GameObject* layer, bool initial = false);
70 
71  void update_current_tip();
72 
73  bool has_mouse_focus() const;
74 
75  TileMap* get_selected_tilemap() const;
76  void set_selected_tilemap(TileMap* tilemap);
77 
78 private:
79  Vector get_layer_coords(const int pos) const;
80  int get_layer_pos(const Vector& coords) const;
81  void update_tip();
82 
83 private:
84  Editor& m_editor;
85  std::vector<std::unique_ptr<LayerIcon>> m_layer_icons;
86  UID m_selected_tilemap;
87 
88  ObjectIcon m_add_icon;
89  std::unique_ptr<EditorTilebox> m_add_layer_box;
90  bool m_add_layer_box_visible;
91 
92  int m_Ypos;
93  const int m_Xpos = 32;
94  int m_Width;
95  int m_scroll;
96  int m_scroll_speed;
97 
98  std::string m_sector_text;
99  int m_sector_text_width;
100 
101  HoveredItem m_hovered_item;
102  unsigned int m_hovered_layer;
103 
104  std::unique_ptr<Tip> m_object_tip;
105 
106  bool m_has_mouse_focus;
107 
108 private:
109  EditorLayersWidget(const EditorLayersWidget&) = delete;
110  EditorLayersWidget& operator=(const EditorLayersWidget&) = delete;
111 };
112 
113 #endif
114 
115 /* EOF */
Definition: tip.hpp:28
Definition: object_icon.hpp:28
Definition: layer_icon.hpp:25
Definition: uid.hpp:37
This class is responsible for: Updating and drawing the object.
Definition: game_object.hpp:83
The tilebox allows selection of tiles or objects from a specified tilegroup/objectgroup.
Definition: tilebox.hpp:44
Definition: editor.hpp:49
Definition: widget.hpp:24
This class is responsible for managing an array of tiles.
Definition: tilemap.hpp:49
This class provides functions for drawing things on screen.
Definition: drawing_context.hpp:42
A widget at the bottom of the screen for switching between tilemap layers and other non-movable GameO...
Definition: layers_widget.hpp:42