Beginner's Guide to data file loading and initialization
From ceguiwiki
1. Overview: data files and resourceprovider
1.1 resource provision-What is resourceprovider?
1.2 XML, XSD? All are XML!
1.3 Data Files
1.3.1 image sets
1.3.2 font
1.3.3 Scheme
1.3.4 Layout
1.3.5 Configuration
2. Load basic files
3. Simple default Initialization
4 Conclusion
1. Overview: data files and resourceprovider
Cegui uses some data file variants, which may cause some confusion. Therefore, we will first introduce what data files are, what they are used for, and how to load them in cegui.
1.1 resource provision-What is resourceprovider?
Cegui uses a help object called resourceprovider. This object provides a cegui core library and an interface for external file loading systems. For example, the ogre and irrlicht engines use their own resource manager and file loading subsystem: by implementing and providing a specialized resourceprovider object, the Renderer of these engines enables "seamless" Integration of the above systems, therefore, cegui data files are loaded through these systems.
By default, direct3d and OpenGL do not use dedicated resourceprovider. By default, these systems load all resource files from the current path of the application. Therefore, these files must be related to the same folder, but they are irrelevant to each other. This is very important.
1.2 XML, XSD? All are XML!
All data files used by cegui are XML except for graphical files and loadable module files (. dll/. So files. The first obstacle is how to use the schema (. XSD) file.
By default, cegui uses xerces-C ++ to process XML files with schema verification. (An Introduction to XSD files ). Cegui has some xsd in the cegui_mk2/xmlrefschema/directory. Remember that the XSD file is required by the resourceprovider system. You can place an appropriate. XSD file in the XML file directory to be loaded.
1.3 Data Files
Data files are often not ended with. XML, although they are all XML files. They are usually defined according to the file content. For example,. imageset is the xml configuration file of imageset,. font is the xml configuration file of the font, and so on. The following is a brief introduction to each data file.
1.3.1 image set imageset
Imageset is only the definition of a region in the original image/texture file (the region will be specified when imageset is defined ). Each defined region has a unique name and is considered as an image in the system. Image is a basic element in imageset. If you want to change the image drawn by cegui, you can change the original image/texture file or the definition area of the image.
1.3.2 font
Two types of fonts can be defined for cegui to use a dynamic font. A Bitmap font is a static font of a true-type (. TTF) font file. This font is based on an imageset that defines images.
1.3.3 Scheme
Schema is a method of combining fragmented data files. It is also the easiest way to load and register the widget type. A schema can contain one or more types of definitions (resources described in these files can be loaded at the schema loading time ).
- Imageset
- Font
- Window set
- Window alias
Imageset and font have been mentioned earlier. A window set specifies the name of the loadable module (. dll/. So, and so on.
The widgets set contains the set of modules you want to register. (Note: according to the information on the Internet, Widgets is similar to themes in windows)
The window or widget type can have multiple names. Windows alias provides this mechanism. We can also use this mechanism to "hide" another registered widget. (A bit like C ++'s hiding ?)
1.3.4 Layout
The layout file contains information about a window layout, which is also in XML format. Each 'window' element defines the created window or widet. The 'properties' element defines the attribute values of each window.
1.3.5 Configuration
Cegui supports configuration files. You can use this file to set some default values, such as scheme, layout, and script file (when sriptmoudle is used ).
2. Load basic files
To run a cegui example, you must have at least the following files.
The benefit of a scheme file is that it can be used to automatically load the other two data files. In the sample schemes of cegui, only imageset is available, but no font is available. Next we will load a scheme file and a font file. As follows:
// Load in the scheme file, which auto-loads the taharezlook imageset
Cegui: schemanager: getsingleton (). loadscheme ("../datafiles/Schemes/taharezlook. Scheme ");
// Load in a font. The first font loaded automatically becomes the default font.
Cegui: fontmanager: getsingleton (). createfont ("../datafiles/fonts/Commonwealth-10.font ");
In the above Code, we assume that the 'datafiles' directory exists and is located in the upper-level directory of the current directory, which contains all the files in cegui_mk2/samples/datafiles.
Oger user Note: To use a sample data file that has not been edited, you must make sure that the current working directory is set as the resource path in oger Resource Manager (which can be set through resources. cfg ). Alternatively, you can add all data file subdirectories and delete all relative paths in the data file. This is because they must work with d3d/OpenGL Under the default resourceprovider, as discussed earlier.
3. Simple default Initialization
Finally, you need to set some default values. This ensures that the system can always have an available font and Mouse icon when no specific theme is specified in the window or widget.
In reality, we do not need to specify a default font, because fontmanager always automatically sets the first loaded font as the default. But if this is not the default font you want, you can set another default font you want. The code for setting the default font is as follows:
System: getsingleton (). setdefaultfont ("Commonwealth-10 ");
Another default object to be set is the Mouse icon. When you do not define an icon that moves the mouse over an element, the mouse will not disappear. The code for setting the default Mouse icon is as follows: (use taharezlook imageset loaded with scheme above)
System: getsingleton (). setdefadefamousecursor ("taharezlook", "mousearrow ");
4 Conclusion
We learned some basic data files, how to load them, and the minimum initialization data files required by cegui. Other articles will discuss the details of each data file.