Not logged in.  Login/Logout/Register | List snippets | | Create snippet | Upload image | Upload data

34
LINES

< > TinyBrain | #1007284 - jcanvas - calculated ImageSurface that adapts to window size

JavaX fragment (include)

sclass Canvas extends ImageSurface {
  O makeImg;
  bool updating;
  
  *() {}
  *(O *makeImg) {}
  
  void update() { updateCanvas(this, makeImg); }
}

// f: (int w, int h) -> BufferedImage
static Canvas jcanvas(O f) {
  ret jcanvas(f, 0); // 100
}

static Canvas jcanvas(fO f, final int updateDelay) {
  ret (Canvas) swing(func {
    final Canvas is = new Canvas(f);
    final Runnable update = new Runnable {
      bool first = true;
      public void run {
        BufferedImage img = is.getImage();
        int w = is.getWidth(), h = is.getHeight();
        if (first || img.getWidth() != w || img.getHeight() != h) {
          updateCanvas(is, f);
          first = false;
        }
      }
    };
    onResize(is, r { awtLater(is, updateDelay, update) });
    bindToComponent(is, update); // first update
    ret is;
  });
}

Author comment

Began life as a copy of #1007280

download  show line numbers  debug dex   

Travelled to 1 computer(s): tvejysmllsmz

No comments. add comment

Snippet ID: #1007284
Snippet name: jcanvas - calculated ImageSurface that adapts to window size
Eternal ID of this version: #1007284/15
Text MD5: 762a9288a61e0037311b69d6e02d01d6
Author: stefan
Category: javax / gui
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2017-03-18 17:50:21
Source code size: 864 bytes / 34 lines
Pitched / IR pitched: No / No
Views / Downloads: 30 / 1
Version history: 14 change(s)
Referenced in: [show]