100 REMark ***** drag and drop routine with a drag-pointer(sprite) made
110 REMark ***** out of the text of the menu item
120 REMark ***** routine by W. Uhlig, Mkspr-function by Per Witte
130 :
140 REMark ***** Create a window with 2 application windows and one "ESC" loose item
150 REMark ***** and save it as "win1_mymenu_men"
160 :
170 OPEN #3,con
180 xlim = SCR_XLIM(#3): ylim = SCR_YLIM(#3)
190 llen = SCR_LLEN(#3): base = SCR_BASE(#3)
200 pw = llen / xlim: REMark Bytes per pixel (1 or 2)
210 :
220 DIM names1$(20,13)
230 FOR i%=0 TO 20:names1$(i%)="anyname"&i%
240 DIM names2$(20,13):REMark ***** remains empty for the moment
250 :
260 MDRAW #3,'win1_mymenu_men'
270 MAWDRAW #3,1,names1$
280 MAWDRAW #3,2,names2$
290 DIM result%(16):REMark ***** array for the PVAL routine
300 :
310 wwd = MWDEF(#3): REMark Window Working Definition
320 cia = PEEK_L(wwd) + $38: REMark -> current item metrics
330 :
340 drag%=0:buffer$="":REMark ***** variables for the d&d routine
350 :
360 REMark ***** start of main program loop *********************
370 REPeat main
380 key=MCALL(#3,key,0)
390 PVAL #3,result%
400 SELect ON key
410 =-1:MCLEAR #3:CLOSE #3:STOP
420 =REMAINDER:
430 IF result%(5)=1
440 REMark ***** when left mouse click
450 awnum=key
460 position=MAWNUM(#3,awnum)-1
470 DRAG_DROP
480 END IF
490 END SELect
500 END REPeat main
510 REMark ***** end of main program loop **********************
520 :
530 DEFine PROCedure DRAG_DROP
540 IF drag%
550 IF MTEXT$(#3,key)<>""
560 NEXT main
570 ELSE
580 IF awnum=1
590 names1$(position)=buffer$
600 ELSE
610 names2$(position)=buffer$
620 END IF
630 MAWITEM #3,key,,buffer$
640 buffer$=""
650 drag%=NOT(drag%)
660 SPRS #3,0
670 RECHP sprity : REMark forget previous sprite
680 END IF
690 ELSE
700 IF MTEXT$(#3,key)<>""
710 IF awnum=1
720 buffer$=names1$(position)
730 names1$(position)=""
740 ELSE
750 buffer$=names2$(position)
760 names2$(position)=""
770 END IF
780 MAWITEM #3,key,,""
790 drag%=NOT(drag%)
800 sprity=MkSpr(PEEK_W(cia + 0), PEEK_W(cia + 2), PEEK_W(cia + 4), PEEK_W(cia + 6))
810 SPRS #3,sprity
820 ELSE
830 NEXT main
840 END IF
850 END IF
860 END DEFine DRAG_DROP
870 :
880 DEFine FuNction MkSpr(xs, ys, xo, yo)
890 LOCal i, a, s, t, pixw
900 :
910 pixw = xs * pw
920 s = base + yo * llen + xo * pw
930 a = ALCHP(24 + (pixw + xs) * ys)
940 POKE_L a, $2200020 : REMark Mode 32 sprite with alpha channel
950 POKE_W a + 4, xs: POKE_W a + 6, ys: REMark Create sprite header
960 POKE_W a + 8, xs DIV 2 : REMark Centre sprite
970 POKE_W a + 10, ys DIV 2
980 POKE_L a + 12, 12
990 POKE_L a + 16, 8 + pixw * ys
1000 POKE_L a + 20, 0
1010 t = a + 24 : REMark Target address for sprite data
1020 REMark ***** Now create sprite, line at a time
1030 FOR i = 1 TO ys
1040 POKE$ t, PEEK$(s, pixw)
1050 s = s + llen
1060 t = t + pixw
1070 END FOR i
1080 REMark ***** Create mask (ghost)
1090 FOR i = t TO t + xs * ys
1100 POKE i, 184
1110 END FOR i
1120 RETurn a
1130 END DEFine MkSpr