Files
NazaraEngine/SDK/include/NDK/Widgets/CheckboxWidget.inl
S6066 55ca4a84ea Added CheckboxWidget (#130)
* Started Checkbox Widget (buggy)

* Added features

* Added enabling feature

* Almost finished Checkbox

* Bugfix

* Bugfixes

* Use a better name

* Optimizations

* Added explicit colors

* ...

* changed lots of things

* Almost finished CheckboxWidget

* Almost almost finished

* Use better UTF8 box

* Edited encode resources script to encode SDK resources

* Finished checkbox widget

* Forgot to delete old function

* Forgot to delete todo comment

* Fix Travis compilation

* Fix Travis compilation a second time

* Fix Travis Compilation a third time

* Fix indentation

* Fix Files encoding

* Moved CheckboxState enum in (new) Enum.hpp

* Probably looks like more generated now

* Reorder CheckboxWidget members

* Reorder checkbox state members

* Reorder members 2...

* Oops

* Reorder members functions

* Fix encoding

* Fix files encoding

* Forgot to fix one file encoding

* Fix SDK Server

* Fix encoding again -_-

* Oops

* Optimize Checkbox Widget

* Fix .gitignore

* Removed .vs in gitignore

* Moved Enums into Widgets folder

* Bugfix

* Fix Encode Resources script

* Remove double line feeds

* Rename SetNextState to SwitchToNextState
2017-08-30 10:25:42 +02:00

92 lines
2.1 KiB
C++

// Copyright (C) 2017 Samy Bensaid
// This file is part of the "Nazara Development Kit"
// For conditions of distribution and use, see copyright notice in Prerequesites.hpp
namespace Ndk
{
inline void CheckboxWidget::EnableAdaptativeMargin(bool enable)
{
m_adaptativeMargin = enable;
Layout();
}
inline void CheckboxWidget::EnableCheckbox(bool enable)
{
m_checkboxEnabled = enable;
UpdateCheckbox();
}
inline void CheckboxWidget::EnableTristate(bool enable)
{
m_tristateEnabled = enable;
if (m_tristateEnabled && GetState() == CheckboxState_Tristate)
SetState(CheckboxState_Unchecked);
}
inline bool CheckboxWidget::IsCheckboxEnabled() const
{
return m_checkboxEnabled;
}
inline bool CheckboxWidget::IsMarginAdaptative() const
{
return m_adaptativeMargin;
}
inline bool CheckboxWidget::IsTristateEnabled() const
{
return m_tristateEnabled;
}
inline const Nz::Vector2f& CheckboxWidget::GetCheckboxSize() const
{
return m_checkboxBorderSprite->GetSize();
}
inline Nz::Vector2f CheckboxWidget::GetCheckboxBorderSize() const
{
return GetCheckboxSize() / s_borderScale;
}
inline CheckboxState CheckboxWidget::GetState() const
{
return m_state;
}
inline float CheckboxWidget::GetTextMargin() const
{
return m_textMargin;
}
inline void CheckboxWidget::SetCheckboxSize(const Nz::Vector2f& size)
{
m_checkboxBorderSprite->SetSize(size);
m_checkboxBackgroundSprite->SetSize(size - GetCheckboxBorderSize() * 2.f);
m_checkboxContentSprite->SetSize(GetCheckboxSize() - GetCheckboxBorderSize() * 2.f - Nz::Vector2f { 4.f, 4.f });
Layout();
}
inline void CheckboxWidget::SetTextMargin(float margin)
{
m_textMargin = margin;
Layout();
}
inline void CheckboxWidget::UpdateText(const Nz::AbstractTextDrawer& drawer)
{
m_textSprite->Update(drawer);
Layout();
}
inline bool CheckboxWidget::ContainsCheckbox(int x, int y) const
{
Nz::Vector2f checkboxSize = GetCheckboxSize();
Nz::Vector3f pos = m_checkboxBorderEntity->GetComponent<NodeComponent>().GetPosition(Nz::CoordSys_Local);
return x > pos.x && x < pos.x + checkboxSize.x &&
y > pos.y && y < pos.y + checkboxSize.y;
}
}