Skip to content

Commit

Permalink
UI1 途中
Browse files Browse the repository at this point in the history
  • Loading branch information
Reputeless committed Aug 30, 2023
1 parent 917bb13 commit a654c4b
Show file tree
Hide file tree
Showing 14 changed files with 510 additions and 17 deletions.
2 changes: 2 additions & 0 deletions Siv3D/include/Siv3D.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1718,6 +1718,8 @@

# include <Siv3D/UI1/UIPanel.hpp>

# include <Siv3D/UI1/ColorRect.hpp>

//////////////////////////////////////////////////
//
// エフェクト | Effect
Expand Down
47 changes: 47 additions & 0 deletions Siv3D/include/Siv3D/UI1/ColorRect.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
//-----------------------------------------------
//
// This file is part of the Siv3D Engine.
//
// Copyright (c) 2008-2023 Ryo Suzuki
// Copyright (c) 2016-2023 OpenSiv3D Project
//
// Licensed under the MIT License.
//
//-----------------------------------------------

# pragma once
# include "../Common.hpp"
# include "../PointVector.hpp"
# include "../ColorHSV.hpp"
# include "UIElement.hpp"

namespace s3d
{
inline namespace UI1
{
class ColorRect final : public UIElement
{
public:

SIV3D_NODISCARD_CXX20
ColorRect() = default;

SIV3D_NODISCARD_CXX20
explicit ColorRect(const SizeF& size, const ColorF& color = ColorF{ 1.0 });

[[nodiscard]]
static std::shared_ptr<ColorRect> Create(const SizeF& size, const ColorF& color = ColorF{ 1.0 });

private:

[[nodiscard]]
SizeF getSize() const noexcept override;

void onDraw() const override;

SizeF m_size = { 0, 0 };

ColorF m_color = ColorF{ 1.0 };
};
}
}
30 changes: 30 additions & 0 deletions Siv3D/include/Siv3D/UI1/Margin.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

# pragma once
# include "../Common.hpp"
# include "../Interpolation.hpp"

namespace s3d
{
Expand Down Expand Up @@ -58,6 +59,35 @@ namespace s3d
SIV3D_NODISCARD_CXX20
constexpr Margin(double _top, double _right, double _bottom, double _left) noexcept;

[[nodiscard]]
constexpr Vec2 topLeft() const noexcept;

[[nodiscard]]
constexpr Vec2 topRight() const noexcept;

[[nodiscard]]
constexpr Vec2 bottomRight() const noexcept;

[[nodiscard]]
constexpr Vec2 bottomLeft() const noexcept;

/// @brief 左辺と右辺のマージンの合計を返します。 | Returns the sum of the left and right margin.
/// @return 左辺と右辺のマージンの合計 | The sum of the left and right margin
[[nodiscard]]
constexpr double totalWidth() const noexcept;

/// @brief 上辺と下辺のマージンの合計を返します。 | Returns the sum of the top and bottom margin.
/// @return 上辺と下辺のマージンの合計 | The sum of the top and bottom margin
[[nodiscard]]
constexpr double totalHeight() const noexcept;

/// @brief 2 つのマージンを線形補間します。 | Performs a linear interpolation between two margins.
/// @param other 他方のマージン | The other margin
/// @param f 補間係数 | The interpolation coefficient
/// @return 補間結果 | The result of interpolation
[[nodiscard]]
constexpr Margin lerp(const Margin& other, double f) const noexcept;

[[nodiscard]]
static constexpr Margin Zero() noexcept;

Expand Down
9 changes: 9 additions & 0 deletions Siv3D/include/Siv3D/UI1/UIContainer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,15 @@ namespace s3d

std::weak_ptr<UICanvas::UICanvasDetail> m_pCanvas;

[[nodiscard]]
bool onUpdateHelper(bool cursorCapturable, bool shapeMouseOver, const Padding& padding, const std::function<void(SizeF)>& resizeFunction);

void onDrawHelper(const Padding& padding) const;

void onDrawOverlayHelper(const Padding& padding) const;

void onDrawDebugHelper(const Padding& padding) const;

private:

UIContainerName m_name;
Expand Down
28 changes: 26 additions & 2 deletions Siv3D/include/Siv3D/UI1/UIElement.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,13 @@ namespace s3d

virtual ~UIElement();

/// @brief UI 要素のサイズ(ピクセル)を返します。
/// @return UI 要素のサイズ(ピクセル)
[[nodiscard]]
virtual SizeF getSize() const noexcept = 0;

/// @brief UI 要素のマージンを返します。
/// @return UI 要素のマージン
[[nodiscard]]
virtual Margin getMargin() const noexcept;

Expand Down Expand Up @@ -66,17 +70,37 @@ namespace s3d

protected:

/// @brief UI 要素の更新処理を記述します。
/// @param cursorCapturable キャプチャできるマウスカーソルがあるか
/// @return UI 要素がマウスを遮った場合 true, それ以外の場合は false
virtual bool onUpdate(bool cursorCapturable);

/// @brief UI 要素の描画処理を記述します。
virtual void onDraw() const;
virtual void onDraw() const {}

/// @brief UI 要素のオーバーレイ描画処理を記述します。
virtual void onDrawOverlay() const;
virtual void onDrawOverlay() const {}

/// @brief UI 要素のデバッグ描画処理を記述します。
virtual void onDrawDebug() const;

/// @brief 要素が押されたときに呼び出される関数
virtual void onPressed() {}

/// @brief 要素が離されたときに呼び出される関数
virtual void onReleased() {}

/// @brief 要素がクリックされたときに呼び出される関数
virtual void onClicked() {}

/// @brief 要素がホバーされたときに呼び出される関数
virtual void onHovered() {}

/// @brief 要素がホバーされなくなったときに呼び出される関数
virtual void onUnhovered() {}

bool updateState(const bool cursorCapturable, const bool shapeMouseOver);

private:

std::weak_ptr<UIContainer> m_parentContainer;
Expand Down
8 changes: 8 additions & 0 deletions Siv3D/include/Siv3D/UI1/UIFwd.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,20 @@ namespace s3d
struct Padding;
struct Margin;
struct BoxShadow;

class UICanvas;

using UIElementName = String;
using UIElementNameView = StringView;
class UIElement;

using UIContainerName = String;
using UIContainerNameView = StringView;
class UIContainer;

class UIPanel;
class UIWindow;

class ColorRect;
}
}
40 changes: 40 additions & 0 deletions Siv3D/include/Siv3D/UI1/detail/Margin.ipp
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,46 @@ namespace s3d
, bottom{ _bottom }
, left{ _left } {}

