• Aucun résultat trouvé

The final OBJECT command in Amiga BASIC is OBJECT.CLIP. It's sup posed to let you define rectangular zones within a screen window and keep ob

Dans le document in utilities, in (Page 126-131)

jects from appearing anywhere outside this zone. The format is

OBJECT.CLIP (xl,yl)-(x2,y2)

where (xl,yl) specify the upper left corner of the rectangle, and (x2,y2) specify the lower right corner (just like the LINES statement).

Unfortunately, OBJECT.CLIP doesn't seem to be implemented in Amiga BASIC 1.0. It doesn't cause an error if you use it—but it doesn't do anything, either. Nevertheless, in case it is implemented in a future revision of Amiga BASIC, we've written a short program that demonstrates its use. "OBJECT.CLIP Demo" is listed at the end of this chapter as Program 4-8.

Program 4-4. Object Datamaker

. *** OBJECT DATAMAKER ****

WINDOW 1,"Object Datamaker",(0,100)-(400,180),22*

WIDTH 38*

*

OpenData:*

'Read object data from disk...-4 CLS:PRINT*

PRINT "Enter filename of BOB or SPRITE:"*

LINE INPUT ">> ",filename?*

ON ERROR GOTO ErrorTrap*

OPEN filename? FOR INPUT AS 1*

object?=INPUT$(LOF(1),1)*

CLOSE 1*

ON ERROR GOTO 0*

*

MakeData:*

'Create new disk file of shape data.*

CLS:PRINT*

PRINT "Enter output filename for shape data:"*

LINE INPUT ">> ",filename2$*

IF filename2$=filename$ THEN*

msgl$="Output filename=input name..."*

msg2$="Replace existing object file?"*

CALL Requester (msgl$,msg2$,"REPLACE","CANCEL",2,answer%)*

IF answer%=0 GOTO MakeData*

END IF*

ON ERROR GOTO ErrorTrap*

OPEN filename2$ FOR OUTPUT AS 1*

PRINT:PRINT "Creating ";filename2$;"..."*

datalines=INT(LEN(object$)/8) 'DATA lines to make.*

remainder=LEN(object?)-datalines*8 'Final DATA line.*

PRINT* I,"1 ";filename2$;" ~";LEN(object?);"bytes."*

FOR n=l TO datalines*8 STEP 8*

PRINT# 1,"DATA ";*

FOR n=l TO remainder*

PRINT#1,USING"#*#";ASC(MID§(object?,(LEN(object?)-remainder)+l,1 IF n<remainder THEN PRINT#lf","; ELSE PRINT#1,""*

NEXT n*

CLOSE 1*

temp&=TIMER 'Wait for drive to finish...*

WHILE TIMER<temp&+6:WEND 'Wait 6 seconds.*

PRINT2PRINT "FINIS."*

ON ERROR GOTO 0*

*

'Allow chance to repeat process:*

msgl$="Create another data file"*

msg2$="or quit to BASIC?"*

CALL Requester (msgl$,msg2§,"REPEAT","QUIT",0,answer%)*

IF answer%=1 GOTO OpenData*

WINDOW 1,"Basic",(0,0)-(617,185)f31:END*

*

