return to first page linux journal archive
keywordscontents
 
switch (c = getch())
{
case KEY_UP:
    current = (current == 0 ? (COLORS - 1) : current - 1);
    value = 0;
    break;

case KEY_DOWN:
    current = (current == (COLORS - 1) ? 0 : current + 1);
    value = 0;
    break;

case KEY_RIGHT:
    field = (field == 2 ? 0 : field + 1);
    value = 0;
    break;

case KEY_LEFT:
    field = (field == 0 ? 2 : field - 1);
    value = 0;
    break;

case '0': case '1': case '2': case '3': case '4':
case '5': case '6': case '7': case '8': case '9':
    do {
	value = value * 10 + (c - '0');
	c = getch();
    } while
	(isdigit(c));
    if (c != '+' && c != '-' && c != '=')
	beep();
    else
	ungetch(c);
    break;

case '+':
    usebase = 1;
    goto changeit;

case '-':
    value = -value;
    usebase = 1;
    goto changeit;

case '=':
    usebase = 0; 
changeit:
    color_content(current, &red, &green, &blue);
    if (field == 0)
	red = red * usebase + value;
    else if (field == 1)
	green = green * usebase + value;
    else if (field == 2)
	blue = blue * usebase + value;
    init_color(current, red, green, blue);
    break;

case '?':
    erase();
    P("                      RGB Value Editing Help");
    P("You are in the RGB value editor.");
    P("To quit, do 'x' or 'q'");
    Pause();
    erase();
    break;

case 'x':
case 'q':
    break;

default:
    beep();
    break;
}

Listing 2: A Program Fragment Illustrating the Keypad Mapping Feature