This page has been translated automatically.
视频教程
界面
要领
高级
实用建议
专业(SIM)
UnigineEditor
界面概述
资源工作流程
版本控制
设置和首选项
项目开发
调整节点参数
Setting Up Materials
设置属性
照明
Sandworm
使用编辑器工具执行特定任务
如何擴展編輯器功能
嵌入式节点类型
Nodes
Objects
Effects
Decals
光源
Geodetics
World Nodes
Sound Objects
Pathfinding Objects
Players
编程
基本原理
搭建开发环境
使用范例
C++
C#
UnigineScript
UUSL (Unified UNIGINE Shader Language)
Plugins
File Formats
材质和着色器
Rebuilding the Engine Tools
GUI
VR Development
双精度坐标
应用程序接口
Animations-Related Classes
Containers
Common Functionality
Controls-Related Classes
Engine-Related Classes
Filesystem Functionality
Math Functionality
Node-Related Classes
Objects-Related Classes
Networking Functionality
Pathfinding-Related Classes
Physics-Related Classes
Plugins-Related Classes
IG Plugin
CIGIConnector Plugin
Rendering-Related Classes
VR-Related Classes
创建内容
内容优化
材质
Material Nodes Library
Miscellaneous
Input
Math
Matrix
Textures
Art Samples
Tutorials

Unigine::EngineWindowViewport Class

Header: #include <UnigineWindowManager.h>
Inherits from: EngineWindow

The class to create and manage window viewports: setting cameras, specifying engine tools available (console, profiler, visualizer, etc.), add widgets to the client area.

To create an engine window viewport, use one of the class constructors:

Source code (C++)
// create an engine window of the specified size with the specified name
EngineWindowViewportPtr window = EngineWindowViewport::create("New window", 580, 300);

Then you can specify behavior of the window viewport and add widgets to its client area:

Source code (C++)
// set the window viewport as the main one
window->setMain(true);

// enable the console, profiler and visualizer for the window viewport
window->setConsoleUsage(true);
window->setProfilerUsage(true);
window->setVisualizerUsage(true);

// add widgets to the client area
window->addChild(WidgetLabel::create(window->getSelfGui(), String::format("This is %s window.", window->getTitle())));
window->addChild(WidgetButton::create(window->getSelfGui(), window->getTitle()), Gui::ALIGN_CENTER);

EngineWindowViewport Class

Members


static EngineWindowViewportPtr create ( const Math::ivec2 & size, int flags = 0 ) #

Constructor. Creates the window viewport of the specified size with the specified flags.

Arguments

  • const Math::ivec2 & size
  • int flags - Mask containing window flags.

static EngineWindowViewportPtr create ( int width, int height, int flags = 0 ) #

Constructor. Creates the window viewport of the specified size with the specified flags.

Arguments

  • int width - Window width.
  • int height - Window height.
  • int flags - Mask containing window flags.

static EngineWindowViewportPtr create ( const char * window_title, int width, int height, int flags = 0 ) #

Constructor. Creates the window viewport of the specified size with the specified title and flags.

Arguments

  • const char * window_title - The title of the window, in UTF-8 encoding.
  • int width - Window width.
  • int height - Window height.
  • int flags - Mask containing window flags.

Ptr<Viewport> getViewport ( ) const#

Returns the window viewport.

Return value

The window viewport.

void setCamera ( const Ptr<Camera> & camera ) #

Sets the camera the image from which is rendered to the engine window. This value has a higher priority over the main camera flag.

Arguments

Ptr<Camera> getCamera ( ) const#

Returns the camera the image from which is rendered to the engine window. This value has a higher priority over the main camera flag.

Return value

The camera the image from which is rendered to the engine window.

void setMain ( bool main ) #

Sets the window as the main window in order to use its size in logic, render from the main player into it, grab controls, etc.
Notice
There may be several windows that are set as main, or no main windows at all.

Arguments

  • bool main - true to set the window as the main window, otherwise false.

bool isMain ( ) const#

Returns a value indicating if this window is the main window (its size is used in logic, image from the main player is rendered into it, controls are grabbed, etc.)
Notice
There may be several windows that are set as main, or no main windows at all.

Return value

true if the window is the main window, otherwise false.

void setConsoleUsage ( bool usage ) #

