Added functions to customize ButtonWidget (#133)

* Made ButtonWidget more usable

* Fix static functions

* Reorder static functions

* Deteriorate ButtonWidget
This commit is contained in:
S6066
2017-09-16 14:19:11 +02:00
committed by Jérôme Leclercq
parent 9a6b007e70
commit 3d4585ec4a
3 changed files with 202 additions and 6 deletions

View File

@@ -10,6 +10,7 @@
#include <NDK/Prerequesites.hpp>
#include <NDK/BaseWidget.hpp>
#include <Nazara/Utility/AbstractTextDrawer.hpp>
#include <Nazara/Core/Color.hpp>
#include <Nazara/Graphics/Sprite.hpp>
#include <Nazara/Graphics/TextSprite.hpp>
@@ -29,17 +30,44 @@ namespace Ndk
void ResizeToContent() override;
inline const Nz::Color& GetColor() const;
inline const Nz::Color& GetCornerColor() const;
inline const Nz::Color& GetHoverColor() const;
inline const Nz::Color& GetHoverCornerColor() const;
inline const Nz::Color& GetPressColor() const;
inline const Nz::Color& GetPressCornerColor() const;
inline const Nz::TextureRef& GetTexture() const;
inline const Nz::TextureRef& GetHoverTexture() const;
inline const Nz::TextureRef& GetPressTexture() const;
inline void SetColor(const Nz::Color& color, const Nz::Color& cornerColor);
inline void SetHoverColor(const Nz::Color& color, const Nz::Color& cornerColor);
inline void SetPressColor(const Nz::Color& color, const Nz::Color& cornerColor);
inline void SetTexture(const Nz::TextureRef& texture);
inline void SetHoverTexture(const Nz::TextureRef& texture);
inline void SetPressTexture(const Nz::TextureRef& texture);
inline void UpdateText(const Nz::AbstractTextDrawer& drawer);
ButtonWidget& operator=(const ButtonWidget&) = delete;
ButtonWidget& operator=(ButtonWidget&&) = default;
static const Nz::Color& GetDefaultColor();
static const Nz::Color& GetDefaultCornerColor();
static const Nz::Color& GetDefaultHoverColor();
static const Nz::Color& GetDefaultHoverCornerColor();
static const Nz::Color& GetDefaultPressColor();
static const Nz::Color& GetDefaultPressCornerColor();
NazaraSignal(OnButtonTrigger, const ButtonWidget* /*button*/);
private:
void Layout() override;
void OnMouseEnter() override;
void OnMouseButtonPress(int x, int y, Nz::Mouse::Button button) override;
void OnMouseButtonRelease(int x, int y, Nz::Mouse::Button button) override;
void OnMouseExit() override;
@@ -47,6 +75,24 @@ namespace Ndk
EntityHandle m_gradientEntity;
Nz::SpriteRef m_gradientSprite;
Nz::TextSpriteRef m_textSprite;
Nz::Color m_color;
Nz::Color m_cornerColor;
Nz::Color m_hoverColor;
Nz::Color m_hoverCornerColor;
Nz::Color m_pressColor;
Nz::Color m_pressCornerColor;
Nz::TextureRef m_texture;
Nz::TextureRef m_hoverTexture;
Nz::TextureRef m_pressTexture;
static Nz::Color s_color;
static Nz::Color s_cornerColor;
static Nz::Color s_hoverColor;
static Nz::Color s_hoverCornerColor;
static Nz::Color s_pressColor;
static Nz::Color s_pressCornerColor;
};
}

View File

@@ -6,6 +6,89 @@
namespace Ndk
{
inline const Nz::Color& ButtonWidget::GetColor() const
{
return m_color;
}
inline const Nz::Color& ButtonWidget::GetCornerColor() const
{
return m_cornerColor;
}
inline const Nz::Color& ButtonWidget::GetHoverColor() const
{
return m_hoverColor;
}
inline const Nz::Color& ButtonWidget::GetHoverCornerColor() const
{
return m_hoverCornerColor;
}
inline const Nz::Color& ButtonWidget::GetPressColor() const
{
return m_pressColor;
}
inline const Nz::Color& ButtonWidget::GetPressCornerColor() const
{
return m_pressCornerColor;
}
inline const Nz::TextureRef& ButtonWidget::GetTexture() const
{
return m_texture;
}
inline const Nz::TextureRef& ButtonWidget::GetHoverTexture() const
{
return m_hoverTexture;
}
inline const Nz::TextureRef& ButtonWidget::GetPressTexture() const
{
return m_pressTexture;
}
inline void ButtonWidget::SetColor(const Nz::Color& color, const Nz::Color& cornerColor)
{
m_color = color;
m_cornerColor = cornerColor;
m_gradientSprite->SetColor(m_color);
m_gradientSprite->SetCornerColor(Nz::RectCorner_LeftBottom, m_cornerColor);
m_gradientSprite->SetCornerColor(Nz::RectCorner_RightBottom, m_cornerColor);
}
inline void ButtonWidget::SetHoverColor(const Nz::Color& color, const Nz::Color& cornerColor)
{
m_hoverColor = color;
m_hoverCornerColor = cornerColor;
}
inline void ButtonWidget::SetPressColor(const Nz::Color& color, const Nz::Color& cornerColor)
{
m_pressColor = color;
m_pressCornerColor = cornerColor;
}
inline void ButtonWidget::SetTexture(const Nz::TextureRef& texture)
{
m_texture = texture;
m_gradientSprite->SetTexture(m_texture);
}
inline void ButtonWidget::SetHoverTexture(const Nz::TextureRef& texture)
{
m_hoverTexture = texture;
}
inline void ButtonWidget::SetPressTexture(const Nz::TextureRef& texture)
{
m_pressTexture = texture;
}
inline void ButtonWidget::UpdateText(const Nz::AbstractTextDrawer& drawer)
{
m_textSprite->Update(drawer);