forked from scp-fs2open/PCS2
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmodel_editor_ctrl.h
More file actions
271 lines (218 loc) · 7.02 KB
/
model_editor_ctrl.h
File metadata and controls
271 lines (218 loc) · 7.02 KB
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
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
#pragma once
#include <wx/wx.h>
#include "pcs_file.h"
#include "primitive_ctrl.h"
#include "omnipoints.h"
#include "op_stack.h"
/*
based roughly on kaz's pe_base, a base class that edits some aspect of a pof
this class does not have the controls on it directly, rather it serves
as the scrolling window parent of a panel that has them, the base for that panel is
defined below
this control can also have common editor elements added to it
*/
//this cannot be replaced with a template cause we need access
//to some of the functions and we need a base class with those
//functions, this is that base class
class model_editor_ctrl_base : public wxScrolledWindow
{
protected:
//this is so you can get access to the control panel from outside
wxPanel *base_panel;
bool Ready;
public:
model_editor_ctrl_base(wxWindow*parent, CHUNK Type)
:wxScrolledWindow(parent), Ready(false), chunk_type(Type)
{
}
//populates the control with data from the model
virtual void set_data(PCS_Model &model)=0;
//applies the data in the control to the model
virtual void apply_data(PCS_Model &model)=0;
virtual void set_item(const std::vector<int>&coord)=0;
virtual std::vector<int> get_item()=0;
virtual omnipoints get_omnipoints()=0;
virtual void set_omnipoints(const omnipoints&points)=0;
virtual void get_omnipoint_coords(int&list, int&item)=0;
virtual void set_omnipoint_coords(int&list, int&item)=0;
const CHUNK chunk_type;
bool ready(){return Ready;}
virtual void push_undo()=0;
virtual void undo()=0;
virtual void redo()=0;
virtual void fix_buttons()=0;
virtual void reset_undo()=0;
virtual wxSizer* get_transform_options(wxWindow* parent)=0;
virtual void transform(const matrix& transform, const vector3d& translation)=0;
};
//base for the panel with the item specific editors on them
//there are four virtual functions all dealing
//with setting/getting data
//functions inherited from editor<type>
//void set_value(const type&t)
// - this function is responcable for takeing a structure
// and displaying the contents on screen
//if you did everything right this will be a bunch of
//name_of_control->set_value(t);
//...
//type get_value()
// - this function is responcable for returning a structure
// from the controls
//if you did everything right this will be a bunch of
//type type_instance;
//type_instance.member = name_of_control->get_value();
//...
//return type_insance;
//editor_ctrl specific functions
//void set_data(PCS_Model &model)
// - this function is responsable for getting the data
// structure from the passed model
//if you did everything right this will be little more than
//set_value(model.get_the_data_you_want());
//void apply_data(PCS_Model &model)
// - this function is responsable for setting the data
// from the control into the model
//if you did everything right this will be little more than
//model.set_the_data_you_want(conrol_panel->get_value());
template<class type>
class editor_ctrl
:public editor<type>
{
protected:
type data;
op_stack<type> undo_stack;
public:
void push_undo(){
data = this->get_value();
undo_stack.push(data);
}
void undo(){
undo_stack.undo(data);
this->set_value(data);//update the UI
}
void redo(){
undo_stack.redo(data);
this->set_value(data);//update the UI
}
void fix_buttons(){
undo_stack.fix_buttons();
}
void reset_undo(){
undo_stack.reset();
}
void recalc_size(){
}
editor_ctrl(wxWindow*parent, const wxString&Title, int orient = wxVERTICAL)
:editor<type>(parent,orient, Title)
{
}
virtual ~editor_ctrl(){}
//populates the control with data from the model
virtual void set_data(PCS_Model &model)=0;
//applies the data in the control to the model
virtual void apply_data(PCS_Model &model)=0;
virtual void set_item(const std::vector<int>&coord)=0;
virtual std::vector<int> get_item()=0;
virtual omnipoints get_omnipoints()=0;
virtual void set_omnipoints(const omnipoints&points)=0;
virtual void get_omnipoint_coords(int&list, int&item)=0;
virtual void set_omnipoint_coords(int&list, int&item)=0;
virtual wxSizer* get_transform_options(wxWindow* parent)=0;
virtual void transform(const matrix& transform, const vector3d& translation)=0;
};
//this makes makeing the actual editors easier as is hides a
//bunch of common init stuff that is type specific
//the fact that the editor control is a template means we can't
//just use that in the base unless the base was a template
//but then we couldn't use the base as a pointer, and we'd lose functionality
//type- the data type this editor deals with
//editor_type- the editor you want to use,
// must be derived from editor_ctrl<type>
template<class type, class editor_type>
class model_editor_ctrl
:public model_editor_ctrl_base
{
protected:
editor_ctrl<type>*conrol_panel;
public:
void push_undo(){
conrol_panel->push_undo();
}
void undo(){
conrol_panel->undo();
}
void redo(){
conrol_panel->redo();
}
void fix_buttons(){
conrol_panel->fix_buttons();
}
void reset_undo(){
conrol_panel->reset_undo();
}
model_editor_ctrl(wxWindow*parent, PCS_Model &model, CHUNK Type)
:model_editor_ctrl_base(parent, Type),conrol_panel(NULL)
{
base_panel = conrol_panel = new editor_type(this);
if(conrol_panel){
conrol_panel->recalc_size();
conrol_panel->set_data(model);
wxBoxSizer*sizer = new wxBoxSizer(wxHORIZONTAL);
SetSizer(sizer);
sizer->Add(conrol_panel,1.0f);
sizer->Layout();
}
Ready = true;
}
//Special for sobj or anything that might need an additional int
model_editor_ctrl(wxWindow*parent, PCS_Model &model, CHUNK Type, int item)
:model_editor_ctrl_base(parent, Type),conrol_panel(NULL)
{
base_panel = conrol_panel = new editor_type(this, item);
conrol_panel->recalc_size();
conrol_panel->set_data(model);
if(conrol_panel){
wxBoxSizer*sizer = new wxBoxSizer(wxHORIZONTAL);
sizer->Add(conrol_panel,1.0f);
SetSizer(sizer);
sizer->Layout();
}
Ready = true;
// conrol_panel->SetSize(100,500);
}
//populates the control with data from the model
void set_data(PCS_Model &model){
conrol_panel->set_data(model);
}
//applies the data in the control to the model
void apply_data(PCS_Model &model){
conrol_panel->apply_data(model);
}
void set_item(const std::vector<int>&coord){
conrol_panel->set_item(coord);
}
virtual std::vector<int> get_item(){
return conrol_panel->get_item();
}
omnipoints get_omnipoints(){
return conrol_panel->get_omnipoints();
}
void set_omnipoints(const omnipoints&points){
conrol_panel->set_omnipoints(points);
}
virtual void get_omnipoint_coords(int&list, int&item){
conrol_panel->get_omnipoint_coords(list, item);
}
virtual void set_omnipoint_coords(int&list, int&item){
conrol_panel->set_omnipoint_coords(list, item);
}
virtual wxSizer* get_transform_options(wxWindow* parent) {
return conrol_panel->get_transform_options(parent);
}
virtual void transform(const matrix& transform, const vector3d& translation) {
conrol_panel->transform(transform, translation);
wxCommandEvent event(EDIT_DONE);
GetEventHandler()->ProcessEvent(event);
reset_undo();
}
};