forked from bsondermann/BlackboxSticksExporter3D
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathIFPGraphicsState.pde
113 lines (89 loc) · 2.51 KB
/
IFPGraphicsState.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
import processing.core.*;
class IFPGraphicsState {
int smooth;
int rectMode, ellipseMode;
PFont textFont;
int textAlign;
float textSize;
int textMode;
boolean tint;
int tintColor;
boolean fill;
int fillColor;
boolean stroke;
int strokeColor;
float strokeWeight;
int cMode;
float cModeX, cModeY, cModeZ, cModeA;
IFPGraphicsState() {
}
/**
* Convenience contstructor saves the applet's graphics state into
* the newly created IFPGraphicsState object.
*
* @param applet the PApplet instance whose state we're saving
*/
IFPGraphicsState(PApplet applet) {
saveSettingsForApplet(applet);
}
/**
* saves the graphics state for the specified PApplet
*
* @param applet the PApplet instance whose state we're saving
*/
void saveSettingsForApplet(PApplet applet) {
smooth = applet.g.smooth;
rectMode = applet.g.rectMode;
ellipseMode = applet.g.ellipseMode;
textFont = applet.g.textFont;
textAlign = applet.g.textAlign;
textSize = applet.g.textSize;
textMode = applet.g.textMode;
tint = applet.g.tint;
fill = applet.g.fill;
stroke = applet.g.stroke;
tintColor = applet.g.tintColor;
fillColor = applet.g.fillColor;
strokeColor = applet.g.strokeColor;
strokeWeight = applet.g.strokeWeight;
cMode = applet.g.colorMode;
cModeX = applet.g.colorModeX;
cModeY = applet.g.colorModeY;
cModeZ = applet.g.colorModeZ;
cModeA = applet.g.colorModeA;
}
/**
* restores the saved graphics state to the specified PApplet
*
* @param applet the PApplet instance whose state we're restoring
*/
void restoreSettingsToApplet(PApplet applet)
{
try {
if (smooth > 0) {
applet.smooth();
} else {
applet.noSmooth();
}
} catch (RuntimeException e) {
// Can't smooth in P3D, throws exception
}
applet.rectMode(rectMode);
applet.ellipseMode(ellipseMode);
if(textFont != null){
applet.textFont(textFont);
applet.textSize(textSize);
}
applet.textAlign(textAlign);
applet.textMode(textMode);
// ***** I THINK YOU CAN SET A COLOR FOR A PROPERTY THAT'S NOT ENABLED *****
if(tint) applet.tint(tintColor);
else applet.noTint();
if(fill) applet.fill(fillColor);
else applet.noFill();
if(stroke) applet.stroke(strokeColor);
else applet.noStroke();
applet.strokeWeight(strokeWeight);
applet.colorMode(cMode, cModeX, cModeY, cModeZ, cModeA);
}
}