// ui*   hardcoded ui functions
// UI*   aliased ui functions
// UI_*  miscellaneous ui stuff

// UImenu 1:"NAME" 2:[children] 3:[on-show] 4:[on-hide] 5:[ui-children] 6:"TITLE"
UImenu = [
   newui $arg1 [
      @arg5
      uivlist 0 [
         uiclamp 1 1 1 1
         @@(? (>= $numargs 6) [
            uivgradient $c_main1 $c_main2 0 0.04 [
               uiclamp 1 1
               uispace 0.012 0 [
                  uiclamp 1 1
                  uitarget 0.039 0.039 [
                     uihover [uicolor 0xC0C0C0 0.017 0.017] [uicolor 0x909090 0.015 0.015]
                     uihold [uicolor 0x606060 0.011 0.011] ; uirelease [hideui [@@@@@@arg1]]
                  ]; uialign- -1
                  uitext [@@@@arg6] 0.8
                  uitarget 0.039 0.039 [
                     uihover [uicolor 0xC0C0C0 0.017 0.017] [uicolor 0x909090 0.015 0.015]
                     uihold [uicolor 0x606060 0.011 0.011] ; uirelease [hideui [@@@@@@arg1]]
                  ]; uialign- 1
               ]
            ]
         ])
         uicolor $c_menu 0.01 0.01 [
            uiclamp 1 1 1 1
            uispace $UIwindow_padding $UIwindow_padding [
               uiclamp 1 1 1 1
               @@@@arg2
            ]
         ]
      ]
      //uioutline $c_line; uiclamp- 1 1 1 1
   ] $arg3 $arg4
]

// UIbar 1:CLAMP-X 2:CLAMP-Y
UIbar = [
   uiline $c_line
   uiclamp- $arg1 $arg1 $arg2 $arg2
]

// UItriangle 1:0xCOLOR 2:(SIZE-W) 3:(SIZE-H) 4:(ORIENTATION)
UItriangle = [
   if $arg1 [] [arg1 = 0xFFFFFF]
   uigroup [
      uitriangle $arg1 $arg2 $arg3 $arg4
      uitriangleoutline $arg1 $arg2 $arg3 $arg4
   ]
]

// UIcircle 1:0xCOLOR 2:(SIZE)
UIcircle = [
   if $arg1 [] [arg1 = 0xFFFFFF]
   uigroup [
      uicircle $arg1 $arg2
      uicircleoutline $arg1 $arg2
   ]
]

// UItitle 1:[title children] 2:(SIZE-W) 3:(SIZE-H)
UItitle = [
   uivgradient $c_line $c_menu $arg2 $arg3 [
      arg1
      //uioutline $c_line
      uiclamp 1 1 1 1
   ]
]

// UIbuttonarea 1:(STYLE) 2:(BUTTON-WIDTH) 3:(BUTTON-HEIGHT) 4:[children]
UIbuttonarea = [
   uitarget $arg2 $arg3 [
      if (=s $arg1 "") [
         style_button_default
      ] [[style_button_@arg1]]
      uiclamp* 1 1 1 1
      doargs $arg4
   ]
]

// UIbutton 1:(STYLE) 2:[button-children] 3:(BUTTON-WIDTH) 4:(BUTTON-HEIGHT) 5:[on-release] 6:(ALIGNMENT) 7:[children] 8:(USE-PADDING)
UIbutton = [
   uitarget $arg3 $arg4 [
      doargs $arg7
      if (=s $arg1 "") [
         style_button_default
      ] [[style_button_@arg1]]
      uirelease [doargs $arg5]
      uiclamp* 1 1 1 1
      uispace (? (>= $numargs 8) $arg8 $UIbutton_padding) 0 [
         uiclamp 1 1
         uihlist 0.01 [
            uialign $arg6 0
            doargs $arg2
         ]
      ]
   ]
]

// UIcheckbox 1:[condition] 2:(SIZE) 3:0xCOLOR-ON 4:0xCOLOR-OFF 5:[children]
UIcheckbox = [
   if $arg4 [] [arg4 = $c_off]
   if $arg3 [] [arg3 = $c_on1]
   uicolor (? (arg1) $arg3 $arg4) $arg2 $arg2 [
      uimodvgradient 0xFFFFFF 0xB0B0B0
      doargs $arg5
      uioutline $c_line
      uiclamp* 1 1 1 1
   ]
]

// UIradio 1:[condition] 2:(SIZE) 3:0xCOLOR-ON 4:0xCOLOR-OFF 5:[children]
UIradio = [
   if $arg4 [] [arg4 = $c_off]
   if $arg3 [] [arg3 = $c_on2]
   uicircleoutline (? (arg1) $arg3 $arg4) $arg2 [
      uicircle (? (arg1) $arg3 $arg4) $arg2 [
         doargs $arg5
         uiclamp* 1 1 1 1
      ]
   ]
]

