This page has been translated automatically.
Video Tutorials
Interface
Essentials
Advanced
How To
Professional (SIM)
UnigineEditor
Interface Overview
Assets Workflow
Settings and Preferences
Working With Projects
Adjusting Node Parameters
Setting Up Materials
Setting Up Properties
Lighting
Sandworm
Using Editor Tools for Specific Tasks
Extending Editor Functionality
Built-in Node Types
Nodes
Objects
Effects
Decals
Light Sources
Geodetics
World Nodes
Sound Objects
Pathfinding Objects
Players
Programming
Fundamentals
Setting Up Development Environment
Usage Examples
C++
C#
UnigineScript
UUSL (Unified UNIGINE Shader Language)
Plugins
File Formats
Materials and Shaders
Rebuilding the Engine Tools
GUI
Double Precision Coordinates
API
Containers
Common Functionality
Controls-Related Classes
Filesystem Functionality
GUI-Related Classes
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
Content Creation
Content Optimization
Materials
Material Nodes Library
Miscellaneous
Input
Math
Matrix
Textures
Art Samples
Tutorials

Unigine::App Class

Header: #include <UnigineApp.h>

The App class contains functions to control the Unigine application graphic context, which includes:

  • Update parameters
  • Events of the controls (keyboard, mouse)
  • FPS
  • Window parameters (height, width, name, etc.)

The class is used, for example, when you need to get and manage user input.

Usage Example#

The following examples perform:

  • Changing parameters of the application window (such as title, icon). The specified changes are applied after application start-up. It means that the window with default settings will appear first. If you need the custom settings are applied before the application window is displayed, you should implement your own class inherited from the App class.
  • Processing user inputs.
  • Updating the application in background.

Changing Window Parameters#

AppSystemLogic.cpp

Source code (C++)
#include "AppSystemLogic.h"

#include <UnigineApp.h>
#include <UnigineImage.h>

using namespace Unigine;


int AppSystemLogic::init() {

	// set a custom icon for the application window
	ImagePtr icon = Image::create("textures/window_icon.png");
	App::setIcon(icon);

	// set a custom title for the application window
	App::setTitle("Custom Window Title");

	return 1;
}

int AppSystemLogic::update() {
	
	// get an image for the mouse pointer
	ImagePtr mouse = Image::create();
	mouse->load("textures/mouse_pointer.png");
	// resize the image to make it square
	mouse->resize(mouse->getWidth(),mouse->getWidth());
	if (mouse->isLoaded() && mouse->getFormat() == Image::FORMAT_RGBA8)
	{
		// set the image for the OS mouse pointer
		App::setMouseCursor(mouse->getPixels(), mouse->getWidth());
		// show the OS mouse pointer
		App::setMouseCursorSystem(1);
	}
	
	return 1;
}

Processing User Inputs#

AppWorldLogic.cpp

Source code (C++)
#include "AppWorldLogic.h"

#include <UnigineApp.h>
#include <UnigineWorld.h>
#include <UnigineGame.h>
#include <UnigineGui.h>
#include <UnigineNode.h>
#include <UniginePlayers.h>

using namespace Unigine;

// declare a player pointer
PlayerPersecutorPtr player;

int AppWorldLogic::init() {
	
	// update the application constantly
	App::setBackgroundUpdate(1);
	// get a node
	NodePtr node = World::getNodeByName("material_ball");
	// create a new persecutor
	player = PlayerPersecutor::create();
	// set the obtainde node as the target one
	player->setTarget(node);
	// set player's settings
	player->setAnchor(Math::vec3(0, 0, 0.45f));
	player->setPhiAngle(-130.0f);
	player->setMinDistance(0.3f);
	player->setMaxDistance(20.0f);
	player->setDistance(5.0f);
	player->setFov(35.0f);
	// set the player to the Game Camera viewport
	Game::setPlayer(player);

	return 1;
}

int AppWorldLogic::update() {

	// change the distance between the player and the target node on mouse wheel scrolling
	int scroll_delta = App::getMouseAxis(App::AXIS_Y);
	if (scroll_delta != 0) {
		float f_scroll_delta = scroll_delta / 30.0f;
		player->setDistance(player->getDistance() - f_scroll_delta);
	}

	// zoom the camera in or out when the right mouse button is pressed and the mouse is moved backward/forward
	if (App::getMouseButton() == App::BUTTON_RIGHT) {
		float mouse_delta = (Gui::get()->getMouseDY() + Gui::get()->getMouseDX()) / 500.0f;
		player->setDistance(player->getDistance() - mouse_delta);
	}

	return 1;
}

