Пример #1
0
menu *sous_menu(menu *m, int choix)
{
	menu *res = NULL;

	if(choix <= 0 || choix > m->nb_choix)
		res = m;
	else if(choix == m->nb_choix)
		res = menu_parent(m);
	else
		res = m->choix[choix];

	return res;
}
Пример #2
0
int main_menu(keystate *k)
{
	int continuer = 1;
	int choix = 1;
	int mx = 0, my = 0;
	menu *m;
	FILE *flux_menu = NULL;
	FSOUND_STREAM *zik;

	/* On cache le curseur, ni vu ni connu j'tembrouille */
	SDL_ShowCursor(0);

	k->precedent[ECHAP] = 1;
	k->precedent[QUITTER] = 1;

	flux_menu = fopen("main.menu", "r");
	m = charger_menu(flux_menu);
	fclose(flux_menu);

	zik = charger_musique("musics/space_mario.wav", 100, -1);
	//FSOUND_Stream_Play(FSOUND_FREE, zik);
	while(continuer)
	{
		glClear(GL_COLOR_BUFFER_BIT);
		/* Dessin du fond, du menu et recuperation de la position du pointeur souris
		et de l'etat des touches */
		//draw_sprite(0, 0, LARGEUR_FENETRE, HAUTEUR_FENETRE, 3, 0, 1, 0, 1);
		SDL_GetMouseState(&mx, &my);
		my = HAUTEUR_FENETRE - my;
		maj_keystate(k, &continuer);
		afficher_menu(m, choix);

		/* L'utilisateur clique sur la croix ou presse echap */
		if(continuer == 0)
		{
			//FSOUND_Stream_Stop(zik);
			//FSOUND_Stream_Close(zik);
			return QUITTER;
		}

		/* Feuille de l'arbre */
		else if(m->nb_choix == 0)
		{
			//FSOUND_Stream_Stop(zik);
			//FSOUND_Stream_Close(zik);
			return m->valeur;
		}

		else
		{
			if((k->actuel[ENTRER] && k->precedent[ENTRER] == 0) || 
				(k->actuel[DROITE] && k->precedent[DROITE] == 0))
			{
				m = sous_menu(m, choix);
				choix = 1;
			}

			else if(k->actuel[GAUCHE] && k->precedent[GAUCHE] == 0)
			{
				m = menu_parent(m);
				choix = 1;
			}

			else if(k->actuel[BAS] && k->precedent[BAS] == 0)
				choix++;

			else if(k->actuel[HAUT] && k->precedent[HAUT] == 0)
				choix--;

			else if(k->actuel[CLIC_G] && k->precedent[CLIC_G] == 0)
			{
				/*************** si la souris est dessu ******************/
				m = sous_menu(m, choix);
				choix = 1;
			}

			if(choix < 1)
				choix = m->nb_choix;
			else if(choix > m->nb_choix)
				choix = 1;
		}

		my_sleep(1);
		SDL_GL_SwapBuffers();
	}

	//FSOUND_Stream_Stop(zik);
	//FSOUND_Stream_Close(zik);

	return m->valeur;
}
Пример #3
0
/**
 * Navigate state.
 * Navigates the menu structure using the following buttons:
 *  - up => go to previous item
 *  - down => go to next item
 *  - left => go to parent item
 *  - right => go to child item
 */
static QState mmi_navigate(struct mmi_ao *me)
{
    switch (Q_SIG(me)) {
    case Q_ENTRY_SIG:
        update_screen(me);
        return Q_HANDLED();
    case Q_EXIT_SIG:
        return Q_HANDLED();
    case SIG_ENCODER:
        switch (menu_cur->typ) {
        case MENU_TYP_PARAM:
            if (modify_param(menu_cur->param, Q_PAR(me), me->shift)) {
                print_param(menu_cur->param);
                if (menu_cur->cmd != CMD_NONE)
                    QActive_post((QActive *) me, SIG_MMI_CMD, menu_cur->cmd);
            }
            break;
        default:
            break;
        }
        return Q_HANDLED();
    case SIG_MMI_CMD:
        return execute_cmd(me, Q_PAR(me));
    case SIG_MMI_SHOW_MSG:
        return Q_TRAN(mmi_show_msg);
    case SIG_KEY_PRESS:
        switch (Q_PAR(me)) {
        case KEY_UP:
            // Go to previous item
            if (menu_prev())
                update_screen(me);
            break;
        case KEY_DOWN:
            // Go to next item
            if (menu_next())
                update_screen(me);
            break;
        case KEY_LEFT:
            // Go to parent item
            if (menu_parent())
                update_screen(me);
            break;
        case KEY_RIGHT:
            // Go to sub item
            if (menu_sub())
                update_screen(me);
            break;
        case KEY_ENTER:
            me->shift = 1;
            switch (menu_cur->typ) {
            case MENU_TYP_CMD:
                // Execute command
                if (menu_cur->cmd)
                    QActive_post((QActive *) me, SIG_MMI_CMD, menu_cur->cmd);
                break;
            case MENU_TYP_SUB:
                // Go to sub item
                if (menu_sub())
                    update_screen(me);
                break;
            default:
                break;
            }
            break;
        }
        return Q_HANDLED();
    case SIG_KEY_RELEASE:
        switch (Q_PAR(me)) {
        case KEY_ENTER:
            me->shift = 0;
        default:
            break;
        }
        return Q_HANDLED();
    case SIG_PROG_START:
        return Q_TRAN(mmi_busy);
        break;
    }

    return Q_SUPER(&QHsm_top);
}