窗口管理
UNIGINE provides an advanced toolkit simplifying development of various visual tools, with a large number of widgets and capabilities.UNIGINE提供了一个高级工具包,通过大量的小部件和功能简化了各种可视化工具的开发。
You can easily create and adjust window viewports and window groups, control their behavior and rendering order, stack them, handle events, check window intersections, and so on via API:对于windows创建,使用EngineWindow类。它允许管理引擎窗口组件、与其他窗口的关系、大小、位置和其他功能。
所有窗口管理操作都是通过WindowManager类执行的,使您能够访问应用程序的任何窗口、组或堆栈窗口、创建各种对话框等等。
See Also另请参阅#
- For window viewport creation, the EngineWindowViewport class is used. It inherits from EngineWindow class and allows managing window viewports: setting cameras, specifying engine tools available (console, profiler, visualizer, etc.), adding widgets to the client area.一组SDK示例(samples/Api/WindowManager)演示了各种使用方面。
创建窗口#
要创建引擎窗口,使用一个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);
创建窗口后,您可以更改其外观和属性,指定该窗口可用的引擎工具,并向其客户区添加小部件。所有这些操作也可以通过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);
要渲染引擎窗口,使用show()函数:
// render the window
window_1->show();
Accessing Windows访问窗口#
When the window viewport is created, you can change its settings: specify the engine tools available, set the viewport as the main one, specify the camera the image from which is rendered into the viewport, and so on. All these operations are provided by the EngineWindowViewport class. For example:可以通过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));
}
}
You can also add widgets to the client area of the window:还有一些函数(如 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));
}
分组的窗户#
Also UNIGINE SDK provides a set of samples (source/samples/Api/WindowManager) that allow you to try all settings in action. For example, in the WindowSandbox sample, you can create a window viewport and adjust it.引擎的窗户通过EngineWindow类可以创建分组。两个窗口分组时,创建一个新窗口,其中包含这些窗口。新窗口被称为 强组。窗户的数量是无限的。
To create the engine window viewport, one of the EngineWindowViewport class constructors is used.窗口组有三种类型:
- 垂直
- 水平
- 群标签
To control window components, its behaviour, visual representaion, and style, use the EngineWindow class functionality. The corresponding article contains short samples that cover most of the available functions.在组中,所有窗口都根据这些类型之一进行堆叠。
There are three types of the window groups:WindowManager类为分组窗口提供了两个主要函数:
- Verticalstack()创建一组两个窗口。
- HorizontalstackGroups()创建一组两个窗口组。
// 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, EngineWindowGroup::GROUP_TYPE_HORIZONTAL);
EngineWindowPtr horizontal_group_2 = WindowManager::stack(horizontal_3, horizontal_4, 1, EngineWindowGroup::GROUP_TYPE_HORIZONTAL);
// create a vertical group of 2 horizontal groups
EngineWindowPtr vertical_group = WindowManager::stackGroups(horizontal_group_1, horizontal_group_2, EngineWindowGroup::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();
每个窗口或窗口组都有一个状态,因此在堆叠后它会改变。
Within the group, all windows are stacked according to one of these types.也有功能基于stack()函数应该使用在特定情况下为了避免额外的检查的参数:
-
stackToParentGroup()将第二个窗口堆叠到第一个窗口的父组。结果,作为参数传递的两个窗口将位于组层次结构中的同一层。
// stack 2 separate windows EngineWindowPtr group_0 = WindowManager::stackWindows(window_1, window_2, EngineWindowGroup::GROUP_TYPE_HORIZONTAL); // stack a separate window to the parent group of "window_1" WindowManager::stackToParentGroup(window_1,window_3);
-
A window group is an instance of the EngineWindowGroup class that can be created in one of the following ways:stackWithWindow()堆栈窗口到另一个窗口。如果第一个参数是单独的窗口,返回一个新窗口组。如果第一个参数是嵌套的窗口,窗口添加到它的组。
// create a group of 2 windows EngineWindowPtr group_1 = WindowManager::stack(window_1, window_2, 1, EngineWindowGroup::GROUP_TYPE_HORIZONTAL); // stack a separate window to the window from the window group WindowManager::stackToWindow(window_1, window_3, EngineWindowGroup::GROUP_TYPE_VERTICAL);
- stackWindows()创建一组独立/嵌套的窗口。窗口按默认顺序堆叠。
- stackToGroup()堆栈窗口或窗口组到另一个窗口组。
对于取消分组,使用unstack()函数:它从父组中删除窗口或窗口组。如果组中只剩下一个窗口,它将自动从组中删除,组也将被删除。
Grouping Using the Mouse使用鼠标对窗口进行分组#
For example, to change the first tab in the group, you can do the following:在应用程序运行时,可以使用鼠标对现有窗口进行分组和取消分组。
UNIGINE SDK provides several samples (source/samples/Api/WindowManager) on the window groups: you can check different group types in the GroupTypes sample or create a new window group and try to adjust it in the WindowSandbox sample. Also the article on the EngineWindowGroup class contains short samples demonstrating the available functions.集团两个独立的windows,请执行以下操作:
- 按住鼠标按钮时将窗口移动到目的地。目标窗口将被分为9个部门。
- 选择所需的扇区并释放鼠标按钮:窗口将被分组。
窗口添加到现有的群,你应该移动窗口时按住鼠标按钮并释放它在以下领域:
-
对于水平组:
-
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:若要取消对窗口的分组,请将其移到组外。
Working with Dialogs处理对话框#
For the group of tabs:要创建对话框窗口,请使用该类的相应函数。例如:
// 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;
}
To ungroup the window, move it outside the group by dragging the title bar.如果你按下按钮创建窗口的客户区,以下对话框将显示: