Beispiel #1
0
static void menu_draw(menu_t *p_menu)
{
  int16_t x_start = p_menu->x1 + (p_menu->x2 - p_menu->x1) / 2 - p_menu->text_w / 2;
  int16_t y_start = p_menu->y1 + (p_menu->y2 - p_menu->y1) / 2 - p_menu->text_h / 2;
  int i;

  for (i=0; i < p_menu->n_entries; i++)
    {
      char *msg = p_menu->pp_msgs[i];

      if ((p_menu->available_options & (1<<i)) == 0)
	print_font(p_menu->p_font, vRGB(128,128,128), x_start, y_start + i * (p_menu->p_font->height + 2), msg);
      else if (p_menu->cur_sel == i)
	print_font(p_menu->p_font, vRGB(255,255,0), x_start, y_start + i * (p_menu->p_font->height + 2), msg);
      else
	print_font(p_menu->p_font, vRGB(255,255,255), x_start, y_start + i * (p_menu->p_font->height + 2), msg);
      if (IS_SUBMENU(msg))
	{
	  submenu_t *p_submenu = find_submenu(p_menu, i);
	  int n_pipe = 0;
	  int n;

	  DbgPrintf("Submenu!...\n");
	  for (n=0; msg[n] != '\0'; n++)
	    {
	      /* Underline the selected entry */
	      if (msg[n] == '|')
		{
		  int16_t n_chars;

		  for (n_chars = 1; msg[n+n_chars] && msg[n+n_chars] != '|'; n_chars++);

		  n_pipe++;
		  if (p_submenu->sel == n_pipe-1)
		    {
		      vSetForeColor(vRGB(0,255,0));
		      vFillRect(x_start + (n+1) * (p_menu->p_font->width)-1,
				y_start + (i+1) * (p_menu->p_font->height + 2)-1,
				x_start + (n+n_chars) * (p_menu->p_font->width)-1,
				y_start + (i+1) * (p_menu->p_font->height + 2)-1);
		      break;
		    }
		}
	    }
	}
    }
}
Beispiel #2
0
static void select_next(menu_t *p_menu, int dx, int dy)
{
  p_menu->cur_sel = (p_menu->cur_sel + dy) < 0 ? p_menu->n_entries - 1 :
    (p_menu->cur_sel + dy) % p_menu->n_entries;
  int next = (p_menu->cur_sel + dy + 1) < 0 ? p_menu->n_entries - 1 :
    (p_menu->cur_sel + dy + 1) % p_menu->n_entries;

  if (p_menu->pp_msgs[p_menu->cur_sel][0] == ' ' ||
      ( (p_menu->available_options & (1<<p_menu->cur_sel)) == 0) ||
      IS_SUBMENU(p_menu->pp_msgs[p_menu->cur_sel]) )
    select_next(p_menu, dx, dy);
  /* If the next is a submenu */
  if (dx != 0 &&
      IS_SUBMENU(p_menu->pp_msgs[next]))
    {
      submenu_t *p_submenu = find_submenu(p_menu, next);

      p_submenu->sel = (p_submenu->sel + dx) < 0 ? p_submenu->n_entries - 1 :
	(p_submenu->sel + dx) % p_submenu->n_entries;
    }
}
Beispiel #3
0
static void select_next(menu_t *p_menu, int dx, int dy, int cicle)
{
	int next;

	p_menu->cur_sel = get_next_seq_y(p_menu, p_menu->cur_sel, dy, cicle);
	next = get_next_seq_y(p_menu, p_menu->cur_sel, dy + 1, cicle);
	if (IS_SUBMENU(p_menu->pp_msgs[p_menu->cur_sel])&&(dy!=1)&&(dy!=-1)) p_menu->cur_sel--;
	if (p_menu->pp_msgs[p_menu->cur_sel][0] == ' ' ||
			p_menu->pp_msgs[p_menu->cur_sel][0] == '#' ||
			IS_SUBMENU(p_menu->pp_msgs[p_menu->cur_sel]) )
		select_next(p_menu, dx, dy, cicle);

	/* If the next is a submenu */
	if (dx != 0 && IS_SUBMENU(p_menu->pp_msgs[next]))
	{
		submenu_t *p_submenu = find_submenu(p_menu, next);

		p_submenu->sel = (p_submenu->sel + dx) < 0 ? p_submenu->n_entries - 1 :
		(p_submenu->sel + dx) % p_submenu->n_entries;
	}
	else if (dx == -1 && !strcmp(p_menu->pp_msgs[0], "[..]"))
		p_menu->cur_sel = 0;
}
Beispiel #4
0
static void menu_draw(SDL_Surface *screen, menu_t *p_menu, int sel, int font_size)
{
	static SDL_Thread *thread = NULL;  
	quit_thread = 1;
	
	int font_height = TTF_FontHeight(p_menu->p_font);
	int line_height = font_height + font_height/16 +(font_height==24);
	int x_start = p_menu->x1+6/RATIO;
	int y_start = p_menu->y1 + line_height;
	SDL_Rect r;
	int entries_visible = (p_menu->y2 - p_menu->y1 -5) / line_height - 1;

	int i, y;
	
	SDL_Rect r_ext = {p_menu->x1, p_menu->y1,
				p_menu->x2 - p_menu->x1, p_menu->y2 - p_menu->y1+2/RATIO};
	SDL_Rect r_int = {p_menu->x1+4/RATIO, p_menu->y1,
				p_menu->x2 - p_menu->x1-8/RATIO, p_menu->y2 - p_menu->y1-2/RATIO};	
				
	
	SDL_FillRect(screen, &r_ext, SDL_MapRGB(screen->format, 116, 117, 206));
	SDL_BlitSurface(image_window, &r_int, screen, &r_int);
		
	if ( p_menu->n_entries * line_height > p_menu->y2 )
		y_start = p_menu->y1 + line_height;

	if (p_menu->cur_sel - p_menu->start_entry_visible > entries_visible)
	{
		while (p_menu->cur_sel - p_menu->start_entry_visible > entries_visible)
		{
			p_menu->start_entry_visible ++;
			if (p_menu->start_entry_visible > p_menu->n_entries)
			{
				p_menu->start_entry_visible = 0;
				break;
			}
		}
	}
	else if ( p_menu->cur_sel < p_menu->start_entry_visible )
		p_menu->start_entry_visible = p_menu->cur_sel;

	if (strlen(p_menu->title))
	{
		r.x = p_menu->x1;
		r.y = p_menu->y1;
		r.w = p_menu->x2 - p_menu->x1;
		r.h = line_height-1;
		if (sel < 0)
			SDL_FillRect(screen, &r, SDL_MapRGB(screen->format, 0x40, 0x00, 0x00));
		else
			SDL_FillRect(screen, &r, SDL_MapRGB(screen->format, 116, 117, 206)); //Title
		menu_print_font(screen, 255,255,255, p_menu->x1+4/RATIO, p_menu->y1, p_menu->title, font_size);
	}

	for (i = p_menu->start_entry_visible; i <= p_menu->start_entry_visible + entries_visible; i++)
	{
		const char *msg = p_menu->pp_msgs[i];

		if (i >= p_menu->n_entries)
			break;
		if (IS_MARKER(msg))
			p_menu->cur_sel = atoi(&msg[1]);
		else
		{
			y = (i - p_menu->start_entry_visible) * line_height;

			if (sel < 0)
				menu_print_font(screen, 0x40,0x40,0x40,
						x_start, y_start + y, msg, font_size);
			else if (p_menu->cur_sel == i) /* Selected - color */
				{
					if (strlen(msg)<=_MAX_STRING) menu_print_font(screen, 0,128,0,
						x_start, y_start + y, msg, font_size);
					else
					{
						if (thread) SDL_WaitThread(thread, NULL);
						thread_struct.screen=screen;
						thread_struct.x=x_start;
						thread_struct.y=y_start + y;
						thread_struct.msg=msg;
						thread_struct.font_size=font_size;
						quit_thread=0;
						thread = SDL_CreateThread(menu_thread, NULL );
					}
				}
			else if (IS_SUBMENU(msg))
			{
				if (p_menu->cur_sel == i-1) /* Selected - color */
					menu_print_font(screen, 0,128,0,
							x_start, y_start + y, msg, font_size);
				else
					menu_print_font(screen, 20,20,20,
							x_start, y_start + y, msg, font_size);
			}
			else if (msg[0] == '#')
			{
				switch (msg[1])
				{
				case '1':
					menu_print_font(screen, 116,117,206,
							x_start, y_start + y, msg+2, font_size);
					break;
				case '2':
					menu_print_font(screen, 25,0,231,
							x_start, y_start + y, msg+2, font_size);
					break;
				default:
					menu_print_font(screen, 0x40,0x40,0x40,
							x_start, y_start + y, msg, font_size);
					break;							
				}
			}
			else //Not selected
				menu_print_font(screen, 20,20,20,
						x_start, y_start + y, msg, font_size);
			if (IS_SUBMENU(msg))
			{
				submenu_t *p_submenu = find_submenu(p_menu, i);
				int n_pipe = 0;
				int n;

				for (n=0; msg[n] != '\0'; n++)
				{
					/* Underline the selected entry */
					if (msg[n] == '|')
					{
						int16_t n_chars;

						for (n_chars = 1; msg[n+n_chars] && msg[n+n_chars] != '|'; n_chars++);

						n_pipe++;
						if (p_submenu->sel == n_pipe-1)
						{
							int w;
							int h;

							if (TTF_SizeText(p_menu->p_font, "X", &w, &h) < 0)
							{
								fw = w;
								fh = h;
								write_log("%s\n", TTF_GetError());
								exit(1);
							}

							r = (SDL_Rect){ x_start + (n+1) * w, y_start + (i+ 1 - p_menu->start_entry_visible) * line_height -3/RATIO, (n_chars - 1) * w, 2};
							if (p_menu->cur_sel == i-1)
								SDL_FillRect(screen, &r,
										SDL_MapRGB(screen->format, 255,0,0));
							else
								SDL_FillRect(screen, &r,
										SDL_MapRGB(screen->format, 20,20,20));
							break;
						}
					}
				}
			}
		}
	}
}