slDraggable - Forum

Forum Navigation
You need to log in to create posts and topics.

slDraggable

Hi All,

 

I  am using slDraggable feature and  I would like to detect when an object is over a rectangle to trigger actions.

My first tought was to use something as :
GetObjectInfo "Object1" "left" [left]
GetObjectInfo "Object1" "top" [top]

and then use a chain of "If" to know when the object is over the rectangle.  But it is complex to manage.
Is there a simplier way to do this ?

Very best,

Hi @otc66, current slDraggable is very basic and doesn't have a Drop system yet.
We want to add a complete "drag and drop" plugin solution, but as far as I know right now there is not a simpler way.
Sorry!

OTC66 has reacted to this post.
OTC66

Hi All,

 

Thks Luis for the answer. So, I have created a code stored in the "click" :

 

GetObjectInfo "Object1" "top" [position]
.To get the position  of the object.  The result is  XXXpx.

 

StrCopy "[position]" 0 3 [position2]
.I care only when the object is bellow 100px so I extract the 3 digits to remove the suffix px.  I don't care if position is X.px - XX.px or XXXXpx.

 

SetVar [position3] [position2]
.I convert it as a numeric

.then I can  trigger the action
If [position3] > 99
AlertBox "Information" "Alert ! " ""
endif

 

It works fine. Is there a simplier way ?

@OTC66:

Is there a simplier way ?

Try this ...

GetObjectInfo "Object1" "top" [position]

StrReplace "[position]" "px" "" [posStr] ""
ToNumber "[posStr]" [posNum]
Math "[posNum]*1" 0 [posNum]
..AlertBox "posNum" "[posNum]" ""

If [posNum] > 99
   AlertBox "Information" "Alert ! " ""
Endif

Notes:

1) I used StrReplace to get rid of "px" because, contrary to what the command wizard for ToNumber says, it does not ignore non-numeric characters ... results in NaN

2) I used the Math command to get rid of any fractional values (sometimes I have seen results like "56.789px")

Thks Gaev!

It is much cleaner like this !

@OTC66:

So, I have created a code stored in the "click"

I am not sure if you meant "click" but if you place the code in the "mouse up" event of Object1, it will get triggered every time your user completes the drag operation (a.k.a "drop" event).

I would like to detect when an object is over a rectangle to trigger actions

Did you mean "while the object is being dragged" or "upon completion" ?

use a chain of "If" to know when the object is over the rectangle. But it is complex to manage.

Many moons ago, I had done a subroutine/call in NeoBook to determine if there was overlap between two objects; if there is of benefit to the community at large, I can take a stab at it.

However, note that slDraggable has optional parameters to constrain the user from dragging outside specified limits.