preprocess.skip=1

video_number=-1


dynamic_zoom.zoom=1
dynamic_zoom.min_sigma=1

function create_defaults
. ((f)).max_brightness=1
. ((f)).use_brightness=0
. ((f)).use_max_intensity=0
. ((f)).xoff=0
. ((f)).yoff=0
. ((f)).glow_scale=1
. ((f)).glow_sigma=.1
. ((f)).glow_power=1
. ((f)).glow_transparency=1
. ((f)).glow.ohot.gutter=.1
. ((f)).glow_map=hot
. ((f)).dynamic_zoom.use_fixed_scale=0
. ((f)).dynamic_zoom.fixed_scale=10
. ((f)).dynamic_zoom.scale_by_number=0
. ((f)).density_scale=1
. ((f)).density_scale.width=.4
. ((f)).density_scale.height=.05
. ((f)).density_scale.x=.1
. ((f)).linescan.normalize=1
. ((f)).density_scale.border.width=5
. ((f)).density_scale.border.color=[128 128 255 255]
endfunction

spots1.density_scale.y=.95
spots2.density_scale.y=.85

f=spots1
create_defaults

f=spots2
create_defaults

one=1


//() only strips one var per line. Hence the if hax
function create_widgets
. if_equal one 1
. . ((w)).AddToggleButton "Use Brightness" (f).use_brightness
. . ((w)).AddToggleButton "Use max intensity" (f).use_max_intensity
. . ((w)).AddMonitor "Maximum brightness" (f).max_brightness 
. . ((w)).AddSlider (f).max_brightness 0 10
. . ((w)).AddMonitor "Maximum opacity" (f).glow_transparency
. . ((w)).AddSlider (f).glow_transparency 0 1
. . ((w)).AddToggleButton "Fixed scale" (f).dynamic_zoom.use_fixed_scale
. . ((w)).AddMonitor "Fixed scale" (f).dynamic_zoom.fixed_scale
. . ((w)).AddSlider (f).dynamic_zoom.fixed_scale 0 50
. . ((w)).AddMonitor "Glow range" (f).glow_scale
. . ((w)).AddSlider (f).glow_scale 1 20
. . ((w)).AddPushButton "Sigma=.4" (f).glow_sigma=.4
. . ((w)).AddMonitor "Pixelization" (f).pixelate.size
. . ((w)).AddSlider (f).pixelate.size 1 20
. . ((w)).AddPushButton "Hot" "(f).glow_map=hot"
. . ((w)).AddPushButton "Overlay hot" "(f).glow_map=ohot"
. . ((w)).AddPushButton "Grey" "(f).glow_map=grey"
. . ((w)).AddPushButton "Green" "(f).glow_map=green"
. . ((w)).AddPushButton "Red" "(f).glow_map=red"
. . ((w)).AddSlider (f).xoff -10 10
. . ((w)).AddSlider (f).yoff -10 10
. . watch ((f)).use_brightness motion
. . watch ((f)).use_max_intensity motion
. . watch ((f)).max_brightness motion
. . watch ((f)).glow_transparency motion
. . watch ((f)).dynamic_zoom.use_fixed_scale motion
. . watch ((f)).dynamic_zoom.fixed_scale motion
. . watch ((f)).glow_scale motion
. . watch ((f)).glow_sigma motion
. . watch ((f)).glow_map motion
. . watch ((f)).pixelate.size motion
. . watch ((f)).xoff motion
. . watch ((f)).yoff motion
. . watch ((f)).xoff linescan
. . watch ((f)).yoff linescan
. endif
endfunction



function s1_widgets
. w=spots1
. f=spots1
. GUI.AddWindow ((w)) "Spots 1 Controls"
. create_widgets
endfunction



function s2_widgets
. w=spots2
. f=spots2
. GUI.AddWindow ((w)) "Spots 2 Controls"
. create_widgets
endfunction


GUI.InitXInterface
GUI.AddWindow c Controls
//c.AddMonitor cross_size cross_size
//c.AddSlider cross_size 0 5
//c.AddMonitor linewidth linewidth
//c.AddSlider linewidth 0 5
//c.AddMonitor xoff xoff
//c.AddSlider xoff -10 10
//c.AddMonitor yoff yoff
//c.AddSlider yoff -10 10
//c.AddMonitor Zoom zoom_level
//c.AddSlider zoom_level -10 10
c.AddMonitor show show
c.AddSlider show 0 1
c.AddToggleButton "Play" play
c.AddPushButton "Rewind" show=0
c.AddPushButton "Nudge" next
c.AddPushButton "Prev" prev





c.AddPushButton "Save video" dump_a_video=1
c.AddToggleButton "Save widefield panel" dump.separate_widefield

