' IupDial Example in C
#Include once "crt.bi"
#Include once "inc/iup.bi"
#Include once "inc/iupcd.bi"
#Include once "inc/iupcontrols.bi"

sub _init_ constructor
  IupOpen(0,0)
  IupControlsOpen()
end sub

sub _exit_ destructor
  IupClose()
end sub

Sub printdial(c As Ihandle ptr ,a As Double,color_ As ZString ptr)
  Dim As ZString Ptr Type_
  Dim As Ihandle Ptr label
  type_ = IupGetAttribute(c, "ORIENTATION")

  Select Case ((*type_)[0])
    case Asc("V")
      label = IupGetHandle("lbl_v")
    case Asc("H")
      label = IupGetHandle("lbl_h")
    case Asc("C")
      label = IupGetHandle("lbl_c")
  End Select

  if (label) Then
    IupSetfAttribute(label, "TITLE", "%.3g", a)
    IupSetAttribute(label, "BGCOLOR", color_)
  End If
End Sub

Function mousemove Cdecl(c As Ihandle ptr ,a As double) As Integer
  printdial(c, a, "0 255 0")
  return IUP_DEFAULT
End Function

Function button_press Cdecl(c As Ihandle ptr ,a As Double) As Integer
  printdial(c, a, "255 0 0")
  return IUP_DEFAULT
End Function

Function button_release cdecl(c As Ihandle ptr ,a As Double) As Integer
  printdial(c, a, NULL)
  return IUP_DEFAULT
End function

'
' main
'
dim as zstring ptr error_ = IupLoad("dial.led")
if error_ <> NULL then
  IupMessage(!"%s\n", error_)
  end
end if

dim as IHandle ptr dlg    = IupGetHandle("dlg")
dim as IHandle ptr dial_h = IupGetHandle("dial_h")
dim as IHandle ptr dial_v = IupGetHandle("dial_v")
dim as IHandle ptr dial_c = IupGetHandle("dial_c")

'/* sets mouse-movement callback */
IupSetFunction("mousemove"     , cast(Icallback, @mousemove))
IupSetFunction("button_press"  , cast(Icallback, @button_press))
IupSetFunction("button_release", cast(Icallback, @button_release))

IupSetAttribute(dial_v, ICTL_BUTTON_PRESS_CB, "button_press")
IupSetAttribute(dial_c, ICTL_BUTTON_PRESS_CB, "button_press")

IupSetAttribute(dial_v, ICTL_BUTTON_RELEASE_CB, "button_release")
IupSetAttribute(dial_h, ICTL_BUTTON_RELEASE_CB, "button_release")

IupSetAttribute(dial_c, ICTL_MOUSEMOVE_CB, "mousemove")
IupSetAttribute(dial_h, ICTL_MOUSEMOVE_CB, "mousemove")

IupShowXY(dlg,IUP_CENTER,IUP_CENTER)

IupMainLoop()




