menu_st *menu_handle_item(menu_st *menulist, int num) { item_st *item; /* out of bounds */ if(num < 0 || num >= menulist->num_items) { Dprintf("menu_handle_item::Invalid item"); return menulist; } item = &menulist->items[num]; menulist->lastsel = -1; if(SUB_MENU_HEADER & item->op) { /* Destroy timer */ menu_handle_timer(menulist, 1); /* create another sub-menu */ menulist = menu_right_transition(menulist, item); } else if(ACTION_MENU & item->op) { /* execute the function */ void (* fp)(void); fp = item->action; (* fp)(); menulist->lastsel = 0; } else if(BOOLEAN_MENU & item->op) { /* toggle boolean; draw */ item->sel_option = !(item->sel_option); if(item->setting != 0) ipod_set_setting(item->setting, item->sel_option); menu_retext_pixmap(menulist, num - menulist->top_item, item); } else if(OPTION_MENU & item->op) { /* rotate option; draw */ item->sel_option = ((item->sel_option + 1) > (item->item_count - 1) ? 0 : item->sel_option + 1); if(item->setting != 0) ipod_set_setting(item->setting, item->sel_option); menu_retext_pixmap(menulist, num - menulist->top_item, item); } else if(SETTING_ITEM & item->op) { if(item->setting != 0) ipod_set_setting(item->setting, item->item_count); menulist = menu_destroy(menulist); } /* this isnt an else, so you can do (ACTION_MENU|SUB_MENU_PREV) */ if(SUB_MENU_PREV & item->op) { menulist = menu_destroy(menulist); } return menulist; }
/*{{{ quit -- quit with confirm*/ int quit() { struct menu_state *state; /* place to keep menu state */ int confirm; /* confirm the quit */ state = menu_define(font,quit_menu,0,0,MENU_COLOR); state = menu_setup(state,screen,mousex,mousey,0); /* The extra call to menu_get() makes the use of the mouse buttons consistent on the menus; namely the action is selected by the button going up. */ menu_get(state,mouse,BUTTON_SYS,0); menu_get(state,mouse,0,0); confirm = menu_ischoice(state) ? menu_choice(state) : 0; menu_destroy(state); if (confirm == M_QUIT) { _quit(); exit(0); } else if (confirm == M_SUSPEND) suspend(); }
void menu_create(menu_t *menu) { beep(); //GUI_Command(4,0); //press_button(IC_BUTTON_MENU); SendToMC(6, 2, 0); SleepTask(100); FLAG_GUI_MODE = 0x2D; // In theory, we do not need this, but menu_close does not work properly without it... //DPData.gui_mode = 0x2D; // this is not the same as FLAG_GUI_MODE, but so far i do not see what it does current_menu = menu; menu_DPData = DPData; menu_destroy(); menu_initialize(); GUI_Lock(); GUI_PalleteInit(); menu_handler = dialog_create(22, menu_event_handler); //*(int*)((int)(menu_handler+0x58)) = (int)hack_central_handler; //*(int*)((int)(menu_handler+0x7C)) = (int)menu_event_handler; PalettePush(); PaletteChange(current_menu->color); menu_event_display(); GUI_UnLock(); GUI_PalleteUnInit(); }
int main(void) { Menu *mainMenu = menu_create(); int cmd = 1; bool exit = false; menu_setTitle(mainMenu, "GalaxY (V0.11.20)"); menu_addButtonText(mainMenu, "Jouer"); menu_addButtonText(mainMenu, "Charger"); menu_addButtonText(mainMenu, "Quitter"); while (!exit) { menu_display(*mainMenu); cmd = menu_getcmd(*mainMenu); switch (cmd) { case 1: play(); break; case 2: break; case 3: exit = true; break; default: break; } } menu_destroy(mainMenu); return 0; }
void _destroy(state_stack *stack) { state_desc *top = (state_desc*) table_ind(stack, stack->m_len-1); _talk_state *st = (_talk_state*) top->m_pData; free(st->m_sNPCText); menu_destroy(st->m_pChoices); free(st); }
/************************************************************************* * menu_del_item_func * * Deletes an item from a menu * * Usage: menu_del_item <menuid> <itemid> * The given item in the given menu will be deleted. If you have deleted all * the items from your client menu, that menu will automatically be removed. */ int menu_del_item_func (Client * c, int argc, char **argv) { Menu * menu; MenuItem * item; char * menu_id; char * item_id; if (!c->ack) return 1; if (argc != 3 ) { sock_send_error(c->sock, "Usage: menu_del_item <menuid> <itemid>\n"); return 0; } menu_id = argv[1]; item_id = argv[2]; /* Does the client have a menu already ? */ if (!c->menu) { sock_send_error(c->sock, "Client has no menu\n"); return 0; } if ( menu_id[0] == 0 ) { /* No menu specified = client's main menu */ menu = c->menu; } else { /* A specified menu */ menu = menu_find_item (c->menu, menu_id, true); } if (!menu) { sock_send_error(c->sock, "Cannot find menu id\n"); return 0; } item = menu_find_item (c->menu, item_id, true); if (!item) { sock_send_error(c->sock, "Cannot find item\n"); return 0; } menuscreen_inform_item_destruction (item); menu_remove_item (menu, item); menuscreen_inform_item_modified (item->parent); menuitem_destroy (item); /* Was it the last item in the client's menu ? */ if (menu_getfirst_item(c->menu) == NULL) { menuscreen_inform_item_destruction (c->menu); menu_remove_item (main_menu, c->menu); menuscreen_inform_item_modified (main_menu); menu_destroy (c->menu); c->menu = NULL; } sock_send_string(c->sock, "success\n"); return 0; }
void _destroy(state_stack* stack) { state_desc *top = (state_desc*) table_ind(stack, stack->m_len-1); _settings_menu *data = (_settings_menu*) top->m_pData; menu *pMenu = (menu*) data->m_menu; settings *pSettings = (settings*) data->m_settings; menu_destroy(pMenu); settings_destroy(pSettings); free(data); }
static void menu_destructor(plugin_instance *p) { menu_priv *m = (menu_priv *) p; ENTER; g_signal_handlers_disconnect_by_func(G_OBJECT(icon_theme), schedule_rebuild_menu, p); menu_destroy(m); gtk_widget_destroy(m->bg); RET(); }
int main(int argc, char** argv){ int i; int j; int* score = (int*) malloc(sizeof(int)); if (SDL_Init(SDL_INIT_EVERYTHING) == -1){ printf("SDL_Init: %s\n", SDL_GetError()); return 1; } // Unicode support for hiscore table SDL_EnableUNICODE(1); if(TTF_Init()==-1) { printf("TTF_Init: %s\n", TTF_GetError()); return 1; } SDL_Surface* screen = SDL_SetVideoMode(608, 640, 32, SDL_SWSURFACE); SDL_WM_SetCaption("martet", "martet"); SDL_Surface* board = create_surface(320, 640); SDL_Surface* border = load_image("../data/tetborder.png"); draw_surface(321, 0, border, screen, NULL); draw_text(390, 35, screen, "Next tetromino:", 255, 255, 255); draw_text(330, 200, screen, "Score: ", 255, 255, 255); // create menu struct Menu* menu = menu_create(); menu_addelement(menu, "Start Game"); menu_addelement(menu, "Quit"); menu->active_element = &menu->elements[0]; menu->active_element->active = 1; bool running = true; while (running){ if (menu_martet(screen, board, menu, score) == KEYEVENT_EXIT) break; // fill the board with blocks on game over for (i = 0; i < BOARD_HEIGHT; i++) { char* line = get_board_line(i); for (j = 0; j < BOARD_WIDTH; j++) { line[j] = rand() % 7 + '0'; } draw_board(board); draw_surface(0, 0, board, screen, NULL); SDL_Flip(screen); SDL_Delay(50); } manage_hiscores(screen, board, score); board_delete(); } menu_destroy(menu); SDL_FreeSurface(border); SDL_FreeSurface(board); free(score); SDL_Quit(); return 0; }
static int destroy_proc(struct menu_item *item) { struct item_data *data = item->data; data->sig_sign->data = NULL; for (int i = 0; i < data->sig_precis; ++i) data->sig_digits[i]->data = NULL; data->exp_sign->data = NULL; for (int i = 0; i < data->exp_precis; ++i) data->exp_digits[i]->data = NULL; menu_destroy(data->imenu); free(data->sig_digits); free(data->exp_digits); return 0; }
void menu_item_remove(struct menu_item *item) { if (!item->destroy_proc || !item->destroy_proc(item)) { if (item->imenu) { menu_destroy(item->imenu); free(item->imenu); } if (item->text) free(item->text); if (item->data) free(item->data); } menu_deselect(item->owner, item); list_erase(&item->owner->items, item); }
static int itunes_do_keystroke(GR_EVENT * event) { int ret = 0; struct menulist *oldml; switch (event->type) { case GR_EVENT_TYPE_TIMER: menu_draw_timer(currentml->itunes_menu); break; case GR_EVENT_TYPE_KEY_DOWN: switch (event->keystroke.ch) { case '\r': /* action key */ case '\n': currentml->select(currentml); break; case 'm': /* menu key */ ret = 1; pz_close_window(currentml->wid); oldml = currentml; currentml->itunes_menu = menu_destroy(currentml->itunes_menu); currentml = currentml->prevml; free(oldml); if (currentml) itunes_draw(currentml); break; case 'r': if(currentml->get_next(currentml)) { menu_shift_selected(currentml->itunes_menu, 1); itunes_do_draw(); ret |= KEY_CLICK; } break; case 'l': if(currentml->get_prev(currentml)) { menu_shift_selected(currentml->itunes_menu, -1); itunes_do_draw(); ret |= KEY_CLICK; } break; } break; } return ret; }
int main(int argc, char* argv[]) { Menu* menu = menu_create(5); menu_add_title(menu, "Topwise company"); menu_add_title(menu, "Hello"); menu_add_item(menu, "hello", hello_print, (void*)HELLO_MSG, NULL); menu_add_item(menu, "weather", hello_print, (void*)WEATHER_MSG, NULL); menu_select(menu, 0); menu_select(menu, 1); menu_destroy(menu); return 0; }
static void menu_create(plugin_instance *p) { menu_priv *m = (menu_priv *) p; ENTER; if (m->menu) menu_destroy(m); m->xc = menu_expand_xc(p->xc, m); m->menu = menu_create_menu(m->xc, TRUE, m); g_signal_connect(G_OBJECT(m->menu), "unmap", G_CALLBACK(menu_unmap), p); m->btime = time(NULL); if (m->has_system_menu) m->tout = g_timeout_add(30000, (GSourceFunc) check_system_menu, p); RET(); }
static void browser_delete_file() { struct stat stat_result; browser_menu_overlay = browser_menu; stat(current_file, &stat_result); if(S_ISDIR(stat_result.st_mode)) { browser_rmdir(current_file); } else if(unlink(current_file) == -1) { pz_perror(current_file); return; } while(browser_menu_overlay->parent != NULL) browser_menu_overlay = menu_destroy(browser_menu_overlay); menu_delete_item(browser_menu_overlay, browser_menu_overlay->sel); }
void menu_close() { /* GUI_Lock(); GUI_PalleteInit(); DeleteDialogBox(menu_handler); menu_destroy(); menu_finish(); GUI_StartMode(GUIMODE_OLC); CreateDialogBox_OlMain(); GUIMode = GUIMODE_OLC; GUI_UnLock(); GUI_PalleteUnInit(); */ press_button(IC_BUTTON_DISP); menu_destroy(); menu_finish(NULL); //TODO:FixMe }
/* the directory to scan */ static void browser_mscandir(char *dira) { DIR *dir = opendir(dira); int i, size, op; struct stat stat_result; struct dirent *subdir; if(browser_menu != NULL) { menu_destroy(browser_menu); } browser_menu = menu_init(browser_wid, _("File Browser"), 0, 0, screen_info.cols, screen_info.rows - (HEADER_TOPLINE + 1), NULL, NULL, ASCII); /* not very good for fragmentation... */ for (i = 0; i < browser_nbEntries; i++) { free(browser_entries[i].full_name); } browser_nbEntries = 0; while ((subdir = readdir(dir))) { if(strncmp(subdir->d_name, ".", strlen(subdir->d_name)) == 0) { continue; } if(strncmp(subdir->d_name, "..", strlen(subdir->d_name)) == 0) { strcpy(browser_entries[browser_nbEntries].name, _(".. [Parent Directory]")); browser_entries[browser_nbEntries].full_name = strdup(browser_entries[browser_nbEntries].name); browser_entries[browser_nbEntries].type = FILE_TYPE_DIRECTORY; browser_entries[browser_nbEntries].op = STUB_MENU; browser_nbEntries++; continue; } if(!ipod_get_setting(BROWSER_HIDDEN)) { if (subdir->d_name[0] == '.') { continue; } } if(browser_nbEntries >= MAX_ENTRIES) { pz_error(_("Directory contains too many files.")); break; } size = strlen(subdir->d_name); size = (size > 62 ? 62 : size); browser_entries[browser_nbEntries].full_name = strdup(subdir->d_name); strncpy(browser_entries[browser_nbEntries].name, subdir->d_name, size); browser_entries[browser_nbEntries].name[size] = '\0'; stat(subdir->d_name, &stat_result); if(S_ISDIR(stat_result.st_mode)) { browser_entries[browser_nbEntries].type = FILE_TYPE_DIRECTORY; op = ARROW_MENU; } else if(stat_result.st_mode & S_IXUSR) { browser_entries[browser_nbEntries].type = FILE_TYPE_PROGRAM; op = EXECUTE_MENU; } else { browser_entries[browser_nbEntries].type = FILE_TYPE_OTHER; op = STUB_MENU; } browser_entries[browser_nbEntries].op = op; browser_nbEntries++; } closedir(dir); qsort(browser_entries, browser_nbEntries, sizeof(Directory), dir_cmp); for (i = 0; i < browser_nbEntries; i++) menu_add_item(browser_menu, browser_entries[i].name, NULL, 0, browser_entries[i].op); }
// run_martet: The game loop. Returns final score. int run_martet(SDL_Surface* screen, SDL_Surface* board) { Tetromino* active_tetromino; Tetromino* next_tetromino; // Create ingame menu struct Menu* ingame_menu = menu_create(); menu_addelement(ingame_menu, "Continue"); menu_addelement(ingame_menu, "Quit Current Game"); ingame_menu->active_element = &ingame_menu->elements[0]; ingame_menu->active_element->active = 1; int score = 0; srand((unsigned) time(NULL)); board_create(); next_tetromino = tetcreaterand(); update_status_bar(next_tetromino, screen, score); active_tetromino = tetcreaterand(); active_tetromino->position[0] = 4; struct Timer* timer = create_timer(); timer_change_alarm_interval(timer, GAME_SPEED); timer_start(timer); bool running = true; while (running){ int event = process_key_events(active_tetromino, tetaction); if (event == KEYEVENT_EXIT) exit(0); else if (event == KEYEVENT_MENU) { if (ingame_menu_martet(screen, board, ingame_menu) == 1) running = false; } else if (event == KEYEVENT_PAUSE) pause_martet(screen, board); if (timer_update(timer)) { // If collision and tetromino not deleted if ( tetmove('d', active_tetromino) == 0 && active_tetromino->color != TETROMINO_DELETE) { place_tetromino(active_tetromino); active_tetromino->color = TETROMINO_DELETE; } else if ( active_tetromino->color == TETROMINO_DELETE ) { free(active_tetromino); active_tetromino = next_tetromino; next_tetromino = tetcreaterand(); if (check_rows(&score)) { // If score has increased. timer_change_alarm_interval(timer, GAME_SPEED / sqrt( (double) score/5) + 1); } } if ( next_tetromino == NULL ) // If game over break; update_status_bar(next_tetromino, screen, score); } clear_surface(board, NULL); draw_board(board); draw_tetromino(board, active_tetromino); draw_ghost_tetromino(board, active_tetromino); draw_surface(0, 0, board, screen, NULL); SDL_Flip(screen); } if (active_tetromino) { free(active_tetromino); } free(next_tetromino); free(timer); menu_destroy(ingame_menu); return score; }
static int browser_do_keystroke(GR_EVENT * event) { int ret = 0; switch(event->type) { case GR_EVENT_TYPE_TIMER: if(((GR_EVENT_TIMER *)event)->tid == browser_key_timer) { GrDestroyTimer(browser_key_timer); browser_key_timer = 0; menu_handle_timer(browser_menu, 1); browser_action(browser_menu->items[browser_menu->sel].orig_pos); browser_do_draw(); } else menu_draw_timer(browser_menu); break; case GR_EVENT_TYPE_KEY_DOWN: switch (event->keystroke.ch) { case '\r': case '\n': if(browser_menu->parent == NULL) browser_key_timer = GrCreateTimer(browser_wid, 500); else { menu_handle_timer(browser_menu, 1); browser_menu = menu_handle_item(browser_menu, browser_menu->sel); if(browser_menu_overlay) { browser_menu = browser_menu_overlay; browser_menu_overlay = 0; } browser_do_draw(); } break; case 'm': case 'q': browser_menu = menu_destroy(browser_menu); ret |= KEY_CLICK; if(browser_menu != NULL) { browser_do_draw(); break; } browser_exit(); GrDestroyGC(browser_gc); pz_close_window(browser_wid); break; case 'r': if (menu_shift_selected(browser_menu, 1)) { menu_draw(browser_menu); ret |= KEY_CLICK; } break; case 'l': if (menu_shift_selected(browser_menu, -1)) { menu_draw(browser_menu); ret |= KEY_CLICK; } break; default: ret |= KEY_UNUSED; } break; case GR_EVENT_TYPE_KEY_UP: switch (event->keystroke.ch) { case '\r': case '\n': if(browser_key_timer) { GrDestroyTimer(browser_key_timer); browser_key_timer = 0; menu_handle_timer(browser_menu, 1); browser_selection_activated(browser_menu->items[browser_menu->sel].orig_pos); browser_do_draw(); } break; } break; default: ret |= EVENT_UNUSED; break; } return ret; }
int main(int argc, char **argv) { int rc = 0; struct cfgdata_t cfg; struct params_t params; kx_inputs inputs; lg = log_open(16); log_msg(lg, "%s starting", PACKAGE_STRING); initmode = do_init(); /* Get cmdline parameters */ params.cfg = &cfg; init_cfgdata(&cfg); cfg.angle = 0; /* No rotation by default */ parse_cmdline(&cfg); kxb_ttydev = cfg.ttydev; setup_terminal(kxb_ttydev, &kxb_echo_state, 1); /* Setup function that will restore terminal when exit() will called */ atexit(atexit_restore_terminal); log_msg(lg, "FB angle is %d, tty is %s", cfg.angle, cfg.ttydev); #ifdef USE_MACHINE_KERNEL machine_kernel = get_machine_kernelpath(); /* FIXME should be passed as arg to get_bootinfo() */ #endif #ifdef USE_DELAY /* extra delay for initializing slow SD/CF */ sleep(USE_DELAY); #endif int no_ui = 1; /* UI presence flag */ #ifdef USE_FBMENU params.gui = NULL; if (no_ui) { params.gui = gui_init(cfg.angle); if (NULL == params.gui) { log_msg(lg, "Can't initialize GUI"); } else no_ui = 0; } #endif #ifdef USE_TEXTUI FILE *ttyfp; params.tui = NULL; if (no_ui) { if (cfg.ttydev) ttyfp = fopen(cfg.ttydev, "w"); else ttyfp = stdout; params.tui = tui_init(ttyfp); if (NULL == params.tui) { log_msg(lg, "Can't initialize TUI"); if (ttyfp != stdout) fclose(ttyfp); } else no_ui = 0; } #endif if (no_ui) exit(-1); /* Exit if no one UI was initialized */ params.menu = build_menu(¶ms); params.bootcfg = NULL; scan_devices(¶ms); if (-1 == fill_menu(¶ms)) { exit(-1); } /* Collect input devices */ inputs_init(&inputs, 8); inputs_open(&inputs); inputs_preprocess(&inputs); /* Run main event loop * Return values: <0 - error, >=0 - selected item id */ rc = do_main_loop(¶ms, &inputs); #ifdef USE_FBMENU if (params.gui) { if (rc < 0) gui_clear(params.gui); gui_destroy(params.gui); } #endif #ifdef USE_TEXTUI if (params.tui) { tui_destroy(params.tui); if (ttyfp != stdout) fclose(ttyfp); } #endif inputs_close(&inputs); inputs_clean(&inputs); log_close(lg); lg = NULL; /* rc < 0 indicate error */ if (rc < 0) exit(rc); menu_destroy(params.menu, 0); if (rc >= A_DEVICES) { start_kernel(¶ms, rc - A_DEVICES); } /* When we reach this point then some error has occured */ DPRINTF("We should not reach this point!"); exit(-1); }
static char *menu_handle(struct menu_display *display) { struct menu *m; int i; void *choice = NULL; char key[2]; int ret; char *s; char temp[6][200]; m = menu_create(display->title, display->timeout, 1, ait_menu_print, NULL, NULL); for (i = 0; display->menulist[i]; i++) { sprintf(key, "%d", i + 1); if (display->id == MENU_NETWORK) { switch (i) { case 0: s = getenv("ipaddr"); break; case 1: s = getenv("netmask"); break; case 2: s = getenv("serverip"); break; case 3: s = getenv("gatewayip"); break; case 4: s = getenv("img_file"); break; default: s = NULL; break; } if (s) { sprintf(temp[i], "%s: %s", display->menulist[i], s); ret = menu_item_add(m, key, temp[i]); } else { ret = menu_item_add(m, key, display->menulist[i]); } } else { ret = menu_item_add(m, key, display->menulist[i]); } if (ret != 1) { printf("failed to add item!"); menu_destroy(m); return NULL; } } sprintf(key, "%d", 1); menu_default_set(m, key); if (menu_get_choice(m, &choice) != 1) debug("Problem picking a choice!\n"); menu_destroy(m); return choice; }
/* destroy all humans. err.. menus */ void menu_destroy_all(menu_st *menulist) { menu_st *parent = menulist; while((parent = menu_destroy(parent)) != NULL); }