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

37
LINES

< > BotCompany Repo | #1005839 // showImageWithSelections

JavaX fragment (include) [tags: use-pretranspiled]

Libraryless. Click here for Pure Java version (13493L/83K).

static ImageSurface showImageWithSelections(MakesBufferedImage img, final Cl<Rect> rects) {
  ret showImageWithSelections(img.getBufferedImage(), rects);
}

static ImageSurface showImageWithSelections(S title, BufferedImage img, Cl<Rect> rects) {
  ret frameTitle(title, showImageWithSelections(img, rects));
}

static ImageSurface showImageWithSelections(BufferedImage img, Cl<Rect> rects) {
  ret showImageWithSelections(img, null, rects);
}

static ImageSurface showImageWithSelections(BufferedImage img, Rect... rects) {
  ret showImageWithSelections(img, asList(rects));
}

// for callers to use
static Var<Rect> showImageWithSelections_highlighted;

static ImageSurface showImageWithSelections(BufferedImage img, ImageSurface _is, Cl<Rect> _rects) {
  final ImageSurface is = showImage(img, _is);
  final L<Rect> rects = sortRectsBySize(_rects);
  final new Var<Rect> highlighted;
  showImageWithSelections_highlighted = highlighted;
  is.overlay = voidfunc(Graphics2D g) {
    for (Rect r : rects)
      is.drawSelectionRect(g, r.getRectangle(), Color.blue, Color.white);
    if (highlighted.has())
      fillRect(g, scaleRect(highlighted!, is.getZoomX(), is.getZoomY()), new Color(0, 0, 0, 0x30)); // semi-transparent black
  };
  imageSurfaceOnMouseMove(is, voidfunc(Pt p) {
    repaintIf(is, setVarIfNeq(highlighted, smallestRectContaining(rects, p)));
  });
  
  is.repaint();
  ret is;
}

download  show line numbers  debug dex  old transpilations   

Travelled to 14 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, gwrvuhgaqvyk, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, sawdedvomwva, tslmcundralx, tvejysmllsmz, vouqrxazstgt

No comments. add comment

Snippet ID: #1005839
Snippet name: showImageWithSelections
Eternal ID of this version: #1005839/13
Text MD5: 3fb0b28183915e00af147e817ee308a3
Transpilation MD5: e2d98787a7ab594c3603f99599439301
Author: stefan
Category: javax / imaging / gui
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2021-09-09 19:00:49
Source code size: 1435 bytes / 37 lines
Pitched / IR pitched: No / No
Views / Downloads: 524 / 560
Version history: 12 change(s)
Referenced in: [show references]