Commit current work
Former-commit-id: 79be9d4e937a73626cd5ec02c1d2e2fcbd440d18
This commit is contained in:
76
SDK/include/NDK/BaseWidget.hpp
Normal file
76
SDK/include/NDK/BaseWidget.hpp
Normal file
@@ -0,0 +1,76 @@
|
||||
// Copyright (C) 2015 Jérôme Leclercq
|
||||
// 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_BASEWIDGET_HPP
|
||||
#define NDK_BASEWIDGET_HPP
|
||||
|
||||
#include <NDK/Prerequesites.hpp>
|
||||
#include <NDK/Entity.hpp>
|
||||
#include <NDK/EntityOwner.hpp>
|
||||
#include <NDK/World.hpp>
|
||||
#include <Nazara/Graphics/Sprite.hpp>
|
||||
#include <Nazara/Utility/Node.hpp>
|
||||
|
||||
namespace Ndk
|
||||
{
|
||||
class NDK_API BaseWidget : public Nz::Node
|
||||
{
|
||||
public:
|
||||
struct Padding;
|
||||
|
||||
inline BaseWidget(WorldHandle world, BaseWidget* parent = nullptr);
|
||||
BaseWidget(const BaseWidget&) = delete;
|
||||
BaseWidget(BaseWidget&&) = default;
|
||||
virtual ~BaseWidget();
|
||||
|
||||
inline void AddChild(std::unique_ptr<BaseWidget>&& widget);
|
||||
|
||||
void EnableBackground(bool enable);
|
||||
|
||||
//virtual BaseWidget* Clone() const = 0;
|
||||
|
||||
inline const Padding& GetPadding() const;
|
||||
inline Nz::Vector2f GetSize() const;
|
||||
|
||||
virtual void ResizeToContent() = 0;
|
||||
|
||||
inline void SetContentSize(const Nz::Vector2f& size);
|
||||
inline void SetPadding(float left, float top, float right, float bottom);
|
||||
void SetSize(const Nz::Vector2f& size);
|
||||
|
||||
BaseWidget& operator=(const BaseWidget&) = delete;
|
||||
BaseWidget& operator=(BaseWidget&&) = default;
|
||||
|
||||
struct Padding
|
||||
{
|
||||
float left;
|
||||
float top;
|
||||
float right;
|
||||
float bottom;
|
||||
};
|
||||
|
||||
protected:
|
||||
EntityHandle CreateEntity();
|
||||
void DestroyEntity(Entity* entity);
|
||||
|
||||
private:
|
||||
void UpdateBackground();
|
||||
|
||||
std::vector<EntityOwner> m_entities;
|
||||
std::vector<BaseWidget*> m_children;
|
||||
EntityOwner m_backgroundEntity;
|
||||
Padding m_padding;
|
||||
WorldHandle m_world;
|
||||
Nz::Color m_backgroundColor;
|
||||
Nz::SpriteRef m_backgroundSprite;
|
||||
Nz::Vector2f m_contentSize;
|
||||
BaseWidget* m_widgetParent;
|
||||
};
|
||||
}
|
||||
|
||||
#include <NDK/BaseWidget.inl>
|
||||
|
||||
#endif // NDK_BASEWIDGET_HPP
|
||||
50
SDK/include/NDK/BaseWidget.inl
Normal file
50
SDK/include/NDK/BaseWidget.inl
Normal file
@@ -0,0 +1,50 @@
|
||||
// Copyright (C) 2015 Jérôme Leclercq
|
||||
// This file is part of the "Nazara Development Kit"
|
||||
// For conditions of distribution and use, see copyright notice in Prerequesites.hpp
|
||||
|
||||
#include <NDK/BaseWidget.hpp>
|
||||
#include <Nazara/Core/Error.hpp>
|
||||
#include <Nazara/Math/Algorithm.hpp>
|
||||
|
||||
namespace Ndk
|
||||
{
|
||||
inline BaseWidget::BaseWidget(WorldHandle world, BaseWidget* parent) :
|
||||
m_world(std::move(world)),
|
||||
m_backgroundColor(Nz::Color(230, 230, 230, 255)),
|
||||
m_contentSize(50.f, 50.f),
|
||||
m_widgetParent(parent)
|
||||
{
|
||||
SetPadding(5.f, 5.f, 5.f, 5.f);
|
||||
}
|
||||
|
||||
inline void BaseWidget::AddChild(std::unique_ptr<BaseWidget>&& widget)
|
||||
{
|
||||
m_children.push_back(widget.release());
|
||||
}
|
||||
|
||||
inline const BaseWidget::Padding& BaseWidget::GetPadding() const
|
||||
{
|
||||
return m_padding;
|
||||
}
|
||||
|
||||
inline Nz::Vector2f BaseWidget::GetSize() const
|
||||
{
|
||||
return Nz::Vector2f(m_contentSize.x + m_padding.left + m_padding.right, m_contentSize.y + m_padding.top + m_padding.bottom);
|
||||
}
|
||||
|
||||
inline void BaseWidget::SetContentSize(const Nz::Vector2f& size)
|
||||
{
|
||||
m_contentSize = size;
|
||||
UpdateBackground();
|
||||
}
|
||||
|
||||
inline void BaseWidget::SetPadding(float left, float top, float right, float bottom)
|
||||
{
|
||||
m_padding.left = left;
|
||||
m_padding.top = top;
|
||||
m_padding.bottom = bottom;
|
||||
m_padding.right = right;
|
||||
|
||||
UpdateBackground();
|
||||
}
|
||||
}
|
||||
44
SDK/include/NDK/Widgets/LabelWidget.hpp
Normal file
44
SDK/include/NDK/Widgets/LabelWidget.hpp
Normal file
@@ -0,0 +1,44 @@
|
||||
// Copyright (C) 2015 Jérôme Leclercq
|
||||
// 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_LABELWIDGET_HPP
|
||||
#define NDK_WIDGETS_LABELWIDGET_HPP
|
||||
|
||||
#include <NDK/Prerequesites.hpp>
|
||||
#include <NDK/BaseWidget.hpp>
|
||||
#include <Nazara/Utility/AbstractTextDrawer.hpp>
|
||||
#include <Nazara/Graphics/TextSprite.hpp>
|
||||
|
||||
namespace Ndk
|
||||
{
|
||||
class World;
|
||||
|
||||
class NDK_API LabelWidget : public BaseWidget
|
||||
{
|
||||
public:
|
||||
LabelWidget(const WorldHandle& world, BaseWidget* parent = nullptr);
|
||||
LabelWidget(const LabelWidget&) = delete;
|
||||
LabelWidget(LabelWidget&&) = default;
|
||||
~LabelWidget() = default;
|
||||
|
||||
//virtual LabelWidget* Clone() const = 0;
|
||||
|
||||
void ResizeToContent();
|
||||
|
||||
inline void UpdateText(const Nz::AbstractTextDrawer& drawer);
|
||||
|
||||
LabelWidget& operator=(const LabelWidget&) = delete;
|
||||
LabelWidget& operator=(LabelWidget&&) = default;
|
||||
|
||||
private:
|
||||
EntityHandle m_textEntity;
|
||||
Nz::TextSpriteRef m_textSprite;
|
||||
};
|
||||
}
|
||||
|
||||
#include <NDK/Widgets/LabelWidget.inl>
|
||||
|
||||
#endif // NDK_WIDGETS_LABELWIDGET_HPP
|
||||
13
SDK/include/NDK/Widgets/LabelWidget.inl
Normal file
13
SDK/include/NDK/Widgets/LabelWidget.inl
Normal file
@@ -0,0 +1,13 @@
|
||||
// Copyright (C) 2015 Jérôme Leclercq
|
||||
// This file is part of the "Nazara Development Kit"
|
||||
// For conditions of distribution and use, see copyright notice in Prerequesites.hpp
|
||||
|
||||
#include <NDK/Widgets/LabelWidget.hpp>
|
||||
|
||||
namespace Ndk
|
||||
{
|
||||
inline void LabelWidget::UpdateText(const Nz::AbstractTextDrawer& drawer)
|
||||
{
|
||||
m_textSprite->Update(drawer);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user