From c3d99b47a7557fc8e7fc4f996d85e34b8cab8f66 Mon Sep 17 00:00:00 2001 From: Bill Currie Date: Wed, 4 Feb 2004 06:56:53 +0000 Subject: [PATCH] in_mouse_amp finally working properly :) forced to move to CMV for the indicator because I ran out of params... --- ruamoko/cl_menu/options.qc | 6 +-- ruamoko/cl_menu/options_util.h | 19 +++++++-- ruamoko/cl_menu/options_util.qc | 68 ++++++++++++++++++++++++--------- 3 files changed, 68 insertions(+), 25 deletions(-) diff --git a/ruamoko/cl_menu/options.qc b/ruamoko/cl_menu/options.qc index 286e30f27..02df8bfbe 100644 --- a/ruamoko/cl_menu/options.qc +++ b/ruamoko/cl_menu/options.qc @@ -41,7 +41,7 @@ Slider gamma_slider; Slider viewsize_slider; -CvarRange mouse_amp_range; +RangeSlider mouse_amp_range; Slider volume_slider; Slider bgmvolume_slider; @@ -58,7 +58,7 @@ Slider bgmvolume_slider; #define MIN_MOUSE_AMP 0 #define MAX_MOUSE_AMP 60 -#define MOUSE_AMP_STEP 2 +#define MOUSE_AMP_STEP 1 #define MIN_VOLUME 0 #define MAX_VOLUME 1.5 @@ -415,7 +415,7 @@ MENU_control_options = Menu_CenterPic (160, 4, "gfx/p_option.lmp"); Menu_Draw (DRAW_control_options); - mouse_amp_range = [[CvarRange alloc] initWithBounds:[[Rect alloc] initWithComponents:70 :100 :240 :8] title:"Mouse amp:" cvar:"in_mouse_amp" min:MIN_MOUSE_AMP max:MAX_MOUSE_AMP step:MOUSE_AMP_STEP]; + mouse_amp_range = [[RangeSlider alloc] initWithBounds:[[Rect alloc] initWithComponents:70 :100 :232 :8] title:"Mouse amp:" sliderWidth:14 * 8 :[[CvarRange alloc] initWithCvar:"in_mouse_amp" min:MIN_MOUSE_AMP max:MAX_MOUSE_AMP step:MOUSE_AMP_STEP]]; MENU_control_binding (); diff --git a/ruamoko/cl_menu/options_util.h b/ruamoko/cl_menu/options_util.h index b66cfe3e5..20e0118d2 100644 --- a/ruamoko/cl_menu/options_util.h +++ b/ruamoko/cl_menu/options_util.h @@ -6,15 +6,26 @@ @class Text; @class Slider; -@interface CvarRange : Group +@interface CvarRange : Object +{ + string name; + float min, max, step; +} +-(id)initWithCvar:(string)cvname min:(float)_min max:(float)_max step:(float)_step; +-(void)inc; +-(void)dec; +-(float)value; +-(integer)percentage; +@end + +@interface RangeSlider : Group { Text title; Text value; Slider slider; - string name; - float min, max, step; + CvarRange range; } --(id)initWithBounds:(Rect)aRect title:(string)_title cvar:(string)cvname min:(float)_min max:(float)_max step:(float)_step; +-(id)initWithBounds:(Rect)aRect title:(string)_title sliderWidth:(integer)width :(CvarRange)_range; -(void)inc; -(void)dec; @end diff --git a/ruamoko/cl_menu/options_util.qc b/ruamoko/cl_menu/options_util.qc index 17f7642ce..a14d07977 100644 --- a/ruamoko/cl_menu/options_util.qc +++ b/ruamoko/cl_menu/options_util.qc @@ -35,24 +35,66 @@ @implementation CvarRange --(void)update +-(id)initWithCvar:(string)cvname min:(float)_min max:(float)_max step:(float)_step { - local float val = cvar (name); - [slider setIndex: to_percentage(min, max, val)]; - [value setText:ftos (val)]; + name = str_new (); + str_copy (name, cvname); + min = _min; + max = _max; + step = _step; + + return self; } --(id)initWithBounds:(Rect)aRect title:(string)_title cvar:(string)cvname min:(float)_min max:(float)_max step:(float)_step +-(void)inc +{ + local float val = cvar (name); + val = min_max_cnt (min, max, step, val, 1); + cvar_set (name, ftos (val)); +} + +-(void)dec +{ + local float val = cvar (name); + val = min_max_cnt (min, max, step, val, 0); + cvar_set (name, ftos (val)); +} + +-(float)value +{ + return cvar (name); +} + +-(integer)percentage +{ + return to_percentage(min, max, cvar (name)); +} + +@end + +@implementation RangeSlider + +-(void)update +{ + [slider setIndex:[range percentage]]; + [value setText:ftos ([range value])]; +} + +-(id)initWithBounds:(Rect)aRect title:(string)_title sliderWidth:(integer)width :(CvarRange)_range { local Rect rect; self = [super initWithBounds:aRect]; + + range = _range; rect = [[Rect alloc] initWithComponents:0 :0 :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; + rect.size.width = width; + if (rect.origin.x + rect.size.width > xlen) + rect.size.width = xlen - rect.origin.x; slider = [[Slider alloc] initWithBounds:rect size:100]; rect.origin.x += rect.size.width + 8; @@ -63,12 +105,6 @@ [self addView:slider]; [self addView:value]; - name = str_new (); - str_copy (name, cvname); - min = _min; - max = _max; - step = _step; - [self update]; return self; @@ -76,17 +112,13 @@ -(void)inc { - local float val = cvar (name); - val = min_max_cnt (min, max, step, val, 1); - cvar_set (name, ftos (val)); + [range inc]; [self update]; } -(void)dec { - local float val = cvar (name); - val = min_max_cnt (min, max, step, val, 0); - cvar_set (name, ftos (val)); + [range dec]; [self update]; }