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

37
LINES

< > BotCompany Repo | #1007284 // jcanvas + Canvas - calculated ImageSurface that adapts to window size

JavaX fragment (include)

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

static Canvas jcanvas() { ret jcanvas(null, 0); }

// 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  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: 536 / 516
Version history: 18 change(s)
Referenced in: [show references]