Changeset View
Changeset View
Standalone View
Standalone View
source/gui/CGUI.cpp
Show All 36 Lines | |||||
#include "maths/Size2D.h" | #include "maths/Size2D.h" | ||||
#include "ps/CLogger.h" | #include "ps/CLogger.h" | ||||
#include "ps/Filesystem.h" | #include "ps/Filesystem.h" | ||||
#include "ps/GameSetup/Config.h" | #include "ps/GameSetup/Config.h" | ||||
#include "ps/Globals.h" | #include "ps/Globals.h" | ||||
#include "ps/Hotkey.h" | #include "ps/Hotkey.h" | ||||
#include "ps/Profile.h" | #include "ps/Profile.h" | ||||
#include "ps/Pyrogenesis.h" | #include "ps/Pyrogenesis.h" | ||||
#include "ps/VideoMode.h" | |||||
#include "ps/XML/Xeromyces.h" | #include "ps/XML/Xeromyces.h" | ||||
#include "scriptinterface/ScriptContext.h" | #include "scriptinterface/ScriptContext.h" | ||||
#include "scriptinterface/ScriptInterface.h" | #include "scriptinterface/ScriptInterface.h" | ||||
#include <string> | #include <string> | ||||
#include <unordered_map> | #include <unordered_map> | ||||
#include <unordered_set> | #include <unordered_set> | ||||
▲ Show 20 Lines • Show All 96 Lines • ▼ Show 20 Lines | if (it != m_HotkeyObjects.end()) | ||||
} | } | ||||
} | } | ||||
else if (ev->ev.type == SDL_MOUSEMOTION) | else if (ev->ev.type == SDL_MOUSEMOTION) | ||||
{ | { | ||||
// Yes the mouse position is stored as float to avoid | // Yes the mouse position is stored as float to avoid | ||||
// constant conversions when operating in a | // constant conversions when operating in a | ||||
// float-based environment. | // float-based environment. | ||||
m_MousePos = CVector2D((float)ev->ev.motion.x / g_GuiScale, (float)ev->ev.motion.y / g_GuiScale); | m_MousePos = CVector2D((float)ev->ev.motion.x / g_VideoMode.GetScale(), (float)ev->ev.motion.y / g_VideoMode.GetScale()); | ||||
SGUIMessage msg(GUIM_MOUSE_MOTION); | SGUIMessage msg(GUIM_MOUSE_MOTION); | ||||
m_BaseObject->RecurseObject(&IGUIObject::IsHiddenOrGhost, &IGUIObject::HandleMessage, msg); | m_BaseObject->RecurseObject(&IGUIObject::IsHiddenOrGhost, &IGUIObject::HandleMessage, msg); | ||||
} | } | ||||
// Update m_MouseButtons. (BUTTONUP is handled later.) | // Update m_MouseButtons. (BUTTONUP is handled later.) | ||||
else if (ev->ev.type == SDL_MOUSEBUTTONDOWN) | else if (ev->ev.type == SDL_MOUSEBUTTONDOWN) | ||||
{ | { | ||||
switch (ev->ev.button.button) | switch (ev->ev.button.button) | ||||
{ | { | ||||
case SDL_BUTTON_LEFT: | case SDL_BUTTON_LEFT: | ||||
case SDL_BUTTON_RIGHT: | case SDL_BUTTON_RIGHT: | ||||
case SDL_BUTTON_MIDDLE: | case SDL_BUTTON_MIDDLE: | ||||
m_MouseButtons |= Bit<unsigned int>(ev->ev.button.button); | m_MouseButtons |= Bit<unsigned int>(ev->ev.button.button); | ||||
break; | break; | ||||
default: | default: | ||||
break; | break; | ||||
} | } | ||||
} | } | ||||
// Update m_MousePos (for delayed mouse button events) | // Update m_MousePos (for delayed mouse button events) | ||||
CVector2D oldMousePos = m_MousePos; | CVector2D 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 = CVector2D((float)ev->ev.button.x / g_GuiScale, (float)ev->ev.button.y / g_GuiScale); | m_MousePos = CVector2D((float)ev->ev.button.x / g_VideoMode.GetScale(), (float)ev->ev.button.y / g_VideoMode.GetScale()); | ||||
} | } | ||||
// Allow the focused object to pre-empt regular GUI events. | // Allow the focused object to pre-empt regular GUI events. | ||||
if (GetFocusedObject()) | if (GetFocusedObject()) | ||||
ret = GetFocusedObject()->PreemptEvent(ev); | ret = GetFocusedObject()->PreemptEvent(ev); | ||||
// Only one object can be hovered | // Only one object can be hovered | ||||
// pNearest will after this point at the hovered object, possibly nullptr | // pNearest will after this point at the hovered object, possibly nullptr | ||||
▲ Show 20 Lines • Show All 224 Lines • ▼ Show 20 Lines | |||||
{ | { | ||||
IGUIObject* pNearest = nullptr; | IGUIObject* pNearest = nullptr; | ||||
m_BaseObject->RecurseObject(&IGUIObject::IsHiddenOrGhost, &IGUIObject::ChooseMouseOverAndClosest, pNearest); | m_BaseObject->RecurseObject(&IGUIObject::IsHiddenOrGhost, &IGUIObject::ChooseMouseOverAndClosest, pNearest); | ||||
return pNearest; | return pNearest; | ||||
} | } | ||||
CSize2D CGUI::GetWindowSize() const | CSize2D CGUI::GetWindowSize() const | ||||
{ | { | ||||
return CSize2D{static_cast<float>(g_xres) / g_GuiScale, static_cast<float>(g_yres) / g_GuiScale}; | return CSize2D{static_cast<float>(g_xres) / g_VideoMode.GetScale(), static_cast<float>(g_yres) / g_VideoMode.GetScale() }; | ||||
} | } | ||||
void CGUI::SetFocusedObject(IGUIObject* pObject) | void CGUI::SetFocusedObject(IGUIObject* pObject) | ||||
{ | { | ||||
if (pObject == m_FocusedObject) | if (pObject == m_FocusedObject) | ||||
return; | return; | ||||
if (m_FocusedObject) | if (m_FocusedObject) | ||||
▲ Show 20 Lines • Show All 884 Lines • Show Last 20 Lines |
Wildfire Games · Phabricator