map_window.h

main 140 lines · 4.4 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_MAP_WINDOW_H_
19#define RME_MAP_WINDOW_H_
20
21#include "position.h"
22#include "replace_items_window.h"
23#include "island_generator_dialog.h"
24#include "ground_validation_dialog.h"
25
26class MapCanvas;
27class DCButton;
28
29// Map window, a window displaying a map, complete with scrollbars
30// and everything. This is the window that's inside each tab in the
31// editor. Does NOT control any map rendering or editing at all.
32// MapCanvas does that. (mapdisplay.h)
33class MapWindow : public wxPanel {
34public:
35 MapWindow(wxWindow* parent, Editor& editor);
36 virtual ~MapWindow();
37
38 // Event handlers
39 void OnSize(wxSizeEvent& event);
40 void OnScroll(wxScrollEvent& event);
41 void OnScrollLineDown(wxScrollEvent& event);
42 void OnScrollLineUp(wxScrollEvent& event);
43 void OnScrollPageDown(wxScrollEvent& event);
44 void OnScrollPageUp(wxScrollEvent& event);
45 void OnGem(wxCommandEvent& event);
46
47 // Custom interface for MapWindow
48
49 // GetViewSize returns the size of the containing canvas, in pixels
50 void GetViewSize(int* x, int* y);
51 // Returns the start of the camera on the map, in pixels
52 // Actually is scroll thumb positions
53 void GetViewStart(int* x, int* y);
54
55 // Set size of this window (in pixels)
56 // if center is true, the camera will be moved to the center of the map.
57 void SetSize(int x, int y, bool center = false);
58
59 // Scroll to the specified, absolute position (in pixels)
60 void Scroll(int x, int y, bool center = false);
61
62 // Scroll this many pixels in X/Y, relative to current position
63 void ScrollRelative(int x, int y);
64
65 // Resize scrollbars to fit to the map dimensions
66 // This needs to be called after updating map height/width
67 void FitToMap();
68
69 // Screen position.
70 Position GetScreenCenterPosition() const;
71 void SetScreenCenterPosition(const Position& position);
72 void GoToPreviousCenterPosition();
73
74 // Return the containing canvas
75 MapCanvas* GetCanvas() const {
76 return canvas;
77 }
78
79 void ShowReplaceItemsDialog(bool selectionOnly);
80 void CloseReplaceItemsDialog();
81 void OnReplaceItemsDialogClose(wxCloseEvent& event);
82
83 void ShowIslandGeneratorDialog();
84 void CloseIslandGeneratorDialog();
85 void OnIslandGeneratorDialogClose(wxCloseEvent& event);
86
87 void ShowGroundValidationDialog();
88 void CloseGroundValidationDialog();
89 void OnGroundValidationDialogClose(wxCloseEvent& event);
90
91protected:
92 // For internal use, call to resize the scrollbars with
93 // the newd dimensions of *this* window
94 void UpdateScrollbars(int nx, int ny);
95 void UpdateDialogs(bool show);
96
97protected:
98 Editor& editor;
99 DCButton* gem;
100 MapCanvas* canvas;
101 wxScrollBar* hScroll;
102 wxScrollBar* vScroll;
103
104private:
105 ReplaceItemsDialog* replaceItemsDialog;
106 IslandGeneratorDialog* islandGeneratorDialog;
107 GroundValidationDialog* groundValidationDialog;
108 Position previous_position;
109
110 friend class MainFrame;
111 friend class MapCanvas;
112
113 DECLARE_EVENT_TABLE()
114};
115
116// MapScrollbar, a special scrollbar that relays alot of events
117// to the canvas, which allows scrolling when the scrollbar has
118// focus (even though it also resents focus as hard as it can.
119class MapScrollBar : public wxScrollBar {
120public:
121 MapScrollBar(MapWindow* parent, wxWindowID id, long style, wxWindow* canvas) :
122 wxScrollBar(parent, id, wxDefaultPosition, wxDefaultSize, style), canvas(canvas) { }
123 virtual ~MapScrollBar() { }
124
125 void OnKey(wxKeyEvent& event) {
126 canvas->GetEventHandler()->AddPendingEvent(event);
127 }
128 void OnWheel(wxMouseEvent& event) {
129 canvas->GetEventHandler()->AddPendingEvent(event);
130 }
131 void OnFocus(wxFocusEvent& event) {
132 canvas->SetFocus();
133 }
134
135 wxWindow* canvas;
136 DECLARE_EVENT_TABLE()
137};
138
139#endif
140
Top