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

35
LINES

< > TinyBrain | #1007284 - jcanvas + Canvas - 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);
    is.specialPurposed = true;
    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 2 computer(s): cfunsshuasjs, tvejysmllsmz

No comments. add comment

Snippet ID: #1007284
Snippet name: jcanvas + Canvas - calculated ImageSurface that adapts to window size
Eternal ID of this version: #1007284/17
Text MD5: e833571cc77d6706b31bbb0be2b87513
Author: stefan
Category: javax / gui
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2017-08-23 17:30:32
Source code size: 896 bytes / 35 lines
Pitched / IR pitched: No / No
Views / Downloads: 77 / 47
Version history: 16 change(s)
Referenced in: [show]