-
Notifications
You must be signed in to change notification settings - Fork 0
/
SketchTransformer.pde
167 lines (139 loc) · 3.75 KB
/
SketchTransformer.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
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
public class SketchTransformer implements java.io.Serializable
{
private float xOffset;
private float yOffset;
private float scaleFactor;
private float mouseXPosition;
private float mouseYPosition;
private PGraphics graphicContext;
private boolean isAnimating;
private boolean dragging = false;
public SketchTransformer(float xOffset, float yOffset, float scaleFactor, PGraphics pg)
{
this.xOffset = xOffset;
this.yOffset = yOffset;
this.scaleFactor = scaleFactor;
this.graphicContext = pg;
isAnimating = false;
}
public SketchTransformer(float xOffset, float yOffset, float scaleFactor)
{
this.xOffset = xOffset;
this.yOffset = yOffset;
this.scaleFactor = scaleFactor;
this.graphicContext = g;
isAnimating = false;
}
public SketchTransformer()
{
this.xOffset = 0;
this.yOffset = 0;
this.scaleFactor = 0;
this.graphicContext = g;
isAnimating = false;
}
public void setXOffset(float offset)
{
this.xOffset = offset;
}
public float getXOffset()
{
return this.xOffset;
}
public void setYOffset(float offset)
{
this.yOffset = offset;
}
public float getYOffset()
{
return this.yOffset;
}
public void setScaleFactor(float factor)
{
this.scaleFactor = factor;
}
public float getScaleFactor()
{
return this.scaleFactor;
}
public void setGraphicContext(PGraphics pg)
{
this.graphicContext = pg;
}
public PGraphics getGraphicContext()
{
return this.graphicContext;
}
public PVector convertCoordinates(float x, float y)
{
PVector translatedPoint = new PVector((x - xOffset) / scaleFactor, (y - yOffset) / scaleFactor);
return translatedPoint;
}
public void setTraslationOffsets(float xOffset, float yOffset)
{
this.xOffset = xOffset;
this.yOffset = yOffset;
}
public void saveMousePosition(float mouseXPos, float mouseYPos)
{
this.mouseXPosition = mouseXPos;
this.mouseYPosition = mouseYPos;
dragging = true;
}
public void updateTranslationOffset(float mouseXPos, float mouseYPos)
{
if(dragging)
{
this.xOffset -= this.mouseXPosition - mouseXPos;
this.yOffset -= this.mouseYPosition - mouseYPos;
this.mouseXPosition = mouseXPos;
this.mouseYPosition = mouseYPos;
}
}
public void resetMousePosition()
{
dragging = false;
/* maybe resetting the mouse position too would not be bad */
}
public void startDrawing(float additionalXOffset, float additionalYOffset, float additionalScaling)
{
graphicContext.pushMatrix();
graphicContext.translate(xOffset + additionalXOffset, yOffset + additionalYOffset);
graphicContext.scale(scaleFactor + additionalScaling);
}
public void startDrawing()
{
this.startDrawing(0, 0, 0);
}
public void endDrawing()
{
graphicContext.popMatrix();
}
public void centerSketch()
{
xOffset = yOffset = 0;
}
// FIXME
public void centerSketch(float drawAreaWidth, float voidDrawAreaWidth,
float drawAreaHeight, float voidDrawAreaHeight,
float patternWidth, float patternHeight)
{
xOffset = ((drawAreaWidth - voidDrawAreaWidth)/2 - (patternWidth/2)*scaleFactor);///scaleFactor;
yOffset = ((drawAreaHeight - voidDrawAreaHeight)/2 - (patternHeight/2)*scaleFactor);///scaleFactor;
}
private void animateCentering()
{
// if (isAnimating)
// {
// xOffset *= deltaX;
// println("X: " + traX + " Y: " + traY);
// if (abs(traX - width/2) < thresholdFloat && abs(traY - height*3/4) < thresholdFloat)
// {
// println("stop animation");
// isAnimating = false;
// traX = width/2;
// traY = height*3/4;
// }
// }
}
}