This page has been translated automatically.
视频教程
界面
要领
高级
实用建议
UnigineEditor
界面概述
资产工作流程
设置和首选项
项目开发
调整节点参数
Setting Up Materials
Setting Up Properties
照明
Landscape Tool
Sandworm
使用编辑器工具执行特定任务
Extending Editor Functionality
嵌入式节点类型
Nodes
Objects
Effects
Decals
光源
Geodetics
World Nodes
Sound Objects
Pathfinding Objects
Players
编程
基本原理
搭建开发环境
Usage Examples
C++
C#
UnigineScript
UUSL (Unified UNIGINE Shader Language)
Plugins
File Formats
Rebuilding the Engine Tools
GUI
双精度坐标
应用程序接口
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
创建内容
Content Optimization
Materials
Art Samples
Tutorials

Unigine::WidgetDialogFile Class

Header: #include <UnigineWidgets.h>
Inherits from: WidgetDialog

This class creates dialog window where a file is selected. On the left side file-related information or an image preview is displayed.

Example#

The following code illustrates how to create a file selection dialog widget and use it to select files. You can copy and paste the code below to the corresponding files of your project (AppWorldLogic.h and AppWorldLogic.cpp).

AppWorldLogic.h

Source code (C++)
#ifndef __APP_WORLD_LOGIC_H__
#define __APP_WORLD_LOGIC_H__

#include <UnigineLogic.h>
#include <UnigineStreams.h>
#include <UnigineWidgets.h>

class AppWorldLogic : public Unigine::WorldLogic
{

public:
	AppWorldLogic();
	virtual ~AppWorldLogic();

	int init() override;

	int update() override;
	int postUpdate() override;
	int updatePhysics() override;

	int shutdown() override;

	int save(const Unigine::StreamPtr &stream) override;
	int restore(const Unigine::StreamPtr &stream) override;
private:
	// declaring widgets to be used and callback functions for them
	Unigine::WidgetLabelPtr file_name;
	Unigine::WidgetButtonPtr open_button;
	Unigine::WidgetDialogFilePtr file_dialog;
	void on_button_clicked();
	void dialog_ok_clicked();
	void dialog_cancel_clicked();
};

#endif // __APP_WORLD_LOGIC_H__

AppWorldLogic.cpp

Source code (C++)
#include <UnigineWidgets.h>
#include <UnigineFileSystem.h>
#include "AppWorldLogic.h"
using namespace Unigine;

// callback to be fired on clicking the button displaying the file dialog
void AppWorldLogic::on_button_clicked()
{
	// resetting file sepection, showing the dialog and setting permanent focus to it
	file_dialog->setFile("");
	file_dialog->setHidden(0);
	file_dialog->setPermanentFocus();
}

// callback to be fired on clicking the Ok button of the file dialog
void AppWorldLogic::dialog_ok_clicked()
{
	// getting the current path selection fron the dialog and checking if the file exists
	String path = file_dialog->getFile();
	if(!FileSystem::isFileExist(path))
		return;
	
	// if the file exists hiding the dialog, displaying the selected file on the "file_name" label and removing focus
	file_dialog->setHidden(1);
	file_name->setText(path);
	file_dialog->removeFocus();
}

// callback to be fired on clicking the Cancel button of the file dialog
void AppWorldLogic::dialog_cancel_clicked()
{
	file_dialog->setHidden(1);
	file_dialog->removeFocus();
}
AppWorldLogic::AppWorldLogic()
{
}

AppWorldLogic::~AppWorldLogic()
{
}

int AppWorldLogic::init()
{
	// getting a pointer to the system GUI
	GuiPtr gui = Gui::get();
	
	// creating a label widget to display the file selected via the dialog
	file_name = WidgetLabel::create(gui, "No file selected yet");
	gui->addChild(file_name, Gui::ALIGN_TOP | Gui::ALIGN_BACKGROUND);
	
	// creating a button widget to display the file dialog
	open_button = WidgetButton::create(gui, "Select an image file on disk");
	gui->addChild(open_button, Gui::ALIGN_TOP | Gui::ALIGN_BACKGROUND);
	
	// setting "on_button_clicked" function to handle CLICKED event for the button
	open_button->addCallback(Gui::CLICKED, MakeCallback(this, &AppWorldLogic::on_button_clicked));

	// creating a file dialog widget and setting its caption, default path and file extensions filter to display only *.png and *.jpeg files
	file_dialog = WidgetDialogFile::create(gui, "File open dialog");
	file_dialog->setPath("./");
	file_dialog->setFilter(".png.jpeg");

	// setting "dialog_ok_clicked" function to handle CLICKED event for dialog Ok button
	file_dialog->getOkButton()->addCallback(Gui::CLICKED, MakeCallback(this, &AppWorldLogic::dialog_ok_clicked));

	// setting "dialog_cancel_clicked" function to handle CLICKED event for dialog Cancel button
	file_dialog->getCancelButton()->addCallback(Gui::CLICKED, MakeCallback(this, &AppWorldLogic::dialog_cancel_clicked));

	// adding the created file dialog widget to the system GUI and hiding it
	file_dialog->setHidden(1);
	gui->addChild(file_dialog, Gui::ALIGN_OVERLAP | Gui::ALIGN_CENTER);
	return 1;
}

