- 1 GUI Themes config file format
- 1.1 Overview
- 1.2 Section names
- 1.3 Expressions
- 1.4 Built-in Constants
- 1.5 Built-in Variables
- 1.6 Defining widget positions
- 1.7 Widget properties
- 1.8 Widget class properties
- 1.9 Special variables
- 1.10 Defining variables
- 1.11 Defining aliases
- 1.12 Special alias
- 1.13 USE keyword
- 1.14 USEASIS keyword
- 1.15 USEWITHPREFIX keyword
- 1.16 skipFor keyword
- 1.17 Modern Theme configuration
- 2 Evaluation precedence
- 3 Widget name conventions
- 4 What to do if I need to add new widgets to GUI
GUI Themes config file format
We always have a built-in theme. It is used when there is no external .ini file. For simplicity it uses exactly same format as external .ini but is defined in Theme::_defaultConfigINI string in gui/theme-config.cpp file.
Config file consists of at least one section. These sections can override one another. This is used to make a slight alteration of base theme possible without duplicating all element whose position is not changed.
NOTE: if you want to add new widgets, pay attention to correspondent section below
They are defined with this regexp: (X|[0-9]+)x(Y|[0-9+]+). I.e. possible names are:
- [XxY] -- universal one which can be used for any resolution
- [640xY] -- could be used for 640x400 and 640x480
- [Xx400] -- could be used for 640x400 only (or any other resolution with height 400)
- [640x480] -- could be used for 640x480 only
To add most flexibility arbitrary arithmetic expressions can be used for specifying any element. Allowed operations are '(', ')', '+', '-', '*', '/'. unary '+' and unary '-'. Atoms are either number or symbolic names.
Currently there are these built-in constants defined:
These correspond to constants defined in gui/widget.h file. There is no restriction on constants names.
- kThumbnailWidth -- defined in graphics/scaler.h
- false = 0
- true = 1
Built-in variables are symbolic names for ScummVM variables whose value is determined at run-time. These are:
- w -- current GUI width
- h -- current GUI height
Defining widget positions
Widgets are specified by following construction:
widget_name=X Y [W H]
X, Y, W and H are whitespace-delimited expressions. W and H are optional.
This construct effectively defines
If W and H are present, also these get defined:
- widget_name.x2 = widget_name.x + widget_name.w
- widget_name.y2 = widget_name.y + widget_name.h
chooser_headline=10 6 (w - 2 * 16) (kLineHeight)
Above mentioned constructions with dots are called widget properties.
Also there are following additional widget properties:
- .visible -- if set to 0, then widget is not drawn
- .align -- for text widgets defines text alignment (kTextAlignLeft, kTextAlignRight or kTextAlignCenter). Default is kTextAlignLeft
Widget class properties
Each widget class can be customized per-resolution. You need to specify their special properties.
This is widget with list of selectable items
ListWidget.leftPadding=7 ListWidget.rightPadding=7 ListWidget.topPadding=5 ListWidget.bottomPadding=5 ListWidget.hlLeftPadding=0 ListWidget.hlRightPadding=0
leftPadding, rightPadding, topPadding and bottomPadding specify list contents (text) padding from widget edges. Default values are 0.
hlLeftPadding, hlRightPadding specify padding of selected text highlight, i.e. green bar in modern theme. Default values are 0.
This is drop-down list used to select one item out of several. In inactive state it displays only selected item.
PopUpWidget.leftPadding=7 PopUpWidget.rightPadding=5 PopUpWidget.labelSpacing=3
leftPadding and rightPadding specify list contents (text) padding from widget endges. Default values are 0.
labelSpacing is used to specify space between text label and widget itself.
This is editable text.
EditTextWidget.leftPadding=7 EditTextWidget.rightPadding=5 EditTextWidget.font=kFontStyleNormal
leftPadding and rightPadding specify list contents (text) padding from widget endges. Default values are 0.
font is used to specify font used by the widget.
This is our debug console
Console.font=kFontStyleFixedNormal Console.leftPadding=7 Console.rightPadding=5 Console.topPadding=5 Console.bottomPadding=5
font is used to specify font for console. Note, that console uses fixed font.
leftPadding, rightPadding, topPadding and bottomPadding specify console contents (text) padding from widget edges. Default values are 0.
Special variables are:
It is reference to current and last defined widget special variables respectively, i.e. .x, .y, .w and .h
chooser_list=10 (6 + kLineHeight + 2) (w - 2 * 16) (h - self.y - buttonHeight - 12)
Denote self.y which equals to computed value of (6 + kLineHeight + 2).
You cannot use these references forward, i.e. refer to .w in .x. They get defined from left to right.
def_kLineHeight=16 * 2 OneThirdWidth=(w / 3)
variable kLineHeight gets value 32. OneThirdWidth will be GUI width divided by 3. Note use of parens in last example. Definitions with 'def_' prefix have a special meaning and get skipped with USE keyword (see below).
You can define alias to any symbolic atom, i.e. constants, variables and widget properties.
Now you can use headerBottomX everywhere.
It sets 6 aliases for each widget property, i.e.
- parent.x = chooser_list.x
- parent.y = chooser_list.y
etc for .w, .h, .x2 and .y2
set_parent=tabMidi midi_checkbox=(parent.x + 10) (parent.y + 20) roland_checkbox=midi_checkbox.x (parent.y + 50)
You can request loading of some particular section at any time within another section. But all variable definitions with def_ prefix get skipped. If you want to define a variable, use plain VAR=VAL construction.
[640xY] def_buttonHeight=kBigButtonHeight def_kLineHeight=16 listW=(w - 2 * 16) chooser_headline=10 6 listW (kLineHeight) chooser_list=10 (6 + kLineHeight + 2) listW (h - self.y - buttonHeight - 12) [320xY] def_buttonHeight=kButtonHeight def_kLineHeight=9 use=640xY
In this example for 320xY resolution chooser_headline and chooser_list will be loaded from [640xY] section, though buttonHeight and kLineHeight will be different. listW will get the value.
Same as USE keyword above but without def_ valuse skipped. Used for weird resolution aliases.
# MM NES resolution [256x240] useAsIs=320xY
This keyword is similiar to above described USE keyword. The difference is that all defined widgetset will get specified prefix. Example:
[XxY] yoffset=10 useWithPrefix=audioControls global_ yoffset=50 useWithPrefix=audioControls game_ [audioControls] myx=10 myw=(options_dialog.w - 20) midipopup=(myx -5) yoffset (myw + 5)
Here you will get global_midipopup and game_midipopup widgets defined.
If this key is defined within section, then section loading will be skipped for specified resolutions. For example, it is used in our modern theme to make 320xY widgets be positioned like in our classic theme.
[XxY] skipFor=320xY,256x240 def_blah=22
In above case section [XxY] will not be loaded for 320x200, 320x240 or 256x240 resolutions. No spaces are allowed in specified value, only [0-9XxYx,]
Modern Theme configuration
In the 'pixmaps' section all pixmaps used by the renderer are defined.
Basically there are four pixmaps per widget/dialog type:
pix_typename_corner - pixmap used for rendering all the corners pix_typname_top - pixmap used for the top/bottom border (y inversed for the bottom border) pix_typname_left - pixmap used for the left/right border (x inversed for the right border) pix_typname_bkgd - pixmap used for the background (all that's not corner or border)
Here's some example to defined the pixmaps used for dialog drawing:
pix_dialog_corner="dialog_bkgd_corner.bmp" pix_dialog_top="dialog_bkgd_top.bmp" pix_dialog_left="dialog_bkgd_left.bmp" pix_dialog_bkgd="dialog_bkgd.bmp"
To check out all widget types, check the entries defined in modern.ini. Also note that just .bmp files with a bpp of 24 bits are supported. The transparency color used is defined in the 'colors' section (see later on).
Apart from the pixmap definitions in the 'pixmaps' section there are some special pixmaps defined:
pix_widget_arrow - pixmap used for all arrows in widgets (like in the scrollbar widget) pix_checkbox_empty - pixmap used for empty checkboxes pix_checkbox_checked - pixmap used for checked checkboxes pix_theme_logo - pixmap used as logo pix_cursor_image - pixmap used as mouse cursor (note that just the first 255 colors found are used)
In the "colors" section colors for the whole theme are specified. A color gets defined in this way:
name=R G B
with values from 0 to 255 for R, G and B.
There is a special color entry to define the transparent color for the pixmaps, named "color_transparency". Our default theme uses pink (255 0 255) as the transparent color.
color_transparency=255 0 255
To set up text colors the following entries have to be set:
color_state_disabled=192 192 192 color_state_highlight=100 162 8 color_state_enabled=0 0 0
- "color_state_disabled" is used for disabled text.
- "color_state_highlight" is used for highlighted text.
- "color_state_enabled" is used for normal text.
The ListWidget uses two special text color entries:
text_inverted_background=100 162 8 text_inverted_color=0 0 0
There "text_inverted_background" is used for the rect which is drawn when an entry is selected, "text_inverted_color" is used for the text drawn when an entry is selected.
Another special color is used for all kinds of text input widgets:
caret_color=0 0 0
This value is used for the color the caret is drawn in.
Some colors are used for background fades, you can easily spot them since they have a '_start' and '_end' suffix. Another example:
main_dialog_start=210 114 10 main_dialog_end=239 196 24
This defines the color fade for the launcher background. "main_dialog_start" defines the color at the top of the drawn area, "main_dialog_end" at the bottom of the drawn area, the colors in between are calculated. (see 'gradients' section for more information).
Sometimes there is more than one color fade definition for a widget, the button widget uses for example one colorfade for normal drawing and a special fade for highlighted drawing. Example:
button_bkgd_start=203 126 107 button_bkgd_end=169 42 12 button_bkgd_highlight_start=255 210 200 button_bkgd_highlight_end=200 70 50
- "button_bkgd_start" and "button_bkgd_end" are used for normal drawing.
- "button_bkgd_highlight_start" and "button_bkgd_highlight_end" are used for highlighted drawing.
There are three special entries for the button widget to define the text color:
button_text_enabled=255 255 255 button_text_disabled=192 192 192 button_text_highlight=255 214 84
- "button_text_enabled" is used for normal buttons.
- "button_text_disabled" is used for buttons which are currently disabled.
- "button_text_highlight" is used for highlighted buttons.
If you want to find out all defineable colors look at our default theme config file, named "modern.ini".
Inactive dialog effects
For using an effect change the "inactive_dialog_shading" option in the "[extra]" section of default-theme.ini. Possible values are: "no_effect", "luminance" and "dim". (Note that currently backends which don't copy the game screen into the overlay buffer should use "no_effect").
- "luminance" will change all inactive screen areas to black and white.
- Example (enables it)
- "dim" will dim the screen with the given percentage value.
- "shading_dim_percent" in the "[extra]" section sets the dimming value. 0 means no dim, 100 is completeley black
- Example (30% screen dim):
[extra] inactive_dialog_shading=dim shading_dim_percent=30
Within one section everything is computed left to right, down to top. No forward references are allowed. The only exception are aliases which can refer to not yet defined variables and widget properties, but at time of useage those variables should be defined (otherwise you will get an error).
Currently any error in evaluation will lead to error() and ScummVM will be closed. So be careful, especially with the built-in theme.
On each resolution change all user-defined variables and aliases get cleared and all sections are recomputed. When sections get loaded for a single resolution, all of them are kept, so you can specify a generic [XxY] scheme and then overwrite only some widgets, thus simplifying the whole thing.
Sections loading order is always the same. For the 640x480 resolution this is:
- Built-in theme
- Custom theme
Only present sections are loaded. If a section is not defined no error message is generated.
Widget name conventions
Widget names are given in the following form:
where dialog_ is the dialog name, and widget is a distinguishable name within that dialog. Be discreet and give meaningful names.
What to do if I need to add new widgets to GUI
Most importantly, not all GUI behaviour is described in theme config. You can only alter the look, not the feel. So all real coding should go into the corresponding files in the gui/ directory.
When you add a new widget, follow this checklist before committing:
- Does it look right in 320xY (./scummvm --force-1x-overlay)
- To do this you should either have no absolute positions in your config file or create [320xY] section
- Does it look right with classic theme (./scummvm --gui-theme=classic)
- that is the [XxY] section in gui/theme-config.cpp
- Does it look right both with classic theme and 320xY resolution (./scummvm --force-1x-overlay --gui-theme=classic)
- that is the [320xY] section in gui/theme-config.cpp
Currently the classic theme has the following most notable differences from the modern theme:
- Line spacing is narrower everywhere
- Indentation is smaller in most cases apart from the Game Options dialog