1 | sclass ImageSurfaceWithXMarkers extends ImageSurface { |
2 | new L<Float> markers; |
3 | Runnable onMarkersChanged; |
4 | |
5 | *(BufferedImage img, Collection<? extends Number> _markers) { |
6 | super(img); |
7 | addAll(this.markers, allToFloat(_markers)); |
8 | overlay = voidfunc(Graphics2D g) { |
9 | g.setColor(Color.red); |
10 | for (float x : markers) { |
11 | Pt p = pointToComponentCoordinates(x, 0); |
12 | g.drawLine(p.x, 0, p.x, getHeight()-1); |
13 | } |
14 | }; |
15 | disableImageSurfaceSelector(this); |
16 | imageSurfaceOnMouseDrag(this, new VF1<Pt> { |
17 | Float marker; |
18 | |
19 | public void get(Pt p) { |
20 | if (p == null) ret with marker = null; |
21 | Pt pComponent = pointToComponentCoordinates(p.x, p.y); |
22 | if (pointFarOutsideOfComponent(ImageSurfaceWithXMarkers.this, pComponent) || pointOutsideOfImage(image, p)) { |
23 | if (marker != null) { |
24 | markers.remove(marker); |
25 | fireMarkersChanged(); |
26 | _print("Markers: " + l(markers)); |
27 | } |
28 | ret with marker = null; |
29 | } |
30 | if (marker == null) |
31 | marker = floatCloseTo(markers, p.x, 2/zoomX); |
32 | Float m = marker; |
33 | marker = (float) p.x; |
34 | if (m == null) { |
35 | markers.add(marker); |
36 | _print("Markers: " + l(markers)); |
37 | } else |
38 | replaceElementOnce(markers, m, marker); |
39 | fireMarkersChanged(); |
40 | } |
41 | }); |
42 | } |
43 | |
44 | void fireMarkersChanged { |
45 | repaint(); |
46 | pcallF(onMarkersChanged); |
47 | } |
48 | } |
download show line numbers debug dex old transpilations
Travelled to 13 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, gwrvuhgaqvyk, irmadwmeruwu, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tvejysmllsmz, vouqrxazstgt
No comments. add comment
Snippet ID: | #1018714 |
Snippet name: | ImageSurfaceWithXMarkers |
Eternal ID of this version: | #1018714/25 |
Text MD5: | 9b3c4b4661847304091f7ef5ced00dfa |
Author: | stefan |
Category: | javax / gui |
Type: | JavaX fragment (include) |
Public (visible to everyone): | Yes |
Archived (hidden from active list): | No |
Created/modified: | 2018-10-14 12:35:26 |
Source code size: | 1511 bytes / 48 lines |
Pitched / IR pitched: | No / No |
Views / Downloads: | 355 / 935 |
Version history: | 24 change(s) |
Referenced in: | [show references] |