WIP
This commit is contained in:
committed by
Jérôme Leclercq
parent
481702c109
commit
05c78da22a
41
include/Nazara/Widgets/BoxLayout.hpp
Normal file
41
include/Nazara/Widgets/BoxLayout.hpp
Normal file
@@ -0,0 +1,41 @@
|
||||
// Copyright (C) 2022 Jérôme "Lynix" Leclercq (lynix680@gmail.com)
|
||||
// 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_BOXLAYOUT_HPP
|
||||
#define NAZARA_WIDGETS_BOXLAYOUT_HPP
|
||||
|
||||
#include <NDK/BaseWidget.hpp>
|
||||
#include <NDK/ClientPrerequisites.hpp>
|
||||
#include <NDK/Widgets/Enums.hpp>
|
||||
#include <memory>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
class NDK_CLIENT_API BoxLayout : public BaseWidget
|
||||
{
|
||||
public:
|
||||
BoxLayout(BaseWidget* parent, BoxLayoutOrientation orientation);
|
||||
BoxLayout(const BoxLayout&) = delete;
|
||||
BoxLayout(BoxLayout&&) = delete;
|
||||
~BoxLayout();
|
||||
|
||||
void Layout() override;
|
||||
|
||||
BoxLayout& operator=(const BoxLayout&) = delete;
|
||||
BoxLayout& operator=(BoxLayout&&) = delete;
|
||||
|
||||
private:
|
||||
struct State;
|
||||
|
||||
std::unique_ptr<State> m_state;
|
||||
BoxLayoutOrientation m_orientation;
|
||||
float m_spacing;
|
||||
};
|
||||
}
|
||||
|
||||
#include <NDK/Widgets/BoxLayout.inl>
|
||||
|
||||
#endif // NAZARA_WIDGETS_BOXLAYOUT_HPP
|
||||
13
include/Nazara/Widgets/BoxLayout.inl
Normal file
13
include/Nazara/Widgets/BoxLayout.inl
Normal file
@@ -0,0 +1,13 @@
|
||||
// Copyright (C) 2022 Jérôme "Lynix" Leclercq (lynix680@gmail.com)
|
||||
// This file is part of the "Nazara Engine - Widgets module"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#include <Nazara/Widgets/BoxLayout.hpp>
|
||||
#include <NDK/Widgets/BoxLayout.hpp>
|
||||
#include <Nazara/Widgets/Debug.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
}
|
||||
|
||||
#include <Nazara/Widgets/DebugOff.hpp>
|
||||
@@ -23,8 +23,12 @@ namespace Nz
|
||||
~DefaultWidgetTheme() = default;
|
||||
|
||||
std::unique_ptr<ButtonWidgetStyle> CreateStyle(ButtonWidget* buttonWidget) const override;
|
||||
std::unique_ptr<CheckboxWidgetStyle> CreateStyle(CheckboxWidget* buttonWidget) const override;
|
||||
std::unique_ptr<LabelWidgetStyle> CreateStyle(LabelWidget* buttonWidget) const override;
|
||||
std::unique_ptr<CheckboxWidgetStyle> CreateStyle(CheckboxWidget* checkboxWidget) const override;
|
||||
std::unique_ptr<ImageButtonWidgetStyle> CreateStyle(ImageButtonWidget* imageButtonWidget) const override;
|
||||
std::unique_ptr<LabelWidgetStyle> CreateStyle(LabelWidget* labelWidget) const override;
|
||||
std::unique_ptr<ScrollAreaWidgetStyle> CreateStyle(ScrollAreaWidget* scrollAreaWidget) const override;
|
||||
std::unique_ptr<ScrollbarWidgetStyle> CreateStyle(ScrollbarWidget* scrollbarWidget) const override;
|
||||
std::unique_ptr<ScrollbarButtonWidgetStyle> CreateStyle(ScrollbarButtonWidget* scrollbarButtonWidget) const override;
|
||||
|
||||
DefaultWidgetTheme& operator=(const DefaultWidgetTheme&) = delete;
|
||||
DefaultWidgetTheme& operator=(DefaultWidgetTheme&&) = default;
|
||||
@@ -38,6 +42,12 @@ namespace Nz
|
||||
std::shared_ptr<Material> m_checkboxBackgroundHoveredMaterial;
|
||||
std::shared_ptr<Material> m_checkboxCheckMaterial;
|
||||
std::shared_ptr<Material> m_checkboxTristateMaterial;
|
||||
std::shared_ptr<Material> m_hoveredMaterial;
|
||||
std::shared_ptr<Material> m_scrollbarBackgroundHorizontalMaterial;
|
||||
std::shared_ptr<Material> m_scrollbarBackgroundVerticalMaterial;
|
||||
std::shared_ptr<Material> m_scrollbarButtonMaterial;
|
||||
std::shared_ptr<Material> m_scrollbarButtonHoveredMaterial;
|
||||
std::shared_ptr<Material> m_scrollbarButtonGrabbedMaterial;
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -32,6 +32,12 @@ namespace Nz
|
||||
|
||||
Max = Normal
|
||||
};
|
||||
|
||||
enum class ScrollbarOrientation
|
||||
{
|
||||
Horizontal,
|
||||
Vertical
|
||||
};
|
||||
}
|
||||
|
||||
#endif // NAZARA_WIDGETS_ENUMS_HPP
|
||||
|
||||
76
include/Nazara/Widgets/ImageButtonWidget.hpp
Normal file
76
include/Nazara/Widgets/ImageButtonWidget.hpp
Normal file
@@ -0,0 +1,76 @@
|
||||
// Copyright (C) 2022 Jérôme "Lynix" Leclercq (lynix680@gmail.com)
|
||||
// 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_IMAGEBUTTONWIDGET_HPP
|
||||
#define NAZARA_WIDGETS_IMAGEBUTTONWIDGET_HPP
|
||||
|
||||
#include <Nazara/Core/Color.hpp>
|
||||
#include <Nazara/Graphics/SlicedSprite.hpp>
|
||||
#include <Nazara/Graphics/TextSprite.hpp>
|
||||
#include <Nazara/Widgets/BaseWidget.hpp>
|
||||
#include <Nazara/Widgets/WidgetTheme.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
class AbstractTextDrawer;
|
||||
class MaterialPass;
|
||||
|
||||
class NAZARA_WIDGETS_API ImageButtonWidget : public BaseWidget
|
||||
{
|
||||
public:
|
||||
inline ImageButtonWidget(BaseWidget* parent, std::shared_ptr<Material> material);
|
||||
inline ImageButtonWidget(BaseWidget* parent, std::shared_ptr<Material> material, float cornerSize, float cornerTexCoords);
|
||||
ImageButtonWidget(BaseWidget* parent, std::shared_ptr<Material> material, std::shared_ptr<Material> hoveredMaterial, std::shared_ptr<Material> pressedMaterial, float cornerSize, float cornerTexCoords);
|
||||
ImageButtonWidget(const ImageButtonWidget&) = delete;
|
||||
ImageButtonWidget(ImageButtonWidget&&) = default;
|
||||
~ImageButtonWidget() = default;
|
||||
|
||||
inline const Color& GetColor() const;
|
||||
inline float GetCornerSize() const;
|
||||
inline float GetCornerTexCoords() const;
|
||||
inline const std::shared_ptr<Material>& GetHoveredMaterial() const;
|
||||
inline const std::shared_ptr<Material>& GetMaterial() const;
|
||||
inline const std::shared_ptr<Material>& GetPressedMaterial() const;
|
||||
inline const Rectf& GetTextureCoords() const;
|
||||
|
||||
inline void SetColor(const Color& color);
|
||||
inline void SetCorner(float size, float texcoords);
|
||||
inline void SetHoveredMaterial(std::shared_ptr<Material> material);
|
||||
inline void SetMaterial(std::shared_ptr<Material> material);
|
||||
inline void SetPressedMaterial(std::shared_ptr<Material> material);
|
||||
inline void SetTextureCoords(const Rectf& coords);
|
||||
|
||||
ImageButtonWidget& operator=(const ImageButtonWidget&) = delete;
|
||||
ImageButtonWidget& operator=(ImageButtonWidget&&) = default;
|
||||
|
||||
NazaraSignal(OnButtonTrigger, const ImageButtonWidget* /*button*/);
|
||||
|
||||
private:
|
||||
void Layout() override;
|
||||
|
||||
void OnMouseEnter() override;
|
||||
void OnMouseButtonPress(int x, int y, Mouse::Button button) override;
|
||||
void OnMouseButtonRelease(int x, int y, Mouse::Button button) override;
|
||||
void OnMouseExit() override;
|
||||
|
||||
void OnRenderLayerUpdated(int baseRenderLayer) override;
|
||||
|
||||
void UpdatePreferredSize();
|
||||
|
||||
std::unique_ptr<ImageButtonWidgetStyle> m_style;
|
||||
std::shared_ptr<Material> m_hoveredMaterial;
|
||||
std::shared_ptr<Material> m_material;
|
||||
std::shared_ptr<Material> m_pressedMaterial;
|
||||
Color m_color;
|
||||
Rectf m_textureCoords;
|
||||
float m_cornerSize;
|
||||
float m_cornerTexCoords;
|
||||
};
|
||||
}
|
||||
|
||||
#include <Nazara/Widgets/ImageButtonWidget.inl>
|
||||
|
||||
#endif // NAZARA_WIDGETS_IMAGEBUTTONWIDGET_HPP
|
||||
101
include/Nazara/Widgets/ImageButtonWidget.inl
Normal file
101
include/Nazara/Widgets/ImageButtonWidget.inl
Normal file
@@ -0,0 +1,101 @@
|
||||
// Copyright (C) 2022 Jérôme "Lynix" Leclercq (lynix680@gmail.com)
|
||||
// This file is part of the "Nazara Engine - Widgets module"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#include <Nazara/Widgets/ImageButtonWidget.hpp>
|
||||
#include <Nazara/Widgets/Debug.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
inline ImageButtonWidget::ImageButtonWidget(BaseWidget* parent, std::shared_ptr<Material> material) :
|
||||
ImageButtonWidget(parent, std::move(material), {}, {}, 0.f, 0.f)
|
||||
{
|
||||
}
|
||||
|
||||
inline ImageButtonWidget::ImageButtonWidget(BaseWidget* parent, std::shared_ptr<Material> material, float cornerSize, float cornerTexCoords) :
|
||||
ImageButtonWidget(parent, std::move(material), {}, {}, cornerSize, cornerTexCoords)
|
||||
{
|
||||
}
|
||||
|
||||
inline const Color& ImageButtonWidget::GetColor() const
|
||||
{
|
||||
return m_color;
|
||||
}
|
||||
|
||||
inline float ImageButtonWidget::GetCornerSize() const
|
||||
{
|
||||
return m_cornerSize;
|
||||
}
|
||||
|
||||
inline float ImageButtonWidget::GetCornerTexCoords() const
|
||||
{
|
||||
return m_cornerTexCoords;
|
||||
}
|
||||
|
||||
inline const std::shared_ptr<Material>& ImageButtonWidget::GetHoveredMaterial() const
|
||||
{
|
||||
return m_hoveredMaterial;
|
||||
}
|
||||
|
||||
inline const std::shared_ptr<Material>& ImageButtonWidget::GetMaterial() const
|
||||
{
|
||||
return m_material;
|
||||
}
|
||||
|
||||
inline const std::shared_ptr<Material>& ImageButtonWidget::GetPressedMaterial() const
|
||||
{
|
||||
return m_pressedMaterial;
|
||||
}
|
||||
|
||||
inline const Rectf& ImageButtonWidget::GetTextureCoords() const
|
||||
{
|
||||
return m_textureCoords;
|
||||
}
|
||||
|
||||
inline void ImageButtonWidget::SetColor(const Color& color)
|
||||
{
|
||||
m_color = color;
|
||||
|
||||
m_style->OnUpdate();
|
||||
}
|
||||
|
||||
inline void ImageButtonWidget::SetCorner(float size, float texcoords)
|
||||
{
|
||||
m_cornerSize = size;
|
||||
m_cornerTexCoords = texcoords;
|
||||
|
||||
m_style->OnUpdate();
|
||||
}
|
||||
|
||||
inline void ImageButtonWidget::SetHoveredMaterial(std::shared_ptr<Material> material)
|
||||
{
|
||||
m_hoveredMaterial = std::move(material);
|
||||
|
||||
m_style->OnUpdate();
|
||||
}
|
||||
|
||||
inline void ImageButtonWidget::SetMaterial(std::shared_ptr<Material> material)
|
||||
{
|
||||
m_material = std::move(material);
|
||||
UpdatePreferredSize();
|
||||
|
||||
m_style->OnUpdate();
|
||||
}
|
||||
|
||||
inline void ImageButtonWidget::SetPressedMaterial(std::shared_ptr<Material> material)
|
||||
{
|
||||
m_pressedMaterial = std::move(material);
|
||||
|
||||
m_style->OnUpdate();
|
||||
}
|
||||
|
||||
inline void ImageButtonWidget::SetTextureCoords(const Rectf& coords)
|
||||
{
|
||||
m_textureCoords = coords;
|
||||
UpdatePreferredSize();
|
||||
|
||||
m_style->OnUpdate();
|
||||
}
|
||||
}
|
||||
|
||||
#include <Nazara/Widgets/DebugOff.hpp>
|
||||
@@ -17,7 +17,7 @@ namespace Nz
|
||||
class NAZARA_WIDGETS_API ImageWidget : public BaseWidget
|
||||
{
|
||||
public:
|
||||
ImageWidget(BaseWidget* parent);
|
||||
ImageWidget(BaseWidget* parent, std::shared_ptr<Material> material);
|
||||
ImageWidget(const ImageWidget&) = delete;
|
||||
ImageWidget(ImageWidget&&) = default;
|
||||
~ImageWidget() = default;
|
||||
@@ -36,6 +36,7 @@ namespace Nz
|
||||
|
||||
private:
|
||||
void Layout() override;
|
||||
inline void UpdatePreferredSize();
|
||||
|
||||
entt::entity m_entity;
|
||||
std::shared_ptr<Sprite> m_sprite;
|
||||
|
||||
@@ -30,7 +30,23 @@ namespace Nz
|
||||
inline void ImageWidget::SetMaterial(const std::shared_ptr<Material>& texture)
|
||||
{
|
||||
m_sprite->SetMaterial(texture);
|
||||
UpdatePreferredSize();
|
||||
}
|
||||
|
||||
inline void ImageWidget::SetTextureCoords(const Rectf& coords)
|
||||
{
|
||||
m_sprite->SetTextureCoords(coords);
|
||||
UpdatePreferredSize();
|
||||
}
|
||||
|
||||
inline void ImageWidget::SetTextureRect(const Rectf& rect)
|
||||
{
|
||||
m_sprite->SetTextureRect(rect);
|
||||
UpdatePreferredSize();
|
||||
}
|
||||
|
||||
inline void ImageWidget::UpdatePreferredSize()
|
||||
{
|
||||
const Rectf& textureCoords = GetTextureCoords();
|
||||
|
||||
Vector2f textureSize = Vector2f(Vector2ui(m_sprite->GetTextureSize()));
|
||||
@@ -39,16 +55,6 @@ namespace Nz
|
||||
|
||||
SetPreferredSize(textureSize);
|
||||
}
|
||||
|
||||
inline void ImageWidget::SetTextureCoords(const Rectf& coords)
|
||||
{
|
||||
m_sprite->SetTextureCoords(coords);
|
||||
}
|
||||
|
||||
inline void ImageWidget::SetTextureRect(const Rectf& rect)
|
||||
{
|
||||
m_sprite->SetTextureRect(rect);
|
||||
}
|
||||
}
|
||||
|
||||
#include <Nazara/Widgets/DebugOff.hpp>
|
||||
|
||||
101
include/Nazara/Widgets/ProgressBarWidget.hpp
Normal file
101
include/Nazara/Widgets/ProgressBarWidget.hpp
Normal file
@@ -0,0 +1,101 @@
|
||||
// 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 <Nazara/Core/Color.hpp>
|
||||
#include <Nazara/Graphics/Sprite.hpp>
|
||||
#include <Nazara/Graphics/TextSprite.hpp>
|
||||
#include <Nazara/Math/Vector2.hpp>
|
||||
#include <Nazara/Renderer/Texture.hpp>
|
||||
#include <Nazara/Utility/SimpleTextDrawer.hpp>
|
||||
#include <NDK/BaseWidget.hpp>
|
||||
#include <NDK/ClientPrerequisites.hpp>
|
||||
|
||||
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 <NDK/Widgets/ProgressBarWidget.inl>
|
||||
|
||||
#endif // NAZARA_WIDGETS_PROGRESSBARWIDGET_HPP
|
||||
155
include/Nazara/Widgets/ProgressBarWidget.inl
Normal file
155
include/Nazara/Widgets/ProgressBarWidget.inl
Normal file
@@ -0,0 +1,155 @@
|
||||
// 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<unsigned int>(std::min(size.x, size.y) / 2.f), 0u, m_textColor));
|
||||
}
|
||||
}
|
||||
}
|
||||
66
include/Nazara/Widgets/ScrollAreaWidget.hpp
Normal file
66
include/Nazara/Widgets/ScrollAreaWidget.hpp
Normal file
@@ -0,0 +1,66 @@
|
||||
// Copyright (C) 2022 Jérôme "Lynix" Leclercq (lynix680@gmail.com)
|
||||
// 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_SCROLLAREAWIDGET_HPP
|
||||
#define NAZARA_WIDGETS_SCROLLAREAWIDGET_HPP
|
||||
|
||||
#include <Nazara/Graphics/TextSprite.hpp>
|
||||
#include <Nazara/Widgets/BaseWidget.hpp>
|
||||
#include <Nazara/Widgets/WidgetTheme.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
class NAZARA_WIDGETS_API ScrollAreaWidget : public BaseWidget
|
||||
{
|
||||
public:
|
||||
ScrollAreaWidget(BaseWidget* parent, BaseWidget* content);
|
||||
ScrollAreaWidget(const ScrollAreaWidget&) = delete;
|
||||
ScrollAreaWidget(ScrollAreaWidget&&) = default;
|
||||
~ScrollAreaWidget() = default;
|
||||
|
||||
void EnableScrollbar(bool enable);
|
||||
|
||||
inline float GetScrollHeight() const;
|
||||
inline float GetScrollRatio() const;
|
||||
|
||||
inline bool HasScrollbar() const;
|
||||
inline bool IsScrollbarEnabled() const;
|
||||
inline bool IsScrollbarVisible() const;
|
||||
|
||||
inline void ScrollToHeight(float height);
|
||||
void ScrollToRatio(float ratio);
|
||||
|
||||
ScrollAreaWidget& operator=(const ScrollAreaWidget&) = delete;
|
||||
ScrollAreaWidget& operator=(ScrollAreaWidget&&) = default;
|
||||
|
||||
private:
|
||||
Nz::Rectf GetScrollbarRect() const;
|
||||
|
||||
void Layout() 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;
|
||||
void OnMouseMoved(int x, int y, int deltaX, int deltaY) override;
|
||||
void OnMouseWheelMoved(int x, int y, float delta) override;
|
||||
|
||||
std::unique_ptr<ScrollAreaWidgetStyle> m_style;
|
||||
BaseWidget* m_content;
|
||||
EntityHandle m_scrollbarBackgroundEntity;
|
||||
EntityHandle m_scrollbarEntity;
|
||||
Nz::SpriteRef m_scrollbarBackgroundSprite;
|
||||
Nz::SpriteRef m_scrollbarSprite;
|
||||
Nz::Vector2i m_grabbedDelta;
|
||||
bool m_isGrabbed;
|
||||
bool m_isScrollbarEnabled;
|
||||
bool m_hasScrollbar;
|
||||
float m_scrollRatio;
|
||||
};
|
||||
}
|
||||
|
||||
#include <Nazara/Widgets/ScrollAreaWidget.inl>
|
||||
|
||||
#endif // NAZARA_WIDGETS_SCROLLAREAWIDGET_HPP
|
||||
43
include/Nazara/Widgets/ScrollAreaWidget.inl
Normal file
43
include/Nazara/Widgets/ScrollAreaWidget.inl
Normal file
@@ -0,0 +1,43 @@
|
||||
// Copyright (C) 2022 Jérôme "Lynix" Leclercq (lynix680@gmail.com)
|
||||
// This file is part of the "Nazara Engine - Widgets module"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#include <Nazara/Widgets/ScrollAreaWidget.hpp>
|
||||
#include <NDK/Widgets/ScrollAreaWidget.hpp>
|
||||
#include <Nazara/Widgets/Debug.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
inline float ScrollAreaWidget::GetScrollHeight() const
|
||||
{
|
||||
return m_scrollRatio * m_content->GetHeight();
|
||||
}
|
||||
|
||||
inline float ScrollAreaWidget::GetScrollRatio() const
|
||||
{
|
||||
return m_scrollRatio;
|
||||
}
|
||||
|
||||
inline bool ScrollAreaWidget::HasScrollbar() const
|
||||
{
|
||||
return m_hasScrollbar;
|
||||
}
|
||||
|
||||
inline bool ScrollAreaWidget::IsScrollbarEnabled() const
|
||||
{
|
||||
return m_isScrollbarEnabled;
|
||||
}
|
||||
|
||||
inline bool ScrollAreaWidget::IsScrollbarVisible() const
|
||||
{
|
||||
return HasScrollbar() && IsScrollbarEnabled();
|
||||
}
|
||||
|
||||
inline void ScrollAreaWidget::ScrollToHeight(float height)
|
||||
{
|
||||
float contentHeight = m_content->GetHeight();
|
||||
ScrollToRatio(height / contentHeight);
|
||||
}
|
||||
}
|
||||
|
||||
#include <Nazara/Widgets/DebugOff.hpp>
|
||||
54
include/Nazara/Widgets/ScrollbarButtonWidget.hpp
Normal file
54
include/Nazara/Widgets/ScrollbarButtonWidget.hpp
Normal file
@@ -0,0 +1,54 @@
|
||||
// Copyright (C) 2022 Jérôme "Lynix" Leclercq (lynix680@gmail.com)
|
||||
// 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_SCROLLBARBUTTONWIDGET_HPP
|
||||
#define NAZARA_WIDGETS_SCROLLBARBUTTONWIDGET_HPP
|
||||
|
||||
#include <Nazara/Core/Color.hpp>
|
||||
#include <Nazara/Graphics/SlicedSprite.hpp>
|
||||
#include <Nazara/Graphics/TextSprite.hpp>
|
||||
#include <Nazara/Widgets/BaseWidget.hpp>
|
||||
#include <Nazara/Widgets/WidgetTheme.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
class AbstractTextDrawer;
|
||||
class MaterialPass;
|
||||
|
||||
class NAZARA_WIDGETS_API ScrollbarButtonWidget : public BaseWidget
|
||||
{
|
||||
public:
|
||||
inline ScrollbarButtonWidget(BaseWidget* parent);
|
||||
ScrollbarButtonWidget(const ScrollbarButtonWidget&) = delete;
|
||||
ScrollbarButtonWidget(ScrollbarButtonWidget&&) = default;
|
||||
~ScrollbarButtonWidget() = default;
|
||||
|
||||
ScrollbarButtonWidget& operator=(const ScrollbarButtonWidget&) = delete;
|
||||
ScrollbarButtonWidget& operator=(ScrollbarButtonWidget&&) = default;
|
||||
|
||||
NazaraSignal(OnButtonGrabbed, ScrollbarButtonWidget* /*emitter*/, int /*x*/, int /*y*/);
|
||||
NazaraSignal(OnButtonMoved, ScrollbarButtonWidget* /*emitter*/, int /*x*/, int /*y*/);
|
||||
NazaraSignal(OnButtonReleased, ScrollbarButtonWidget* /*emitter*/);
|
||||
|
||||
private:
|
||||
void Layout() override;
|
||||
|
||||
void OnMouseEnter() override;
|
||||
void OnMouseButtonPress(int x, int y, Mouse::Button button) override;
|
||||
void OnMouseButtonRelease(int x, int y, Mouse::Button button) override;
|
||||
void OnMouseExit() override;
|
||||
void OnMouseMoved(int x, int y, int deltaX, int deltaY) override;
|
||||
|
||||
void OnRenderLayerUpdated(int baseRenderLayer) override;
|
||||
|
||||
std::unique_ptr<ScrollbarButtonWidgetStyle> m_style;
|
||||
bool m_isGrabbed;
|
||||
};
|
||||
}
|
||||
|
||||
#include <Nazara/Widgets/ScrollbarButtonWidget.inl>
|
||||
|
||||
#endif // NAZARA_WIDGETS_SCROLLBARBUTTONWIDGET_HPP
|
||||
12
include/Nazara/Widgets/ScrollbarButtonWidget.inl
Normal file
12
include/Nazara/Widgets/ScrollbarButtonWidget.inl
Normal file
@@ -0,0 +1,12 @@
|
||||
// Copyright (C) 2022 Jérôme "Lynix" Leclercq (lynix680@gmail.com)
|
||||
// This file is part of the "Nazara Engine - Widgets module"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#include <Nazara/Widgets/ScrollbarButtonWidget.hpp>
|
||||
#include <Nazara/Widgets/Debug.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
}
|
||||
|
||||
#include <Nazara/Widgets/DebugOff.hpp>
|
||||
60
include/Nazara/Widgets/ScrollbarWidget.hpp
Normal file
60
include/Nazara/Widgets/ScrollbarWidget.hpp
Normal file
@@ -0,0 +1,60 @@
|
||||
// Copyright (C) 2022 Jérôme "Lynix" Leclercq (lynix680@gmail.com)
|
||||
// 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_SCROLLBARWIDGET_HPP
|
||||
#define NAZARA_WIDGETS_SCROLLBARWIDGET_HPP
|
||||
|
||||
#include <Nazara/Graphics/TextSprite.hpp>
|
||||
#include <Nazara/Widgets/BaseWidget.hpp>
|
||||
#include <Nazara/Widgets/WidgetTheme.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
class NAZARA_WIDGETS_API ScrollbarWidget : public BaseWidget
|
||||
{
|
||||
public:
|
||||
ScrollbarWidget(BaseWidget* parent, ScrollbarOrientation orientation);
|
||||
ScrollbarWidget(const ScrollbarWidget&) = delete;
|
||||
ScrollbarWidget(ScrollbarWidget&&) = default;
|
||||
~ScrollbarWidget() = default;
|
||||
|
||||
inline ScrollbarOrientation GetOrientation() const;
|
||||
inline float GetMaximumValue() const;
|
||||
inline float GetMinimumValue() const;
|
||||
inline float GetStep() const;
|
||||
inline float GetValue() const;
|
||||
|
||||
inline void SetValue(float newValue);
|
||||
|
||||
ScrollbarWidget& operator=(const ScrollbarWidget&) = delete;
|
||||
ScrollbarWidget& operator=(ScrollbarWidget&&) = default;
|
||||
|
||||
private:
|
||||
void Layout() override;
|
||||
|
||||
void OnMouseEnter() override;
|
||||
void OnMouseExit() override;
|
||||
|
||||
void OnRenderLayerUpdated(int baseRenderLayer);
|
||||
|
||||
std::unique_ptr<ScrollbarWidgetStyle> m_style;
|
||||
ImageButtonWidget* m_scrollBackButton;
|
||||
ImageButtonWidget* m_scrollNextButton;
|
||||
ScrollbarButtonWidget* m_scrollCenterButton;
|
||||
ScrollbarOrientation m_orientation;
|
||||
bool m_isGrabbed;
|
||||
float m_maximumValue;
|
||||
float m_minimumValue;
|
||||
float m_step;
|
||||
float m_value;
|
||||
float m_grabbedValue;
|
||||
int m_grabbedPosition;
|
||||
};
|
||||
}
|
||||
|
||||
#include <Nazara/Widgets/ScrollbarWidget.inl>
|
||||
|
||||
#endif // NAZARA_WIDGETS_SCROLLBARWIDGET_HPP
|
||||
44
include/Nazara/Widgets/ScrollbarWidget.inl
Normal file
44
include/Nazara/Widgets/ScrollbarWidget.inl
Normal file
@@ -0,0 +1,44 @@
|
||||
// Copyright (C) 2022 Jérôme "Lynix" Leclercq (lynix680@gmail.com)
|
||||
// This file is part of the "Nazara Engine - Widgets module"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#include <Nazara/Widgets/ScrollbarWidget.hpp>
|
||||
#include <Nazara/Utils/Algorithm.hpp>
|
||||
#include <Nazara/Widgets/Debug.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
inline ScrollbarOrientation ScrollbarWidget::GetOrientation() const
|
||||
{
|
||||
return m_orientation;
|
||||
}
|
||||
|
||||
inline float ScrollbarWidget::GetMaximumValue() const
|
||||
{
|
||||
return m_maximumValue;
|
||||
}
|
||||
|
||||
inline float ScrollbarWidget::GetMinimumValue() const
|
||||
{
|
||||
return m_minimumValue;
|
||||
}
|
||||
|
||||
inline float ScrollbarWidget::GetStep() const
|
||||
{
|
||||
return m_step;
|
||||
}
|
||||
|
||||
inline float ScrollbarWidget::GetValue() const
|
||||
{
|
||||
return m_value;
|
||||
}
|
||||
|
||||
inline void ScrollbarWidget::SetValue(float newValue)
|
||||
{
|
||||
m_value = Clamp(newValue, m_minimumValue, m_maximumValue);
|
||||
|
||||
Layout();
|
||||
}
|
||||
}
|
||||
|
||||
#include <Nazara/Widgets/DebugOff.hpp>
|
||||
@@ -7,6 +7,7 @@
|
||||
#ifndef NAZARA_WIDGETS_SIMPLEWIDGETSTYLES_HPP
|
||||
#define NAZARA_WIDGETS_SIMPLEWIDGETSTYLES_HPP
|
||||
|
||||
#include <Nazara/Graphics/LinearSlicedSprite.hpp>
|
||||
#include <Nazara/Graphics/SlicedSprite.hpp>
|
||||
#include <Nazara/Graphics/TextSprite.hpp>
|
||||
#include <Nazara/Widgets/WidgetTheme.hpp>
|
||||
@@ -108,7 +109,48 @@ namespace Nz
|
||||
entt::entity m_checkEntity;
|
||||
bool m_isHovered;
|
||||
};
|
||||
|
||||
class NAZARA_WIDGETS_API SimpleImageButtonWidgetStyle : public ImageButtonWidgetStyle
|
||||
{
|
||||
public:
|
||||
struct StyleConfig;
|
||||
|
||||
SimpleImageButtonWidgetStyle(ImageButtonWidget* imageButtonWidget, StyleConfig config);
|
||||
SimpleImageButtonWidgetStyle(const SimpleImageButtonWidgetStyle&) = delete;
|
||||
SimpleImageButtonWidgetStyle(SimpleImageButtonWidgetStyle&&) = default;
|
||||
~SimpleImageButtonWidgetStyle() = default;
|
||||
|
||||
void Layout(const Vector2f& size) override;
|
||||
|
||||
void OnHoverBegin() override;
|
||||
void OnHoverEnd() override;
|
||||
void OnPress() override;
|
||||
void OnRelease() override;
|
||||
void OnUpdate() override;
|
||||
|
||||
void UpdateRenderLayer(int baseRenderLayer) override;
|
||||
|
||||
SimpleImageButtonWidgetStyle& operator=(const SimpleImageButtonWidgetStyle&) = delete;
|
||||
SimpleImageButtonWidgetStyle& operator=(SimpleImageButtonWidgetStyle&&) = default;
|
||||
|
||||
struct StyleConfig
|
||||
{
|
||||
std::shared_ptr<Material> hoveredMaterial;
|
||||
float hoveredCornerSize;
|
||||
float hoveredCornerTexCoords;
|
||||
};
|
||||
|
||||
protected:
|
||||
virtual void Update(bool hovered, bool pressed);
|
||||
|
||||
private:
|
||||
std::shared_ptr<SlicedSprite> m_hoveredSprite;
|
||||
std::shared_ptr<SlicedSprite> m_sprite;
|
||||
entt::entity m_entity;
|
||||
bool m_isHovered;
|
||||
bool m_isPressed;
|
||||
};
|
||||
|
||||
class NAZARA_WIDGETS_API SimpleLabelWidgetStyle : public LabelWidgetStyle
|
||||
{
|
||||
public:
|
||||
@@ -137,6 +179,106 @@ namespace Nz
|
||||
std::shared_ptr<TextSprite> m_textSprite;
|
||||
entt::entity m_entity;
|
||||
};
|
||||
|
||||
class NAZARA_WIDGETS_API SimpleScrollAreaWidgetStyle : public ScrollAreaWidgetStyle
|
||||
{
|
||||
public:
|
||||
SimpleScrollAreaWidgetStyle(ScrollAreaWidget* scrollAreaWidget);
|
||||
SimpleScrollAreaWidgetStyle(const SimpleScrollAreaWidgetStyle&) = delete;
|
||||
SimpleScrollAreaWidgetStyle(SimpleScrollAreaWidgetStyle&&) = default;
|
||||
~SimpleScrollAreaWidgetStyle() = default;
|
||||
|
||||
void Layout(const Vector2f& size) override;
|
||||
|
||||
void UpdateRenderLayer(int baseRenderLayer) override;
|
||||
|
||||
SimpleScrollAreaWidgetStyle& operator=(const SimpleScrollAreaWidgetStyle&) = delete;
|
||||
SimpleScrollAreaWidgetStyle& operator=(SimpleScrollAreaWidgetStyle&&) = default;
|
||||
|
||||
private:
|
||||
std::shared_ptr<Material> m_hoveredMaterial;
|
||||
std::shared_ptr<Material> m_material;
|
||||
std::shared_ptr<TextSprite> m_textSprite;
|
||||
entt::entity m_entity;
|
||||
};
|
||||
|
||||
class NAZARA_WIDGETS_API SimpleScrollbarWidgetStyle : public ScrollbarWidgetStyle
|
||||
{
|
||||
public:
|
||||
struct StyleConfig;
|
||||
|
||||
SimpleScrollbarWidgetStyle(ScrollbarWidget* scrollBarWidget, StyleConfig config);
|
||||
SimpleScrollbarWidgetStyle(const SimpleScrollbarWidgetStyle&) = delete;
|
||||
SimpleScrollbarWidgetStyle(SimpleScrollbarWidgetStyle&&) = default;
|
||||
~SimpleScrollbarWidgetStyle() = default;
|
||||
|
||||
void Layout(const Vector2f& size) override;
|
||||
|
||||
void UpdateRenderLayer(int baseRenderLayer) override;
|
||||
|
||||
SimpleScrollbarWidgetStyle& operator=(const SimpleScrollbarWidgetStyle&) = delete;
|
||||
SimpleScrollbarWidgetStyle& operator=(SimpleScrollbarWidgetStyle&&) = default;
|
||||
|
||||
struct StyleConfig
|
||||
{
|
||||
std::shared_ptr<Material> backgroundHorizontalMaterial;
|
||||
std::shared_ptr<Material> backgroundVerticalMaterial;
|
||||
};
|
||||
|
||||
private:
|
||||
StyleConfig m_config;
|
||||
std::shared_ptr<Sprite> m_backgroundScrollbarSprite;
|
||||
std::shared_ptr<SlicedSprite> m_scrollbarSprite;
|
||||
entt::entity m_backgroundScrollbarSpriteEntity;
|
||||
entt::entity m_scrollbarSpriteEntity;
|
||||
};
|
||||
|
||||
class NAZARA_WIDGETS_API SimpleScrollbarButtonWidgetStyle : public ScrollbarButtonWidgetStyle
|
||||
{
|
||||
public:
|
||||
struct StyleConfig;
|
||||
|
||||
SimpleScrollbarButtonWidgetStyle(ScrollbarButtonWidget* scrollbarButtonWidget, StyleConfig config);
|
||||
SimpleScrollbarButtonWidgetStyle(const SimpleScrollbarWidgetStyle&) = delete;
|
||||
SimpleScrollbarButtonWidgetStyle(SimpleScrollbarButtonWidgetStyle&&) = default;
|
||||
~SimpleScrollbarButtonWidgetStyle() = default;
|
||||
|
||||
void Layout(const Vector2f& size) override;
|
||||
|
||||
void OnHoverBegin() override;
|
||||
void OnHoverEnd() override;
|
||||
void OnGrab() override;
|
||||
void OnRelease() override;
|
||||
|
||||
void UpdateRenderLayer(int baseRenderLayer) override;
|
||||
|
||||
SimpleScrollbarButtonWidgetStyle& operator=(const SimpleScrollbarButtonWidgetStyle&) = delete;
|
||||
SimpleScrollbarButtonWidgetStyle& operator=(SimpleScrollbarButtonWidgetStyle&&) = default;
|
||||
|
||||
struct StyleConfig
|
||||
{
|
||||
std::shared_ptr<Material> material;
|
||||
std::shared_ptr<Material> grabbedMaterial;
|
||||
std::shared_ptr<Material> grabbedHoveredMaterial;
|
||||
std::shared_ptr<Material> hoveredMaterial;
|
||||
float cornerSize;
|
||||
float cornerTexCoords;
|
||||
};
|
||||
|
||||
protected:
|
||||
virtual void Update(bool hovered, bool pressed);
|
||||
|
||||
private:
|
||||
StyleConfig m_config;
|
||||
std::shared_ptr<Material> m_hoveredMaterial;
|
||||
std::shared_ptr<Material> m_material;
|
||||
std::shared_ptr<Material> m_pressedMaterial;
|
||||
std::shared_ptr<Material> m_pressedHoveredMaterial;
|
||||
std::shared_ptr<SlicedSprite> m_sprite;
|
||||
entt::entity m_entity;
|
||||
bool m_isHovered;
|
||||
bool m_isPressed;
|
||||
};
|
||||
}
|
||||
|
||||
#include <Nazara/Widgets/DefaultWidgetTheme.inl>
|
||||
|
||||
@@ -20,25 +20,60 @@ namespace Nz
|
||||
class ButtonWidgetStyle;
|
||||
class CheckboxWidget;
|
||||
class CheckboxWidgetStyle;
|
||||
class ImageButtonWidget;
|
||||
class ImageButtonWidgetStyle;
|
||||
class LabelWidget;
|
||||
class LabelWidgetStyle;
|
||||
class ScrollAreaWidget;
|
||||
class ScrollAreaWidgetStyle;
|
||||
class ScrollbarWidget;
|
||||
class ScrollbarWidgetStyle;
|
||||
class ScrollbarButtonWidget;
|
||||
class ScrollbarButtonWidgetStyle;
|
||||
|
||||
class NAZARA_WIDGETS_API WidgetTheme
|
||||
{
|
||||
public:
|
||||
struct Config;
|
||||
|
||||
WidgetTheme() = default;
|
||||
WidgetTheme(const WidgetTheme&) = delete;
|
||||
WidgetTheme(WidgetTheme&&) = default;
|
||||
virtual ~WidgetTheme();
|
||||
|
||||
virtual std::unique_ptr<ButtonWidgetStyle> CreateStyle(ButtonWidget* buttonWidget) const = 0;
|
||||
virtual std::unique_ptr<CheckboxWidgetStyle> CreateStyle(CheckboxWidget* buttonWidget) const = 0;
|
||||
virtual std::unique_ptr<LabelWidgetStyle> CreateStyle(LabelWidget* buttonWidget) const = 0;
|
||||
virtual std::unique_ptr<CheckboxWidgetStyle> CreateStyle(CheckboxWidget* checkboxWidget) const = 0;
|
||||
virtual std::unique_ptr<ImageButtonWidgetStyle> CreateStyle(ImageButtonWidget* imageButtonWidget) const = 0;
|
||||
virtual std::unique_ptr<LabelWidgetStyle> CreateStyle(LabelWidget* labelWidget) const = 0;
|
||||
virtual std::unique_ptr<ScrollAreaWidgetStyle> CreateStyle(ScrollAreaWidget* scrollareaWidget) const = 0;
|
||||
virtual std::unique_ptr<ScrollbarWidgetStyle> CreateStyle(ScrollbarWidget* scrollbarWidget) const = 0;
|
||||
virtual std::unique_ptr<ScrollbarButtonWidgetStyle> CreateStyle(ScrollbarButtonWidget* scrollbarButtonWidget) const = 0;
|
||||
|
||||
inline const Config& GetConfig() const;
|
||||
|
||||
WidgetTheme& operator=(const WidgetTheme&) = delete;
|
||||
WidgetTheme& operator=(WidgetTheme&&) = default;
|
||||
|
||||
private:
|
||||
struct Config
|
||||
{
|
||||
std::shared_ptr<Material> scrollbarButtonDownMaterial;
|
||||
std::shared_ptr<Material> scrollbarButtonDownHoveredMaterial;
|
||||
std::shared_ptr<Material> scrollbarButtonDownPressedMaterial;
|
||||
std::shared_ptr<Material> scrollbarButtonLeftMaterial;
|
||||
std::shared_ptr<Material> scrollbarButtonLeftHoveredMaterial;
|
||||
std::shared_ptr<Material> scrollbarButtonLeftPressedMaterial;
|
||||
std::shared_ptr<Material> scrollbarButtonRightMaterial;
|
||||
std::shared_ptr<Material> scrollbarButtonRightHoveredMaterial;
|
||||
std::shared_ptr<Material> scrollbarButtonRightPressedMaterial;
|
||||
std::shared_ptr<Material> scrollbarButtonUpMaterial;
|
||||
std::shared_ptr<Material> scrollbarButtonUpHoveredMaterial;
|
||||
std::shared_ptr<Material> scrollbarButtonUpPressedMaterial;
|
||||
float scrollbarButtonCornerSize;
|
||||
float scrollbarButtonCornerTexcoords;
|
||||
};
|
||||
|
||||
protected:
|
||||
Config m_config;
|
||||
};
|
||||
|
||||
class NAZARA_WIDGETS_API BaseWidgetStyle
|
||||
@@ -53,6 +88,7 @@ namespace Nz
|
||||
entt::entity CreateGraphicsEntity();
|
||||
inline void DestroyEntity(entt::entity entity);
|
||||
|
||||
template<typename T> T* GetOwnerWidget() const;
|
||||
inline entt::registry& GetRegistry();
|
||||
inline const entt::registry& GetRegistry() const;
|
||||
UInt32 GetRenderMask() const;
|
||||
@@ -88,7 +124,7 @@ namespace Nz
|
||||
ButtonWidgetStyle& operator=(const ButtonWidgetStyle&) = delete;
|
||||
ButtonWidgetStyle& operator=(ButtonWidgetStyle&&) = default;
|
||||
};
|
||||
|
||||
|
||||
class NAZARA_WIDGETS_API CheckboxWidgetStyle : public BaseWidgetStyle
|
||||
{
|
||||
public:
|
||||
@@ -108,6 +144,26 @@ namespace Nz
|
||||
CheckboxWidgetStyle& operator=(const CheckboxWidgetStyle&) = delete;
|
||||
CheckboxWidgetStyle& operator=(CheckboxWidgetStyle&&) = default;
|
||||
};
|
||||
|
||||
class NAZARA_WIDGETS_API ImageButtonWidgetStyle : public BaseWidgetStyle
|
||||
{
|
||||
public:
|
||||
using BaseWidgetStyle::BaseWidgetStyle;
|
||||
ImageButtonWidgetStyle(const ImageButtonWidgetStyle&) = delete;
|
||||
ImageButtonWidgetStyle(ImageButtonWidgetStyle&&) = default;
|
||||
~ImageButtonWidgetStyle() = default;
|
||||
|
||||
virtual void Layout(const Vector2f& size) = 0;
|
||||
|
||||
virtual void OnHoverBegin();
|
||||
virtual void OnHoverEnd();
|
||||
virtual void OnPress();
|
||||
virtual void OnRelease();
|
||||
virtual void OnUpdate() = 0;
|
||||
|
||||
ImageButtonWidgetStyle& operator=(const ImageButtonWidgetStyle&) = delete;
|
||||
ImageButtonWidgetStyle& operator=(ImageButtonWidgetStyle&&) = default;
|
||||
};
|
||||
|
||||
class NAZARA_WIDGETS_API LabelWidgetStyle : public BaseWidgetStyle
|
||||
{
|
||||
@@ -127,6 +183,58 @@ namespace Nz
|
||||
LabelWidgetStyle& operator=(const LabelWidgetStyle&) = delete;
|
||||
LabelWidgetStyle& operator=(LabelWidgetStyle&&) = default;
|
||||
};
|
||||
|
||||
class NAZARA_WIDGETS_API ScrollAreaWidgetStyle : public BaseWidgetStyle
|
||||
{
|
||||
public:
|
||||
using BaseWidgetStyle::BaseWidgetStyle;
|
||||
ScrollAreaWidgetStyle(const ScrollAreaWidgetStyle&) = delete;
|
||||
ScrollAreaWidgetStyle(ScrollAreaWidgetStyle&&) = default;
|
||||
~ScrollAreaWidgetStyle() = default;
|
||||
|
||||
virtual void Layout(const Vector2f& size) = 0;
|
||||
|
||||
ScrollAreaWidgetStyle& operator=(const ScrollAreaWidgetStyle&) = delete;
|
||||
ScrollAreaWidgetStyle& operator=(ScrollAreaWidgetStyle&&) = default;
|
||||
};
|
||||
|
||||
class NAZARA_WIDGETS_API ScrollbarWidgetStyle : public BaseWidgetStyle
|
||||
{
|
||||
public:
|
||||
using BaseWidgetStyle::BaseWidgetStyle;
|
||||
ScrollbarWidgetStyle(const ScrollbarWidgetStyle&) = delete;
|
||||
ScrollbarWidgetStyle(ScrollbarWidgetStyle&&) = default;
|
||||
~ScrollbarWidgetStyle() = default;
|
||||
|
||||
virtual void Layout(const Vector2f& size) = 0;
|
||||
|
||||
virtual void OnButtonGrab();
|
||||
virtual void OnButtonRelease();
|
||||
virtual void OnHoverBegin();
|
||||
virtual void OnHoverEnd();
|
||||
|
||||
ScrollbarWidgetStyle& operator=(const ScrollbarWidgetStyle&) = delete;
|
||||
ScrollbarWidgetStyle& operator=(ScrollbarWidgetStyle&&) = default;
|
||||
};
|
||||
|
||||
class NAZARA_WIDGETS_API ScrollbarButtonWidgetStyle : public BaseWidgetStyle
|
||||
{
|
||||
public:
|
||||
using BaseWidgetStyle::BaseWidgetStyle;
|
||||
ScrollbarButtonWidgetStyle(const ScrollbarButtonWidgetStyle&) = delete;
|
||||
ScrollbarButtonWidgetStyle(ScrollbarButtonWidgetStyle&&) = default;
|
||||
~ScrollbarButtonWidgetStyle() = default;
|
||||
|
||||
virtual void Layout(const Vector2f& size) = 0;
|
||||
|
||||
virtual void OnHoverBegin();
|
||||
virtual void OnHoverEnd();
|
||||
virtual void OnGrab();
|
||||
virtual void OnRelease();
|
||||
|
||||
ScrollbarButtonWidgetStyle& operator=(const ScrollbarButtonWidgetStyle&) = delete;
|
||||
ScrollbarButtonWidgetStyle& operator=(ScrollbarButtonWidgetStyle&&) = default;
|
||||
};
|
||||
}
|
||||
|
||||
#include <Nazara/Widgets/WidgetTheme.inl>
|
||||
|
||||
@@ -3,11 +3,18 @@
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#include <Nazara/Widgets/WidgetTheme.hpp>
|
||||
#include <Nazara/Utils/Algorithm.hpp>
|
||||
#include <cassert>
|
||||
#include <Nazara/Widgets/Debug.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
inline auto WidgetTheme::GetConfig() const -> const Config&
|
||||
{
|
||||
return m_config;
|
||||
}
|
||||
|
||||
|
||||
inline BaseWidgetStyle::BaseWidgetStyle(BaseWidget* widget, int renderLayerCount) :
|
||||
m_widgetOwner(widget),
|
||||
m_renderLayerCount(renderLayerCount)
|
||||
@@ -25,6 +32,12 @@ namespace Nz
|
||||
m_widgetOwner->DestroyEntity(entity);
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
T* BaseWidgetStyle::GetOwnerWidget() const
|
||||
{
|
||||
return SafeCast<T*>(m_widgetOwner);
|
||||
}
|
||||
|
||||
inline entt::registry& BaseWidgetStyle::GetRegistry()
|
||||
{
|
||||
return m_widgetOwner->GetRegistry();
|
||||
|
||||
Reference in New Issue
Block a user