home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
AMOS PD CD
/
amospdcd.iso
/
501-525
/
apd511
/
fontreq.amos
/
fontreq.amosSourceCode
Wrap
AMOS Source Code
|
1991-01-18
|
8KB
|
267 lines
'--------------------------------------------------------------------
' FontReq
'
' A Font Requester.
'
' * Has a show area (like DPaint III), and a drag bar (Top area)
' * Specify number of fonts displayed.
' * XY addressable, easy auto-centering.
' * Works with a four colour screen, or greater. (it aint pretty)
' * Works in Hires or Lowres.
' * Saves background & callers palette (has its own fixed palette)
'
' Look inside SELECTFONT for parameter details.
'
' Robert Farnsworth
' 1 Vidovic Ave, Mildura, 3500
' Jan. 91.
'-------------------------------------------------------------------
'
Screen Open 0,640,256,16,Hires
Curs Off : Flash Off
Reserve Zone 6
'
Global SELECTEDFONT
' --- Default font - Topaz 8
SELECTEDFONT=2
'
INITFONTS
Do
Draw 0,0 To 640,256 : Draw 0,256 To 640,0
SELECTFONT[0,0,0,SELECTEDFONT,8]
Set Font SELECTEDFONT
'
Print At(0,0);Font$(SELECTEDFONT)
Ink 2,1
Text 0,Screen Height/2,Font$(SELECTEDFONT)
Loop
End
'
'---------------- Font Requester routines -------------
'
Procedure INITFONTS
' --- Read the fonts.
Shared LASTNAME
' --- Load the fonts
Get Fonts
' how many fonts?
F=1
While Font$(F)<>""
Inc F
Wend
LASTNAME=F-1
End Proc
'
Procedure SELECTFONT[X,Y,SCR,OLDFONT,LINES]
'
' Font requester.
'
' Requires at least a 4 colour screen.
' INITFONTS must be called first.
'
' X,Y Coords of top left corner. If zero, requester is centered.
' SCR Screen number for the requester, pops this screen to front.
' OLDFONT The number of the font that is being used prior to calling
' this routine.
' LINES The number of text lines for displaying font names, mimimum
' of four.
' RETURNS: SELECTEDFONT (Global) with the number of the font that is
' chosen. See comments near the end of this routine
' for alternative approach.
'
Shared LASTNAME,SELECTEDFONT
'
Screen SCR
Screen To Front SCR
Set Font 2 : Rem Topaz 8
Set Text 0
' --- Setup our own palette
Dim P(4)
For C=0 To 3 : P(C)=Colour(C) : Next
Palette ,,$DDD,$0
' --- You may need to change this ---
Reset Zone
Reserve Zone 6
'
LINES=Max(4,LINES)
WIDTH=240 : HEIGHT=62+LINES*8
' --- Centre requester if X or Y are zero
If X=0 Then X=Screen Width/2-WIDTH/2
If Y=0 Then Y=Screen Height/2-HEIGHT/2
X1=X : X2=X1+WIDTH : Y1=Y : Y2=Y1+HEIGHT
' --- save background ---
Get Block 1,X1,Y1,WIDTH/16*16+16,HEIGHT+1
'------------ Draw the body ---------
Ink 2
Bar X1,Y1 To X2,Y2
Ink 3
Box X1+2,Y1+1 To X2-2,Y2-1
'--- font name area
WX1=X1+7 : WY1=Y1+12 : WX2=X2-7 : WY2=WY1+LINES*8
Box WX1,WY1 To WX2,WY2+2
Set Zone 5,WX1,WY1+1 To WX2,WY2+1
'--- show area
SY1=WY2+4 : SY2=SY1+30
Box WX1,SY1 To WX2,SY2
Ink 3,2
Text X1+75,Y1+10,"Select a Font"
Set Zone 6,X1,Y1 To X2,WY1
' --- Draw buttons
Z=1 : F=2 : B=3
S#=(WX2-WX1)/3.9
BUTTON[WX1+4,SY2+10," OK ",Z,F,B] : Inc Z
BUTTON[WX1+S#*1,SY2+10,"BACK",Z,F,B] : Inc Z
BUTTON[WX1+S#*2,SY2+10,"NEXT",Z,F,B] : Inc Z
BUTTON[WX1+S#*3,SY2+10,"CANCEL",Z,F,B] : Inc Z
' -----------------------------------
P=1
PAGE[P,LASTNAME,LINES,WX1,WY1,WX2,WY2]
SELECTEDFONT=0
Ink 3,2 : HILITE=-1
' --- Main loop
Repeat
If Mouse Click=1 Then BUTTON=Mouse Zone
' in font name area ?
While Mouse Zone=5
' --- calc which font name
Y=(Y Screen(Y Mouse)-WY1-2)/8
' --- font selected ?
If Mouse Click=1
' --- Undo last hilite
If HILITE>-1
PRTFONT[WX1+1,WY1,P,HILITE]
HILITE=-1
End If
' --- Hilite & Show selected font
If P+Y<=LASTNAME
' --- Hilite font name
Gr Writing 4+1
PRTFONT[WX1+1,WY1,P,Y]
Gr Writing 1
HILITE=Y : Rem --- set flag
' --- Set & display font
SELECTEDFONT=P+Y
Set Font SELECTEDFONT
Ink 2
Bar WX1+1,SY1+1 To WX2-1,SY2-1
Clip WX1=1,SY1+1 To WX2-1,SY2
Ink 3,2
Text WX1+1,SY2-2,"AaBbCcDdy"
Clip 0,0 To Screen Width,Screen Height
Set Font 2
BUTTON=0
End If
End If
Wend
Set Font 2
' --- BACK ---
If BUTTON=2
If P-LINES>0
P=P-LINES
Else
P=1
End If
PAGE[P,LASTNAME,LINES,WX1,WY1,WX2,WY2]
BUTTON=0
End If
' --- NEXT ---
If BUTTON=3
If P+LINES<=LASTNAME
P=P+LINES
PAGE[P,LASTNAME,LINES,WX1,WY1,WX2,WY2]
BUTTON=0
End If
End If
' --- Move requester ---
If BUTTON=6
' --- Get req image
Get Block 2,X1,Y1,WIDTH,HEIGHT+1
MX=X Screen(X Mouse) : MY=Y Screen(Y Mouse)
MXO=MX-X1 : MYO=MY-Y1
Limit Mouse X Hard(MXO),Y Hard(MYO) To X Hard(Screen Width-(WIDTH-MXO)),Y Hard(Screen Height-(HEIGHT-MYO)-1)
Gr Writing 2 : Rem XOR
While Mouse Key=1
Box MX-MXO,MY-MYO To MX-MXO+WIDTH,MY-MYO+HEIGHT
OLDX=MX : OLDY=MY
While OLDX=X Screen(X Mouse) and OLDY=Y Screen(Y Mouse) : Wend
MX=X Screen(X Mouse) : MY=Y Screen(Y Mouse)
Box OLDX-MXO,OLDY-MYO To OLDX-MXO+WIDTH,OLDY-MYO+HEIGHT
Wend
Gr Writing 1
Limit Mouse X Hard(0),Y Hard(0) To X Hard(Screen Width),Y Hard(Screen Height)
' --- Restore bg at present location
Put Block 1
' --- Save bg at new location
Get Block 1,MX-MXO,MY-MYO,WIDTH,HEIGHT+1
' --- Put Req at new location
Put Block 2,MX-MXO,MY-MYO
Del Block 2
' --- Re-calc var's & zones ---
X=MX-MXO : Y=MY-MYO
X1=X : X2=X1+WIDTH : Y1=Y : Y2=Y1+HEIGHT
WX1=X1+7 : WY1=Y1+12 : WX2=X2-7 : WY2=WY1+LINES*8
SY1=WY2+4 : SY2=SY1+30
Set Zone 5,WX1,WY1+1 To WX2,WY2+1
Set Zone 6,X1,Y1 To X2,WY1
S#=(WX2-WX1)/3.9 : Z=1
BUTTON[WX1+4,SY2+10," OK ",Z,F,B] : Inc Z
BUTTON[WX1+S#*1,SY2+10,"BACK",Z,F,B] : Inc Z
BUTTON[WX1+S#*2,SY2+10,"NEXT",Z,F,B] : Inc Z
BUTTON[WX1+S#*3,SY2+10,"CANCEL",Z,F,B] : Inc Z
Ink 3,2
BUTTON=0
End If
Until BUTTON=1 or BUTTON=4
' --- Finaly, set the selected font. ---
'
' (Remove the Rem's from the two lines below if
' you want to Set the font in this routine, otherwise
' use the global variable SELECTEDFONT - this contains
' the font number that has just been chosen.)
'
If BUTTON=1 and SELECTEDFONT>0
' --- OK. Set selected font here if you want.
' Set Font SELECTEDFONT
Else
' --- CANCEL. Restore the font that was being used.
' Set Font oldfont
SELECTEDFONT=OLDFONT
End If
' --- Restore background
Put Block 1
Del Block 1
' --- restore palette
For C=0 To 3 : Colour C,P(C) : Next
End Proc
'
Procedure PAGE[P,LAST,LINES,X1,Y1,X2,Y2]
'--- Print a page of font names
Ink 2
Bar X1+1,Y1+1 To X2-1,Y2+1
Ink 3,2
For I=0 To LINES-1
If P+I<=LAST
PRTFONT[X1+1,Y1,P,I]
End If
Next
End Proc
'
Procedure PRTFONT[X,Y,PG,I]
'--- Print one font name
F$=Left$(Font$(PG+I),Instr(Font$(PG+I),".font")-1)
F$=F$+String$(" ",22-Len(F$))+Mid$(Font$(PG+I),30,6)
Text X,Y+(I*8)+8,F$
End Proc
'
Procedure BUTTON[X,Y,A$,Z,FG,BG]
X1=X-2 : Y1=Y-8 : X2=X1+Len(A$)*8+2 : Y2=Y+2
Ink BG
Bar X1+1,Y1+2 To X2+3,Y2+1
Ink BG,BG,FG
Set Paint 1
Bar X1-1,Y1 To X2+1,Y2
Set Paint 0
Ink FG,BG
Text X,Y,A$
Set Zone Z,X1,Y1 To X2,Y2
End Proc