moving towards object-ized menus :)

This commit is contained in:
Bill Currie 2004-02-04 02:35:57 +00:00
parent f79e34628b
commit 237027d1ff
18 changed files with 253 additions and 47 deletions

View file

@ -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 ();

View file

@ -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;

View file

@ -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

42
ruamoko/gui/Group.r Normal file
View file

@ -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

View file

@ -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

View file

@ -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

35
ruamoko/gui/Text.r Normal file
View file

@ -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

View file

@ -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

View file

@ -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;

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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