Not logged in.  Login/Logout/Register | List snippets | | Create snippet | Upload image | Upload data

37
LINES

< > BotCompany Repo | #1008773 // ImageSurfaceDragger - scrolls by dragging

JavaX fragment (include) [tags: use-pretranspiled]

Libraryless. Click here for Pure Java version (16792L/104K).

sclass ImageSurfaceDragger extends ImageSurfaceMouseHandler {
  sbool debug = true;
  Point start, startScroll;
  int dx, dy;

  *() {}
  *(ImageSurface is) {
    if (containsInstance(is.tools, ImageSurfaceDragger)) ret;
    this.register(is);
  }

  public void mousePressed(MouseEvent e) {
    JScrollPane sp = enclosingScrollPane(is);
    if (sp == null) ret;
    if (e.getButton() == MouseEvent.BUTTON1) {
      start = e.getLocationOnScreen();
      startScroll = new Point(
        scrollBarValue(sp.getHorizontalScrollBar()),
        scrollBarValue(sp.getVerticalScrollBar()));
    }
  }

  public void mouseDragged(MouseEvent e) {
    if (start == null) ret;
    JScrollPane sp = enclosingScrollPane(is);
    if (sp == null) ret;
    Point p = e.getLocationOnScreen();
    //if (debug) print("ImageSurfaceDragger: drag " + p.x + "/" + p.y);
    setScrollBarValue(sp.getHorizontalScrollBar(), -(p.x-start.x)+startScroll.x);
    setScrollBarValue(sp.getVerticalScrollBar(), -(p.y-start.y)+startScroll.y);
  }

  public void mouseReleased(MouseEvent e) {
    mouseDragged(e);
    start = null;
  }
}

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: 576 / 1293
Version history: 22 change(s)
Referenced in: #1033810 - ImageSurface_PositionToolTip
#1034167 - Standard Classes + Interfaces (LIVE, continuation of #1003674)