From 237027d1ffc461a501420533e7982500632015d9 Mon Sep 17 00:00:00 2001 From: Bill Currie Date: Wed, 4 Feb 2004 02:35:57 +0000 Subject: [PATCH] moving towards object-ized menus :) --- ruamoko/cl_menu/options.qc | 32 ++++++++--------- ruamoko/cl_menu/options_util.h | 18 ++++++++++ ruamoko/cl_menu/options_util.qc | 64 +++++++++++++++++++++++++++++++++ ruamoko/gui/Group.r | 42 ++++++++++++++++++++++ ruamoko/gui/InputLine.r | 7 ++-- ruamoko/gui/Makefile.am | 2 +- ruamoko/gui/Text.r | 35 ++++++++++++++++++ ruamoko/gui/View.r | 11 ++++-- ruamoko/include/Array.h | 2 +- ruamoko/include/Makefile.am | 3 +- ruamoko/include/gui/Group.h | 20 +++++++++++ ruamoko/include/gui/InputLine.h | 13 +++---- ruamoko/include/gui/Point.h | 6 ++-- ruamoko/include/gui/Rect.h | 6 ++-- ruamoko/include/gui/Size.h | 6 ++-- ruamoko/include/gui/Slider.h | 6 ++-- ruamoko/include/gui/Text.h | 18 ++++++++++ ruamoko/include/gui/View.h | 9 ++--- 18 files changed, 253 insertions(+), 47 deletions(-) create mode 100644 ruamoko/gui/Group.r create mode 100644 ruamoko/gui/Text.r create mode 100644 ruamoko/include/gui/Group.h create mode 100644 ruamoko/include/gui/Text.h diff --git a/ruamoko/cl_menu/options.qc b/ruamoko/cl_menu/options.qc index a0b1528a4..a4d5ac5e4 100644 --- a/ruamoko/cl_menu/options.qc +++ b/ruamoko/cl_menu/options.qc @@ -39,9 +39,12 @@ #include "gui/Rect.h" #include "gui/Slider.h" +void () traceon = #29; +void () traceoff = #30; + Slider gamma_slider; Slider viewsize_slider; -Slider mouse_amp_slider; +CvarRange mouse_amp_range; Slider volume_slider; Slider bgmvolume_slider; @@ -313,8 +316,6 @@ MENU_audio_options = integer (string text, integer key) CB_control_options = { - local float val; - switch (text) { case "in_grab": Cbuf_AddText ("toggle in_grab\n"); @@ -356,12 +357,10 @@ CB_control_options = } switch (text) { case "mouseamp": - val = cvar("in_mouse_amp"); - val = min_max_cnt(MIN_MOUSE_AMP, MAX_MOUSE_AMP, MOUSE_AMP_STEP, val, - (key == QFK_RIGHT) && (key != QFK_LEFT)); - cvar_set("in_mouse_amp", ftos(val)); - [mouse_amp_slider setIndex:to_percentage (MIN_MOUSE_AMP, - MAX_MOUSE_AMP, val)]; + if ((key == QFK_RIGHT) && (key != QFK_LEFT)) + [mouse_amp_range inc]; + else + [mouse_amp_range dec]; break; } return 0; @@ -391,11 +390,10 @@ DRAW_control_options = cvar ("m_pitch") < 0 ? "On" : "Off"); bar_pad = y + 90; - Draw_String (x + 70, bar_pad + 10, "Mouse amp:"); - [mouse_amp_slider setBasePos:x y:y]; - [mouse_amp_slider draw]; - Draw_String (x + 150 + (12 + 4) * 8 , bar_pad + 10, - ftos (cvar ("in_mouse_amp"))); + traceon (); + [mouse_amp_range setBasePos:x y:y]; + traceoff (); + [mouse_amp_range draw]; draw_val_item (x + 70, y + 110, spacing, "Freelook", cvar("freelook") ? "On" : "Off"); @@ -422,9 +420,9 @@ MENU_control_options = Menu_CenterPic (160, 4, "gfx/p_option.lmp"); Menu_Draw (DRAW_control_options); - mouse_amp_slider = [[Slider alloc] initWithBounds:[[Rect alloc] initWithComponents:158 :100 :14 * 8 :8] size:100]; - [mouse_amp_slider setIndex: to_percentage (MIN_MOUSE_AMP, MAX_MOUSE_AMP, - cvar("in_mouse_amp"))]; + traceon (); + mouse_amp_range = [[CvarRange alloc] initWithBounds:[[Rect alloc] initWithComponents:70 :100 :232 :8] title:"Mouse amp:" cvar:"in_mouse_amp" min:MIN_MOUSE_AMP max:MAX_MOUSE_AMP step:MOUSE_AMP_STEP]; + traceoff (); MENU_control_binding (); diff --git a/ruamoko/cl_menu/options_util.h b/ruamoko/cl_menu/options_util.h index b6c9d38b7..b66cfe3e5 100644 --- a/ruamoko/cl_menu/options_util.h +++ b/ruamoko/cl_menu/options_util.h @@ -1,6 +1,24 @@ #ifndef __options_util_h #define __options_util_h +#include "gui/Group.h" + +@class Text; +@class Slider; + +@interface CvarRange : Group +{ + Text title; + Text value; + Slider slider; + string name; + float min, max, step; +} +-(id)initWithBounds:(Rect)aRect title:(string)_title cvar:(string)cvname min:(float)_min max:(float)_max step:(float)_step; +-(void)inc; +-(void)dec; +@end + @extern void (integer x, integer y) opt_cursor; @extern void (integer x, integer y, integer spacing, string spacechar, string label, string valstr) draw_item; @extern void (integer x, integer y, integer spacing, string label, string valstr) draw_val_item; diff --git a/ruamoko/cl_menu/options_util.qc b/ruamoko/cl_menu/options_util.qc index fd55df76a..27ae9e273 100644 --- a/ruamoko/cl_menu/options_util.qc +++ b/ruamoko/cl_menu/options_util.qc @@ -28,6 +28,70 @@ #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 diff --git a/ruamoko/gui/Group.r b/ruamoko/gui/Group.r new file mode 100644 index 000000000..ff40a115e --- /dev/null +++ b/ruamoko/gui/Group.r @@ -0,0 +1,42 @@ +#include "gui/Group.h" +#include "gui/Point.h" +#include "Array.h" + +@implementation Group + +- (id) initWithBounds: (Rect)bounds +{ + self = [super initWithBounds:bounds]; + views = [[Array alloc] init]; + return self; +} + +- (void) dealloc +{ + [views dealloc]; +} + +- (View) addView: (View)aView +{ + [views addItem:aView]; +} + +- (void) moveTo: (integer)x y:(integer)y +{ + [self setBasePos: x y:y]; +} + +- (void) setBasePos: (Point) pos +{ + [super setBasePos:pos]; + local Point point = [[Point alloc] initWithComponents:xabs :yabs]; + [views makeObjectsPerformSelector:@selector (setBasePos:) withObject:point]; + [point dealloc]; +} + +- (void) draw +{ + [views makeObjectsPerformSelector:@selector (draw)]; +} + +@end diff --git a/ruamoko/gui/InputLine.r b/ruamoko/gui/InputLine.r index 494c587ca..cd9630df5 100644 --- a/ruamoko/gui/InputLine.r +++ b/ruamoko/gui/InputLine.r @@ -33,10 +33,11 @@ string (inputline_t il) InputLine_GetText = #0; [super free]; } -- (void) setBasePos: (integer) x y: (integer) y +- (void) setBasePos: (Point)pos { - control.xbase = x; - control.ybase = y; + [super setBasePos:pos]; + control.xbase = pos.x; + control.ybase = pos.y; } - (void) setWidth: (integer)visibleWidth diff --git a/ruamoko/gui/Makefile.am b/ruamoko/gui/Makefile.am index 89a6c964d..4ca3e86d0 100644 --- a/ruamoko/gui/Makefile.am +++ b/ruamoko/gui/Makefile.am @@ -27,7 +27,7 @@ EXTRA_LIBRARIES= $(gui_libs) $(QFCC) $(QCFLAGS) $(QCPPFLAGS) -c -o $@ $< libgui_a_SOURCES= \ - InputLine.r Point.r Rect.r Size.r Slider.r View.r + Group.r InputLine.r Point.r Rect.r Size.r Slider.r Text.r View.r libgui_a_AR= $(PAK) -cf CLEANFILES= *.qfo *.o diff --git a/ruamoko/gui/Text.r b/ruamoko/gui/Text.r new file mode 100644 index 000000000..f7c7bf4fa --- /dev/null +++ b/ruamoko/gui/Text.r @@ -0,0 +1,35 @@ +#include "gui/Text.h" +#include "string.h" +#include "draw.h" + +@implementation Text +- (id) initWithBounds: (Rect)aRect +{ + return [self initWithBounds:aRect text:""]; +} + +- (id) initWithBounds: (Rect)aRect text:(string)str +{ + self = [super initWithBounds:aRect]; + text = str_new (); + str_copy (text, str); + return self; +} + +- (void) dealloc +{ + str_free (text); +} + +- (void) setText: (string)str +{ + str_copy (text, str); +} + +- (void) draw +{ + local integer maxlen = xlen / 8; + Draw_nString (xabs, yabs, text, maxlen); +} + +@end diff --git a/ruamoko/gui/View.r b/ruamoko/gui/View.r index 87bcd893e..081c2c282 100644 --- a/ruamoko/gui/View.r +++ b/ruamoko/gui/View.r @@ -28,8 +28,15 @@ - (void) setBasePos: (integer) x y: (integer) y { - xabs = xpos + x; - yabs = ypos + y; + local Point point = [[Point alloc] initWithComponents:x :y]; + [self setBasePos:point]; + [point dealloc]; +} + +- (void) setBasePos: (Point)pos +{ + xabs = xpos + pos.x; + yabs = ypos + pos.y; } -(void) draw diff --git a/ruamoko/include/Array.h b/ruamoko/include/Array.h index cd1a2a2aa..d2cd0420c 100644 --- a/ruamoko/include/Array.h +++ b/ruamoko/include/Array.h @@ -11,7 +11,7 @@ } - (id) init; - (id) initWithIncrement: (integer) inc; -- (void) free; +- (void) dealloc; - (id) getItemAt: (integer) index; - (void) setItemAt: (integer) index item:(id) item; - (void) addItem: (id) item; diff --git a/ruamoko/include/Makefile.am b/ruamoko/include/Makefile.am index c8d258afb..9278fa621 100644 --- a/ruamoko/include/Makefile.am +++ b/ruamoko/include/Makefile.am @@ -10,4 +10,5 @@ include_HEADERS= \ cbuf.h cmd.h cvar.h file.h gib.h hash.h plist.h \ Object.h AutoreleasePool.h Array.h Entity.h List.h ListNode.h Stack.h \ \ - gui/InputLine.h gui/Point.h gui/Rect.h gui/Size.h gui/View.h + gui/Group.h gui/InputLine.h gui/Point.h gui/Rect.h gui/Size.h gui/Text.h \ + gui/View.h diff --git a/ruamoko/include/gui/Group.h b/ruamoko/include/gui/Group.h new file mode 100644 index 000000000..cd8cfc87e --- /dev/null +++ b/ruamoko/include/gui/Group.h @@ -0,0 +1,20 @@ +#ifndef __ruamoko_gui_Group_h +#define __ruamoko_gui_Group_h + +#include "View.h" + +@class Array; + +@interface Group : View +{ + Array views; +} +- (id) initWithBounds: (Rect)bounds; +- (void) dealloc; +- (View) addView: (View)aView; +- (void) moveTo: (integer)x y:(integer)y; +- (void) setBasePos: (Point)pos; +- (void) draw; +@end + +#endif//__ruamoko_gui_Group_h diff --git a/ruamoko/include/gui/InputLine.h b/ruamoko/include/gui/InputLine.h index 6575ce5c0..7493ff2b6 100644 --- a/ruamoko/include/gui/InputLine.h +++ b/ruamoko/include/gui/InputLine.h @@ -1,7 +1,7 @@ -#ifndef __ruamoko_InputLine_h -#define __ruamoko_InputLine_h +#ifndef __ruamoko_gui_InputLine_h +#define __ruamoko_gui_InputLine_h -#include "Object.h" +#include "View.h" struct _inputline_t = {}; // opaque type :) typedef struct _inputline_t [] inputline_t; @@ -23,8 +23,9 @@ struct il_data_t = { }; @class Rect; +@class Point; -@interface InputLine: Object +@interface InputLine: View { struct il_data_t control; inputline_t il; @@ -34,7 +35,7 @@ struct il_data_t = { //-initAt:(Point)p HistoryLines:(integer)l LineSize:(integer)s PromptChar:(integer)prompt; - (void) free; -- (void) setBasePos: (integer) x y: (integer) y; +- (void) setBasePos: (Point)pos; - (void) setWidth: (integer)width; - (void) draw: (BOOL)cursor; @@ -45,4 +46,4 @@ struct il_data_t = { @end -#endif //__ruamoko_inputline_h +#endif //__ruamoko_gui_InputLine_h diff --git a/ruamoko/include/gui/Point.h b/ruamoko/include/gui/Point.h index 4ab58a4de..e8f8e53dc 100644 --- a/ruamoko/include/gui/Point.h +++ b/ruamoko/include/gui/Point.h @@ -1,5 +1,5 @@ -#ifndef __ruamoko_Point_h -#define __ruamoko_Point_h +#ifndef __ruamoko_gui_Point_h +#define __ruamoko_gui_Point_h #include "Object.h" @@ -23,4 +23,4 @@ - (void) setPoint: (Point)aPoint; @end -#endif //__ruamoko_Point_h +#endif //__ruamoko_gui_Point_h diff --git a/ruamoko/include/gui/Rect.h b/ruamoko/include/gui/Rect.h index 863dd79c4..682cd3a7a 100644 --- a/ruamoko/include/gui/Rect.h +++ b/ruamoko/include/gui/Rect.h @@ -1,5 +1,5 @@ -#ifndef __ruamoko_Rect_h -#define __ruamoko_Rect_h +#ifndef __ruamoko_gui_Rect_h +#define __ruamoko_gui_Rect_h #include "Object.h" #include "gui/Point.h" @@ -40,4 +40,4 @@ @end -#endif //__ruamoko_Rect_h +#endif //__ruamoko_gui_Rect_h diff --git a/ruamoko/include/gui/Size.h b/ruamoko/include/gui/Size.h index 4522c7d2a..ac40a79ec 100644 --- a/ruamoko/include/gui/Size.h +++ b/ruamoko/include/gui/Size.h @@ -1,5 +1,5 @@ -#ifndef __ruamoko_Size_h -#define __ruamoko_Size_h +#ifndef __ruamoko_gui_Size_h +#define __ruamoko_gui_Size_h #include "Object.h" @@ -26,4 +26,4 @@ @end -#endif //__ruamoko_Size_h +#endif //__ruamoko_gui_Size_h diff --git a/ruamoko/include/gui/Slider.h b/ruamoko/include/gui/Slider.h index 19a5ff76c..489a57629 100644 --- a/ruamoko/include/gui/Slider.h +++ b/ruamoko/include/gui/Slider.h @@ -1,5 +1,5 @@ -#ifndef __ruamoko_Slider_h -#define __ruamoko_Slider_h +#ifndef __ruamoko_gui_Slider_h +#define __ruamoko_gui_Slider_h #include "View.h" @@ -16,4 +16,4 @@ @end -#endif //__ruamoko_Slider_h +#endif //__ruamoko_gui_Slider_h diff --git a/ruamoko/include/gui/Text.h b/ruamoko/include/gui/Text.h new file mode 100644 index 000000000..8b4051976 --- /dev/null +++ b/ruamoko/include/gui/Text.h @@ -0,0 +1,18 @@ +#ifndef __ruamoko_gui_Text_h +#define __ruamoko_gui_Text_h + +#include "View.h" + +@interface Text: View +{ +@public + string text; +} + +- (id) initWithBounds: (Rect)aRect; +- (id) initWithBounds: (Rect)aRect text:(string)str; +- (void) setText: (string)str; +- (void) draw; +@end + +#endif //__ruamoko_gui_Text_h diff --git a/ruamoko/include/gui/View.h b/ruamoko/include/gui/View.h index 9a2a014d5..0cdeab0bf 100644 --- a/ruamoko/include/gui/View.h +++ b/ruamoko/include/gui/View.h @@ -1,5 +1,5 @@ -#ifndef __ruamoko_View_h -#define __ruamoko_View_h +#ifndef __ruamoko_gui_View_h +#define __ruamoko_gui_View_h #include "Object.h" @@ -19,8 +19,9 @@ - (id) initWithComponents: (integer)x : (integer)y : (integer)w : (integer)h; - (id) initWithOrigin: (Point)anOrigin size: (Size)aSize; - (id) initWithBounds: (Rect)aRect; -- (void) setBasePos: (integer) x y: (integer) y; +- (void) setBasePos: (integer)x y: (integer)y; +- (void) setBasePos: (Point)pos; - (void) draw; @end -#endif //__ruamoko_View_h +#endif //__ruamoko_gui_View_h