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_TOOLBOX_WIDGET_HPP |
18 | #define |
19 | |
20 | #include <stdexcept> |
21 | |
22 | #include "control/input_manager.hpp" |
23 | #include "editor/widget.hpp" |
24 | #include "math/vector.hpp" |
25 | #include "supertux/screen.hpp" |
26 | #include "supertux/tile_set.hpp" |
27 | |
28 | class Editor; |
29 | class ObjectInfo; |
30 | class Rectf; |
31 | class TileSelection; |
32 | class ToolIcon; |
33 | |
34 | /** The toolbox is on the right side of the screen and allows |
35 | selection of the current tool and contains the object or tile |
36 | palette */ |
37 | class EditorToolboxWidget final : public Widget |
38 | { |
39 | public: |
40 | enum class HoveredItem { |
41 | NONE, TILEGROUP, OBJECTS, TILE, TOOL |
42 | }; |
43 | |
44 | enum class TileScrolling { |
45 | NONE, UP, DOWN |
46 | }; |
47 | |
48 | enum class InputType { |
49 | NONE, TILE, OBJECT |
50 | }; |
51 | |
52 | public: |
53 | EditorToolboxWidget(Editor& editor); |
54 | |
55 | virtual void draw(DrawingContext& context) override; |
56 | virtual void update(float dt_sec) override; |
57 | |
58 | virtual bool on_mouse_button_up(const SDL_MouseButtonEvent& button) override; |
59 | virtual bool on_mouse_button_down(const SDL_MouseButtonEvent& button) override; |
60 | virtual bool on_mouse_motion(const SDL_MouseMotionEvent& motion) override; |
61 | virtual bool on_mouse_wheel(const SDL_MouseWheelEvent& wheel) override; |
62 | |
63 | virtual void setup() override; |
64 | virtual void resize() override; |
65 | |
66 | void update_mouse_icon(); |
67 | |
68 | int get_tileselect_select_mode() const; |
69 | int get_tileselect_move_mode() const; |
70 | |
71 | void select_tilegroup(int id); |
72 | void select_objectgroup(int id); |
73 | |
74 | const ObjectInfo& get_object_info() const { return *m_object_info; } |
75 | InputType get_input_type() const { return m_input_type; } |
76 | void set_input_type(InputType input_type) { m_input_type = input_type; } |
77 | |
78 | std::string get_object() const { return m_object; } |
79 | TileSelection* get_tiles() const { return m_tiles.get(); } |
80 | |
81 | private: |
82 | Vector get_tile_coords(const int pos) const; |
83 | int get_tile_pos(const Vector& coords) const; |
84 | Vector get_tool_coords(const int pos) const; |
85 | int get_tool_pos(const Vector& coords) const; |
86 | |
87 | Rectf get_item_rect(const HoveredItem& item) const; |
88 | |
89 | void update_selection(); |
90 | Rectf normalize_selection() const; |
91 | Rectf selection_draw_rect() const; |
92 | |
93 | void draw_tilegroup(DrawingContext&); |
94 | void draw_objectgroup(DrawingContext&); |
95 | |
96 | private: |
97 | Editor& m_editor; |
98 | |
99 | std::unique_ptr<TileSelection> m_tiles; |
100 | |
101 | std::string m_object; |
102 | InputType m_input_type; |
103 | |
104 | std::unique_ptr<Tilegroup> m_active_tilegroup; |
105 | int m_active_objectgroup; |
106 | std::unique_ptr<ObjectInfo> m_object_info; |
107 | |
108 | std::unique_ptr<ToolIcon> m_rubber; |
109 | std::unique_ptr<ToolIcon> m_select_mode; |
110 | std::unique_ptr<ToolIcon> m_move_mode; |
111 | std::unique_ptr<ToolIcon> m_undo_mode; |
112 | |
113 | HoveredItem m_hovered_item; |
114 | int m_hovered_tile; |
115 | TileScrolling m_tile_scrolling; |
116 | bool m_using_scroll_wheel; |
117 | int m_wheel_scroll_amount; |
118 | int m_starting_tile; |
119 | bool m_dragging; |
120 | Vector m_drag_start; |
121 | |
122 | int m_Xpos; |
123 | const int m_Ypos = 96; |
124 | |
125 | private: |
126 | EditorToolboxWidget(const EditorToolboxWidget&) = delete; |
127 | EditorToolboxWidget& operator=(const EditorToolboxWidget&) = delete; |
128 | }; |
129 | |
130 | #endif |
131 | |
132 | /* EOF */ |
133 | |