Ejemplo n.º 1
0
static int do_ok(int msg)
{
char *cmd;
	__popdown(POP_Y,POP_X,POP_H,popwidth);
	switch(menu[item].type)
	{
	case TYPE_MENU:do_menu(menu[item].arg);break;
	case TYPE_CMD:
    if(ischoice(menu[item].msg)){
	cmd=getChoiceCmd(menu[item].msg);
	if(!cmd)break;
	}
	else
	{
    cmd=getItemCmd(menu[item].msg);
    cmd=getItemCmd(menu[item].msg);
	}
    cmd=expand(cmd);
	if(msg=='e'){strcpy(myline,cmd);do_cmd(edit_cmdline(myline));}
	else do_cmd(cmd);
	break;
	case TYPE_MSG:__msgbox(MSG_Y,MSG_X,MSG_H,MSG_W,menu[item].arg);break;
	case TYPE_EDITMENU:do_editmenu();break;
	}
	__popup(POP_Y,POP_X,POP_H,popwidth);
	printmenu();
return 0;
}
Ejemplo n.º 2
0
static int plugins_menu(void* param)
{
    (void)param;
    MENUITEM_STRINGLIST(plugins_menu_items, ID2P(LANG_PLUGINS), NULL,
                        ID2P(LANG_PLUGIN_GAMES),
                        ID2P(LANG_PLUGIN_APPS), ID2P(LANG_PLUGIN_DEMOS));
    const char *folder;
    int retval = GO_TO_PREVIOUS;
    int selection = 0, current = 0;
    while (retval == GO_TO_PREVIOUS)
    {
        selection = do_menu(&plugins_menu_items, &current, NULL, false);
        switch (selection)
        {
            case 0:
                folder = PLUGIN_GAMES_DIR;
                break;
            case 1:
                folder = PLUGIN_APPS_DIR;
                break;
            case 2:
                folder = PLUGIN_DEMOS_DIR;
                break;
            default:
                return selection;
        }
        retval = rockbox_browse(folder, SHOW_PLUGINS);
    }
    return retval;
}
Ejemplo n.º 3
0
static int
ask_yesno(const char *title)
{
	int i;
	i = do_menu(yesno_menu, 2, 0, title);
	return (i == 0 ? 1 : 0);
}
Ejemplo n.º 4
0
static int cmd_setup(int ac, char **av)
{
	__console_alloc();
	do_menu(&testmenu);
	__console_free();
	return 0;
}
Ejemplo n.º 5
0
int main_sprtplte_callback(DIALOG * d, int ic)
{
    struct sprite_palette **spmp;
    struct sprite_palette *spm;

    spmp = d->dp;
    spm = *spmp;

    sprite_edit_function = SEF_NOTHING;

    sprintf(sprite_popup[0].text, "Sprite 0x%03x", ic);

    // try to center the popup menu on the cursor...
    do_menu(sprite_popup, mouse_x-56, mouse_y-50);

    switch (sprite_edit_function)
    {
    case (SEF_EDIT): // get
	sprite_get(ic, current_sprite, spm);
	spm->last_selected = ic;
	return D_REDRAW;
	break;

    case (SEF_REPLACE): // put
	sprite_put(ic, current_sprite, spm);
	spm->last_selected = ic; // redundant
	return D_REDRAW;
	break;

    case (SEF_NOTHING):
    default:
	break;
    }
    return(D_O_K);
}
Ejemplo n.º 6
0
int do_menu(const char *pname)
{
  bx_list_c *menu = (bx_list_c *)SIM->get_param(pname, NULL);
  while (1) {
    menu->get_choice()->set(0);
    int status = menu->text_ask(stdin, stderr);
    if (status < 0) return status;
    bx_param_num_c *choice = menu->get_choice();
    if (choice->get() < 1)
      return choice->get();
    else {
      int index = choice->get() - 1;  // choosing 1 means list[0]
      bx_param_c *chosen = menu->get(index);
      assert(chosen != NULL);
      if (chosen->get_enabled()) {
        if (SIM->get_init_done() && !chosen->get_runtime_param()) {
          fprintf(stderr, "\nWARNING: parameter not available at runtime!\n");
        } else if (chosen->get_type() == BXT_LIST) {
          char chosen_pname[80];
          chosen->get_param_path(chosen_pname, 80);
          do_menu(chosen_pname);
        } else {
          chosen->text_ask(stdin, stderr);
        }
      }
    }
  }
}
Ejemplo n.º 7
0
static void ft_load_font(char *file)
{
    int current_font_id;
    enum screen_type screen = SCREEN_MAIN;
#if NB_SCREENS > 1
    MENUITEM_STRINGLIST(menu, ID2P(LANG_CUSTOM_FONT), NULL, 
                        ID2P(LANG_MAIN_SCREEN), ID2P(LANG_REMOTE_SCREEN))
    switch (do_menu(&menu, NULL, NULL, false))
    {
        case 0: /* main lcd */
            screen = SCREEN_MAIN;
            set_file(file, (char *)global_settings.font_file, MAX_FILENAME);
            break;
        case 1: /* remote */
            screen = SCREEN_REMOTE;
            set_file(file, (char *)global_settings.remote_font_file, MAX_FILENAME);
            break;
    }
#else
    set_file(file, (char *)global_settings.font_file, MAX_FILENAME);
#endif
    splash(0, ID2P(LANG_WAIT));
    current_font_id = global_status.font_id[screen];
    if (current_font_id >= 0)
        font_unload(current_font_id);
    current_font_id = font_load(file);
    if(screen==SCREEN_MAIN)
        font_set_ui(current_font_id);
    global_status.font_id[screen] = current_font_id;
    viewportmanager_theme_changed(THEME_UI_VIEWPORT);
}    
Ejemplo n.º 8
0
int time_screen(void* ignored)
{
    (void)ignored;
    int nb_lines, font_h, ret;
    menu_was_pressed = false;

    push_current_activity(ACTIVITY_TIMEDATESCREEN);

    FOR_NB_SCREENS(i)
    {
        viewport_set_defaults(&clock_vps[i], i);
#ifdef HAVE_BUTTONBAR
        if (global_settings.buttonbar)
        {
            clock_vps[i].height -= BUTTONBAR_HEIGHT;
        }
#endif
        nb_lines = viewport_get_nb_lines(&clock_vps[i]);

        gui_synclist_set_viewport_defaults(&menu[i], i);
        /* force time to be drawn centered */
        clock_vps[i].flags |= VP_FLAG_ALIGN_CENTER;

        font_h = font_get(clock_vps[i].font)->height;
        nb_lines -= 2; /* at least 2 lines for menu */
        if (nb_lines > 4)
            nb_lines = 4;
        if (nb_lines >= 2)
            clock_vps[i].height = nb_lines*font_h;
        else /* disable the clock_vps drawing */
            clock_vps[i].height = 0;
        menu[i].y += clock_vps[i].height;
        menu[i].height -= clock_vps[i].height;
        draw_timedate(&clock_vps[i], &screens[i]);
    }

#ifdef SAMSUNG_YH820
    /* some hardware revisions of the yh820 have a rtc problem: if you try to set
       the time/date it will leave the player in an absolute unresponsive state
       which can only be reverted by removing the battery. Setting time/date
       should be prohibited on this targets. Fortunately we can autodetect these,
       because they always report "02:02:02" as time.
    */
    struct tm *tm = get_time();
    if (tm->tm_year==102 && tm->tm_hour==2 && tm->tm_min==2 && tm->tm_sec==2) {
        splash(4*HZ, "Can't set time/date due to hardware issues!");
        return 0;
    }
#endif

    ret = do_menu(&time_menu, NULL, menu, false);
    pop_current_activity();
    /* see comments above in the button callback */
    if (!menu_was_pressed && ret == GO_TO_PREVIOUS)
        return 0;
    return ret;
}
Ejemplo n.º 9
0
void spi_init() {
  if((outft = open("/dev/ttyUSB0", O_RDWR))==-1){
    perror("open");
  }

  do_menu('#');
  do_menu('m');
  do_menu('5');
  do_menu('3');
  do_menu('1');
  do_menu('2');
  do_menu('1');
  do_menu('2');
  do_menu('2');

  do_menu('W');

}
Ejemplo n.º 10
0
static void
ask_ok(const char *title, ...)
{
	va_list ap;

	va_start(ap, title);
	do_menu(ok_menu, 1, 1, title, ap);
	va_end(ap);

	return;
}
Ejemplo n.º 11
0
static void
menu_menupkgs(const char *title)
{
	int			i = 0;
	char		*outpkg, *querystr;
	struct menuoption *options;
	char		plist_with_comment[] = "%-20s %s";
	char		plist_without_comment[] = "%-20s";

	/*options = calloc(plisthead->P_count + 1, sizeof(struct menuoption));
	SLIST_FOREACH(plist, plisthead->P_Plisthead, next) {
		if (criterion != NULL) {
			if (!criterion(plist))
				continue;
		}
		if (plist->comment != NULL)
			querystr = plist_with_comment;
		else
			querystr = plist_without_comment;
		if (asprintf(&outpkg, querystr, plist->full, plist->comment) > 0) {
			options[i].m_name = outpkg;
			options[i].m_argv = plist;
			options[i].m_action = package_menu;
			i++;
		} else {
			endwin();
			err(1, "asprintf");
		}
	}
        */
	if (asprintf(&outpkg, "Back to main menu") > 0) {
		options[i].m_name = outpkg;
		options[i].m_argv = NULL;
		options[i].m_action = NULL;
		i++;
	} else {
		endwin();
		err(1, "asprintf");
	}
	
	if (i <= 1)
		ask_ok("No packages found.");
	else
		while (do_menu(options, i, 0, title) == 0)
			{}

	for (; i > 0; i--)
		free(options[i-1].m_name);
	free(options);

	return;
}
Ejemplo n.º 12
0
static int miscscrn(void * param)
{
    const struct menu_item_ex *menu = (const struct menu_item_ex*)param;
    int result = do_menu(menu, NULL, NULL, false);
    switch (result)
    {
        case GO_TO_PLAYLIST_VIEWER:
        case GO_TO_WPS:
            return result;
        default:
            return GO_TO_ROOT;
    }
}
Ejemplo n.º 13
0
uint8_t function_menu() {
  uint8_t func_number;

  display_menu();
  func_number = read_menu();
  if (func_number == 0) {
	  return 0;
  } else {
	  do_menu(func_number);
          lcd_MEM2_string(Done_str);	// "Done.\n"
	  lcd_refresh();
	  return 1;
  }
}
Ejemplo n.º 14
0
int main(void) {
    size_t cmd_buf_sz = 20;
    char buf[cmd_buf_sz];
    jokedb_struct jokedb;

    // load with default jokes (array of joke_struct's)
    load_default_jokes(&jokedb);

    // send INITMSG
    send(INITMSG, cgc_strlen(INITMSG));
    
    // send MENU
    do_menu();
    
    while (1) {
        // send ROOTPROMPT
        cgc_memset(buf, '\0', cmd_buf_sz);
        prompt_user(ROOTPROMPT, buf, cmd_buf_sz);

        // receive user input and check for COMMAND
        if (streq(buf, "LIST") == 0) {
            do_list(&jokedb);
        } else if (streq(buf, "ADD") == 0) {
            do_add(&jokedb);
        } else if (streq(buf, "COUNT") == 0) {
            do_count(&jokedb);
        } else if (streq(buf, "SHOW") == 0) {
            do_show(&jokedb);
        } else if (streq(buf, "HELP") == 0) {
            do_help();
        } else if (streq(buf, "QUIT") == 0) {
            do_quit();
        } else {
            do_menu();
        }
    }
}
Ejemplo n.º 15
0
int enemy_path_menu(int num)
{
 int ans;
 MENU temp_menu[]=
 {
	 //text            proc    menu-child     flags      dp
	{ "Delete",  delete_enemy_path,      NULL,          0,         NULL},
	{ NULL,         NULL,      NULL,          0,         NULL}
	};
	
	
    ans=do_menu(temp_menu,mouse_x,mouse_y);

	return D_REDRAW;
}
Ejemplo n.º 16
0
static void do_opt_menu(void) {
  int mi, num_items;
  bool done = false;

  /* set a couple of defaults */
  num_items = sizeof(opt_menu) / sizeof(char*);
  mi = 0;
  snprintf((char *)opt_menu[0], 17, "Frameskip      %1d", frameskip);
  snprintf((char *)opt_menu[1], 17, "TV Out       %s", (TVState ? " ON" : "OFF"));
  snprintf((char *)opt_menu[2], 17, "TV Standard %s", (TVStd ? " PAL" : "NTSC"));
  snprintf((char *)opt_menu[3], 17, "TV Interlaced  %s", (TVInt ? "Y" : "N"));
  while (!done) {
    mi = do_menu(OPT_MENU_TITLE, (char**) opt_menu, num_items, mi);
    switch(mi) {
      case OM_ITEM_FRAME:
        frameskip=(frameskip+1)%10;
        snprintf((char *)opt_menu[0], 17, "Frameskip      %1d", frameskip);
        break;
      case OM_ITEM_TV:
        (*(volatile unsigned short *)(0x30800))^=0x4;
        TVState = !TVState;
        if(TVState)(*(volatile unsigned short *)(0x3058E))=0x2000;
        else (*(volatile unsigned short *)(0x3058A))=0x2000;
        snprintf((char *)opt_menu[1], 17, "TV Out       %s", (TVState ? " ON" : "OFF"));
        break;
      case OM_ITEM_TVS:
        (*(volatile unsigned short *)(0x30800))^=0x8000;
        TVStd = !TVStd;
        snprintf((char *)opt_menu[2], 17, "TV Standard %s", (TVStd ? " PAL" : "NTSC"));
        break;
      case OM_ITEM_TVI:
        (*(volatile unsigned short *)(0x30800))^=0x4000;
        TVInt = !TVInt;
        snprintf((char *)opt_menu[3], 17, "TV Interlaced  %s", (TVInt ? "Y" : "N"));
        break;
      case OM_ITEM_MO:
        do_opt2_menu();
        break;
      case MENU_CANCEL:
        done = true;
        break;
      case OM_ITEM_BACK:
        done = true;
        break;
    }
  }
}
Ejemplo n.º 17
0
int main_thread(SceSize args, void *argp)
{
	SceUID block_id;
	void *vram;

	block_id = sceKernelAllocPartitionMemory(4, "debugmenu", PSP_SMEM_Low, 512*272*2, NULL);
	if(block_id < 0)
	{
		Kprintf("Error could not allocate memory buffer 0x%08X\n", block_id);
		goto error;
	}
	 
	vram = (void*) (0xA0000000 | (unsigned int) sceKernelGetBlockHeadAddr(block_id));
	g_eventflag = sceKernelCreateEventFlag("DebugMenuEvent", 0, 0, NULL);
	if(g_eventflag < 0)
	{
		Kprintf("Could not create event flag %08X\n", g_eventflag);
		goto error;
	}

	//sceCtrlRegisterButtonCallback(0, PSP_CTRL_HOME, button_callback, NULL);
	sceCtrlRegisterButtonCallback(3, TRIGGER, button_callback, NULL);
	while(1)
	{
		unsigned int bits;
		if(sceKernelWaitEventFlag(g_eventflag, START_MENU,
					PSP_EVENT_WAITOR | PSP_EVENT_WAITCLEAR, &bits, NULL) < 0)
		{
			break;
		}
		sceCtrlSetButtonMasks(0xFFFF, 1);  // Mask lower 16bits
		sceCtrlSetButtonMasks(0x10000, 2); // Always return HOME key
		sceDisplaySetFrameBufferInternal(0, vram, 512, 0, 1);
		pspDebugScreenInitEx(vram, 0, 0);
		do_menu();
		sceDisplaySetFrameBufferInternal(0, 0, 512, 0, 1);
		sceCtrlSetButtonMasks(0x10000, 0); // Unset HOME key
		sceCtrlSetButtonMasks(0xFFFF, 0);  // Unset mask
		sceKernelClearEventFlag(g_eventflag, ~START_MENU);
	}

error:
	sceKernelExitDeleteThread(0);

	return 0;
}
Ejemplo n.º 18
0
int soundemitor_menu(int num)
{
 int ans;
 MENU temp_menu[]=
 {
	 //text            proc    menu-child     flags      dp
	{ "Edit",    edit_soundemitor,      NULL,          0,         NULL},
	{ "",  NULL,      NULL,          0,         NULL},
	{ "Delete",  delete_soundemitor,      NULL,          0,         NULL},
	{ NULL,         NULL,      NULL,          0,         NULL}
	};
	
	current_soundemitor=num;	

    ans=do_menu(temp_menu,mouse_x,mouse_y);

	return D_REDRAW;
}
Ejemplo n.º 19
0
int enemy_menu(int num)
{
 int ans;
 MENU temp_menu[]=
 {
	 //text            proc    menu-child     flags      dp
	{ "Edit",      edit_enemy,      NULL,          0,         NULL},
	{ "Path", edit_enemy_path_data,      NULL,          0,         NULL},
	{ "",  NULL,      NULL,          0,         NULL},
	{ "Delete",  delete_enemy,      NULL,          0,         NULL},
	{ NULL,         NULL,      NULL,          0,         NULL}
	};
	
	current_enemy=num;	
	
    ans=do_menu(temp_menu,mouse_x,mouse_y);
		
	return D_REDRAW;
}
Ejemplo n.º 20
0
int time_screen(void* ignored)
{
    (void)ignored;
    int nb_lines, font_h, ret;
    menu_was_pressed = false;

    push_current_activity(ACTIVITY_TIMEDATESCREEN);

    FOR_NB_SCREENS(i)
    {
        viewport_set_defaults(&clock_vps[i], i);
#ifdef HAVE_BUTTONBAR
        if (global_settings.buttonbar)
        {
            clock_vps[i].height -= BUTTONBAR_HEIGHT;
        }
#endif
        nb_lines = viewport_get_nb_lines(&clock_vps[i]);

        gui_synclist_set_viewport_defaults(&menu[i], i);
        /* force time to be drawn centered */
        clock_vps[i].flags |= VP_FLAG_ALIGN_CENTER;

        font_h = font_get(clock_vps[i].font)->height;
        nb_lines -= 2; /* at least 2 lines for menu */
        if (nb_lines > 4)
            nb_lines = 4;
        if (nb_lines >= 2)
            clock_vps[i].height = nb_lines*font_h;
        else /* disable the clock_vps drawing */
            clock_vps[i].height = 0;
        menu[i].y += clock_vps[i].height;
        menu[i].height -= clock_vps[i].height;
        draw_timedate(&clock_vps[i], &screens[i]);
    }

    ret = do_menu(&time_menu, NULL, menu, false);
    pop_current_activity();
    /* see comments above in the button callback */
    if (!menu_was_pressed && ret == GO_TO_PREVIOUS)
        return 0;
    return ret;
}
Ejemplo n.º 21
0
static int load_context_screen(int selection)
{
    const struct menu_item_ex *context_menu = NULL;
    if ((root_menu__[selection]->flags&MENU_TYPE_MASK) == MT_RETURN_VALUE)
    {
        int item = root_menu__[selection]->value;
        context_menu = items[item].context_menu;
    }
    /* special cases */
    else if (root_menu__[selection] == &info_menu)
    {
        context_menu = &system_menu;
    }
    
    if (context_menu)
        return do_menu(context_menu, NULL, NULL, false);
    else
        return GO_TO_PREVIOUS;
}
Ejemplo n.º 22
0
static void do_editmenu(void)
{
char *env,*p,*p1;
int len;
char *cmd;
cmd=getItemCmd(menu[item].msg);
p=strstr(cmd,";;");
p[0]=0;
p1=expand(cmd);
len=strlen(p1);
env=malloc(len+1);
strcpy(env,p1);
p[0]=';';
  makeup_menu(menu[item].msg,env,p+2);
  do_menu(&menu_edit);
envs_local=0;
args_local=0;
free(env);
}
Ejemplo n.º 23
0
static int 
do_cmd(MENU *mptr,XO *xo,int x,int y)
{
   usint mode;
   void *p;
   int (*func) ();

   if(mptr->umode < 0)
   {
      p = DL_get(mptr->func);
      if(!p) 
        return 0;
      mptr->func = p;
      mptr->umode = - (mptr->umode);
   }

   switch (mptr->umode)
   {
      case POPUP_SO :
        p = DL_get(mptr->func);
        if(!p) return 0;
        mptr->func = p;
        mptr->umode = POPUP_FUN;
        func = p;
        mode = (*func) ();
        return -1;
      case POPUP_MENU :
//        sprintf(t,"【%s】",mptr->desc);
        vs_restore(sl);
        return do_menu((MENU *)mptr->func,xo,x,y);
      case POPUP_XO :
        func = mptr->func;
        mode = (*func) (xo);
        return -1;
      case POPUP_FUN :
        func = mptr->func;
        mode = (*func) ();
        return -1;
   }
   
   return -1;
}
Ejemplo n.º 24
0
static int load_context_screen(int selection)
{
    const struct menu_item_ex *context_menu = NULL;
    int retval = GO_TO_PREVIOUS;
    push_current_activity(ACTIVITY_CONTEXTMENU);
    if ((root_menu__[selection]->flags&MENU_TYPE_MASK) == MT_RETURN_VALUE)
    {
        int item = root_menu__[selection]->value;
        context_menu = items[item].context_menu;
    }
    /* special cases */
    else if (root_menu__[selection] == &info_menu)
    {
        context_menu = &system_menu;
    }
    
    if (context_menu)
        retval = do_menu(context_menu, NULL, NULL, false);
    pop_current_activity();
    return retval;
}
Ejemplo n.º 25
0
int onplay(char* file, int attr, int from, bool hotkey)
{
    const struct menu_item_ex *menu;
    onplay_result = ONPLAY_OK;
    context = from;
    selected_file = file;
    selected_file_attr = attr;
    int menu_selection;
#ifdef HAVE_HOTKEY
    if (hotkey)
        return execute_hotkey(context == CONTEXT_WPS);
#else
    (void)hotkey;
#endif

    push_current_activity(ACTIVITY_CONTEXTMENU);
    if (context == CONTEXT_WPS)
        menu = &wps_onplay_menu;
    else
        menu = &tree_onplay_menu;
    menu_selection = do_menu(menu, NULL, NULL, false);
    pop_current_activity();

    switch (menu_selection)
    {
        case GO_TO_WPS:
            return ONPLAY_START_PLAY;
        case GO_TO_ROOT:
        case GO_TO_MAINMENU:
            return ONPLAY_MAINMENU;
        case GO_TO_PLAYLIST_VIEWER:
            return ONPLAY_PLAYLIST;
#ifdef HAVE_PICTUREFLOW_INTEGRATION
        case GO_TO_PICTUREFLOW:
            return ONPLAY_PICTUREFLOW;
#endif
        default:
            return onplay_result;
    }
}
Ejemplo n.º 26
0
/*---------------------------------------------------------------------------*
 *	data from keyboard available, read and process it
 *---------------------------------------------------------------------------*/
