map_tab.cpp

main 110 lines · 2.8 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#include "main.h"
19
20#include "gui.h"
21#include "editor.h"
22#include "map.h"
23#include "sprites.h"
24#include "map_tab.h"
25#include "editor_tabs.h"
26#include "map_display.h"
27
28MapTab::MapTab(MapTabbook* aui, Editor* editor) :
29 EditorTab(),
30 MapWindow(aui, *editor),
31 aui(aui) {
32 iref = newd InternalReference;
33 iref->editor = editor;
34 iref->owner_count = 1;
35
36 aui->AddTab(this, true);
37 FitToMap();
38}
39
40MapTab::MapTab(const MapTab* other) :
41 EditorTab(),
42 MapWindow(other->aui, *other->iref->editor),
43 aui(other->aui),
44 iref(other->iref) {
45 iref->owner_count++;
46 aui->AddTab(this, true);
47 FitToMap();
48 int x, y;
49 other->GetCanvas()->GetScreenCenter(&x, &y);
50 SetScreenCenterPosition(Position(x, y, other->GetCanvas()->GetFloor()));
51}
52
53MapTab::~MapTab() {
54 iref->owner_count--;
55 if (iref->owner_count <= 0) {
56 delete iref->editor;
57 delete iref;
58 }
59}
60
61bool MapTab::IsUniqueReference() const {
62 return iref->owner_count == 1;
63}
64
65wxWindow* MapTab::GetWindow() const {
66 return const_cast<MapTab*>(this);
67}
68
69MapCanvas* MapTab::GetCanvas() const {
70 return canvas;
71}
72
73MapWindow* MapTab::GetView() const {
74 return const_cast<MapWindow*>((const MapWindow*)this);
75}
76
77wxString MapTab::GetTitle() const {
78 wxString ss;
79 ss << wxstr(iref->editor->map.getName()) << (iref->editor->map.hasChanged() ? "*" : "");
80 return ss;
81}
82
83Editor* MapTab::GetEditor() const {
84 return &editor;
85}
86
87Map* MapTab::GetMap() const {
88 return &editor.map;
89}
90
91Position MapTab::GetScreenCenterPosition() const {
92 // Forward to the MapWindow implementation
93 return MapWindow::GetScreenCenterPosition();
94}
95
96void MapTab::VisibilityCheck() {
97 EditorTab* editorTab = aui->GetCurrentTab();
98 MapTab* mapTab = dynamic_cast<MapTab*>(editorTab);
99 UpdateDialogs(mapTab && HasSameReference(mapTab));
100}
101
102void MapTab::OnSwitchEditorMode(EditorMode mode) {
103 gem->SetSprite(mode == DRAWING_MODE ? EDITOR_SPRITE_DRAWING_GEM : EDITOR_SPRITE_SELECTION_GEM);
104 if (mode == SELECTION_MODE) {
105 canvas->EnterSelectionMode();
106 } else {
107 canvas->EnterDrawingMode();
108 }
109}
110
Top