This page has been translated automatically.
视频教程
界面
要领
高级
实用建议
基础
专业(SIM)
UnigineEditor
界面概述
资源工作流程
Version Control
设置和首选项
项目开发
调整节点参数
Setting Up Materials
设置属性
照明
Sandworm
使用编辑器工具执行特定任务
如何擴展編輯器功能
嵌入式节点类型
Nodes
Objects
Effects
Decals
光源
Geodetics
World Nodes
Sound Objects
Pathfinding Objects
Players
编程
基本原理
搭建开发环境
使用范例
C++
C#
UnigineScript
统一的Unigine着色器语言 UUSL (Unified UNIGINE Shader Language)
Plugins
File Formats
材质和着色器
Rebuilding the Engine Tools
GUI
双精度坐标
应用程序接口
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
注意! 这个版本的文档是过时的,因为它描述了一个较老的SDK版本!请切换到最新SDK版本的文档。
注意! 这个版本的文档描述了一个不再受支持的旧SDK版本!请升级到最新的SDK版本。

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. Add the code below to the corresponding files of your project (AppWorldLogic.h and AppWorldLogic.cpp).

AppWorldLogic.h

Source code (C++)
class AppWorldLogic : public Unigine::WorldLogic
{

	// ... //

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(const Unigine::WidgetPtr & widget,  int mouse_buttons);
	void dialog_ok_clicked();
	void dialog_cancel_clicked();

	Unigine::EventConnections connection;
};

AppWorldLogic.cpp

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

using namespace Unigine;

// callback to be fired on clicking the button displaying the file dialog
void AppWorldLogic::on_button_clicked(const WidgetPtr & widget, int mouse_buttons)
{
	// resetting file selection, 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();
}

int AppWorldLogic::init()
{
	// getting a pointer to the system GUI
	GuiPtr gui = Gui::getCurrent();

	// 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->getEventClicked().connect(connection, 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()->getEventClicked().connect(connection, this, &AppWorldLogic::dialog_ok_clicked);

	// setting "dialog_cancel_clicked" function to handle CLICKED event for dialog Cancel button
	file_dialog->getCancelButton()->getEventClicked().connect(connection, 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;
}

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: 2024-08-16
Build: ()