B4J Question Smooth dragging

ThRuST

Well-Known Member
Licensed User
Longtime User
In what sub do you usually store the mouse x,y position to init dragging of an object to allow smooth calculated dragging of objects? (in this case an image)

since this is not triggered when dragging begins. Is there a MouseDraggedBegins event or how you solve that?

B4X:
public Sub xIcon_MouseClicked (EventData As MouseEvent)
   
    'fx.Msgbox(Main.MainForm, "Clicked!!", "")
    StoreClickPosX = currentMouseX
    StoreClickPosY = currentMouseY
   
    Log("Position stored")
   
End Sub
 

Cableguy

Expert
Licensed User
Longtime User
In the EventData you will find all you need!
the mouse event will tell you if is is a down, a move or an up event, along with the screen coordinates.
 
Upvote 0

ThRuST

Well-Known Member
Licensed User
Longtime User
@Cableguy I was assuming that the initial storage of the x,ypostion should be done in one of the below events, but perhaps another event should be used.

B4X:
_MouseClicked (EventData As MouseEvent)

B4X:
_MousePressed (EventData As MouseEvent)

B4X:
_MouseDragged (EventData As MouseEvent)
 
Upvote 0

ThRuST

Well-Known Member
Licensed User
Longtime User
-Storing x and y is used to avoid the glitch and "jump" of the object at the beginning of dragging that is. This is usually done is the MouseClick event in C sharp, but my old method didn't work in B4J. Thereby my question.
 
Upvote 0

ThRuST

Well-Known Member
Licensed User
Longtime User
upload_2018-11-20_0-24-52.png
 
Upvote 0

Alexander Stolte

Expert
Licensed User
Longtime User
Smooth dragging:
B4X:
Private Sub xpnl_test_Touch(Action As Int, X As Float, Y As Float) As Boolean
       If Action = xpnl_test.TOUCH_ACTION_DOWN Then
   
            donwx  = X
            downy  = y
   
        Else if Action = xpnl_test.TOUCH_ACTION_MOVE Then
   
            xpnl_test.Top = xpnl_test.Top + y - downy
            xpnl_test.Left = xpnl_test.Left + x - donwx
   
        End If
  
    Return True
End Sub
I use this code in my AS MsgBox Class.
 
Upvote 0
Top