Ejemplo n.º 1
0
void main_menu() {
  int selected_menu_entry;
  do {
    selected_menu_entry = display_menu();
    if(selected_menu_entry == 1) {
      // run the game
      run();
    } else if(selected_menu_entry == 2) {
      // display the highscores
      show_highscores();
    } else if(selected_menu_entry == 3) {
      // display a dialog which explains the controls of the game
      display_controls();
    } else if(selected_menu_entry == 4) {
      // display a dialog which explains the elements of the game
      display_help();
    } else if(selected_menu_entry == 5) {
      // clear highscores
      if(clear_score_dialog() == 1) {
          clear_highscore();
      }
    }
    // leave if the menu entry "exit" is chosen
  } while(selected_menu_entry != 6);
}
static void balance_volumes(void)
{
	struct control *control;
	long left, right;
	int err;

	control = get_focus_control(TYPE_PVOLUME | TYPE_CVOLUME);
	if (!control || !(control->flags & HAS_VOLUME_1))
		return;
	if (control->flags & TYPE_PVOLUME) {
		err = snd_mixer_selem_get_playback_volume(control->elem, control->volume_channels[0], &left);
		if (err < 0)
			return;
		err = snd_mixer_selem_get_playback_volume(control->elem, control->volume_channels[1], &right);
		if (err < 0)
			return;
	} else {
		err = snd_mixer_selem_get_capture_volume(control->elem, control->volume_channels[0], &left);
		if (err < 0)
			return;
		err = snd_mixer_selem_get_capture_volume(control->elem, control->volume_channels[1], &right);
		if (err < 0)
			return;
	}
	left = (left + right) / 2;
	if (control->flags & TYPE_PVOLUME) {
		snd_mixer_selem_set_playback_volume(control->elem, control->volume_channels[0], left);
		snd_mixer_selem_set_playback_volume(control->elem, control->volume_channels[1], left);
	} else {
		snd_mixer_selem_set_capture_volume(control->elem, control->volume_channels[0], left);
		snd_mixer_selem_set_capture_volume(control->elem, control->volume_channels[1], left);
	}
	display_controls();
}
void refocus_control(void)
{
	if (focus_control_index < controls_count) {
		snd_mixer_selem_get_id(controls[focus_control_index].elem, current_selem_id);
		current_control_flags = controls[focus_control_index].flags;
	}

	display_controls();
}
static void change_control_relative(int delta, unsigned int channels)
{
	struct control *control;

	control = get_focus_control(TYPE_PVOLUME | TYPE_CVOLUME | TYPE_ENUM);
	if (!control)
		return;
	if (control->flags & TYPE_ENUM)
		change_enum_relative(control, delta);
	else
		change_volume_relative(control, delta, channels);
	display_controls();
}
static void change_control_to_percent(int value, unsigned int channels)
{
	struct control *control;

	control = get_focus_control(TYPE_PVOLUME | TYPE_CVOLUME | TYPE_ENUM);
	if (!control)
		return;
	if (control->flags & TYPE_ENUM)
		change_enum_to_percent(control, value);
	else
		change_volume_to_percent(control, value, channels);
	display_controls();
}
static void toggle_switches(unsigned int type, unsigned int channels)
{
	struct control *control;
	unsigned int switch_1_mask;
	int (*get_func)(snd_mixer_elem_t *, snd_mixer_selem_channel_id_t, int *);
	int (*set_func)(snd_mixer_elem_t *, snd_mixer_selem_channel_id_t, int);
	snd_mixer_selem_channel_id_t channel_ids[2];
	int left, right;
	int err;

	control = get_focus_control(type);
	if (!control)
		return;
	if (type == TYPE_PSWITCH) {
		switch_1_mask = HAS_PSWITCH_1;
		get_func = snd_mixer_selem_get_playback_switch;
		set_func = snd_mixer_selem_set_playback_switch;
		channel_ids[0] = control->pswitch_channels[0];
		channel_ids[1] = control->pswitch_channels[1];
	} else {
		switch_1_mask = HAS_CSWITCH_1;
		get_func = snd_mixer_selem_get_capture_switch;
		set_func = snd_mixer_selem_set_capture_switch;
		channel_ids[0] = control->cswitch_channels[0];
		channel_ids[1] = control->cswitch_channels[1];
	}
	if (!(control->flags & switch_1_mask))
		channels = LEFT;
	if (channels & LEFT) {
		err = get_func(control->elem, channel_ids[0], &left);
		if (err < 0)
			return;
	}
	if (channels & RIGHT) {
		err = get_func(control->elem, channel_ids[1], &right);
		if (err < 0)
			return;
	}
	if (channels & LEFT)
		set_func(control->elem, channel_ids[0], !left);
	if (channels & RIGHT)
		set_func(control->elem, channel_ids[1], !right);
	display_controls();
}
static void on_handle_key(int key)
{
	switch (key) {
	case 27:
	case KEY_CANCEL:
	case KEY_F(10):
		mixer_widget.close();
		break;
	case KEY_F(1):
	case KEY_HELP:
	case 'H':
	case 'h':
	case '?':
		show_help();
		break;
	case KEY_F(2):
	case '/':
		create_proc_files_list();
		break;
	case KEY_F(3):
		set_view_mode(VIEW_MODE_PLAYBACK);
		break;
	case KEY_F(4):
		set_view_mode(VIEW_MODE_CAPTURE);
		break;
	case KEY_F(5):
		set_view_mode(VIEW_MODE_ALL);
		break;
	case '\t':
		set_view_mode((enum view_mode)((view_mode + 1) % VIEW_MODE_COUNT));
		break;
	case KEY_F(6):
	case 'S':
	case 's':
		create_card_select_list();
		break;
	case KEY_REFRESH:
	case 12:
	case 'L':
	case 'l':
		clearok(mixer_widget.window, TRUE);
		display_controls();
		break;
	case KEY_LEFT:
	case 'P':
	case 'p':
		if (focus_control_index > 0) {
			--focus_control_index;
			refocus_control();
		}
		break;
	case KEY_RIGHT:
	case 'N':
	case 'n':
		if (focus_control_index < controls_count - 1) {
			++focus_control_index;
			refocus_control();
		}
		break;
	case KEY_PPAGE:
		change_control_relative(5, LEFT | RIGHT);
		break;
	case KEY_NPAGE:
		change_control_relative(-5, LEFT | RIGHT);
		break;
#if 0
	case KEY_BEG:
	case KEY_HOME:
		change_control_to_percent(100, LEFT | RIGHT);
		break;
#endif
	case KEY_LL:
	case KEY_END:
		change_control_to_percent(0, LEFT | RIGHT);
		break;
	case KEY_UP:
	case '+':
	case 'K':
	case 'k':
	case 'W':
	case 'w':
		change_control_relative(1, LEFT | RIGHT);
		break;
	case KEY_DOWN:
	case '-':
	case 'J':
	case 'j':
	case 'X':
	case 'x':
		change_control_relative(-1, LEFT | RIGHT);
		break;
	case '0': case '1': case '2': case '3': case '4':
	case '5': case '6': case '7': case '8': case '9':
		change_control_to_percent((key - '0') * 10, LEFT | RIGHT);
		break;
	case 'Q':
	case 'q':
		change_control_relative(1, LEFT);
		break;
	case 'Y':
	case 'y':
	case 'Z':
	case 'z':
		change_control_relative(-1, LEFT);
		break;
	case 'E':
	case 'e':
		change_control_relative(1, RIGHT);
		break;
	case 'C':
	case 'c':
		change_control_relative(-1, RIGHT);
		break;
	case 'M':
	case 'm':
		toggle_mute(LEFT | RIGHT);
		break;
	case 'B':
	case 'b':
	case '=':
		balance_volumes();
		break;
	case '<':
	case ',':
		toggle_mute(LEFT);
		break;
	case '>':
	case '.':
		toggle_mute(RIGHT);
		break;
	case ' ':
		toggle_capture(LEFT | RIGHT);
		break;
	case KEY_IC:
	case ';':
		toggle_capture(LEFT);
		break;
	case KEY_DC:
	case '\'':
		toggle_capture(RIGHT);
		break;
	}
}
Ejemplo n.º 8
0
Archivo: app.c Proyecto: baylesj/cs411
/*
 * main():
 * Control user flow, get input and control our rocket launcher!
 */
