All of lore.kernel.org
 help / color / mirror / Atom feed
From: Vladimir Testov <vladimir.testov@rosalab.ru>
To: grub-devel@gnu.org
Subject: Re: [PATCH] [3/?] grub-core/gfxmenu/gui_list.c - some code cleaning
Date: Mon, 15 Jul 2013 17:31:56 +0400	[thread overview]
Message-ID: <3685549.UdAN4IxoBL@icedphoenix> (raw)
In-Reply-To: <8981891.3POqYUAcJJ@icedphoenix>

[-- Attachment #1: Type: text/plain, Size: 729 bytes --]

Yeah, the patch.

On Monday, July 15, 2013 05:31:11 PM Vladimir Testov wrote:
> First. The structure should be changed a little to apply the 4th patch and
> some of the following patches.
> Second. After applying the patch GRUB won't count some values during every
> redrawing of the boot menu.
> Third. For me, source code became a little more human-readable.
> --
> With best regards,
> _______________________________
> Vladimir Testov, ROSA Laboratory.
> www.rosalab.ru
> 
> _______________________________________________
> Grub-devel mailing list
> Grub-devel@gnu.org
> https://lists.gnu.org/mailman/listinfo/grub-devel
-- 
With best regards,
_______________________________
Vladimir Testov, ROSA Laboratory.
www.rosalab.ru

[-- Attachment #2: grub-list-code-cleaning.patch --]
[-- Type: text/x-patch, Size: 5385 bytes --]

diff -Naur grub-new2/grub-core/gfxmenu/gui_list.c grub-new3/grub-core/gfxmenu/gui_list.c
--- grub-new2/grub-core/gfxmenu/gui_list.c	2013-07-11 18:17:38.856943765 +0400
+++ grub-new3/grub-core/gfxmenu/gui_list.c	2013-07-15 15:30:26.585116409 +0400
@@ -42,9 +42,13 @@
   int item_spacing;
   grub_font_t item_font;
   grub_font_t selected_item_font;
-  grub_video_rgba_color_t item_color;
+  int selected_item_font_set;
+  grub_video_rgba_color_t item_color_name;
+  grub_video_color_t item_color;
   int selected_item_color_set;
-  grub_video_rgba_color_t selected_item_color;
+  grub_video_rgba_color_t selected_item_color_name;
+  grub_video_color_t selected_item_color;
+  int need_to_recreate_colors;
 
   int draw_scrollbar;
   int need_to_recreate_scrollbar;
@@ -149,6 +153,21 @@
   return (self->scrollbar_frame != 0 && self->scrollbar_thumb != 0);
 }
 
+static void
+check_colors (list_impl_t self)
+{
+  if (self->need_to_recreate_colors)
+    {
+      self->item_color = grub_video_map_rgba_color (self->item_color_name);
+      self->selected_item_color =
+        (self->selected_item_color_set
+         ? grub_video_map_rgba_color (self->selected_item_color_name)
+         : self->item_color);
+
+      self->need_to_recreate_colors = 0;
+    }
+}
+
 static const char *
 list_get_id (void *vself)
 {
@@ -262,17 +281,27 @@
   sviewport.width = cwidth - string_left_offset;
   sviewport.height = item_height;
 
+  check_colors (self);
+
   for (visible_index = 0, menu_index = self->first_shown_index;
        visible_index < num_shown_items && menu_index < self->view->menu->size;
        visible_index++, menu_index++)
     {
       int is_selected = (menu_index == self->view->selected);
       struct grub_video_bitmap *icon;
+      grub_font_t font;
+      grub_video_color_t color;
 
       if (is_selected)
         {
-          selbox->draw (selbox, 0,
-                        item_top - sel_toppad);
+          selbox->draw (selbox, 0, item_top - sel_toppad);
+          font = self->selected_item_font;
+          color = self->selected_item_color;
+        }
+      else
+        {
+          font = self->item_font;
+          color = self->item_color;
         }
 
       icon = get_item_icon (self, menu_index);
@@ -284,20 +313,12 @@
 
       const char *item_title =
         grub_menu_get_entry (self->view->menu, menu_index)->title;
-      grub_font_t font =
-        (is_selected && self->selected_item_font
-         ? self->selected_item_font
-         : self->item_font);
-      grub_video_rgba_color_t text_color =
-        ((is_selected && self->selected_item_color_set)
-         ? self->selected_item_color
-         : self->item_color);
 
       sviewport.y = item_top;
       grub_gui_set_viewport (&sviewport, &svpsave);
       grub_font_draw_string (item_title,
                              font,
-                             grub_video_map_rgba_color (text_color),
+                             color,
                              0,
                              string_top_offset);
       grub_gui_restore_viewport (&svpsave);
@@ -445,17 +466,23 @@
   if (grub_strcmp (name, "item_font") == 0)
     {
       self->item_font = grub_font_get (value);
+      if (!self->selected_item_font_set)
+        self->selected_item_font = self->item_font;
     }
   else if (grub_strcmp (name, "selected_item_font") == 0)
     {
       if (! value || grub_strcmp (value, "inherit") == 0)
-        self->selected_item_font = 0;
+        self->selected_item_font = self->item_font;
       else
-        self->selected_item_font = grub_font_get (value);
+        {
+          self->selected_item_font = grub_font_get (value);
+          self->selected_item_font_set = 1;
+        }
     }
   else if (grub_strcmp (name, "item_color") == 0)
     {
-      grub_video_parse_color (value, &self->item_color);
+      if (grub_video_parse_color (value, &self->item_color_name) == GRUB_ERR_NONE)
+        self->need_to_recreate_colors = 1;
     }
   else if (grub_strcmp (name, "selected_item_color") == 0)
     {
@@ -465,9 +492,12 @@
         }
       else
         {
-          if (grub_video_parse_color (value, &self->selected_item_color)
+          if (grub_video_parse_color (value, &self->selected_item_color_name)
               == GRUB_ERR_NONE)
-            self->selected_item_color_set = 1;
+            {
+              self->selected_item_color_set = 1;
+              self->need_to_recreate_colors = 1;
+            }
         }
     }
   else if (grub_strcmp (name, "icon_width") == 0)
@@ -620,10 +650,15 @@
   self->item_icon_space = 4;
   self->item_spacing = 16;
   self->item_font = default_font;
-  self->selected_item_font = 0;    /* Default to using the item_font.  */
-  self->item_color = default_fg_color;
+  self->selected_item_font = default_font;
+  self->selected_item_font_set = 0; /* Default to using the item_font.  */
+  self->item_color_name = default_fg_color;
+  self->item_color = grub_video_map_rgba_color (self->item_color_name);
   self->selected_item_color_set = 0;  /* Default to using the item_color.  */
-  self->selected_item_color = default_fg_color;
+  self->selected_item_color_name = default_fg_color;
+  self->selected_item_color =
+    grub_video_map_rgba_color (self->selected_item_color_name);
+  self->need_to_recreate_colors = 0;
 
   self->draw_scrollbar = 1;
   self->need_to_recreate_scrollbar = 1;

  reply	other threads:[~2013-07-15 13:32 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-07-15 13:31 [PATCH] [3/?] grub-core/gfxmenu/gui_list.c - some code cleaning Vladimir Testov
2013-07-15 13:31 ` Vladimir Testov [this message]
2013-07-15 15:35 ` Vladimir 'φ-coder/phcoder' Serbinenko
2013-07-16  7:56   ` Vladimir Testov

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=3685549.UdAN4IxoBL@icedphoenix \
    --to=vladimir.testov@rosalab.ru \
    --cc=grub-devel@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.