Changeset View
Changeset View
Standalone View
Standalone View
source/gui/CGUI.cpp
Show First 20 Lines • Show All 118 Lines • ▼ Show 20 Lines | InReaction CGUI::HandleEvent(const SDL_Event_* ev) | ||||
// Update m_MousePos (for delayed mouse button events) | // Update m_MousePos (for delayed mouse button events) | ||||
CPos oldMousePos = m_MousePos; | CPos oldMousePos = m_MousePos; | ||||
if (ev->ev.type == SDL_MOUSEBUTTONDOWN || ev->ev.type == SDL_MOUSEBUTTONUP) | if (ev->ev.type == SDL_MOUSEBUTTONDOWN || ev->ev.type == SDL_MOUSEBUTTONUP) | ||||
{ | { | ||||
m_MousePos = CPos((float)ev->ev.button.x / g_GuiScale, (float)ev->ev.button.y / g_GuiScale); | m_MousePos = CPos((float)ev->ev.button.x / g_GuiScale, (float)ev->ev.button.y / g_GuiScale); | ||||
} | } | ||||
// Only one object can be hovered | // Only one object can be hovered | ||||
IGUIObject* pNearest = NULL; | IGUIObject* pNearest = nullptr; | ||||
// TODO Gee: (2004-09-08) Big TODO, don't do the below if the SDL_Event is something like a keypress! | // TODO Gee: (2004-09-08) Big TODO, don't do the below if the SDL_Event is something like a keypress! | ||||
try | try | ||||
{ | { | ||||
PROFILE("mouse events"); | PROFILE("mouse events"); | ||||
// TODO Gee: Optimizations needed! | // TODO Gee: Optimizations needed! | ||||
// these two recursive function are quite overhead heavy. | // these two recursive function are quite overhead heavy. | ||||
// pNearest will after this point at the hovered object, possibly NULL | // pNearest will after this point at the hovered object, possibly nullptr | ||||
pNearest = FindObjectUnderMouse(); | pNearest = FindObjectUnderMouse(); | ||||
// Now we'll call UpdateMouseOver on *all* objects, | // Now we'll call UpdateMouseOver on *all* objects, | ||||
// we'll input the one hovered, and they will each | // we'll input the one hovered, and they will each | ||||
// update their own data and send messages accordingly | // update their own data and send messages accordingly | ||||
GUI<IGUIObject*>::RecurseObject(GUIRR_HIDDEN | GUIRR_GHOST, | GUI<IGUIObject*>::RecurseObject(GUIRR_HIDDEN | GUIRR_GHOST, | ||||
m_BaseObject, &IGUIObject::UpdateMouseOver, pNearest); | m_BaseObject, &IGUIObject::UpdateMouseOver, pNearest); | ||||
▲ Show 20 Lines • Show All 129 Lines • ▼ Show 20 Lines | void CGUI::SendEventToAll(const CStr& EventName) | ||||
// (sending events here) wasn't converting to lower case, | // (sending events here) wasn't converting to lower case, | ||||
// leading to a similar problem. | // leading to a similar problem. | ||||
// now fixed; case is irrelevant since all are converted to lower. | // now fixed; case is irrelevant since all are converted to lower. | ||||
GUI<CStr>::RecurseObject(0, m_BaseObject, | GUI<CStr>::RecurseObject(0, m_BaseObject, | ||||
&IGUIObject::ScriptEvent, EventName.LowerCase()); | &IGUIObject::ScriptEvent, EventName.LowerCase()); | ||||
} | } | ||||
CGUI::CGUI(const shared_ptr<ScriptRuntime>& runtime) | CGUI::CGUI(const shared_ptr<ScriptRuntime>& runtime) | ||||
: m_MouseButtons(0), m_FocusedObject(NULL), m_InternalNameNumber(0) | : m_MouseButtons(0), m_FocusedObject(nullptr), m_InternalNameNumber(0) | ||||
{ | { | ||||
m_ScriptInterface.reset(new ScriptInterface("Engine", "GUIPage", runtime)); | m_ScriptInterface.reset(new ScriptInterface("Engine", "GUIPage", runtime)); | ||||
GuiScriptingInit(*m_ScriptInterface); | GuiScriptingInit(*m_ScriptInterface); | ||||
m_ScriptInterface->LoadGlobalScripts(); | m_ScriptInterface->LoadGlobalScripts(); | ||||
m_BaseObject = new CGUIDummyObject; | m_BaseObject = new CGUIDummyObject; | ||||
m_BaseObject->SetGUI(this); | m_BaseObject->SetGUI(this); | ||||
} | } | ||||
CGUI::~CGUI() | CGUI::~CGUI() | ||||
{ | { | ||||
Destroy(); | Destroy(); | ||||
if (m_BaseObject) | if (m_BaseObject) | ||||
delete m_BaseObject; | delete m_BaseObject; | ||||
} | } | ||||
IGUIObject* CGUI::ConstructObject(const CStr& str) | IGUIObject* CGUI::ConstructObject(const CStr& str) | ||||
{ | { | ||||
if (m_ObjectTypes.count(str) > 0) | if (m_ObjectTypes.count(str) > 0) | ||||
return (*m_ObjectTypes[str])(); | return (*m_ObjectTypes[str])(); | ||||
else | else | ||||
{ | { | ||||
// Error reporting will be handled with the NULL return. | // Error reporting will be handled with the nullptr return. | ||||
return NULL; | return nullptr; | ||||
} | } | ||||
} | } | ||||
void CGUI::Initialize() | void CGUI::Initialize() | ||||
{ | { | ||||
// Add base types! | // Add base types! | ||||
// You can also add types outside the GUI to extend the flexibility of the GUI. | // You can also add types outside the GUI to extend the flexibility of the GUI. | ||||
// Pyrogenesis though will have all the object types inserted from here. | // Pyrogenesis though will have all the object types inserted from here. | ||||
▲ Show 20 Lines • Show All 120 Lines • ▼ Show 20 Lines | |||||
{ | { | ||||
return m_pAllObjects.count(Name) != 0; | return m_pAllObjects.count(Name) != 0; | ||||
} | } | ||||
IGUIObject* CGUI::FindObjectByName(const CStr& Name) const | IGUIObject* CGUI::FindObjectByName(const CStr& Name) const | ||||
{ | { | ||||
map_pObjects::const_iterator it = m_pAllObjects.find(Name); | map_pObjects::const_iterator it = m_pAllObjects.find(Name); | ||||
if (it == m_pAllObjects.end()) | if (it == m_pAllObjects.end()) | ||||
return NULL; | return nullptr; | ||||
else | else | ||||
return it->second; | return it->second; | ||||
} | } | ||||
IGUIObject* CGUI::FindObjectUnderMouse() const | IGUIObject* CGUI::FindObjectUnderMouse() const | ||||
{ | { | ||||
IGUIObject* pNearest = NULL; | IGUIObject* pNearest = nullptr; | ||||
GUI<IGUIObject*>::RecurseObject(GUIRR_HIDDEN | GUIRR_GHOST, m_BaseObject, | GUI<IGUIObject*>::RecurseObject(GUIRR_HIDDEN | GUIRR_GHOST, m_BaseObject, | ||||
&IGUIObject::ChooseMouseOverAndClosest, pNearest); | &IGUIObject::ChooseMouseOverAndClosest, pNearest); | ||||
return pNearest; | return pNearest; | ||||
} | } | ||||
void CGUI::SetFocusedObject(IGUIObject* pObject) | void CGUI::SetFocusedObject(IGUIObject* pObject) | ||||
▲ Show 20 Lines • Show All 909 Lines • ▼ Show 20 Lines | void CGUI::Xeromyces_ReadSprite(XMBElement Element, CXeromyces* pFile) | ||||
CGUISprite* Sprite = new CGUISprite; | CGUISprite* Sprite = new CGUISprite; | ||||
// Get name, we know it exists because of DTD requirements | // Get name, we know it exists because of DTD requirements | ||||
CStr name = Element.GetAttributes().GetNamedItem(pFile->GetAttributeID("name")); | CStr name = Element.GetAttributes().GetNamedItem(pFile->GetAttributeID("name")); | ||||
if (m_Sprites.find(name) != m_Sprites.end()) | if (m_Sprites.find(name) != m_Sprites.end()) | ||||
LOGWARNING("GUI sprite name '%s' used more than once; first definition will be discarded", name.c_str()); | LOGWARNING("GUI sprite name '%s' used more than once; first definition will be discarded", name.c_str()); | ||||
SGUIImageEffects* effects = NULL; | SGUIImageEffects* effects = nullptr; | ||||
for (XMBElement child : Element.GetChildNodes()) | for (XMBElement child : Element.GetChildNodes()) | ||||
{ | { | ||||
CStr ElementName(pFile->GetElementString(child.GetNodeName())); | CStr ElementName(pFile->GetElementString(child.GetNodeName())); | ||||
if (ElementName == "image") | if (ElementName == "image") | ||||
Xeromyces_ReadImage(child, pFile, *Sprite); | Xeromyces_ReadImage(child, pFile, *Sprite); | ||||
else if (ElementName == "effect") | else if (ElementName == "effect") | ||||
▲ Show 20 Lines • Show All 361 Lines • Show Last 20 Lines |
Wildfire Games · Phabricator