Difference between revisions of "How preferences work"
m (→Declaring a New Preference: Version number correction, as per SLDev post, Wed Apr 9 14:32:14 PDT 2008 by Soft Linden, [sldev] "1.20 release notes") |
Rand Linden (talk | contribs) |
||
Line 9: | Line 9: | ||
== Declaring a New Preference == | == Declaring a New Preference == | ||
As of Viewer relese 1.20 the settings system uses an XML file, <code>app_settings/settings.xml</code>, to control settings values. | |||
This file provides the following information for each preference setting: | |||
* Data type | |||
* Name | |||
* Default value | |||
* | * Documentation string, displayed in the "Debug Settings" floater (in the Client menu); | ||
* | * (optional) persistence, that is, whether it is saved between sessions. | ||
* | |||
* | |||
* (optional) | |||
The following example (taken from "indra/newview/llcontroldef.cpp") declares a preference which stores a 4-channel (RGBA) color, called "EffectColor", with a default value of totally-opaque white (1, 1, 1, 1), and a documentation string, "Particle effects color": | The following example (taken from "indra/newview/llcontroldef.cpp") declares a preference which stores a 4-channel (RGBA) color, called "EffectColor", with a default value of totally-opaque white (1, 1, 1, 1), and a documentation string, "Particle effects color": | ||
Line 28: | Line 25: | ||
gSavedSettings.declareBOOL("ShowTools", FALSE, "", NO_PERSIST); | gSavedSettings.declareBOOL("ShowTools", FALSE, "", NO_PERSIST); | ||
The | === Data types === | ||
The following table describes the data types valid for preferences. For data types that start with "LL", the declare function name does not contain the leading "LL." For example data type LLString the declare function is "declareString." | |||
{| | {| {{Prettytable}} | ||
|-{{Hl2}} | |||
!Data Type !! Declare Function !! Description | !Data Type !! Declare Function !! Description | ||
|- | |- |
Revision as of 22:31, 16 February 2009
This document contains information about how user preferences are stored and manipulated in the Second Life Viewer Client.
The gSavedSettings Control Group
The values for user preferences are stored in gSavedSettings, a global variable of the class LLControlGroup (see "indra/llxml/llcontrol.cpp" for the definition of that class). At the end of the session (i.e. when the viewer client is quit), persistent settings are saved to "settings.xml". They will be loaded from that file at the beginning of the next session.
Declaring a New Preference
As of Viewer relese 1.20 the settings system uses an XML file, app_settings/settings.xml
, to control settings values.
This file provides the following information for each preference setting:
- Data type
- Name
- Default value
- Documentation string, displayed in the "Debug Settings" floater (in the Client menu);
- (optional) persistence, that is, whether it is saved between sessions.
The following example (taken from "indra/newview/llcontroldef.cpp") declares a preference which stores a 4-channel (RGBA) color, called "EffectColor", with a default value of totally-opaque white (1, 1, 1, 1), and a documentation string, "Particle effects color":
gSavedSettings.declareColor4("EffectColor", LLColor4(1.f, 1.f, 1.f, 1.f), "Particle effects color");
This next example shows how you can specify that the preference should NOT persist between sessions, by giving NO_PERSIST as a fourth argument to the declaration:
gSavedSettings.declareBOOL("ShowTools", FALSE, "", NO_PERSIST);
Data types
The following table describes the data types valid for preferences. For data types that start with "LL", the declare function name does not contain the leading "LL." For example data type LLString the declare function is "declareString."
Data Type | Declare Function | Description |
---|---|---|
U32 | declareU32 | Unsigned 32-bit Integer |
S32 | declareS32 | Signed 32-bit Integer |
F32 | declareF32 | 32-bit Float |
BOOL | declareBOOL | Boolean (True/False) |
LLString | declareString | Character String (Text) |
LLVector3 | declareVec3 | 3D Vector |
LLVector3d | declareVec3d | 3D Vector (double data size) |
LLRect | declareRect | Rectangle (left, bottom, width, height) |
LLColor4U | declareColor4U | Unsigned 4-Channel Color (RGBA) |
LLColor4 | declareColor4 | 4-Channel Color (RGBA) |
LLColor3 | declareColor3 | 3-Channel Color (RGB) |
Accessing Preference Data
The LLControlGroup class (of which gSavedSettings is an instance) defines "get" and "set" functions for each of the data types. The functions follow this format, where "DataType" is replaced with the proper data type, e.g. BOOL, F32, LLColor4. (As with the declare functions, the get and set function names to not contain the leading "LL" for data types like LLString and LLColor4.)
LLControlGroup::getDataType( LLString name ); LLControlGroup::setDataType( LLString name, DataType new_value );
A contrived example of retrieving and then setting an LLColor4-typed preference:
LLColor4 my_color; my_color = gSavedSettings.getColor4( "EffectColor" ); gSavedSettings.setColor4( "EffectColor", my_color );
There are three additional "get" functions for certain special cases:
Function Name | Return Type | Description |
---|---|---|
getWString | LLWString | Wide-Data Strings (multiple bytes per char) |
getText | LLString | Special handler for strings from a file? |
getColor | LLColor4 | Handles both LLColor4 and LLColor4u types. |