Libraryless. Click here for Pure Java version (5803L/32K).
1 | srecord noeq VolatileImageMakerForComponent(Component component, int w, int h, Renderable renderable) {
|
2 | VolatileImage vImg; |
3 | long contentsLostCounter; |
4 | |
5 | event fireContentsLost; |
6 | |
7 | // rendering to the image |
8 | void renderOffscreen() {
|
9 | do {
|
10 | if (vImg.validate(component.getGraphicsConfiguration()) == |
11 | VolatileImage.IMAGE_INCOMPATIBLE) |
12 | // old vImg doesn't work with new GraphicsConfig; re-create it |
13 | vImg = component.createVolatileImage(w, h); |
14 | Graphics2D g = vImg.createGraphics(); |
15 | |
16 | renderable.renderOn(g, w, h); |
17 | |
18 | g.dispose(); |
19 | } while (contentsLost()); |
20 | } |
21 | |
22 | void paintOnScreen(Graphics2D gScreen) {
|
23 | do {
|
24 | if (vImg == null) vImg = component.createVolatileImage(w, h); |
25 | |
26 | int returnCode = vImg.validate(component.getGraphicsConfiguration()); |
27 | if (returnCode == VolatileImage.IMAGE_RESTORED) {
|
28 | // Contents need to be restored |
29 | renderOffscreen(); |
30 | } else if (returnCode == VolatileImage.IMAGE_INCOMPATIBLE) {
|
31 | // old vImg doesn't work with new GraphicsConfig; re-create it |
32 | vImg = component.createVolatileImage(w, h); |
33 | renderOffscreen(); |
34 | } |
35 | |
36 | gScreen.drawImage(vImg, 0, 0, component); |
37 | } while (contentsLost()); |
38 | } |
39 | |
40 | bool contentsLost() {
|
41 | if (!vImg.contentsLost()) false; |
42 | ++contentsLostCounter; |
43 | fireContentsLost(); |
44 | true; |
45 | } |
46 | |
47 | bool sizeIs(int w, int h) { ret this.w == w && this.h == h; }
|
48 | } |
download show line numbers debug dex old transpilations
Travelled to 3 computer(s): bhatertpkbcr, ekrmjmnbrukm, mqqgnosmbjvj
No comments. add comment
| Snippet ID: | #1033788 |
| Snippet name: | VolatileImageMakerForComponent |
| Eternal ID of this version: | #1033788/10 |
| Text MD5: | 6e4113eda989bafadac3edc728f22802 |
| Transpilation MD5: | 56d7d1568e8b2ea20b419166b0f16bcf |
| Author: | stefan |
| Category: | javax / gui |
| Type: | JavaX fragment (include) |
| Public (visible to everyone): | Yes |
| Archived (hidden from active list): | No |
| Created/modified: | 2022-02-05 22:46:29 |
| Source code size: | 1540 bytes / 48 lines |
| Pitched / IR pitched: | No / No |
| Views / Downloads: | 398 / 583 |
| Version history: | 9 change(s) |
| Referenced in: | [show references] |