int AppWorldLogic::shutdown() {
	
	// clear the player pointer
	player.clear();

	return 1;
}

See Also#

A set of UnigineScript API samples located in the <UnigineSDK>/data/samples/systems/ folder:

  • app_00
  • icon_00
  • mouse_00

App Class

Enums

CALLBACK_INDEX#

NameDescription
CALLBACK_BEFORE_UPDATE = 0
CALLBACK_AFTER_UPDATE = 1
CALLBACK_BEFORE_RENDER = 2
CALLBACK_AFTER_RENDER = 3
CALLBACK_BEFORE_SWAP = 4
CALLBACK_AFTER_SWAP = 5
NUM_CALLBACKS = 6

Members


int isActive ( ) #

Returns a value indicating if the current application is active (i.e. in focus). The function will always return 1, if the window background update mode is set to 1.
Notice
The sounds will be automatically disabled, if the application is not active.

Return value

1 if application is active; otherwise, 0.

int isLegacyMode ( ) const#

Returns a value indicating if rendering during the Engine's initialization stage is disabled for the application. Engine's boot screen requires rendering to be performed at the Engine's initialization stage. Certain applications do not support rendering in the init() by design. To ensure stable operation for such apps you can disable render-during-init functionality by setting the legacy mode. Thus, the boot screen won't be displayed for these applications.

Return value

1 if rendering during the Engine's initialization stage is disabled for the application; otherwise, 0.

void setClipboard ( const char * str ) #

Updates the contents of the system clipboard.

Arguments

  • const char * str - Contents to set.

const char * getClipboard ( ) #

Retrieves the contents of the system clipboard.

Return value

Contents of the system clipboard.

void * getHandle ( ) #

Returns a pointer to the application handle.

Return value

Pointer to the application handle.

int isDone ( ) #

Returns a value indicating if the application is closed.

Return value

1 if the application is closed; otherwise, 0.

int isInitialized ( ) #

Returns a value indicating if the application is initialized.

Return value

1 if the application is initialized; otherwise, 0.

int getFlags ( ) #

Returns the video mode flags set for the application.

Return value

Video mode flags: RESIZABLE, FULLSCREEN, etc.

float getFps ( ) #

Returns the application FPS counter value.

Return value

Application FPS counter value.

float getMinFps ( ) #

Returns the minimum FPS counter value for the last 600 frames.

Return value

Minimum FPS counter value for the last 600 frames.

float getMaxFps ( ) #

Returns the maximum FPS counter value for the last 600 frames.

Return value

Maximum FPS counter value for the last 600 frames.

float getMeanFps ( ) #

Returns the average FPS counter value for the last 600 frames.

Return value

Average FPS counter value for the last 600 frames.

void setHeight ( int value ) #

Sets the new height for the application window. The height is specified for the window inside and doesn't include the window borders.
Notice
If the INDEPENDENT_SIZE_WINDOW flag is set, only render resolution will be changed, leaving the window size unaffected.

Arguments

  • int value - Application window height, in pixels.

int getHeight ( ) #

Returns the current height of the application window. The returned value is the window inside height without borders.

Return value

Current height of the application window, in pixels.

int setIcon ( const Ptr<Image> & icon ) #

Sets an icon for the application window. The image must be of the square size and RGBA8 format.
Source code (C++)
// create an instance of the Image class
ImagePtr icon = Image::create("window_icon.png");
// set the image as an icon of the application window
App::setIcon(icon);

Arguments

  • const Ptr<Image> & icon - Image to be set as application's icon.

Return value

1 if the icon is set successfully; otherwise, 0.

float getIFps ( ) #

Returns an inverse value of the application FPS counter.

Return value

Inverse value of the application FPS counter (1/FPS).

void setMouseGrab ( int grab ) #

Sets a value indicating if the mouse pointer is bound to the application window.

Arguments

  • int grab - 1 if the mouse cannot leave the application window; otherwise, 0.

bool isMouseGrab ( ) #

Returns a value indicating if the mouse pointer is bound to the application window.

Return value

true if the mouse pointer cannot leave the application window; otherwise, false.

const char * getVideoAppName ( ) #

Returns a name of the graphics API used for application rendering.

Return value

One of the following values:
  • gl for OpenGL
  • d3d11 for DirectX 11
  • d3d12 for DirectX 12
  • null if no graphics API is used for application rendering

int getNumTouches ( ) #

Returns the number of touches. The maximum number of touches is 16.

Return value

Number of touches.

int setPosition ( int x, int y ) #

Sets the window position.

Arguments

  • int x - X coordinate of the upper-left corner of the window.
  • int y - Y coordinate of the upper-left corner of the window.

Return value

