Files
NazaraEngine/SDK/include/NDK/Widgets/CheckboxWidget.hpp
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

105 lines
2.9 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
#pragma once
#ifndef NDK_WIDGETS_CHECKBOXWIDGET_HPP
#define NDK_WIDGETS_CHECKBOXWIDGET_HPP
#include <NDK/Prerequesites.hpp>
#include <NDK/BaseWidget.hpp>
#include <NDK/Widgets/Enums.hpp>
#include <NDK/Components/NodeComponent.hpp>
#include <Nazara/Renderer/Texture.hpp>
#include <Nazara/Utility/AbstractTextDrawer.hpp>
#include <Nazara/Graphics/Sprite.hpp>
#include <Nazara/Graphics/TextSprite.hpp>
#include <Nazara/Math/Vector2.hpp>
#include <Nazara/Math/Rect.hpp>
namespace Ndk
{
class World;
class NDK_API CheckboxWidget : public BaseWidget
{
friend class Sdk;
public:
CheckboxWidget(BaseWidget* parent = nullptr);
CheckboxWidget(const CheckboxWidget&) = delete;
CheckboxWidget(CheckboxWidget&&) = default;
~CheckboxWidget() = default;
//virtual CheckboxWidget* Clone() const = 0;
inline void EnableAdaptativeMargin(bool enable = true);
inline void EnableCheckbox(bool enable = true);
inline void EnableTristate(bool enable = true);
inline bool IsCheckboxEnabled() const;
inline bool IsMarginAdaptative() const;
inline bool IsTristateEnabled() const;
inline const Nz::Vector2f& GetCheckboxSize() const;
inline Nz::Vector2f GetCheckboxBorderSize() const;
inline CheckboxState GetState() const;
inline float GetTextMargin() const;
inline void SetCheckboxSize(const Nz::Vector2f& size);
CheckboxState SwitchToNextState();
void SetState(CheckboxState state);
inline void SetTextMargin(float margin);
void ResizeToContent() override;
inline void UpdateText(const Nz::AbstractTextDrawer& drawer);
CheckboxWidget& operator=(const CheckboxWidget&) = delete;
CheckboxWidget& operator=(CheckboxWidget&&) = default;
NazaraSignal(OnStateChanged, const CheckboxWidget* /*checkbox*/);
private:
static bool Initialize();
static void Uninitialize();
void Layout() override;
void UpdateCheckbox();
void OnMouseButtonRelease(int x, int y, Nz::Mouse::Button button) override;
inline bool ContainsCheckbox(int x, int y) const;
EntityHandle m_checkboxBorderEntity;
EntityHandle m_checkboxBackgroundEntity;
EntityHandle m_checkboxContentEntity;
EntityHandle m_textEntity;
Nz::TextureRef m_checkMark;
Nz::SpriteRef m_checkboxContentSprite;
Nz::SpriteRef m_checkboxBorderSprite;
Nz::SpriteRef m_checkboxBackgroundSprite;
Nz::TextSpriteRef m_textSprite;
static Nz::Color s_backgroundColor;
static Nz::Color s_disabledBackgroundColor;
static Nz::Color s_disabledBorderColor;
static Nz::Color s_borderColor;
bool m_adaptativeMargin;
bool m_checkboxEnabled;
bool m_tristateEnabled;
static float s_borderScale;
float m_textMargin;
CheckboxState m_state;
};
}
#include <NDK/Widgets/CheckboxWidget.inl>
#endif // NDK_WIDGETS_CHECKBOXWIDGET_HPP