/'
  Program to exemplify the IupVal element.
 '/

#include once "crt.bi"
#include once "inc/iup.bi"

sub _init_ constructor
  IupOpen(0,0)
end sub

sub _exit_ destructor
  IupClose()
end sub

dim shared as Ihandle ptr lbl_h, lbl_v

function mousemove cdecl (c as Ihandle ptr,a as double) as integer
  dim as zstring*40 buffer
  dim as zstring ptr type_

  sprintf(buffer, "VALUE=%.2g", a)
  type_ = IupGetAttribute(c, "ORIENTATION")
  select case (*Type_)[0]
  case asc("V")
    IupStoreAttribute(lbl_v, "TITLE", @buffer)
  case asc("H")
    IupStoreAttribute(lbl_h, "TITLE", @buffer)
  end select
  return IUP_DEFAULT
end function

function button_press cdecl(c as Ihandle ptr ,a as double) as integer
  dim as zstring ptr type_ = IupGetAttribute(c, "ORIENTATION")
  select case (*Type_)[0]
  case Asc("V")
    IupSetAttribute(lbl_v, "FGCOLOR", "255 0 0")
  case asc("H")
    IupSetAttribute(lbl_h, "FGCOLOR", "255 0 0")
  end select
  mousemove(c, a)
  return IUP_DEFAULT
end function

function button_release cdecl(c as Ihandle ptr ,a as double) as integer
  dim as zstring ptr type_ = IupGetAttribute(c, "ORIENTATION")
  select case (*Type_)[0]
  case Asc("V")
    IupSetAttribute(lbl_v, "FGCOLOR", "0 0 0")
  case asc("H")
    IupSetAttribute(lbl_h, "FGCOLOR", "0 0 0")
  end select
  mousemove(c, a)
  return IUP_DEFAULT
end function

'
' main
'
dim as Ihandle ptr dlg_val, val_h, val_v
val_v = IupVal("VERTICAL")
val_h = IupVal("HORIZONTAL")
lbl_v = IupLabel("VALUE=")
lbl_h = IupLabel("VALUE=")
IupSetAttribute(lbl_v, "SIZE", "50x")
IupSetAttribute(lbl_h, "SIZE", "50x")
IupSetAttribute(val_v, "SHOWTICKS", "5")

dlg_val = IupDialog _
  ( _
    IupHbox _
    ( _
        IupSetAttributes(IupHbox _
        ( _
          val_v,_
          lbl_v,_
          NULL _
        ), "ALIGNMENT=ACENTER"),_
        IupSetAttributes(IupVbox _
        (_
          val_h,_
          lbl_h,_
          NULL _
        ), "ALIGNMENT=ACENTER"),_
      NULL _
    )_
  )

IupSetCallback(val_v, "BUTTON_PRESS_CB"  , cast(Icallback,@button_press))
IupSetCallback(val_v, "BUTTON_RELEASE_CB", cast(Icallback,@button_release))
IupSetCallback(val_v, "MOUSEMOVE_CB"     , cast(Icallback,@mousemove)) 

IupSetCallback(val_h, "BUTTON_PRESS_CB"  , cast(Icallback,@button_press))
IupSetCallback(val_h, "BUTTON_RELEASE_CB", cast(Icallback,@button_release))
IupSetCallback(val_h, "MOUSEMOVE_CB"     , cast(Icallback,@mousemove))

IupSetAttribute(dlg_val, "TITLE" , "IupVal")
IupSetAttribute(dlg_val, "MARGIN", "10x10")
IupShowXY(dlg_val,IUP_CENTER,IUP_CENTER)

IupMainLoop()