int main(int argc, char **argv)
{
    int ch = 0;	/* Store our input files */
    WINDOW *win;

    /* beginning ncurses */
    initscr(); // init the ncurses
    clear();
    noecho();  // stop pressed keys from displaying on screen
    raw();
    win = newwin(30,10,0,0);
    keypad(win, TRUE);
    keypad(stdscr,TRUE);
    refresh();

    /* init the driver */
    dcml_context * ctx = dcml_init();

    /* check init to  make sure it was successful */
    if(!ctx) {
        printf("ERROR failed to get dcml context!\n");
        return 1;
    }
    display_controls();
    while (ch !=ESCAPE_KEY) {

        ch = get_input();/* get input from the user */
        clear();
        display_controls();

        switch(ch) {

        case KEY_LEFT:
            printw("Move left. \n");
            dcml_left(ctx, DURATION);
            break;
        case KEY_RIGHT:
            printw("Move right. \n");
            dcml_right(ctx, DURATION);
            break;
        case KEY_UP:
            printw("Move up.\n");
            dcml_up(ctx, DURATION);
            break;
        case KEY_DOWN:
            printw("Move down.\n");
            dcml_down(ctx, DURATION);
            break;
        case SPACE_KEY:
            printw("Firing the missile!\n");
            dcml_fire(ctx);
            break;

        default:
            /* do nothing */
            break;
        }

        refresh();
    }

    /* cleanup after use */
    dcml_exit(ctx);

    /* ending ncurses mode */
    endwin();
    return 0;
}