示例#1
0
文件: config.c 项目: yibnl/PebbleIHM
static void main_window_load(Window *window) {
  Layer *window_layer = window_get_root_layer(window);
  GRect bounds = layer_get_frame(window_layer);

  s_title_layer = text_layer_create(GRect(0, 0, bounds.size.w, 28));
  text_layer_set_text(s_title_layer, item_title(s_item));
  text_layer_set_font(s_title_layer, fonts_get_system_font(FONT_KEY_GOTHIC_24_BOLD));
  text_layer_set_text_alignment(s_title_layer, GTextAlignmentLeft);
  layer_add_child(window_layer, text_layer_get_layer(s_title_layer));
  
  s_image_layer = layer_create(GRect(60, 0, bounds.size.w, 28));
  layer_set_update_proc(s_image_layer, layer_update_callback); 
  layer_add_child(window_layer, s_image_layer); 
  
  s_subtitle_layer = text_layer_create(GRect(0, 30, bounds.size.w, 28));
  text_layer_set_text(s_subtitle_layer, item_subtitle(s_item));
  text_layer_set_font(s_subtitle_layer, fonts_get_system_font(FONT_KEY_GOTHIC_14_BOLD));
  text_layer_set_text_alignment(s_subtitle_layer, GTextAlignmentLeft);
  layer_add_child(window_layer, text_layer_get_layer(s_subtitle_layer));
  
  s_description_layer = text_layer_create(GRect(0, 50, bounds.size.w, 28));
  text_layer_set_text(s_description_layer, item_description(s_item));
  text_layer_set_font(s_description_layer, fonts_get_system_font(FONT_KEY_GOTHIC_14));
  text_layer_set_text_alignment(s_description_layer, GTextAlignmentLeft);
  layer_add_child(window_layer, text_layer_get_layer(s_description_layer)); 
}
示例#2
0
文件: choosewin.c 项目: weezel/fcd
void
show_chooser_win(MENU *dirmenu, size_t items, char *buf)
{
	int	 c = 0;
	size_t	 buflen, offset = 0;
	char	*tmp;

	buflen = strlen(buf) - 1;

	set_menu_fore(dirmenu, A_REVERSE);
	returnval = set_menu_format(dirmenu, LINES, 1);
	post_menu(dirmenu);
	refresh();

	while ((c = getch()) != 'q') {
		switch(c) {
		case 'j':
		case KEY_DOWN:
			menu_driver(dirmenu, REQ_DOWN_ITEM);
			break;
		case 'k':
		case KEY_UP:
			menu_driver(dirmenu, REQ_UP_ITEM);
			break;
		case KEY_NPAGE:
			menu_driver(dirmenu, REQ_SCR_DPAGE);
			break;
		case KEY_PPAGE:
			menu_driver(dirmenu, REQ_SCR_UPAGE);
			break;
		case KEY_END:
			menu_driver(dirmenu, REQ_LAST_ITEM);
			break;
		case KEY_HOME:
			menu_driver(dirmenu, REQ_FIRST_ITEM);
			break;
		case 10: /* Enter */
			move(20, 0);
			clrtoeol();

			tmp = (char *)item_name(current_item(dirmenu));
			offset = strlcpy(buf, tmp, MAX_CHOICESIZE);
			if (offset >= MAX_CHOICESIZE)
				goto toolong;
			if (strlcpy(buf + offset,
				    item_description(current_item(dirmenu)),
				    MAX_CHOICESIZE - offset))
				goto toolong;

			pos_menu_cursor(dirmenu);
			break;
		}
	}
toolong:
	unpost_menu(dirmenu);
	fprintf(stdout, "shit happens\n");

	fprintf(stdout, "VALUE WAS: %d\n", returnval);
}
示例#3
0
static ITEM *
search_menu_backwards (MENU * menu)
{
  char *search_string = NULL;
  ITEM *result_item = NULL;

  /* the search string is stored in the menu user pointer */
  search_string = (char *) menu_userptr (menu);

  if (NULL != search_string)
    {
      int i = -1;
      int current_index = -1;
      ITEM **items = NULL;
      int found = 0;
      bool done = FALSE;

      current_index = item_index (current_item (menu));
      items = menu_items (menu);

      /* start search from the item immediately before the current item */
      for (i = current_index - 1; i >= 0 && !found; i--)
        {
          found = strstr_nocase (item_description (items[i]), search_string);
        }

      if (!found)
        {
          int count = -1;
          count = item_count (menu);
          /* start search from the end (i.e. wrap around) */
          for (i = count - 1; i >= current_index && !found; i--)
            {
              found =
                  strstr_nocase (item_description (items[i]), search_string);
            }
        }

      if (found)
        {
          result_item = items[i + 1];
        }
    }

  return result_item;
}
示例#4
0
int main()
{	ITEM **my_items;
	int c;				
	MENU *my_menu;
        int n_choices, i;
	ITEM *cur_item;
	
	
	initscr();
        cbreak();
        noecho();
	keypad(stdscr, TRUE);
	
        n_choices = ARRAY_SIZE(choices);
        my_items = (ITEM **)calloc(n_choices + 1, sizeof(ITEM *));

        for(i = 0; i < n_choices; ++i)
                my_items[i] = new_item(choices[i], choices[i]);
	my_items[n_choices] = (ITEM *)NULL;

	my_menu = new_menu((ITEM **)my_items);
	post_menu(my_menu);
	refresh();

	while((c = getch()) != KEY_F(1))
	{       switch(c)
	        {	case KEY_DOWN:
				menu_driver(my_menu, REQ_DOWN_ITEM);
				break;
			case KEY_UP:
				menu_driver(my_menu, REQ_UP_ITEM);
				break;
			case 10:	/* Enter */
				cur_item = current_item(my_menu);
				move(LINES - 2, 0);
				clrtoeol();
				mvprintw(LINES - 2, 0, "You have chosen %d item with name %s and description %s", 
				item_index(cur_item) + 1,  item_name(cur_item), 
				item_description(cur_item));
				
				refresh();
				pos_menu_cursor(my_menu);
				break;
		}
	}	

	free_item(my_items[0]);
        free_item(my_items[1]);
	free_menu(my_menu);
	endwin();
}
示例#5
0
文件: nchgdc.c 项目: Eeketh/hgd
int
hgd_unpost_and_free_content_menu(struct ui *u, int which)
{
	ITEM			**items;
	int			  n_items, i;

	if (u->content_menus[which] == NULL)
		return (HGD_OK);

	DPRINTF(HGD_D_INFO, "free menu: %s", window_names[which]);

	if ((n_items = item_count(u->content_menus[which])) == ERR) {
		DPRINTF(HGD_D_ERROR, "Couldn't get item count");
		return (HGD_FAIL);
	}

	if ((items = menu_items(u->content_menus[which])) == NULL) {
		DPRINTF(HGD_D_ERROR, "Got NULL items array");
		return (HGD_FAIL);
	}

	if (unpost_menu(u->content_menus[which]) != E_OK)
		DPRINTF(HGD_D_ERROR, "could not unpost menu %d", errno);

	/* must come before freeing items */
	if (free_menu(u->content_menus[which]) != E_OK)
		DPRINTF(HGD_D_ERROR, "could not free menu");

	for (i = 0; i < n_items; i++) {
		free((char *) item_name(items[i]));
		free((char *) item_description(items[i]));
		free(item_userptr(items[i]));
		if (free_item(items[i]) != OK)
			DPRINTF(HGD_D_ERROR, "can't free item");
	}

	free(items);
	u->content_menus[which] = NULL;

	return (HGD_OK);
}
示例#6
0
void
selection_free_or_die(struct selection *selection)
{
    if (!selection) return;
    
    if (selection->menu) {
        unpost_menu(selection->menu);
        free_menu(selection->menu);
    }
    if (selection->sub_window) delwin(selection->sub_window);
    if (selection->window) delwin(selection->window);
    
    for (int i = 0; i < selection->items_count; ++i) {
        free_or_die((char *)item_name(selection->items[i]));
        free_or_die((char *)item_description(selection->items[i]));
        free_or_die(item_userptr(selection->items[i]));
        free_item(selection->items[i]);
    }
    free_or_die(selection->items);
    free_or_die(selection->title);
    free_or_die(selection);
}
int
main_menu(void)
{
	MENU                    *my_menu = NULL;
 	ITEM                    **my_items = NULL;
    struct tool_instance    *list = NULL;
    const char              *ret_msg = NULL;
    // Init at refresh for first loop.
    int                     c = 'R';

    do
    {
        switch (c)
        {
        // Navigate in the menu
        case KEY_DOWN:
        case KEY_RIGHT:
            menu_driver(my_menu, REQ_DOWN_ITEM);
            break ;
        case KEY_UP:
        case KEY_LEFT:
            menu_driver(my_menu, REQ_UP_ITEM);
            break ;
        // Select a migration to monitor
        case ' ':
        case 13: // Enter key
            {
                if (item_count(my_menu) > 0)
                {
                    ITEM *curitem = current_item(my_menu);
                    if (view_instance(item_description(curitem))
                        != EXIT_SUCCESS)
                    {
        ret_msg = "An error occured while trying to display the tool's data.";
                    }
                }
            }
            // No break here to allow refreshing the list
            // when coming out of the instance display.
        // Refresh the list.
        case 'r':
        case 'R':
            if (list)
                clear_instance_list(list);
            list = get_instance_list();
            if (list == NULL)
                mvprintw(0, 0,
                "cloudmig-view: No cloudmig tool is running at the moment.\n");

            if (my_menu)
                clear_menu(my_menu, my_items);
            my_items = NULL;
            my_menu = NULL;
            
            if (fill_menu(list, &my_items, &my_menu))
                return EXIT_FAILURE;
            post_menu(my_menu);
            break;
        // Leave the monitor
        case 'q':
        case 'Q':
            break ;
        // Ignore the others
        default:
            break ;
        }
        mvprintw(LINES - 4, 0,
             "Use <SPACE> or <ENTER> to select the process to monitor.");
        mvprintw(LINES - 3, 0,
                 "    <q> or <Q> to quit this program.");
        mvprintw(LINES - 2, 0,
                 "    <r> or <R> to see refresh the list manually.");
        if (ret_msg)
        {
            mvprintw(LINES -6, 0, "%.*s", COLS, ret_msg);
            ret_msg = NULL;
        }
        refresh();
    } while ((c = getch()) != 'q');

    return EXIT_FAILURE;
}
示例#8
0
static VALUE rbncurs_c_item_description(VALUE rb_item)
{
  ITEM *item = get_item(rb_item);
  return rb_str_new2(item_description(item));
}
示例#9
0
文件: config.c 项目: yibnl/PebbleIHM
static void down_click_handler(ClickRecognizerRef recognizer, void *context) {
  s_item = (s_item + 1) % item_count();
  text_layer_set_text(s_title_layer, item_title(s_item));
  text_layer_set_text(s_subtitle_layer, item_subtitle(s_item));
  text_layer_set_text(s_description_layer, item_description(s_item));
}
示例#10
0
文件: config.c 项目: yibnl/PebbleIHM
static void up_click_handler(ClickRecognizerRef recognizer, void *context) {
  s_item = s_item == 0 ? item_count() -1 : s_item - 1;
  text_layer_set_text(s_title_layer, item_title(s_item));
  text_layer_set_text(s_subtitle_layer, item_subtitle(s_item));
  text_layer_set_text(s_description_layer, item_description(s_item));
}
示例#11
0
文件: menu.c 项目: MarxBro/radio_bash
int main(){	
    main_pid = getpid();
    char line[BUF][BUF];
    FILE *rlist = NULL; 
    int igt     = 0;
    int total   = 0;
    rlist       = fopen("STATIONS.txt", "r");
    while( fgets ( line[igt], BUF, rlist )) {
        /* get rid of ending \n from fgets */
        line[igt][strlen(line[igt]) - 1] = '\0';
        char *line_f        = line[igt];
        uris[igt]           = strtok(line_f,    "@");
        choices[igt]        = strtok(NULL,      "@");
        descriptions[igt]   = strtok(NULL,      "@");
        igt++;
    }
    
	/* Initialize curses */	
    ITEM **my_items;
	int c;				
	MENU *my_menu;
        int n_choices, i;
	ITEM *cur_item;
	initscr();
    /*We dont really need colors for now...*/
    /*start_color();*/
        cbreak();
        noecho();
	keypad(stdscr, TRUE);
    /*wborder(0 , 0,0,0,0,0,0,0,0,);*/
    /*init_pair(1, COLOR_RED,COLOR_WHITE);*/
    /*init_pair(2, COLOR_GREEN,COLOR_WHITE);*/
    /*init_pair(3, COLOR_MAGENTA,COLOR_WHITE);*/
	/* Initialize items */
        n_choices = ARRAY_SIZE(choices);
        my_items = (ITEM **)calloc(n_choices + 1, sizeof(ITEM *));
        for(i = 0; i < n_choices; ++i) {
            my_items[i] = new_item(choices[i],descriptions[i]);
		    /* The F*cking user pointer */
		    set_item_userptr(my_items[i], func);
	    }
	my_items[n_choices] = (ITEM *)NULL;

	/* Create menu */
	my_menu = new_menu((ITEM **)my_items);
    set_menu_opts(my_menu,O_SHOWDESC);
    int y_lines_menu = LINES - y_lines_reserved;
    set_menu_format(my_menu,y_lines_menu,1);

	/* Post the menu */
    /*Help thingy*/
    hacete_una_linea_putin(5);
	mvprintw(LINES - 4, 0, " Press <ENTER> to play the station,");
	mvprintw(LINES - 3, 0, " any <arrow> to move the menu buffer, <Q> to Quit or");
	mvprintw(LINES - 2, 0, " <K> to Kill child mplayer process.");
    hacete_una_linea_putin(1);
	post_menu(my_menu);
	refresh();

    /*big loop thingy*/
    while((c = getch()) != 113){
        switch(c){
            case KEY_DOWN:
                menu_driver(my_menu, REQ_DOWN_ITEM);
                break;
            case KEY_UP:
                menu_driver(my_menu, REQ_UP_ITEM);
                break;
            case KEY_LEFT:
                menu_driver(my_menu, REQ_SCR_UPAGE);
                break;
            case KEY_RIGHT:
                menu_driver(my_menu, REQ_SCR_DPAGE);
                break;
            case 107:   // k
                kill_child();
                break;
            case 10: {    /* Enter  == Play some radio! */
                ITEM *cur;
                void (*p)(char *);
                if (*contador >= 1){
                    kill_child();
                }
                cur = current_item(my_menu);
                description_fn = (char *)item_description(cur);
                p = item_userptr(cur);
                p((char *)item_name(cur));
                pos_menu_cursor(my_menu);
                play_radio();
                cuenta = cuenta + 1;
                break;
            }
            break;
        }
    }
    /*That's all, free memory, kill any pid and exit.*/
    unpost_menu(my_menu);
    for(i = 0; i < n_choices; ++i){
        free_item(my_items[i]);
    }
    free_menu(my_menu);
    endwin();
    kill_child();
    exit(0);
}