2006-12-16 14:42:55 +00:00
|
|
|
#include "impulse_menu.h"
|
|
|
|
#include "string.h"
|
|
|
|
|
|
|
|
@implementation MenuItem
|
|
|
|
- (id) initWithText:(string)txt
|
|
|
|
{
|
|
|
|
self = [super init];
|
|
|
|
text = txt;
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (string) text
|
|
|
|
{
|
|
|
|
return text;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) select
|
|
|
|
{
|
|
|
|
}
|
|
|
|
@end
|
|
|
|
|
|
|
|
@implementation FlagMenuItem
|
|
|
|
- (id) initWithText:(string)txt flagObject:(id)flg
|
|
|
|
{
|
|
|
|
self = [super initWithText: txt];
|
|
|
|
flag = flg;
|
2006-12-19 14:17:58 +00:00
|
|
|
return self;
|
2006-12-16 14:42:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (string) text
|
|
|
|
{
|
2010-08-23 05:08:37 +00:00
|
|
|
local integer state = (integer)[flag state];
|
2006-12-16 14:42:55 +00:00
|
|
|
return sprintf ("[%c] %s", state ? '#' : ' ', [super text]);
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) select
|
|
|
|
{
|
2010-08-23 05:08:37 +00:00
|
|
|
[flag toggle];
|
2006-12-16 14:42:55 +00:00
|
|
|
}
|
|
|
|
@end
|
|
|
|
|
|
|
|
@implementation CommandMenuItem
|
|
|
|
- (id) initWithText:(string)txt object:(id)obj selector:(SEL)sel
|
|
|
|
{
|
|
|
|
self = [super initWithText: txt];
|
|
|
|
object = obj;
|
|
|
|
selector = sel;
|
2006-12-19 14:17:58 +00:00
|
|
|
return self;
|
2006-12-16 14:42:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void) select
|
|
|
|
{
|
|
|
|
[object performSelector:selector];
|
|
|
|
}
|
|
|
|
@end
|
|
|
|
|
|
|
|
@implementation ImpulseMenu
|
|
|
|
- (id) initWithText:(string)txt
|
|
|
|
{
|
|
|
|
self = [super init];
|
|
|
|
text = txt;
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (integer) impulse: (integer) imp
|
|
|
|
{
|
|
|
|
return imp;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (string) text
|
|
|
|
{
|
|
|
|
return sprintf ("%s", text);
|
|
|
|
}
|
|
|
|
@end
|
|
|
|
|
|
|
|
@implementation ImpulseValueMenu
|
|
|
|
- (integer) impulse: (integer) imp
|
|
|
|
{
|
|
|
|
if (imp < 1 || imp > 10)
|
|
|
|
return imp;
|
|
|
|
if (imp == 10)
|
|
|
|
imp = 0;
|
|
|
|
value = value * 10 + imp;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (string) text
|
|
|
|
{
|
|
|
|
return sprintf ("%s%i", text, value);
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) clearValue
|
|
|
|
{
|
|
|
|
value = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (integer) value
|
|
|
|
{
|
|
|
|
return value;
|
|
|
|
}
|
|
|
|
@end
|
|
|
|
|
|
|
|
@implementation ImpulseListMenu
|
|
|
|
- (integer) impulse: (integer) imp
|
|
|
|
{
|
|
|
|
if (imp < 1 || imp > 10)
|
|
|
|
return imp;
|
|
|
|
if (items[imp - 1])
|
|
|
|
[items[imp - 1] select];
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (string) text
|
|
|
|
{
|
|
|
|
local string str = text;
|
|
|
|
local string s;
|
|
|
|
local integer i;
|
2006-12-20 10:51:16 +00:00
|
|
|
local string [10] is;
|
|
|
|
local integer max_len = 0, len;
|
2006-12-16 14:42:55 +00:00
|
|
|
|
2006-12-20 10:51:16 +00:00
|
|
|
for (i = 0; i < 10; i++) {
|
|
|
|
if (!items[i])
|
|
|
|
break;
|
|
|
|
is[i] = [items[i] text];
|
|
|
|
len = strlen(is[i]);
|
|
|
|
if (len > max_len)
|
|
|
|
max_len = len;
|
|
|
|
}
|
|
|
|
for (i = 0; i < 10; i++) {
|
|
|
|
if (!items[i])
|
2006-12-16 14:42:55 +00:00
|
|
|
break;
|
2006-12-20 10:51:16 +00:00
|
|
|
s = is[i];
|
2006-12-16 14:42:55 +00:00
|
|
|
if (s)
|
2006-12-20 10:51:16 +00:00
|
|
|
str = sprintf (sprintf ("%%s\n[%%i] %%-%ds", max_len),
|
|
|
|
str, (i + 1) % 10, s);
|
2006-12-16 14:42:55 +00:00
|
|
|
else
|
|
|
|
str = sprintf ("%s\n", str);
|
|
|
|
}
|
|
|
|
return str;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) addItem:(MenuItem) item
|
|
|
|
{
|
|
|
|
local integer i;
|
|
|
|
|
|
|
|
for (i = 0; i < 10; i++) {
|
|
|
|
if (!items[i]) {
|
|
|
|
items[i] = item;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
@end
|