1 | sclass Canvas extends ImageSurface { |
2 | O makeImg; |
3 | bool updating; |
4 | |
5 | *() { zoomable = false; } |
6 | *(O makeImg) { this(); this.makeImg = makeImg; } |
7 | |
8 | void update() { updateCanvas(this, makeImg); } |
9 | } |
10 | |
11 | static Canvas jcanvas() { ret jcanvas(null, 0); } |
12 | |
13 | // f: (int w, int h) -> BufferedImage |
14 | static Canvas jcanvas(O f) { |
15 | ret jcanvas(f, 0); // 100 |
16 | } |
17 | |
18 | static Canvas jcanvas(fO f, final int updateDelay) { |
19 | ret (Canvas) swing(func { |
20 | final Canvas is = new Canvas(f); |
21 | is.specialPurposed = true; |
22 | final Runnable update = new Runnable { |
23 | bool first = true; |
24 | public void run { |
25 | BufferedImage img = is.getImage(); |
26 | int w = is.getWidth(), h = is.getHeight(); |
27 | if (first || img.getWidth() != w || img.getHeight() != h) { |
28 | updateCanvas(is, f); |
29 | first = false; |
30 | } |
31 | } |
32 | }; |
33 | onResize(is, r { awtLater(is, updateDelay, update) }); |
34 | bindToComponent(is, update); // first update |
35 | ret is; |
36 | }); |
37 | } |
Began life as a copy of #1007280
download show line numbers debug dex old transpilations
Travelled to 13 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, gwrvuhgaqvyk, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tslmcundralx, tvejysmllsmz, vouqrxazstgt
No comments. add comment
Snippet ID: | #1007284 |
Snippet name: | jcanvas + Canvas - calculated ImageSurface that adapts to window size |
Eternal ID of this version: | #1007284/19 |
Text MD5: | c0c81434080337c45a7c514ab49f207f |
Author: | stefan |
Category: | javax / gui |
Type: | JavaX fragment (include) |
Public (visible to everyone): | Yes |
Archived (hidden from active list): | No |
Created/modified: | 2017-10-15 17:07:23 |
Source code size: | 1000 bytes / 37 lines |
Pitched / IR pitched: | No / No |
Views / Downloads: | 610 / 596 |
Version history: | 18 change(s) |
Referenced in: | [show references] |