1 if the position of the window is set successfully; otherwise, 0.

int getPositionX ( ) #

Returns the X coordinate of the upper-left corner of the window.

Return value

X coordinate of the upper-left corner of the window.

int getPositionY ( ) #

Returns the Y coordinate of the upper-left corner of the window.

Return value

Y coordinate of the upper-left corner of the window.

int setTitle ( const char * title ) #

Sets a title for the application window.

Arguments

  • const char * title - Window title.

Return value

1 if the title is set successfully; otherwise, 0.

int getTouchX ( int touch ) #

Returns the X coordinate of the touch in the coordinate system of the application window.

Arguments

  • int touch - The touch number.

Return value

X coordinate of the touch.

int getTouchY ( int touch ) #

Returns the Y coordinate of the touch in the coordinate system of the application window.

Arguments

  • int touch - The toucn number.

Return value

Y coordinate of the touch.

void setBackgroundUpdate ( bool update ) #

Sets the value indicating whether the application window is updated when the window is hidden or out of focus (rendering frames in background). By default your UNIGINE application stops rendering frames and updating its main window, when it window goes out of focus (e.g. user switches to another window). Setting the background update mode enables constant rendering regardless of whether the application window is focused or in the background.

Arguments

  • bool update - Window update mode: true for constantly repeating update cycle (i.e. the application is updated even if the window is hidden or out of focus); otherwise, false.

bool isBackgroundUpdate ( ) #

Returns a value indicating whether the application window is updated when the window is hidden or out of focus.

Return value

true if the update cycle is constantly repeated (i.e. the application is updated even if the window is hidden or out of focus); otherwise, false.

int getVideoAdapter ( ) const#

Returns the number of the current video adapter.

Return value

Number of the current video adapter.

bool setVideoMode ( int width, int height, int flags = 0 ) #

Sets a video mode and initializes the application.

Arguments

Return value

true if the video mode is set and the application is initialized successfully; otherwise, false.

const char * getVideoModeName ( ) #

Returns the name of the current video mode.

Return value

Returns the name of the current video mode.

void setWidth ( int value ) #

Sets the new width of the application window. The width is specified for the window inside part and doesn't include the window borders.
Notice
If the INDEPENDENT_SIZE_WINDOW flag is set, only render resolution will be changed, leaving the window size unaffected.

Arguments

  • int value - Window width, in pixels.

int getWidth ( ) #

Returns the current application window width. The returned value is the window inside part width without borders.

Return value

Window width, in pixels.

void exit ( ) #

The engine requests to exit the application.

void keyPress ( unsigned int key ) #

Application notifies the engine that the specified key on a keyboard is pressed.

Arguments

  • unsigned int key - Key ID. Possible values can be in range [0;255], which are standard ASCII code symbols, or in range [KEY_ESC;KEY_F12], which are used for control buttons. For the full list of control keys see KEY_* variables of the Input class.

void keyPressUnicode ( unsigned int key ) #

Application notifies the engine that the specified key is pressed.

Arguments

  • unsigned int key - Unicode symbol.

void keyRelease ( unsigned int key ) #

Application notifies the engine that the specified key on a keyboard is released.

Arguments

  • unsigned int key - Key ID. Possible values can be in range [0;255], which are standard ASCII code symbols, or in range [KEY_ESC;KEY_F12], which are used for control buttons. For the full list of control keys see KEY_* variables of the Input class.

void startFps ( ) #

Starts the FPS counter if it was stopped. All function calls are placed into a stack, so the number of calls to this function should correspond to the number of calls to the stopFps() function.

void stopFps ( ) #

Stops the FPS counter. This function should be called if application window is hidden or some heavy non-rendering tasks are processing. All function calls are placed into a stack, so the number of calls to this function should correspond to the number of calls to the startFps() function.

void setMouseCursorHide ( bool hide ) #

Sets a value indicating if the mouse cursor should be hidden. Can be used, for example, to hide mouse cursor for a certain element.
Notice
This method hides the cursor only for one frame. So, you should call it each frame if a longer period is required.

Arguments

  • bool hide - true to hide the mouse cursor for a single frame, false - to show it.

bool isMouseCursorHide ( ) #

Returns a value indicating if the mouse cursor is hidden in the current frame.

Return value

true if mouse cursor is hidden in the current frame, false - to show it.

void setMouseCursorSystem ( bool system ) #

Sets a value indicating if the OS mouse pointer should be displayed.

Arguments

  • bool system - true to display the OS mouse pointer; otherwise, false.

bool isMouseCursorSystem ( ) #

Returns a value indicating if the OS mouse pointer is displayed.

Return value

