/* options_util.qc Utilities for the options menu Copyright (C) 2002 Robin Redeker This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to: Free Software Foundation, Inc. 59 Temple Place - Suite 330 Boston, MA 02111-1307, USA */ #include "draw.h" #include "system.h" #include "string.h" #include "gui/Text.h" #include "gui/Rect.h" #include "gui/Slider.h" #include "options_util.h" @implementation CvarRange -(void)update { local float val = cvar (name); [slider setIndex: to_percentage(min, max, val)]; [value setText:ftos (val)]; } -(id)initWithBounds:(Rect)aRect title:(string)_title cvar:(string)cvname min:(float)_min max:(float)_max step:(float)_step { local Rect rect; self = [super initWithBounds:aRect]; rect = [[Rect alloc] initWithComponents:0 :0 :(integer)strlen (_title) * 8 :8]; title = [[Text alloc] initWithBounds:rect text:_title]; rect.origin.x += rect.size.width + 8; rect.size.width = ((_max - _min) / _step + 2) * 8 / 2; slider = [[Slider alloc] initWithBounds:rect size:100]; rect.origin.x += rect.size.width + 8; rect.size.width = xlen - rect.origin.x; value = [[Text alloc] initWithBounds:rect]; [self addView:title]; [self addView:slider]; [self addView:value]; name = str_new (); str_copy (name, cvname); min = _min; max = _max; step = _step; [self update]; return self; } -(void)inc { local float val = cvar (name); val = min_max_cnt (min, max, step, val, 1); cvar_set (name, ftos (val)); [self update]; } -(void)dec { local float val = cvar (name); val = min_max_cnt (min, max, step, val, 0); cvar_set (name, ftos (val)); [self update]; } @end /* opt_cursor function for drawing the cursor */ void (integer x, integer y) opt_cursor = { // use time becaus we want a nice rotaing cursor Draw_Character (x, y, 12 + (integer) (time * 4) & 1); }; /* draw_item Draws a item with a specific spacing between label and value to position x, y. Used as helper function for draw_val_item. */ void (integer x, integer y, integer spacing, string spacechar, string label, string valstr) draw_item = { local integer i; Draw_String (x, y, label); for (i = x + (integer) strlen (label) * 8; i < (x+spacing); i += 8) { Draw_String (i, y, spacechar); } Draw_String (x + spacing, y, valstr); }; /* draw_val_item Draws a nice menu item. Use this function for a consistent look of menu items! Example: