Libraryless. Click here for Pure Java version (19927L/123K).
sclass ImageSurfaceSelector extends ImageSurfaceMouseHandler {
Point startingPoint;
bool enabled = true;
static bool verbose = false;
*() {}
*(ImageSurface is) {
if (containsInstance(is.tools, ImageSurfaceSelector)) ret;
this.register(is);
}
public void mousePressed(MouseEvent evt) {
if (verbose) print("mousePressed");
if (evt.getButton() != MouseEvent.BUTTON1) return;
if (enabled)
startingPoint = getPoint(evt);
}
public void mouseDragged(MouseEvent e) {
if (verbose) print("mouseDragged");
if (startingPoint != null) {
Point endPoint = getPoint(e);
Rectangle r = new Rectangle(startingPoint, new Dimension(endPoint.x-startingPoint.x+1, endPoint.y-startingPoint.y+1));
normalize(r);
r.width = min(r.width, is.getImage().getWidth()-r.x);
r.height = min(r.height, is.getImage().getHeight()-r.y);
is.setSelection(r);
}
if (verbose) print("mouseDragged done");
}
public static void normalize(Rectangle r) {
if (r.width < 0) {
r.x += r.width;
r.width = -r.width;
}
if (r.height < 0) {
r.y += r.height;
r.height = -r.height;
}
}
public void mouseReleased(MouseEvent e) {
if (verbose) print("mouseReleased");
mouseDragged(e);
if (getPoint(e).equals(startingPoint))
is.setSelection((Rectangle) null);
startingPoint = null;
}
}download show line numbers debug dex old transpilations
Travelled to 19 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, ddnzoavkxhuk, gwrvuhgaqvyk, ishqpsrjomds, jtubtzbbkimh, lpdgvwnxivlt, mqqgnosmbjvj, onxytkatvevr, ppjhyzlbdabe, pyentgdyhuwx, pzhvpgtvlbxg, sawdedvomwva, tslmcundralx, tvejysmllsmz, vouqrxazstgt, xrpafgyirdlv
No comments. add comment
| Snippet ID: | #1005517 |
| Snippet name: | ImageSurfaceSelector - provide rectangular selection by mouse to ImageSurface |
| Eternal ID of this version: | #1005517/9 |
| Text MD5: | 49351ddcebf4951997d6403b239f27c6 |
| Transpilation MD5: | 510bd6a86d5ef546af9039075cc9cb63 |
| Author: | stefan |
| Category: | javax / gui |
| Type: | JavaX fragment (include) |
| Public (visible to everyone): | Yes |
| Archived (hidden from active list): | No |
| Created/modified: | 2022-02-15 22:29:01 |
| Source code size: | 1444 bytes / 50 lines |
| Pitched / IR pitched: | No / No |
| Views / Downloads: | 1090 / 6564 |
| Version history: | 8 change(s) |
| Referenced in: | [show references] |