Handle each GUI event type seperately as per Irrlicht documentation...

...Add a scope around cases to fix "error: jump to case label
[-fpermissive]" and provide a separate scope for variables created in
each case. Remove b3view.depend.
master
poikilos 2021-03-22 11:22:21 -04:00
parent 0f03078717
commit 50a9c1916d
3 changed files with 153 additions and 388 deletions

View File

@ -325,8 +325,12 @@ void UserInterface::incrementFrame(f32 frameCount, bool enableRound)
} }
} }
void UserInterface::handleMenuItemPressed(IGUIContextMenu* menu) bool UserInterface::handleMenuItemPressed(const SEvent::SGUIEvent* ge)
{ {
// ^ formerly ...(IGUIContextMenu* menu): called as ...(static_cast<IGUIContextMenu*>(ge->Caller)); protytyped as ...(irr::gui::IGUIContextMenu* menu)
bool handled = true;
IGUIContextMenu* menu = static_cast<IGUIContextMenu*>(ge->Caller);
s32 callerID = ge->Caller->getID();
s32 selected = menu->getSelectedItem(); s32 selected = menu->getSelectedItem();
if (selected > -1) { if (selected > -1) {
s32 id = menu->getItemCommandId(static_cast<u32>(selected)); s32 id = menu->getItemCommandId(static_cast<u32>(selected));
@ -458,10 +462,22 @@ void UserInterface::handleMenuItemPressed(IGUIContextMenu* menu)
); );
break; break;
default: default:
cerr << "[UserInterface::handleMenuItemPressed] Unknown caller id: " << id << endl; // if ((ge->Caller->getID() >= this->m_file_recent_first_idx)
// && (ge->Caller->getID() <= m_file_recent_last_idx)) {
if (std::find(this->recentIndices.begin(), this->recentIndices.end(), ge->Caller->getID()) != this->recentIndices.end()) {
cerr << "Recent item id: " << callerID << endl;
this->openRecent(callerID, ge->Caller->getText());
}
else {
cerr << "Unknown caller id: " << callerID << " Text:" << ge->Caller->getText() << endl;
handled = false;
}
// cerr << "[UserInterface::handleMenuItemPressed] Unknown caller id: " << id << endl;
break; break;
} }
} }
return handled;
} }
void UserInterface::updateSettingsDisplay() void UserInterface::updateSettingsDisplay()
@ -898,161 +914,147 @@ bool UserInterface::OnEvent(const SEvent& event)
handled = true; // set to false below if not handled handled = true; // set to false below if not handled
const SEvent::SGUIEvent* ge = &(event.GUIEvent); const SEvent::SGUIEvent* ge = &(event.GUIEvent);
s32 callerID = ge->Caller->getID(); s32 callerID = ge->Caller->getID();
// TODO: switch (ge->EventType) { switch (ge->EventType) {
// // See http://irrlicht.sourceforge.net/docu/example009.html // See http://irrlicht.sourceforge.net/docu/example009.html
// case EGET_MENU_ITEM_SELECTED: case EGET_ELEMENT_FOCUSED:
// case EGET_SCROLL_BAR_CHANGED: break;
// case EGET_COMBO_BOX_CHANGED: case EGET_ELEMENT_HOVERED:
// case EGET_BUTTON_CLICKED: break;
// switch(callerID) { case EGET_ELEMENT_LEFT:
// case UIE_PLAYBACKSTARTSTOPBUTTON: break;
// default: case EGET_MENU_ITEM_SELECTED:
// cerr << "Unknown button clicked: " << callerID << std::endl; handled = handleMenuItemPressed(ge);
// default: break;
// cerr << "Unknown event.GUIEvent.EventType " << ge->EventType << std::endl; case EGET_SCROLL_BAR_CHANGED:
// break; break;
switch (callerID) { case EGET_COMBO_BOX_CHANGED:
case UIE_FILEMENU: break;
case UIE_RECENTMENU: case EGET_BUTTON_CLICKED:
case UIE_PLAYBACKMENU: switch(callerID) {
case UIE_VIEWMENU: case UIE_PLAYBACKSTARTSTOPBUTTON:
// call handler for all menu related actions this->m_Engine->toggleAnimation();
handleMenuItemPressed(static_cast<IGUIContextMenu*>(ge->Caller)); break;
break; case UIE_PLAYBACKINCREASEBUTTON:
case UIE_LOADFILEDIALOG: this->m_Engine->incrementAnimationFPS(5);
if (ge->EventType == EGET_FILE_SELECTED) { break;
IGUIFileOpenDialog* fileOpenDialog = static_cast<IGUIFileOpenDialog*>(ge->Caller); case UIE_PLAYBACKDECREASEBUTTON:
wstring path = fileOpenDialog->getFileName(); this->m_Engine->incrementAnimationFPS(-5);
bool result = false; break;
wstring extension = Utility::extensionOf(path); default:
if (Utility::toLower(Utility::toString(extension)) == "irr") { cerr << "EGET_BUTTON_CLICKED wasn't expected from ID " << callerID << std::endl;
result = m_Engine->loadScene(fileOpenDialog->getFileName()); handled = false;
break;
} }
else { case EGET_FILE_SELECTED:
result = m_Engine->loadMesh(fileOpenDialog->getFileName()); switch(callerID) {
} case UIE_LOADFILEDIALOG:
if (result) { {
try { IGUIFileOpenDialog* fileOpenDialog = static_cast<IGUIFileOpenDialog*>(ge->Caller);
wstring path = fileOpenDialog->getFileName();
bool result = false;
wstring extension = Utility::extensionOf(path);
if (Utility::toLower(Utility::toString(extension)) == "irr") {
result = m_Engine->loadScene(fileOpenDialog->getFileName());
}
else {
result = m_Engine->loadMesh(fileOpenDialog->getFileName());
}
if (result) {
try {
this->addRecentMenuItem(Utility::toString(path), true); this->addRecentMenuItem(Utility::toString(path), true);
}
catch (const std::runtime_error& ex) {
cerr << ex.what() << std::endl;
break;
}
}
if (!result) {
this->m_Engine->m_Device->getGUIEnvironment()->addMessageBox(
L"Load Mesh", L"The model is inaccessible or not in a compatible format.");
}
} }
catch (const std::runtime_error& ex) {
cerr << ex.what() << std::endl; break;
break; case UIE_SAVEFILEDIALOG:
{
if (m_Engine->m_LoadedMesh != nullptr) {
IGUIFileOpenDialog* fileOpenDialog = static_cast<IGUIFileOpenDialog*>(ge->Caller);
// fileOpenDialog->getFileName()
m_Engine->saveMesh(fileOpenDialog->getDirectoryName(), "", "dae");
}
else {
this->m_Engine->m_Device->getGUIEnvironment()->addMessageBox(
L"Export", L"There is nothing to save.");
}
} }
break;
case UIE_LOADTEXTUREDIALOG:
{
IGUIFileOpenDialog* fileOpenDialog = static_cast<IGUIFileOpenDialog*>(ge->Caller);
m_Engine->loadTexture(fileOpenDialog->getFileName());
}
break;
default:
cerr << "EGET_FILE_SELECTED wasn't expected from ID: " << callerID << std::endl;
handled = false;
break;
} }
if (!result) { case EGET_EDITBOX_ENTER:
this->m_Engine->m_Device->getGUIEnvironment()->addMessageBox( switch (callerID) {
L"Load Mesh", L"The model is inaccessible or not in a compatible format."); case UIE_PLAYBACKSETFRAMEEDITBOX:
} if (this->m_Engine->m_LoadedMesh != nullptr) {
} this->m_Engine->m_LoadedMesh->setCurrentFrame(
break; Utility::toF32(this->playbackSetFrameEditBox->getText())
case UIE_SAVEFILEDIALOG: );
if (ge->EventType == EGET_FILE_SELECTED) { }
if (m_Engine->m_LoadedMesh != nullptr) { break;
IGUIFileOpenDialog* fileOpenDialog = static_cast<IGUIFileOpenDialog*>(ge->Caller); case UIE_PLAYBACKSTARTFRAMEEDITBOX:
// fileOpenDialog->getFileName() if (this->m_Engine->m_LoadedMesh != nullptr) {
m_Engine->saveMesh(fileOpenDialog->getDirectoryName(), "", "dae"); this->m_Engine->m_LoadedMesh->setFrameLoop(
} Utility::toF32(this->playbackStartFrameEditBox->getText()),
else { Utility::toF32(this->playbackEndFrameEditBox->getText())
this->m_Engine->m_Device->getGUIEnvironment()->addMessageBox( );
L"Export", L"There is nothing to save."); }
} break;
} case UIE_PLAYBACKENDFRAMEEDITBOX:
break; if (this->m_Engine->m_LoadedMesh != nullptr) {
this->m_Engine->m_LoadedMesh->setFrameLoop(
case UIE_LOADTEXTUREDIALOG: Utility::toF32(this->playbackStartFrameEditBox->getText()),
if (ge->EventType == EGET_FILE_SELECTED) { Utility::toF32(this->playbackEndFrameEditBox->getText())
IGUIFileOpenDialog* fileOpenDialog = static_cast<IGUIFileOpenDialog*>(ge->Caller); );
m_Engine->loadTexture(fileOpenDialog->getFileName()); }
} break;
break; case UIE_TEXTUREPATHEDITBOX:
if (this->m_Engine->m_LoadedMesh != nullptr) {
case UIE_PLAYBACKSTARTSTOPBUTTON: this->m_Engine->loadTexture(texturePathEditBox->getText());
if (ge->EventType == EGET_BUTTON_CLICKED) { }
this->m_Engine->toggleAnimation(); break;
} case UIE_FPSEDITBOX:
break; if (this->m_Engine->m_LoadedMesh != nullptr) {
this->m_Engine->m_LoadedMesh->setAnimationSpeed(
case UIE_PLAYBACKINCREASEBUTTON: Utility::toF32(this->playbackFPSEditBox->getText())
if (ge->EventType == EGET_BUTTON_CLICKED) { );
this->m_Engine->incrementAnimationFPS(5); }
} break;
break; case UIE_AXISSIZEEDITBOX:
this->m_Engine->m_AxisLength = Utility::toF32(
case UIE_PLAYBACKDECREASEBUTTON: this->axisSizeEditBox->getText()
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) {
this->m_Engine->m_LoadedMesh->setCurrentFrame(
Utility::toF32(this->playbackSetFrameEditBox->getText())
); );
break;
default:
cerr << "EGET_EDITBOX_ENTER isn't processed for ID: " << callerID << std::endl;
handled = false;
break;
} }
} default:
break; // EET_MOUSE_INPUT_EVENT EET_KEY_INPUT_EVENT EET_JOYSTICK_INPUT_EVENT
case UIE_PLAYBACKSTARTFRAMEEDITBOX: cerr << "[UserInterface] (verbose message) event.GUIEvent.EventType " << ge->EventType << " (See EGET_*) is not handled (event.EventType is EET_GUI_EVENT)." << std::endl;
if (ge->EventType == EGET_EDITBOX_ENTER) {
if (this->m_Engine->m_LoadedMesh != nullptr) {
this->m_Engine->m_LoadedMesh->setFrameLoop(
Utility::toF32(this->playbackStartFrameEditBox->getText()),
Utility::toF32(this->playbackEndFrameEditBox->getText())
);
}
}
break;
case UIE_PLAYBACKENDFRAMEEDITBOX:
if (ge->EventType == EGET_EDITBOX_ENTER) {
if (this->m_Engine->m_LoadedMesh != nullptr) {
this->m_Engine->m_LoadedMesh->setFrameLoop(
Utility::toF32(this->playbackStartFrameEditBox->getText()),
Utility::toF32(this->playbackEndFrameEditBox->getText())
);
}
}
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) {
this->m_Engine->m_LoadedMesh->setAnimationSpeed(
Utility::toF32(this->playbackFPSEditBox->getText())
);
}
}
break;
case UIE_AXISSIZEEDITBOX:
if (ge->EventType == EGET_EDITBOX_ENTER) {
this->m_Engine->m_AxisLength = Utility::toF32(
this->axisSizeEditBox->getText()
);
}
break;
case -1:
break;
default:
// if ((ge->Caller->getID() >= this->m_file_recent_first_idx)
// && (ge->Caller->getID() <= m_file_recent_last_idx)) {
if (std::find(this->recentIndices.begin(), this->recentIndices.end(), ge->Caller->getID()) != this->recentIndices.end()) {
cerr << "Recent item id: " << callerID << endl;
this->openRecent(callerID, ge->Caller->getText());
}
else {
cerr << "Unknown caller id: " << callerID << " Text:" << ge->Caller->getText() << endl;
handled = false; handled = false;
} break;
} }
} else if (event.EventType == EET_KEY_INPUT_EVENT) { } else if (event.EventType == EET_KEY_INPUT_EVENT) {
// debug() << "EET_KEY_INPUT_EVENT..." << endl; // debug() << "EET_KEY_INPUT_EVENT..." << endl;
handled = true; // set to false below if not handled handled = true; // set to false below if not handled
@ -1162,6 +1164,8 @@ bool UserInterface::OnEvent(const SEvent& event)
default: default:
handled = false; handled = false;
} }
} else {
cerr << "[UserInterface] (verbose message) event.EventType " << event.EventType << " is ignored." << std::endl;
} }
return handled; return handled;
} }

