2010-04-21 07:48:36 -07:00
|
|
|
#include "UserInterface.h"
|
2019-03-09 05:56:23 -08:00
|
|
|
#include <algorithm>
|
2019-04-11 01:31:04 -07:00
|
|
|
#include <iostream>
|
|
|
|
#include <string>
|
2019-03-09 09:51:25 -08:00
|
|
|
|
|
|
|
// NOTE: to use filesystem, you must also include the fs library such
|
|
|
|
// as via the `-lstdc++fs` linker option -- see b3view.pro
|
2019-03-09 09:47:08 -08:00
|
|
|
// #include <filesystem> // requires C++17
|
2019-04-11 01:31:04 -07:00
|
|
|
#include <experimental/filesystem> // requires C++14 such as gcc 8.2.1
|
2010-04-21 07:48:36 -07:00
|
|
|
|
2019-03-09 12:42:40 -08:00
|
|
|
#include "Debug.h"
|
|
|
|
#include "Engine.h"
|
2019-04-10 23:41:14 -07:00
|
|
|
#include "Utility.h"
|
2019-03-09 12:42:40 -08:00
|
|
|
|
2019-03-07 19:18:07 -08:00
|
|
|
using namespace irr;
|
|
|
|
using namespace irr::core;
|
|
|
|
using namespace irr::gui;
|
|
|
|
|
|
|
|
using std::string;
|
|
|
|
using std::wstring;
|
2019-03-07 23:30:06 -08:00
|
|
|
using namespace std;
|
|
|
|
|
|
|
|
// C++14: namespace filesystem = std::experimental::filesystem;
|
|
|
|
// namespace fs = std::filesystem; // doesn't work (not a namespace in gcc's C++17)
|
|
|
|
// using namespace std::filesystem; // doesn't work (not a namespace in gcc's C++17)
|
|
|
|
namespace fs = std::experimental::filesystem;
|
2019-03-07 19:18:07 -08:00
|
|
|
|
2010-04-21 07:48:36 -07:00
|
|
|
// PRIVATE
|
|
|
|
void UserInterface::setupUserInterface()
|
|
|
|
{
|
2019-03-07 10:23:54 -08:00
|
|
|
// Menu
|
2019-04-08 19:52:18 -07:00
|
|
|
menu = m_Gui->addMenu();
|
2019-04-11 01:31:04 -07:00
|
|
|
menu->addItem(L"File", UIE_FILEMENU, true, true);
|
|
|
|
menu->addItem(L"View", UIE_VIEWMENU, true, true);
|
2010-04-21 07:48:36 -07:00
|
|
|
|
2019-03-07 10:23:54 -08:00
|
|
|
// File Menu
|
2019-04-11 01:31:04 -07:00
|
|
|
fileMenu = menu->getSubMenu(0);
|
2019-04-19 12:29:30 -07:00
|
|
|
fileMenu->addItem(L"Open", UIC_FILE_OPEN);
|
|
|
|
fileMenu->addItem(L"Change Texture", UIC_FILE_OPEN_TEXTURE);
|
2019-04-19 12:50:06 -07:00
|
|
|
fileMenu->addItem(L"Previous Texture Shift F3", UIC_FILE_PREVIOUS_TEXTURE);
|
|
|
|
fileMenu->addItem(L"Next Texture F3", UIC_FILE_NEXT_TEXTURE);
|
2019-04-11 01:31:04 -07:00
|
|
|
fileMenu->addItem(L"Quit", UIC_FILE_QUIT);
|
2010-04-21 07:48:36 -07:00
|
|
|
|
2010-08-16 05:23:20 -07:00
|
|
|
// View Menu
|
2019-04-11 01:31:04 -07:00
|
|
|
viewMenu = menu->getSubMenu(1);
|
2019-04-19 14:13:58 -07:00
|
|
|
viewWireframeIdx = viewMenu->addItem(L"Wireframe",
|
|
|
|
UIC_VIEW_WIREFRAME, true,
|
|
|
|
false, this->m_WireframeDisplay, true);
|
|
|
|
viewLightingIdx = viewMenu->addItem(L"Lighting",
|
|
|
|
UIC_VIEW_LIGHTING, true,
|
|
|
|
false, this->m_Lighting, true);
|
|
|
|
viewAxisWidgetIdx = viewMenu->addItem(L"Origin Axis Widget",
|
|
|
|
UIC_VIEW_AXIS_WIDGET, true, false,
|
|
|
|
true, true);
|
|
|
|
viewTargetIdx = viewMenu->addItem(L"Camera Target",
|
|
|
|
UIC_VIEW_TARGET, true, false,
|
|
|
|
false, true);
|
|
|
|
|
|
|
|
viewTextureInterpolationIdx = viewMenu->addItem(L"Texture Interpolation Ctrl i",
|
|
|
|
UIC_VIEW_TEXTURE_INTERPOLATION, true, false,
|
|
|
|
this->m_TextureInterpolation, true);
|
|
|
|
|
|
|
|
viewYUpIdx = viewMenu->addItem(L"Y Up",
|
|
|
|
UIC_VIEW_Y_UP, true, false,
|
|
|
|
true, true);
|
|
|
|
viewZUpIdx = viewMenu->addItem(L"Z Up",
|
|
|
|
UIC_VIEW_Z_UP, true, false,
|
|
|
|
false, true);
|
|
|
|
viewMenu->addItem(L"Slower Ctrl Left",
|
|
|
|
UIC_VIEW_SLOWER, true, false,
|
|
|
|
false, false);
|
|
|
|
viewMenu->addItem(L"Faster Ctrl Right",
|
|
|
|
UIC_VIEW_FASTER, true, false,
|
|
|
|
false, false);
|
2010-08-16 05:23:20 -07:00
|
|
|
|
2019-03-07 21:52:29 -08:00
|
|
|
// Playback Control Window
|
|
|
|
dimension2d<u32> windowSize = m_Engine->m_Driver->getScreenSize();
|
2019-04-10 23:30:48 -07:00
|
|
|
playbackWindow = m_Gui->addWindow(
|
2019-04-19 14:13:58 -07:00
|
|
|
rect<s32>(vector2d<s32>(windowSize.Width - 4 - 160, 28),
|
|
|
|
dimension2d<s32>(160, 300)),
|
|
|
|
false,
|
|
|
|
L"Playback",
|
|
|
|
nullptr,
|
|
|
|
UIE_PLAYBACKWINDOW
|
|
|
|
);
|
2019-04-11 01:31:04 -07:00
|
|
|
playbackWindow->getCloseButton()->setVisible(false);
|
2019-03-07 21:52:29 -08:00
|
|
|
s32 spacing_x = 4;
|
2019-04-19 12:29:30 -07:00
|
|
|
s32 margin_y = 4;
|
2019-04-11 01:31:04 -07:00
|
|
|
spacing_y = 4;
|
2019-03-07 21:52:29 -08:00
|
|
|
s32 size_x = playbackWindow->getClientRect().getWidth() - 8;
|
|
|
|
s32 size_y = 24;
|
|
|
|
s32 y = 24;
|
|
|
|
playbackStartStopButton = m_Gui->addButton(
|
2019-04-19 14:13:58 -07:00
|
|
|
rect<s32>(vector2d<s32>(spacing_x, y),
|
|
|
|
dimension2d<s32>(size_x, size_y)),
|
2019-04-11 01:31:04 -07:00
|
|
|
playbackWindow,
|
|
|
|
UIE_PLAYBACKSTARTSTOPBUTTON,
|
|
|
|
L"Start/Stop",
|
|
|
|
nullptr);
|
2019-04-19 12:29:30 -07:00
|
|
|
|
|
|
|
y += size_y + spacing_y;
|
|
|
|
playbackSetFrameEditBox = m_Gui->addEditBox(
|
|
|
|
L"",
|
2019-04-19 14:13:58 -07:00
|
|
|
rect<s32>(vector2d<s32>(spacing_x, y),
|
|
|
|
dimension2d<s32>(size_x, size_y)),
|
2019-04-19 12:29:30 -07:00
|
|
|
true,
|
|
|
|
playbackWindow,
|
|
|
|
UIE_PLAYBACKSETFRAMEEDITBOX);
|
|
|
|
y += margin_y;
|
|
|
|
|
2019-03-07 21:52:29 -08:00
|
|
|
y += size_y + spacing_y;
|
|
|
|
playbackIncreaseButton = m_Gui->addButton(
|
2019-04-19 14:13:58 -07:00
|
|
|
rect<s32>(vector2d<s32>(spacing_x, y),
|
|
|
|
dimension2d<s32>(size_x, size_y)),
|
2019-04-11 01:31:04 -07:00
|
|
|
playbackWindow,
|
|
|
|
UIE_PLAYBACKINCREASEBUTTON,
|
|
|
|
L"Faster",
|
|
|
|
nullptr);
|
2019-04-19 12:29:30 -07:00
|
|
|
|
2019-03-07 21:52:29 -08:00
|
|
|
y += size_y + spacing_y;
|
|
|
|
playbackDecreaseButton = m_Gui->addButton(
|
2019-04-19 14:13:58 -07:00
|
|
|
rect<s32>(vector2d<s32>(spacing_x, y),
|
|
|
|
dimension2d<s32>(size_x, size_y)),
|
2019-04-11 01:31:04 -07:00
|
|
|
playbackWindow,
|
|
|
|
UIE_PLAYBACKDECREASEBUTTON,
|
|
|
|
L"Slower",
|
|
|
|
nullptr);
|
2010-04-23 01:13:44 -07:00
|
|
|
|
2019-04-03 07:35:27 -07:00
|
|
|
y += size_y + spacing_y;
|
2019-04-19 12:29:30 -07:00
|
|
|
playbackFPSEditBox = m_Gui->addEditBox(
|
2019-04-03 07:35:27 -07:00
|
|
|
L"",
|
2019-04-19 14:13:58 -07:00
|
|
|
rect<s32>(vector2d<s32>(spacing_x, y),
|
|
|
|
dimension2d<s32>(size_x, size_y)),
|
2019-04-03 07:35:27 -07:00
|
|
|
true,
|
|
|
|
playbackWindow,
|
2019-04-19 12:29:30 -07:00
|
|
|
UIE_FPSEDITBOX);
|
|
|
|
y += margin_y;
|
2019-04-03 07:35:27 -07:00
|
|
|
|
2019-04-08 19:52:18 -07:00
|
|
|
y += size_y + spacing_y;
|
|
|
|
texturePathStaticText = m_Gui->addStaticText(
|
|
|
|
L"Texture Path:",
|
2019-04-19 14:13:58 -07:00
|
|
|
rect<s32>(vector2d<s32>(spacing_x, y),
|
|
|
|
dimension2d<s32>(size_x, size_y)),
|
2019-04-08 19:52:18 -07:00
|
|
|
true,
|
|
|
|
true,
|
|
|
|
playbackWindow,
|
|
|
|
UIE_TEXTUREPATHSTATICTEXT,
|
2019-04-11 01:31:04 -07:00
|
|
|
false);
|
2019-04-19 12:29:30 -07:00
|
|
|
|
2019-04-08 19:52:18 -07:00
|
|
|
y += size_y + spacing_y;
|
|
|
|
texturePathEditBox = m_Gui->addEditBox(
|
|
|
|
L"",
|
2019-04-19 14:13:58 -07:00
|
|
|
rect<s32>(vector2d<s32>(spacing_x, y),
|
|
|
|
dimension2d<s32>(size_x, size_y)),
|
2019-04-08 19:52:18 -07:00
|
|
|
true,
|
|
|
|
playbackWindow,
|
2019-04-11 01:31:04 -07:00
|
|
|
UIE_TEXTUREPATHEDITBOX);
|
2019-04-19 12:29:30 -07:00
|
|
|
y += margin_y;
|
|
|
|
|
|
|
|
y += size_y + spacing_y;
|
|
|
|
axisSizeStaticText = m_Gui->addStaticText(
|
|
|
|
L"Axis Size:",
|
2019-04-19 14:13:58 -07:00
|
|
|
rect<s32>(vector2d<s32>(spacing_x, y)
|
|
|
|
dimension2d<s32>(size_x, size_y)),
|
2019-04-19 12:29:30 -07:00
|
|
|
true,
|
|
|
|
true,
|
|
|
|
playbackWindow,
|
|
|
|
UIE_AXISSIZESTATICTEXT,
|
|
|
|
false);
|
|
|
|
|
|
|
|
y += size_y + spacing_y;
|
|
|
|
axisSizeEditBox = m_Gui->addEditBox(
|
|
|
|
L"",
|
2019-04-19 14:13:58 -07:00
|
|
|
rect<s32>(vector2d<s32>(spacing_x, y),
|
|
|
|
dimension2d<s32>(size_x, size_y)),
|
2019-04-19 12:29:30 -07:00
|
|
|
true,
|
|
|
|
playbackWindow,
|
|
|
|
UIE_AXISSIZEEDITBOX);
|
|
|
|
y += margin_y;
|
|
|
|
|
|
|
|
y += size_y + spacing_y;
|
2019-04-08 19:52:18 -07:00
|
|
|
|
2010-04-21 07:48:36 -07:00
|
|
|
// Set Font for UI Elements
|
2010-04-23 01:13:44 -07:00
|
|
|
m_GuiFontFace = new CGUITTFace();
|
2019-03-07 19:18:07 -08:00
|
|
|
// irrString defines stringc as string<c8>
|
2019-04-11 01:31:04 -07:00
|
|
|
// if (QFile(fontPath).exists()) {
|
2019-03-09 13:41:56 -08:00
|
|
|
if (!Utility::isFile(m_Engine->m_FontPath)) {
|
|
|
|
m_Engine->m_FontPath = L"C:\\Windows\\Fonts\\calibrib.ttf";
|
|
|
|
}
|
|
|
|
if (!Utility::isFile(m_Engine->m_FontPath)) {
|
|
|
|
m_Engine->m_FontPath = L"C:\\Windows\\Fonts\\arialbd.ttf";
|
|
|
|
}
|
|
|
|
if (!Utility::isFile(m_Engine->m_FontPath)) {
|
2019-03-09 14:15:50 -08:00
|
|
|
m_Engine->m_FontPath = L"/usr/share/fonts/liberation/LiberationSans-Bold.ttf";
|
2019-03-09 13:41:56 -08:00
|
|
|
}
|
|
|
|
if (!Utility::isFile(m_Engine->m_FontPath)) {
|
2019-03-09 14:15:50 -08:00
|
|
|
m_Engine->m_FontPath = L"/usr/share/fonts/gnu-free/FreeSansBold.ttf";
|
2019-03-09 13:41:56 -08:00
|
|
|
}
|
|
|
|
if (!Utility::isFile(m_Engine->m_FontPath)) {
|
|
|
|
m_Engine->m_FontPath = L"/usr/share/fonts/dejavu/DejaVuSans-Bold.ttf";
|
|
|
|
}
|
|
|
|
if (!Utility::isFile(m_Engine->m_FontPath)) {
|
|
|
|
m_Engine->m_FontPath = L"/usr/share/fonts/google-droid/DroidSans-Bold.ttf";
|
|
|
|
}
|
|
|
|
|
2019-04-11 01:31:04 -07:00
|
|
|
if (m_GuiFontFace->load(m_Engine->m_FontPath.c_str())) { // actually takes `const io::path &`
|
|
|
|
m_GuiFont = new CGUITTFont(m_Gui);
|
|
|
|
m_GuiFont->attach(m_GuiFontFace, 14);
|
|
|
|
m_Gui->getSkin()->setFont(m_GuiFont);
|
|
|
|
} else {
|
2019-04-19 14:13:58 -07:00
|
|
|
std::wcerr << L"WARNING: Missing '" << m_Engine->m_FontPath << L"'"
|
|
|
|
<< endl;
|
2019-03-07 19:18:07 -08:00
|
|
|
delete m_GuiFontFace;
|
|
|
|
m_GuiFontFace = nullptr;
|
|
|
|
if (m_GuiFont != nullptr) {
|
|
|
|
std::wcerr << L"WARNING: Keeping old font loaded." << endl;
|
|
|
|
}
|
2019-03-07 10:23:54 -08:00
|
|
|
}
|
|
|
|
//}
|
2010-04-21 07:48:36 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void UserInterface::displayLoadFileDialog()
|
|
|
|
{
|
2019-04-19 14:13:58 -07:00
|
|
|
m_Gui->addFileOpenDialog(L"Select file to load",
|
|
|
|
true, nullptr, UIE_LOADFILEDIALOG);
|
2010-04-21 07:48:36 -07:00
|
|
|
}
|
|
|
|
|
2019-03-07 14:17:42 -08:00
|
|
|
void UserInterface::displayLoadTextureDialog()
|
|
|
|
{
|
2019-04-19 14:13:58 -07:00
|
|
|
m_Gui->addFileOpenDialog(L"Select file to load",
|
|
|
|
true, nullptr, UIE_LOADTEXTUREDIALOG);
|
2019-03-07 14:17:42 -08:00
|
|
|
}
|
|
|
|
|
2019-04-11 01:31:04 -07:00
|
|
|
void UserInterface::handleMenuItemPressed(IGUIContextMenu* menu)
|
2010-04-23 00:28:59 -07:00
|
|
|
{
|
2019-04-10 23:39:12 -07:00
|
|
|
s32 selected = menu->getSelectedItem();
|
|
|
|
if (selected > -1) {
|
|
|
|
s32 id = menu->getItemCommandId(static_cast<u32>(selected));
|
|
|
|
|
2019-04-11 01:31:04 -07:00
|
|
|
switch (id) {
|
2019-04-19 12:29:30 -07:00
|
|
|
case UIC_FILE_OPEN:
|
2019-04-10 23:39:12 -07:00
|
|
|
displayLoadFileDialog();
|
|
|
|
break;
|
|
|
|
|
2019-04-19 12:29:30 -07:00
|
|
|
case UIC_FILE_OPEN_TEXTURE:
|
2019-04-10 23:39:12 -07:00
|
|
|
displayLoadTextureDialog();
|
|
|
|
break;
|
|
|
|
|
2019-04-19 12:29:30 -07:00
|
|
|
case UIC_FILE_PREVIOUS_TEXTURE:
|
|
|
|
loadNextTexture(-1);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case UIC_FILE_NEXT_TEXTURE:
|
|
|
|
loadNextTexture(1);
|
|
|
|
break;
|
|
|
|
|
2019-04-10 23:39:12 -07:00
|
|
|
case UIC_FILE_QUIT:
|
|
|
|
m_Engine->m_RunEngine = false;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case UIC_VIEW_WIREFRAME:
|
2019-04-19 12:29:30 -07:00
|
|
|
m_WireframeDisplay = viewMenu->isItemChecked(viewWireframeIdx);
|
2019-04-19 14:13:58 -07:00
|
|
|
m_Engine->setMeshDisplayMode(m_WireframeDisplay, m_Lighting,
|
|
|
|
m_TextureInterpolation);
|
2019-04-10 23:39:12 -07:00
|
|
|
break;
|
|
|
|
|
|
|
|
case UIC_VIEW_LIGHTING:
|
2019-04-19 12:29:30 -07:00
|
|
|
m_Lighting = viewMenu->isItemChecked(viewLightingIdx);
|
2019-04-19 14:13:58 -07:00
|
|
|
m_Engine->setMeshDisplayMode(m_WireframeDisplay, m_Lighting,
|
|
|
|
m_TextureInterpolation);
|
2019-04-10 23:39:12 -07:00
|
|
|
break;
|
|
|
|
|
2019-04-19 12:29:30 -07:00
|
|
|
case UIC_VIEW_TARGET:
|
|
|
|
//
|
|
|
|
break;
|
|
|
|
|
|
|
|
case UIC_VIEW_Y_UP:
|
|
|
|
m_Engine->setZUp(false);
|
|
|
|
viewMenu->setItemChecked(viewZUpIdx, false);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case UIC_VIEW_Z_UP:
|
|
|
|
m_Engine->setZUp(true);
|
|
|
|
viewMenu->setItemChecked(viewYUpIdx, false);
|
|
|
|
break;
|
|
|
|
|
2019-04-10 23:39:12 -07:00
|
|
|
case UIC_VIEW_TEXTURE_INTERPOLATION:
|
2019-04-19 14:13:58 -07:00
|
|
|
m_TextureInterpolation = viewMenu->isItemChecked(
|
|
|
|
viewTextureInterpolationIdx
|
|
|
|
);
|
|
|
|
m_Engine->setMeshDisplayMode(m_WireframeDisplay, m_Lighting,
|
|
|
|
m_TextureInterpolation);
|
2019-04-10 23:39:12 -07:00
|
|
|
break;
|
|
|
|
}
|
2010-04-23 00:28:59 -07:00
|
|
|
}
|
2019-04-11 01:31:04 -07:00
|
|
|
}
|
2019-04-08 19:52:18 -07:00
|
|
|
|
2019-04-11 01:31:04 -07:00
|
|
|
void UserInterface::snapWidgets()
|
|
|
|
{
|
|
|
|
dimension2d<u32> screenSize = m_Engine->m_Driver->getScreenSize();
|
|
|
|
rect<s32> newRect;
|
|
|
|
//newRect.LowerRightCorner.X = static_cast<s32>(size.Width);
|
|
|
|
//newRect.LowerRightCorner.Y = static_cast<s32>(size.Height);
|
|
|
|
rect<s32> prevRect = playbackWindow->getRelativePosition();
|
2019-04-19 14:13:58 -07:00
|
|
|
newRect.UpperLeftCorner.X = static_cast<s32>(screenSize.Width)
|
|
|
|
- prevRect.getWidth() - spacing_y;
|
|
|
|
// debug() << "screen size: " << screenSize.Width << "x" << screenSize.Height;
|
|
|
|
// debug() << " prevRect: "
|
|
|
|
// << prevRect.UpperLeftCorner.X << ","
|
|
|
|
// << prevRect.UpperLeftCorner.Y << ","
|
|
|
|
// << prevRect.LowerRightCorner.X << ","
|
|
|
|
// << prevRect.LowerRightCorner.Y
|
|
|
|
// << " size=(" << prevRect.getWidth() << ","
|
|
|
|
// << prevRect.getHeight() << ")" << endl;
|
2019-04-11 01:31:04 -07:00
|
|
|
newRect.UpperLeftCorner.Y = prevRect.UpperLeftCorner.Y;
|
2019-04-19 14:13:58 -07:00
|
|
|
newRect.LowerRightCorner.X = newRect.UpperLeftCorner.X
|
|
|
|
+ prevRect.getWidth();
|
|
|
|
newRect.LowerRightCorner.Y = newRect.UpperLeftCorner.Y
|
|
|
|
+ prevRect.getHeight();
|
2019-04-11 01:31:04 -07:00
|
|
|
playbackWindow->setRelativePosition(newRect);
|
|
|
|
m_WindowSize.Width = m_Engine->m_Driver->getScreenSize().Width;
|
|
|
|
m_WindowSize.Height = m_Engine->m_Driver->getScreenSize().Height;
|
2010-04-23 00:28:59 -07:00
|
|
|
}
|
|
|
|
|
2010-04-21 07:48:36 -07:00
|
|
|
// PUBLIC
|
2019-04-11 01:31:04 -07:00
|
|
|
UserInterface::UserInterface(Engine* engine)
|
2010-04-21 07:48:36 -07:00
|
|
|
{
|
2019-04-19 12:29:30 -07:00
|
|
|
viewTextureInterpolationIdx = 0;
|
|
|
|
viewWireframeIdx = 0;
|
|
|
|
viewLightingIdx = 0;
|
2019-03-07 21:52:29 -08:00
|
|
|
this->playbackStartStopButton = nullptr;
|
|
|
|
|
2010-04-21 07:48:36 -07:00
|
|
|
m_Engine = engine;
|
|
|
|
m_Gui = engine->getGUIEnvironment();
|
|
|
|
|
2010-08-16 05:23:20 -07:00
|
|
|
m_WireframeDisplay = false;
|
|
|
|
m_Lighting = true;
|
2019-04-08 19:52:18 -07:00
|
|
|
m_TextureInterpolation = true;
|
2019-04-10 23:30:48 -07:00
|
|
|
playbackWindow = nullptr;
|
2010-08-16 05:23:20 -07:00
|
|
|
|
2010-04-21 07:48:36 -07:00
|
|
|
setupUserInterface();
|
|
|
|
}
|
|
|
|
|
|
|
|
UserInterface::~UserInterface()
|
|
|
|
{
|
|
|
|
delete m_GuiFont;
|
2010-04-23 01:13:44 -07:00
|
|
|
delete m_GuiFontFace;
|
2010-04-21 07:48:36 -07:00
|
|
|
}
|
|
|
|
|
2019-04-11 01:31:04 -07:00
|
|
|
IGUIEnvironment* UserInterface::getGUIEnvironment() const
|
2010-04-21 07:48:36 -07:00
|
|
|
{
|
|
|
|
return m_Gui;
|
|
|
|
}
|
|
|
|
|
2010-04-23 00:28:59 -07:00
|
|
|
void UserInterface::drawStatusLine() const
|
2010-04-21 07:48:36 -07:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2019-03-07 23:30:06 -08:00
|
|
|
bool UserInterface::loadNextTexture(int direction)
|
|
|
|
{
|
|
|
|
bool ret = false;
|
|
|
|
this->m_Engine->m_NextPath = L"";
|
|
|
|
std::wstring basePath = L".";
|
|
|
|
if (this->m_Engine->m_PreviousPath.length() > 0) {
|
2019-04-19 14:13:58 -07:00
|
|
|
std::wstring lastName = Utility::basename(
|
|
|
|
this->m_Engine->m_PreviousPath
|
|
|
|
);
|
|
|
|
std::wstring lastDirPath = Utility::parentOfPath(
|
|
|
|
this->m_Engine->m_PreviousPath
|
|
|
|
);
|
2019-03-07 23:30:06 -08:00
|
|
|
std::wstring parentPath = Utility::parentOfPath(lastDirPath);
|
2019-04-19 14:13:58 -07:00
|
|
|
std::wstring dirSeparator = Utility::delimiter(
|
|
|
|
this->m_Engine->m_PreviousPath
|
|
|
|
);
|
2019-03-07 23:30:06 -08:00
|
|
|
std::wstring texturesPath = parentPath + dirSeparator + L"textures";
|
2019-04-19 14:13:58 -07:00
|
|
|
std::wstring tryTexPath = texturesPath + dirSeparator
|
|
|
|
+ Utility::withoutExtension(lastName)
|
|
|
|
+ L".png";
|
2019-04-11 01:31:04 -07:00
|
|
|
if (direction == 0 && Utility::isFile(tryTexPath)) {
|
2019-03-07 23:30:06 -08:00
|
|
|
this->m_Engine->m_NextPath = tryTexPath;
|
|
|
|
this->m_Engine->loadTexture(this->m_Engine->m_NextPath);
|
2019-04-11 01:31:04 -07:00
|
|
|
} else {
|
2019-04-19 14:13:58 -07:00
|
|
|
tryTexPath = lastDirPath + dirSeparator
|
|
|
|
+ Utility::withoutExtension(lastName) + L".png";
|
2019-04-11 01:31:04 -07:00
|
|
|
if (direction == 0 && Utility::isFile(tryTexPath)) {
|
2019-03-07 23:30:06 -08:00
|
|
|
this->m_Engine->m_NextPath = tryTexPath;
|
|
|
|
ret = this->m_Engine->loadTexture(this->m_Engine->m_NextPath);
|
2019-04-11 01:31:04 -07:00
|
|
|
} else {
|
2019-03-07 23:30:06 -08:00
|
|
|
std::wstring path = texturesPath;
|
|
|
|
|
2019-03-09 04:43:36 -08:00
|
|
|
if (!fs::is_directory(fs::status(path)))
|
2019-04-19 14:13:58 -07:00
|
|
|
path = lastDirPath; // cycle in model's directory instead
|
2019-03-09 04:43:36 -08:00
|
|
|
|
2019-04-19 14:13:58 -07:00
|
|
|
fs::directory_iterator end_itr; // default yields past-the-end
|
2019-03-07 23:30:06 -08:00
|
|
|
|
|
|
|
std::wstring nextPath = L"";
|
|
|
|
std::wstring retroPath = L"";
|
|
|
|
std::wstring lastPath = L"";
|
|
|
|
|
|
|
|
bool found = false;
|
2019-04-08 19:52:18 -07:00
|
|
|
bool force = false;
|
|
|
|
wstring tryPath;
|
2019-03-09 04:43:36 -08:00
|
|
|
if (fs::is_directory(fs::status(path))) {
|
2019-04-08 19:52:18 -07:00
|
|
|
if (this->m_Engine->m_PrevTexturePath.length() == 0) {
|
2019-04-11 01:31:04 -07:00
|
|
|
if (this->m_Engine->m_PreviousPath.length() > 0) {
|
2019-04-19 14:13:58 -07:00
|
|
|
tryPath = texturesPath + dirSeparator
|
|
|
|
+ Utility::withoutExtension(
|
|
|
|
Utility::basename(
|
|
|
|
this->m_Engine->m_PreviousPath
|
|
|
|
)
|
|
|
|
)
|
|
|
|
+ L".png";
|
2019-04-08 19:52:18 -07:00
|
|
|
tryPath = Utility::toWstring(Utility::toString(tryPath));
|
|
|
|
if (!Utility::isFile(tryPath)) {
|
2019-04-19 14:13:58 -07:00
|
|
|
tryPath = texturesPath + dirSeparator
|
|
|
|
+ Utility::withoutExtension(
|
|
|
|
Utility::basename(
|
|
|
|
this->m_Engine->m_PreviousPath
|
|
|
|
)
|
|
|
|
)
|
|
|
|
+ L".jpg";
|
|
|
|
tryPath = Utility::toWstring(
|
|
|
|
Utility::toString(tryPath)
|
|
|
|
);
|
2019-04-08 19:52:18 -07:00
|
|
|
if (Utility::isFile(tryPath)) {
|
|
|
|
nextPath = tryPath;
|
|
|
|
found = true;
|
|
|
|
force = true;
|
|
|
|
}
|
2019-04-11 01:31:04 -07:00
|
|
|
} else {
|
2019-04-08 19:52:18 -07:00
|
|
|
nextPath = tryPath;
|
|
|
|
found = true;
|
|
|
|
force = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2019-04-11 01:31:04 -07:00
|
|
|
for (const auto& itr : fs::directory_iterator(path)) {
|
2019-04-19 14:13:58 -07:00
|
|
|
std::wstring ext = Utility::extensionOf(
|
|
|
|
itr.path().wstring()
|
|
|
|
); // no dot!
|
2019-03-09 05:56:23 -08:00
|
|
|
if (!is_directory(itr.status())
|
2019-04-19 14:13:58 -07:00
|
|
|
&& std::find(m_Engine->textureExtensions.begin(),
|
|
|
|
m_Engine->textureExtensions.end(), ext)
|
|
|
|
!= m_Engine->textureExtensions.end()) {
|
|
|
|
// cycle through files (go to next after
|
|
|
|
// m_PrevTexturePath if any previously loaded,
|
|
|
|
// otherwise first)
|
2019-04-11 01:31:04 -07:00
|
|
|
if (nextPath.length() == 0)
|
|
|
|
nextPath = itr.path().wstring();
|
2019-03-08 19:41:59 -08:00
|
|
|
lastPath = itr.path().wstring();
|
2019-03-09 05:56:23 -08:00
|
|
|
if (found && direction > 0) {
|
2019-04-11 01:31:04 -07:00
|
|
|
if (!force)
|
|
|
|
nextPath = itr.path().wstring();
|
2019-03-08 19:41:59 -08:00
|
|
|
break;
|
|
|
|
}
|
2019-04-19 14:13:58 -07:00
|
|
|
if (itr.path().wstring()
|
|
|
|
== this->m_Engine->m_PrevTexturePath)
|
2019-04-11 01:31:04 -07:00
|
|
|
found = true;
|
|
|
|
if (!found)
|
|
|
|
retroPath = itr.path().wstring();
|
2019-03-07 23:30:06 -08:00
|
|
|
}
|
|
|
|
}
|
2019-04-08 19:52:18 -07:00
|
|
|
if (retroPath.length() == 0)
|
2019-04-19 14:13:58 -07:00
|
|
|
retroPath = lastPath; // previous is last if at start
|
2019-03-09 05:56:23 -08:00
|
|
|
if (direction < 0)
|
|
|
|
nextPath = retroPath;
|
|
|
|
if (nextPath.length() > 0) {
|
|
|
|
ret = this->m_Engine->loadTexture(nextPath);
|
|
|
|
}
|
2019-03-07 23:30:06 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2019-04-11 01:31:04 -07:00
|
|
|
} else
|
|
|
|
debug() << "Can't cycle texture since no file was opened" << endl;
|
2019-03-09 05:56:23 -08:00
|
|
|
return ret;
|
2019-03-07 23:30:06 -08:00
|
|
|
}
|
|
|
|
|
2010-04-21 07:48:36 -07:00
|
|
|
// IEventReceiver
|
2019-04-11 01:31:04 -07:00
|
|
|
bool UserInterface::OnEvent(const SEvent& event)
|
2010-04-21 07:48:36 -07:00
|
|
|
{
|
|
|
|
// Events arriving here should be destined for us
|
2019-04-19 12:29:30 -07:00
|
|
|
bool handled = false;
|
2019-04-11 01:31:04 -07:00
|
|
|
if (event.EventType == EET_USER_EVENT) {
|
2019-04-19 12:29:30 -07:00
|
|
|
// debug() << "EET_USER_EVENT..." << endl;
|
2019-04-11 01:31:04 -07:00
|
|
|
if (event.UserEvent.UserData1 == UEI_WINDOWSIZECHANGED) {
|
2019-04-19 14:13:58 -07:00
|
|
|
if ((m_WindowSize.Width != m_Engine->m_Driver->getScreenSize().Width)
|
|
|
|
|| (m_WindowSize.Height != m_Engine->m_Driver->getScreenSize().Height)) {
|
2019-04-11 01:31:04 -07:00
|
|
|
snapWidgets();
|
|
|
|
}
|
2019-04-19 12:29:30 -07:00
|
|
|
handled = true;
|
|
|
|
}
|
|
|
|
} else if (event.EventType == EET_GUI_EVENT) {
|
|
|
|
// debug() << "EET_GUI_EVENT..." << endl;
|
|
|
|
handled = true; // set to false below if not handled
|
|
|
|
const SEvent::SGUIEvent* ge = &(event.GUIEvent);
|
|
|
|
switch (ge->Caller->getID()) {
|
|
|
|
case UIE_FILEMENU:
|
|
|
|
case UIE_VIEWMENU:
|
|
|
|
// call handler for all menu related actions
|
|
|
|
handleMenuItemPressed(static_cast<IGUIContextMenu*>(ge->Caller));
|
|
|
|
break;
|
|
|
|
|
|
|
|
case UIE_LOADFILEDIALOG:
|
|
|
|
if (ge->EventType == EGET_FILE_SELECTED) {
|
|
|
|
IGUIFileOpenDialog* fileOpenDialog = static_cast<IGUIFileOpenDialog*>(ge->Caller);
|
|
|
|
m_Engine->loadMesh(fileOpenDialog->getFileName());
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case UIE_LOADTEXTUREDIALOG:
|
|
|
|
if (ge->EventType == EGET_FILE_SELECTED) {
|
|
|
|
IGUIFileOpenDialog* fileOpenDialog = static_cast<IGUIFileOpenDialog*>(ge->Caller);
|
|
|
|
m_Engine->loadTexture(fileOpenDialog->getFileName());
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case UIE_PLAYBACKSTARTSTOPBUTTON:
|
|
|
|
if (ge->EventType == EGET_BUTTON_CLICKED) {
|
|
|
|
this->m_Engine->toggleAnimation();
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case UIE_PLAYBACKINCREASEBUTTON:
|
|
|
|
if (ge->EventType == EGET_BUTTON_CLICKED) {
|
|
|
|
this->m_Engine->incrementAnimationFPS(5);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case UIE_PLAYBACKDECREASEBUTTON:
|
|
|
|
if (ge->EventType == EGET_BUTTON_CLICKED) {
|
|
|
|
this->m_Engine->incrementAnimationFPS(-5);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case UIE_PLAYBACKSETFRAMEEDITBOX:
|
|
|
|
if (ge->EventType == EGET_EDITBOX_ENTER) {
|
|
|
|
if (this->m_Engine->m_LoadedMesh != nullptr) {
|
2019-04-19 14:13:58 -07:00
|
|
|
this->m_Engine->m_LoadedMesh->setCurrentFrame(
|
|
|
|
Utility::toF32(this->playbackSetFrameEditBox->getText())
|
|
|
|
);
|
2019-04-19 12:29:30 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case UIE_TEXTUREPATHEDITBOX:
|
|
|
|
if (ge->EventType == EGET_EDITBOX_ENTER) {
|
|
|
|
if (this->m_Engine->m_LoadedMesh != nullptr) {
|
|
|
|
this->m_Engine->loadTexture(texturePathEditBox->getText());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case UIE_FPSEDITBOX:
|
|
|
|
if (ge->EventType == EGET_EDITBOX_ENTER) {
|
|
|
|
if (this->m_Engine->m_LoadedMesh != nullptr) {
|
2019-04-19 14:13:58 -07:00
|
|
|
this->m_Engine->m_LoadedMesh->setAnimationSpeed(
|
|
|
|
Utility::toF32(this->playbackFPSEditBox->getText())
|
|
|
|
);
|
2019-04-19 12:29:30 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case UIE_AXISSIZEEDITBOX:
|
|
|
|
if (ge->EventType == EGET_EDITBOX_ENTER) {
|
2019-04-19 14:13:58 -07:00
|
|
|
this->m_Engine->axisLength = Utility::toF32(
|
|
|
|
this->axisSizeEditBox->getText()
|
|
|
|
);
|
2019-04-19 12:29:30 -07:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
// break;
|
|
|
|
handled = false;
|
2019-04-11 01:31:04 -07:00
|
|
|
}
|
|
|
|
} else if (event.EventType == EET_KEY_INPUT_EVENT) {
|
2019-04-19 12:29:30 -07:00
|
|
|
// debug() << "EET_KEY_INPUT_EVENT..." << endl;
|
|
|
|
handled = true; // set to false below if not handled
|
2019-03-10 06:55:31 -07:00
|
|
|
if (event.KeyInput.PressedDown && !m_Engine->KeyIsDown[event.KeyInput.Key]) {
|
|
|
|
if (event.KeyInput.Key == irr::KEY_F5) {
|
2019-04-19 14:13:58 -07:00
|
|
|
if (m_Engine->KeyIsDown[irr::KEY_LSHIFT]
|
|
|
|
|| m_Engine->KeyIsDown[irr::KEY_RSHIFT]) {
|
2019-04-19 12:29:30 -07:00
|
|
|
m_Engine->reloadTexture();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
m_Engine->reloadMesh();
|
|
|
|
} else if (event.KeyInput.Key == irr::KEY_F3) {
|
2019-04-19 14:13:58 -07:00
|
|
|
if (m_Engine->KeyIsDown[irr::KEY_LSHIFT]
|
|
|
|
|| m_Engine->KeyIsDown[irr::KEY_RSHIFT]) {
|
2019-04-19 12:29:30 -07:00
|
|
|
loadNextTexture(-1);
|
|
|
|
debug() << " - back" << endl;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
loadNextTexture(1);
|
|
|
|
} else if (event.KeyInput.Key == irr::KEY_KEY_I) {
|
2019-04-19 14:13:58 -07:00
|
|
|
if (m_Engine->KeyIsDown[irr::KEY_LCONTROL]
|
|
|
|
|| m_Engine->KeyIsDown[irr::KEY_RCONTROL]) {
|
|
|
|
// IGUIContextMenu* textureInterpolationElement = (
|
|
|
|
// dynamic_cast<IGUIContextMenu*>(
|
|
|
|
// viewMenu->getElementFromId(
|
|
|
|
// UIC_VIEW_TEXTURE_INTERPOLATION
|
|
|
|
// )
|
|
|
|
// );
|
|
|
|
// )
|
2019-04-19 12:29:30 -07:00
|
|
|
// m_TextureInterpolation = textureInterpolationElement->isItemChecked(UIC_VIEW_TEXTURE_INTERPOLATION);
|
|
|
|
m_TextureInterpolation = m_TextureInterpolation ? false : true;
|
|
|
|
// doesn't work: m_TextureInterpolation = viewMenu->isItemChecked(UIC_VIEW_TEXTURE_INTERPOLATION);
|
|
|
|
m_Engine->setMeshDisplayMode(m_WireframeDisplay, m_Lighting, m_TextureInterpolation);
|
|
|
|
viewMenu->setItemChecked(viewTextureInterpolationIdx, m_TextureInterpolation);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
handled = false;
|
|
|
|
} else if (event.KeyInput.Key == irr::KEY_RIGHT) {
|
2019-04-19 14:13:58 -07:00
|
|
|
if (m_Engine->KeyIsDown[irr::KEY_LCONTROL]
|
|
|
|
|| m_Engine->KeyIsDown[irr::KEY_RCONTROL]) {
|
2019-04-19 12:29:30 -07:00
|
|
|
m_Engine->incrementAnimationFPS(5);
|
2019-03-07 21:52:29 -08:00
|
|
|
}
|
2019-04-19 12:29:30 -07:00
|
|
|
else
|
|
|
|
handled = false;
|
|
|
|
} else if (event.KeyInput.Key == irr::KEY_LEFT) {
|
2019-04-19 14:13:58 -07:00
|
|
|
if (m_Engine->KeyIsDown[irr::KEY_LCONTROL]
|
|
|
|
|| m_Engine->KeyIsDown[irr::KEY_RCONTROL]) {
|
2019-04-19 12:29:30 -07:00
|
|
|
m_Engine->incrementAnimationFPS(-5);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
handled = false;
|
2019-04-11 01:31:04 -07:00
|
|
|
} else if (event.KeyInput.Char == L' ') {
|
2019-03-07 21:52:29 -08:00
|
|
|
m_Engine->toggleAnimation();
|
2019-04-11 01:31:04 -07:00
|
|
|
} else if (event.KeyInput.Key == irr::KEY_LEFT) {
|
2019-04-03 07:35:27 -07:00
|
|
|
if (this->m_Engine->m_LoadedMesh != nullptr) {
|
2019-04-11 01:31:04 -07:00
|
|
|
if (m_Engine->isPlaying)
|
|
|
|
m_Engine->toggleAnimation();
|
2019-04-19 14:13:58 -07:00
|
|
|
this->m_Engine->m_LoadedMesh->setCurrentFrame(
|
|
|
|
round(this->m_Engine->m_LoadedMesh->getFrameNr()) - 1
|
|
|
|
);
|
|
|
|
this->playbackSetFrameEditBox->setText(
|
|
|
|
Utility::toWstring(
|
|
|
|
this->m_Engine->m_LoadedMesh->getFrameNr()
|
|
|
|
).c_str()
|
|
|
|
);
|
2019-04-03 07:35:27 -07:00
|
|
|
}
|
2019-04-11 01:31:04 -07:00
|
|
|
} else if (event.KeyInput.Key == irr::KEY_RIGHT) {
|
2019-04-03 07:35:27 -07:00
|
|
|
if (this->m_Engine->m_LoadedMesh != nullptr) {
|
2019-04-11 01:31:04 -07:00
|
|
|
if (m_Engine->isPlaying)
|
|
|
|
m_Engine->toggleAnimation();
|
2019-04-19 14:13:58 -07:00
|
|
|
this->m_Engine->m_LoadedMesh->setCurrentFrame(
|
|
|
|
round(this->m_Engine->m_LoadedMesh->getFrameNr()) + 1
|
|
|
|
);
|
|
|
|
this->playbackSetFrameEditBox->setText(
|
|
|
|
Utility::toWstring(
|
|
|
|
this->m_Engine->m_LoadedMesh->getFrameNr()
|
|
|
|
).c_str()
|
|
|
|
);
|
2019-04-03 07:35:27 -07:00
|
|
|
}
|
|
|
|
}
|
2019-04-19 12:29:30 -07:00
|
|
|
else
|
|
|
|
handled = false;
|
2019-03-07 21:52:29 -08:00
|
|
|
// std::wcerr << "Char: " << event.KeyInput.Char << endl;
|
|
|
|
}
|
2019-03-10 06:55:31 -07:00
|
|
|
m_Engine->KeyIsDown[event.KeyInput.Key] = event.KeyInput.PressedDown;
|
2019-03-07 21:52:29 -08:00
|
|
|
return true;
|
2019-04-11 01:31:04 -07:00
|
|
|
} else if (event.EventType == EET_MOUSE_INPUT_EVENT) {
|
2019-04-19 12:29:30 -07:00
|
|
|
// debug() << "EET_MOUSE_INPUT_EVENT..." << endl;
|
|
|
|
handled = true; // set to false below if not handled
|
|
|
|
// TODO: improve this copypasta (or elsewhere use states 1 and 3 as
|
|
|
|
// events, and add 1 as "handled" (or set back to 0 for no drag feature)
|
|
|
|
// as intended for drag or long press handling).
|
2019-04-11 01:31:04 -07:00
|
|
|
switch (event.MouseInput.Event) {
|
2019-03-09 05:56:23 -08:00
|
|
|
case EMIE_LMOUSE_LEFT_UP:
|
2019-04-11 01:31:04 -07:00
|
|
|
if (m_Engine->LMouseState == 2) {
|
2019-03-10 06:55:31 -07:00
|
|
|
m_Engine->LMouseState = 3;
|
2019-03-09 05:56:23 -08:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case EMIE_LMOUSE_PRESSED_DOWN:
|
2019-04-11 01:31:04 -07:00
|
|
|
if (m_Engine->LMouseState == 0) {
|
2019-03-10 06:55:31 -07:00
|
|
|
m_Engine->LMouseState = 1;
|
2019-03-09 05:56:23 -08:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case EMIE_RMOUSE_LEFT_UP:
|
2019-04-11 01:31:04 -07:00
|
|
|
if (m_Engine->RMouseState == 2) {
|
2019-03-10 06:55:31 -07:00
|
|
|
m_Engine->RMouseState = 3;
|
2019-03-09 05:56:23 -08:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case EMIE_RMOUSE_PRESSED_DOWN:
|
2019-04-11 01:31:04 -07:00
|
|
|
if (m_Engine->RMouseState == 0) {
|
2019-03-10 06:55:31 -07:00
|
|
|
m_Engine->RMouseState = 1;
|
2019-03-09 05:56:23 -08:00
|
|
|
}
|
|
|
|
break;
|
2019-04-19 12:29:30 -07:00
|
|
|
default:
|
|
|
|
handled = false;
|
2019-03-09 05:56:23 -08:00
|
|
|
}
|
2010-04-21 07:48:36 -07:00
|
|
|
}
|
2019-04-19 12:29:30 -07:00
|
|
|
return handled;
|
2010-04-21 07:48:36 -07:00
|
|
|
}
|