Difference between revisions of "User:Vasily.podvornyak"

From Rosalab Wiki
Jump to: navigation, search
(Created page with "<span style="font-size: 300%">'''Grub2 2.00'''</span> <br> Плавая по просторам большой мировой сети, мне не удалось найти ...")
 
(Blanked the page)
 
(20 intermediate revisions by the same user not shown)
Line 1: Line 1:
<span style="font-size: 300%">'''Grub2 2.00'''</span>
 
<br>
 
Плавая по просторам большой мировой сети, мне не удалось найти руководства по созданию тем оформления загрузчика GRUB2, которое бы помогло мне понять смысл каждого значения и каждой переменной на конкретных примерах. Несмотря на это, когда вы создаёте тему оформления, вы хотите получить конкретный результат. Так, что-бы каждая точка была там, где вам нужно. Вот я и решил написать такое руководство, пока просматривал исходный код. Цель данного руковдства представить каждую возможность графического оформления, показать особенности и ограничения в офомлении загрузчика GRUB2, представить план по созданию новой темы, с точностью до каждого пикселя.
 
  
='''С чего начать'''=
 
 
И так, мы хотим создать оформление для загрузчика. Давайте пройдём этот путь шаг за шагом.
 
 
=='''Создай дирректорию'''==
 
 
Сначала, создайте пустую дирректорию для файлов новой темы оформления.
 
 
Так же желательно создать поддирректорию <tt>/boot/grub2/themes/</tt>
 
 
(примечание, предпологается что загрузчик установлен в дирректории <tt>/boot/grub2/</tt>)
 
 
Let it be directory <tt>/boot/grub2/themes/test/</tt>
 
 
=='''create text file'''==
 
 
We should create main theme file in the directory we just have created.
 
 
It is recommended to call the file <tt>theme.txt</tt>.
 
 
So, we have created file <tt>/boot/grub2/themes/test/theme.txt</tt>
 
 
(hereinafter, <tt>theme.txt</tt> or main theme file)
 
 
=='''parameter <tt>GRUB_THEME</tt> in <tt>/etc/default/grub</tt>'''==
 
 
To make the bootloader switch to our theme, we should set
 
 
parameter <tt>GRUB_THEME</tt> in file <tt>/etc/default/grub</tt>.
 
 
In other words, we should write a string <tt>GRUB_THEME=/boot/grub2/themes/test/theme.txt</tt>.
 
 
After the sign "<tt>=</tt>" we should write the absolute path to the main theme file.
 
 
If the string <tt>GRUB_THEME=...</tt> already exists in <tt>/etc/default/grub</tt>,
 
 
we should rewrite it, so it will be <tt>GRUB_THEME=/boot/grub2/themes/test/theme.txt</tt>.
 
 
There shouldn't be two strings for the same parameter.
 
 
=='''bootloader configuration file <tt>/boot/grub2/grub.cfg</tt>'''==
 
 
Changes in this file won't be applied until we regenerate bootloader configuration file.
 
 
Usually, there is script <tt>update-grub2</tt> in the system. It should be run with <tt>root</tt> rights.
 
 
In case there is no such script in the system we should run command <tt>grub2-mkconfig -o /boot/grub2/grub.cfg</tt> with <tt>root</tt> rights.
 
 
<tt>update-grub2</tt> does exactly the same command.
 
 
<tt>update-grub2</tt> should be called each time we make changes to <tt>/etc/default/grub</tt>.
 
 
Most of Grub2 theme options are described in <tt>theme.txt</tt>. Grub2 parses this file each time during boot process. So we should reboot to see result of changes made to <tt>theme.txt</tt> or to our theme directory.
 
