A spinner box allows the user to set a numerical value and, in particular, either a float or an int. For our example, we allow the user to set the base color of the geometry and, in turn, we create three spinners corresponding to the three primaries red, green and blue. We create and add each of the three spinners to the color 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 (colorPanel in this case). The second parameter is a string that provides a text label for the spinner box. We use the strings "Red", "Green" and "Blue", respectively. The third parameter sets the data type of the values provided by the spinner. We use GLUI_SPINNER_FLOAT for each of the spinners. (Note that GLUI_SPINNER_INT is used for int type data.) 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 send the value to the appropriate place in our program. The fifth parameter is an integer that provides an identifier for the spinner; the id is passed to the callback function. We establish a callback handler with the next parameter for each of the three spinners. Thus, to distinguish between the spinners, we use 1, 2 and 3 as the ids, respectively. 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.
The next function call to
set_float_limits
sets the limits of the spinner values. The first two parametes passed to the function set, respectively, the lower and upper limits. The third parameter establishes 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.