-
Notifications
You must be signed in to change notification settings - Fork 50
Expand file tree
/
Copy pathExample.java
More file actions
62 lines (52 loc) · 2.12 KB
/
Example.java
File metadata and controls
62 lines (52 loc) · 2.12 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
package io.github.humbleui.jwm.examples;
import io.github.humbleui.jwm.*;
import io.github.humbleui.jwm.skija.*;
import io.github.humbleui.skija.*;
import io.github.humbleui.types.*;
import java.util.*;
import java.util.function.*;
public class Example implements Consumer<Event> {
public Window window;
public Example() {
window = App.makeWindow();
window.setEventListener(this);
window.setTitle("Empty");
window.setLayer(new LayerGLSkija());
var screen = App.getPrimaryScreen();
var scale = screen.getScale();
var bounds = screen.getWorkArea();
window.setWindowSize((int) (300 * scale), (int) (600 * scale));
window.setWindowPosition((int) (300 * scale), (int) (200 * scale));
window.setVisible(true);
}
public void paint(Canvas canvas, int width, int height) {
float scale = window.getScreen().getScale();
canvas.clear(0xFF264653);
try (var paint = new Paint()) {
paint.setColor(0xFFe76f51);
canvas.drawRect(Rect.makeXYWH(10 * scale, 10 * scale, 10 * scale, 10 * scale), paint);
canvas.drawRect(Rect.makeXYWH(width - 20 * scale, 10 * scale, 10 * scale, 10 * scale), paint);
canvas.drawRect(Rect.makeXYWH(10 * scale, height - 20 * scale, 10 * scale, 10 * scale), paint);
canvas.drawRect(Rect.makeXYWH(width - 20 * scale, height - 20 * scale, 10 * scale, 10 * scale), paint);
canvas.drawRect(Rect.makeXYWH(width / 2 - 5 * scale, height / 2 - 5 * scale, 10 * scale, 10 * scale), paint);
}
}
@Override
public void accept(Event e) {
if (e instanceof EventWindowClose) {
if (App._windows.size() == 0)
App.terminate();
return;
} else if (e instanceof EventFrameSkija ee) {
Surface s = ee.getSurface();
paint(s.getCanvas(), s.getWidth(), s.getHeight());
} else if (e instanceof EventWindowCloseRequest) {
window.close();
}
}
public static void main(String[] args) {
App.start(() -> {
new Example();
});
}
}