After normal button, Radio button is also done (Sample Programs)

by UglyMike ⌂ @, Brussels, Thursday, August 29, 2013, 11:33 (1424 days ago) @ UglyMike

An Aqua like radio button list in Basic-256....

# Aqua inspired Radio button GUI element
# Graphical interfaces often will need to use radio buttons to make selections
# Radio buttons are placed one below the other
# The number of radio buttons is not fixed
# Radio buttons cover a certain area (going top to bottom)
# Radio buttons have captions
# Only a single radio button within a group can be selected
# here we create a subroutine that takes input and creates the radio buttons
# You are responsible for the
# lenght of the caption versus available space
# number of radio buttons versus available vertical space
# Inputs are
# elements : The number of elements in the radio group
# locx : horizontal location of the radio-button group
# locy_top : vertical location of the topmost radio button
# locy_bot : vertical location of the bottom radio button
# active : the position of the active radio button (0 for no button active)
#
# Additionally you need an global array for radio button captions
# You need to copy the local array in the global array (here called radio$)
#
# Copy and Paste the subroutine in your program and pass it the correct parameters
#
#basic initialisation
graphsize 300,250
fastgraphics
clg
#create Aqua background
color rgb(240,240,240)
rect 0,0,499,499
color rgb(250,250,250)
for i = 1 to 500 step 10
rect 0,i,500,5
next i
#here, you set up and draw your radio buttons
# eg we'll draw a 7-option radio group on the left side the canvas area and a 4-option radio group on the right side
#you MUST declare the array used in the subroutine as Global as arrays cannot be passed as argument
global radio$
dim radio$(7)
# definition and initial drawing of first test array
dim radio1$(7)
radio1$={"radio button 1","radio button 2","radio button 3","radio button 4","radio button 5","radio button 6","radio button 7"}
radio1_elements=7
radio1_locx=30:radio1_locy_top=50:radio1_locy_bot=200
radio1_active=1
for i= 0 to radio1_elements-1
radio$[i]=radio1$[i]
next i
call adrawradio(radio1_elements, radio1_locx, radio1_locy_top, radio1_locy_bot, radio1_active)
# definition and initial drawing of second test array
dim radio2$(4)
radio2$={"A","B","C","D"}
radio2_elements=4
radio2_locx=200:radio2_locy_top=50:radio2_locy_bot=150
radio2_active=1
for i= 0 to radio2_elements-1
radio$[i]=radio2$[i]
next i
call adrawradio(radio2_elements, radio2_locx, radio2_locy_top, radio2_locy_bot, radio2_active)
# a 'real' radio group would trigger a reaction on changing the selection
# here, we just allow switching between radio buttons with the mouse
clickclear
while 1=1
if clickb=1 then
if mousex > radio1_locx-5 and mousex < radio1_locx+5 then
if mousey > radio1_locy_top-4 and mousey < radio1_locy_bot+5 then
for i=0 to radio1_elements
if mousey > radio1_locy_top-5+ (i*(radio1_locy_bot-radio1_locy_top)/(radio1_elements-1)) and mousey < radio1_locy_top+5+ (i*(radio1_locy_bot-radio1_locy_top)/(radio1_elements-1)) then
radio1_active=i+1
for i= 0 to radio1_elements-1
radio$[i]=radio1$[i]
next i
call adrawradio(radio1_elements, radio1_locx, radio1_locy_top, radio1_locy_bot, radio1_active)
end if
next i
end if
else
if mousex > radio2_locx-5 and mousex < radio2_locx+5 then
if mousey > radio2_locy_top-4 and mousey < radio2_locy_bot+5 then
for i=0 to radio2_elements
if mousey > radio2_locy_top-5+ (i*(radio2_locy_bot-radio2_locy_top)/(radio2_elements-1)) and mousey < radio2_locy_top+5+ (i*(radio2_locy_bot-radio2_locy_top)/(radio2_elements-1)) then
radio2_active=i+1
for i= 0 to radio2_elements-1
radio$[i]=radio2$[i]
next i
call adrawradio(radio2_elements, radio2_locx, radio2_locy_top, radio2_locy_bot, radio2_active)
end if
next i
end if
end if
end if
end if
clickclear
pause 0.1
end while
#***************************************************
# sub routine "Draw an Aqua-like radio button list"
#***************************************************
subroutine adrawradio(elements, locx, locy_top, locy_bot, active)

# Do not forget to declare and initialize a global array 'radio$' before calling the subroutine
color black
font "Tahoma",10,100
radio_spacing = (locy_bot-locy_top)/(elements-1)
b_width=12:b_height=12
for j = 0 to (elements -1)
color darkgrey
circle locx, locy_top+(radio_spacing*j), 8
cactive=locy_top+(radio_spacing*j)+1
color rgb(180,180,180)
half=6
circle locx, locy_top+(radio_spacing*j),6
for i = 9 to 1 step -1
color rgb(240-(10-i)*9, 240-(10-i)*9, 240-(10-i)*9)
color rgb(180+i*8, 180+i*8, 180+i*8)
rect sin(-acos(i/10))*abs(half)+locx, cactive-0.6*i-1, 6, 2
refresh
next i
for i = 1 to 9
color rgb(160+i*9, 160+i*9, 160+i*9)
rect -(sin(acos(i/10)))*abs(half)+locx, cactive+0.5*i-1, 7, 2
next i
for i = 9 to 1 step -1
color rgb(240-(10-i)*9, 240-(10-i)*9, 240-(10-i)*9)
color rgb(180+i*8, 180+i*8, 180+i*8)
rect -sin(-acos(i/10))*half+locx-half,cactive-0.6*i-1, 7, 2
refresh
next i
for i = 1 to 9
color rgb(160+i*9, 160+i*9, 160+i*9)
rect (sin(acos(i/10)))*abs(half)+locx-half, cactive+0.5*i-1, 7, 2
next i
refresh

next j
#radio text captions
color black
for i = 0 to elements-1
text locx + 15,locy_top + (radio_spacing*i)-8, radio$[i]
next i
# paint active radio button
if active > 0 then
color rgb(180,180,180)
half=6
cactive=locy_top+(radio_spacing*(active-1))
circle locx, cactive, abs(half+1)
for i = 9 to 1 step -1
color rgb(80+i*15, 240-(10-i)*9, 252-(8-i))
rect sin(-acos(i/10))*abs(half)+locx, cactive-0.5*i, 6, 2
refresh
next i
for i = 1 to 9
color rgb(0, 130+i*9, 243+i)
rect -(sin(acos(i/10)))*abs(half)+locx, cactive+0.5*i, 7, 2
next i
for i = 9 to 1 step -1
color rgb(80+i*15, 240-(10-i)*9, 252-(8-i))
rect -sin(-acos(i/10))*half+locx-half,cactive-0.5*i, 7, 2
refresh
next i
for i = 1 to 9
color rgb(0, 130+i*9, 243+i)
rect (sin(acos(i/10)))*abs(half)+locx-half, cactive+0.5*i, 7, 2
next i
color black
circle locx,cactive,2
refresh
refresh
endif
refresh
end subroutine


Complete thread:

 RSS Feed of thread

powered by my little forum