Enables and disables display of the console for the window currently in focus.

Arguments

  • bool usage - true to display the console for the window in focus, false to disable it.

bool isConsoleUsage ( ) const#

Returns the value indicating if the console is displayed for the window currently in focus.

Return value

true if the console is displayed for the window in focus, otherwise false.

void setProfilerUsage ( bool usage ) #

Enables and disables the profiler display for the viewport of the window currently in focus.

Arguments

  • bool usage - true to enable the profiler display for the window in focus, false to disable it.

bool isProfilerUsage ( ) const#

Returns the value indicating if the profiler is displayed for the window currently in focus.

Return value

true if the profiler is displayed for the window in focus, otherwise false.

void setVisualizerUsage ( bool usage ) #

Enables and disables the visualizer display for the window currently in focus.

Arguments

  • bool usage - true to enable the visualizer display for the window currently in focus, false to disable it.

bool isVisualizerUsage ( ) const#

Returns the value indicating if the visualizer is displayed for the window currently in focus.

Return value

true if the visualizer is displayed for the window currently in focus, otherwise false.

void setSkipRenderEngine ( bool engine ) #

Disables the Engine rendering for the current window (even if it has the main camera flag or the user camera set). This doesn't disable the Gui instance, so widgets and the console remain available.

Arguments

  • bool engine - true to disable rendering, false to enable it.

bool isSkipRenderEngine ( ) const#

Returns the value indicating whether the Engine rendering is disabled.

Return value

true if the Engine rendering is disabled; otherwise, false.

bool isFullscreen ( ) const#

Returns the value indicating if the window is in a fullscreen state. A nested window will be withdrawn from the group if set to fullscreen.

Return value

true if the engine window is the fullscreen state, false if it is in the window mode.

void disableFullscreen ( ) #

Disables the fullscreen mode for the window in the fullscreen mode and sets the focus to this window. States and positions of other windows are restored.
Notice
This method can't be applied to nested windows.

bool enableFullscreen ( int display = -1, int mode = -1 ) #

Enables the specified fullscreen mode for the specified display. The states of other displayed windows are stored in order to restore their states and positions when the fullscreen mode is disabled. A nested window will be withdrawn from the group if set to fullscreen.

Arguments

  • int display - Display index.
  • int mode - Index of the mode supported by the display.

Return value

true if the specified fullscreen mode has been enabled for the specified display; otherwise, false.

void setMouseGrab ( bool grab ) #

Sets a value indicating if the mouse pointer is bound to the engine window viewport.
Notice
This method can be applied to a separate or parent window, using this method for a nested window is not allowed.

Arguments

  • bool grab - true if the pointer cannot leave the engine window viewport, otherwise false.

bool isMouseGrab ( ) const#

Returns a value indicating if the mouse pointer is bound to the engine window viewport.
Notice
This method can be applied to a separate or parent window, for nested windows, it returns false.

Return value

true if the pointer cannot leave the engine window viewport, otherwise false.

void addChild ( const Ptr<Widget> & widget, int flags = -1 ) #

Adds the specified widget as a child to the client area of the engine window.

Arguments

  • const Ptr<Widget> & widget - Child widget to be added.
  • int flags - Widget flags: one of the ALIGN_* pre-defined variables. This is an optional parameter.

void removeChild ( const Ptr<Widget> & widget ) #

Removes the specified widget from the engine window.

Arguments

  • const Ptr<Widget> & widget - Child widget to be removed.

Ptr<Widget> getChild ( int index ) #

Returns the child widget by its index.

Arguments

  • int index - Widget index.

Return value

Child widget.

int getNumChildren ( ) const#

Returns the total number of children widgets of the engine window.

Return value

The total number of children widgets.

bool isChild ( const Ptr<Widget> & widget ) #

Checks if the argument widget is the child of the current window viewport.

Arguments

Return value

true if the widget is the child of the current window viewport; otherwise, false.

Event<const Ptr<EngineWindowViewport> &> getEventCustomRender ( ) #

Event triggered when {event_description}. You can subscribe to events via connect()  and unsubscribe via disconnect(). You can also use EventConnection  and EventConnections  classes for convenience (see examples below).

Usage Example

Source code (C++)
// implement the CustomRender event handler
void customrender_event_handler(const Ptr<EngineWindowViewport> & viewport)
{
	Log::message("\Handling CustomRender event\n");
}


