Unigine::WindowManager Class
Header: | #include <UnigineWindowManager.h> |
The class to manage windows enabling you to access any window of the appllication, group or stack windows, create various dialogs and so on.
Accessing Windows#
An application window can be accessed via the getWindow() function. There are also some functions (like getMainWindow()) that allow accessing the specific windows (a focused window, a fullscreen window and so on).
// 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. There are three types of the window groups:
- Vertical
- Horizontal
- Group of tabs
The WindowManager class provides two main functions for grouping windows:
- stack() creates a group of two windows.
- stackGroups() creates a group of two window groups.
// 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("Horizontal Group");
// render the window group
vertical_group->show();
There are also functions based on the stack() function that should be used in specific cases to avoid additional checking of arguments:
- 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.
- stackWindows() creates a group of the separate/nested windows. The windows are stacked in the default order.
- 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.
- stackToGroup() stacks the window or window group to another window group.
For ungrouping, the unstack() function is used: it removes the window or the window group from the parent group.
Creating Dialog Windows#
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", "Button has been clicked");
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 %s window.", 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;
}
See Also#
- A set of SDK samples (samples/Api/WindowManager) demonstrating various usage aspects.
WindowManager Class
Enums
CALLBACKS#
Members
Ptr<EngineWindow> getMainWindow ( ) const#
Returns the window that is set as the main window by default.
Return value
The engine window.int getNumWindows ( ) const#
Returns the number of windows.Return value
The number of windows.Ptr<EngineWindow> getWindow ( int index ) #
Returns the window by its index.Arguments
- int index - Index of the window.
Return value
Engine window.int getWindowIndex ( const Ptr<EngineWindow> & window ) const#
Returns the index of the specified window.Arguments
- const Ptr<EngineWindow> & window - Engine window.
Return value
Index of the window.Ptr<EngineWindow> stack ( const Ptr<EngineWindow> & first, const Ptr<EngineWindow> & second, int index = -1, EngineWindow::GROUP_TYPE group_type = Enum.EngineWindow.GROUP_TYPE.TAB, bool decompose_second = false ) #
Returns the group of windows. If the first argument is a window, a new group is always created. If the first argument is a group, the second element is added to this group. The order of stacking can be changed by passing the index argument. To combine two groups into a new one, use the stackGroups() method.EngineWindowPtr window_1 = EngineWindow::create("Window 1", 512, 256);
EngineWindowPtr window_2 = EngineWindow::create("Window 2", 512, 256);
// create a horizontal group of windows
EngineWindowPtr group_1 = WindowManager::stack(window_1, window_2, 1, EngineWindow::GROUP_TYPE_HORIZONTAL);
Arguments
- const Ptr<EngineWindow> & first - The first window or group for merging.
- const Ptr<EngineWindow> & second - The second window for merging.
- int index - A place where a window or a group should be placed in a group.
- EngineWindow::GROUP_TYPE group_type - Type of a group to be created, if the first argument is a window and not a group.
- bool decompose_second - Flag to decompose the second argument of the merge, if it is a group, and combine with the first window or a group.
Return value
Group of windows.Ptr<EngineWindow> stackToParentGroup ( const Ptr<EngineWindow> & destination, const Ptr<EngineWindow> & window, int index = -1, bool decompose_second = false ) #
Stacks the second window to the parent window group of the first window. In the result, both windows passed as arguments will be on the same level in the group hierarchy. If the first window has no parent group, the function will return it as is.EngineWindowPtr window_1 = EngineWindow::create("Window 1", 512, 256);
EngineWindowPtr window_2 = EngineWindow::create("Window 2", 512, 256);
EngineWindowPtr window_3 = EngineWindow::create("Window 3", 512, 256);
// 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);
Arguments
- const Ptr<EngineWindow> & destination - The window into the parent group of which the other window is stacked.
- const Ptr<EngineWindow> & window - The window to be stacked.
- int index - A place where a window or a group should be placed in a group.
- bool decompose_second - Flag to decompose the second argument of the merge, if it is a group, and combine with the first window or a group.
Return value
Group of windows.Ptr<EngineWindow> stackWindows ( const Ptr<EngineWindow> & first, const Ptr<EngineWindow> & second, EngineWindow::GROUP_TYPE group_type = Enum.EngineWindow.GROUP_TYPE.TAB ) #
Returns a newly created group of the separate and/or nested windows. You cannot stack the window group to the separate window, however, you can stack a window nested in the window group: in this case, the window will be unstacked from its parent group and added to the new one. The windows are stacked in the default order. For example:EngineWindowPtr window_1 = EngineWindow::create("Window 1", 512, 256);
EngineWindowPtr window_2 = EngineWindow::create("Window 2", 512, 256);
EngineWindowPtr window_3 = EngineWindow::create("Window 3", 512, 256);
// stack 2 separate windows
EngineWindowPtr group_0 = WindowManager::stackWindows(window_1, window_2, EngineWindow::GROUP_TYPE_HORIZONTAL);
// stack a window from the window group to a separate window
EngineWindowPtr group_1 = WindowManager::stackWindows(window_3, window_1, EngineWindow::GROUP_TYPE_VERTICAL);
Arguments
- const Ptr<EngineWindow> & first - The window to be stacked.
- const Ptr<EngineWindow> & second - The window to be stacked.
- EngineWindow::GROUP_TYPE group_type - Type of a group to be created.
Return value
Group of windows.Ptr<EngineWindow> stackGroups ( const Ptr<EngineWindow> & first, const Ptr<EngineWindow> & second, EngineWindow::GROUP_TYPE group_type = Enum.EngineWindow.GROUP_TYPE.TAB, bool decompose_second = false ) #
Returns the group of window groups. The second group is added to the first group. To combine two windows or a group and a window, use the stack() method.EngineWindowPtr window_1 = EngineWindow::create("Window 1", 512, 256);
EngineWindowPtr window_2 = EngineWindow::create("Window 2", 512, 256);
EngineWindowPtr window_3 = EngineWindow::create("Window 3", 512, 256);
EngineWindowPtr window_4 = EngineWindow::create("Window 4", 512, 256);
// create 2 horizontal groups of windows
EngineWindowPtr group_1 = WindowManager::stack(window_1, window_2, 1, EngineWindow::GROUP_TYPE_HORIZONTAL);
EngineWindowPtr group_2 = WindowManager::stack(window_3, window_4, 1, EngineWindow::GROUP_TYPE_HORIZONTAL);
// stack one group to another to create a new vertical group
EngineWindowPtr group_3 = WindowManager::stackGroups(group_1, group_2, EngineWindow::GROUP_TYPE_VERTICAL);
Arguments
- const Ptr<EngineWindow> & first - The first window group for merging.
- const Ptr<EngineWindow> & second - The second window group for merging.
- EngineWindow::GROUP_TYPE group_type - Type of a group to be created.
- bool decompose_second - Flag to decompose the second argument of the merge, if it is a group, and combine with the first group.
Return value
Group of windows.Ptr<EngineWindow> stackToWindow ( const Ptr<EngineWindow> & destination_window, const Ptr<EngineWindow> & window, EngineWindow::GROUP_TYPE group_type = Enum.EngineWindow.GROUP_TYPE.TAB, bool decompose_second = false ) #
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.EngineWindowPtr window_1 = EngineWindow::create("Window 1", 512, 256);
EngineWindowPtr window_2 = EngineWindow::create("Window 2", 512, 256);
EngineWindowPtr window_3 = EngineWindow::create("Window 3", 512, 256);
// 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);
Arguments
- const Ptr<EngineWindow> & destination_window - The parent window to which another window is stacked.
- const Ptr<EngineWindow> & window - The window to be stacked.
- EngineWindow::GROUP_TYPE group_type - Type of a group to be created.
- bool decompose_second - Flag to decompose the second argument of the merge, if it is a group, and combine with the first group.
Return value
Group of stacked windows.Ptr<EngineWindow> stackToGroup ( const Ptr<EngineWindow> & destination_group, const Ptr<EngineWindow> & group, int index = -1, bool decompose_second = false ) #
Stacks the window or window group to another window group. The updated group of windows is returned.EngineWindowPtr window_1 = EngineWindow::create("Window 1", 512, 256);
EngineWindowPtr window_2 = EngineWindow::create("Window 2", 512, 256);
EngineWindowPtr window_3 = EngineWindow::create("Window 3", 512, 256);
EngineWindowPtr window_4 = EngineWindow::create("Window 4", 512, 256);
// create 2 horizontal groups of windows
EngineWindowPtr group_1 = WindowManager::stack(window_1, window_2, 1, EngineWindow::GROUP_TYPE_HORIZONTAL);
EngineWindowPtr group_2 = WindowManager::stack(window_3, window_4, 1, EngineWindow::GROUP_TYPE_HORIZONTAL);
// stack one group to another
WindowManager::stackToGroup(group_1, group_2);
Arguments
- const Ptr<EngineWindow> & destination_group - The parent group to which another group is stacked.
- const Ptr<EngineWindow> & group - The window or window group to be stacked.
- int index - A place where a window or a group should be placed in a group.
- bool decompose_second - Flag to decompose the second argument of the merge and combine with the first group.
Return value
Group of stacked windows.void unstack ( const Ptr<EngineWindow> & unstacked ) #
Removes a window or a group from a parent group. If there is only one window left, the group is automatically deleted after removing the window from it.Arguments
- const Ptr<EngineWindow> & unstacked - A window or a group to be removed from a parent group.
bool isMultipleWindowsSupported ( ) const#
Returns the value indicating if the engine can create more than one window. In addition to the settings defined by the user, it is currently impossible to create more than one window using Vulkan and DirectX 12. GL and DirectX 11, however, allow creating multiple windows.Return value
true if multiple windows are supported, otherwise false.bool isFullscreenMode ( ) const#
Returns the value indicating if at least one engine window is in a fullscreen state.Return value
true if the window is the fullscreen state, false if it's in the window mode.Ptr<EngineWindow> getFullscreenWindow ( ) const#
Returns the first window that is in the fullscreen state.Return value
Window in the fullscreen state, or nullptr if no window is found.Ptr<EngineWindow> getGuiFocusedWindow ( ) const#
Returns the window the content (internal widget) of which is clicked. The window itself doesn't have any nested windows.Return value
The window the GUI of which is in focus, or nullptr if no window is found.Ptr<EngineWindow> getWindowByID ( unsigned long long win_id ) const#
Returns the window by its ID.Arguments
- unsigned long long win_id - Window ID.
Return value
Window with the specified ID, or nullptr if the window is not found.bool dialogMessage ( const char * title, const char * message ) #
Displays a message dialog with the specified title and text.Arguments
- const char * title - Title of the message dialog to be displayed.
- const char * message - Message text to be displayed.
Return value
true if the message is displayed successfully; otherwise, false.bool dialogWarning ( const char * title, const char * warning ) #
Displays a warning dialog with the specified title and text.Arguments
- const char * title - Title of the warning dialog to be displayed.
- const char * warning - Warning message text to be displayed.
Return value
true if the message is displayed successfully; otherwise, false.bool dialogError ( const char * title, const char * error ) #
Displays an error dialog with the specified title and text.Arguments
- const char * title - Title of the error dialog to be displayed.
- const char * error - Error message text to be displayed.
Return value
true if the message is displayed successfully; otherwise, false.int showSystemDialog ( const Ptr<SystemDialog> & dialog ) #
Displays a custom system dialog with an arbitrary set of buttons.Arguments
- const Ptr<SystemDialog> & dialog - SystemDialog class instance representing the custom system dialog to be shown.
Return value
Number of the dialog button clicked by the user; or -1 if an error has occurred.const char * dialogOpenFolder ( const char * path ) #
Opens a common dialog enabling the user to specify a folder to open. When the dialog opens the specified default path shall be set displaying the corresponding elements.Arguments
- const char * path - Path to be set by default when the dialog opens.
Return value
Resulting folder name specified by the user.const char * dialogOpenFolder ( ) #
Opens a common dialog enabling the user to specify a folder to open.Return value
Resulting folder name specified by the user.Vector<String> dialogOpenFiles ( const char * path, const char * filter ) #
Opens a common dialog enabling the user to specify a list of filenames to open multiple files. When the dialog opens the specified default path and file filter shall be set displaying the corresponding elements.Arguments
- const char * path - Path to be set by default when the dialog opens.
- const char * filter - File name filter string to be set by default when the dialog opens. This filter string determines file type choices to be displayed in the Files of type box.
Return value
Resulting list of filenames specified by the user.Vector<String> dialogOpenFiles ( const char * path ) #
Opens a common dialog enabling the user to specify a list of filenames to open multiple files. When the dialog opens the specified default path shall be set displaying the corresponding elements.Arguments
- const char * path - Path to be set by default when the dialog opens.
Return value
Resulting list of filenames specified by the user.Vector<String> dialogOpenFiles ( ) #
Opens a common dialog enabling the user to specify a list of filenames to open multiple files.Return value
Resulting list of filenames specified by the user.const char * dialogOpenFile ( const char * path, const char * filter ) #
Opens a common dialog enabling the user to specify a filename to open a file. When the dialog opens the specified default path and file filter shall be set displaying the corresponding elements.Arguments
- const char * path - Path to be set by default when the dialog opens.
- const char * filter - File name filter string to be set by default when the dialog opens. This filter string determines file type choices to be displayed in the Files of type box.
Return value
Resulting filename specified by the user.const char * dialogOpenFile ( const char * path ) #
Opens a common dialog enabling the user to specify a filename to open a file. When the dialog opens the specified default path shall be set displaying the corresponding elements.Arguments
- const char * path - Path to be set by default when the dialog opens.
Return value
Resulting filename specified by the user.const char * dialogOpenFile ( ) #
Opens a common dialog enabling the user to specify a filename to open a file.Return value
Resulting filename specified by the user.const char * dialogSaveFile ( const char * path, const char * filter ) #
Opens a common dialog enabling the user to specify a filename to save a file as. When the dialog opens the specified default path and file filter shall be set displaying the corresponding elements.Arguments
- const char * path - Path to be set by default when the dialog opens.
- const char * filter - File name filter string to be set by default when the dialog opens. This filter string determines file type choices to be displayed in the Save as file type or Files of type box.
Return value
Resulting filename specified by the user.const char * dialogSaveFile ( const char * path ) #
Opens a common dialog enabling the user to specify a filename to save a file as. When the dialog opens the specified default path shall be set displaying the corresponding elements.Arguments
- const char * path - Path to be set by default when the dialog opens.
Return value
Resulting filename specified by the user.const char * dialogSaveFile ( ) #
Opens a common dialog enabling the user to specify a filename to save a file as.Return value
Resulting filename specified by the user.Ptr<EngineWindow> getUnderCursorWindow ( ) const#
Returns the window which is currently under cursor.Return value
The window which is currently under cursor.Ptr<EngineWindow> getFocusedWindow ( ) const#
Returns the window which is currently in focus.Return value
The window which is currently in focus.Ptr<EngineWindow> getIntersection ( const Math::ivec2 & global_pos, const Vector<Ptr<EngineWindow>> & excludes ) const#
Returns the window the intersection with which is detected.Arguments
- const Math::ivec2 & global_pos - The position of the intersection point in global coordinates.
- const Vector<Ptr<EngineWindow>> & excludes - The windows to be excluded from the intersection detection.
Return value
The window the intersection with which is detected.Ptr<EngineWindow> getIntersection ( const Math::ivec2 & global_pos ) const#
Returns the window the intersection with which is detected.Arguments
- const Math::ivec2 & global_pos - The position of the intersection point in global coordinates.
Return value
The window the intersection with which is detected.void forceUpdateWindowOrders ( ) #
Updates the Z order of all windows.void setEventsFilter ( int (*)(const Ptr<InputEvent> &) func ) #
Sets a callback function to be executed on receiving input events. This input event filter enables you to reject certain input events for the Engine and get necessary information on all input events.Arguments
- int (*)(const Ptr<InputEvent> &) func - Input event callback.