Index: ps/trunk/source/gui/CButton.cpp =================================================================== --- ps/trunk/source/gui/CButton.cpp +++ ps/trunk/source/gui/CButton.cpp @@ -57,9 +57,6 @@ void CButton::SetupText() { - if (!GetGUI()) - return; - ENSURE(m_GeneratedTexts.size() == 1); CStrW font; Index: ps/trunk/source/gui/CChart.cpp =================================================================== --- ps/trunk/source/gui/CChart.cpp +++ ps/trunk/source/gui/CChart.cpp @@ -116,9 +116,6 @@ { PROFILE3("render chart"); - if (!GetGUI()) - return; - if (m_Series.empty()) return; @@ -210,9 +207,6 @@ void CChart::SetupText() { - if (!GetGUI()) - return; - for (SGUIText* t : m_GeneratedTexts) delete t; m_GeneratedTexts.clear(); Index: ps/trunk/source/gui/CCheckBox.cpp =================================================================== --- ps/trunk/source/gui/CCheckBox.cpp +++ ps/trunk/source/gui/CCheckBox.cpp @@ -66,9 +66,6 @@ void CCheckBox::SetupText() { - if (!GetGUI()) - return; - ENSURE(m_GeneratedTexts.size() == 1); CStrW font; Index: ps/trunk/source/gui/CDropDown.cpp =================================================================== --- ps/trunk/source/gui/CDropDown.cpp +++ ps/trunk/source/gui/CDropDown.cpp @@ -103,7 +103,7 @@ if (!m_Open) break; - CPos mouse = GetMousePos(); + CPos mouse = m_pGUI->GetMousePos(); if (!GetListRect().PointInside(mouse)) break; @@ -205,7 +205,7 @@ } else { - CPos mouse = GetMousePos(); + const CPos& mouse = m_pGUI->GetMousePos(); // If the regular area is pressed, then abort, and close. if (m_CachedActualSize.PointInside(mouse)) @@ -460,24 +460,18 @@ bool CDropDown::MouseOver() { - if(!GetGUI()) - throw PSERROR_GUI_OperationNeedsGUIObject(); - if (m_Open) { CRect rect(m_CachedActualSize.left, std::min(m_CachedActualSize.top, GetListRect().top), m_CachedActualSize.right, std::max(m_CachedActualSize.bottom, GetListRect().bottom)); - return rect.PointInside(GetMousePos()); + return rect.PointInside(m_pGUI->GetMousePos()); } else - return m_CachedActualSize.PointInside(GetMousePos()); + return m_CachedActualSize.PointInside(m_pGUI->GetMousePos()); } void CDropDown::Draw() { - if (!GetGUI()) - return; - float bz = GetBufferedZ(); float dropdown_size, button_width; Index: ps/trunk/source/gui/CGUI.h =================================================================== --- ps/trunk/source/gui/CGUI.h +++ ps/trunk/source/gui/CGUI.h @@ -72,8 +72,6 @@ { NONCOPYABLE(CGUI); - friend class IGUIObject; - private: // Private typedefs using ConstructObjectFunction = IGUIObject* (*)(CGUI*); @@ -162,6 +160,11 @@ void LoadXmlFile(const VfsPath& Filename, boost::unordered_set& Paths); /** + * Return the object which is an ancestor of every other GUI object. + */ + IGUIObject* GetBaseObject() const { return m_BaseObject; }; + + /** * Checks if object exists and return true or false accordingly * * @param Name String name of object @@ -169,7 +172,6 @@ */ bool ObjectExists(const CStr& Name) const; - /** * Returns the GUI object with the desired name, or NULL * if no match is found, @@ -184,6 +186,16 @@ */ IGUIObject* FindObjectUnderMouse() const; + /** + * Returns the current screen coordinates of the cursor. + */ + const CPos& GetMousePos() const { return m_MousePos; }; + + /** + * Returns the currently pressed mouse buttons. + */ + const unsigned int& GetMouseButtons() { return m_MouseButtons; }; + const SGUIScrollBarStyle* GetScrollBarStyle(const CStr& style) const; /** @@ -233,16 +245,25 @@ */ SGUIText GenerateText(const CGUIString& Text, const CStrW& Font, const float& Width, const float& BufferZone, const IGUIObject* pObject = NULL); - /** * Check if an icon exists */ - bool IconExists(const CStr& str) const { return (m_Icons.count(str) != 0); } + bool HasIcon(const CStr& name) const { return (m_Icons.count(name) != 0); } /** * Get Icon (a const reference, can never be changed) */ - const SGUIIcon& GetIcon(const CStr& str) const { return m_Icons.find(str)->second; } + const SGUIIcon& GetIcon(const CStr& name) const { return m_Icons.at(name); } + + /** + * Check if a style exists + */ + bool HasStyle(const CStr& name) const { return (m_Styles.count(name) != 0); } + + /** + * Get Style if it exists, otherwise throws an exception. + */ + const SGUIStyle& GetStyle(const CStr& name) const { return m_Styles.at(name); } /** * Get pre-defined color (if it exists) @@ -253,8 +274,6 @@ shared_ptr GetScriptInterface() { return m_ScriptInterface; }; JS::Value GetGlobalObject() { return m_ScriptInterface->GetGlobalObject(); }; -private: - /** * Updates the object pointers, needs to be called each * time an object has been added or removed. @@ -266,6 +285,7 @@ */ void UpdateObjects(); +private: /** * Adds an object to the GUI's object database * Private, since you can only add objects through @@ -286,12 +306,12 @@ */ IGUIObject* ConstructObject(const CStr& str); +public: /** * Get Focused Object. */ IGUIObject* GetFocusedObject() { return m_FocusedObject; } -public: /** * Change focus to new object. * Will send LOST_FOCUS/GOT_FOCUS messages as appropriate. Index: ps/trunk/source/gui/CImage.cpp =================================================================== --- ps/trunk/source/gui/CImage.cpp +++ ps/trunk/source/gui/CImage.cpp @@ -38,9 +38,6 @@ void CImage::Draw() { - if (!GetGUI()) - return; - float bz = GetBufferedZ(); CGUISpriteInstance* sprite; Index: ps/trunk/source/gui/CInput.cpp =================================================================== --- ps/trunk/source/gui/CInput.cpp +++ ps/trunk/source/gui/CInput.cpp @@ -912,7 +912,7 @@ // Check if we're selecting the scrollbar if (GetScrollBar(0).GetStyle() && multiline) { - if (GetMousePos().x > m_CachedActualSize.right - GetScrollBar(0).GetStyle()->m_Width) + if (m_pGUI->GetMousePos().x > m_CachedActualSize.right - GetScrollBar(0).GetStyle()->m_Width) break; } @@ -1178,9 +1178,6 @@ if (scrollbar && multiline) IGUIScrollBarOwner::Draw(); - if (!GetGUI()) - return; - CStrW font_name_w; CGUIColor color, color_selected; GUI::GetSetting(this, "font", font_name_w); @@ -1907,7 +1904,7 @@ std::list::const_iterator current = m_CharacterPositions.begin(); - CPos mouse = GetMousePos(); + CPos mouse = m_pGUI->GetMousePos(); if (multiline) { Index: ps/trunk/source/gui/CList.cpp =================================================================== --- ps/trunk/source/gui/CList.cpp +++ ps/trunk/source/gui/CList.cpp @@ -71,9 +71,6 @@ void CList::SetupText() { - if (!GetGUI()) - return; - m_Modified = true; CGUIList* pList; GUI::GetSettingPointer(this, "list", pList); @@ -538,8 +535,8 @@ if (scrollbar) scroll = GetScrollBar(0).GetPos(); - CRect rect = GetListRect(); - CPos mouse = GetMousePos(); + const CRect& rect = GetListRect(); + CPos mouse = m_pGUI->GetMousePos(); mouse.y += scroll; // Mouse is over scrollbar Index: ps/trunk/source/gui/COList.cpp =================================================================== --- ps/trunk/source/gui/COList.cpp +++ ps/trunk/source/gui/COList.cpp @@ -41,9 +41,6 @@ void COList::SetupText() { - if (!GetGUI()) - return; - CGUIList* pList; GUI::GetSettingPointer(this, "list", pList); @@ -154,7 +151,7 @@ if (!sortable) return; - CPos mouse = GetMousePos(); + const CPos& mouse = m_pGUI->GetMousePos(); if (!m_CachedActualSize.PointInside(mouse)) return; @@ -321,9 +318,6 @@ if (scrollbar) IGUIScrollBarOwner::Draw(); - if (!GetGUI()) - return; - CRect rect = GetListRect(); CGUISpriteInstance* sprite = NULL; Index: ps/trunk/source/gui/CProgressBar.cpp =================================================================== --- ps/trunk/source/gui/CProgressBar.cpp +++ ps/trunk/source/gui/CProgressBar.cpp @@ -64,9 +64,6 @@ void CProgressBar::Draw() { - if (!GetGUI()) - return; - float bz = GetBufferedZ(); CGUISpriteInstance* sprite_background; Index: ps/trunk/source/gui/CSlider.cpp =================================================================== --- ps/trunk/source/gui/CSlider.cpp +++ ps/trunk/source/gui/CSlider.cpp @@ -83,7 +83,7 @@ } case GUIM_MOUSE_PRESS_LEFT: { - m_Mouse = GetMousePos(); + m_Mouse = m_pGUI->GetMousePos(); m_IsPressed = true; IncrementallyChangeValue((m_Mouse.x - GetButtonRect().CenterPoint().x) * GetSliderRatio()); @@ -100,8 +100,8 @@ m_IsPressed = false; if (m_IsPressed) { - float difference = float(GetMousePos().x - m_Mouse.x) * GetSliderRatio(); - m_Mouse = GetMousePos(); + float difference = float(m_pGUI->GetMousePos().x - m_Mouse.x) * GetSliderRatio(); + m_Mouse = m_pGUI->GetMousePos(); IncrementallyChangeValue(difference); } break; @@ -113,9 +113,6 @@ void CSlider::Draw() { - if (!GetGUI()) - return; - CGUISpriteInstance* sprite; CGUISpriteInstance* sprite_button; int cell_id; Index: ps/trunk/source/gui/CText.cpp =================================================================== --- ps/trunk/source/gui/CText.cpp +++ ps/trunk/source/gui/CText.cpp @@ -198,9 +198,6 @@ // Draw scrollbar IGUIScrollBarOwner::Draw(); - if (!GetGUI()) - return; - CGUISpriteInstance* sprite; int cell_id; bool clip; @@ -251,7 +248,7 @@ for (const SGUIText::SSpriteCall& spritecall : guitext->m_SpriteCalls) { // Check mouse over sprite - if (!spritecall.m_Area.PointInside(GetMousePos() - m_CachedActualSize.TopLeft())) + if (!spritecall.m_Area.PointInside(m_pGUI->GetMousePos() - m_CachedActualSize.TopLeft())) continue; // If tooltip exists, set the property Index: ps/trunk/source/gui/CTooltip.cpp =================================================================== --- ps/trunk/source/gui/CTooltip.cpp +++ ps/trunk/source/gui/CTooltip.cpp @@ -63,9 +63,6 @@ void CTooltip::SetupText() { - if (!GetGUI()) - return; - ENSURE(m_GeneratedTexts.size() == 1); CStrW font; @@ -92,7 +89,7 @@ GUI::GetSetting(this, "independent", independent); if (independent) - mousepos = GetMousePos(); + mousepos = m_pGUI->GetMousePos(); else GUI::GetSetting(this, "_mousepos", mousepos); @@ -151,9 +148,6 @@ void CTooltip::Draw() { - if (!GetGUI()) - return; - float z = 900.f; // TODO: Find a nicer way of putting the tooltip on top of everything else CGUISpriteInstance* sprite; Index: ps/trunk/source/gui/GUItext.cpp =================================================================== --- ps/trunk/source/gui/GUItext.cpp +++ ps/trunk/source/gui/GUItext.cpp @@ -97,7 +97,7 @@ tag.m_TagType == TextChunk::Tag::TAG_ICON); const std::string& path = utf8_from_wstring(tag.m_TagValue); - if (!pGUI->IconExists(path)) + if (!pGUI->HasIcon(path)) { if (pObject) LOGERROR("Trying to use an icon, imgleft or imgright-tag with an undefined icon (\"%s\").", path.c_str()); Index: ps/trunk/source/gui/IGUIButtonBehavior.cpp =================================================================== --- ps/trunk/source/gui/IGUIButtonBehavior.cpp +++ ps/trunk/source/gui/IGUIButtonBehavior.cpp @@ -166,9 +166,6 @@ void IGUIButtonBehavior::DrawButton(const CRect& rect, const float& z, CGUISpriteInstance& sprite, CGUISpriteInstance& sprite_over, CGUISpriteInstance& sprite_pressed, CGUISpriteInstance& sprite_disabled, int cell_id) { - if (!GetGUI()) - return; - bool enabled; GUI::GetSetting(this, "enabled", enabled); Index: ps/trunk/source/gui/IGUIObject.h =================================================================== --- ps/trunk/source/gui/IGUIObject.h +++ ps/trunk/source/gui/IGUIObject.h @@ -264,7 +264,7 @@ * @param GUIinstance Reference to the GUI * @param StyleName Style by name */ - void LoadStyle(CGUI& GUIinstance, const CStr& StyleName); + void LoadStyle(CGUI& pGUI, const CStr& StyleName); /** * Loads a style. @@ -320,11 +320,6 @@ IGUIObject* GetParent() const; /** - * Get Mouse from CGUI. - */ - CPos GetMousePos() const; - - /** * Handle additional children to the \-tag. In IGUIObject, this function does * nothing. In CList and CDropDown, it handles the \, used to build the data. * Index: ps/trunk/source/gui/IGUIObject.cpp =================================================================== --- ps/trunk/source/gui/IGUIObject.cpp +++ ps/trunk/source/gui/IGUIObject.cpp @@ -70,11 +70,6 @@ m_Children.push_back(pChild); - // If this (not the child) object is already attached - // to a CGUI, it pGUI pointer will be non-null. - // This will mean we'll have to check if we're using - // names already used. - if (pChild->GetGUI()) { try { @@ -135,10 +130,7 @@ bool IGUIObject::MouseOver() { - if (!GetGUI()) - throw PSERROR_GUI_OperationNeedsGUIObject(); - - return m_CachedActualSize.PointInside(GetMousePos()); + return m_CachedActualSize.PointInside(m_pGUI->GetMousePos()); } bool IGUIObject::MouseOverIcon() @@ -146,14 +138,6 @@ return false; } -CPos IGUIObject::GetMousePos() const -{ - if (GetGUI()) - return GetGUI()->m_MousePos; - - return CPos(); -} - void IGUIObject::UpdateMouseOver(IGUIObject* const& pMouseOver) { if (pMouseOver == this) @@ -269,17 +253,12 @@ } } -void IGUIObject::LoadStyle(CGUI& GUIinstance, const CStr& StyleName) +void IGUIObject::LoadStyle(CGUI& pGUI, const CStr& StyleName) { - // Fetch style - if (GUIinstance.m_Styles.count(StyleName) == 1) - { - LoadStyle(GUIinstance.m_Styles[StyleName]); - } + if (pGUI.HasStyle(StyleName)) + LoadStyle(pGUI.GetStyle(StyleName)); else - { debug_warn(L"IGUIObject::LoadStyle failed"); - } } void IGUIObject::LoadStyle(const SGUIStyle& Style) @@ -325,9 +304,6 @@ void IGUIObject::RegisterScriptHandler(const CStr& Action, const CStr& Code, CGUI* pGUI) { - if(!GetGUI()) - throw PSERROR_GUI_OperationNeedsGUIObject(); - JSContext* cx = pGUI->GetScriptInterface()->GetContext(); JSAutoRequest rq(cx); JS::RootedValue globalVal(cx, pGUI->GetGlobalObject()); @@ -396,11 +372,13 @@ // Set up the 'mouse' parameter JS::RootedValue mouse(cx); + const CPos& mousePos = m_pGUI->GetMousePos(); + m_pGUI->GetScriptInterface()->CreateObject( &mouse, - "x", m_pGUI->m_MousePos.x, - "y", m_pGUI->m_MousePos.y, - "buttons", m_pGUI->m_MouseButtons); + "x", mousePos.x, + "y", mousePos.y, + "buttons", m_pGUI->GetMouseButtons()); JS::AutoValueVector paramData(cx); paramData.append(mouse); @@ -465,17 +443,17 @@ void IGUIObject::SetFocus() { - GetGUI()->m_FocusedObject = this; + m_pGUI->SetFocusedObject(this); } bool IGUIObject::IsFocused() const { - return GetGUI()->m_FocusedObject == this; + return m_pGUI->GetFocusedObject() == this; } bool IGUIObject::IsRootObject() const { - return GetGUI() != 0 && m_pParent == GetGUI()->m_BaseObject; + return m_pParent == m_pGUI->GetBaseObject(); } void IGUIObject::TraceMember(JSTracer* trc) Index: ps/trunk/source/gui/IGUIScrollBar.cpp =================================================================== --- ps/trunk/source/gui/IGUIScrollBar.cpp +++ ps/trunk/source/gui/IGUIScrollBar.cpp @@ -96,7 +96,7 @@ { // TODO Gee: Optimizations needed! - CPos mouse = m_pHostObject->GetMousePos(); + const CPos& mouse = m_pGUI->GetMousePos(); // If bar is being dragged if (m_BarPressed) @@ -123,7 +123,7 @@ if (!m_pHostObject) break; - CPos mouse = m_pHostObject->GetMousePos(); + const CPos& mouse = m_pGUI->GetMousePos(); // if bar is pressed if (GetBarRect().PointInside(mouse)) Index: ps/trunk/source/gui/IGUIScrollBarOwner.cpp =================================================================== --- ps/trunk/source/gui/IGUIScrollBarOwner.cpp +++ ps/trunk/source/gui/IGUIScrollBarOwner.cpp @@ -46,9 +46,6 @@ const SGUIScrollBarStyle* IGUIScrollBarOwner::GetScrollBarStyle(const CStr& style) const { - if (!GetGUI()) - return NULL; - return GetGUI()->GetScrollBarStyle(style); } Index: ps/trunk/source/gui/MiniMap.cpp =================================================================== --- ps/trunk/source/gui/MiniMap.cpp +++ ps/trunk/source/gui/MiniMap.cpp @@ -192,7 +192,7 @@ bool CMiniMap::MouseOver() { // Get the mouse position. - CPos mousePos = GetMousePos(); + const CPos& mousePos = m_pGUI->GetMousePos(); // Get the position of the center of the minimap. CPos minimapCenter = CPos(m_CachedActualSize.left + m_CachedActualSize.GetWidth() / 2.0, m_CachedActualSize.bottom - m_CachedActualSize.GetHeight() / 2.0); // Take the magnitude of the difference of the mouse position and minimap center. @@ -208,7 +208,7 @@ { // Determine X and Z according to proportion of mouse position and minimap - CPos mousePos = GetMousePos(); + const CPos& mousePos = m_pGUI->GetMousePos(); float px = (mousePos.x - m_CachedActualSize.left) / m_CachedActualSize.GetWidth(); float py = (m_CachedActualSize.bottom - mousePos.y) / m_CachedActualSize.GetHeight();