I have made a simple program to convert decibels to pressure using the FLTK gui. I would like to set one of two buttons to "on". Only one or the other can be "on". This sets the reference pressure to either psi or pascals. I would like to set Button_radio_psi to "on"
Thanks,
Darren
Code: Select all
' Convert decibel to pressure (RMS)
'
#INCLUDE "fltk-c.bi"
#include "string.bi"
'Window and widgets:
DIM SHARED AS Fl_Window PTR Window_Main
DIM SHARED AS Fl_Input PTR SPL_text
DIM SHARED AS Fl_Input PTR Pressure_text
DIM SHARED AS Fl_Button PTR Button_Compute
DIM SHARED AS Fl_Group PTR Group_radio
DIM SHARED AS Fl_Radio_Round_Button PTR Button_radio_psi,Button_radio_pascal
DIM SHARED AS DOUBLE p0
SUB Create_Window_Main ()
'Window with widgets:
Window_Main = Fl_WindowNew (300, 300, "SPL <> Pressure")
Group_radio = Fl_GroupNew (50, 20, 120, 90, "Choose a Ref. Pressure")
Fl_GroupBegin (Group_radio)
Button_radio_psi = Fl_Radio_Round_ButtonNew (20, 40, 100, 20, "psi")
Button_radio_pascal = Fl_Radio_Round_ButtonNew (20, 60, 100, 20, "Pascals")
Fl_GroupEnd (Group_radio)
SPL_text = Fl_InputNew (100, 100, 180, 20, "SPL")
Pressure_text = Fl_InputNew (100, 130, 180, 20, "Pressure")
Button_Compute = Fl_ButtonNew (100, 200, 100, 20, "Compute")
'Fl_Input_SetValue (Input_text, "170")
END SUB
SUB Button_Ref CDECL (widget AS FL_Widget PTR, arg as ANY PTR)
SELECT CASE arg
CASE Button_radio_psi
p0 = 2.90075E-9
CASE Button_radio_pascal
p0 = 2.0e-5
END SELECT
'print "p0 = ";p0
END SUB
SUB Button_Compute_Event CDECL (widget AS FL_Widget PTR)
'Callback function for Button
DIM AS STRING spl_txt,pp_txt
dim as double spl,pprime
'p0 = 2.90075E-9
spl_txt = *Fl_Input_GetValue (SPL_text)
pp_txt = *Fl_Input_GetValue (Pressure_text)
if spl_txt <> "" then
spl = val(spl_txt)
pprime = 10^(spl/20)*p0
pp_txt = Format(pprime,"#.####E+0#")
else
pprime = val(pp_txt)
spl = 20*(log(pprime/p0)/log(10))
spl_txt = Format(spl,"###.0#")
end if
Fl_Input_SetValue (SPL_text, spl_txt)
Fl_Input_SetValue (Pressure_text, pp_txt)
END SUB
'Main program:
Create_Window_Main ()
Fl_WidgetSetCallbackArg (Button_radio_psi, @Button_Ref, Button_radio_psi)
Fl_WidgetSetCallbackArg (Button_radio_pascal, @Button_Ref, Button_radio_pascal)
Fl_WidgetSetCallback0 (Button_Compute, @Button_Compute_Event())
Fl_WindowShow (Window_Main)
Fl_Run
END