static void
kbdrdhdl(void)
{
	int ch = getch();

	if(ch == ERR)
	{
		dolog(LL_ERR, "kbdrdhdl: ERROR, read error on controlling tty, errno = %d!", errno);
		error_exit(1, "kbdrdhdl: ERROR, read error on controlling tty, errno = %d!", errno);
	}

	switch(ch)
	{
		case 0x0c:	/* control L */
			wrefresh(curscr);
			break;

		case '\n':
		case '\r':
			do_menu();
			break;
	}
}
Ejemplo n.º 27
0
/*
 * do_user_menu - create the user menu on the screen.
 *
 * Returns USER_MENU_QUIT if the user selected "quit", otherwise
 * returns zero.
 *
 * Note: this is the only non-static function in this file at the
 * moment.  In the future I may turn do_menu/etc into a proper API, in
 * which case they'll be exposed as well.
 *
 */
int do_user_menu(void) {
  int mi, ret, num_items;
  bool done = false;

  /* set defaults */
  ret = 0; /* return value */
  mi = 0; /* initial menu selection */
  num_items = sizeof(main_menu) / sizeof(char*);

  /* loop until we should exit menu */
  while (!done) {
    /* get item selection */
    mi = do_menu(MAIN_MENU_TITLE, (char**) main_menu, num_items, mi);
    
    /* handle selected menu item */
    switch (mi) {
      case MM_ITEM_QUIT:
        ret = USER_MENU_QUIT;
      case MENU_CANCEL:
      case MM_ITEM_BACK:
        done = true;
        break;
      case MM_ITEM_LOAD:
        do_slot_menu(true);
        break;
      case MM_ITEM_SAVE:
        do_slot_menu(false);
        break;
      case MM_ITEM_OPT:
        do_opt_menu();
        break;
    }
  }

  /* return somethin' */
  return ret;
}
Ejemplo n.º 28
0
/*
 * do_slot_menu - prompt the user for a load/save memory slot
 */
