
#include "inc/iup.bi"

dim shared as Ihandle ptr timer1, timer2

sub _init_ constructor
  IupOpen(0,0)
end sub

sub _exit_ destructor
  ' Timers are NOT automatically destroyed, must be manually done
  if timer1 then IupDestroy(timer1)
  if timer2 then IupDestroy(timer2)
  IupClose()
end sub


function timer1_cb cdecl (ih as Ihandle ptr) as integer
  static as integer nTicks=0
  nTicks+=1
  print("timer1 " & nTicks & " times called")
  return IUP_DEFAULT
end function

function timer2_cb cdecl (ih as Ihandle ptr) as integer
  static as integer nTicks=0
  nTicks+=1
  print("timer2 " & nTicks & " times called")
  if nTicks>10 then
    return IUP_CLOSE
  else
    return IUP_DEFAULT
  end if
end function

'
' main
'

dim as Ihandle ptr text = IupLabel("Timer example")

' Creating main dialog
dim as Ihandle ptr dialog = IupDialog(IupVbox(text, NULL))
IupSetAttribute(dialog, "TITLE", "timer example")
IupSetAttribute(dialog, "SIZE", "256x256")
IupShowXY(dialog, IUP_CENTER, IUP_CENTER)

timer1 = IupTimer()
IupSetAttribute(timer1, "TIME", "100") 
IupSetAttribute(timer1, "RUN", "YES")
IupSetCallback(timer1, "ACTION_CB", @timer1_cb)

timer2 = IupTimer()
IupSetAttribute(timer2, "TIME", "1000")
IupSetAttribute(timer2, "RUN", "YES")
IupSetCallback(timer2, "ACTION_CB", @timer2_cb)

IupMainLoop()




