2010-04-21 07:48:36 -07:00
|
|
|
#include "UserInterface.h"
|
2019-03-07 10:23:54 -08:00
|
|
|
#include <iostream>
|
2010-04-21 07:48:36 -07:00
|
|
|
|
|
|
|
// PRIVATE
|
|
|
|
void UserInterface::setupUserInterface()
|
|
|
|
{
|
2019-03-07 10:23:54 -08:00
|
|
|
// Menu
|
2010-04-21 07:48:36 -07:00
|
|
|
IGUIContextMenu *menu = m_Gui->addMenu();
|
|
|
|
menu->addItem( L"File", UIE_FILEMENU, true, true );
|
2010-08-16 05:23:20 -07:00
|
|
|
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
|
2010-04-21 07:48:36 -07:00
|
|
|
IGUIContextMenu *fileMenu = menu->getSubMenu( 0 );
|
|
|
|
fileMenu->addItem( L"Load", UIC_FILE_LOAD );
|
2019-03-07 14:17:42 -08:00
|
|
|
fileMenu->addItem( L"LoadTexture", UIC_FILE_LOAD_TEXTURE );
|
2010-04-21 07:48:36 -07:00
|
|
|
fileMenu->addItem( L"Quit", UIC_FILE_QUIT );
|
|
|
|
|
2010-08-16 05:23:20 -07:00
|
|
|
// View Menu
|
|
|
|
IGUIContextMenu *viewMenu = menu->getSubMenu( 1 );
|
|
|
|
viewMenu->addItem( L"Wireframe Mesh", UIC_VIEW_WIREFRAME, true, false, false, true );
|
|
|
|
viewMenu->addItem( L"Lighting",UIC_VIEW_LIGHTING, true, false, true, true );
|
|
|
|
|
2019-03-07 15:07:49 -08:00
|
|
|
// TODO: Playback Control Window
|
|
|
|
// dimension2d<u32> windowSize = m_Engine->m_Driver->getScreenSize();
|
|
|
|
// IGUIWindow *playbackWindow = m_Gui->addWindow(
|
|
|
|
// rect<s32>( vector2d<s32>( windowSize.Width - 4 - 160, 28 ), dimension2d<s32>( 160, 300 )), false, L"Playback", nullptr, UIE_PLAYBACKWINDOW );
|
|
|
|
// playbackWindow->getCloseButton()->setVisible( false );
|
|
|
|
// IGUIButton *playbackStartStopButton = m_Gui->addButton(
|
|
|
|
// rect<s32>( vector2d<s32>( 4, 24 ), dimension2d<s32>( playbackWindow->getClientRect().getWidth() - 8, 24 )),
|
|
|
|
// playbackWindow,
|
|
|
|
// UIE_PLAYBACKSTARTSTOPBUTTON,
|
|
|
|
// L"Start/Stop",
|
|
|
|
// nullptr
|
|
|
|
// );
|
2010-04-23 01:13:44 -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 10:23:54 -08:00
|
|
|
//irrString defines stringc as string<c8>
|
|
|
|
std::string fontPath = "arial.ttf"; // core::stringc has implicit conversion to io::path
|
|
|
|
//if (QFile(fontPath).exists()) {}
|
|
|
|
m_GuiFontFace->load( fontPath.c_str() ); //actually takes `const io::path &`
|
2010-04-23 01:13:44 -07:00
|
|
|
m_GuiFont = new CGUITTFont( m_Gui );
|
2019-03-07 10:23:54 -08:00
|
|
|
assert(m_GuiFontFace != nullptr);
|
|
|
|
if (m_GuiFontFace->face != nullptr) {
|
|
|
|
m_GuiFont->attach( m_GuiFontFace, 14 );
|
|
|
|
m_Gui->getSkin()->setFont( m_GuiFont );
|
|
|
|
}
|
|
|
|
else {
|
2019-03-07 15:07:49 -08:00
|
|
|
cerr << "WARNING: Missing '" << fontPath << "'" << endl;
|
2019-03-07 10:23:54 -08:00
|
|
|
}
|
|
|
|
//}
|
2010-04-21 07:48:36 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void UserInterface::displayLoadFileDialog()
|
|
|
|
{
|
2019-03-07 10:23:54 -08: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()
|
|
|
|
{
|
|
|
|
m_Gui->addFileOpenDialog( L"Select file to load", true, nullptr, UIE_LOADTEXTUREDIALOG );
|
|
|
|
}
|
|
|
|
|
2010-04-23 00:28:59 -07:00
|
|
|
void UserInterface::handleMenuItemPressed( IGUIContextMenu *menu )
|
|
|
|
{
|
|
|
|
s32 id = menu->getItemCommandId( menu->getSelectedItem() );
|
|
|
|
|
|
|
|
switch( id )
|
|
|
|
{
|
|
|
|
case UIC_FILE_LOAD:
|
|
|
|
displayLoadFileDialog();
|
|
|
|
break;
|
|
|
|
|
2019-03-07 14:17:42 -08:00
|
|
|
case UIC_FILE_LOAD_TEXTURE:
|
|
|
|
displayLoadTextureDialog();
|
|
|
|
break;
|
|
|
|
|
2010-04-23 00:28:59 -07:00
|
|
|
case UIC_FILE_QUIT:
|
|
|
|
m_Engine->m_RunEngine = false;
|
|
|
|
break;
|
2010-08-16 05:23:20 -07:00
|
|
|
|
|
|
|
case UIC_VIEW_WIREFRAME:
|
|
|
|
m_WireframeDisplay = m_WireframeDisplay ? false : true;
|
|
|
|
m_Engine->setMeshDisplayMode( m_WireframeDisplay, m_Lighting );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case UIC_VIEW_LIGHTING:
|
|
|
|
m_Lighting = m_Lighting ? false : true;
|
|
|
|
m_Engine->setMeshDisplayMode( m_WireframeDisplay, m_Lighting );
|
|
|
|
break;
|
2010-04-23 00:28:59 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-04-21 07:48:36 -07:00
|
|
|
// PUBLIC
|
|
|
|
UserInterface::UserInterface( Engine *engine )
|
|
|
|
{
|
|
|
|
m_Engine = engine;
|
|
|
|
m_Gui = engine->getGUIEnvironment();
|
|
|
|
|
2010-08-16 05:23:20 -07:00
|
|
|
m_WireframeDisplay = false;
|
|
|
|
m_Lighting = true;
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
IGUIEnvironment * UserInterface::getGUIEnvironment() const
|
|
|
|
{
|
|
|
|
return m_Gui;
|
|
|
|
}
|
|
|
|
|
2010-04-23 00:28:59 -07:00
|
|
|
void UserInterface::drawStatusLine() const
|
2010-04-21 07:48:36 -07:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
// IEventReceiver
|
|
|
|
bool UserInterface::OnEvent( const SEvent &event )
|
|
|
|
{
|
|
|
|
// Events arriving here should be destined for us
|
2019-03-07 10:23:54 -08:00
|
|
|
if( ! (event.EventType == EET_GUI_EVENT) )
|
2010-04-21 07:48:36 -07:00
|
|
|
return false;
|
|
|
|
|
|
|
|
const SEvent::SGUIEvent *ge = &( event.GUIEvent );
|
|
|
|
|
|
|
|
switch( ge->Caller->getID() )
|
|
|
|
{
|
|
|
|
case UIE_FILEMENU:
|
2010-08-16 05:23:20 -07:00
|
|
|
case UIE_VIEWMENU:
|
2010-04-21 07:48:36 -07:00
|
|
|
// call handler for all menu related actions
|
|
|
|
handleMenuItemPressed( static_cast<IGUIContextMenu *>( ge->Caller ));
|
2010-08-16 05:23:20 -07:00
|
|
|
break;
|
2010-04-21 07:48:36 -07:00
|
|
|
|
|
|
|
case UIE_LOADFILEDIALOG:
|
|
|
|
if( ge->EventType == EGET_FILE_SELECTED )
|
|
|
|
{
|
|
|
|
IGUIFileOpenDialog *fileOpenDialog = static_cast<IGUIFileOpenDialog *>( ge->Caller );
|
|
|
|
m_Engine->loadMesh( fileOpenDialog->getFileName() );
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2019-03-07 14:17:42 -08:00
|
|
|
case UIE_LOADTEXTUREDIALOG:
|
|
|
|
if( ge->EventType == EGET_FILE_SELECTED )
|
|
|
|
{
|
|
|
|
IGUIFileOpenDialog *fileOpenDialog = static_cast<IGUIFileOpenDialog *>( ge->Caller );
|
|
|
|
m_Engine->loadTexture( fileOpenDialog->getFileName() );
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2010-04-21 07:48:36 -07:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|