static void do_slot_menu(bool is_load) {
  int i, mi, ret, num_items;
  bool done = false;
  char *title;

  /* set defaults */
  ret = 0; /* return value */
  mi = 0; /* initial menu selection */
  num_items = sizeof(slot_menu) / sizeof(char*);
  
  /* create menu items (the last two are file and previous menu,
   * so don't populate those) */
  for (i = 0; i < num_items - 1; i++)
    slot_info((char*) slot_menu[i], 17, i);

  /* set menu title */
  if(is_load) title = "Load State";
  else title = "Save State";

  /* loop until we should exit menu */
  while (!done) {
    /* get item selection */
    mi = do_menu(title, (char**) slot_menu, num_items, mi);

    /* handle selected menu item */
    done = true;
    if (mi != MENU_CANCEL && mi != SM_ITEM_BACK) {
      done = do_slot(mi, is_load);

      /* if we couldn't save the state file, then print out an
       * error message */
      if (!is_load && !done)
      printf("Couldn't save state file.");
    }
  }
}
Ejemplo n.º 29
0
int
main(int argc, char **argv)
{
	BITMAP *bmp = NULL;
	int x, y, mx, my;
	int result, mode = GFX_AUTODETECT;

	allegro_init();
	install_keyboard();

	if (install_mouse() < 0) {
		allegro_message("This example requires a mouse to run!");
		return -1;
	}

	jpgalleg_init();

	if (cpu_capabilities & CPU_MMX)
		popup_menu[2].flags = D_SELECTED;

	if ((argc > 1) && (!strcmp(argv[1], "-window")))
		mode = GFX_AUTODETECT_WINDOWED;

	set_color_depth(32);
	if (set_gfx_mode(mode, 640, 480, 0, 0)) {
		set_color_depth(16);
		if (set_gfx_mode(mode, 640, 480, 0, 0)) {
			set_color_depth(15);
			if (set_gfx_mode(mode, 640, 480, 0, 0)) {
				allegro_message("Unable to init truecolor 640x480 gfx mode: %s", allegro_error);
				return -1;
			}
		}
	}

	clear_to_color(screen, gui_mg_color);
	show_mouse(screen);
	
	alert("JPG image load/save example for " JPGALLEG_VERSION_STRING, NULL, "Press right mouse button for contextual menu, ESC to quit.", "Ok", NULL, 0, 0);

	while (!key[KEY_ESC]) {
		x = mouse_x;
		y = mouse_y;
		get_mouse_mickeys(&mx, &my);
		mx /= 2;
		my /= 2;

		bmp = settings_dialog[PREVIEW].dp;

		if (bmp) {
			old_sx = sx;
			old_sy = sy;
			if (bmp->w > SCREEN_W) {
				if ((x == 0) && (mx < 0) && (sx > 0))
					sx = MAX(0, sx + mx);
				if ((x == SCREEN_W - 1) && (mx > 0) && (sx < bmp->w - SCREEN_W - 1))
					sx = MIN(sx + mx, bmp->w - SCREEN_W - 1);
				if (key[KEY_LEFT] && (sx > 0))
					sx = MAX(0, sx - 8);
				if (key[KEY_RIGHT] && (sx < bmp->w - SCREEN_W - 1))
					sx = MIN(sx + 8, bmp->w - SCREEN_W - 1);
			}
			if (bmp->h > SCREEN_H) {
				if ((y == 0) && (my < 0) && (sy > 0))
					sy = MAX(0, sy + my);
				if ((y == SCREEN_H - 1) && (my > 0) && (sy < bmp->h - SCREEN_H - 1))
					sy = MIN(sy + my, bmp->h - SCREEN_H - 1);
				if (key[KEY_UP] && (sy > 0))
					sy = MAX(0, sy - 8);
				if (key[KEY_DOWN] && (sy < bmp->h - SCREEN_H - 1))
					sy = MIN(sy + 8, bmp->h - SCREEN_H - 1);
			}
			if ((sx != old_sx) || (sy != old_sy))
				draw_image(bmp, sx, sy);
		}
		if (mouse_b & 0x2) {
			result = do_menu(popup_menu, x, y);
			while(key[KEY_ESC])
				;
			if (result == 3)
				break;
			draw_image((BITMAP *)settings_dialog[PREVIEW].dp, sx, sy);
		}
	}

	if (bmp)
		destroy_bitmap(bmp);

	return 0;
}
Ejemplo n.º 30
0
/* ------------------------------------------------------------------------*/
static int select_bookmark(const char* bookmark_file_name, bool show_dont_resume, char** selected_bookmark)
{
    struct bookmark_list* bookmarks;
    struct gui_synclist list;
    int item = 0;
    int action;
    size_t size;
    bool exit = false;
    bool refresh = true;
    int ret = BOOKMARK_FAIL;

    bookmarks = plugin_get_buffer(&size);
    bookmarks->buffer_size = size;
    bookmarks->show_dont_resume = show_dont_resume;
    bookmarks->filename = bookmark_file_name;
    bookmarks->start = 0;
    bookmarks->show_playlist_name
        = strcmp(bookmark_file_name, RECENT_BOOKMARK_FILE) == 0;
    gui_synclist_init(&list, &get_bookmark_info, (void*) bookmarks, false, 2, NULL);
    if(global_settings.talk_menu)
        gui_synclist_set_voice_callback(&list, bookmark_list_voice_cb);
    gui_synclist_set_title(&list, str(LANG_BOOKMARK_SELECT_BOOKMARK), 
        Icon_Bookmark);

    while (!exit)
    {
        
        if (refresh)
        {
            int count = get_bookmark_count(bookmark_file_name);
            bookmarks->total_count = count;

            if (bookmarks->total_count < 1)
            {
                /* No more bookmarks, delete file and exit */
                splash(HZ, ID2P(LANG_BOOKMARK_LOAD_EMPTY));
                remove(bookmark_file_name);
                *selected_bookmark = NULL;
                return BOOKMARK_FAIL;
            }

            if (bookmarks->show_dont_resume)
            {
                count++;
                item++;
            }

            gui_synclist_set_nb_items(&list, count * 2);

            if (item >= count)
            {
                /* Selected item has been deleted */
                item = count - 1;
                gui_synclist_select_item(&list, item * 2);
            }

            buffer_bookmarks(bookmarks, bookmarks->start);
            gui_synclist_draw(&list);
            cond_talk_ids_fq(VOICE_EXT_BMARK);
            gui_synclist_speak_item(&list);
            refresh = false;
        }

        list_do_action(CONTEXT_BOOKMARKSCREEN, HZ / 2,
                       &list, &action, LIST_WRAP_UNLESS_HELD);
        item = gui_synclist_get_sel_pos(&list) / 2;

        if (bookmarks->show_dont_resume)
        {
            item--;
        }

        if (action == ACTION_STD_CONTEXT)
        {
            MENUITEM_STRINGLIST(menu_items, ID2P(LANG_BOOKMARK_CONTEXT_MENU),
                NULL, ID2P(LANG_BOOKMARK_CONTEXT_RESUME), 
                ID2P(LANG_BOOKMARK_CONTEXT_DELETE));
            static const int menu_actions[] = 
            {
                ACTION_STD_OK, ACTION_BMS_DELETE
            };
            int selection = do_menu(&menu_items, NULL, NULL, false);
            
            refresh = true;

            if (selection >= 0 && selection <= 
                (int) (sizeof(menu_actions) / sizeof(menu_actions[0])))
            {
                action = menu_actions[selection];
            }
        }

        switch (action)
        {
        case ACTION_STD_OK:
            if (item >= 0)
            {
                talk_shutup();
                *selected_bookmark = bookmarks->items[item - bookmarks->start];
                return BOOKMARK_SUCCESS;
            }
            exit = true;
            ret = BOOKMARK_SUCCESS;
            break;

        case ACTION_TREE_WPS:
        case ACTION_STD_CANCEL:
            exit = true;
            break;

        case ACTION_BMS_DELETE:
            if (item >= 0)
            {                
                const char *lines[]={
                    ID2P(LANG_REALLY_DELETE)
                };
                const char *yes_lines[]={
                    ID2P(LANG_DELETING)
                };

                const struct text_message message={lines, 1};
                const struct text_message yes_message={yes_lines, 1};

                if(gui_syncyesno_run(&message, &yes_message, NULL)==YESNO_YES)
                {                    
                    delete_bookmark(bookmark_file_name, item);
                    bookmarks->reload = true;
                }
                refresh = true;
            }
            break;

        default:
            if (default_event_handler(action) == SYS_USB_CONNECTED)
            {
                ret = BOOKMARK_USB_CONNECTED;
                exit = true;
            }

            break;
        }
    }

    talk_shutup();
    *selected_bookmark = NULL;
    return ret;
}