Getting started with creating a cegui window -- describes how to create a simple cegui window

Source: Internet
Author: User

Cegui 4
Getting started with creating a cegui window describes how to create a simple cegui window.
All controls are windows.
This is the most important concept. All control classes are derived from the window base class. Therefore, in this tutorial, whenever I mention a window, it can be a button or a scroll bar control.

Many settings will be inherited.
In cegui, many settings and properties of the window are passed down by the parent-child level of the window. For example, if you set the Alpha transparency of a window to 0.5, all subwindows/components attached to that window will be affected by default. At the same time, note that the actual settings of the sub-window are not changed-the final attribute value is usually composed of all attribute values from the top to the current window. Many things have this rule, such as window destruction: by default, a window will destroy all its subwindows when it is destroyed. The biggest advantage of this mechanism is that the entire GUI can be easily controlled by changing the Alpha transparency, display/hide, activation/disable status of the root window; you can easily clear the entire GUI by simply destroying the root window. This default Inheritance mechanism can be changed when some windows require more precise control or better management technology.
Create window
There are two ways to create a window: Through the C ++ hard coding implementation and through the XML layout file implementation. The two methods are discussed below.
All windows in cegui are created by the windowmanager object. You can use the getsingleton function to obtain this object,CodeAs follows:
Using namespace cegui;
Windowmanager & wmgr = windowmanager: getsingleton ();
In general, you will use defaultwindow (or its old name: defaultguisheet) as the "root" Window of the GUI. This is not necessary, but it is a good habit of using cegui and can help simplify the layout. Next, we will create a defaultwindow as the root window of the GUI (here sheet is root ).

window * myroot = wmgr. createwindow ("defaultwindow", "root");
system: getsingleton (). setguisheet (myroot);
indowmanager: The createwindow function has two string-type parameters. The first parameter, which is "defaultwindow" in this example, tells the system the type or class of the window to be created. Generally, you can use window classes that are registered when you load scheme files. Some global types such as defaultwindow are always available. The second parameter, "root" in this example, is a unique name that will be given to this window. You can use this name to obtain the pointer to this window. Note: It is not necessary to name your root window as "root", but this is a common naming convention.
the system: setguisheet function is used to specify a window as the root window of the GUI. This will replace the current root window, but note that the previous window/control is not destroyed, but is removed from the current display chain-by using the setguisheet function, you can easily switch between multiple guis.
now, you have created the first window and attached it to the GUI system. When the system draws the GUI, it uses the window as the root of the GUI. However, if you compile and run the code, you still won't see anything. What's wrong? Your Program has no problems. The problem is: The defaultwindow we just created is hidden! This is why defaultwindow is so suitable for the root window: it is only used as an empty canvas for other windows and controls to attach. So, let's work harder... Now, we will create a framework window, which is similar to the window on your desktop. It has a title bar that can be moved or changed. The Code is as follows:

Framewindow * fwnd = (framewindow *) wmgr. createwindow (
"Taharezlook/framewindow", "testwindow ");

This Code creates a "taharezlook/framewindow" window. The entire system uses this naming convention: The Window Type uses the component group name as the prefix (if you load windowslook scheme, you can create a "windowslook/framewindow" object ). We name this new window "testwindow ". Note that the use of that type conversion is because the createwindow function always returns the window base class pointer. In this case and other cases, it is enough to return this window pointer, but sometimes you need to access the subclass method, so the type conversion in the example is very common when using cegui.

In order for the system to use our new window to do something useful, we still need to do something.
First, we must attach this new window to the root window we specified above. The Code is as follows:

Myroot-> addchildwindow (fwnd );

Now, we can set the position and size of it. Cegui uses a "unified" coordinate system so that the relative and absolute parts can be used at the same time-that is why each coordinate you see is composed of two parts.

// Locate the 1/4 position starting in the upper left corner of the parent window
Fwnd-> setposition (uvector2 (udim (0.25f, 0), udim (0.25f, 0 )));

// Set the size to half of the parent window
Fwnd-> setsize (uvector2 (udim (0.5f, 0), udim (0.5f, 0 )));

Finally, we set a title for the title bar of the Framework Window:

Fwnd-> settext ("Hello world! ");

XML Layout
The above method looks good, but it has a major drawback: every time you want to adjust the GUI layout, You have to modify the code and re-compile it. Isn't it exhausting? What you really want to do is to save the layout in the file and then call the layout file in the code.

The system supports layout files in XML format. You can use the windowmanager: loadwindowlayout function to load this file. This function creates all windows for you and returns a pointer to the root window. This pointer is not suitable when you call setguisheet to set the GUI root window.
Therefore, we need a layout file first. The window described in the XML file below is the same as the window we created in C ++ above:

<Guilayout>
<Window type = "defaultwindow" name = "root">
<Window type = "taharezlook/framewindow" name = "testwindow">
<Property name = "unifiedposition" value = "{0.25, 0}, {0.25, 0}">
<Property name = "unifiedsize" value = "{0.5, 0}, {0.5, 0}">
<Property name = "text" value = "Hello world! ">
</Property> </WINDOW>
</WINDOW>
</Guilayout>

The properties of the window element correspond to the parameters of the windowmanager: createwindow function one by one. See the createwindow function discussed above.
The embedded window element is used to indicate the parent-child relationship of the window. Note: In a layout file, you can have only one "root" window, which is another reason for using defaultwindow as the root window.

The property element is used to set the properties of the current window. Each window/control class has many attributes, and each class inherits all attributes from its parent class. You can view all hard encoding attributes and their formats here. Because the "falagard" skin ('falagard' skins) can create its own attributes, the window you use may have more attributes-for those "soft encoding" attributes, you need to refer to the documentation of the skin you are using (see sample skin taharezlook and windowslook ).

If you save the layout file as "test. layout", you can load and set the GUI root window as follows:

Using namespace cegui;
Window * myroot = windowmanager: getsingleton (). loadwindowlayout (
"Test. layout ");
System: getsingleton (). setguisheet (myroot );

The results obtained after compilation and running are the same as those written in C ++. However, now you can easily modify and enhance the GUI layout without modifying or re-compiling the code.

This article from the csdn blog, reproduced please indicate the source: http://blog.csdn.net/bluekane/archive/2009/01/09/3738439.aspx

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.