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).

1  
sclass ImageSurface_HighlightRegion > ImageSurfaceMouseHandler is G2Drawable {
2  
  settable RegionPainter regionPainter = new RegionBoundingBoxPainter;
3  
  FastRegions_BWImage regions;
4  
  int iHighlightedRegion;
5  
  Pt lastPt;
6  
  
7  
  *(ImageSurface is) {
8  
    if (containsInstance(is.tools, getClass())) ret;
9  
    register(is);
10  
    is.overlays.add(this);
11  
  }
12  
  
13  
  public void close :: after {
14  
    is.overlays.remove(this);
15  
  }
16  
17  
  public void mouseMoved aka mouseEntered(MouseEvent e) {
18  
    lastPt = getPt(e);
19  
    update();
20  
  }
21  
  
22  
  public void mouseExited(MouseEvent e) {
23  
    lastPt = null;
24  
    update();
25  
  }
26  
  
27  
  int newRegion() {
28  
    if (lastPt == null || regions == null) ret 0;
29  
    ret regions.regionAt(lastPt.x, lastPt.y);
30  
  }
31  
  
32  
  void update {
33  
    int r = newRegion();
34  
    if (iHighlightedRegion != r) {
35  
      iHighlightedRegion = r;
36  
      is.repaint();
37  
    }
38  
  }
39  
  
40  
  void setRegions(FastRegions_BWImage regions) {
41  
    this.regions = regions;
42  
    iHighlightedRegion = -abs(iHighlightedRegion);
43  
    update();
44  
  }
45  
  
46  
  public void drawOn(Graphics2D g) {
47  
    if (iHighlightedRegion == 0 || regionPainter == null) ret;
48  
    regionPainter.zoomX(is.getZoomX());
49  
    regionPainter.zoomY(is.getZoomY());
50  
    regionPainter.g(g); afterwards { regionPainter.g(null); }
51  
    regionPainter.regions(regions).iRegion(iHighlightedRegion);
52  
    regionPainter.drawRegion();
53  
  }
54  
}

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: 162 / 290
Version history: 15 change(s)
Referenced in: [show references]