forked from scp-fs2open/PCS2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathop_stack.cpp
95 lines (83 loc) · 2.88 KB
/
op_stack.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
#include "pcs2.h"
#include "op_stack.h"
template<class type>
void op_stack<type>::push(const type&new_state){
if(operation.size()>0){
//if we already have this, there is no need to save it again
if(top > -1 && operation[top] == new_state)
return;
}
top++;
operation.resize(top+1);
(operation[top]) = new_state;
if(get_main_window()){
//this function always kills redo
get_main_window()->on_redo_enable(false);
//this function always enables undo
if(top>0)get_main_window()->on_undo_enable();
}
}
//+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
template<class type>
bool op_stack<type>::undo(type&state){
top--;
//pushed past the begining of the stack
if(top <= 0){
//if we are at the bottom of the stack there is nothing to undo so disable it
if(get_main_window())get_main_window()->on_undo_enable(false);
if(top<0)return false;
}
//this function always enables redo
if(get_main_window())get_main_window()->on_redo_enable();
state = (operation[top]);
return true;
}
//+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
template<class type>
bool op_stack<type>::redo(type&state){
if(top < (int)operation.size()-1){
top++;
if(top == (int)operation.size()-1){
//if we are at the top of the stack there is nothing to redo so disable it
if(get_main_window())get_main_window()->on_redo_enable(false);
}
//this function always enables undo
if(get_main_window())get_main_window()->on_undo_enable();
state = (operation[top]);
return true;
}
return false;
}
//+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
template<class type>
void op_stack<type>::fix_buttons(){
if(top > 0){
if(get_main_window())
get_main_window()->on_undo_enable();
}else{
if(get_main_window())
get_main_window()->on_undo_enable(false);
}
if(top > -1 && top < (int)operation.size()){
if(get_main_window())
get_main_window()->on_redo_enable();
}else{
if(get_main_window())
get_main_window()->on_redo_enable(false);
}
}
// Force the compiler to instantiate the template:
template class op_stack<class std::vector<struct pcs_shield_triangle> >;
template class op_stack<class std::vector<std::string> >;
template class op_stack<struct pcs_sobj>;
template class op_stack<class std::vector<struct pcs_path> >;
template class op_stack<class std::vector<struct pcs_turret> >;
template class op_stack<class std::vector<struct pcs_glow_array> >;
template class op_stack<class std::vector<struct pcs_thruster> >;
template class op_stack<class std::vector<struct pcs_eye_pos> >;
template class op_stack<class std::vector<struct pcs_special> >;
template class op_stack<class std::vector<struct pcs_dock_point> >;
template class op_stack<class std::vector<struct pcs_slot> >;
template class op_stack<class std::vector<struct pcs_insig> >;
template class op_stack<struct vector3d>;
template class op_stack<struct header_data>;