All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] [3/?] grub-core/gfxmenu/gui_list.c - some code cleaning
@ 2013-07-15 13:31 Vladimir Testov
  2013-07-15 13:31 ` Vladimir Testov
  2013-07-15 15:35 ` Vladimir 'φ-coder/phcoder' Serbinenko
  0 siblings, 2 replies; 4+ messages in thread
From: Vladimir Testov @ 2013-07-15 13:31 UTC (permalink / raw)
  To: grub-devel

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


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] [3/?] grub-core/gfxmenu/gui_list.c - some code cleaning
  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
  2013-07-15 15:35 ` Vladimir 'φ-coder/phcoder' Serbinenko
  1 sibling, 0 replies; 4+ messages in thread
From: Vladimir Testov @ 2013-07-15 13:31 UTC (permalink / raw)
  To: grub-devel

[-- 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;

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] [3/?] grub-core/gfxmenu/gui_list.c - some code cleaning
  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
@ 2013-07-15 15:35 ` Vladimir 'φ-coder/phcoder' Serbinenko
  2013-07-16  7:56   ` Vladimir Testov
  1 sibling, 1 reply; 4+ messages in thread
From: Vladimir 'φ-coder/phcoder' Serbinenko @ 2013-07-15 15:35 UTC (permalink / raw)
  To: The development of GNU GRUB

On 15.07.2013 15:31, 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.
>
Attach Changelog entries.


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] [3/?] grub-core/gfxmenu/gui_list.c - some code cleaning
  2013-07-15 15:35 ` Vladimir 'φ-coder/phcoder' Serbinenko
@ 2013-07-16  7:56   ` Vladimir Testov
  0 siblings, 0 replies; 4+ messages in thread
From: Vladimir Testov @ 2013-07-16  7:56 UTC (permalink / raw)
  To: grub-devel; +Cc: Vladimir 'φ-coder/phcoder' Serbinenko

Like that? :)

2013-07-16  Vladimir Testov <vladimir.testov@rosalab.ru>

	* grub-core/gfxmenu/gui_list.c: Code cleaning. Create colors only
	once. Define selected_item_font and selected_item_color so these
	values won't be recount multiple times on each redrawing.

On Monday, July 15, 2013 05:35:30 PM Vladimir 'φ-coder/phcoder' Serbinenko 
wrote:
> On 15.07.2013 15:31, 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.
> 
> Attach Changelog entries.
> 
> _______________________________________________
> 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


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2013-07-16  7:56 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
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
2013-07-15 15:35 ` Vladimir 'φ-coder/phcoder' Serbinenko
2013-07-16  7:56   ` Vladimir Testov

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.