dialsGauges

Dials/gauges
Slider type controls demo. These controls work for output - and for input, too. code format="vbnet" nomainwin

WindowWidth = 568 WindowHeight = 380

UpperLeftX=int((DisplayWidth-WindowWidth)/2) UpperLeftY=int((DisplayHeight-WindowHeight)/2)

button #main.btnStart, "Start", [btnStartClick], UL, 422, 21, 122, 25 button #main.btnStop, "Stop", [btnStopClick], UL, 422, 61, 122, 25 button #main.btnRnd, "Randomize", [btnRndClick], UL, 422, 101, 122, 25

button #main.btnQuit, "Quit", [btnQuitClick], UL, 414, 306, 122, 25 graphicbox #main.graph1, 14, 16, 240, 100 graphicbox #main.graph2, 14, 126, 240, 100 graphicbox #main.graph3, 14, 236, 240, 100 graphicbox #main.dial1, 294, 16, 25, 100 graphicbox #main.dial2, 270, 161, 100, 25 graphicbox #main.dial3, 270, 236, 100, 100 statictext #main.lbl1, "100", 326, 56, 30, 20 statictext #main.lbl2, "100", 310, 141, 30, 20 statictext #main.lbl3, "100", 310, 216, 30, 20 open "slider type controls" for dialog as #main print #main.graph1,"down; fill white; flush" print #main.graph2,"down; fill white; flush" print #main.graph3,"down; fill white; flush" print #main.dial1,"down; fill white; flush" print #main.dial2,"down; fill white; flush" print #main.dial3,"down; fill white; flush" print #main, "trapclose [quit.main]" print #main.dial1,"when leftButtonUp [setDial1]" print #main.dial2,"when leftButtonUp [setDial2]" print #main.dial3,"when leftButtonUp [setDial3]"

print #main, "font ms_sans_serif 10"

dim a(3) for i = 1 to 3 handle$= "#main.graph";i #handle$, "down" a(i)=int(100*rnd(1)) y = 100 - a(i) #handle$, "color ";word$("red green blue",i) #handle$, "line 0 ";y;" 240 ";y next

#main.dial3, "fill white; color blue; place 50 50; circle 35" da = 45 'degrees rr = 43 for i = 0 to 10 ai = i*10 f1 = ai/100*(180+2*da)-da f2 = f1 *3.1415926/180 x1 = 50 + rr*cos(f2) y1 = 50 - rr*sin(f2) #main.dial3, "size ";int(i*.7)+2;";set ";x1;" ";y1 next rr = 35 #main.dial3, "size 1; getbmp dial3 0 0 100 100" gosub [drawDials] wait

[setDial1] a(1) = 100 - MouseY if timerEnabled = 0 then gosub [drawDials] wait

[setDial2] a(2) = MouseX if timerEnabled = 0 then gosub [drawDials] wait

[setDial3] 'to get angle from MouseX, MouseY - ??? dx = MouseX - 50 dy = 50 - MouseY a = atan2(dx, dy)  '0..360 if a>270 then a = a-360 '-90..270 '-45..225 -> 0..100   select case case a<-45 a2 = 0 case a>225 a2 = 100 case else a2 = (a+45)/270*100 end select a(3) = a2   if timerEnabled = 0 then gosub [drawDials] wait

[quit.main] timer 0 Close #main END

[btnRndClick] for i = 1 to 3 a(i)=int(100*rnd(1)) next if timerEnabled = 0 then gosub [drawDials] wait

[drawDials] for i = 1 to 3 handle$= "#main.lbl";i #handle$, a(i) y = 100 - a(i) select case i       case 1 #main.dial1, "fill white; backcolor red; color red; place 0 100; boxfilled 25 ";y '           print "0 ";y;" 25 100" case 2 #main.dial2, "fill white; color green; line 0 20 100 0" x = 100-y  'reverce one more time i0 = 20*(1-x/100) for i1 = i0 to 20 xx = (20-i1)/20*100 #main.dial2, "line ";xx;" ";i1;" ";x;" ";i1 next '           print "0 ";y;" 25 100" case 3 f1 = a(i)/100*(180+2*da)-da f2 = f1 *3.1415926/180 x1 = 50 + rr*cos(f2) y1 = 50 - rr*sin(f2) #main.dial3, "discard; drawbmp dial3 0 0" #main.dial3, "line 50 50 ";x1;" ";y1 end select next i return

[nextTimer] timer 0 for i = 1 to 3 a(i)=a(i)+int(5*rnd(1))-2 if a(i)>100 then a(i)=100 if a(i)<0 then a(i)=0

handle$= "#main.graph";i #handle$, "getbmp tmpBmp 0 0 239 100" #handle$, "drawbmp tmpBmp 1 0" #handle$, "color white; line 0 0 0 100; discard" y = 100 - a(i) #handle$, "color ";word$("red green blue",i) #handle$, "set 0 ";y next gosub [drawDials] timer 100, [nextTimer] wait

[btnStartClick]   'Perform action for the button named 'btnStart' 'Insert your own code here timer 0 timerEnabled = 1 timer 100, [nextTimer] wait

[btnStopClick]   'Perform action for the button named 'btnStop' 'Insert your own code here timer 0 timerEnabled = 0 wait

[btnQuitClick]   'Perform action for the button named 'btnQuit' goto [quit.main] wait

'***************************************** function atan2(x,y) 'returns 0..360 degrees if abs(x)<0.001 then atan2 = 90+(y<0)*180 : exit function pi = 3.1415925 tan = y/x atn = atn(tan) select case case x>0 and y>0 atan2 = atn/pi*180 case x<=0 atn = atn + pi       atan2 = atn/pi*180 case else atn = atn + 2*pi atan2 = atn/pi*180 end select end function code