1#include "key.h" 2#include "sound.h" 3#include "string.h" 4 5#include "gui/Text.h" 6#include "gui/InputLine.h" 7#include "CvarStringView.h" 8#include "CvarString.h" 9 10@implementation CvarStringView 11 12-enter: (string) line 13{ 14 [cvstring setString: line]; 15 return self; 16} 17 18-(void)update 19{ 20 [ilb setText: [cvstring value]]; 21} 22 23-(id)initWithBounds:(Rect)aRect title:(string)_title inputLength: (int)length :(CvarString *)_cvstring 24{ 25 Rect rect; 26 27 self = [super initWithBounds:aRect]; 28 29 cvstring = _cvstring; 30 31 rect = makeRect (0, 0, strlen (_title) * 8, 8); 32 title = [[Text alloc] initWithBounds:rect text:_title]; 33 34 rect.origin.x += rect.size.width + 8; 35 rect.origin.y = -8; 36 rect.size.width = (aRect.size.width - rect.size.width) / 8 - 2; 37 rect.size.height = 4; // history lines (stupid interface:P) 38 ilb = [[InputLineBox alloc] initWithBounds:rect promptCharacter:' ']; 39 [ilb setEnter: self message:@selector(enter:)]; 40 41 [self addView:title]; 42 [self addView:ilb]; 43 44 [self update]; 45 46 return self; 47} 48 49- (int) keyEvent:(int)key unicode:(int)unicode down:(int)down 50{ 51 if (active) { 52 if (key == QFK_ESCAPE) { 53 [self update]; 54 active = 0; 55 [ilb cursor: NO]; 56 } else { 57 [ilb processInput:(key >= 256 ? key : unicode)]; 58 if (key == QFK_RETURN) { 59 [self update]; 60 active = 0; 61 [ilb cursor: NO]; 62 } 63 } 64 return 1; 65 } else { 66 if (key == QFK_RETURN) { 67 active = 1; 68 [ilb cursor: YES]; 69 } 70 } 71 return 0; 72} 73 74@end 75