目录
前言
本节的主要内容为点击下拉菜单选项后的功能实现。
主要工作
掌握信息显示的方法,并结合UI选项尝试实现了文本信息窗口。
一、具体代码
auto help = m.dropdown("Help");
if (help.item("Shortcuts")) shortcuts();
help.separator();
if (help.item("About")) about();
在上文的代码中实现了下拉菜单的UI布局,并编写了与之对应的功能函数shortcuts(快捷键提示)、about(相关信息提示)。
代码主要使用msgBox函数生成消息显示框,具体参数如下:
FALCOR_API MsgBoxButton msgBox(const std::string& msg, MsgBoxType type = MsgBoxType::Ok, MsgBoxIcon icon = MsgBoxIcon::None);
在shortcut是函数中,需要访问系统框架中自带的快捷键内容,例如退出界面、隐藏全部UI、捕捉当前相机位置等(这些信息为系统自定义,需要使用函数访问)。
void shortcuts()
{
constexpr char help[] =
"F1 - Show the help message\n"
"F9 - Show/hide the time\n"
"F6 - Show/hide the graph UI\n"
"F10 - Show/hide the FPS\n"
"F11 - Enable/disable main menu auto-hiding\n"
"` - Show the consle\n"
"ps. If you want to use the consle,any input\n"
" will be unvaild as shortcuts except 'ESC'.\n"
"\n";
msgBox(help + gpFramework->getKeyboardShortcutsStr());
}
void about()
{
std::string s = Renderer::getVersionString() + "\n";
s += "Powered by Falcor ";
s += FALCOR_VERSION_STRING;
s += "\nTeam Member:\n";
s += "ChenXiang\n";
s += "HuangYu\n";
s += "ChenRan\n";
s += "LiJiaze\n";
msgBox(s);
}
二、结果展示
在msgBox函数中传入字符串后,在点击shortcuts或about选项后,就能看到以下场景: