mirror of
https://github.com/whoahq/whoa.git
synced 2026-02-01 00:02:45 +03:00
feat(ui): add CSimpleCheckbox::LoadXML
This commit is contained in:
parent
5e00730587
commit
0a2c95cda1
@ -1,6 +1,9 @@
|
||||
#include "ui/CSimpleCheckbox.hpp"
|
||||
#include "ui/CSimpleCheckboxScript.hpp"
|
||||
#include "ui/CSimpleTexture.hpp"
|
||||
#include "ui/LoadXML.hpp"
|
||||
#include "util/StringTo.hpp"
|
||||
#include <common/XML.hpp>
|
||||
|
||||
int32_t CSimpleCheckbox::s_metatable;
|
||||
int32_t CSimpleCheckbox::s_objectType;
|
||||
@ -40,6 +43,28 @@ int32_t CSimpleCheckbox::GetChecked() {
|
||||
return this->m_checked;
|
||||
}
|
||||
|
||||
void CSimpleCheckbox::LoadXML(XMLNode* node, CStatus* status) {
|
||||
CSimpleButton::LoadXML(node, status);
|
||||
|
||||
auto checkedAttr = node->GetAttributeByName("checked");
|
||||
if (checkedAttr && *checkedAttr) {
|
||||
auto checked = StringToBOOL(checkedAttr);
|
||||
this->SetChecked(checked, 0);
|
||||
}
|
||||
|
||||
for (auto child = node->m_child; child; child = child->m_next) {
|
||||
if (!SStrCmpI(child->GetName(), "CheckedTexture")) {
|
||||
auto checkedTexture = LoadXML_Texture(child, this, status);
|
||||
this->SetCheckedTexture(checkedTexture);
|
||||
|
||||
} else if (!SStrCmpI(child->GetName(), "DisabledCheckedTexture")) {
|
||||
auto disabledTexture = LoadXML_Texture(child, this, status);
|
||||
this->SetDisabledCheckedTexture(disabledTexture);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void CSimpleCheckbox::SetChecked(int32_t checked, int32_t force) {
|
||||
if (checked == this->m_checked && !force) {
|
||||
return;
|
||||
@ -63,3 +88,29 @@ void CSimpleCheckbox::SetChecked(int32_t checked, int32_t force) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void CSimpleCheckbox::SetCheckedTexture(CSimpleTexture* texture) {
|
||||
if (this->m_checkedTexture) {
|
||||
delete this->m_checkedTexture;
|
||||
}
|
||||
|
||||
if (texture) {
|
||||
texture->SetFrame(this, DRAWLAYER_ARTWORK_OVERLAY, 0);
|
||||
}
|
||||
|
||||
this->m_checkedTexture = texture;
|
||||
this->SetChecked(this->m_checked, 1);
|
||||
}
|
||||
|
||||
void CSimpleCheckbox::SetDisabledCheckedTexture(CSimpleTexture* texture) {
|
||||
if (this->m_disabledTexture) {
|
||||
delete this->m_disabledTexture;
|
||||
}
|
||||
|
||||
if (texture) {
|
||||
texture->SetFrame(this, DRAWLAYER_ARTWORK_OVERLAY, 0);
|
||||
}
|
||||
|
||||
this->m_disabledTexture = texture;
|
||||
this->SetChecked(this->m_checked, 1);
|
||||
}
|
||||
|
||||
@ -22,12 +22,15 @@ class CSimpleCheckbox : public CSimpleButton {
|
||||
// Virtual member functions
|
||||
virtual bool IsA(int32_t type);
|
||||
virtual int32_t GetScriptMetaTable();
|
||||
virtual void LoadXML(XMLNode* node, CStatus* status);
|
||||
|
||||
// Member functions
|
||||
CSimpleCheckbox(CSimpleFrame* parent)
|
||||
: CSimpleButton(parent) {};
|
||||
int32_t GetChecked();
|
||||
void SetChecked(int32_t checked, int32_t force);
|
||||
void SetCheckedTexture(CSimpleTexture* texture);
|
||||
void SetDisabledCheckedTexture(CSimpleTexture* texture);
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
Loading…
Reference in New Issue
Block a user