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

30
LINES

< > BotCompany Repo | #1018716 // imageSurfaceOnMouseDrag

JavaX fragment (include)

// combines mousePressed, mouseDragged and mouseReleased
// left button only
// f : voidfunc(Pt) - point can be null, then mouse was released
static void imageSurfaceOnMouseDrag(final ImageSurface is, final O f) {
  swing {
    MouseAdapter ma = new MouseAdapter {
      bool in;
      
      public void mouseDragged(MouseEvent e) {
        if (!in) ret;
        pcallF(f, is.pointFromEvent(e));
      }
      
      public void mousePressed(MouseEvent e) {
        if (e.getButton() != MouseEvent.BUTTON1) ret;
        in = true;
        pcallF(f, is.pointFromEvent(e));
      }
  
      public void mouseReleased(MouseEvent e) {
        if (e.getButton() != MouseEvent.BUTTON1) ret;
        if (!in) ret;
        in = false;
        pcallF(f, (Pt) null);
      }
    };
    is.addMouseMotionListener(ma);
    is.addMouseListener(ma);
  }
}

Author comment

Began life as a copy of #1005948

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: #1018716
Snippet name: imageSurfaceOnMouseDrag
Eternal ID of this version: #1018716/1
Text MD5: 6a39a1d6935c20291c117686ec4012a8
Author: stefan
Category: javax / gui
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2018-10-11 20:50:01
Source code size: 871 bytes / 30 lines
Pitched / IR pitched: No / No
Views / Downloads: 194 / 225
Referenced in: [show references]