-
Notifications
You must be signed in to change notification settings - Fork 224
/
actions_history_window.cpp
183 lines (163 loc) · 5.63 KB
/
actions_history_window.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
//////////////////////////////////////////////////////////////////////
// This file is part of Remere's Map Editor
//////////////////////////////////////////////////////////////////////
// Remere's Map Editor is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Remere's Map Editor is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
//////////////////////////////////////////////////////////////////////
#include "main.h"
#include "actions_history_window.h"
#include "artprovider.h"
#include "editor.h"
#include "gui.h"
HistoryListBox::HistoryListBox(wxWindow* parent) :
wxVListBox(parent, wxID_ANY)
{
wxSize icon_size = FROM_DIP(parent, wxSize(16, 16));
open_bitmap = wxArtProvider::GetBitmap(wxART_FILE_OPEN, wxART_TOOLBAR, icon_size);
move_bitmap = wxArtProvider::GetBitmap(ART_MOVE, wxART_LIST, icon_size);
remote_bitmap = wxArtProvider::GetBitmap(ART_REMOTE, wxART_LIST, icon_size);
select_bitmap = wxArtProvider::GetBitmap(ART_SELECT, wxART_LIST, icon_size);
unselect_bitmap = wxArtProvider::GetBitmap(ART_UNSELECT, wxART_LIST, icon_size);
delete_bitmap = wxArtProvider::GetBitmap(ART_DELETE, wxART_LIST, icon_size);
cut_bitmap = wxArtProvider::GetBitmap(ART_CUT, wxART_LIST, icon_size);
paste_bitmap = wxArtProvider::GetBitmap(ART_PASTE, wxART_LIST, icon_size);
randomize_bitmap = wxArtProvider::GetBitmap(ART_RANDOMIZE, wxART_LIST, icon_size);
borderize_bitmap = wxArtProvider::GetBitmap(ART_BORDERIZE, wxART_LIST, icon_size);
draw_bitmap = wxArtProvider::GetBitmap(ART_DRAW, wxART_LIST, icon_size);
erase_bitmap = wxArtProvider::GetBitmap(ART_ERASE, wxART_LIST, icon_size);
switch_bitmap = wxArtProvider::GetBitmap(ART_SWITCH, wxART_LIST, icon_size);
rotate_bitmap = wxArtProvider::GetBitmap(ART_ROTATE, wxART_LIST, icon_size);
replace_bitmap = wxArtProvider::GetBitmap(ART_REPLACE, wxART_LIST, icon_size);
change_bitmap = wxArtProvider::GetBitmap(ART_CHANGE, wxART_LIST, icon_size);
}
void HistoryListBox::OnDrawItem(wxDC& dc, const wxRect& rect, size_t index) const
{
const Editor* editor = g_gui.GetCurrentEditor();
if(!editor) {
return;
}
const ActionQueue* actions = editor->getHistoryActions();
if(!actions) {
return;
}
if(IsSelected(index)) {
dc.SetTextForeground(*wxBLUE);
} else {
dc.SetTextForeground(*wxBLACK);
}
const BatchAction* action = actions->getAction(index - 1);
if(action) {
const wxBitmap& bitmap = getIconBitmap(action->getType());
dc.DrawBitmap(bitmap, rect.GetX() + 4, rect.GetY() + 4, true);
dc.DrawText(action->getLabel(), rect.GetX() + 28, rect.GetY() + 3);
} else {
dc.DrawBitmap(open_bitmap, rect.GetX() + 4, rect.GetY() + 4, true);
dc.DrawText("Open Map", rect.GetX() + 28, rect.GetY() + 3);
}
}
wxCoord HistoryListBox::OnMeasureItem(size_t index) const
{
return 24;
}
const wxBitmap& HistoryListBox::getIconBitmap(ActionIdentifier identifier) const
{
switch (identifier)
{
case ACTION_MOVE:
return move_bitmap;
case ACTION_REMOTE:
return remote_bitmap;
case ACTION_SELECT:
return select_bitmap;
case ACTION_UNSELECT:
return unselect_bitmap;
case ACTION_DELETE_TILES:
return delete_bitmap;
case ACTION_CUT_TILES:
return cut_bitmap;
case ACTION_PASTE_TILES:
return paste_bitmap;
case ACTION_RANDOMIZE:
return randomize_bitmap;
case ACTION_BORDERIZE:
return borderize_bitmap;
case ACTION_DRAW:
return draw_bitmap;
case ACTION_ERASE:
return erase_bitmap;
case ACTION_SWITCHDOOR:
return switch_bitmap;
case ACTION_ROTATE_ITEM:
return rotate_bitmap;
case ACTION_REPLACE_ITEMS:
return replace_bitmap;
case ACTION_CHANGE_PROPERTIES:
return change_bitmap;
default:
return wxNullBitmap;
}
}
ActionsHistoryWindow::ActionsHistoryWindow(wxWindow* parent) :
wxPanel(parent, wxID_ANY, wxDefaultPosition, wxSize(230, 250))
{
SetSizeHints(wxDefaultSize, wxDefaultSize);
wxBoxSizer* sizer = new wxBoxSizer(wxVERTICAL);
list = new HistoryListBox(this);
list->SetCanFocus(false);
sizer->Add(list, 1, wxEXPAND, 5);
SetSizer(sizer);
Layout();
// Connect Events
list->Connect(wxEVT_COMMAND_LISTBOX_SELECTED, wxCommandEventHandler(ActionsHistoryWindow::OnListSelected), NULL, this);
}
ActionsHistoryWindow::~ActionsHistoryWindow()
{
// Disconnect Events
list->Disconnect(wxEVT_COMMAND_LISTBOX_SELECTED, wxCommandEventHandler(ActionsHistoryWindow::OnListSelected), NULL, this);
}
void ActionsHistoryWindow::RefreshActions()
{
if(!IsShownOnScreen())
return;
const Editor* editor = g_gui.GetCurrentEditor();
if(!editor) {
list->SetItemCount(0);
list->Refresh();
return;
}
size_t count = 1;
int selection = 0;
const ActionQueue* actions = editor->getHistoryActions();
if(actions) {
count += actions->size();
selection += actions->getCurrentIndex();
}
list->SetItemCount(count);
list->SetSelection(selection);
list->Refresh();
}
void ActionsHistoryWindow::OnListSelected(wxCommandEvent& event)
{
int index = list->GetSelection();
if(index == wxNOT_FOUND)
return;
Editor* editor = g_gui.GetCurrentEditor();
if(editor && editor->getHistoryActions()) {
int current = editor->getHistoryActions()->getCurrentIndex();
if(index > current) {
editor->redo(index - current);
} else if (index < current) {
editor->undo(current - index);
}
}
}