窗口管理
UNIGINE provides an advanced toolkit simplifying development of various visual tools, with a large number of widgets and capabilities.UNIGINE提供了一个高级工具包,通过大量的小部件和功能简化了各种可视化工具的开发。
For windows creation, the EngineWindow class is used. It allows managing engine windows components, relations with other windows, size, position, and other features.对于windows创建,使用EngineWindow类。它允许管理引擎窗口组件、与其他窗口的关系、大小、位置和其他功能。
All window management operations are performed via the WindowManager class enabling you to access any window of the application, group or stack windows, create various dialogs, and so on.所有窗口管理操作都是通过WindowManager类执行的,使您能够访问应用程序的任何窗口、组或堆栈窗口、创建各种对话框等等。
See Also另请参阅#
- A set of SDK samples (samples/Api/WindowManager) demonstrating various usage aspects.一组SDK示例(samples/Api/WindowManager)演示了各种使用方面。
Creating Windows创建窗口#
To create the engine window, one of the EngineWindow class constructors is used.要创建引擎窗口,使用一个EngineWindow类构造函数。
// create an engine window of the specified size with the specified name
EngineWindowPtr window_0 = EngineWindow::create("Window", 580, 300);
// create the main engine window of the specified size
EngineWindowPtr window_1 = EngineWindow::create(580, 300, EngineWindow::FLAGS_MAIN);
When the window is created, you can change its appearance and properties, specify the engine tools available for the window and add widgets to its client area. All these operations can be done by means of the EngineWindow class as well.创建窗口后,您可以更改其外观和属性,指定该窗口可用的引擎工具,并向其客户区添加小部件。所有这些操作也可以通过EngineWindow类来完成。
// set an icon and a title for the window
window_1->setIcon("icon.png");
window_1->setTitle("Main Window");
// allow using the window as a nested one
window_1->setNestedUsage(true);
// enable the console, profiler and visualizer for the window
window_1->setConsoleUsage(true);
window_1->setProfilerUsage(true);
window_1->setVisualizerUsage(true);
// add widgets to the client area of the window
window_1->addChild(WidgetLabel::create(window->getSelfGui(), String::format("This is %s window.", window->getTitle())));
window_1->addChild(WidgetButton::create(window->getSelfGui(), window->getTitle()), Gui::ALIGN_CENTER);
To render the engine window, use the show() function:要渲染引擎窗口,使用show()函数:
// render the window
window_1->show();
Accessing Windows访问窗口#
An application window can be accessed via the getWindow() function of the WindowManager class.可以通过WindowManager类的getWindow()函数访问应用程序窗口。
// get the number of windows
int num = WindowManager::getNumWindows();
// check each window
for (int i = 0; i < num; i++)
{
// get the window with the current index
EngineWindowPtr window = WindowManager::getWindow(i);
// change its position and size if it is main
if (window->isMain())
{
window->setPosition(Math::ivec2(1020, 60));
window->setSize(Math::ivec2(305, 670));
}
}
There are also some functions (like getMainWindow()) that allow accessing the specific windows (the main, focused, fullscreen window and so on). For example:还有一些函数(如 getMainWindow())允许访问特定窗口(主窗口、聚焦窗口、全屏窗口等)。 例如:
// get the main window
EngineWindowPtr main_window = WindowManager::getMainWindow();
// change its position and size
if (main_window)
{
main_window->setPosition(Math::ivec2(1020, 60));
main_window->setSize(Math::ivec2(305, 670));
}
Grouping Windows分组的窗户#
The engine windows created via the EngineWindow class can be grouped. When two windows are grouped, a new window containing these windows is created. The new window is called a group. The number of windows in the group is unlimited.引擎的窗户通过EngineWindow类可以创建分组。两个窗口分组时,创建一个新窗口,其中包含这些窗口。新窗口被称为 强组。窗户的数量是无限的。
There are three types of the window groups:窗口组有三种类型:
- Vertical垂直
- Horizontal水平
- Group of tabs群标签
Within the group, all windows are stacked according to one of these types.在组中,所有窗口都根据这些类型之一进行堆叠。
The WindowManager class provides two main functions for grouping windows:WindowManager类为分组窗口提供了两个主要函数:
- stack() creates a group of two windows.stack()创建一组两个窗口。
- stackGroups() creates a group of two window groups.stackGroups()创建一组两个窗口组。
// create separate windows
EngineWindowPtr horizontal_1 = EngineWindow::create("Horizontal 1", 512, 256);
EngineWindowPtr horizontal_2 = EngineWindow::create("Horizontal 2", 512, 256);
EngineWindowPtr horizontal_3 = EngineWindow::create("Horizontal 3", 512, 256);
EngineWindowPtr horizontal_4 = EngineWindow::create("Horizontal 4", 512, 256);
// create 2 horizontal window groups
EngineWindowPtr horizontal_group_1 = WindowManager::stack(horizontal_1, horizontal_2, 1, EngineWindow::GROUP_TYPE_HORIZONTAL);
EngineWindowPtr horizontal_group_2 = WindowManager::stack(horizontal_3, horizontal_4, 1, EngineWindow::GROUP_TYPE_HORIZONTAL);
// create a vertical group of 2 horizontal groups
EngineWindowPtr vertical_group = WindowManager::stackGroups(horizontal_group_1, horizontal_group_2, EngineWindow::GROUP_TYPE_VERTICAL);
// specify position, size, title of the verical window group
vertical_group->setPosition(Math::ivec2(50, 60));
vertical_group->setSize(Math::ivec2(565, 310));
vertical_group->setTitle("Vertical Group");
// render the window group
vertical_group->show();
Each window or window group has a state, so it changes after stacking.每个窗口或窗口组的状态 ,因此在堆叠后它会改变。
There are also functions based on the stack() function that should be used in specific cases to avoid additional checking of arguments:也有功能基于stack()函数应该使用在特定情况下为了避免额外的检查的参数:
-
stackToParentGroup() stacks the second window to the parent group of the first window. In the result, both windows passed as arguments will be on the same level in the group hierarchy.stackToParentGroup()将第二个窗口堆叠到第一个窗口的父组。结果,作为参数传递的两个窗口将位于组层次结构中的同一层。
// stack 2 separate windows EngineWindowPtr group_0 = WindowManager::stackWindows(window_1, window_2, EngineWindow::GROUP_TYPE_HORIZONTAL); // stack a separate window to the parent group of "window_1" WindowManager::stackToParentGroup(window_1,window_3);
-
stackToWindow() stacks the window to the other window. If the first argument is the separate window, a new window group is returned. If the first argument is the nested window, the window is added to its group.stackToWindow()堆栈窗口到另一个窗口。如果第一个参数是单独的窗口,返回一个新窗口组。如果第一个参数是嵌套的窗口,窗口添加到它的组。
// create a group of 2 windows EngineWindowPtr group_1 = WindowManager::stack(window_1, window_2, 1, EngineWindow::GROUP_TYPE_HORIZONTAL); // stack a separate window to the window from the window group WindowManager::stackToWindow(window_1, window_3, EngineWindow::GROUP_TYPE_VERTICAL);
- stackWindows() creates a group of the separate/nested windows. The windows are stacked in the default order.stackWindows()创建一组独立/嵌套的窗口。窗口按默认顺序堆叠。
- stackToGroup() stacks the window or window group to another window group.stackToGroup()堆栈窗口或窗口组到另一个窗口组。
For ungrouping, the unstack() function is used: it removes the window or the window group from the parent group. If only one window remains in the group, it is automatically removed from the group and the group is deleted.对于取消分组,使用unstack()函数:它从父组中删除窗口或窗口组。如果组中只剩下一个窗口,它将自动从组中删除,组也将被删除。
Grouping Using the Mouse使用鼠标对窗口进行分组#
While the application is running, you can group and ungroup the existing windows by using the mouse.在应用程序运行时,可以使用鼠标对现有窗口进行分组和取消分组。
To group two separate windows, do the following:集团两个独立的windows,请执行以下操作:
- Hold the mouse button while moving the window to the destination one. The destination window will be divided into 9 sectors.按住鼠标按钮时将窗口移动到目的地。目标窗口将被分为9个部门。
- Choose the required sector and release the mouse button: the windows will be grouped.选择所需的扇区并释放鼠标按钮:窗口将被分组。
To add the window to the existing group, you should hold the mouse button while moving the window and release it in one of the following areas:窗口添加到现有的群,你应该移动窗口时按住鼠标按钮并释放它在以下领域:
-
For the horizontal group:对于水平组:
-
For the vertical group:垂直组织:
-
For the group of tabs:对于选项卡组:
To ungroup the window, move it outside the group.若要取消对窗口的分组,请将其移到组外。
Working with Dialogs处理对话框#
To create a dialog window, use the corresponding functions of the class. For example:要创建对话框窗口,请使用该类的相应函数。例如:
// event handler function
int AppSystemLogic::onButtonClicked()
{
// show the message dialog
WindowManager::dialogMessage("Message", "The button has been pressed.");
return 1;
}
int AppSystemLogic::init()
{
// create a window with widgets in the client area
auto create_window = [](const char *name)
{
EngineWindowPtr window = EngineWindow::create(name, 512, 256);
window->addChild(WidgetLabel::create(window->getSelfGui(), String::format("This is a {0}.", name)), Gui::ALIGN_TOP);
window->addChild(WidgetButton::create(window->getSelfGui(), name), Gui::ALIGN_CENTER);
return window;
};
{
// create a window
EngineWindowPtr window = create_window("Window");
// get the child widget of the window
WidgetPtr button = window->getChild(1);
// add a callback for this widget
button->addCallback(Gui::CLICKED, MakeCallback(this, &AppSystemLogic::onButtonClicked));
// show the window
window->setPosition(Math::ivec2(50, 60));
window->show();
}
return 1;
}
If you press the button in the client area of the created window, the following dialog will be shown:如果你按下按钮创建窗口的客户区,以下对话框将显示: