// Update an 'int' value, direction = 1 for increment, -1 for decrement static void update_int_value(const CMenuItem *mi, int direction) { // do update *(mi->value) += int_incr * direction; // Limit new value to defined bounds if ( mi->type & MENUITEM_F_UNSIGNED) { if (*(mi->value) < 0) *(mi->value) = 0; if ( mi->type & MENUITEM_F_MIN) { if (*(mi->value) < MENU_MIN_UNSIGNED(mi->arg)) *(mi->value) = MENU_MIN_UNSIGNED(mi->arg); } } else { if (*(mi->value) < -9999) *(mi->value) = -9999; if ( mi->type & MENUITEM_F_MIN) { if (*(mi->value) < MENU_MIN_SIGNED(mi->arg)) *(mi->value) = MENU_MIN_SIGNED(mi->arg); } } if (*(mi->value) > 99999) *(mi->value) = 99999; if ( mi->type & MENUITEM_F_UNSIGNED) { if ( mi->type & MENUITEM_F_MAX) { if (*(mi->value) > MENU_MAX_UNSIGNED(mi->arg)) *(mi->value) = MENU_MAX_UNSIGNED(mi->arg); } } else { if ( mi->type & MENUITEM_F_MAX) { if (*(mi->value) > MENU_MAX_SIGNED(mi->arg)) *(mi->value) = MENU_MAX_SIGNED(mi->arg); } } // execute custom callback and on_change functions do_callback(mi); // force menu redraw gui_menu_redraw=1; }
void script_update_menu() { int j = 0; for (int i = 0; i < SCRIPT_NUM_PARAMS; i++) { int p = script_param_order[i]; if (!p) continue; p--; int min = MENU_MIN_SIGNED(script_range_values[p]); int max = MENU_MAX_SIGNED(script_range_values[p]); if (script_range_types[p] == 0) // no min/max, use some default range { min = -1000; max = 1000; } // if our name is short, fill it with spaces int n = strlen(script_params[p]); int k; for (k = n; k < MAX_PARAM_NAME_LEN-2; k++) script_params[p][k] = ' '; script_params[p][k] = 0; script_setup_param(j++, script_params[p], &conf_script_vars[p], min, max); } }
static int increment_factor() { // Increase int_incr // Returns 1 if value changed. // Get info about the current menu item int item_flags = curr_menu->menu[gui_menu_curr_item].type; int item_type = item_flags & MENUITEM_MASK; int item_arg = curr_menu->menu[gui_menu_curr_item].arg; int item_val = *(curr_menu->menu[gui_menu_curr_item].value); // If state / value menu pair get info from value entry if (item_type == MENUITEM_STATE_VAL_PAIR) { CMenuItem *c = (CMenuItem*)(curr_menu->menu[gui_menu_curr_item].value); item_flags = c[0].type; item_type = item_flags & MENUITEM_MASK; item_arg = c[0].arg; item_val = *(c[0].value); } // Calculate max allowed value for int_incr // Default is 10000 for positive int values, 1000 for negative values or 1 otherwise int max = ((item_type == MENUITEM_INT) || (item_flags & MENUITEM_DECIMAL)) ? ((item_val<0)?1000:10000) : 1; // If an int value has a defined MIN / MAX range then adjust int_incr max to fit the range int vmax = 0; if ( item_flags & MENUITEM_F_MINMAX ) { if ( item_flags & MENUITEM_F_UNSIGNED ) { vmax = MAX(MENU_MIN_UNSIGNED(item_arg),MENU_MAX_UNSIGNED(item_arg)); } else { vmax = MAX(abs(MENU_MIN_SIGNED(item_arg)),abs(MENU_MAX_SIGNED(item_arg))); } } // Default for SD type (item_arg holds max allowed value) if (item_flags & MENUITEM_SD_INT) { vmax = item_arg; } // If a max value has been set adjust accordingly if (vmax > 0) { max = menu_calc_max_increment_factor(vmax); } // Default for HH:MM:SS type if (item_flags & MENUITEM_HHMMSS) { max = 100; } // Adjust value if (int_incr < max) { int_incr *= 10; return 1; } if (int_incr > max) { int_incr = max; return 1; } return 0; }