[3/?] grub-core/gfxmenu/gui_list.c - some code cleaning
PATCH 1/1 [3/?] grub-core/gfxmenu/gui_list.c - some code cleaning
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.
Signature · 4 lines
With best regards, _______________________________ Vladimir Testov, ROSA Laboratory. www.rosalab.ru
Yeah, the patch.
Quoted 15 lines · Vladimir Testov
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
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel
Signature · 4 lines
With best regards, _______________________________ Vladimir Testov, ROSA Laboratory. www.rosalab.ru
grub-core/gfxmenu/gui_list.c +56 -21
@@ -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 ;
Quoted 6 lines · Vladimir Testov
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.
Like that? :)
2013-07-16 Vladimir Testov <[email protected]>
* 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.
Quoted 13 lines · Vladimir 'φ-coder/phcoder' Serbinenko
Quoted 5 lines · Vladimir Testov
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
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel
Signature · 4 lines
With best regards, _______________________________ Vladimir Testov, ROSA Laboratory. www.rosalab.ru