Index: ps/trunk/source/gui/CGUI.cpp =================================================================== --- ps/trunk/source/gui/CGUI.cpp +++ ps/trunk/source/gui/CGUI.cpp @@ -608,7 +608,7 @@ Text.m_Size.cy = std::max(Text.m_Size.cy, Image.m_YTo); Images[j].push_back(Image); - Text.m_SpriteCalls.push_back(SpriteCall); + Text.m_SpriteCalls.push_back(std::move(SpriteCall)); } } } @@ -784,7 +784,10 @@ // Sprite call can exist within only a newline segment, // therefore we need this. - Text.m_SpriteCalls.insert(Text.m_SpriteCalls.end(), Feedback2.m_SpriteCalls.begin(), Feedback2.m_SpriteCalls.end()); + Text.m_SpriteCalls.insert( + Text.m_SpriteCalls.end(), + std::make_move_iterator(Feedback2.m_SpriteCalls.begin()), + std::make_move_iterator(Feedback2.m_SpriteCalls.end())); break; } else if (x > width_range[To] && j == temp_from) @@ -800,8 +803,15 @@ } // Add the whole Feedback2.m_TextCalls to our m_TextCalls. - Text.m_TextCalls.insert(Text.m_TextCalls.end(), Feedback2.m_TextCalls.begin(), Feedback2.m_TextCalls.end()); - Text.m_SpriteCalls.insert(Text.m_SpriteCalls.end(), Feedback2.m_SpriteCalls.begin(), Feedback2.m_SpriteCalls.end()); + Text.m_TextCalls.insert( + Text.m_TextCalls.end(), + std::make_move_iterator(Feedback2.m_TextCalls.begin()), + std::make_move_iterator(Feedback2.m_TextCalls.end())); + + Text.m_SpriteCalls.insert( + Text.m_SpriteCalls.end(), + std::make_move_iterator(Feedback2.m_SpriteCalls.begin()), + std::make_move_iterator(Feedback2.m_SpriteCalls.end())); if (j == (int)string.m_Words.size()-2) done = true; @@ -1677,7 +1687,7 @@ scrollbar.m_SpriteBarVerticalPressed = attr_value; } - m_ScrollBarStyles[name] = scrollbar; + m_ScrollBarStyles[name] = std::move(scrollbar); } void CGUI::Xeromyces_ReadIcon(XMBElement Element, CXeromyces* pFile) Index: ps/trunk/source/gui/CGUISprite.h =================================================================== --- ps/trunk/source/gui/CGUISprite.h +++ ps/trunk/source/gui/CGUISprite.h @@ -157,16 +157,19 @@ // calculations between draw calls. class CGUISpriteInstance { + NONCOPYABLE(CGUISpriteInstance); + public: CGUISpriteInstance(); CGUISpriteInstance(const CStr& SpriteName); - CGUISpriteInstance(const CGUISpriteInstance& Sprite); - CGUISpriteInstance& operator=(const CGUISpriteInstance&); - CGUISpriteInstance& operator=(const CStr& SpriteName); - void Draw(CRect Size, int CellID, std::map& Sprites, float Z) const; - void Invalidate(); + + CGUISpriteInstance(CGUISpriteInstance&&) = default; + CGUISpriteInstance& operator=(CGUISpriteInstance&&) = default; + + void Draw(const CRect& Size, int CellID, std::map& Sprites, float Z) const; bool IsEmpty() const; - const CStr& GetName() { return m_SpriteName; } + const CStr& GetName() const { return m_SpriteName; } + void SetName(const CStr& SpriteName); private: CStr m_SpriteName; Index: ps/trunk/source/gui/CGUISprite.cpp =================================================================== --- ps/trunk/source/gui/CGUISprite.cpp +++ ps/trunk/source/gui/CGUISprite.cpp @@ -30,7 +30,7 @@ m_Images.push_back(image); } -void CGUISpriteInstance::Draw(CRect Size, int CellID, std::map& Sprites, float Z) const +void CGUISpriteInstance::Draw(const CRect& Size, int CellID, std::map& Sprites, float Z) const { if (m_CachedSize != Size || m_CachedCellID != CellID) { @@ -41,12 +41,6 @@ GUIRenderer::Draw(m_DrawCallCache, Z); } -void CGUISpriteInstance::Invalidate() -{ - m_CachedSize = CRect(); - m_CachedCellID = -1; -} - bool CGUISpriteInstance::IsEmpty() const { return m_SpriteName.empty(); @@ -66,21 +60,10 @@ { } -CGUISpriteInstance::CGUISpriteInstance(const CGUISpriteInstance& Sprite) - : m_SpriteName(Sprite.m_SpriteName), m_CachedCellID(-1) -{ -} - -CGUISpriteInstance& CGUISpriteInstance::operator=(const CGUISpriteInstance& Sprite) -{ - return this->operator=(Sprite.m_SpriteName); -} - -CGUISpriteInstance& CGUISpriteInstance::operator=(const CStr& SpriteName) +void CGUISpriteInstance::SetName(const CStr& SpriteName) { m_SpriteName = SpriteName; + m_CachedSize = CRect(); m_DrawCallCache.clear(); - Invalidate(); - return *this; + m_CachedCellID = -1; } - Index: ps/trunk/source/gui/GUItext.cpp =================================================================== --- ps/trunk/source/gui/GUItext.cpp +++ ps/trunk/source/gui/GUItext.cpp @@ -159,7 +159,7 @@ SpriteCall.m_CellID = icon.m_CellID; // Add sprite call - Feedback.m_SpriteCalls.push_back(SpriteCall); + Feedback.m_SpriteCalls.push_back(std::move(SpriteCall)); // Finalize text call TextCall.m_pSpriteCall = &Feedback.m_SpriteCalls.back(); Index: ps/trunk/source/gui/GUIutil.h =================================================================== --- ps/trunk/source/gui/GUIutil.h +++ ps/trunk/source/gui/GUIutil.h @@ -37,6 +37,8 @@ #include "gui/GUIbase.h" #include "gui/IGUIObject.h" +#include + class CClientArea; class CGUIString; class CMatrix3D; @@ -90,11 +92,18 @@ * This is the official way of setting a setting, no other * way should only cautiously be used! * + * This variant will use the move-assignment. + * * @param pObject Object pointer * @param Setting Setting by name * @param Value Sets value to this, note type T! * @param SkipMessage Does not send a GUIM_SETTINGS_UPDATED if true */ + static PSRETURN SetSetting(IGUIObject* pObject, const CStr& Setting, T& Value, const bool& SkipMessage = false); + + /** + * This variant will copy the value. + */ static PSRETURN SetSetting(IGUIObject* pObject, const CStr& Setting, const T& Value, const bool& SkipMessage = false); /** @@ -147,6 +156,12 @@ private: + /** + * Changes the value of the setting by calling the valueSet functon that performs either a copy or move assignment. + * Updates some internal data depending on the setting changed. + */ + static PSRETURN SetSettingWrap(IGUIObject* pObject, const CStr& Setting, const T& Value, const bool& SkipMessage, const std::function& valueSet); + // templated typedef of function pointer typedef void (IGUIObject::*void_Object_pFunction_argT)(const T& arg); typedef void (IGUIObject::*void_Object_pFunction_argRefT)(T& arg); @@ -238,7 +253,6 @@ RecurseObject(RR, obj, pFunc); } -private: /** * Checks restrictions for the iteration, for instance if * you tell the recursor to avoid all hidden objects, it Index: ps/trunk/source/gui/GUIutil.cpp =================================================================== --- ps/trunk/source/gui/GUIutil.cpp +++ ps/trunk/source/gui/GUIutil.cpp @@ -325,6 +325,24 @@ return ret; } +template +PSRETURN GUI::SetSetting(IGUIObject* pObject, const CStr& Setting, T& Value, const bool& SkipMessage) +{ + return SetSettingWrap(pObject, Setting, Value, SkipMessage, + [&pObject, &Setting, &Value]() { + *static_cast(pObject->m_Settings[Setting].m_pSetting) = std::move(Value); + }); +} + +template +PSRETURN GUI::SetSetting(IGUIObject* pObject, const CStr& Setting, const T& Value, const bool& SkipMessage) +{ + return SetSettingWrap(pObject, Setting, Value, SkipMessage, + [&pObject, &Setting, &Value]() { + *static_cast(pObject->m_Settings[Setting].m_pSetting) = Value; + }); +} + // Helper function for SetSetting template bool IsBoolTrue(const T&) @@ -338,7 +356,7 @@ } template -PSRETURN GUI::SetSetting(IGUIObject* pObject, const CStr& Setting, const T& Value, const bool& SkipMessage) +PSRETURN GUI::SetSettingWrap(IGUIObject* pObject, const CStr& Setting, const T& Value, const bool& SkipMessage, const std::function& valueSet) { ENSURE(pObject != NULL); @@ -354,12 +372,9 @@ CheckType(pObject, Setting); #endif - // Set value - *(T*)pObject->m_Settings[Setting].m_pSetting = Value; + valueSet(); - // // Some settings needs special attention at change - // // If setting was "size", we need to re-cache itself and all children if (Setting == "size") @@ -386,6 +401,7 @@ #define TYPE(T) \ template PSRETURN GUI::GetSettingPointer(const IGUIObject* pObject, const CStr& Setting, T*& Value); \ template PSRETURN GUI::GetSetting(const IGUIObject* pObject, const CStr& Setting, T& Value); \ + template PSRETURN GUI::SetSetting(IGUIObject* pObject, const CStr& Setting, T& Value, const bool& SkipMessage); \ template PSRETURN GUI::SetSetting(IGUIObject* pObject, const CStr& Setting, const T& Value, const bool& SkipMessage); #define GUITYPE_IGNORE_CGUISpriteInstance #include "GUItypes.h" @@ -397,4 +413,4 @@ // and will mess up the caching performed by DrawSprite. You have to use GetSettingPointer // instead. (This is mainly useful to stop me accidentally using the wrong function.) template PSRETURN GUI::GetSettingPointer(const IGUIObject* pObject, const CStr& Setting, CGUISpriteInstance*& Value); -template PSRETURN GUI::SetSetting(IGUIObject* pObject, const CStr& Setting, const CGUISpriteInstance& Value, const bool& SkipMessage); +template PSRETURN GUI::SetSetting(IGUIObject* pObject, const CStr& Setting, CGUISpriteInstance& Value, const bool& SkipMessage); Index: ps/trunk/source/gui/scripting/GuiScriptConversions.cpp =================================================================== --- ps/trunk/source/gui/scripting/GuiScriptConversions.cpp +++ ps/trunk/source/gui/scripting/GuiScriptConversions.cpp @@ -286,3 +286,18 @@ } return true; } + +template<> void ScriptInterface::ToJSVal(JSContext* cx, JS::MutableHandleValue ret, const CGUISpriteInstance& val) +{ + ToJSVal(cx, ret, val.GetName()); +} + +template<> bool ScriptInterface::FromJSVal(JSContext* cx, JS::HandleValue v, CGUISpriteInstance& out) +{ + std::string name; + if (!FromJSVal(cx, v, name)) + return false; + + out.SetName(name); + return true; +} Index: ps/trunk/source/gui/scripting/JSInterface_IGUIObject.cpp =================================================================== --- ps/trunk/source/gui/scripting/JSInterface_IGUIObject.cpp +++ ps/trunk/source/gui/scripting/JSInterface_IGUIObject.cpp @@ -203,7 +203,7 @@ { CGUISpriteInstance* value; GUI::GetSettingPointer(e, propName, value); - ScriptInterface::ToJSVal(cx, vp, value->GetName()); + ScriptInterface::ToJSVal(cx, vp, *value); break; } @@ -324,11 +324,11 @@ case GUIST_CGUISpriteInstance: { - std::string value; + CGUISpriteInstance value; if (!ScriptInterface::FromJSVal(cx, vp, value)) return false; - GUI::SetSetting(e, propName, CGUISpriteInstance(value)); + GUI::SetSetting(e, propName, value); break; }