inline constexpr Vec2 Margin::topLeft() const noexcept
{
return{ left, top };
}

inline constexpr Vec2 Margin::topRight() const noexcept
{
return{ right, top };
}

inline constexpr Vec2 Margin::bottomRight() const noexcept
{
return{ right, bottom };
}

inline constexpr Vec2 Margin::bottomLeft() const noexcept
{
return{ left, bottom };
}

inline constexpr double Margin::totalWidth() const noexcept
{
return (left + right);
}

inline constexpr double Margin::totalHeight() const noexcept
{
return (top + bottom);
}

inline constexpr Margin Margin::lerp(const Margin& other, const double f) const noexcept
{
return{
Math::Lerp(top, other.top, f),
Math::Lerp(right, other.right, f),
Math::Lerp(bottom, other.bottom, f),
Math::Lerp(left, other.left, f)
};
}

inline constexpr Margin Margin::Zero() noexcept
{
return{ 0, 0, 0, 0 };
Expand Down
38 changes: 38 additions & 0 deletions Siv3D/src/Siv3D/UI1/SivColorRect.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
//-----------------------------------------------
//
// This file is part of the Siv3D Engine.
//
// Copyright (c) 2008-2023 Ryo Suzuki
// Copyright (c) 2016-2023 OpenSiv3D Project
//
// Licensed under the MIT License.
//
//-----------------------------------------------

# include <Siv3D/UI1/ColorRect.hpp>
# include <Siv3D/2DShapes.hpp>

namespace s3d
{
namespace UI1
{
ColorRect::ColorRect(const SizeF& size, const ColorF& color)
: m_size{ size }
, m_color{ color } {}

std::shared_ptr<ColorRect> ColorRect::Create(const SizeF& size, const ColorF& color)
{
return std::make_shared<ColorRect>(size, color);
}

SizeF ColorRect::getSize() const noexcept
{
return m_size;
}

void ColorRect::onDraw() const
{
RectF{ m_size }.draw(m_color);
}
}
}
2 changes: 1 addition & 1 deletion Siv3D/src/Siv3D/UI1/SivUICanvas.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ namespace s3d

UIContainer& UICanvas::addContainer(const std::shared_ptr<UIContainer>& container)
{
return pImpl->addContainer(container);
return pImpl->addContainer(container)._setRoot(pImpl);
}

void UICanvas::removeContainer(const UIContainerNameView name)
Expand Down
Loading

0 comments on commit a654c4b

Please sign in to comment.