diff --git a/include/Nazara/Widgets/ProgressBarWidget.hpp b/include/Nazara/Widgets/ProgressBarWidget.hpp deleted file mode 100644 index 896d05d6d..000000000 --- a/include/Nazara/Widgets/ProgressBarWidget.hpp +++ /dev/null @@ -1,101 +0,0 @@ -// Copyright (C) 2022 Samy Bensaid -// This file is part of the "Nazara Engine - Widgets module" -// For conditions of distribution and use, see copyright notice in Config.hpp - -#pragma once - -#ifndef NAZARA_WIDGETS_PROGRESSBARWIDGET_HPP -#define NAZARA_WIDGETS_PROGRESSBARWIDGET_HPP - -#include -#include -#include -#include -#include -#include -#include -#include - -namespace Nz -{ - class NDK_CLIENT_API ProgressBarWidget : public BaseWidget - { - friend class Sdk; - - public: - ProgressBarWidget(BaseWidget* parent); - ProgressBarWidget(const ProgressBarWidget&) = delete; - ProgressBarWidget(ProgressBarWidget&&) = default; - ~ProgressBarWidget() = default; - - //virtual ProgressBarWidget* Clone() const = 0; - - inline void EnableText(bool enable = true); - inline void EnableBorder(bool enable = true); - - inline bool IsTextEnabled() const; - inline bool IsBorderEnabled() const; - - - inline unsigned GetPercentageValue() const; - inline Nz::Vector2f GetProgressBarSize() const; - inline Nz::Vector2f GetProgressBarBorderSize() const; - inline float GetTextMargin() const; - - - inline const Nz::Color& GetBarBackgroundColor() const; - inline const Nz::Color& GetBarBackgroundCornerColor() const; - inline const Nz::Color& GetBarColor() const; - inline const Nz::Color& GetBarCornerColor() const; - - inline const Nz::TextureRef& GetBarBackgroundTexture() const; - inline const Nz::TextureRef& GetBarTexture() const; - - static const Nz::Color& GetDefaultBarColor(); - static const Nz::Color& GetDefaultBarCornerColor(); - static const Nz::Color& GetDefaultBarBackgroundColor(); - static const Nz::Color& GetDefaultBarBackgroundCornerColor(); - - - inline void SetBarBackgroundColor(const Nz::Color& globalColor, const Nz::Color& cornerColor); - inline void SetBarBackgroundTexture(Nz::TextureRef texture, bool resetColors = true); - inline void SetBarColor(const Nz::Color& globalColor, const Nz::Color& cornerColor); - inline void SetBarTexture(Nz::TextureRef texture, bool resetColors = true); - - - inline void SetPercentageValue(unsigned percentage); - inline void SetTextMargin(float margin); - inline void SetTextColor(const Nz::Color& color); - - NazaraSignal(OnValueChanged, const ProgressBarWidget* /*progressBar*/); - - private: - void Layout() override; - inline void UpdateText(); - - - EntityHandle m_borderEntity; - EntityHandle m_barEntity; - EntityHandle m_textEntity; - - static Nz::Color s_borderColor; - static Nz::Color s_barBackgroundColor; - static Nz::Color s_barBackgroundCornerColor; - static Nz::Color s_barColor; - static Nz::Color s_barCornerColor; - Nz::Color m_textColor; - - Nz::SpriteRef m_borderSprite; - Nz::SpriteRef m_barBackgroundSprite; - Nz::SpriteRef m_barSprite; - Nz::TextSpriteRef m_textSprite; - - static float s_borderScale; - float m_textMargin; - unsigned m_value; - }; -} - -#include - -#endif // NAZARA_WIDGETS_PROGRESSBARWIDGET_HPP diff --git a/include/Nazara/Widgets/ProgressBarWidget.inl b/include/Nazara/Widgets/ProgressBarWidget.inl deleted file mode 100644 index e88e69390..000000000 --- a/include/Nazara/Widgets/ProgressBarWidget.inl +++ /dev/null @@ -1,155 +0,0 @@ -// Copyright (C) 2022 Samy Bensaid -// This file is part of the "Nazara Engine - Widgets module" -// For conditions of distribution and use, see copyright notice in Config.hpp - -namespace Nz -{ - inline void ProgressBarWidget::EnableText(bool enable) - { - m_textEntity->Enable(enable); - Layout(); - } - - inline void ProgressBarWidget::EnableBorder(bool enable) - { - m_borderEntity->Enable(enable); - } - - inline bool ProgressBarWidget::IsTextEnabled() const - { - return m_textEntity->IsEnabled(); - } - - inline bool ProgressBarWidget::IsBorderEnabled() const - { - return m_borderEntity->IsEnabled(); - } - - - inline unsigned ProgressBarWidget::GetPercentageValue() const - { - return m_value; - } - - inline Nz::Vector2f ProgressBarWidget::GetProgressBarSize() const - { - Nz::Vector3f progressBarSize = m_borderSprite->GetBoundingVolume().obb.localBox.GetLengths(); - - if (IsTextEnabled()) - { - Nz::Vector3f textSize = m_textSprite->GetBoundingVolume().obb.localBox.GetLengths(); - progressBarSize -= { textSize.x + m_textMargin, 0.f, 0.f }; - } - - return { progressBarSize.x, progressBarSize.y }; - } - - inline Nz::Vector2f ProgressBarWidget::GetProgressBarBorderSize() const - { - Nz::Vector2f barSize = GetProgressBarSize(); - return { barSize.y / s_borderScale, barSize.y / s_borderScale }; - } - - inline float ProgressBarWidget::GetTextMargin() const - { - return m_textMargin; - } - - - inline const Nz::Color& ProgressBarWidget::GetBarBackgroundColor() const - { - return m_barBackgroundSprite->GetColor(); - } - - inline const Nz::Color& ProgressBarWidget::GetBarBackgroundCornerColor() const - { - return m_barBackgroundSprite->GetCornerColor(Nz::RectCorner_LeftTop); - } - - inline const Nz::Color& ProgressBarWidget::GetBarColor() const - { - return m_barSprite->GetColor(); - } - - inline const Nz::Color& ProgressBarWidget::GetBarCornerColor() const - { - return m_barSprite->GetCornerColor(Nz::RectCorner_LeftTop); - } - - - inline const Nz::TextureRef& ProgressBarWidget::GetBarBackgroundTexture() const - { - return m_barBackgroundSprite->GetMaterial()->GetDiffuseMap(); - } - - inline const Nz::TextureRef& ProgressBarWidget::GetBarTexture() const - { - return m_barSprite->GetMaterial()->GetDiffuseMap(); - } - - - inline void ProgressBarWidget::SetBarBackgroundColor(const Nz::Color& globalColor, const Nz::Color& cornerColor) - { - m_barBackgroundSprite->SetColor(globalColor); - m_barBackgroundSprite->SetCornerColor(Nz::RectCorner_LeftTop, cornerColor); - m_barBackgroundSprite->SetCornerColor(Nz::RectCorner_RightTop, cornerColor); - m_barBackgroundSprite->SetCornerColor(Nz::RectCorner_LeftBottom, globalColor); - m_barBackgroundSprite->SetCornerColor(Nz::RectCorner_RightBottom, globalColor); - } - - inline void ProgressBarWidget::SetBarBackgroundTexture(Nz::TextureRef texture, bool resetColors) - { - m_barBackgroundSprite->SetTexture(texture, false); - - if (resetColors) - SetBarBackgroundColor(Nz::Color::White, Nz::Color::White); - } - - inline void ProgressBarWidget::SetBarColor(const Nz::Color& globalColor, const Nz::Color& cornerColor) - { - m_barSprite->SetColor(globalColor); - m_barSprite->SetCornerColor(Nz::RectCorner_LeftTop, cornerColor); - m_barSprite->SetCornerColor(Nz::RectCorner_RightTop, cornerColor); - m_barSprite->SetCornerColor(Nz::RectCorner_LeftBottom, globalColor); - m_barSprite->SetCornerColor(Nz::RectCorner_RightBottom, globalColor); - } - - inline void ProgressBarWidget::SetBarTexture(Nz::TextureRef texture, bool resetColors) - { - m_barSprite->SetTexture(texture, false); - - if (resetColors) - SetBarColor(Nz::Color::White, Nz::Color::White); - } - - - inline void ProgressBarWidget::SetPercentageValue(unsigned percentage) - { - m_value = percentage; - OnValueChanged(this); - Layout(); - } - - inline void ProgressBarWidget::SetTextMargin(float margin) - { - m_textMargin = margin; - - if (IsTextEnabled()) - Layout(); - } - - inline void ProgressBarWidget::SetTextColor(const Nz::Color& color) - { - m_textColor = color; - UpdateText(); - } - - inline void ProgressBarWidget::UpdateText() - { - if (IsTextEnabled()) - { - Nz::Vector2f size = GetSize(); - m_textSprite->Update(Nz::SimpleTextDrawer::Draw(Nz::String::Number(m_value).Append('%'), static_cast(std::min(size.x, size.y) / 2.f), 0u, m_textColor)); - } - } -} diff --git a/src/Nazara/Widgets/ProgressBarWidget.cpp b/src/Nazara/Widgets/ProgressBarWidget.cpp deleted file mode 100644 index a3b1945ac..000000000 --- a/src/Nazara/Widgets/ProgressBarWidget.cpp +++ /dev/null @@ -1,106 +0,0 @@ -// Copyright (C) 2022 Samy Bensaid -// This file is part of the "Nazara Engine - Widgets module" -// For conditions of distribution and use, see copyright notice in Config.hpp - -#if 0 - -#include -#include -#include -#include -#include - -namespace Nz -{ - float ProgressBarWidget::s_borderScale { 16.f }; - Nz::Color ProgressBarWidget::s_borderColor { Nz::Color::Black }; - Nz::Color ProgressBarWidget::s_barBackgroundColor { Nz::Color { 225, 225, 225 } }; - Nz::Color ProgressBarWidget::s_barBackgroundCornerColor { Nz::Color { 255, 255, 255 } }; - Nz::Color ProgressBarWidget::s_barColor { Nz::Color { 0, 225, 0 } }; - Nz::Color ProgressBarWidget::s_barCornerColor { Nz::Color { 220, 255, 220 } }; - - ProgressBarWidget::ProgressBarWidget(BaseWidget* parent) : - BaseWidget(parent), - m_textColor { Nz::Color::Black }, - m_textMargin { 16.f }, - m_value { 0u } - { - m_borderSprite = Nz::Sprite::New(Nz::Material::New("Basic2D")); - m_barBackgroundSprite = Nz::Sprite::New(Nz::Material::New("Basic2D")); - m_barSprite = Nz::Sprite::New(Nz::Material::New("Basic2D")); - - m_borderSprite->SetColor(s_borderColor); - SetBarBackgroundColor(s_barBackgroundColor, s_barBackgroundCornerColor); - SetBarColor(s_barColor, s_barCornerColor); - - - m_borderEntity = CreateEntity(); - m_borderEntity->AddComponent().SetParent(this); - m_borderEntity->AddComponent().Attach(m_borderSprite); - - m_barEntity = CreateEntity(); - m_barEntity->AddComponent().SetParent(this); - GraphicsComponent& graphics = m_barEntity->AddComponent(); - - graphics.Attach(m_barBackgroundSprite, 1); - graphics.Attach(m_barSprite, 2); - - - m_textSprite = Nz::TextSprite::New(); - m_textEntity = CreateEntity(); - - m_textEntity->AddComponent().SetParent(this); - m_textEntity->AddComponent().Attach(m_textSprite); - - UpdateText(); - Layout(); - } - - - const Nz::Color& ProgressBarWidget::GetDefaultBarColor() - { - return s_barColor; - } - - const Nz::Color& ProgressBarWidget::GetDefaultBarCornerColor() - { - return s_barCornerColor; - } - - const Nz::Color& ProgressBarWidget::GetDefaultBarBackgroundColor() - { - return s_barBackgroundColor; - } - - const Nz::Color& ProgressBarWidget::GetDefaultBarBackgroundCornerColor() - { - return s_barBackgroundCornerColor; - } - - - void ProgressBarWidget::Layout() - { - Nz::Vector2f size = GetSize(); - Nz::Vector2f progressBarSize = size; - - if (IsTextEnabled()) - { - UpdateText(); - - Nz::Vector3f textSize = m_textSprite->GetBoundingVolume().obb.localBox.GetLengths(); - m_textEntity->GetComponent().SetPosition(size.x - textSize.x, size.y / 2.f - textSize.y); - - progressBarSize -= { textSize.x + m_textMargin, 0.f }; - } - - m_borderSprite->SetSize(progressBarSize); - Nz::Vector2f borderSize = GetProgressBarBorderSize(); - - m_barBackgroundSprite->SetSize(progressBarSize - (borderSize * 2.f)); - m_barSprite->SetSize((progressBarSize.x - (borderSize.x * 2.f)) / 100.f * static_cast(m_value), progressBarSize.y - (borderSize.y * 2.f)); - - m_barEntity->GetComponent().SetPosition(borderSize.x, borderSize.y); - } -} - -#endif