! Int_

Post Reply
User avatar
Dutchman
Posts: 151
Joined: Tue Aug 06, 2019 4:47 pm
Location: Netherlands

! Int_

Post by Dutchman » Tue Nov 19, 2019 10:09 pm

! Int_ {/Extensions/Interface/! Int_}
Functions to set Buttons and Signs from a list of parameters.
Two interface objects are included as default: button 'Bnext' ' and sign 'Scaption', 'Bnext' is a button in the lower right corner and 'Scaption' is a sign at the bottom of the display.

Code: Select all

' {/Extensions/Interface/! Int_}
[ Set interface objects via list of parameters ]
'
IF NOT Int_.Set THEN CALL Int_ ' initialise
[–––––––––––––––––––– Test program –––––––––––––––––––––––––
'--- show parms
Int_.test=1
CALL Int_
'--- set Id's
NextButt=Int_.Bnext(0)
Caption=Int_.Scapt(0)
'--- activate  caption
CALL Int_Sign(Int_.Scapt,Int_.ScaptCol)
'--- activate button
WaitForNext
'--- finish
INBUTT DELETE NextButt
INSIGN TEXT Caption "Done"
END ' testprogram –––––––––]
'
[–––––––––––– Container for  Parameters –––––––––––––––––––––
Int_   container for parameters
Default position x,y and size width,height will be calculated
parameterId's  0    1       2       3      4   5     6       7
Parm$()=     ("Id","Text","Font$","Fsize","X","Y","Width","Height")
Bnext()=     ( BnextId,  "Next","Arial", 20,   0,0,0,0)
BnextCol()=  (1,1,0,1,  0,0,1,1) 'Fcolor, Bcolor (r,g,b,A)
Scapt()=     (ScaptionId,"Caption","Arial",20,  0,0,0,0)
ScaptCol()=  (0,0,1,1  0,0,0,0) 'Fcolor  Bcolor (r,g,b,A)
––– 
END container ]
'
[–––––––––––––––––––––––– Functions ––––––––––––––––––––––––
Int_ColFB((Bg,C()) ' renamed copy of Col_FB() in ../Graphics/! Col_ utils
return colour from colour parameters 'C()'
if Bg=1 then Background color else Fontcolor
___
WaitForNext
keep waiting until button "Next" is touched
–––
Int_Sign(p(),C())
set sign field with parameters p() and colors c()
local variable 'Align' is default 3 and can be changed
–––
Int_Butt(P(),C())
set button with parameters P() and colors C()
–––
Int_Parms(P(),C())
Print parameters P() en colours C()
––––
End of function description –––––––––––]
'
[–––––––––––––––––––––– Implementation ––––––––––––––––––––––]
DEF Int_
'Container for parameters
'Position x,y and size width,height will be calculated
IF Set THEN Update ' defaults changed
'parameterId's 0    1       2       3      4   5     6       7
DIM Parm$()=(     "Id",   "Text","Font$","Fsize","X","Y","Width","Height")
DIM Bnext()=(INBUTT INDEX, "Next","Arial", 20,   0,0,0,0)
DIM BnextCol()=(1,1,0,1,  0,0,1,1) 'Fcolor, Bcolor
DIM Scapt()=(INSIGN INDEX,"Caption","Arial",20,  0,0,0,0)
DIM ScaptCol()=(0,0,1,1  0,0,0,0) 'Fcolor & Bcolor (r,g,b,A)
Update: 
sw,sh=SCRSIZE|2
GOSUB SetSize
GOSUB SetXY
IF test
  PRINT "sw sh =";sw;sh : PRINT
  PRINT """Bnext"" parameters:"
  CALL Int_Parms(Bnext,BnextCol) : PRINT
  PRINT """Scapt"" parameters:"
  CALL Int_Parms(Scapt,ScaptCol)
ENDIF
test=0 ' don't continue testing
Set=1  ' defaults are set
RETURN ' from function
'–––––––– Local Subroutines –––––––––
SetSize:
'--- Bnext
DRAWFONT Bnext(2),Bnext(3)
Bnext(6)=1.4*STRWIDTH Bnext(1)
Bnext(7)=2*STRHEIGHT Bnext(1)
'--- Scapt
DRAWFONT Scapt(2),Scapt(3)
Scapt(6)=0.75*sw ' 1.4*STRWIDTH Scapt(1)
Scapt(7)=1.55*STRHEIGHT Scapt(1)
RETURN 'from subroutine
SetXY:
Bnext(4)=INT(sw-Bnext(6)-10) : Bnext(5)=INT(sh-Bnext(7)-5)
Scapt(4)=INT((sw-Scapt(6))/2) : Scapt(5)=INT(sh-Scapt(7))
RETURN
END DEF
'
DEF WaitForNext ' by Ton Nillesen, November 2019
IF NOT Set THEN GOSUB Init
DO
  IF INBUTT HIT Int_.Bnext(0) THEN RETURN
  CPU RELAX
REDO
Init: ' set parms
CALL Int_Butt(Int_.Bnext,Int_.BnextCol)
Set=1
RETURN from subroutine
END DEF
'
DEF Int_Sign(p(),C()) ' by Ton Nillesen, November 2019
IF Align=0 THEN Align=3 ' on first call
Id=P(0)
INSIGN SET    Id p(1),p(4),p(5),p(6),p(7)
INSIGN FONT   Id p(2),p(3)
INSIGN FCOLOR Id Int_ColFB|4(0,C)
INSIGN BCOLOR Id Int_ColFB|4(1,C)
INSIGN ALIGN  Id Align
END DEF
'
DEF Int_Butt(P(),C()) ' by Ton Nillesen, November 2019
Id=p(0)
INBUTT SET    Id p(1),p(4),p(5),p(6),p(7)
INBUTT FONT   Id p(2),p(3)
INBUTT FCOLOR Id Int_ColFB|4(0,C)
INBUTT BCOLOR Id Int_ColFB|4(1,C)
END DEF
'
DEF Int_Parms(P(),C()) ' by Ton Nillesen, November 2019
'Print parameters
FOR i=0 TO (SIZEOF Int_.Parm$)-1
  PRINT Int_.Parm$(i)+"="; P(i)
NEXT i
DIM Col$()=("Fcolor","Bcolor")
FOR i=0 TO 1
   PRINT Col$(i);
   r,g,b,A=Int_ColFB|4(i,C)
   PRINT r;g;b;A
NEXT i
END DEF

DEF Int_ColFB(i,C())' renamed copy of Col_FB() in ../Graphics/! Col_ utils
n=4*i
RETURN C(n),C(n+1),,C(n+2),C(n+3)
END DEF
.
# Int_ Defaults.bb is a test program which places 'Bnext' and 'Scaption'
Int_Parms(P(),C()) can be used to print the parameters and or colors of Buttons or Signs.
Int.Parm$() contains the names of the parameters.
The output on console for the 'Bnext' (Id=0)

Code: Select all

Id= 0 
Text=Next
Font$=Arial
Fsize= 20 
X= 511.766 
Y= 269.898 
Width= 55.2344 
Height= 29.1016 
Fcolor 1  1  0  1 
Bcolor 0  0  1  1 
For more buttons and/or signs:
• Copy Int_.Bnext, Int.BnextCol and/or Int_.Scapt, Int_ScaptCol
to user defined (and DIM-ed) parameter lists.
• Made desired changes in the parameters.
Change at least:
– ObjectId index 'Id': use ascending numbering or random numbers assigned to variables
– Position parameters 'X' and 'Y'
• CALL Int_Butt(P(),C()) with parameter and color lists to set the Button OR
CALL Int_Sign(p(),C()) with parameter and color lists to set the Sign

UPDATES
20191125
Index of "Bnext" and "Scapt" set with 'INBUTT INDEX' and 'INSIGN INDEX'
Included Col_FB() replaced by local Int_ColFB()
It is still a long way to go

Post Reply