-
Notifications
You must be signed in to change notification settings - Fork 51
Expand file tree
/
Copy pathIViewportStack.java
More file actions
206 lines (178 loc) · 5.46 KB
/
IViewportStack.java
File metadata and controls
206 lines (178 loc) · 5.46 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
package com.cleanroommc.modularui.api.layout;
import com.cleanroommc.modularui.screen.viewport.TransformationMatrix;
import com.cleanroommc.modularui.utils.Vector3f;
import com.cleanroommc.modularui.widget.sizer.Area;
import org.jetbrains.annotations.Nullable;
/**
* This handles all viewports in a GUI. Also keeps track of a matrix stack used for rendering and
* user interaction.
*/
public interface IViewportStack {
/**
* Reset all viewports and the matrix stack.
*/
void reset();
/**
* @return current viewport
*/
Area getViewport();
/**
* Pushes a viewport to the top. Also pushes a new matrix.
*
* @param viewport viewport to push
* @param area area of the viewport
*/
void pushViewport(IViewport viewport, Area area);
/**
* Only pushes a matrix without a viewport.
*/
void pushMatrix();
/**
* Removes the top viewport and its matrix from the stack.
*
* @param viewport viewport to remove from the top.
* @throws IllegalStateException if the given viewport doesn't match the viewport at the top.
*/
void popViewport(IViewport viewport);
/**
* Removes the top matrix from the stack.
*
* @throws IllegalStateException if the top matrix is a viewport.
*/
void popMatrix();
/**
* @return the matrix stack size
*/
int getStackSize();
/**
* Removes all matrices ABOVE the given index.
*
* @param index matrices are removed above this index.
*/
void popUntilIndex(int index);
/**
* Removes all matrices ABOVE the given viewport.
*
* @param viewport matrices are removed above this viewport.
*/
void popUntilViewport(IViewport viewport);
/**
* Applies translation transformation to the current top matrix.
*
* @param x translation in x
* @param y translation in y
*/
void translate(float x, float y);
/**
* Applies translation transformation to the current top matrix.
*
* @param x translation in x
* @param y translation in y
* @param z translation in z
*/
void translate(float x, float y, float z);
/**
* Applies rotation transformation to the current top matrix.
*
* @param angle clockwise rotation angle in radians
* @param x x-axis rotation. 1 for yes, 0 for no
* @param y y-axis rotation. 1 for yes, 0 for no
* @param z z-axis rotation. 1 for yes, 0 for no
*/
void rotate(float angle, float x, float y, float z);
/**
* Applies rotation transformation to the current top matrix around z.
*
* @param angle clockwise rotation angle in radians
*/
void rotateZ(float angle);
/**
* Applies scaling transformation to the current top matrix around.
*
* @param x x scale factor
* @param y y scale factor
*/
void scale(float x, float y);
/**
* Resets the top matrix to the matrix below.
*/
void resetCurrent();
/**
* Transforms the x component of a position withe current matrix transformations.
*
* @param x x component of position
* @param y y component of position
* @return transformed x component
*/
int transformX(float x, float y);
/**
* Transforms the y component of a position withe current matrix transformations.
*
* @param x x component of position
* @param y y component of position
* @return transformed y component
*/
int transformY(float x, float y);
/**
* Transforms the x component of a position with the current inverted matrix transformations.
*
* @param x x component of position
* @param y y component of position
* @return un-transformed x component
*/
int unTransformX(float x, float y);
/**
* Transforms the y component of a position with the current inverted matrix transformations.
*
* @param x x component of position
* @param y y component of position
* @return un-transformed y component
*/
int unTransformY(float x, float y);
/**
* Transforms a vector with the current matrix transformations.
* This modifies the given vector.
*
* @param vec vector to transform
* @return transformed vector
*/
default Vector3f transform(Vector3f vec) {
return transform(vec, vec);
}
/**
* Transforms a vector with the current matrix transformations.
*
* @param vec vector to transform
* @param dest vector to write the result to
* @return transformed vector
*/
Vector3f transform(Vector3f vec, Vector3f dest);
/**
* Transforms a vector with the current inverted matrix transformations.
* This modifies the given vector.
*
* @param vec vector to un-transform
* @return un-transformed vector
*/
default Vector3f unTransform(Vector3f vec) {
return unTransform(vec, vec);
}
/**
* Transforms a vector with the current inverted matrix transformations.
* This modifies the given vector.
*
* @param vec vector to un-transform
* @param dest vector to write the result to
* @return un-transformed vector
*/
Vector3f unTransform(Vector3f vec, Vector3f dest);
/**
* Applies the current matrix transformations the current OpenGL matrix.
*/
void applyToOpenGl();
/**
* @return the top matrix or null if stack is empty
*/
@Nullable
TransformationMatrix peek();
}