// UIarrowbutton 1:(SIZE-W) 2:(SIZE-H) 3:(ORIENTATION) 4:[on-release] 5:(ARROW-%-SIZE) 6:[children]
UIarrowbutton = [
   local arrowsize
   arrowsize = (*f (minf $arg1 $arg2) (minf 1 (maxf 0 $arg5)))
   uitarget $arg1 $arg2 [
      uicolor $c_menu
      doargs $arg6
      style_button_default
      uirelease [doargs $arg4]
      uiclamp* 1 1 1 1
      UItriangle 0 $arrowsize $arrowsize $arg3
   ]
]

// UIhtab 1:(SIZE-W) 2:(SIZE-H) 3:VAR 4:["name" [action] ..] 5:<BUTTON BEHAVIOR: 0=HOVER, 1=PRESS, 2=RELEASE>
UIhtab = [
   uifill $arg1 $arg2 [
      uihlist 0 [
         uiclamp 1 1
         looplist3 v n c $arg4 [
            if (=s $$arg3 $v) [
               uimodvgradient 0xFFFFFF $c_grdmod 0 $arg2 [
                  UIbar 0 1 ; uialign- -1 0
                  UIbar 0 1 ; uialign-  1 0
                  uispace 0.01 0 [uitext (concatword "^f8" $n) 0.7]
               ]
            ] [
               uitarget 0 $arg2 [
                  uispace 0.01 0 [uitext $n 0.7]
                  case $arg5 0 [
                     uihover [$arg3 = $v]
                  ] 1 [
                     uipress [$arg3 = $v]
                  ] 2 [uirelease [$arg3 = $v]]
                  do $c
               ]
            ]
         ]
         uiclamp* 1 1
      ]
      UIbar 1 0 ; uialign- 0 1
   ]
]

// UIvtab 1:(SIZE-W) 2:(SIZE-H) 3:VAR 4:["name" [action] ..] 5:<BUTTON BEHAVIOR: 0=HOVER, 1=PRESS, 2=RELEASE>
UIvtab = [
   uifill $arg1 $arg2 [
      uivlist 0 [
         uiclamp 0 0 1 1
         looplist3 v n c $arg4 [
            if (=s $$arg3 $v) [
               uimodhgradient 0xFFFFFF $c_grdmod $arg1 0 [
                  UIbar 1 ; uialign- 0 -1
                  UIbar 1 ; uialign- 0  1
                  uispace 0.01 0 [uitext (concatword "^f8" $n) 0.7]
               ]
            ] [
               uitarget $arg1 0 [
                  uispace 0.01 0 [uitext $n 0.7]
                  case $arg5 0 [
                     uihover [$arg3 = $v]
                  ] 1 [
                     uipress [$arg3 = $v]
                  ] 2 [uirelease [$arg3 = $v]]
                  do $c
               ]
            ]
         ]
         uiclamp* 1 1 1 1
      ]
      UIbar 0 1 ; uialign- 1
   ]
]

// UIvscroll 1:(SIZE-W) 2:(SIZE-H) 3:(SCROLLSPEED) 4:(ARROW-%-SIZE)
UIvscroll = [
   if $arg4 [] [arg4 = 0.5]
   uivlist 0 [
      uiscrollarrow (-f 0 $arg3) [UIarrowbutton $arg1 $arg1 0 [] $arg4]
      uivscrollbar [
         uifill $arg1 (-f $arg2 (*f $arg1 2)) [uicolor $c_slider ; uiclamp- 1 1 1 1]
         uiscrollbutton [
            uicolor $c_menu $arg1
            style_button_hold5
            uiclamp* 1 1 1 1
            style_generic_linesh 3 0.004 (*f $arg1 0.5)
         ]
      ]
      uiscrollarrow $arg3 [UIarrowbutton $arg1 $arg1 180 [] $arg4]
   ]
]

// UIhscroll 1:(SIZE-W) 2:(SIZE-H) 3:(SCROLLSPEED) 4:(ARROW-%-SIZE)
UIhscroll = [
   if $arg4 [] [arg4 = 0.5]
   uihlist 0 [
      uiscrollarrow (-f 0 $arg3) [UIarrowbutton $arg2 $arg2 90 [] $arg4]
      uihscrollbar [
         uifill (-f $arg1 (*f $arg2 2)) $arg2 [uicolor $c_slider ; uiclamp- 1 1 1 1]
         uiscrollbutton [
            uicolor $c_menu 0 $arg2
            style_button_hold1
            uiclamp* 1 1 1 1
            style_generic_linesv 3 0.004 (*f $arg2 0.5)
         ]
      ]
      uiscrollarrow $arg3 [UIarrowbutton $arg2 $arg2 270 [] $arg4]
   ]
]

