map_display.h

main 235 lines · 6.1 KB Raw
Alex Alex Commit Map Editor 18/10/2026 23:40
1//////////////////////////////////////////////////////////////////////
2// This file is part of Remere's Map Editor
3//////////////////////////////////////////////////////////////////////
4// Remere's Map Editor 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// Remere's Map Editor 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
18#ifndef RME_DISPLAY_WINDOW_H_
19#define RME_DISPLAY_WINDOW_H_
20
21#include "action.h"
22#include "tile.h"
23#include "creature.h"
24
25class Item;
26class Creature;
27class MapWindow;
28class MapPopupMenu;
29class AnimationTimer;
30class MapDrawer;
31
32class MapCanvas : public wxGLCanvas {
33public:
34 MapCanvas(MapWindow* parent, Editor& editor, int* attriblist);
35 virtual ~MapCanvas();
36 void Reset();
37
38 // All events
39 void OnPaint(wxPaintEvent& event);
40 void OnEraseBackground(wxEraseEvent& event) { }
41
42 void OnMouseMove(wxMouseEvent& event);
43 void OnMouseLeftRelease(wxMouseEvent& event);
44 void OnMouseLeftClick(wxMouseEvent& event);
45 void OnMouseLeftDoubleClick(wxMouseEvent& event);
46 void OnMouseCenterClick(wxMouseEvent& event);
47 void OnMouseCenterRelease(wxMouseEvent& event);
48 void OnMouseRightClick(wxMouseEvent& event);
49 void OnMouseRightRelease(wxMouseEvent& event);
50
51 void OnKeyDown(wxKeyEvent& event);
52 void OnKeyUp(wxKeyEvent& event);
53 void OnWheel(wxMouseEvent& event);
54 void OnGainMouse(wxMouseEvent& event);
55 void OnLoseMouse(wxMouseEvent& event);
56
57
58 // Mouse events handlers (called by the above)
59 void OnMouseActionRelease(wxMouseEvent& event);
60 void OnMouseActionClick(wxMouseEvent& event);
61 void OnMouseCameraClick(wxMouseEvent& event);
62 void OnMouseCameraRelease(wxMouseEvent& event);
63 void OnMousePropertiesClick(wxMouseEvent& event);
64 void OnMousePropertiesRelease(wxMouseEvent& event);
65
66 //
67 void OnCut(wxCommandEvent& event);
68 void OnCopy(wxCommandEvent& event);
69 void OnCopyPosition(wxCommandEvent& event);
70 void OnCopyServerId(wxCommandEvent& event);
71 void OnCopyClientId(wxCommandEvent& event);
72 void OnCopyName(wxCommandEvent& event);
73 void OnBrowseTile(wxCommandEvent& event);
74 void OnPaste(wxCommandEvent& event);
75 void OnDelete(wxCommandEvent& event);
76 // ----
77 void OnGotoDestination(wxCommandEvent& event);
78 void OnRotateItem(wxCommandEvent& event);
79 void OnSwitchDoor(wxCommandEvent& event);
80 // ----
81 void OnSelectRAWBrush(wxCommandEvent& event);
82 void OnSelectGroundBrush(wxCommandEvent& event);
83 void OnSelectDoodadBrush(wxCommandEvent& event);
84 void OnSelectDoorBrush(wxCommandEvent& event);
85 void OnSelectWallBrush(wxCommandEvent& event);
86 void OnSelectCarpetBrush(wxCommandEvent& event);
87 void OnSelectTableBrush(wxCommandEvent& event);
88 void OnSelectCreatureBrush(wxCommandEvent& event);
89 void OnSelectSpawnBrush(wxCommandEvent& event);
90 void OnSelectHouseBrush(wxCommandEvent& event);
91 void OnSelectCollectionBrush(wxCommandEvent& event);
92 void OnSelectMoveTo(wxCommandEvent& event);
93
94 void OnFindSimilarItems(wxCommandEvent& event);
95 void OnGenerateIsland(wxCommandEvent& event);
96 void OnCreateHouse(wxCommandEvent& event);
97
98 void OnSelectionToDoodad(wxCommandEvent& event);
99 // ---
100 void OnProperties(wxCommandEvent& event);
101 void OnFill(wxCommandEvent& event);
102
103 void Refresh();
104
105 void ScreenToMap(int screen_x, int screen_y, int* map_x, int* map_y);
106 void GetScreenCenter(int* map_x, int* map_y);
107
108 void StartPasting();
109 void EndPasting();
110 void EnterSelectionMode();
111 void EnterDrawingMode();
112
113 void UpdatePositionStatus(int x = -1, int y = -1);
114 void UpdateZoomStatus();
115
116 void ChangeFloor(int new_floor);
117 int GetFloor() const {
118 return floor;
119 }
120 double GetZoom() const {
121 return zoom;
122 }
123 void SetZoom(double value);
124 void GetViewBox(int* view_scroll_x, int* view_scroll_y, int* screensize_x, int* screensize_y) const;
125
126 Position GetCursorPosition() const;
127
128 void TakeScreenshot(wxFileName path, wxString format);
129
130 void MouseToMap(int* map_x, int* map_y) {
131 ScreenToMap(cursor_x, cursor_y, map_x, map_y);
132 }
133
134protected:
135 void getTilesToDraw(int mouse_map_x, int mouse_map_y, int floor, PositionVector* tilestodraw, PositionVector* tilestoborder, bool fill = false);
136 bool floodFill(Map* map, const Position& center, int x, int y, GroundBrush* brush, PositionVector* positions);
137 bool hasHouseWall(Tile* tile);
138 bool hasDoor(Tile* tile);
139 bool hasStairsOrLadder(Tile* tile);
140
141private:
142 enum {
143 BLOCK_SIZE = 100
144 };
145
146 inline int getFillIndex(int x, int y) const {
147 return x + BLOCK_SIZE * y;
148 }
149
150 static bool processed[BLOCK_SIZE * BLOCK_SIZE];
151
152 Editor& editor;
153 MapDrawer* drawer;
154 int keyCode;
155 int countMaxFills = 0;
156
157 // View related
158 int floor;
159 double zoom;
160 int cursor_x;
161 int cursor_y;
162
163 bool dragging;
164 bool boundbox_selection;
165 bool screendragging;
166 bool isPasting() const;
167 bool drawing;
168 bool dragging_draw;
169 bool replace_dragging;
170
171 uint8_t* screenshot_buffer;
172
173 int drag_start_x;
174 int drag_start_y;
175 int drag_start_z;
176
177 int last_cursor_map_x;
178 int last_cursor_map_y;
179 int last_cursor_map_z;
180
181 int last_click_map_x;
182 int last_click_map_y;
183 int last_click_map_z;
184 int last_click_abs_x;
185 int last_click_abs_y;
186 int last_click_x;
187 int last_click_y;
188
189 int last_mmb_click_x;
190 int last_mmb_click_y;
191
192 int view_scroll_x;
193 int view_scroll_y;
194
195 uint32_t current_house_id;
196
197 wxStopWatch refresh_watch;
198 MapPopupMenu* popup_menu;
199 AnimationTimer* animation_timer;
200
201 bool show_fill_warning = true;
202
203 friend class MapDrawer;
204
205 DECLARE_EVENT_TABLE()
206};
207
208// Right-click popup menu
209class MapPopupMenu : public wxMenu {
210public:
211 MapPopupMenu(Editor& editor);
212 virtual ~MapPopupMenu();
213
214 void Update();
215
216protected:
217 Editor& editor;
218};
219
220class AnimationTimer : public wxTimer {
221public:
222 AnimationTimer(MapCanvas* canvas);
223 ~AnimationTimer();
224
225 void Notify();
226 void Start();
227 void Stop();
228
229private:
230 MapCanvas* map_canvas;
231 bool started;
232};
233
234#endif
235
Top