A spinner box is one of the many interactive controls available with GLUI. We create and add a spinner to a panel with a call to the function
add_spinner_to_panel
The function requires six parameters. The first parameter is the pointer to the panel to which the spinner is added (mainPanel in this example). The second parameter is a string that provides a text label for the spinner box. Since the spinner is allowing our user to set the transparency value, we label the box with the string "Alpha". The third parameter sets the data type of the values provided by the spinner. The two choices are
GLUI_SPINNER_FLOAT and GLUI_SPINNER_INT
The fourth parameter is a pointer to a "live variable", if any, that receives the spinner value. We set this parameter to NULL since we are using a handler to pass the value to the appropriate place. The fifth parameter is an integer that provides an identifier for the spinner; the id is passed to the callback function. We are establishing a callback handler with the next parameter, which does not need the id. Thus, we set the id to any integer such as -1. The name of the callback function, which is a pointer, is passed as the sixth and final parameter. Our callback function is invoked as the spinner changes value through user interaction.
A spinner box provides numerical values. We need to set the limits of the values, which is done with a call to one of the following functions
set_float_limits and set_int_limits
The first parameter to either function sets the lower limit while the second parameter sets the upper limit. The third parameter given in a function call sets how to handle values outside these limits. In particular, the parameter GLUI_LIMIT_CLAMP simply means the spinner value will not be allowed to go outside the limits. An alternate parameter is GLUI_LIMIT_WRAP, which means a value above the upper limit is set to the lower limit and conversely.
Last, we initialize the spinner value with a call to
set_float_val
as seen in this code.