Libraryless. Click here for Pure Java version (16961L/106K).
sclass ImageSurfaceScribbleTool extends ImageSurfaceMouseHandler { settable BasicStroke stroke = new BasicStroke(5); settable Color color = Color.black; settable bool enabled; Pt lastPt; event painted; event scribbleDone(Scribble scribble); Scribble scribble; *() {} *(ImageSurface is) { this.register(is); } public void mousePressed(MouseEvent evt) { if (evt.getButton() != MouseEvent.BUTTON1) ret; if (!enabled) ret; lastPt = getPt(evt); scribble = new Scribble(color, stroke.getLineWidth(), new L); drawPoint(lastPt); } public void mouseReleased(MouseEvent e) { mouseDragged(e); lastPt = null; scribbleDone(scribble); scribble = null; } public void mouseDragged(MouseEvent e) { if (lastPt == null) ret; Pt p = getPt(e); if (!eq(p, lastPt)) drawLine(lastPt, p); lastPt = p; is.repaint(); // That's gonna be slow... } void drawPoint(Pt p) { drawLine(p, p); } void drawLine(Pt a, Pt b) { scribble?.addPoint(b); Graphics2D g = getImageSurface().getImage().createGraphics(); g.setStroke(stroke); g.setColor(color); g.drawLine(a.x, a.y, b.x, b.y); g.dispose(); painted(); } }
Began life as a copy of #1005517
download show line numbers debug dex old transpilations
Travelled to 4 computer(s): bhatertpkbcr, ekrmjmnbrukm, mowyntqkapby, mqqgnosmbjvj
No comments. add comment
Snippet ID: | #1034389 |
Snippet name: | ImageSurfaceScribbleTool |
Eternal ID of this version: | #1034389/16 |
Text MD5: | d3b52a9fe34458bad66eb578caa09533 |
Transpilation MD5: | d8088786d26cb54f3fc7f07c3fdcbf45 |
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:28:45 |
Source code size: | 1269 bytes / 51 lines |
Pitched / IR pitched: | No / No |
Views / Downloads: | 192 / 342 |
Version history: | 15 change(s) |
Referenced in: | #1003674 - Standard Classes + Interfaces (LIVE continued in #1034167) |