DECLARE SUB DRAWit ()
DECLARE SUB UpdateCorner (X%, Y%)
REM $INCLUDE: 'future.bi'

Set640x400 8

DIM SHARED sprite%(9000), handle%
DIM SHARED X1%, Y1%, X2%, Y2%, X3%, Y3%, U1%, V1%, U2%, V2%, U3%, V3%
handle% = AllExpMem%(640 * 400&)
DefineEMSbufferSize handle%, 640, 400, 0

Future.LOADGIF "image.gif", 0, 0

Future.Get 0, 0, 127, 127, sprite%()
U1% = 0: V1% = 0
U2% = 0: V2% = 127
U3% = 127: V3% = 127

X1% = 150: Y1% = 40
X2% = 127: Y2% = 300
X3% = 500: Y3% = 340

SetEMSPage 0
DRAWit

Future.MouseOn
DO

SetEMSPage 0
IF (Future.MouseB AND 1) = 1 THEN
        UpdateCorner U1%, V1%
        UpdateCorner U2%, V2%
        UpdateCorner U3%, V3%
        UpdateCorner X1%, Y1%
        UpdateCorner X2%, Y2%
        UpdateCorner X3%, Y3%
END IF

Future.Updatemouse
SetPage 0
Future.EMSput 0, 0, handle%
LOOP UNTIL INKEY$ = CHR$(27)

Resetscreen
DeallExpMem handle%

SUB DRAWit
Future.CLS 0
Future.Put 0, 0, sprite%()
Future.FILLBOX U1% - 1, V1% - 1, U1% + 1, V1% + 1, 255
Future.FILLBOX U2% - 1, V2% - 1, U2% + 1, V2% + 1, 255
Future.FILLBOX U3% - 1, V3% - 1, U3% + 1, V3% + 1, 255
Future.line U1%, V1%, U2%, V2%, 255, &HAAAA
Future.line U2%, V2%, U3%, V3%, 255, &HAAAA
Future.line U3%, V3%, U1%, V1%, 255, &HAAAA
Future.line X1%, Y1%, X2%, Y2%, 255, &HAAAA
Future.line X2%, Y2%, X3%, Y3%, 255, &HAAAA
Future.line X3%, Y3%, X1%, Y1%, 255, &HAAAA
Future.TRITEXT X1%, Y1%, X2%, Y2%, X3%, Y3%, U1%, V1%, U2%, V2%, U3%, V3%, sprite%()
Future.FILLBOX X1% - 1, Y1% - 1, X1% + 1, Y1% + 1, 255
Future.FILLBOX X2% - 1, Y2% - 1, X2% + 1, Y2% + 1, 255
Future.FILLBOX X3% - 1, Y3% - 1, X3% + 1, Y3% + 1, 255
END SUB

SUB UpdateCorner (X%, Y%)

IF Future.MouseX < (X% + 2) AND Future.MouseX > (X% - 2) THEN
      IF Future.MouseY < (Y% + 2) AND Future.MouseY > (Y% - 2) THEN
        DO
          IF X% <> Future.MouseX OR Y% <> Future.MouseY THEN
           X% = Future.MouseX: Y% = Future.MouseY
           SetEMSPage 0
           Future.MouseOff
           DRAWit
           Future.MouseOn
           SetPage 0
           Future.EMSput 0, 0, handle%
          END IF
        LOOP UNTIL (Future.MouseB AND 1) = 0
     
      END IF
    END IF

END SUB

