From 20c18802f3373f8b1f44de2c392caa33bf9fe079 Mon Sep 17 00:00:00 2001 From: poikilos <7557867+poikilos@users.noreply.github.com> Date: Mon, 22 Mar 2021 12:21:01 -0400 Subject: [PATCH] Block zooming in load/save. Output more event info (working on recent menu items). --- UserInterface.cpp | 101 ++++++++++++++++++++++++++++++++++++++-------- Utility.cpp | 4 ++ View.cpp | 12 ++++-- View.h | 1 + 4 files changed, 99 insertions(+), 19 deletions(-) diff --git a/UserInterface.cpp b/UserInterface.cpp index c78bde4..804ba9e 100644 --- a/UserInterface.cpp +++ b/UserInterface.cpp @@ -2,6 +2,8 @@ #include "Engine.h" #include "Utility.h" #include "UserInterface.h" +// class View : public irr::IEventReceiver; // avoid incomplete type when accessing member of this type from friend class +#include "View.h" // avoid incomplete type when accessing member of this type from friend class #include #include @@ -27,6 +29,7 @@ using namespace std; namespace fs = std::experimental::filesystem; // namespace fs = std::filesystem; // doesn't work (not a namespace in gcc's C++17) + const u32 UserInterface::UIC_FILE_RECENT_FIRST = UIE_RECENTMENU + 1; // PRIVATE @@ -469,7 +472,14 @@ bool UserInterface::handleMenuItemPressed(const SEvent::SGUIEvent* ge) this->openRecent(callerID, ge->Caller->getText()); } else { - cerr << "Unknown caller id: " << callerID << " Text:" << ge->Caller->getText() << endl; + cerr << "Unknown caller id: " << callerID << " Text:" << Utility::toString(ge->Caller->getText()) << endl; + if (this->recentIndices.size() < 1) { + cerr << "- recentIndices.size(): " << recentIndices.size() << endl; + } + // range based for loop requires C++11 or higher: + for(irr::u32 i : this->recentIndices) { + cerr << " - " << i << endl; + } handled = false; } @@ -898,7 +908,8 @@ void UserInterface::openRecent(s32 menuID, std::wstring menuText) // IEventReceiver bool UserInterface::OnEvent(const SEvent& event) { - // Events arriving here should be destined for us + // Note EventHandler::OnEvent calls other handlers for + // Certain event types (See ERT_3DVIEW there for instance). bool handled = false; if (event.EventType == EET_USER_EVENT) { // debug() << "EET_USER_EVENT..." << endl; @@ -916,19 +927,6 @@ bool UserInterface::OnEvent(const SEvent& event) s32 callerID = ge->Caller->getID(); switch (ge->EventType) { // See http://irrlicht.sourceforge.net/docu/example009.html - case EGET_ELEMENT_FOCUSED: - break; - case EGET_ELEMENT_HOVERED: - break; - case EGET_ELEMENT_LEFT: - break; - case EGET_MENU_ITEM_SELECTED: - handled = handleMenuItemPressed(ge); - break; - case EGET_SCROLL_BAR_CHANGED: - break; - case EGET_COMBO_BOX_CHANGED: - break; case EGET_BUTTON_CLICKED: switch(callerID) { case UIE_PLAYBACKSTARTSTOPBUTTON: @@ -946,6 +944,7 @@ bool UserInterface::OnEvent(const SEvent& event) break; } case EGET_FILE_SELECTED: + this->m_Engine->m_View->m_MouseUser = ""; switch(callerID) { case UIE_LOADFILEDIALOG: { @@ -1047,9 +1046,79 @@ bool UserInterface::OnEvent(const SEvent& event) handled = false; break; } + case EGET_MESSAGEBOX_YES: + this->m_Engine->m_View->m_MouseUser = ""; + break; + case EGET_MESSAGEBOX_NO: + this->m_Engine->m_View->m_MouseUser = ""; + break; + case EGET_MESSAGEBOX_OK: + this->m_Engine->m_View->m_MouseUser = ""; + break; + case EGET_MESSAGEBOX_CANCEL: + this->m_Engine->m_View->m_MouseUser = ""; + break; + case EGET_FILE_CHOOSE_DIALOG_CANCELLED: + // ^ 12 usually + this->m_Engine->m_View->m_MouseUser = ""; + break; + case EGET_ELEMENT_FOCUS_LOST: + // ^ 0 usually + switch (callerID) { + case UIE_LOADFILEDIALOG: + this->m_Engine->m_View->m_MouseUser = ""; + break; + case UIE_SAVEFILEDIALOG: + this->m_Engine->m_View->m_MouseUser = ""; + break; + default: + break; + } + debug() << callerID << " lost focus." << std::endl; + handled = false; + break; + case EGET_ELEMENT_FOCUSED: + switch (callerID) { + case UIE_LOADFILEDIALOG: + this->m_Engine->m_View->m_MouseUser = "UIE_LOADFILEDIALOG"; + break; + case UIE_SAVEFILEDIALOG: + this->m_Engine->m_View->m_MouseUser = "UIE_SAVEFILEDIALOG"; + break; + default: + break; + } + debug() << callerID << " got focus." << std::endl; + handled = false; + break; + case EGET_ELEMENT_HOVERED: + debug() << "hovered over " << callerID << "." << std::endl; + handled = false; + break; + case EGET_ELEMENT_LEFT: + debug() << "left " << callerID << "." << std::endl; + handled = false; + break; + case EGET_MENU_ITEM_SELECTED: + handled = handleMenuItemPressed(ge); + break; + case EGET_SCROLL_BAR_CHANGED: + handled = false; + break; + case EGET_COMBO_BOX_CHANGED: + handled = false; + break; + case EGET_ELEMENT_CLOSED: + debug() << "closed " << callerID << "." << std::endl; + handled = false; + break; + case EGET_DIRECTORY_SELECTED: + this->m_Engine->m_View->m_MouseUser = ""; + handled = false; + break; default: // EET_MOUSE_INPUT_EVENT EET_KEY_INPUT_EVENT EET_JOYSTICK_INPUT_EVENT - cerr << "[UserInterface] (verbose message) event.GUIEvent.EventType " << ge->EventType << " (See EGET_*) is not handled (event.EventType is EET_GUI_EVENT)." << std::endl; + cerr << "[UserInterface] (verbose message) event.GUIEvent.EventType " << ge->EventType << " (See EGET_* in irrlicht/IEventReciever.h) is not handled (event.EventType is EET_GUI_EVENT)." << std::endl; handled = false; break; } diff --git a/Utility.cpp b/Utility.cpp index 4aacd97..5d91989 100644 --- a/Utility.cpp +++ b/Utility.cpp @@ -506,11 +506,15 @@ void Utility::create_directory(const std::string &path) { std::string Utility::toString(int val) { return std::to_string(val); + // The only throw is std::bad_alloc according to + // } std::string Utility::toString(irr::f32 val) { return std::to_string(val); + // The only throw is std::bad_alloc according to + // } std::string Utility::ltrim(const std::string& s) diff --git a/View.cpp b/View.cpp index 0202b0a..642ab96 100644 --- a/View.cpp +++ b/View.cpp @@ -90,7 +90,8 @@ View::View(Engine* engine) m_Engine = engine; m_LastMousePosition = new vector2d(); m_RotMouse = false; - + m_Shift = false; + this->m_MouseUser = ""; // m_Pitch = PI; // Initial camera values: see Engine::setupScene @@ -171,7 +172,10 @@ bool View::OnEvent(const SEvent& event) // Handle mouse event const SEvent::SMouseInput* mouseEvent = &(event.MouseInput); - + if (this->m_MouseUser != "") { + std::cerr << "[View] The mouse is being used by " << this->m_MouseUser << std::endl; + return false; + } if (mouseEvent->Event == EMIE_MMOUSE_PRESSED_DOWN) { m_RotMouse = true; m_LastMousePosition->X = mouseEvent->X; @@ -218,7 +222,9 @@ bool View::OnEvent(const SEvent& event) m_CameraDistance /= 2; } setNewCameraPosition(); - debug() << "m_CamPos: " << m_Engine->m_CamPos.X + debug() << "View got the event and used event.MouseInput." + // << " event.GUIEvent.Caller: " << callerID // not avail in Irrlicht (Use this->m_MouseUser instead) + << ", m_CamPos: " << m_Engine->m_CamPos.X << "," << m_Engine->m_CamPos.Y << " m_CamTarget: " << m_Engine->m_CamTarget.X << "," << m_Engine->m_CamTarget.Y << endl; diff --git a/View.h b/View.h index ebe4d6d..5764f4f 100644 --- a/View.h +++ b/View.h @@ -25,6 +25,7 @@ public: void setCameraDistance(float cameraDistance); bool zUp(); bool m_Shift; + std::string m_MouseUser; // IEventReceiver virtual bool OnEvent(const irr::SEvent& event);