View File

@ -84,7 +84,7 @@ private:
void displaySaveFileDialog(); void displaySaveFileDialog();
void displayLoadTextureDialog(); void displayLoadTextureDialog();
void incrementFrame(irr::f32 frameCount, bool enableRound); void incrementFrame(irr::f32 frameCount, bool enableRound);
void handleMenuItemPressed(irr::gui::IGUIContextMenu* menu); bool handleMenuItemPressed(const irr::SEvent::SGUIEvent* ge);
void updateSettingsDisplay(); void updateSettingsDisplay();
irr::gui::IGUIWindow* playbackWindow; irr::gui::IGUIWindow* playbackWindow;

View File

@ -1,239 +0,0 @@
# depslib dependency file v1.0
1554970747 source:/opt/b3view/Debug.cpp
"Debug.h"
1616415754 /opt/b3view/Debug.h
<iostream>
1616415912 source:/opt/b3view/Engine.cpp
<string>
<filesystem>
"Engine.h"
"UserInterface.h"
"Utility.h"
"View.h"
<cerrno>
<unistd.h>
1613679774 /opt/b3view/Engine.h
<iostream>
<sstream>
<string>
<vector>
"EventHandler.h"
"extlib/CGUITTFont.h"
<irrlicht/irrlicht.h>
"settings.h"
1554970974 /opt/b3view/EventHandler.h
<iostream>
<map>
<utility>
"Debug.h"
<irrlicht/irrlicht.h>
1616368477 /opt/b3view/extlib/CGUITTFont.h
<ft2build.h>
<irrlicht/irrlicht.h>
1613661547 /opt/b3view/settings.h
<string>
<map>
<irrlicht/irrlicht.h>
1613683794 /opt/b3view/UserInterface.h
"extlib/CGUITTFont.h"
<irrlicht/irrlicht.h>
<string>
<vector>
1613676318 /opt/b3view/Utility.h
<irrlicht/irrlicht.h>
<ctime>
<string>
<vector>
1555700256 /opt/b3view/View.h
<irrlicht/irrlicht.h>
1613660813 source:/opt/b3view/EventHandler.cpp
"EventHandler.h"
"Utility.h"
<string.h>
<sys/stat.h>
<sys/types.h>
1554967184 source:/opt/b3view/extlib/CGUITTFont.cpp
<assert.h>
<iostream>
<irrlicht/irrlicht.h>
"CGUITTFont.h"
1562175368 source:/opt/b3view/main.cpp
<malloc.h>
<stdlib.h>
<string.h>
"Engine.h"
<Windows.h>
1616415840 source:/opt/b3view/settings.cpp
"Utility.h"
"settings.h"
<fstream>
<iostream>
<vector>
<algorithm>
<assert.h>
1616415979 source:/opt/b3view/UserInterface.cpp
"Debug.h"
"Engine.h"
"Utility.h"
"UserInterface.h"
<algorithm>
<iostream>
<string>
<experimental/filesystem>
1613676405 source:/opt/b3view/Utility.cpp
"Debug.h"
"Utility.h"
<algorithm>
<clocale>
<cmath>
<cwctype>
<iostream>
<filesystem>
<locale>
<sstream>
<string>
<vector>
<assert.h>
<sys/stat.h>
<experimental/filesystem>
1613676471 source:/opt/b3view/View.cpp
"Engine.h"
"Utility.h"
"View.h"
<iostream>
1554970747 source:/home/owner/git/b3view/Debug.cpp
"Debug.h"
1616415754 /home/owner/git/b3view/Debug.h
<iostream>
1613660813 source:/home/owner/git/b3view/EventHandler.cpp
"EventHandler.h"
"Utility.h"
<string.h>
<sys/stat.h>
<sys/types.h>
1554970974 /home/owner/git/b3view/EventHandler.h
<iostream>
<map>
<utility>
"Debug.h"
<irrlicht/irrlicht.h>
1613676318 /home/owner/git/b3view/Utility.h
<irrlicht/irrlicht.h>
<ctime>
<string>
<vector>
1616417794 source:/home/owner/git/b3view/extlib/CGUITTFont.cpp
<assert.h>
<iostream>
<irrlicht/irrlicht.h>
"CGUITTFont.h"
1616368477 /home/owner/git/b3view/extlib/CGUITTFont.h
<ft2build.h>
<irrlicht/irrlicht.h>
1562175368 source:/home/owner/git/b3view/main.cpp
<malloc.h>
<stdlib.h>
<string.h>
"Engine.h"
<Windows.h>
1613679774 /home/owner/git/b3view/Engine.h
<iostream>
<sstream>
<string>
<vector>
"EventHandler.h"
"extlib/CGUITTFont.h"
<irrlicht/irrlicht.h>
"settings.h"
1613661547 /home/owner/git/b3view/settings.h
<string>
<map>
<irrlicht/irrlicht.h>
1616420536 source:/home/owner/git/b3view/settings.cpp
"Utility.h"
"settings.h"
<fstream>
<iostream>
<vector>
<algorithm>
<assert.h>
1613676405 source:/home/owner/git/b3view/Utility.cpp
"Debug.h"
"Utility.h"
<algorithm>
<clocale>
<cmath>
<cwctype>
<iostream>
<filesystem>
<locale>
<sstream>
<string>
<vector>
<assert.h>
<sys/stat.h>
<experimental/filesystem>
1613676471 source:/home/owner/git/b3view/View.cpp
"Engine.h"
"Utility.h"
"View.h"
<iostream>
1555700256 /home/owner/git/b3view/View.h
<irrlicht/irrlicht.h>
1616420911 source:/home/owner/git/b3view/Engine.cpp
<string>
<filesystem>
"Engine.h"
"UserInterface.h"
"Utility.h"
"View.h"
<cerrno>
<unistd.h>
1613683794 /home/owner/git/b3view/UserInterface.h
"extlib/CGUITTFont.h"
<irrlicht/irrlicht.h>
<string>
<vector>
1616419830 source:/home/owner/git/b3view/UserInterface.cpp
"Debug.h"
"Engine.h"
"Utility.h"
"UserInterface.h"
<algorithm>
<iostream>
<string>
<experimental/filesystem>