ui_textarea_t *ui_textarea_create(UINTN line_nb, UINTN row_nb, ui_font_t *font,
				  EFI_GRAPHICS_OUTPUT_BLT_PIXEL *color,
				  EFI_GRAPHICS_OUTPUT_BLT_PIXEL *bg_color)
{
	UINTN text_size;

	if (!font)
		font = ui_font_get_default();

	ui_textarea_t *textarea = AllocatePool(sizeof(ui_textarea_t));
	if (!textarea)
		return NULL;

	textarea->line_nb = line_nb;
	textarea->row_nb = row_nb;
	textarea->font = font;

	if (EFI_ERROR(ui_textarea_allocate_blt(textarea))) {
		FreePool(textarea);
		return NULL;
	}

	text_size = sizeof(*textarea->text) * line_nb;
	textarea->text = AllocateZeroPool(text_size);
	if (!textarea->text) {
		FreePool(textarea->blt);
		FreePool(textarea);
		return NULL;
	}

	textarea->current = -1;
	textarea->color = color;
	textarea->bg_color = bg_color;

	return textarea;
}
Exemplo n.º 2
0
BOOLEAN ui_confirm(const ui_textline_t *text, UINTN width, UINTN height,
		   UINTN x, UINTN y)
{
	ui_events_t event;

#ifdef USE_POWER_BUTTON
	UINTN line_nb, len, row_nb = 0;
	EFI_STATUS ret;
	ui_font_t *font;
	UINTN text_height, scaled_text_height, scaled_text_width, line_height;

	font = ui_font_get_default();
	if (!font) {
		error(L"Default font not available");
		return FALSE;
	}

	for (line_nb = 0; text[line_nb].str; line_nb++) {
		len = strlen((CHAR8 *)text[line_nb].str);
		row_nb = row_nb < len ? len : row_nb;
	}

	if (!line_nb || !row_nb) {
		error(L"Invalid text for ui_confirm");
		return FALSE;
	}

	text_height = line_nb * height / (line_nb + ARRAY_SIZE(yes_no_menu));
	ret = ui_textarea_display_text(text, font, x, &y, width, text_height, NULL);
	if (EFI_ERROR(ret))
		return FALSE;

	ui_get_scaled_dimension((row_nb * font->cwidth), (line_nb * font->cheight),
				width, text_height, &scaled_text_width, &scaled_text_height);
	line_height = scaled_text_height / line_nb;

	ret = ui_confirm_draw_menu(font, x, y, scaled_text_width, line_height);
	if (EFI_ERROR(ret))
		return FALSE;
	for (;;) {
		event = ui_wait_for_input(TIMEOUT_SECS);
		switch (event) {
		case EV_UP:
		case EV_DOWN:
			current = (current + 1) % ARRAY_SIZE(yes_no_menu);
			ret = ui_confirm_draw_menu(font, x, y, scaled_text_width, line_height);
			if (EFI_ERROR(ret))
				return FALSE;
			break;
		case EV_POWER:
			ui_wait_for_key_release();
			return !current;
		default:
			break;
		}
	}
#else
	const ui_textline_t *texts[] = {text, yes_no_text, NULL};
	ui_display_texts(texts, x, y, width, height);
	event = ui_wait_for_input(TIMEOUT_SECS);
	return event == EV_UP ? TRUE : FALSE;
#endif
}