quakeforge/ruamoko/cl_menu/CvarStringView.r
Bill Currie 30bd1c0134 Create classes for inputing cvar strings and script the network menu.
Hitting enter after inputting text is currently broken, but that's because
support for it was never put in the inputline wrapper code.
2011-03-25 18:26:10 +09:00

62 lines
1.2 KiB
R

#include "key.h"
#include "sound.h"
#include "string.h"
#include "gui/Text.h"
#include "gui/InputLine.h"
#include "CvarStringView.h"
#include "CvarString.h"
@implementation CvarStringView
-(void)update
{
[ilb setText: [cvstring value]];
}
-(id)initWithBounds:(Rect)aRect title:(string)_title inputLength: (int)length :(CvarString *)_cvstring
{
Rect rect;
self = [super initWithBounds:aRect];
cvstring = _cvstring;
rect = makeRect (0, 0, strlen (_title) * 8, 8);
title = [[Text alloc] initWithBounds:rect text:_title];
rect.origin.x += rect.size.width + 8;
rect.origin.y = -8;
rect.size.width = (aRect.size.width - rect.size.width) / 8 - 2;
rect.size.height = 4; // history lines (stupid interface:P)
ilb = [[InputLineBox alloc] initWithBounds:rect promptCharacter:' '];
[self addView:title];
[self addView:ilb];
[self update];
return self;
}
- (int) keyEvent:(int)key unicode:(int)unicode down:(int)down
{
if (active) {
if (key == QFK_ESCAPE) {
[self update];
active = 0;
[ilb cursor: NO];
} else {
[ilb processInput:(key >= 256 ? key : unicode)];
}
return 1;
} else {
if (key == QFK_RETURN) {
active = 1;
[ilb cursor: YES];
}
}
return 0;
}
@end