-
Notifications
You must be signed in to change notification settings - Fork 19
Expand file tree
/
Copy pathWindowThread.java
More file actions
98 lines (82 loc) · 1.95 KB
/
WindowThread.java
File metadata and controls
98 lines (82 loc) · 1.95 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
package lwjgui.scene;
import lwjgui.LWJGUI;
import lwjgui.Task;
public class WindowThread extends Thread {
private Window window;
private WindowHandle handle;
public WindowThread() {
this("Window");
}
public WindowThread(String title) {
this(100, 100, title);
}
public WindowThread(int width, int height, String title) {
this(width, height, title, false);
}
public WindowThread(int width, int height, String title, boolean legacyGL) {
handle = WindowManager.generateHandle(width, height, title, legacyGL);
handle.isVisible(false);
setupHandle(handle);
window = WindowManager.generateWindow(handle);
}
/**
* Called before window generation, allows for modifying GLFW window hints.
*
* @param handle The {@link WindowHandle} object used to create
*/
protected void setupHandle(WindowHandle handle) {
}
/**
* Called before thread loop. Use it to setup the UI.
*
* @param window
*/
protected void init(Window window) {
}
/**
* Called before {@link Window#render()}
*/
protected void update() {
}
/**
* Called before {@link Window#dispose()}. Use it to unload any OpenGL or NanoVG
* resources.
*/
protected void dispose() {
}
@Override
public void run() {
LWJGUI.setThreadWindow(window);
WindowManager.createWindow(handle, window, true);
init(window);
while (!window.isCloseRequested()) {
update();
window.render();
window.updateDisplay(0);
}
dispose();
window.dispose();
LWJGUI.removeThreadWindow();
}
/**
* Executes code at the beginning of the next frame.
*
* @param runnable
*/
public void runLater(Runnable runnable) {
window.runLater(runnable);
}
/**
* Submits a {@link Task} to be execute at the beginning of the next frame.
*
* @param <T> Return value
* @param t Task
* @return A {@link Task} with the specificed return value
*/
public <T> Task<T> submitTask(Task<T> t) {
return window.submitTask(t);
}
public Window getWindow() {
return window;
}
}