Libraryless. Click here for Pure Java version (16792L/104K).
1 | sclass ImageSurfaceDragger extends ImageSurfaceMouseHandler { |
2 | sbool debug = true; |
3 | Point start, startScroll; |
4 | int dx, dy; |
5 | |
6 | *() {} |
7 | *(ImageSurface is) { |
8 | if (containsInstance(is.tools, ImageSurfaceDragger)) ret; |
9 | this.register(is); |
10 | } |
11 | |
12 | public void mousePressed(MouseEvent e) { |
13 | JScrollPane sp = enclosingScrollPane(is); |
14 | if (sp == null) ret; |
15 | if (e.getButton() == MouseEvent.BUTTON1) { |
16 | start = e.getLocationOnScreen(); |
17 | startScroll = new Point( |
18 | scrollBarValue(sp.getHorizontalScrollBar()), |
19 | scrollBarValue(sp.getVerticalScrollBar())); |
20 | } |
21 | } |
22 | |
23 | public void mouseDragged(MouseEvent e) { |
24 | if (start == null) ret; |
25 | JScrollPane sp = enclosingScrollPane(is); |
26 | if (sp == null) ret; |
27 | Point p = e.getLocationOnScreen(); |
28 | //if (debug) print("ImageSurfaceDragger: drag " + p.x + "/" + p.y); |
29 | setScrollBarValue(sp.getHorizontalScrollBar(), -(p.x-start.x)+startScroll.x); |
30 | setScrollBarValue(sp.getVerticalScrollBar(), -(p.y-start.y)+startScroll.y); |
31 | } |
32 | |
33 | public void mouseReleased(MouseEvent e) { |
34 | mouseDragged(e); |
35 | start = null; |
36 | } |
37 | } |
download show line numbers debug dex old transpilations
Travelled to 13 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, gwrvuhgaqvyk, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tslmcundralx, tvejysmllsmz, vouqrxazstgt
No comments. add comment
Snippet ID: | #1008773 |
Snippet name: | ImageSurfaceDragger - scrolls by dragging |
Eternal ID of this version: | #1008773/23 |
Text MD5: | 1a66c7513256b0efb7a9187e7af3e600 |
Transpilation MD5: | b365b4772f11188009f414160ad29994 |
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:23 |
Source code size: | 1140 bytes / 37 lines |
Pitched / IR pitched: | No / No |
Views / Downloads: | 577 / 1295 |
Version history: | 22 change(s) |
Referenced in: | [show references] |