Beispiel #1
0
/* Set the specified property NAME on the view to the given string VALUE.
   The caller is responsible for the lifetimes of NAME and VALUE.  */
static grub_err_t
theme_set_string (grub_gfxmenu_view_t view,
                  const char *name,
                  const char *value,
                  const char *theme_dir,
                  const char *filename,
                  int line_num,
                  int col_num)
{
  if (! grub_strcmp ("title-font", name))
    view->title_font = grub_font_get (value);
  else if (! grub_strcmp ("message-font", name))
    view->message_font = grub_font_get (value);
  else if (! grub_strcmp ("terminal-font", name))
    {
      grub_free (view->terminal_font_name);
      view->terminal_font_name = grub_strdup (value);
      if (! view->terminal_font_name)
        return grub_errno;
    }
  else if (! grub_strcmp ("title-color", name))
    grub_video_parse_color (value, &view->title_color);
  else if (! grub_strcmp ("message-color", name))
    grub_video_parse_color (value, &view->message_color);
  else if (! grub_strcmp ("message-bg-color", name))
    grub_video_parse_color (value, &view->message_bg_color);
  else if (! grub_strcmp ("desktop-image", name))
    {
      struct grub_video_bitmap *raw_bitmap;
      char *path;
      path = grub_resolve_relative_path (theme_dir, value);
      if (! path)
        return grub_errno;
      if (grub_video_bitmap_load (&raw_bitmap, path) != GRUB_ERR_NONE)
        {
          grub_free (path);
          return grub_errno;
        }
      grub_free(path);
      grub_video_bitmap_destroy (view->raw_desktop_image);
      view->raw_desktop_image = raw_bitmap;
    }
  else if (! grub_strcmp ("desktop-image-scale-method", name))
    {
      if (! value || ! grub_strcmp ("stretch", value))
        view->desktop_image_scale_method =
            GRUB_VIDEO_BITMAP_SELECTION_METHOD_STRETCH;
      else if (! grub_strcmp ("crop", value))
        view->desktop_image_scale_method =
            GRUB_VIDEO_BITMAP_SELECTION_METHOD_CROP;
      else if (! grub_strcmp ("padding", value))
        view->desktop_image_scale_method =
            GRUB_VIDEO_BITMAP_SELECTION_METHOD_PADDING;
      else if (! grub_strcmp ("fitwidth", value))
        view->desktop_image_scale_method =
            GRUB_VIDEO_BITMAP_SELECTION_METHOD_FITWIDTH;
      else if (! grub_strcmp ("fitheight", value))
        view->desktop_image_scale_method =
            GRUB_VIDEO_BITMAP_SELECTION_METHOD_FITHEIGHT;
      else
        return grub_error (GRUB_ERR_BAD_ARGUMENT,
                           "Unsupported scale method: %s",
                           value);
    }
  else if (! grub_strcmp ("desktop-image-h-align", name))
    {
      if (! grub_strcmp ("left", value))
        view->desktop_image_h_align = GRUB_VIDEO_BITMAP_H_ALIGN_LEFT;
      else if (! grub_strcmp ("center", value))
        view->desktop_image_h_align = GRUB_VIDEO_BITMAP_H_ALIGN_CENTER;
      else if (! grub_strcmp ("right", value))
        view->desktop_image_h_align = GRUB_VIDEO_BITMAP_H_ALIGN_RIGHT;
      else
        return grub_error (GRUB_ERR_BAD_ARGUMENT,
                           "Unsupported horizontal align method: %s",
                           value);
    }
  else if (! grub_strcmp ("desktop-image-v-align", name))
    {
      if (! grub_strcmp ("top", value))
        view->desktop_image_v_align = GRUB_VIDEO_BITMAP_V_ALIGN_TOP;
      else if (! grub_strcmp ("center", value))
        view->desktop_image_v_align = GRUB_VIDEO_BITMAP_V_ALIGN_CENTER;
      else if (! grub_strcmp ("bottom", value))
        view->desktop_image_v_align = GRUB_VIDEO_BITMAP_V_ALIGN_BOTTOM;
      else
        return grub_error (GRUB_ERR_BAD_ARGUMENT,
                           "Unsupported vertical align method: %s",
                           value);
    }
  else if (! grub_strcmp ("desktop-color", name))
     grub_video_parse_color (value, &view->desktop_color);
  else if (! grub_strcmp ("terminal-box", name))
    {
        grub_err_t err;
        err = grub_gui_recreate_box (&view->terminal_box, value, theme_dir);
        if (err != GRUB_ERR_NONE)
          return err;
    }
  else if (! grub_strcmp ("terminal-border", name))
    {
      view->terminal_border = grub_strtoul (value, 0, 10);
      if (grub_errno)
        return grub_errno;
    }
  else if (! grub_strcmp ("terminal-left", name))
    {
      unsigned int tmp;
      int err = theme_get_unsigned_int_from_proportional (value,
                                                          view->screen.width,
                                                          &tmp);
      if (err != GRUB_ERR_NONE)
        return err;
      view->terminal_rect.x = tmp;
    }
  else if (! grub_strcmp ("terminal-top", name))
    {
      unsigned int tmp;
      int err = theme_get_unsigned_int_from_proportional (value,
                                                          view->screen.height,
                                                          &tmp);
      if (err != GRUB_ERR_NONE)
        return err;
      view->terminal_rect.y = tmp;
    }
  else if (! grub_strcmp ("terminal-width", name))
    {
      unsigned int tmp;
      int err = theme_get_unsigned_int_from_proportional (value,
                                                          view->screen.width,
                                                          &tmp);
      if (err != GRUB_ERR_NONE)
        return err;
      view->terminal_rect.width = tmp;
    }
  else if (! grub_strcmp ("terminal-height", name))
    {
      unsigned int tmp;
      int err = theme_get_unsigned_int_from_proportional (value,
                                                          view->screen.height,
                                                          &tmp);
      if (err != GRUB_ERR_NONE)
        return err;
      view->terminal_rect.height = tmp;
    }
  else if (! grub_strcmp ("title-text", name))
    {
      grub_free (view->title_text);
      view->title_text = grub_strdup (value);
      if (! view->title_text)
        return grub_errno;
    }
  else
    {
      return grub_error (GRUB_ERR_BAD_ARGUMENT,
                         "%s:%d:%d unknown property `%s'",
                         filename, line_num, col_num, name);
    }
  return grub_errno;
}
Beispiel #2
0
static grub_err_t
grub_cmd_videotest (grub_command_t cmd __attribute__ ((unused)),
                    int argc, char **args)
{
  grub_err_t err;
  grub_video_color_t color;
  unsigned int x;
  unsigned int y;
  unsigned int width;
  unsigned int height;
  int i;
  struct grub_video_render_target *text_layer;
  grub_video_color_t palette[16];
  const char *mode = NULL;

#ifdef GRUB_MACHINE_PCBIOS
  if (grub_strcmp (cmd->name, "vbetest") == 0)
    grub_dl_load ("vbe");
#endif

  mode = grub_env_get ("gfxmode");
  if (argc)
    mode = args[0];
  if (!mode)
    mode = "auto";

  err = grub_video_set_mode (mode, GRUB_VIDEO_MODE_TYPE_PURE_TEXT, 0);
  if (err)
    return err;

  grub_video_get_viewport (&x, &y, &width, &height);

  {
    const char *str;
    int texty;
    grub_font_t sansbig;
    grub_font_t sans;
    grub_font_t sanssmall;
    grub_font_t fixed;
    struct grub_font_glyph *glyph;

    grub_video_create_render_target (&text_layer, width, height,
				     GRUB_VIDEO_MODE_TYPE_RGB
				     | GRUB_VIDEO_MODE_TYPE_ALPHA);

    grub_video_set_active_render_target (text_layer);

    color = grub_video_map_rgb (0, 255, 255);
    sansbig = grub_font_get ("Unknown Regular 16");
    sans = grub_font_get ("Unknown Regular 16");
    sanssmall = grub_font_get ("Unknown Regular 16");
    fixed = grub_font_get ("Fixed 20");
    if (! sansbig || ! sans || ! sanssmall || ! fixed)
      return grub_error (GRUB_ERR_BAD_FONT, "no font loaded");

    glyph = grub_font_get_glyph (fixed, '*');
    grub_font_draw_glyph (glyph, color, 200 ,0);

    color = grub_video_map_rgb (255, 255, 255);

    texty = 32;
    grub_font_draw_string ("The quick brown fox jumped over the lazy dog.",
			   sans, color, 16, texty);
    texty += grub_font_get_descent (sans) + grub_font_get_leading (sans);

    texty += grub_font_get_ascent (fixed);
    grub_font_draw_string ("The quick brown fox jumped over the lazy dog.",
			   fixed, color, 16, texty);
    texty += grub_font_get_descent (fixed) + grub_font_get_leading (fixed);

    /* To convert Unicode characters into UTF-8 for this test, the following
       command is useful:
       echo -ne '\x00\x00\x26\x3A' | iconv -f UTF-32BE -t UTF-8 | od -t x1
       This converts the Unicode character U+263A to UTF-8.  */

    /* Characters used:
       Code point  Description                    UTF-8 encoding
       ----------- ------------------------------ --------------
       U+263A      unfilled smiley face           E2 98 BA
       U+00A1      inverted exclamation point     C2 A1
       U+00A3      British pound currency symbol  C2 A3
       U+03C4      Greek tau                      CF 84
       U+00E4      lowercase letter a with umlaut C3 A4
       U+2124      set 'Z' symbol (integers)      E2 84 A4
       U+2287      subset symbol                  E2 8A 87
       U+211D      set 'R' symbol (real numbers)  E2 84 9D  */

    str =
      "Unicode test: happy\xE2\x98\xBA \xC2\xA3 5.00"
      " \xC2\xA1\xCF\x84\xC3\xA4u! "
      " \xE2\x84\xA4\xE2\x8A\x87\xE2\x84\x9D";
    color = grub_video_map_rgb (128, 128, 255);

    /* All characters in the string exist in the 'Fixed 20' (10x20) font.  */
    texty += grub_font_get_ascent(fixed);
    grub_font_draw_string (str, fixed, color, 16, texty);
    texty += grub_font_get_descent (fixed) + grub_font_get_leading (fixed);

    texty += grub_font_get_ascent(sansbig);
    grub_font_draw_string (str, sansbig, color, 16, texty);
    texty += grub_font_get_descent (sansbig) + grub_font_get_leading (sansbig);

    texty += grub_font_get_ascent(sans);
    grub_font_draw_string (str, sans, color, 16, texty);
    texty += grub_font_get_descent (sans) + grub_font_get_leading (sans);

    texty += grub_font_get_ascent(sanssmall);
    grub_font_draw_string (str, sanssmall, color, 16, texty);
    texty += (grub_font_get_descent (sanssmall)
	      + grub_font_get_leading (sanssmall));

    glyph = grub_font_get_glyph (fixed, '*');

    for (i = 0; i < 16; i++)
      {
	color = grub_video_map_color (i);
	palette[i] = color;
	grub_font_draw_glyph (glyph, color, 16 + i * 16, 220);
      }
  }

  grub_video_set_active_render_target (GRUB_VIDEO_RENDER_TARGET_DISPLAY);

  for (i = 0; i < 2; i++)
    {
      color = grub_video_map_rgb (0, 0, 0);
      grub_video_fill_rect (color, 0, 0, width, height);

      color = grub_video_map_rgb (255, 0, 0);
      grub_video_fill_rect (color, 0, 0, 100, 100);

      color = grub_video_map_rgb (0, 255, 255);
      grub_video_fill_rect (color, 100, 100, 100, 100);

      grub_video_set_viewport (x + 150, y + 150,
			       width - 150 * 2, height - 150 * 2);
      color = grub_video_map_rgb (77, 33, 77);
      grub_video_fill_rect (color, 0, 0, width, height);
      grub_video_swap_buffers ();
    }

  for (i = 0; i < 5; i++)
    {
      color = grub_video_map_rgb (i, 33, 77);
      grub_video_fill_rect (color, 0, 0, width, height);
      grub_video_blit_render_target (text_layer, GRUB_VIDEO_BLIT_BLEND, 0, 0,
                                     0, 0, width, height);
      grub_video_swap_buffers ();
    }

  grub_getkey ();

  grub_video_delete_render_target (text_layer);

  grub_video_restore ();

  for (i = 0; i < 16; i++)
    grub_printf("color %d: %08x\n", i, palette[i]);

  grub_errno = GRUB_ERR_NONE;
  return grub_errno;
}