<tt>update-grub2</tt> writes main theme file's path to the bootloader's configuration file.
 
 
<br>
 
 
='''Common conceptions'''=
 
 
Start with reading [[Grub2 theme / reference#Main file syntax |
 
Main file syntax]].
 
 
Each parameter have a predefined type.
 
 
You can read about data types [[Grub2 theme / reference#Data types | Here]].
 
 
Note, that global options and components' names are checked. If there is an error, error message will be shown during boot process. It is different for component's options. If there is an error then parameter won't be applied and error message won't be shown.
 
 
=='''Types of elements'''==
 
There are some predefined types:
 
 
; root element
 
: Top level of <tt>theme.txt</tt>. Here we set global options.
 
 
; Boot menu (<tt>boot_menu</tt>)
 
: The main element. Here boot menu's options are set.
 
 
; Horizontal timeout indicator (<tt>progress_bar</tt>)
 
: Indication of elapsed time to execution the default entry of the boot menu. Uses horizontal tab and text.
 
 
; Circular timeout indicator (<tt>circular_progress</tt>)
 
: Indication of elapsed time to execution the default entry of the boot menu. Uses circular animation.
 
 
; Text string (<tt>label</tt>)
 
: Output a text string.
 
 
; Image (<tt>image</tt>)
 
: Output an image.
 
 
; Vertical container (<tt>vbox</tt>)
 
: Container. Element which contains other elements. Outputs elements vertically one by one from top to bottom.
 
 
; Horizontal container (<tt>hbox</tt>)
 
: Container. Element which contains other elements. Outputs elements horizontally one be one from left to right.
 
 
; Canvas (<tt>canvas</tt>)
 
: Container. Element which contains other elements. Coordinates should be set for each child element.
 
 
Root element is an instance canvas with some additional options. It is stretched to the screen dimensions.
 
 
=='''Images'''==
 
Image is stretched to the defined sized, if these sizes are greater than real image's sizes. Minimal values are real image sizes.
 
 
You should take this feature into account while selecting background image. There are several types of displays. The same image can look different on displays with aspect ratio 4:3 and 16:9.
 
 
If image is an logotype you should use absolute values for parameters width and height so there won't be any distortions.
 
 
Using stretching it is easy to do different kinds of gradients. For example, you could use gradient image 1px width.
 
 
=='''Graphical decoration'''==
 
Graphical decoration of an element consists of 9 zones - central, south, south-west, west etc.
 
 
4 diagonal zones (north-west etc) are not stretched.
 
 
East and west zones are stretched by vertical.
 
 
North and south zones are stretched by horizontal.
 
 
Central zone is stretched by vertical and by horizontal.
 
 
If there is a diagonal zone in the decoration so there should be both side zones in the decoration, connected with the diagonal zone. E.g. if there is north-west zone, so there should be both north and west zones. Moreover, constant values of the diagonal zone should be equal to corresponding values of side zones. In our example, height of north-west zone should be equal to the height of north zone and width of the north-west zone should be equal to the width of the west zone.
 
 
=='''Fonts'''==
 
Fonts should be created using special utility <tt>grub2-mkfont</tt>. More detailed information in [["Font creation guide"|"Font creating guide"]]
 
 
<br>
 
 
='''Test scheme description'''=
 
 
=='''decoration elements'''==
 
Increased in 5 times for better understanding. Alpha-channel - 75%. (transparency)
 
 
Dark red background - for clarity.
 
 
===graphical decoration element===
 
 
{| class="wikitable" border="1" style="background: #600000;"
 
|+ inbox_*.png
 
|-
 
| [[Image:grub2_guide_inbox_nw.png|25px]] || [[Image:grub2_guide_inbox_n.png|5px]] || [[Image:grub2_guide_inbox_ne.png|25px]]
 
|-
 
| [[Image:grub2_guide_inbox_w.png|25px]] || [[Image:grub2_guide_inbox_c.png|5px]] || [[Image:grub2_guide_inbox_e.png|25px]]
 
|-
 
| [[Image:grub2_guide_inbox_sw.png|25px]] || [[Image:grub2_guide_inbox_s.png|5px]] || [[Image:grub2_guide_inbox_se.png|25px]]
 
|}
 
 
===graphical decoration element===
 
{| class="wikitable" border="1" style="background: #600000;"
 
|+ button_*.png
 
|-
 
| [[Image:grub2_guide_inbox_se.png|25px]] || [[Image:grub2_guide_inbox_s.png|5px]] || [[Image:grub2_guide_button_ne.png|25px]]
 
|-
 
| [[Image:grub2_guide_inbox_e.png|25px]] || [[Image:grub2_guide_inbox_c.png|5px]] || [[Image:grub2_guide_inbox_w.png|25px]]
 
|-
 
| [[Image:grub2_guide_button_ne.png|25px]] || [[Image:grub2_guide_inbox_n.png|5px]] || [[Image:grub2_guide_inbox_nw.png|25px]]
 
|}
 
 
===boot menu decoration===
 
 
{| class="wikitable" border="1" style="background: #600000;"
 
|+ menu_*.png
 
|-
 
| [[Image:grub2_guide_inbox_nw.png|25px]] || [[Image:grub2_guide_inbox_n.png|5px]] || [[Image:grub2_guide_menu_ne.png|75px]]
 
|-
 
| [[Image:grub2_guide_inbox_w.png|25px]] || [[Image:grub2_guide_inbox_c.png|5px]] || [[Image:grub2_guide_menu_e.png|75px]]
 
|-
 
| [[Image:grub2_guide_inbox_sw.png|25px]] || [[Image:grub2_guide_inbox_s.png|5px]] || [[Image:grub2_guide_menu_se.png|75px]]
 
|}
 
 
===scrollbar background===
 
 
{| class="wikitable" border="1" style="background: #600000;"
 
|+ scrollbar_frame_*.png
 
|-
 
| [[Image:grub2_guide_frame_n.png|50px]]
 
|-
 
| [[Image:grub2_guide_frame_c.png|50px]]
 
|-
 
| [[Image:grub2_guide_frame_s.png|50px]]
 
|}
 
 
===scrollbar thumb===
 
 
{| class="wikitable" border="1" style="background: #600000;"
 
|+ scrollbar_thumb_*.png
 
|-
 
| [[Image:grub2_guide_thumb_n.png|50px]]
 
|-
 
| [[Image:grub2_guide_thumb_c.png|50px]]
 
|-
 
| [[Image:grub2_guide_thumb_s.png|50px]]
 
|}
 
 
===progress bar decoration===
 
{| class="wikitable" border="1" style="background: #600000;"
 
|+ progress_*.png
 
|-
 
| [[Image:grub2_guide_progress_c.png|5px]]
 
|}
 
 
=='''images'''==
 
 
===central image of circular progress===
 
{| class="wikitable" border="1" style="background: #600000;"
 
|+ center.png
 
|-
 
| [[Image:grub-guide-circular-center.png]]
 
|}
 
 
===tick image of circular progress===
 
{| class="wikitable" border="1" style="background: #600000;"
 
|+ tick.png
 
|-
 
| [[Image:grub-guide-circular-tick.png|25px]]
 
|}
 
 
<br>
 
 
='''Properties of elements'''=
 
 
Complete description of option values with screenshots and schemes.
 
 
<br>
 
 
=='''Common properties'''==
 
[[Grub2 theme / reference#Common options | brief description]]
 
 
<tt>left, top, width, height</tt> - coordinates of the rectangle, containing an element.
 
 
<tt>id</tt> - Using special value of element's id affects the way this element will be shown. Using value other than special won't affect anything.
 
 
<br>
 
 
=='''Root element'''==
 
[[Grub2 theme / reference#Global options | brief description]]
 
 
Root element is the element containing every element of the theme. Also it contains several global options. Root element is an extended canvas element.
 
 
Note, that global option name contains minus character (<tt>"-"</tt>, e.g. <tt>"terminal-box"</tt>), but elements' options contain underline character (<tt>"_"</tt>, e.g. <tt>"item_height"</tt>). Also note that global options use colon character as the divider (<tt>":"</tt>, e.g. <tt>"title_text: "GNU Grub""</tt>), but elements options use equal sign character as the divider (<tt>"="</tt>, e.g. <tt>"item_height = 20"</tt>).
 
 
===<tt>desktop-color, desktop-image</tt> - background===
 
First is background color.
 
 
Second is background image.
 
 
If <tt>desktop-image</tt> is set then <tt>desktop-color</tt> is not used.
 
 
Image should be placed into the theme's directory.
 
 
Image is scaled to the screen resolution.
 
 
===<tt>title-text, title-color, title-font</tt> - title settings===
 
Title decor. If the title shouldn't be shown, set <tt>title-text=""</tt>.
 
 
Title text is always center aligned and text's baseline is placed at <tt>40 + ascent</tt> from the top side of the screen. (see [[#Font creating guide|Font creating guide]])
 
 
title-text: "Title Text"
 
title-color: "#FFFFFF"
 
desktop-image: "background.png"
 
 
[[Image:grub2-guide-title-en.png]]
 
 
===<tt>terminal-box</tt> - console decoration===
 
Graphical decoration of the console.
 
 
Decoration is drawn OUTSIDE of the console rectangle. Coordinates of the console are constant and hard-coded. They can be changed using a patch. See [[#Console moving|below]].
 
 
Note, that console is drawn on center slice with 3px padding from each side.
 
 
Console background is set in <tt>/etc/default/grub</tt>. See [[#GRUB_BACKGROUND|below]].
 
 
An image for the console background should not be transparent.
 
 
By default there will be black screen.
 
 
===<tt>terminal-font</tt> - console font===
 
The name of the font, used in the console.
 
 
After a new font has been added to the theme's directory, <tt>update-grub2</tt> should be executed.
 
 
See more about font's creating in [[#Font creation guide|font creating]]
 
 
title-text: ""
 
desktop-image: "background.png"
 
terminal-font: "Droid Sans Mono Regular 11"
 
terminal-box: "inbox_*.png"
 
 
Hereinafter, global options are exactly the same.
 
 
[[Image:grub2-guide-terminal-en.png ]]
 
 
===<tt>message-font, message-color, message-bg-color</tt> - not used===
 
These parameters can be set, but they aren't used currently.
 
 
<br>
 
 
=='''<tt>boot_menu</tt> - boot menu'''==
 
[[Grub2 theme / reference#Boot menu (boot_menu) | brief description]]
 
 
The main element. Shows the list of installed operating systems. We can select the system we'd like to boot in.
 
 
===<tt>left, top, width, height</tt> - coordinates of the rectangle===
 
Standard parameters. Don't forget to set them.
 
 
===<tt>item_color, item_font, selected_item_color, selected_item_font</tt> - font and color of boot menu items===
 
We must understand which item is selected, so it should be highlighted somehow. We can use font, color or graphical decoration.
 
<tt>item_color, item_font</tt> - color and font of non-active menu items
 
<tt>selected_item_color, selected_item_font</tt> - color and font of the selected item
 
 
+ boot_menu {
 
        left = 50%-300
 
        top = 50%-100
 
        width = 600
 
        height = 300
 
 
 
        selected_item_color = "#0000FF"
 
}
 
 
[[Image:grub2-guide-bootmenu-simple-en.png]]
 
 
See more about font's creating in [[#Font creation guide|font creating]]
 
 
===<tt>seleted_item_pixmap_style, item_pixmap_style</tt>  - items decoration===
 
The decoration is drawn OUTSIDE of menu item.
 
 
By default we can set graphical decoration only for the selected menu item.
 
 
In ROSA you could set graphical decoration for non-active menu items.
 
 
Lets define sizes of selected item's frame as <tt>pad_left</tt>, <tt>pad_top</tt>, <tt>pad_right</tt> and <tt>pad_bottom</tt>. Full item's height will be <tt>item_height + pad_top + pad_bottom - 1</tt>.
 
 
You should take decreasing by 1 into account to achieve the desired size of the selected item.
 
 
+ boot_menu {
 
        left = 50%-300
 
        top = 50%-100
 
        width = 600
 
        height = 300
 
 
 
        selected_item_color = "#0000FF"
 
        selected_item_pixmap_style = "button_*.png"
 
}
 
 
[[Image:grub2-guide-bootmenu-selected-box-en.png]]
 
 
===<tt>menu_pixmap_style</tt> - boot menu decoration===
 
Menu decoration is drawn INSIDE the desired rectangle of the element (boot menu). Sized of this decoration are counted for menu items (menu items are drawn in the center slice). It is more complicated for a scrollbar (see [[#scrollbar_frame, scrollbar_thumb, scrollbar_width, scrollbar - scrollbar settings|below]]).
 
 
===<tt>item_padding</tt> - padding===
 
Sets printing area of boot menu items - rectangle inside central slice of menu's graphical decoration (or entire menu rectangle if no graphical decoration is set) with padding <tt>item-padding</tt> from each side of central slice edges (or from edges of boot menu's rectangle if no graphical decoration is set).
 
 
Note, that <tt>item_padding</tt> does not affect scrollbar's outfit. Modify graphical decorations of menu and scrollbar if changes in scrollbar padding are needed (e.g. you can add transparent pixels to corresponding areas)
 
 
===<tt>height, item_height, item_spacing</tt> - items composition===
 
Distance between bottom sides of menu items (see picture) is always <tt>item_height + item_spacing.</tt>
 
 
Note, that formula of shown items number includes menu's frame and <tt>item_padding</tt>, but excludes <tt>pad_top</tt> and <tt>pad_bottom</tt>. (see picture)
 
 
<tt>height</tt> should be count using unobvious formula. N - is the number of items we would like to see. Total <tt>height</tt> should be equal to
 
 
<tt>2*item_padding + menu_pad_top + menu_pad_bottom + (N - 1)*(item_height + item_spacing)
 
+ pad_top + pad_bottom + item_height - 1</tt>
 
 
Also note, that minimal number of shown items (N) - is 3.
 
 
If height is less then the value, counted with this formula, number of menu items is big enough and the bottom item is selected, then graphical decoration of the selected item won't be drawn completely.
 
if height is greater then the value, counted with this formula, number of menu item is big enough and the bottom item is selected, then the scrollbar's bottom edge will not be aligned with bottom edge of the selected item's graphical decoration.
 
 
+ boot_menu {
 
        left = 50%-300
 
        top = 50%-100
 
        width = 600
 
        height = 289
 
   
 
        selected_item_color = "#0000FF"
 
        selected_item_pixmap_style = "button_*.png"
 
 
        menu_pixmap_style = "inbox_*.png"
 
 
        item_padding = 20
 
       
 
        item_spacing = 20
 
        item_height = 30
 
}
 
Height is counted using the given formula.
 
 
[[Image:grub2-guide-bootmenu-vertical-scheme.png]]
 
 
===<tt>icon-width, icon-height, item_icon_space</tt> - icons and icon space===
 
By default,
 
icon_width = 32
 
icon_height = 32
 
item_icon_space = 4
 
 
Text is indented additionally for <tt>icon_width + item_icon_space</tt> from the left edge of the item's drawing area.
 
In other words, free space for an icon is always left independently of is there an icon to be drawn or not.
 
 
If this behavior is unwanted you should null <tt>icon_width</tt> and set desired value for <tt>item_icon_space</tt>.
 
 
Also note, that width of menu items is decreased by 2 pixels. That way, we will see additional 2 pixels of free space from the right edge of east slice of the menu.
 
 
Note, that font's symbols can include empty pixels from either side. E.g. in out test scheme, distance from the left edge is 36 by default (<tt>icond_width + item_icon_space</tt>), but distance to the first pixel of the first symbol is 37.
 
 
[[Image:grub2-guide-bootmenu-icon-space.png]]
 
 
===Using of icons===
 
 
If you'd like to use icons you should make directory <tt>image</tt> in the theme directory.
 
 
Then you should place icons in <tt>png</tt> format to the directory <tt>image</tt>. Icon's name should correspond to some predefined class.
 
 
Default classes:
 
* windows > os
 
* gnu-linux > gnu > os
 
* osx > darwin > os
 
* hurd > gnu > os
 
 
More important class is to the left. If icon <tt>windows.png</tt> is found then it will be shown. The icon <tt>os.png</tt> will not.
 
 
Main system's class (equal to it's name) will be available also. (main system in this case - is the system where <tt>update-grub2</tt> script was called). This class is more important than <tt>gnu-linux</tt>.
 
 
E.g. for ROSA system this class will be "<tt>rosa</tt>" etc. You can find classes in the file <tt>/boot/grub2/grub.cfg</tt>.
 
 
With patch applied to ROSA, such class will be shown for every other installed OS on the particular computer.
 
 
===<tt>scrollbar_frame, scrollbar_thumb, scrollbar_width, scrollbar</tt> - scrollbar settings===
 
 
Let's see detailed information about scrollbars.
 
 
* Do not use slices different from north, south and center for <tt>scrollbar_thumb</tt>.
 
 
* You could use all 9 slices for <tt>scrollbar_frame</tt>.
 
 
* You can increase padding from any side of the scrollbar by adding transparent pixels to the corresponding slice.
 
 
* Scrollbar is drawn to the right of the center slice. So, if we don't have menu's graphical decoration or there isn't east slice in the menu's graphical decoration we won't see scrollbar even if it's needed.
 
 
* Scrollbar is drawn only if needed.
 
 
* Note that width of the boot menu is decreases by 2 pixels (from maximum width). Because of that distance between menu items and the scrollbar is always at least 2 pixels.
 
 
* You have to set both <tt>scrollbar_frame</tt> and <tt>scrollbar_thumb</tt>. If one of these parameters isn't set you won't see the scrollbar.
 
 
* Width of <tt>scrollbar_frame</tt> and width of <tt>scrollbar_thumb</tt> can be different.
 
 
* <tt>scrollbar_frame</tt> is drawn in the east slice of menu's graphical decoration. <tt>scrollbar_thumb</tt> is drawn entirely in the center slice of <tt>scrollbar_frame</tt>.
 
 
* <tt>scrollbar_width</tt> - width of the scrollbar. It means width of the central part of <tt>scrollbar_frame</tt>. If sum of <tt>scrollbar_width</tt> and widths of east and west slices of <tt>scrollbar_frame</tt> are less than width of the east slice of menu's graphical decoration, then the scrollbar won't be drawn completely.
 
 
* You could set value <tt>False</tt> for <tt>scrollbar</tt>. In that case the scrollbar won't be shown. Alternative: just don't set parameters <tt>scrollbar_thumb</tt> and <tt>scrollbar_frame</tt>.
 
 
* As it was said before, <tt>item_padding</tt> don't affects the scrollbar.
 
 
In this example there are no additional pixels for the scrollbar in the east slice of menu's graphical decoration.
 
+ boot_menu {
 
        left = 50%-300
 
        top = 50%-100
 
        width = 600
 
        height = 289
 
       
 
        selected_item_color = "#0000FF"
 
        selected_item_pixmap_style = "button_*.png"
 
       
 
        menu_pixmap_style = "inbox_*.png"
 
     
 
        item_padding = 20
 
       
 
        item_height = 30
 
        item_spacing = 20
 
       
 
        scrollbar_thumb = "scrollbar_thumb_*.png"
 
        scrollbar_frame = "scrollbar_frame_*.png"
 
        scrollbar_width = 10
 
}
 
 
As we can see, scrollbar isn't completely drawn.
 
 
[[Image:grub2-guide-bootmenu-scrollbar-incorrect-menu-box.png]]
 
 
In this example we have changed menu's graphical decoration. We'll use this configuration of the boot menu hereinafter.
 
<tt>boot_menu</tt>.
 
+ boot_menu {
 
        left = 50%-300
 
        top = 50%-100
 
        width = 600
 
        height = 289
 
       
 
        selected_item_color = "#0000FF"
 
        selected_item_pixmap_style = "button_*.png"
 
       
 
        menu_pixmap_style = "menu_*.png"
 
     
 
        item_padding = 20
 
       
 
        item_height = 30
 
        item_spacing = 20
 
       
 
        scrollbar_thumb = "scrollbar_thumb_*.png"
 
        scrollbar_frame = "scrollbar_frame_*.png"
 
        scrollbar_width = 10
 
}
 
 
Now the scrollbar is correctly displayed. Also we can see that <tt>item_padding</tt> does not affect the scrollbar.
 
 
[[Image:grub2-guide-bootmenu-scrollbar-menu-box.png]]
 
 
===<tt>visible</tt> - don't show boot menu===
 
We can set value <tt>False</tt> for the <tt>visible</tt> property. That way the boot menu won't be shown. Alternative: do not describe <tt>boot_menu</tt> component in the main theme file.
 
 
<br>
 
 
=='''<tt>progress_bar</tt> - Horizontal indicator of elapsed time'''==
 
[[Grub2 theme / reference#Horizontal indicator of elapsed time (progress_bar)| Brief description]]
 
 
This element displays elapsed time to execution of the default entry.
 
 
Progress starts from non-zero length.
 
 
===<tt>left, top, width, height</tt> - coordinates of the rectangle===
 
Standard parameters. Don't forget to set them.
 
 
Note that if <tt>width</tt> or <tt>height</tt> is less than needed to display the given text then <tt>width</tt> or <tt>height</tt> will be auto-increased.
 
 
===<tt>id</tt> - identificator===
 
To display countdown (visually or textually) you should set predefined value to <tt>id</tt>.
 
id = "__timeout__"
 
 
===<tt>text</tt> - text, displayed on the progress bar===
 
Text to output on the countdown indicator.
 
There are several predefined special values. They have special meaning and are translated to different languages.
 
* @TIMEOUT_NOTIFICATION_SHORT@ for "Ns"
 
* @TIMEOUT_NOTIFICATION_MIDDLE@ for "Ns remaining."
 
* @TIMEOUT_NOTIFICATION_LONG@ for "The highlighted entry will be executed automatically in Ns."
 
<tt>N</tt> is an amount of seconds to execution of the default entry. The string is updated every second.
 
Also you can set any constant text value.
 
 
===<tt>text-color, font</tt> - color and font of the text===
 
Font and font color of the text string, printed on the indicator.
 
 
See more about font's creating in [[#Font creation guide|font creating]]
 
 
===Mono-color and graphical modes of decoration===
 
There are 2 options of decoration:
 
* mono-color mode, with areas filled with fixed colors and 1px border
 
* graphical mode, with graphical decorations
 
If one of the options for graphical decoration is used then will be turned on the second option. Otherwise the first option will be used.
 
 
See detailed information below.
 
 
===<tt>bg_color, fg_color, border_color</tt> - for mono-color mode ===
 
 
+ progress_bar {
 
        left = 50%-300
 
        top = 50%+200
 
        width = 600
 
        height = 50
 
     
 
        id = "__timeout__"
 
        text = "@TIMEOUT_NOTIFICATION_LONG@"
 
     
 
        border_color = "white"
 
}
 
 
Default value are used in this example:
 
bg_color = "128, 128, 128"
 
fg_color = "200, 200, 200"
 
 
[[Image:grub2-guide-progress-bar-mono-en.png]]
 
 
===<tt>bar_style, highlight_style</tt> - for graphical mode===
 
 
Note, it is recommended to use only central slice for the <tt>highlight_style</tt> parameter. Otherwise the countdown indicator will be shown incorrectly.
 
 
Note, using of any of these parameters turns on the graphical mode.
 
 
+ progress_bar {
 
        left = 50%-300
 
        top = 50%+200
 
        width = 600
 
        height = 50
 
     
 
        id = "__timeout__"
 
        text = "@TIMEOUT_NOTIFICATION_LONG@"
 
     
 
        bar_style = "inbox_*.png"
 
        highlight_style = "progress_*.png"
 
}
 
 
[[Image:grub2-guide-progress-bar-styled-en.png]]
 
 
===Remove decoration===
 
 
If you'd like to remove decorations so only the text string will be shown you should set equal values to <tt>bar_styly</tt> and <tt>highlight_style</tt>.
 
 
The value can be any text value. This is not necessary for the value to be the name of some real graphical decoration.
 
 
The value must include the symbol "<tt>*</tt>".
 
 
In the following example text color is "white".
 
 
+ progress_bar {
 
        left = 50%-300
 
        top = 50%+200
 
        width = 600
 
        height = 50
 
     
 
        id = "__timeout__"
 
        text = "@TIMEOUT_NOTIFICATION_LONG@"
 
     
 
        text_color = "white"
 
     
 
        bar_style = "*"
 
        highlight_style = "*"
 
}
 
 
[[Image:grub2-guide-progress-bar-only-text-en.png]]
 
 
===<tt>visible</tt> - do not show progress bar===
 
You could set the value <tt>False</tt> to this parameter. That way progress bar won't be shown. Alternative: just don't use <tt>progress_bar</tt> element in the main theme file.
 
 
<br>
 
 
=='''<tt>circular_progress</tt> - Circular indicator of elapsed time'''==
 
[[Grub2 theme / reference#Circular indicator of elapsed time (circular_progress)| Brief description]]
 
 
Circular indicator of elapsed time shows graphically the elapsed time to executing the default entry.
 
 
Elapsed time is displayed with drawing ticks.
 
 
If <tt>ticks_disappear</tt> isn't set then ticks are appearing (along the circumference, clockwise) until the circle is completed.
 
 
If <tt>ticks_disappear</tt> is set then ticks are disappearing.
 
 
Number of drawn ticks is always decreased by 1. Some ticks can be drawn at the first state. (circular indicator starts filling from non-zero value)
 
 
===<tt>left, top, width, height</tt> - coordinates of the rectangle===
 
Standard parameters. Don't forget to set them.
 
 
It is recommended to set similar value to width and to height. Detailed information about rectangle coordinates features see [[#center_bitmap, tick_bitmap - images for the circular progress indicator | below]].
 
 
===<tt>id</tt> - identificator===
 
To display countdown you should set predefined value to <tt>id</tt>.
 
id = "__timeout__"
 
 
===<tt>center_bitmap, tick_bitmap</tt> - images for the circular progress indicator===
 
 
Central image neither scaled or turned. It's drawn in the center of the desired rectangle of the element. If the image is less than the rectangle then part of the image won't be drawn. It's the background of the indicator.
 
 
Tick image also doesn't scaled or turned. It's drawn multiple times circumferential. The circle is inscribed into the desired rectangle.
 
 
It's recommended to use square images (height and width are the same).
 
 
Calculations use elements' width and tick's width.
 
 
If width of the element is greater then it's height then some ticks won't be drawn.
 
 
[[Image:grub-guide-circular-wrongwidth.png]]
 
 
It tick's height is greater then it's width then ticks won't be completely drawn.
 
 
[[Image:grub-guide-circular-wrongtickheight.png]]
 
 
It's recommended to make tick's width the same parity as element's width. (only in that case we will have correct symmetrical displaying)
 
 
===<tt>num_ticks, start_angle, ticks_disappear</tt> - circular progress settings===
 
 
<tt>num_ticks</tt> - The number of ticks to make a full circle.
 
 
<tt>start_angle</tt> - The starting angle. (starting from x-axis). It's measured in "parrots". One "parrot" - <tt>1/256</tt> of the full circle. That way <tt>-90</tt> degree (or <tt>-&pi;/2</tt>) will be <tt>-64</tt> "parrots".
 
 
<tt>tick_bitmap</tt> is drawn without any changes (no turning, no scaling etc) and angles are measured (in the algorithm) in "parrots" so it's recommended to set <tt>num_ticks</tt> with values equal to n-th power of 2. That way we will have smooth and symmetrical picture.
 
 
<tt>ticks_disappear</tt> - by default ticks are appearing.
 
 
[[Image:grub-guide-ticks-appear.png]]
 
 
 
You could set value <tt>True</tt> for <tt>ticks_disappear</tt> parameter. In this case ticks will disappear until none of them are present.
 
 
ticks_disappear = "True"
 
 
[[Image:grub-guide-ticks-disappear.png]]
 
 
Note, that number of drawn ticks is alway decreased by 1.
 
 
===Example===
 
+ circular_progress {
 
        left = 50%-450
 
        top = 50%+310
 
        id = "__timeout__"
 
        width = 51
 
        height = 51
 
        center_bitmap = "center.png"
 
        tick_bitmap = "tick.png"
 
        num_ticks = 8
 
}
 
 
[[Image:grub-guide-circular.png]]
 
 
<br>
 
 
=='''<tt>label</tt> - a string of text'''==
 
[[Grub2 theme / reference#Text string (label) | Brief description]]
 
 
We can display a line of text using <tt>label</tt> element.
 
 
If special values for <tt>id</tt> and <tt>text</tt> are set then elapsed time to execution of the default entry will be shown.
 
 
Note that there is not line-breaking mechanism. If printing length of the text line is greater then rectangle's width will be increased.
 
 
===<tt>left, top, width, height</tt> - coordinates of the rectangle===
 
Standard parameters. Don't forget to set them.
 
 
Note that <tt>width</tt> is used only for aligning the text if <tt>align</tt> parameter have value of <tt>"center"</tt> or <tt>"right"</tt>.
 
 
Note also that <tt>height</tt> isn't used.
 
 
===<tt>font, color</tt> - color and font of the text===
 
Font and color of the text.
 
 
See more about font's creating in [[#Font creation guide|font creating]]
 
 
===<tt>align</tt> - aligning===
 
Three correct values are available:
 
* left - align the text by the left edge of the element
 
* center - align the text by center of the element
 
* right - align the text by the right edge of the element
 
 
===Show elapsed time to booting the default item===
 
To show the elapsed time we should set special value of <tt>id</tt> and the parameter <tt>text</tt> should not be present in the description of the element in the main theme file.
 
+ label {
 
        left = 50%-350
 
        top = 50%+260
 
        height = 30
 
        width = 30
 
     
 
        id = "__timeout__"
 
     
 
        color = "white"
 
}
 
 
[[Image:grub-guide-label-timeout.png]]
 
 
===<tt>text</tt> - shown text===
 
We can output any text message.
 
There are several special values:
 
* @KEYMAP_SHORT@ for "enter: boot, `e': options, `c': cmd-line"
 
* @KEYMAP_MIDDLE@ for "Press enter to boot the selected OS, `e' to edit the commands before booting or `c' for a command-line."
 
* @KEYMAP_LONG@ for "Press enter to boot the selected OS, `e' to edit the commands before booting or `c' for a command-line. ESC to return previous menu."
 
 
Special values are translated to the language, used in GRUB.
 
 
Note that there is no line-breaking mechanism and text line's width isn't limited.
 
 
===Example with common value of <tt>text</tt>===
 
+ label {
 
        left = 50%-300
 
        top = 50%+220
 
        height = 30
 
        width = 600
 
     
 
        color = "white"
 
     
 
        align = "right"
 
     
 
        text = "Some text."
 
}
 
 
[[Image:grub-guide-label-text.png]]
 
 
===Example with special value of <tt>text</tt>===
 
+ label {
 
        left = 50%-300
 
        top = 50%+220
 
        height = 30
 
        width = 600
 
     
 
        color = "cyan"
 
     
 
        align = "center"
 
     
 
        text = "@KEYMAP_SHORT@"
 
}
 
 
[[Image:grub-guide-label-special.png]]
 
 
<br>
 
 
=='''<tt>image</tt> - Image'''==
 
[[Grub2 theme / reference#Image file (image) | Brief description]]
 
 
An image can be displayed on the screen.
 
 
If image's height is less than defined height, then defined height will be set to the image's real height. The same works for the image's width.
 
 
If defined width or height are greater than image's real width or height (correspondingly) then the image will be stretched to the defined size.
 
 
===<tt>left, top, width, height</tt> - coordinates of the rectangle===
 
Standard parameters. Don't forget to set them.
 
 
If you'd like to display unchanged image just don't set <tt>width</tt> and <tt>height</tt> parameters - they will be set automatically.
 
 
===<tt>file</tt> - full path to the image file===
 
Full path to the image file.
 
 
<br>
 
 
=='''<tt>vbox</tt> - vertical container'''==
 
[[Grub2 theme / reference#Vertical box (vbox) | Brief description]]
 
 
Container. Parent element which contains other elements.
 
 
===<tt>left, top, width, height</tt> - coordinates of the rectangle===
 
Don't forget to set <tt>left</tt> and <tt>top</tt> parameters. <tt>height</tt> and <tt>width</tt> are ignored and will be redefined so you don't need to set them.
 
 
===Composition of contained elements===
 
 
Elements, contained in the vertical box are shown consequentially from top to bottom.
 
 
You don't need to set <tt>left</tt> and <tt>top</tt> parameters for child elements - these values won't be taken into account.
 
 
Maximum of child elements' widths is being counted, then all widths (widths of every child element and the container) vertical are set with the resulting value.
 
 
Values of child elements' heights aren't change.
 
 
===Example===
 
 
+ vbox {
 
        left = 50%+310
 
        top = 50%-50
 
        width = 20
 
        height = 100
 
     
 
#D1
 
        + image { left = 50 top = 10 width = 60 height = 60 file = "center.png" }
 
#D2
 
        + image { left = 40 top = 20 width = 70 height = 70 file = "button_n.png" }
 
}
 
 
[[Image:grub-guide-vbox-layout.png]]
 
 
<br>
 
 
=='''<tt>hbox</tt> - horizontal container'''==
 
[[Grub2 theme / reference#Horizontal box (hbox) | Brief description]]
 
 
Container. Parent element which contains other elements.
 
 
===<tt>left, top, width, height</tt> - coordinates of the rectangle===
 
Don't forget to set <tt>left</tt> and <tt>top</tt> parameters. <tt>height</tt> and <tt>width</tt> are ignored and will be redefined so you don't need to set them.
 
 
===composition of contained elements===
 
 
Elements, contained in the horizontal box are shown consequentially from left to right.
 
 
You don't need to set <tt>left</tt> and <tt>top</tt> parameters for child elements - these values won't be taken into account.
 
 
Maximum of child elements' heights is being counted, then all heights (heights of every child element and the container) are set with the resulting value.
 
 
Values of child elements' widths won't change.
 
 
===Example===
 
 
+ hbox {
 
        left = 300
 
        top = 50%+310
 
        width = 20
 
        height = 100
 
     
 
#D1
 
        + image { left = 50 top = 10 width = 60 height = 60 file = "center.png" }
 
#D2
 
        + image { left = 40 top = 20 width = 70 height = 70 file = "button_n.png" }
 
}
 
 
 
[[Image:grub-guide-hbox-layout.png]]
 
 
<br>
 
 
=='''<tt>canvas</tt> - Canvas'''==
 
[[Grub2 theme / reference#Canvas (canvas) | Brief description]]
 
 
Container. Parent element which contains other elements. Child elements' coordinates are relative. That way, (0,0) for a child element is coordinates of top left corner of the container.
 
 
Root element is an instance of canvas.
 
 
===<tt>left, top, width, height</tt> - coordinates of the rectangle===
 
Standard parameters. Don't forget to set them.
 
 
<br>
 
 
='''Common feautures'''=
 
 
Common features not related to some concrete subject.
 
 
=='''Elements' drawing order'''==
 
 
Elements are drawn consequently from top to bottom in a vertical box.
 
 
Elements are drawn consequently from left to right in a horizontal box.
 
 
Child elements for a canvas are drawn in reverse order. If element A in placed before element B in the main theme file then A will be drawn after B.
 
 
=='''Element's drawing zone'''==
 
 
There is drawing area defined for each element. It is set with parameters <tt>left</tt>, <tt>top</tt>, <tt>width</tt>, <tt>height</tt>.
 
 
Everything that crosses the defined area won't be drawn.
 
 
=='''Element's minimal size'''==
 
 
Each element have a function for determination of the minimal size of the rectangle enough to draw this element. If defined width (height) is less then minimal width (height) then defined width (height) will be redefined to the minimal value.
 
 
=='''What if number values are incorrect'''==
 
[[Grub2 theme / reference#Numeric  | Description of numeric values.]]
 
 
Note, that absolute and relative values are counted relative to the parent container.
 
 
Lets call width and height of the parent container <tt>parent_width</tt> and <tt>parent_height</tt> correspondingly.
 
 
It <tt>left</tt> or <tt>top</tt> are negative - it will be redefined to 0.
 
 
If <tt>left</tt> + <tt>width</tt> is greater than <tt>parent_width</tt> then <tt>width</tt> will be redefined to <tt>parent_width - left</tt>. That way, right edge of the element will match right edge of the parent container.
 
 
If <tt>top</tt> + <tt>height</tt> is greater than <tt>parent_height</tt> then <tt>height</tt> will be redefined to <tt>parent_height - top</tt>. That way, bottom edge of the element will match bottom edge of the parent container.
 
 
We can use this features to achieve different composition of elements on different screen resolutions.
 
 
=='''Choosing of symbol'''==
 
 
The font of an element is described in the main theme file. If the desired font hasn't been found or the desired symbol isn't contained in the desired font - the most appropriate symbol from another font (present in the theme) will be used.
 
 
For example border symbols aren't present in some fonts. If we've selected such font to be the font of the console then border symbols will be taken from another font. Knowing this feature help to avoid confusion about unexpected results (e.g. dashed border or question mark symbols in place of the border)
 
 
<br>
 
 
='''Font creation guide'''=
 
[[Grub2 theme / reference#Font name  | Brief description]]
 
 
GRUB uses it's own font format. Needed font can be created using the utility <tt>grub-mkfont</tt>
 
 
After the font has been created and placed into the theme's directory, utility <tt>grub2-update</tt> should be executed so the changes will be applied.
 
 
=='''Create font using <tt>grub2-mkfont</tt>'''==
 
 
GRUB don't use kerning (changes of the distance between the symbols in case of some character combinations).
 
 
File, resulting from execution of the utility should necessarily have the extension <tt>.pf2</tt>
 
 
Syntax:
 
 
<tt>grub2-mkfont INPUT_FONT [optional parameters] -o OUTPUT_FONT</tt>
 
 
Resulting file should be placed into the theme directory.
 
 
=='''Parameters of <tt>grub2-mkfont</tt>'''==
 
 
===<tt>--output, -o</tt>===
 
 
Necessary parameter. The name of the resulting file. Should have extension <tt>.pf2</tt> so the font can be used by GRUB.
 
 
===<tt>--verbose, -v</tt>===
 
 
grub2-mkfont DroidSansMono.ttf -o tmp.pf2 -v
 
Font name: Droid Sans Mono Regular 16
 
Max width: 13
 
Max height: 17
 
Font ascent: 17
 
Font descent: 5
 
Number of glyph: 591
 
 
Display information about the created font.
 
 
Displays name, maximum width and height, ascent and descent of the font, quantity of symbols.
 
 
===<tt>--name, -n</tt>===
 
 
Set the font's name.
 
 
By default, font's name is auto-created with template: FONT_NAME TYPE SIZE
 
 
===<tt>--size, -s</tt>===
 
 
Set the font's size in pixels.
 
 
The value is 16 by default.
 
 
===<tt>--bold, -b</tt>===
 
 
Output bold font.
 
 
It is normal by default.
 
 
===<tt>ascent</tt>, <tt>descent</tt> of the font===
 
[[Image:grub-guide-font-scheme.png]]
 
 
--asce, -c
 
ascent of the font (see picture)
 
 
--desc, -d
 
descent of the font (see picture)
 
 
We can set these parameters to achieve larger \ lesser line spacing, to align the baseline (see picture). If we are going to set these parameters we should watch carefully that every needed symbol is correctly displayed.
 
 
===Select range of symbols to encode===
 
We can set a range of symbols to encode.
 
 
--ascii-bitmaps
 
to encode only ascii symbols
 
 
--range, -r
 
to encode the given range of symbols
 
 
<br>
 
 
='''Parameters which are set outside of <tt>theme.txt</tt>'''=
 
 
Options, which are set outside of the main theme file.
 
 
=='''<tt>/etc/default/grub</tt> File'''==
 
 
===GRUB_THEME===
 
 
Full path to the main theme file.
 
 
===GRUB_BACKGROUND===
 
 
Full path to the background image of the console. This file should be non-transparent. It's stretched to the sizes of the console. (note the 3px border)
 
 
===LANG и LANGUAGE===
 
 
If you'd like to set a language used in GRUB you should set both this parameters to the same value.
 
 
Different syntax can be used: <tt>en</tt>, <tt>en_US</tt>, <tt>en_US.UTF-8</tt>.
 
 
<br>
 
 
 
 
<br><br>
 
Vladimir Testov, ROSA, 2013.
 
[[en:Grub2 theme tutorial]]
 
[[ru:Grub2 (руководство по созданию темы)]]
 

Latest revision as of 10:52, 13 August 2015