-
Notifications
You must be signed in to change notification settings - Fork 3
/
steps.pde
115 lines (98 loc) · 3.67 KB
/
steps.pde
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
// =============================================================================
// Globals, logic, and event handlers related to confirming, resetting, and
// recording sketch steps
// =============================================================================
import java.util.ArrayList;
// Manager =====================================================================
public class StepManager {
// Store string representation of info about each step
ArrayList<String> sketchSteps;
// References to manager objects for generating step strings
ChannelManager channelManager;
ShiftManager xShiftManager, yShiftManager;
ShiftTypeManager shiftTypeManager;
ImgManager imgManager;
public StepManager(ShiftManager xShiftManager, ShiftManager yShiftManager, ChannelManager channelManager, ShiftTypeManager shiftTypeManager, ImgManager imgManager) {
sketchSteps = new ArrayList<String>();
this.channelManager = channelManager;
this.xShiftManager = xShiftManager;
this.yShiftManager = yShiftManager;
this.shiftTypeManager = shiftTypeManager;
this.imgManager = imgManager;
}
public String stringifyStep() {
String step = "";
step += channelManager.stringifyStep();
step += xShiftManager.stringifyStep() + yShiftManager.stringifyStep();
step += shiftTypeManager.stringifyStep();
if (imgManager.recursiveIteration)
step += "-rec";
return step;
}
public void commitStep(String step) {
sketchSteps.add(step);
}
public void commitCurrentStep() {
commitStep(stringifyStep());
}
/**
* Returns true if source and target channels match and x/y shift are both 0
* and we're using the default shift type
*/
public boolean noChangesInCurrentStep() {
return channelManager.channelsMatch() && xShiftManager.shiftIsZero() && yShiftManager.shiftIsZero() && shiftTypeManager.isDefaultType();
}
/**
* Returns a string representation of the sketch steps so far. Each step is
* separated by an underscore
*
* @param includeCurrent If true, append the current step as well
* @return String representation of the sketch steps
*/
public String stepsToString(boolean includeCurrent) {
String steps = "";
if (sketchSteps.size() > 0)
steps += "_" + String.join("_", sketchSteps);
if (includeCurrent)
steps += "_" + stringifyStep();
return steps;
}
/**
* Returns a string representation of the sketch steps so far. Each step is
* separated by an underscore. If changes were made in the current step,
* append it to the resulting string
*
* @return String representation of the sketch steps
*/
public String stepsToString() { return stepsToString(!noChangesInCurrentStep()); }
public void resetSteps() { sketchSteps.clear(); }
}
// Event Handlers ==============================================================
// Reset Button ----------------------------------------------------------------
/**
* Reset selected source/target channels and horizontal/vertical shift values
* for current step
*/
void resetShift() {
channelManager.resetChannels();
updateChannelToggles();
xShiftManager.resetShift();
yShiftManager.resetShift();
updateShiftSliders();
}
public void resetBtn_click(GButton source, GEvent event) {
resetShift();
showPreview();
}
// Confirm Button --------------------------------------------------------------
public void confirmBtn_click(GButton source, GEvent event) {
// Display preview
showPreview();
// Update sketch steps
stepManager.commitCurrentStep();
// Confirm changes from previewImg and update sourceImg if the recursive
// iteration box is checked
imgManager.confirmStep();
// Reset shift values and UI
resetShift();
}