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

54
LINES

< > BotCompany Repo | #1033812 // ImageSurface_HighlightRegion

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

Libraryless. Click here for Pure Java version (26510L/171K).

sclass ImageSurface_HighlightRegion > ImageSurfaceMouseHandler is G2Drawable {
  settable RegionPainter regionPainter = new RegionBoundingBoxPainter;
  FastRegions_BWImage regions;
  int iHighlightedRegion;
  Pt lastPt;
  
  *(ImageSurface is) {
    if (containsInstance(is.tools, getClass())) ret;
    register(is);
    is.overlays.add(this);
  }
  
  public void close :: after {
    is.overlays.remove(this);
  }

  public void mouseMoved aka mouseEntered(MouseEvent e) {
    lastPt = getPt(e);
    update();
  }
  
  public void mouseExited(MouseEvent e) {
    lastPt = null;
    update();
  }
  
  int newRegion() {
    if (lastPt == null || regions == null) ret 0;
    ret regions.regionAt(lastPt.x, lastPt.y);
  }
  
  void update {
    int r = newRegion();
    if (iHighlightedRegion != r) {
      iHighlightedRegion = r;
      is.repaint();
    }
  }
  
  void setRegions(FastRegions_BWImage regions) {
    this.regions = regions;
    iHighlightedRegion = -abs(iHighlightedRegion);
    update();
  }
  
  public void drawOn(Graphics2D g) {
    if (iHighlightedRegion == 0 || regionPainter == null) ret;
    regionPainter.zoomX(is.getZoomX());
    regionPainter.zoomY(is.getZoomY());
    regionPainter.g(g); afterwards { regionPainter.g(null); }
    regionPainter.regions(regions).iRegion(iHighlightedRegion);
    regionPainter.drawRegion();
  }
}

Author comment

Began life as a copy of #1033810

download  show line numbers  debug dex  old transpilations   

Travelled to 4 computer(s): bhatertpkbcr, ekrmjmnbrukm, mowyntqkapby, mqqgnosmbjvj

No comments. add comment

Snippet ID: #1033812
Snippet name: ImageSurface_HighlightRegion
Eternal ID of this version: #1033812/16
Text MD5: 40f2cea12e46b7f8869f6fe1a98aca3e
Transpilation MD5: bbc3aa2da515b06ce9fb038e327de07f
Author: stefan
Category: javax / gui
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2022-01-10 16:00:02
Source code size: 1408 bytes / 54 lines
Pitched / IR pitched: No / No
Views / Downloads: 163 / 292
Version history: 15 change(s)
Referenced in: #1033855 - RegionBoundingBoxPainter
#1034167 - Standard Classes + Interfaces (LIVE, continuation of #1003674)