supertux
toolbox_widget.hpp
1 // SuperTux
2 // Copyright (C) 2015 Hume2 <teratux.mail@gmail.com>
3 // 2024 Vankata453
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 #ifndef HEADER_SUPERTUX_EDITOR_TOOLBOX_WIDGET_HPP
19 #define HEADER_SUPERTUX_EDITOR_TOOLBOX_WIDGET_HPP
20 
21 #include "editor/widget.hpp"
22 
23 #include <memory>
24 
25 #include "math/rectf.hpp"
26 #include "math/vector.hpp"
27 #include "video/surface_ptr.hpp"
28 
29 class Editor;
30 class EditorTilebox;
31 class ToolIcon;
32 
36 class EditorToolboxWidget final : public Widget
37 {
38 public:
39  enum class HoveredItem {
40  NONE, TILEGROUP, OBJECTS, TOOL, TILEBOX
41  };
42 
43 public:
44  EditorToolboxWidget(Editor& editor);
45 
46  virtual void draw(DrawingContext& context) 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  virtual bool on_mouse_wheel(const SDL_MouseWheelEvent& wheel) override;
52 
53  virtual void setup() override;
54  virtual void resize() override;
55 
56  void select_tilegroup(int id);
57  void select_objectgroup(int id);
58 
59  int get_tileselect_select_mode() const;
60  int get_tileselect_move_mode() const;
61 
62  void update_mouse_icon();
63 
64  EditorTilebox& get_tilebox() const { return *m_tilebox; }
65 
66  bool has_mouse_focus() const { return m_has_mouse_focus; }
67 
68 private:
69  Vector get_tool_coords(int pos) const;
70  int get_tool_pos(const Vector& coords) const;
71 
72  Rectf get_hovered_item_rect() const;
73 
74  SurfacePtr get_mouse_icon() const;
75 
76 private:
77  Editor& m_editor;
78 
79  std::unique_ptr<EditorTilebox> m_tilebox;
80 
81  float m_pos_x;
82  HoveredItem m_hovered_item;
83  int m_hovered_tool;
84 
85  std::unique_ptr<ToolIcon> m_rubber;
86  std::unique_ptr<ToolIcon> m_select_mode;
87  std::unique_ptr<ToolIcon> m_node_marker_mode;
88  std::unique_ptr<ToolIcon> m_move_mode;
89  std::unique_ptr<ToolIcon> m_undo_mode;
90 
91  bool m_has_mouse_focus;
92 
93 private:
95  EditorToolboxWidget& operator=(const EditorToolboxWidget&) = delete;
96 };
97 
98 #endif
99 
100 /* EOF */
Definition: tool_icon.hpp:28
The toolbox is on the right side of the screen and allows selection of the current tool and contains ...
Definition: toolbox_widget.hpp:36
Definition: rectf.hpp:31
virtual bool on_mouse_motion(const SDL_MouseMotionEvent &motion) override
Definition: toolbox_widget.cpp:200
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 provides functions for drawing things on screen.
Definition: drawing_context.hpp:42