Changeset View
Changeset View
Standalone View
Standalone View
source/gui/GUIutil.cpp
/* Copyright (C) 2016 Wildfire Games. | /* Copyright (C) 2018 Wildfire Games. | ||||
* This file is part of 0 A.D. | * This file is part of 0 A.D. | ||||
* | * | ||||
* 0 A.D. is free software: you can redistribute it and/or modify | * 0 A.D. is free software: you can redistribute it and/or modify | ||||
* it under the terms of the GNU General Public License as published by | * it under the terms of the GNU General Public License as published by | ||||
* the Free Software Foundation, either version 2 of the License, or | * the Free Software Foundation, either version 2 of the License, or | ||||
* (at your option) any later version. | * (at your option) any later version. | ||||
* | * | ||||
* 0 A.D. is distributed in the hope that it will be useful, | * 0 A.D. is distributed in the hope that it will be useful, | ||||
▲ Show 20 Lines • Show All 316 Lines • ▼ Show 20 Lines | |||||
#endif | #endif | ||||
//-------------------------------------------------------------------- | //-------------------------------------------------------------------- | ||||
template <typename T> | template <typename T> | ||||
PSRETURN GUI<T>::GetSettingPointer(const IGUIObject* pObject, const CStr& Setting, T*& Value) | PSRETURN GUI<T>::GetSettingPointer(const IGUIObject* pObject, const CStr& Setting, T*& Value) | ||||
{ | { | ||||
ENSURE(pObject != NULL); | ENSURE(pObject != nullptr); | ||||
std::map<CStr, SGUISetting>::const_iterator it = pObject->m_Settings.find(Setting); | std::map<CStr, SGUISetting>::const_iterator it = pObject->m_Settings.find(Setting); | ||||
if (it == pObject->m_Settings.end()) | if (it == pObject->m_Settings.end()) | ||||
{ | { | ||||
LOGWARNING("setting %s was not found on object %s", | LOGWARNING("setting %s was not found on object %s", | ||||
Setting.c_str(), | Setting.c_str(), | ||||
pObject->GetPresentableName().c_str()); | pObject->GetPresentableName().c_str()); | ||||
return PSRETURN_GUI_InvalidSetting; | return PSRETURN_GUI_InvalidSetting; | ||||
} | } | ||||
if (it->second.m_pSetting == NULL) | if (it->second.m_pSetting == nullptr) | ||||
return PSRETURN_GUI_InvalidSetting; | return PSRETURN_GUI_InvalidSetting; | ||||
#ifndef NDEBUG | #ifndef NDEBUG | ||||
CheckType<T>(pObject, Setting); | CheckType<T>(pObject, Setting); | ||||
#endif | #endif | ||||
// Get value | // Get value | ||||
Value = (T*)(it->second.m_pSetting); | Value = (T*)(it->second.m_pSetting); | ||||
return PSRETURN_OK; | return PSRETURN_OK; | ||||
} | } | ||||
template <typename T> | template <typename T> | ||||
PSRETURN GUI<T>::GetSetting(const IGUIObject* pObject, const CStr& Setting, T& Value) | PSRETURN GUI<T>::GetSetting(const IGUIObject* pObject, const CStr& Setting, T& Value) | ||||
{ | { | ||||
T* v = NULL; | T* v = nullptr; | ||||
PSRETURN ret = GetSettingPointer(pObject, Setting, v); | PSRETURN ret = GetSettingPointer(pObject, Setting, v); | ||||
if (ret == PSRETURN_OK) | if (ret == PSRETURN_OK) | ||||
Value = *v; | Value = *v; | ||||
return ret; | return ret; | ||||
} | } | ||||
// Helper function for SetSetting | // Helper function for SetSetting | ||||
template <typename T> | template <typename T> | ||||
bool IsBoolTrue(const T&) | bool IsBoolTrue(const T&) | ||||
{ | { | ||||
return false; | return false; | ||||
} | } | ||||
template <> | template <> | ||||
bool IsBoolTrue<bool>(const bool& v) | bool IsBoolTrue<bool>(const bool& v) | ||||
{ | { | ||||
return v; | return v; | ||||
} | } | ||||
template <typename T> | template <typename T> | ||||
PSRETURN GUI<T>::SetSetting(IGUIObject* pObject, const CStr& Setting, const T& Value, const bool& SkipMessage) | PSRETURN GUI<T>::SetSetting(IGUIObject* pObject, const CStr& Setting, const T& Value, const bool& SkipMessage) | ||||
{ | { | ||||
ENSURE(pObject != NULL); | ENSURE(pObject != nullptr); | ||||
if (!pObject->SettingExists(Setting)) | if (!pObject->SettingExists(Setting)) | ||||
{ | { | ||||
LOGWARNING("setting %s was not found on object %s", | LOGWARNING("setting %s was not found on object %s", | ||||
Setting.c_str(), | Setting.c_str(), | ||||
pObject->GetPresentableName().c_str()); | pObject->GetPresentableName().c_str()); | ||||
return PSRETURN_GUI_InvalidSetting; | return PSRETURN_GUI_InvalidSetting; | ||||
} | } | ||||
▲ Show 20 Lines • Show All 49 Lines • Show Last 20 Lines |
Wildfire Games · Phabricator