Igor Chess Clock v.0.1
#pragma rtGlobals=1 // Use modern global access method.
Menu "w00t"
"chess clock/1", chessclock()
End
macro chessclock_globals()
variable /g glock=1
variable /g gvisual=0
variable /g gaudio=0
variable /g glmin
variable /g grmin
variable /g glsec
variable /g grsec
variable /g glres=0
variable /g grres=0
variable /g gresume=0
variable /g gstart=0
variable /g gcharacter=1
end
function chessclock()
string tmpstring
nvar turn = gturn
nvar lmin = glmin
nvar rmin = grmin
nvar lsec = glsec
nvar rsec = grsec
sprintf tmpstring "chessclock_globals()"
execute tmpstring
if((lmin==0) & (lsec==0))
lmin = 10
lsec = 0
endif
if((rmin==0) & (rsec==0))
rmin=10
rsec=0
endif
sprintf tmpstring, "Display /W=(0,35,640,250) /K=1 as \"SNC Chess Clock\""
execute tmpstring
controlbar 125
sprintf tmpstring, "TitleBox lefttitle frame=1, pos={125,10}, size={100,20}, title=\"\\f01 Player One \""
execute tmpstring
sprintf tmpstring, "SetVariable leftminutes activate, bodyWidth=60, disable=0, font=\"Verdana\", format=\"%%d\", value=glmin, frame=1, fsize=10, labelBack=(55000,55000,63000), limits={0,999,1}, pos={140,45}, size={80,15}, proc=settime, title=\"Min: \""
execute tmpstring
sprintf tmpstring, "SetVariable leftseconds bodyWidth=60, disable=0, font=\"Verdana\", format=\"%%d\", value=glsec, frame=1, fsize=10, labelBack=(63000,55000,55000), limits={0,59,1}, pos={140,70}, size={80,15}, proc=settime, title=\"Sec: \""
execute tmpstring
sprintf tmpstring, "CheckBox leftwhite, disable=0, value=1, mode=1, pos={120,100}, proc=colorselect, title=\"White\""
execute tmpstring
sprintf tmpstring, "CheckBox leftblack, disable=0, value=0, mode=1, pos={180,100}, proc=colorselect, title=\"Black\""
execute tmpstring
sprintf tmpstring, "TitleBox righttitle frame=1, pos={625,10}, size={100,20}, title=\"\\f01 Player Two \""
execute tmpstring
sprintf tmpstring, "SetVariable rightminutes bodyWidth=60, disable=0, font=\"Verdana\", format=\"%%d\", value=grmin, frame=1, fsize=10, labelBack=(55000,55000,63000), limits={0,999,1}, pos={640,45}, size={80,15}, proc=settime, title=\"Min: \""
execute tmpstring
sprintf tmpstring, "SetVariable rightseconds bodyWidth=60, disable=0, font=\"Verdana\", format=\"%%d\", value=grsec, frame=1, fsize=10, labelBack=(63000,55000,55000), limits={0,59,1}, pos={640,70}, size={80,15}, proc=settime, title=\"Sec: \""
execute tmpstring
sprintf tmpstring, "CheckBox rightwhite, disable=0, value=0, mode=1, pos={620,100}, proc=colorselect, title=\"White\""
execute tmpstring
sprintf tmpstring, "CheckBox rightblack, disable=0, value=1, mode=1, pos={680,100}, proc=colorselect, title=\"Black\""
execute tmpstring
sprintf tmpstring, "Button divider1 disable=0, pos={350,5}, size={3,115}, title=\"\""
execute tmpstring
sprintf tmpstring, "Button divider2 disable=2, pos={500,5}, size={3,115}, title=\"\""
execute tmpstring
sprintf tmpstring "CheckBox lockplayers disable=0, value=1, mode=0, pos={370,10}, variable=glock, title=\"Symmetrical times\""
execute tmpstring
sprintf tmpstring "CheckBox visualnote disable=1, value=0, mode=0, pos={370,30}, variable=gvisual, title=\"Visual notice\""
execute tmpstring
sprintf tmpstring "CheckBox character disable=0, value=gcharacter, mode=0, pos={370,30}, variable=gcharacter, title=\"Show character\""
execute tmpstring
sprintf tmpstring "CheckBox audionote disable=0, value=0, mode=0, pos={370,50}, variable=gaudio, title=\"Audio notice\""
execute tmpstring
sprintf tmpstring "Button starttime disable=0, pos={375,75}, size={100,20}, title=\"Start Clock\", proc=starttime"
execute tmpstring
sprintf tmpstring "Button stoptime disable=1, pos={375,75}, size={100,20}, title=\"[Space] to pause\", proc=stoptime"
execute tmpstring
sprintf tmpstring "Button resume disable=1, pos={375,100}, size={100,15}, title=\"Resume...\", proc=starttime"
execute tmpstring
sprintf tmpstring "Button reset disable=1, pos={375,75}, size={100,20}, title=\"Reset\", proc=reset"
execute tmpstring
variable i,x=763,y=100
imageload /q/o/t=jpg "C:\\icc\\left1.jpg"
imageload /q/o/t=jpg "C:\\icc\\left2.jpg"
imageload /q/o/t=jpg "C:\\icc\\left3.jpg"
imageload /q/o/t=jpg "C:\\icc\\left4.jpg"
imageload /q/o/t=jpg "C:\\icc\\left5.jpg"
imageload /q/o/t=jpg "C:\\icc\\right1.jpg"
imageload /q/o/t=jpg "C:\\icc\\right2.jpg"
imageload /q/o/t=jpg "C:\\icc\\right3.jpg"
imageload /q/o/t=jpg "C:\\icc\\right4.jpg"
imageload /q/o/t=jpg "C:\\icc\\right5.jpg"
imageload /q/o/t=jpg "C:\\icc\\start.jpg"
imageload /q/o/t=jpg "C:\\icc\\finish.jpg"
imageload /q/o/t=jpg "C:\\icc\\start2.jpg"
imageload /q/o/t=jpg "C:\\icc\\finish2.jpg"
make/o/n=764 picx
make/o/n=101 picy
for(i=0;i<=x;i+=1)
picx[i]=i
endfor
for(i=0;i<=y;i+=1)
picy[i]=i
endfor
appendimage 'start2.jpg' vs {picx,picy}
ModifyGraph axRGB=(65535,65535,65535),tlblRGB=(65535,65535,65535),alblRGB=(65535,65535,65535),nticks=0
end
// Function to control the initial time. Basically used to set symmetrical times if the option is set.
function settime(name,varNum,varStr,varName) : SetVariableControl
string name
variable varNum
string varStr, varName
nvar lmin=glmin
nvar lsec=glsec
nvar rmin=grmin
nvar rsec=grsec
nvar lock=glock
if(lock)
strswitch (name)
case "leftminutes":
rmin=lmin
break
case "leftseconds":
rsec=lsec
break
case "rightminutes":
lmin=rmin
break
case "rightseconds":
lsec=rsec
break
endswitch
endif
end
// Starts the clock.
function starttime(name) : ButtonControl
string name
nvar gturn=gstart
nvar lmin=glmin
nvar lsec=glsec
nvar rmin=grmin
nvar rsec=grsec
nvar lres=glres
nvar rres=grres
nvar resume=gresume
nvar visual=gvisual
nvar audio=gaudio
nvar character=gcharacter
variable turn=gturn
variable tlsec=lsec+60*lmin
variable trsec=rsec+60*rmin
variable ttlsec=tlsec, ttrsec=trsec
variable tsec
variable clsec
variable crsec
variable start=datetime
variable laudio=1
variable raudio=1
variable lpicstatus=0, rpicstatus=0
string tmpstring
if(resume)
tlsec=lres
trsec=rres
endif
clsec=tlsec
crsec=trsec
tsec=tlsec+trsec
sprintf tmpstring "Button starttime disable=1"
execute tmpstring
sprintf tmpstring "Button stoptime disable=2"
execute tmpstring
sprintf tmpstring "Button resume disable=1"
execute tmpstring
sprintf tmpstring "Button reset disable=1"
execute tmpstring
SetVariable leftminutes disable=2
SetVariable leftseconds disable=2
SetVariable rightminutes disable=2
SetVariable rightseconds disable=2
CheckBox lockplayers disable=2
//CheckBox visualnote disable=2
CheckBox character disable=2
CheckBox audionote disable=2
CheckBox rightwhite disable=2
CheckBox rightblack disable=2
CheckBox leftwhite disable=2
CheckBox leftblack disable=2
sprintf tmpstring, "\\Z70%s", secs2time(clsec,3)[3,7]
TextBox /C /N=leftclock /V=1 /A=LC /T=50 /B=(65535,65535,65535) /F=0 tmpstring
sprintf tmpstring, "\\Z70%s", secs2time(crsec,3)[3,7]
TextBox /C /N=rightclock /V=1 /A=RC /T=50 /B=(65535,65535,65535) /F=0 tmpstring
if(character & (resume==0))
if(gturn)
removeimage /Z 'right1.jpg' // to avoid double occurances
appendimage 'right1.jpg' vs {picx,picy}
rpicstatus=1
else
removeimage /Z 'left1.jpg'
appendimage 'left1.jpg' vs {picx,picy}
lpicstatus=1
endif
ModifyGraph axRGB=(65535,65535,65535),tlblRGB=(65535,65535,65535),alblRGB=(65535,65535,65535),nticks=0
else
removeimage /Z 'start2.jpg'
removeimage /Z 'finish2.jpg'
endif
DoUpdate
do
if(cmpstr(keyboardstate("")[0],"1")==0)
turn=1
if(character)
if(crsec<=0)
rpicstatus=6
appendimage 'finish.jpg' vs {picx,picy}
elseif(crsec<ttrsec/5)
rpicstatus=5
appendimage 'right5.jpg' vs {picx,picy}
elseif(crsec<2*ttrsec/5)
rpicstatus=4
appendimage 'right4.jpg' vs {picx,picy}
elseif(crsec<3*ttrsec/5)
rpicstatus=3
appendimage 'right3.jpg' vs {picx,picy}
elseif(crsec<4*ttrsec/5)
rpicstatus=2
appendimage 'right2.jpg' vs {picx,picy}
else
rpicstatus=1
appendimage 'right1.jpg' vs {picx,picy}
endif
if(lpicstatus==6)
removeimage 'finish.jpg'
else
sprintf tmpstring "removeimage /Z 'left%g.jpg'", lpicstatus
execute tmpstring
endif
DoUpdate
endif
endif
if(cmpstr(keyboardstate("")[6],"1")==0)
turn=0
if(character)
if(clsec<=0)
lpicstatus=6
appendimage 'finish.jpg' vs {picx,picy}
elseif(clsec<ttlsec/5)
lpicstatus=5
appendimage 'left5.jpg' vs {picx,picy}
elseif(clsec<2*ttlsec/5)
lpicstatus=4
appendimage 'left4.jpg' vs {picx,picy}
elseif(clsec<3*ttlsec/5)
lpicstatus=3
appendimage 'left3.jpg' vs {picx,picy}
elseif(clsec<4*ttlsec/5)
lpicstatus=2
appendimage 'left2.jpg' vs {picx,picy}
else
lpicstatus=1
appendimage 'left1.jpg' vs {picx,picy}
endif
if(rpicstatus==6)
removeimage 'finish.jpg'
else
sprintf tmpstring "removeimage /Z 'right%g.jpg'", lpicstatus
execute tmpstring
endif
DoUpdate
endif
endif
if(cmpstr(keyboardstate("")[9]," ")==0)
//lmin=trunc(clsec/60)
//lsec=mod(clsec,60)
//rmin=trunc(crsec/60)
//rsec=mod(crsec,60)
lres=clsec
rres=crsec
resume=1
gturn=turn
sprintf tmpstring "Button reset disable=0"
execute tmpstring
sprintf tmpstring "Button stoptime disable=1"
execute tmpstring
sprintf tmpstring "Button resume disable=0"
execute tmpstring
printf "Clock paused by user!\r"
return 0
endif
if(turn==0) // Update player one clock
clsec=tsec-crsec-(datetime-start)
if(character)
if((clsec<=0) & (lpicstatus<6))
lpicstatus=6
appendimage 'finish.jpg' vs {picx,picy}
removefromgraph /Z 'left5.jpg'
DoUpdate
elseif((clsec<ttlsec/5) & (lpicstatus<5))
lpicstatus=5
appendimage 'left5.jpg' vs {picx,picy}
removefromgraph /Z 'left4.jpg'
DoUpdate
elseif((clsec<2*ttlsec/5) & (lpicstatus<4))
lpicstatus=4
appendimage 'left4.jpg' vs {picx,picy}
removefromgraph /Z 'left3.jpg'
DoUpdate
elseif((clsec<3*ttlsec/5) & (lpicstatus<3))
lpicstatus=3
appendimage 'left3.jpg' vs {picx,picy}
removefromgraph /Z 'left2.jpg'
DoUpdate
elseif((clsec<4*ttlsec/5) & (lpicstatus<2))
lpicstatus=2
appendimage 'left2.jpg' vs {picx,picy}
removefromgraph /Z 'left1.jpg'
DoUpdate
elseif(lpicstatus<1)
lpicstatus=1
appendimage 'left1.jpg' vs {picx,picy}
DoUpdate
endif
endif
if(clsec<=0)
sprintf tmpstring "\"\\Z70\\K(60000,0,0)-%s\"", secs2time(clsec,3)[4,8]
if(visual)
sprintf tmpstring "/B=(65000,55000,55000) %s", tmpstring
endif
if(audio & laudio)
Make/B/O/N=1000 sineSound
SetScale/P x,0,1e-4,sineSound
sineSound= 100*sin(2*Pi*1000*x)
PlaySound sineSound
laudio=0
endif
sprintf tmpstring "TextBox /C /N=leftclock /V=1 /A=LC /T=50 /F=0 %s", tmpstring
execute tmpstring
else
sprintf tmpstring, "\\Z70%s", secs2time(clsec,3)[3,7]
TextBox /C /N=leftclock /V=1 /A=LC /T=50 /B=(65535,65535,65535) /F=0 tmpstring
endif
else // Update player two clock
crsec=tsec-clsec-(datetime-start)
if(character)
if((crsec<=0) & (rpicstatus<6))
rpicstatus=6
appendimage 'finish.jpg' vs {picx,picy}
removefromgraph /Z 'right5.jpg'
DoUpdate
elseif((crsec<trsec/5) & (rpicstatus<5))
rpicstatus=5
appendimage 'right5.jpg' vs {picx,picy}
removefromgraph /Z 'right4.jpg'
DoUpdate
elseif((crsec<2*trsec/5) & (rpicstatus<4))
rpicstatus=4
appendimage 'right4.jpg' vs {picx,picy}
removefromgraph /Z 'right3.jpg'
DoUpdate
elseif((crsec<3*trsec/5) & (rpicstatus<3))
rpicstatus=3
appendimage 'right3.jpg' vs {picx,picy}
removefromgraph /Z 'right2.jpg'
DoUpdate
elseif((crsec<4*trsec/5) & (rpicstatus<2))
rpicstatus=2
appendimage 'right2.jpg' vs {picx,picy}
removefromgraph /Z 'right1.jpg'
DoUpdate
elseif(rpicstatus<1)
rpicstatus=1
appendimage 'right1.jpg' vs {picx,picy}
DoUpdate
endif
endif
if(crsec<=0)
sprintf tmpstring "\"\\Z70\\K(60000,0,0)-%s\"", secs2time(crsec,3)[4,8]
if(visual)
sprintf tmpstring "/B=(65000,55000,55000) %s", tmpstring
endif
if(audio & raudio)
Make/B/O/N=1000 sineSound
SetScale/P x,0,1e-4,sineSound
sineSound= 100*sin(2*Pi*1000*x)
PlaySound sineSound
raudio=0
endif
sprintf tmpstring "TextBox /C /N=rightclock /V=1 /A=RC /T=50 /F=0 %s", tmpstring
execute tmpstring
else
sprintf tmpstring, "\\Z70%s", secs2time(crsec,3)[3,7]
TextBox /C /N=rightclock /V=1 /A=RC /T=50 /B=(65535,65535,65535) /F=0 tmpstring
endif
endif
while(1)
end
// Resets clock and initial times to default values.
function reset(name) : ButtonControl
string name
nvar character=gcharacter
nvar lres=glres
nvar rres=grres
string tmpstring
do
sprintf tmpstring "removeimage %s", stringfromlist(0,imagenamelist("",";"))
execute tmpstring
while(itemsinlist(imagenamelist("",";"))>0)
if((rres<=0) || (lres<=0))
appendimage 'finish2.jpg' vs {picx,picy}
else
appendimage 'start2.jpg' vs {picx,picy}
endif
ModifyGraph axRGB=(65535,65535,65535),tlblRGB=(65535,65535,65535),alblRGB=(65535,65535,65535),nticks=0
sprintf tmpstring "chessclock_globals()"
execute tmpstring
sprintf tmpstring, "SetVariable leftminutes activate, disable=0"
execute tmpstring
sprintf tmpstring, "SetVariable leftseconds disable=0"
execute tmpstring
sprintf tmpstring, "CheckBox leftwhite, disable=0"
execute tmpstring
sprintf tmpstring, "CheckBox leftblack, disable=0"
execute tmpstring
sprintf tmpstring, "SetVariable rightminutes disable=0"
execute tmpstring
sprintf tmpstring, "SetVariable rightseconds disable=0"
execute tmpstring
sprintf tmpstring, "CheckBox rightwhite, disable=0"
execute tmpstring
sprintf tmpstring, "CheckBox rightblack, disable=0"
execute tmpstring
sprintf tmpstring "CheckBox lockplayers disable=0"
execute tmpstring
//sprintf tmpstring "CheckBox visualnote disable=0"
sprintf tmpstring "CheckBox character disable=0"
execute tmpstring
sprintf tmpstring "CheckBox audionote disable=0"
execute tmpstring
sprintf tmpstring "Button starttime disable=0"
execute tmpstring
sprintf tmpstring "Button stoptime disable=1"
execute tmpstring
sprintf tmpstring "Button resume disable=1"
execute tmpstring
sprintf tmpstring "Button reset disable=1"
execute tmpstring
end
// Function to control which player plays white/black
function colorselect (name,value)
string name
variable value
nvar start = gstart
strswitch (name)
case "leftwhite":
start=0
break
case "rightblack":
start=0
break
case "leftblack":
start=1
break
case "rightwhite":
start=1
break
endswitch
checkbox leftwhite, value=(start==0)
checkbox rightblack, value=(start==0)
checkbox leftblack, value=(start==1)
checkbox rightwhite, value=(start==1)
end
Go to the Contents
Wed Nov 05 23:34:54 2003