SUB Requester (msgl§#msg2$#bl$#b2§#hilite%#answer%) STATIC*

•Requester window subprogram *

SHARED scrid 'Global variable for SCREEN ID.*

IF scrid<l OR scrid>4 THEN scrid=-l 'Default to Workbench.*

WINDOW 3,"Program Request",(0,0)-(311,45),16,scrid*

maxwidth=INT(WINDOW(2)/8) 'Truncate prompts if too long...*

PRINT LEFT$(msgl?,maxwidth):PRINT LEFT$(msg2$,maxwidth)*

bl$=LEFT$(bl$,12):b2$=LEFT$(b2$,12) 'Truncate buttons.*

bsizel=(LEN(bl$)+2)*10:bsize2=(LEN(b2$)+2)*10 'Button size.*

xl=(312-(bsizel+bsize2))/3 'Calculate button positions...*

x2=xl+bsizel:x3=xl+x2:x4=x3+bsize2*

'Draw buttons:*

LINE (xl,20)-(x2,38),2,b:LINE (x3#20)-(x4,38),2,b*

IF hilite%=l THEN LINE (xl+2,22)-(x2-2,36),3,b*

IF hilite%=2 THEN LINE (x3+2,22)-(x4-2,36),3,b*

LOCATE 4,1:PRINT PTAB(xl+10);bl§;*

PRINT PTAB(x3+10);b2$*

reqloop: 'Loop which acts on mouse clicks...*

WHILE MOUSE(0)=0:WEND:ml=MOUSE(l):m2=MOUSE(2)*

IF ml>xl AND ml<x2 AND m2>20 AND m2<38 THEN*

answer%=l 'Left button was selected.*

LINE (xl,20)-(x2,38),l,bf 'Flash left button.*

ELSEIF ml>x3 AND ml<x4 AND m2>20 AND m2<38 THEN*

answer%=0 'Right button was selected.*

LINE (x3,20)-(x4,38),l,bf 'Flash right button.*

ELSE*

GOTO reqloop 'Neither button selected; repeat loop.*

END IF*

WHILE MOUSE(0)<>0:WEND:WINDOW CLOSE 3*

END SUB*

*

ErrorTrap:*

1 Version 1.5.-*

1 Traps common errors, mostly disk.-*

1 Requires Requester window subprogram.-*

BEEP ' Get user's attention.-*

IF ERR=53 THEN-*

requestl$="FILE NOT FOUND."-*

GOTO ExitError-*

END IF-*

IF ERR=61 THEN-*

requestl$="DISK FULL."-*

GOTO ExitError-*

END IF-*

IF ERR=64 THEN-*

requestl§="BAD FILENAME."-*

GOTO ExitError-*

END IF-*

IF ERR=67 THEN-*

requestl§="DIRECTORY FULL."-*

GOTO ExitError-*

END IF-*

IF ERR=68 THEN-*

requestl$="DEVICE UNAVAILABLE. "-*

GOTO ExitError-*

END IF-*

IF ERR=70 THEN-*

requestl$="DISK WRITE-PROTECTED. "-*

GOTO ExitError-*

END IF-*

IF ERR=74 THEN-*

request 1$="UNKNOWN DISK VOLUME."-*

GOTO ExitError-*

END IF-*

requestl$="ERROR NUMBER"+STR$ (ERR)-*

ExitError:-*

1 Abort operation or try again.-*

CALL Requester (request 1$ ,"", "Retry" , "CANCEL" , 2, answer%)-*

IF answer%=0 THEN-*

CLOSE 1-*

RESUME OpenData-*

ELSE-*

CLOSE 1-*

ON ERROR GOTO ErrorTrap-*

RESUME-*

END IF-*

Program 4-5. PlanePick

1 *** PlanePick & PlaneOnOff Utility ***-*

1 For designing colors of bobs.-*

4,

Initialize:-*

CLS:WIDTH 80: LOCATE 2#1-*

INPUT "Preferences set for 60 or 80";prefs-*

IF prefs<>60 AND prefs<>80 THEN Initialize-*

IF prefs=80 THEN posl=12 :pos2=19 :ELSE posl=ll :pos2=17-*

CLS:SCREEN 1,320,200,5,12maxcolors=32:WIDTH prefs/2«

scrn=l:CALL PanelSetup(scrn)*

DIM status(5):F0R n=l TO 5 : status (n) = l :NEXT: status (5 ) = 2-*

GOSUB NewScreen:GOSUB OpenBob-*

ON MENU GOSUB MenuHandler :MENU ON-*

ON BREAK GOSUB Quit:BREAK ON-*

GOTO MainLoop-*

-4

NewScreen:«

WINDOW 2,"PlanePick",(0,0)-(311,185),20,1-*

MENU 1,0,1, "Project11-*

MENU 1,1,1, "Open Bob "-*

MENU 1,2,1, "Change Palette "-*

MENU l,3,status(l)," SCREEN Depth 1"-*

MENU 1,4, status (2)," SCREEN Depth 2"-*

MENU 1,5, status(3)," SCREEN Depth 3"-*

MENU 1,6, status(4)," SCREEN Depth 4"-*

MENU 1,7, status(5)," SCREEN Depth 5"-*

MENU 1,8,1, "Quit to BASIC "-*

MENU 2,0,0,"":MENU 3, 0,0, " " :MENU 4,0,0,""-*

RETURN-*

«4

DrawButtons:*

xl=2:yl=100: x2=9 :y2=120-*

FOR n=l TO 2-*

FOR nn=0 TO maxcolors-1-4 LINE (xl,yl)-(x2,y2),l,b-*

xl=x2+2:x2=x2+9-*

NEXT nn-*

xl=2 :yl=160: xlimit=x2-9: x2=9: y2=180-*

NEXT n-*

RETURN-*

-4

MainLoop:*

LOCATE posl,l:PRINT "PlanePick = "; PlanePick-*

LINE ((PlanePick)*9+3,101)-((PlanePick)*9+8,119),l,bf-*

LOCATE pos2,l:PRINT "PlaneOnOff =" ;PlaneOnOf f-*

LINE ((PlaneOnOff) *9+3,161) - ((PlaneOnOff) *9+8,179), 1, bf-*

WHILE MOUSE(0)=0:WEND 'Wait here for mouse press.-*

mx=MOUSE (1) :my=MOUSE ( 2) <*

IF my>100 AND my<120 AND mx>2 AND mx<xlimit THEN-*

LINE ((PlanePick)*9+3,101)-((PlanePick)*9+8,119),0,bf«

PlanePick=INT( (mx-2)/9) 'Get new PlanePick value.-*

ELSEIF my>160 AND my<180 AND mx>2 AND mx<xlimit THEN-*

LINE ((PlaneOnOff) *9+3,161)-((PlaneOnOff)*9+8,179), 0,bf-*

PlaneOnOff=INT((mx-2)/9) 'Get new PlaneOnOff value.-4

END IF-*

WHILE MOUSE(0)<>0:WEND 'Wait here for mouse release.-*

OBJECT. PLANES 1, PlanePick, PlaneOnOff-4 GOTO MainLoop*

4,

MenuHandler:-4

MENU l,0,0 2item=MENU(l)-*

IF item=l THEN OBJECT.CLOSE lzGOSUB OpenBob-*

IF item=2 THEN CALL PalettePanel(scrn,prefs)-*

IF item>2 AND item<8 THEN GOSUB ChangeSCREEN-*

IF item=8 THEN Quit-4

MENU 1,0,1:MENU ON:GOTO MainLoop-*

«*

OpenBob:•*

•Loads bob file created with Object Editor.-*

CLS:WIDTH prefs/2-*

PRINT "Enter filename of bob to load:"-*

LINE INPUT ">> " ; filename?'*

IF filename$="" THEN OpenBob-*

OPEN filename? FOR INPUT AS #1-*

bob$=INPUT§ (LOF (1), 1) -*

CLOSE #1-*

CLS:GOSUB DrawButtons :GOSUB MakeShape-*

RETURN-*

<*

ChangeSCREEN:-*

'Changes SCREEN mode (depth of bit-planes).-*

OBJECT.CLOSE:WINDOW CLOSE 2:SCREEN CLOSE 1-*

SCREEN 1,320, 200, item-2,1 :maxcolors=2* (item-2) -*

FOR n=l TO 5:status(n)=l:status(item-2)=2: NEXT-*

GOSUB NewScreen*

FOR n=0 TO WIND0W(6) 'Restore previous PALETTE values...-*

PALETTE n,hue(n,0) ,hue(n, 1) ,hue(n, 2)-*

NEXT n-*

GOSUB MakeShape: GOSUB DrawButtons-*

RETURN-*

•*

Quit:-*

'It's polite to clean up after ourselves...-*

OBJECT.CLOSE:WINDOW CLOSE 2-*

OBJECT. PLANES 1, PlanePick, PlaneOnOf f-*

OBJECT.X 1,140:OBJECT.Y 1,10 :OBJECT.ON-*

RETURN-*

SUB PanelSetup (screenwindow) STATIC-*

'See "Designing A User. Interface" chapter for info.-*

PanelSetup :•*

IF screenwindow<l OR screenwindow>4 THEN screenwindow=-l-*

WINDOW 2,,,,screenwindow*

DIM SHARED hue (31,2) ' Holds current PALETTE values.-*

DIM SHARED newhue(31,2) ' Holds new PALETTE values.-*

'Define default colors here (you can insert your own values):-*

hue(0,0)=0:hue(0,l)=.46:hue(0,2)=0 'Color 0-*

hue(l,0) = .9:hue(l,l) = .9:hue(l,2)=.9 'Color 1-*

hue(2,0)=0:hue(2,l)=0:hue(2,2)=0 'Color 2-*

hue(3,0)=.91:hue(3,l)=.48:hue(3,2)=.15 'Color 3-*

FOR n=4 TO 31 'We'll use random colors for the rest.-*

FOR nn=0 TO 2-*

hue (n, nn) =RND-*

NEXT nn-*

NEXT n-*

FOR n=0 TO 31 'Copy current colors into temp array.-*

newhue(n,0)=hue(n,0)<*

newhue(n,l)=hue(n,l):newhue(n,2)=hue(n,2)-*

NEXT n-*

FOR n=0 TO WINDOW(6) ' Change PALETTE values.-*

PALETTE n,hue(n,0),hue(n,l),hue(n,2)-*

SUB PalettePanel (screenwindow,preferences) STATIC-*

•See "Designing A User Interface" chapter for info.-*

PalettePanel:-*

IF screenwindow<l OR screenwindow>4 THEN screenwindow=-l-*

WINDOW 3, "Palette Panel" , (0,0)-(311,185), 16,screenwindow-*

WIDTH 80-*

colr=0 '■ Current PALETTE color selected on panel.-*

r=hue(colr,0) 'RED value for current color.-*

g=hue(colr,l) 'GREEN value for current color.-*

b=hue(colr,2) 'BLUE value for current color.-*

mx=0:my=0 'Clear mouse coordinates.-*

FOR n=0 TO 3 'Draw color panel...-*

FOR nn=0 TO 7-*

IF n*8+nn<WIND0W(6)+l THEN 'Fill color box on panel:-*

LINE (nn*39+l,n*20)-(nn*39+38,n*20+20),n*8+nn,bf«*

END IF-*

LINE (nn*39+l,n*20)-(nn*39+38,n*20+20),l,b 'Draw frame.-*

NEXT nn-*

NEXT n-*

FOR n=100 TO 140 STEP 20 'Draw color controls...-*

LINE (l,n)-(310,n+10),2,b-*

NEXT n<*

'Draw exit buttons:-*

IF preferences=80 THEN y=22 ELSE y=20-*

LOCATE y,5:PRINT "USE";: LOCATE y,y:PRINT "CANCEL";-*

LINE (l,160)-(156,184),l,b:LINE (156 ,160)-( 310,184), 1, b-*

SubMainLoop: •*

IF my>160 THEN btn=INT(mx/153 ) .-GOTO ExitPanel-*

IF mx>2 AND mx<309 AND my>100 THEN 'Clicked on a slider.-*

IF my<110 THEN 'Clicked on RED slider.-*

LINE (r*300+2,101)-(r*300+9,109),0,bf 'Erase RED slider.-*

r=(mx-2)/307 'Calculate new position of RED slider.-*

newhue(coir,0)=r 'New RED color value.-*

ELSEIF my>120 AND my< 130 THEN 'Clicked on GREEN slider.-*

LINE (g*300+2,121)-(g*300+9,129),0,bf 'Erase GREEN slider.-*

Dans le document in utilities, in (Page 126-131)