true if the OS mouse pointer is displayed; otherwise, false.

void setMouseCursorNeedUpdate ( bool update ) #

Sets a value indicating that some changes were made to the cursor (e.g., it was shown, hidden, changed to system, etc.) and it has to be updated. Suppose the cursor was modified, for example, by the Interface plugin. After closing the plugin's window the cursor shall not return to its previous state because SDL doesn't even know about the changes. You can use this flag to signalize, that mouse cursor must be updated.

Arguments

  • bool update - true to signalize that the mouse cursor has to be updated; otherwise, false.

bool isMouseCursorNeedUpdate ( ) #

Returns a value indicating that changes were made to the cursor (e.g., it was shown, hidden, changed to system, etc.) and it has to be updated. Suppose the cursor was modified, for example, by the Interface plugin. After closing the plugin's window the cursor shall not return to its previous state because SDL doesn't even know about the changes. You can use this flag to signalize, that mouse cursor must be updated.

Return value

true if the mouse cursor has to be updated; otherwise, false.

void setMouseCursorSkinCustom ( const Ptr<Image> & image ) #

Sets a custom image to be used for the mouse cursor.

Arguments

  • const Ptr<Image> & image - Image containing pointer shapes to be set for the mouse cursor (e.g., select, move, resize, etc.).

void setMouseCursorSkinSystem ( ) #

Sets the current OS cursor skin (pointer shapes like select, move, resize, etc.).

void setMouseCursorSkinDefault ( ) #

Sets the default Engine cursor skin (pointer shapes like select, move, resize, etc.).

void setMouseCursorCustom ( const Ptr<Image> & image, int x = 0, int y = 0 ) #

Sets a custom image for the OS mouse cursor. The image must be of the square size and RGBA8 format.
Source code (C++)
// create an instance of the Image class
ImagePtr cursor = Image::create("textures/my_cursor.png");
// set the image as the mouse cursor
App::setMouseCursorCustom(cursor);
// show the OS mouse pointer
App::setMouseCursorSystem(1);

Arguments

  • const Ptr<Image> & image - Cursor image to be set.
  • int x - X coordinate of the cursor's hot spot.
  • int y - Y coordinate of the cursor's hot spot.

void clearMouseCursorCustom ( ) #

Clears the custom mouse cursor set via the setMouseCursorCustom() method.

void updateMouseCursor ( ) #

Updates the mouse cursor. This method should be called after making changes to the mouse cursor to apply them all together. After calling this method the cursor shall be updated in the next frame.

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

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.

void setCustomSwapBuffersCallback ( CallbackBase * callback ) #

Sets a callback to subscribe for an event to take place instead of swapping from the back buffer to the front one. So you can add your custom logic just before, right after or even instead of the buffer swap operation. The callback signature is as follows:
Source code
void CallbackMethod(void *arg1, void *arg2, void *arg3)
Logic of these three pointers is determined by the current graphics API:
  • DirectX on Windows: arg1 - ID3D11Device, arg2 - ID3D11DeviceContext, arg3 - IDXGISwapChain
  • OpenGL on Windows: arg1 - HDC
  • OpenGL on Linux: arg1 - Display, arg2 - GLXDrawable

Here is an example that uses VSync even if -video_vsync 0:

Custom Swap Buffer Logic Example

Source code (C++)
void custom_swap_buffers(void *arg1, void *arg2, void *arg3)
{
	if (Render::getAPI() == Render::API_DIRECT3D11)
	{
		#ifdef _WIN32
		ID3D11Device *device = static_cast<ID3D11Device *>(arg1);
		ID3D11DeviceContext *context = static_cast<ID3D11DeviceContext *>(arg2);
		IDXGISwapChain *swap_chain = static_cast<IDXGISwapChain *>(arg3);

		swap_chain->Present(1, 0);
		#endif
	}
	else if (Render::getAPI() == Render::API_OPENGL)
	{
		#ifdef _WIN32
		hdc = static_cast<HDC>(arg1);
		#else
		display = static_cast<Display *>(arg1);
		drawable = *static_cast<GLXDrawable *>(arg2);
		#endif

		#ifdef _WIN32
		wglSwapIntervalEXT(1);
		SwapBuffers(hdc);
		#else
		glXSwapIntervalEXT(display, drawable, 1);
		glXSwapBuffers(display, drawable);
		#endif
	}
}

Arguments

CallbackBase * getCustomSwapBuffersCallback ( ) #

Returns the current buffer swap callback function set for the application.

Return value

Callback pointer.

bool isEmptyClipboard ( ) const#

int getVSync ( ) const#

Last update: 2022-07-01
Build: ()