////////////////////////////////////////////////////////////////////////////////
// start of the main loop
////////////////////////////////////////////////////////////////////////////////

int AppWorldLogic::update()
{
	// Write here code to be called before updating each render frame: specify all graphics-related functions you want to be called every frame while your application executes.
	return 1;
}

int AppWorldLogic::postUpdate()
{
	// The engine calls this function after updating each render frame: correct behavior after the state of the node has been updated.
	return 1;
}

int AppWorldLogic::updatePhysics()
{
	// Write here code to be called before updating each physics frame: control physics in your application and put non-rendering calculations.
	// The engine calls updatePhysics() with the fixed rate (60 times per second by default) regardless of the FPS value.
	// WARNING: do not create, delete or change transformations of nodes here, because rendering is already in progress.
	return 1;
}

////////////////////////////////////////////////////////////////////////////////
// end of the main loop
////////////////////////////////////////////////////////////////////////////////

int AppWorldLogic::shutdown()
{
	// Write here code to be called on world shutdown: delete resources that were created during world script execution to avoid memory leaks.

	return 1;
}

int AppWorldLogic::save(const Unigine::StreamPtr &stream)
{
	// Write here code to be called when the world is saving its state (i.e. state_save is called): save custom user data to a file.
	UNIGINE_UNUSED(stream);
	return 1;
}

int AppWorldLogic::restore(const Unigine::StreamPtr &stream)
{
	// Write here code to be called when the world is restoring its state (i.e. state_restore is called): restore custom user data to a file here.
	UNIGINE_UNUSED(stream);
	return 1;
}

WidgetDialogFile Class

Members


static WidgetDialogFilePtr create ( const Ptr<Gui> & gui, const char * str = 0 ) #

Constructor. Creates a file picker dialog with given parameters and adds it to the specified GUI.

Arguments

  • const Ptr<Gui> & gui - GUI, to which the dialog will belong.
  • const char * str - Dialog title. This is an optional parameter.

static WidgetDialogFilePtr create ( const char * str = 0 ) #

Constructor. Creates a file picker dialog with given parameters and adds it to the Engine GUI.

Arguments

  • const char * str - Dialog title. This is an optional parameter.

void setFile ( const char * file ) #

Selects a given file in the file picker.

Arguments

  • const char * file - Absolute or relative (to the data folder) path.

const char * getFile ( ) const#

Returns the currently selected file.

Return value

Path to the file.

void setFilter ( const char * filter ) #

Sets a file name filter, which is used to display files of required types only.

Arguments

  • const char * filter - List of file extensions with leading dots and without additional separators, for example: .mesh.smesh.

const char * getFilter ( ) const#

Returns the currently used file name filter.

Return value

List of file extensions with leading dots and without additional separators, for example: .mesh.smesh.

void setPath ( const char * path ) #

Sets a path to the folder, contents of which should be displayed in the file picker.

Arguments

  • const char * path - Absolute or relative (to the data folder) path.

const char * getPath ( ) const#

Returns the current path to the folder, contents of which is displayed in the file picker.

Return value

Current path to the folder.

void setTabs ( const char * tabs ) #

Adds a set of tabs to the file picker dialog. The tabs allow the user to interact with several folders at once.

Arguments

  • const char * tabs - List of paths separated with semicolons. Each path corresponds to a tab.

const char * getTabs ( ) const#

Returns a list of tabs in the file picker dialog. The tabs allow the user to interact several folders at once.

Return value

List of paths separated with semicolons. Each path corresponds to a tab.
Last update: 2021-08-24
Build: ()