Index: ps/trunk/source/gui/CGUI.h =================================================================== --- ps/trunk/source/gui/CGUI.h +++ ps/trunk/source/gui/CGUI.h @@ -29,6 +29,7 @@ #include "gui/SGUIStyle.h" #include "lib/input.h" #include "maths/Rect.h" +#include "maths/Size2D.h" #include "maths/Vector2D.h" #include "ps/XML/Xeromyces.h" #include "scriptinterface/ScriptForward.h" @@ -177,16 +178,21 @@ /** * Returns the current screen coordinates of the cursor. */ - const CVector2D& GetMousePos() const { return m_MousePos; }; + const CVector2D& GetMousePos() const { return m_MousePos; } /** * Returns the currently pressed mouse buttons. */ - const unsigned int& GetMouseButtons() { return m_MouseButtons; }; + const unsigned int& GetMouseButtons() { return m_MouseButtons; } const SGUIScrollBarStyle* GetScrollBarStyle(const CStr& style) const; /** + * Returns the current GUI window size. + */ + CSize2D GetWindowSize() const; + + /** * The GUI needs to have all object types inputted and * their constructors. Also it needs to associate a type * by a string name of the type. Index: ps/trunk/source/gui/CGUI.cpp =================================================================== --- ps/trunk/source/gui/CGUI.cpp +++ ps/trunk/source/gui/CGUI.cpp @@ -419,6 +419,11 @@ return pNearest; } +CSize2D CGUI::GetWindowSize() const +{ + return CSize2D{static_cast(g_xres) / g_GuiScale, static_cast(g_yres) / g_GuiScale}; +} + void CGUI::SetFocusedObject(IGUIObject* pObject) { if (pObject == m_FocusedObject) Index: ps/trunk/source/gui/ObjectBases/IGUIObject.cpp =================================================================== --- ps/trunk/source/gui/ObjectBases/IGUIObject.cpp +++ ps/trunk/source/gui/ObjectBases/IGUIObject.cpp @@ -25,7 +25,6 @@ #include "gui/Scripting/JSInterface_GUIProxy.h" #include "js/Conversions.h" #include "ps/CLogger.h" -#include "ps/GameSetup/Config.h" #include "ps/Profile.h" #include "scriptinterface/Object.h" #include "scriptinterface/ScriptContext.h" @@ -208,7 +207,7 @@ if (!m_Absolute && m_pParent && !IsRootObject()) m_CachedActualSize = m_Size->GetSize(m_pParent->m_CachedActualSize); else - m_CachedActualSize = m_Size->GetSize(CRect(0.f, 0.f, g_xres / g_GuiScale, g_yres / g_GuiScale)); + m_CachedActualSize = m_Size->GetSize(CRect(m_pGUI.GetWindowSize())); // In a few cases, GUI objects have to resize to fill the screen // but maintain a constant aspect ratio. Index: ps/trunk/source/gui/ObjectTypes/CDropDown.cpp =================================================================== --- ps/trunk/source/gui/ObjectTypes/CDropDown.cpp +++ ps/trunk/source/gui/ObjectTypes/CDropDown.cpp @@ -348,9 +348,7 @@ void CDropDown::SetupListRect() { - extern int g_yres; - extern float g_GuiScale; - const float yres = g_yres / g_GuiScale; + const CSize2D windowSize = m_pGUI.GetWindowSize(); if (m_ItemsYPositions.empty()) { @@ -362,13 +360,13 @@ else if (m_ItemsYPositions.back() > m_DropDownSize) { // Place items below if at least some items can be placed below - if (m_CachedActualSize.bottom + m_DropDownBuffer + m_DropDownSize <= yres) + if (m_CachedActualSize.bottom + m_DropDownBuffer + m_DropDownSize <= windowSize.Height) m_CachedListRect = CRect(m_CachedActualSize.left, m_CachedActualSize.bottom + m_DropDownBuffer, m_CachedActualSize.right, m_CachedActualSize.bottom + m_DropDownBuffer + m_DropDownSize); - else if ((m_ItemsYPositions.size() > m_MinimumVisibleItems && yres - m_CachedActualSize.bottom - m_DropDownBuffer >= m_ItemsYPositions[m_MinimumVisibleItems]) || - m_CachedActualSize.top < yres - m_CachedActualSize.bottom) + else if ((m_ItemsYPositions.size() > m_MinimumVisibleItems && windowSize.Height - m_CachedActualSize.bottom - m_DropDownBuffer >= m_ItemsYPositions[m_MinimumVisibleItems]) || + m_CachedActualSize.top < windowSize.Height - m_CachedActualSize.bottom) m_CachedListRect = CRect(m_CachedActualSize.left, m_CachedActualSize.bottom + m_DropDownBuffer, - m_CachedActualSize.right, yres); + m_CachedActualSize.right, windowSize.Height); // Not enough space below, thus place items above else m_CachedListRect = CRect(m_CachedActualSize.left, std::max(0.f, m_CachedActualSize.top - m_DropDownBuffer - m_DropDownSize), @@ -379,18 +377,18 @@ else { // Enough space below, no scrollbar needed - if (m_CachedActualSize.bottom + m_DropDownBuffer + m_ItemsYPositions.back() <= yres) + if (m_CachedActualSize.bottom + m_DropDownBuffer + m_ItemsYPositions.back() <= windowSize.Height) { m_CachedListRect = CRect(m_CachedActualSize.left, m_CachedActualSize.bottom + m_DropDownBuffer, m_CachedActualSize.right, m_CachedActualSize.bottom + m_DropDownBuffer + m_ItemsYPositions.back()); m_HideScrollBar = true; } // Enough space below for some items, but not all, so place items below and use a scrollbar - else if ((m_ItemsYPositions.size() > m_MinimumVisibleItems && yres - m_CachedActualSize.bottom - m_DropDownBuffer >= m_ItemsYPositions[m_MinimumVisibleItems]) || - m_CachedActualSize.top < yres - m_CachedActualSize.bottom) + else if ((m_ItemsYPositions.size() > m_MinimumVisibleItems && windowSize.Height - m_CachedActualSize.bottom - m_DropDownBuffer >= m_ItemsYPositions[m_MinimumVisibleItems]) || + m_CachedActualSize.top < windowSize.Height - m_CachedActualSize.bottom) { m_CachedListRect = CRect(m_CachedActualSize.left, m_CachedActualSize.bottom + m_DropDownBuffer, - m_CachedActualSize.right, yres); + m_CachedActualSize.right, windowSize.Height); m_HideScrollBar = false; } // Not enough space below, thus place items above. Hide the scrollbar accordingly Index: ps/trunk/source/gui/ObjectTypes/CTooltip.cpp =================================================================== --- ps/trunk/source/gui/ObjectTypes/CTooltip.cpp +++ ps/trunk/source/gui/ObjectTypes/CTooltip.cpp @@ -91,22 +91,30 @@ } - // Reposition the tooltip if it's falling off the screen: - - extern int g_xres, g_yres; - extern float g_GuiScale; - float screenw = g_xres / g_GuiScale; - float screenh = g_yres / g_GuiScale; + // Reposition the tooltip if it's falling off in the GUI window. + const CSize2D windowSize = m_pGUI.GetWindowSize(); if (size.pixel.top < 0.f) - size.pixel.bottom -= size.pixel.top, size.pixel.top = 0.f; - else if (size.pixel.bottom > screenh) - size.pixel.top -= (size.pixel.bottom-screenh), size.pixel.bottom = screenh; + { + size.pixel.bottom -= size.pixel.top; + size.pixel.top = 0.f; + } + else if (size.pixel.bottom > windowSize.Height) + { + size.pixel.top -= size.pixel.bottom - windowSize.Height; + size.pixel.bottom = windowSize.Height; + } if (size.pixel.left < 0.f) - size.pixel.right -= size.pixel.left, size.pixel.left = 0.f; - else if (size.pixel.right > screenw) - size.pixel.left -= (size.pixel.right-screenw), size.pixel.right = screenw; + { + size.pixel.right -= size.pixel.left; + size.pixel.left = 0.f; + } + else if (size.pixel.right > windowSize.Width) + { + size.pixel.left -= size.pixel.right - windowSize.Width; + size.pixel.right = windowSize.Width; + } m_Size.Set(size, true); }