//////////////////////////////////////////////////////////////////////////////
//  1. Multiple subscriptions can be linked to an instance of the EventConnections 
//  class that you can use later to remove all these subscriptions at once
//////////////////////////////////////////////////////////////////////////////

// create an instance of the EventConnections class
EventConnections customrender_event_connections;

// link to this instance when subscribing for an event (subscription for various events can be linked)
enginewindowviewport->getEventCustomRender().connect(customrender_event_connections, customrender_event_handler);

// other subscriptions are also linked to this EventConnections instance 
// (e.g. you can subscribe using lambdas)
enginewindowviewport->getEventCustomRender().connect(customrender_event_connections, [](const Ptr<EngineWindowViewport> & viewport) { 
		Log::message("\Handling CustomRender event (lambda).\n");
	}
);

// ...

// later all of these linked subscriptions can be removed with a single line
customrender_event_connections.disconnectAll();

//////////////////////////////////////////////////////////////////////////////
//  2. You can subscribe and unsubscribe via an instance of the EventConnection 
//  class. And toggle this particular connection off and on, when necessary.
//////////////////////////////////////////////////////////////////////////////

// create an instance of the EventConnection class
EventConnection customrender_event_connection;

// subscribe for the CustomRender event with a handler function keeping the connection
enginewindowviewport->getEventCustomRender().connect(customrender_event_connection, customrender_event_handler);

// ...

// you can temporarily disable a particular event connection to perform certain actions
customrender_event_connection.setEnabled(false);

// ... actions to be performed

// and enable it back when necessary
customrender_event_connection.setEnabled(true);

// ...

// remove subscription for the CustomRender event via the connection
customrender_event_connection.disconnect();

//////////////////////////////////////////////////////////////////////////////
//  3. You can add EventConnection/EventConnections instance as a member of the
//  class that handles the event. In this case all linked subscriptions will be 
//  automatically removed when class destructor is called
//////////////////////////////////////////////////////////////////////////////

// Class handling the event
class SomeClass
{
public:
	// instance of the EventConnections class as a class member
	EventConnections e_connections;

	// A CustomRender event handler implemented as a class member
	void event_handler(const Ptr<EngineWindowViewport> & viewport)
	{
		Log::message("\Handling CustomRender event\n");
		// ...
	}
};

SomeClass *sc = new SomeClass();

// ...

// specify a class instance in case a handler method belongs to some class
enginewindowviewport->getEventCustomRender().connect(sc->e_connections, sc, &SomeClass::event_handler);

// ...

// handler class instance is deleted with all its subscriptions removed automatically
delete sc;

//////////////////////////////////////////////////////////////////////////////
//  4. You can subscribe and unsubscribe via the handler function directly
//////////////////////////////////////////////////////////////////////////////

// subscribe for the CustomRender event with a handler function
enginewindowviewport->getEventCustomRender().connect(customrender_event_handler);


// remove subscription for the CustomRender event later by the handler function
enginewindowviewport->getEventCustomRender().disconnect(customrender_event_handler);


//////////////////////////////////////////////////////////////////////////////
//   5. Subscribe to an event saving an ID and unsubscribe later by this ID
//////////////////////////////////////////////////////////////////////////////

// define a connection ID to be used to unsubscribe later
EventConnectionId customrender_handler_id;

// subscribe for the CustomRender event with a lambda handler function and keeping connection ID
customrender_handler_id = enginewindowviewport->getEventCustomRender().connect([](const Ptr<EngineWindowViewport> & viewport) { 
		Log::message("\Handling CustomRender event (lambda).\n");
	}
);

// remove the subscription later using the ID
enginewindowviewport->getEventCustomRender().disconnect(customrender_handler_id);


//////////////////////////////////////////////////////////////////////////////
//   6. Ignoring all CustomRender events when necessary
//////////////////////////////////////////////////////////////////////////////

// you can temporarily disable the event to perform certain actions without triggering it
enginewindowviewport->getEventCustomRender().setEnabled(false);

// ... actions to be performed

// and enable it back when necessary
enginewindowviewport->getEventCustomRender().setEnabled(true);
Notice
For more details see the Event Handling article.
Last update: 2024-01-10
Build: ()