supertux
overlay_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_OVERLAY_WIDGET_HPP
18 #define HEADER_SUPERTUX_EDITOR_OVERLAY_WIDGET_HPP
19 
20 #include <SDL.h>
21 
22 #include "control/input_manager.hpp"
23 #include "editor/widget.hpp"
24 #include "math/vector.hpp"
25 
26 class Color;
27 class DrawingContext;
28 class Editor;
29 class GameObject;
30 class MovingObject;
31 class NodeMarker;
32 class Path;
33 class Rectf;
34 class Tip;
35 
38 class EditorOverlayWidget final : public Widget
39 {
40 public:
41  static bool render_background;
42  static bool render_grid;
43  static bool snap_to_grid;
44  static int selected_snap_grid_size;
45 
46 public:
47  EditorOverlayWidget(Editor& editor);
48  virtual ~EditorOverlayWidget();
49 
50  virtual void draw(DrawingContext&) override;
51  virtual void update(float dt_sec) override;
52 
53  virtual bool on_mouse_button_up(const SDL_MouseButtonEvent& button) override;
54  virtual bool on_mouse_button_down(const SDL_MouseButtonEvent& button) override;
55  virtual bool on_mouse_motion(const SDL_MouseMotionEvent& motion) override;
56  virtual bool on_key_up(const SDL_KeyboardEvent& key) override;
57  virtual bool on_key_down(const SDL_KeyboardEvent& key) override;
58 
59  void update_pos();
60  void delete_markers();
61  void update_node_iterators();
62  void on_level_change();
63 
64  void edit_path(Path* path, GameObject* new_marked_object = nullptr);
65 
66 private:
67  void input_tile(const Vector& pos, uint32_t tile);
68  void put_tile();
69  void draw_rectangle();
70  void fill();
71  void put_object();
72 
73  void rubber_object();
74  void rubber_rect();
75 
76  void grab_object();
77  void move_object();
78  void clone_object();
79  void hover_object();
80  void show_object_menu(GameObject& object);
81  void select_object();
82  void add_path_node();
83 
84  void draw_tile_tip(DrawingContext&);
85  void draw_tile_grid(DrawingContext&, const Color& line_color, int tile_size = 32);
86  void draw_tilemap_border(DrawingContext&);
87  void draw_path(DrawingContext&);
88 
89  void process_left_click();
90  void process_right_click();
91 
92  // sp is sector pos, tp is pos on tilemap.
93  Vector tp_to_sp(const Vector& tp, int tile_size = 32);
94  Vector sp_to_tp(const Vector& sp, int tile_size = 32);
95  Vector tile_screen_pos(const Vector& tp, int tile_size = 32);
96 
97  // in sector position
98  Rectf drag_rect();
99  Rectf tile_drag_rect();
100  Rectf selection_draw_rect();
101  void update_tile_selection();
102 
103 private:
104  Editor& m_editor;
105  Vector m_hovered_tile;
106  Vector m_sector_pos;
107  Vector m_mouse_pos;
108 
109  bool m_dragging;
110  bool m_dragging_right;
111  Vector m_drag_start;
112  MovingObject* m_dragged_object;
113 
114  MovingObject* m_hovered_object;
115  GameObject* m_selected_object;
116  Path* m_edited_path;
117  NodeMarker* m_last_node_marker;
118 
119  std::unique_ptr<Tip> m_object_tip;
120  Vector m_obj_mouse_desync;
121 
122 private:
123  EditorOverlayWidget(const EditorOverlayWidget&) = delete;
124  EditorOverlayWidget& operator=(const EditorOverlayWidget&) = delete;
125 };
126 
127 #endif
128 
129 /* EOF */
Definition: tip.hpp:27
Simple two dimensional vector.
Definition: vector.hpp:24
A widget that is drawn on top of the current sector and handles mouse input and tool drawing...
Definition: overlay_widget.hpp:38
Definition: path.hpp:44
Definition: rectf.hpp:29
Base class for all the things that make up Levels&#39; Sectors.
Definition: game_object.hpp:46
Base class for all dynamic/moving game objects.
Definition: moving_object.hpp:31
Definition: editor.hpp:45
Definition: widget.hpp:24
Definition: color.hpp:25
Definition: node_marker.hpp:23
This class provides functions for drawing things on screen.
Definition: drawing_context.hpp:42