// UIvslider 1:VAR 2:MIN 3:MAX 4:STEP 5:X 6:Y 7:[children] 8:[on-change] 9:(ARROW-%-SIZE)
UIvslider = [
   if $arg9 [] [arg9 = 0.5]
   uivlist 0 [
      uisliderarrow -1 [UIarrowbutton $arg5 $arg5 0 [] $arg9]
      uihslider $arg1 (minf $arg3 $arg2) (maxf $arg2 $arg3) $arg4 $arg8 [
         uifill (-f $arg6 (*f $arg5 2)) $arg5 [uicolor $c_slider ; uiclamp- 1 1 1 1]
         uisliderbutton [
            uicolor $c_menu $arg5
            style_button_hold5
            uiclamp* 1 1 1 1
            uispace (? (>= $numargs 10) $arg11 $UIbutton_padding) 0 [arg7]
         ]
      ]
      uisliderarrow 1 [UIarrowbutton $arg5 $arg5 180 [] $arg9]
   ]
]

// UIhslider 1:VAR 2:MIN 3:MAX 4:STEP 5:X 6:Y 7:[children] 8:[on-change] 9:(ARROW-%-SIZE)
UIhslider = [
   if $arg9 [] [arg9 = 0.5]
   uihlist 0 [
      uisliderarrow -1 [UIarrowbutton $arg6 $arg6 90 [] $arg9]
      uihslider $arg1 $arg2 $arg3 $arg4 $arg8 [
         uifill (-f $arg5 (*f $arg6 2)) $arg6 [uicolor $c_slider ; uiclamp- 1 1 1 1]
         uisliderbutton [
            uicolor $c_menu 0 $arg6
            style_button_hold1
            uiclamp* 1 1 1 1
            uispace (? (>= $numargs 10) $arg11 $UIbutton_padding) 0 [arg7]
         ]
      ]
      uisliderarrow 1 [UIarrowbutton $arg6 $arg6 270 [] $arg9]
   ]
]

// UIvcolorslider 1:VAR 2:MIN 3:MAX 4:0xCOLOR1 5:0xCOLOR2 6:X 7:Y 8:[on-change]
UIvcolorslider = [
   uigroup [
      uivgradient $arg5 $arg4 (*f 0.85 $arg6) $arg7 [uioutline $c_line ; uiclamp- 1 1 1 1]
      uifont "default_outline" [uivlist -0.01 [
         loop i (strlen (abs $$arg1)) [
            uicolortext (substr $$arg1 $i 1) (? (|| uihover? uihold?) 0x80FFFFFF 0x40FFFFFF) 0.8
         ]
      ]]
      uivslider $arg1 $arg2 $arg3 1 $arg8 [
         uifill $arg6 (*f 0.98 $arg7)
         uisliderbutton [uiline 0xFFFFFF $arg6 0]
      ]
   ]
]

// UIhcolorslider 1:VAR 2:MIN 3:MAX 4:0xCOLOR1 5:0xCOLOR2 6:X 7:Y 8:[on-change]
UIhcolorslider = [
   uigroup [
      uihgradient $arg4 $arg5 $arg6 (*f 0.85 $arg7) [uioutline $c_line ; uiclamp- 1 1 1 1]
      uihslider $arg1 $arg2 $arg3 1 $arg8 [
         uifill (*f 0.98 $arg6) $arg7
         uisliderbutton [uiline 0xFFFFFF 0 $arg7]
      ]
   ]
]

//UIlistslider 1:VAR 2:COMPARISON 3:[values] 4:X 5:Y 6:[on-change] 7:(ARROW-%-SIZE) 8:[children]
UIlistslider = [
   if $arg7 [] [arg7 = 0.5]
   uihlist 0 [
      UIarrowbutton $arg5 $arg5 90 [
         n = ([listfind@arg2] $arg3 $$arg1 1)
         if (< $n 0) [n = 0] [
            n = (- $n 2)
            if (< $n 0) [n = (+ $n (listlen $arg3))]
         ]
         $arg1 = (at $arg3 $n)
         arg6
      ] $arg7
      uifill (-f $arg4 (*f $arg5 2)) $arg5 [
         uicolor $c_slider
         uiclamp* 1 1 1 1
         if (=s $arg8 "") [
            uitext (|| [[listassoc@arg2] $arg3 $$arg1] [result "custom"]) 0.6
         ] arg8
      ]
      UIarrowbutton $arg5 $arg5 270 [
         n = ([listfind@arg2] $arg3 $$arg1 1)
         n = (if (>= $n 0) [mod (+ $n 2) (listlen $arg3)] [- (listlen $arg3) 2])
         $arg1 = (at $arg3 $n)
         arg6
      ] $arg7
   ]
]