c.AddMonitor "Image brightness" image_brightness
c.AddSlider image_brightness 1 10
// 
// max_brightness=10
// c.AddToggleButton "Use Brightness" use_brightness
// c.AddToggleButton "Use max intensity" use_max_intensity
// c.AddMonitor "Maximum brightness" max_brightness 
// c.AddSlider max_brightness 0 10
// //c.AddMonitor "Opacity" weighting 
// //c.AddSlider weighting 0 1
// 
// 
// c.AddToggleButton "Glow scale" dynamic_zoom
// c.AddToggleButton "Transparent glow" hot_transparent
// c.AddMonitor "Maximum opacity" glow_transparency
// c.AddSlider glow_transparency 0 1
// c.AddToggleButton "Fixed scale" dynamic_zoom.use_fixed_scale
// c.AddMonitor "Fixed scale" dynamic_zoom.fixed_scale
// c.AddSlider dynamic_zoom.fixed_scale 0 10
// c.AddMonitor "Glow range" glow_scale
// c.AddSlider glow_scale 1 20
// 

c.AddToggleButton "Glow scale" dynamic_zoom
c.AddToggleButton "Transparent glow" hot_transparent


c.AddPushButton "Dump density map" dump_density=1

c.AddPushButton "Linescan" line_mode=linescan
c.AddPushButton "Line normal data" "line_mode=normal points"
c.AddMonitor "Mode:" line_mode
normal_std=none
c.AddMonitor "STD:" normal_std

c.AddMonitor "Normal Width" normal_width
c.AddSlider normal_width  0 20

c.AddPushButton "Save linescan" save_linescan=1
linescan_length=none
c.AddMonitor "Number" save_linescan_num
c.AddMonitor "Linescan length" linescan_length
c.AddMonitor "FWHM" fwhm
fwhm.find=1

c.AddPushButton "Spots 1..." s1_widgets
c.AddPushButton "Spots 2..." s2_widgets

watch max_brightness
watch use_max_intensity
watch weighting
watch use_brightness
watch cross_size
watch xoff
watch yoff
watch show
watch linewidth
watch color
watch hot
watch glow_scale
watch glow_sigma
watch glow_zoom
watch glow_power
watch show_simulation
watch simulations.color
watch simulations.linewidth
watch simulations.cross_size
watch dynamic_zoom
watch dynamic_zoom.zoom
watch dynamic_zoom.min_sigma
watch dynamic_zoom.use_fixed_scale
watch dynamic_zoom.fixed_scale
watch dynamic_zoom.scale_by_number

watch zoom_level motion
watch hot_transparent motion
watch glow_transparency motion
watch normal_width motion
watch line_mode motion
watch line_mode motion
watch use_mean motion
watch mask.show motion
watch mask.color motion

watch mask.color mask_update

mask.color=[0 0 1 .5]

c.AddToggleButton "Sim" show_simulation
c.AddPushButton "Quit" keep_running=0

xoff=.5
yoff=.5
cross_size=.01
preprocess.lpf=5
glow_power=1


scalebar=1
scalebar.scale=200
scalebar.width=6
scalebar.color=[1 1 1]
scalebar.pos=[0.1 0.9]

watch scalebar.pos motion
watch scalebar.scale motion
watch scalebar motion

watch pixel_size_in_nm motion
watch pixel_size_in_nm linescan



simulations.color=[0 0 1 .5]
simulations.linewidth=2
simulations.cross_size=1

dynamic_zoom.zoom=1
dynamic_zoom.min_sigma=1
dynamic_zoom.use_fixed_scale=0
dynamic_zoom.fixed_scale=1


linescan.cross.color=[0 1 1]
linescan.cross.size=5
linescan.cross.width=1
linescan.line.color=[1 1 0]
linescan.normalarea.color=[0 0 1 .5]
linescan.line.width=1
linescan.points=1000

mask.color=[0 0 255 255]

watch linescan.points  linescan
watch glow_scale linescan
watch glow_sigma linescan
watch glow_zoom linescan
watch glow_power linescan
watch normal_width linescan
watch line_mode linescan
watch save_linescan linescan
watch dynamic_zoom linescan
watch dynamic_zoom.zoom linescan
watch dynamic_zoom.min_sigma linescan
watch update_linescan linescan
watch show linescan
watch linescan.1 linescan
watch linescan.2 linescan
watch spots1.use_brightness linescan
watch spots1.use_max_intensity linescan
watch spots1.max_brightness linescan
watch spots2.use_brightness linescan
watch spots2.use_max_intensity linescan
watch spots2.max_brightness linescan

watch show image_to_show
watch use_mean image_to_show
watch image_brightness image_to_show

video_stub=/tmp/k000l2/vid-%02i-%03i.jpg


pixel_size_in_nm=10000000

watch pixel_size_in_nm motio

function rewind
. show=0
endfunction

// c.AddSlider xoff -3 3
// .AddSlider yoff -3 3


line_mode="newlinescan"

spots2.glow_power=0.5
spots2.glow_map=grey
s1_widgets
s2_widgets
