' This software is one simple example for drag one object on the screen and drop it in another place.
 
DIM img(116) ' One array for save the screen back the object.

' Prepare the screen with one reticle for show the perfect movement of the object. 
SCREEN 12: COLOR 3 ' The screen is 640x480 MSDOS old system. Other screens can be prepare with _NEWIMAGE statement.
FOR vi% = 0 TO 479 STEP 10
    LINE (0, vi%)-(640, vi%)
NEXT vi%
FOR vi% = 0 TO 639 STEP 10
    LINE (vi%, 0)-(vi%, 479)
NEXT vi%

' First title for the program.
COLOR 10, 2
LOCATE 1, 1: PRINT ; "This is one simple example of drag-drop system."
LOCATE 2, 1: PRINT ; "Drag the purple circle and drop it into the black hole."

' Second title for me.
LOCATE 4, 1: PRINT ; "Program created by... Andrea MERCURIO!"
LOCATE 5, 1: PRINT ; "      http://esagon.orgfree.com       "

' Draw one black hole for drop inside the object.
CIRCLE (500, 50), 20, 7: PAINT (500, 50), 7, 7
CIRCLE (500, 50), 20, 0: PAINT (500, 50), 0, 0

' Create one object for drag it, the label is for begin all again, when drop it out the black hole.
begin: GET (36, 386)-(64, 414), img() ' Save the background back the object before.
CIRCLE (50, 400), 14, 5: PAINT (50, 400), 5, 5 ' Object created, is possible PUT one image array like the backgroung in this example, or use _PUTIMAGE too.

' First: wait the clik on the object for drag. 
DO
    GOSUB mousegetbott1xy ' Call the mouse informations about button1 x, y axis, see the subroutine at the end.
LOOP UNTIL bott1~` AND x% > 36 AND x% < 64 AND y% > 386 AND y% < 414 ' If button1 is positive on the object zone, go away.  
PUT (36, 386), img(), PSET ' Reset the screen back the object.

' Second: the core of the program, moving the object, loop appear-disappear. 
DO
    GET (x% - 14, y% - 14)-(x% + 14, y% + 14), img() ' Save the background before move the object in the new position.
    CIRCLE (x%, y%), 14, 5: PAINT (x%, y%), 5, 5 ' The object appear in the new position of the cursor.
    xp% = x%: yp% = y% ' Save the position. 
    repeat: GOSUB mousegetbott1xy ' Call the mouse informations of the next position.
    IF x% > 625 OR x% < 15 OR y% > 465 OR y% < 15 GOTO repeat ' If the mouse is out of screen the object no move. Need one border with margin of the screen more big of object, else the program go in crash.
    IF bott1~` AND xp% = x% AND yp% = y% GOTO repeat ' If the mouse no move, the appear-disappear of the object no need, but if the button is released exit from the sub-loop.
    PUT (xp% - 14, yp% - 14), img(), PSET ' Set the background empty in the old position, and the object disappear before, next in the loop, re-appear in the new position.
LOOP UNTIL bott1~` = 0 ' Button released exit loop.

' Third: control if the object is dropped in the correct position.
IF x% < 480 OR x% > 520 OR y% < 30 OR y% > 70 GOTO begin ' If the object not in the black hole area all re-work.
CIRCLE (500, 50), 14, 5: PAINT (500, 50), 5, 5 ' Else, if all go fine, the object in the black hole appear.

' End program.
LOCATE 15, 37: COLOR 10, 2: PRINT ; "Great!"
_DELAY 5 ' Five second for admire the opera.
SYSTEM ' Return to Windows.

' Mouse subroutine.
mousegetbott1xy: IF _MOUSEINPUT = 0 THEN RETURN ' Call mouse information, if no news return to loop.
bott1~` = _MOUSEBUTTON(1) ' Boolean variable for the button on-off.
x% = _MOUSEX: y% = _MOUSEY '  Integer for the x, y axis.
RETURN

