2010-04-21 07:48:36 -07:00
|
|
|
#include "UserInterface.h"
|
|
|
|
|
|
|
|
// PRIVATE
|
|
|
|
void UserInterface::setupUserInterface()
|
|
|
|
{
|
2010-04-22 05:16:15 -07:00
|
|
|
// Menu
|
2010-04-21 07:48:36 -07:00
|
|
|
IGUIContextMenu *menu = m_Gui->addMenu();
|
|
|
|
menu->addItem( L"File", UIE_FILEMENU, true, true );
|
|
|
|
|
2010-04-22 05:16:15 -07:00
|
|
|
// File Menu
|
2010-04-21 07:48:36 -07:00
|
|
|
IGUIContextMenu *fileMenu = menu->getSubMenu( 0 );
|
|
|
|
fileMenu->addItem( L"Load", UIC_FILE_LOAD );
|
|
|
|
fileMenu->addItem( L"Quit", UIC_FILE_QUIT );
|
|
|
|
|
2010-04-23 01:13:44 -07:00
|
|
|
// Playback Control Window
|
2010-04-23 02:00:07 -07:00
|
|
|
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", 0, UIE_PLAYBACKWINDOW );
|
2010-04-23 01:13:44 -07:00
|
|
|
playbackWindow->getCloseButton()->setVisible( false );
|
2010-04-23 02:00:07 -07:00
|
|
|
IGUIButton *playbackStartStopButton = m_Gui->addButton(
|
|
|
|
rect<s32>( vector2d<s32>( 4, 24 ), dimension2d<s32>( playbackWindow->getClientRect().getWidth() - 8, 24 )),
|
|
|
|
playbackWindow,
|
|
|
|
UIE_PLAYBACKSTARTSTOPBUTTON,
|
|
|
|
L"Start/Stop",
|
|
|
|
0
|
|
|
|
);
|
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();
|
|
|
|
m_GuiFontFace->load( "arial.ttf" );
|
|
|
|
m_GuiFont = new CGUITTFont( m_Gui );
|
|
|
|
m_GuiFont->attach( m_GuiFontFace, 14 );
|
|
|
|
|
2010-04-21 07:48:36 -07:00
|
|
|
m_Gui->getSkin()->setFont( m_GuiFont );
|
|
|
|
}
|
|
|
|
|
|
|
|
void UserInterface::displayLoadFileDialog()
|
|
|
|
{
|
|
|
|
m_Gui->addFileOpenDialog( L"Select file to load", true, 0, UIE_LOADFILEDIALOG );
|
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
case UIC_FILE_QUIT:
|
|
|
|
m_Engine->m_RunEngine = false;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-04-21 07:48:36 -07:00
|
|
|
// PUBLIC
|
|
|
|
UserInterface::UserInterface( Engine *engine )
|
|
|
|
{
|
|
|
|
m_Engine = engine;
|
|
|
|
m_Gui = engine->getGUIEnvironment();
|
|
|
|
|
|
|
|
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
|
|
|
|
if( ! event.EventType == EET_GUI_EVENT )
|
|
|
|
return false;
|
|
|
|
|
|
|
|
const SEvent::SGUIEvent *ge = &( event.GUIEvent );
|
|
|
|
|
|
|
|
switch( ge->Caller->getID() )
|
|
|
|
{
|
|
|
|
case UIE_FILEMENU:
|
|
|
|
// 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;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|