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 a654c4b commit 1df57a3
Show file tree
Hide file tree
Showing 8 changed files with 361 additions and 9 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/UIWindow.hpp>

# include <Siv3D/UI1/ColorRect.hpp>

//////////////////////////////////////////////////
Expand Down
16 changes: 9 additions & 7 deletions Siv3D/include/Siv3D/UI1/UIPanel.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ namespace s3d
inline namespace UI1
{
/// @brief UI 要素を配置するパネル
class UIPanel final : public UIContainer
class UIPanel : public UIContainer
{
public:

Expand Down Expand Up @@ -84,17 +84,13 @@ namespace s3d

/// @brief UI パネルを作成します。
/// @param name UI コンテナとしての一意な名前
/// @param rect パネルの領域
/// @param rect パネルの初期領域
/// @param style スタイル
/// @return 作成されたパネル
[[nodiscard]]
static std::shared_ptr<UIPanel> Create(UIContainerNameView name, const RectF& rect, const Style& style = Style::Default());

private:

Style m_style;

RectF m_rect = RectF::Empty();
protected:

[[nodiscard]]
RoundRect getShape() const noexcept;
Expand All @@ -104,6 +100,12 @@ namespace s3d

[[nodiscard]]
void drawDebugBackground() const;

private:

Style m_style;

RectF m_rect = RectF::Empty();
};
}
}
135 changes: 135 additions & 0 deletions Siv3D/include/Siv3D/UI1/UIWindow.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
//-----------------------------------------------
//
// 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 "../Optional.hpp"
# include "../ColorHSV.hpp"
# include "Padding.hpp"
# include "BoxShadow.hpp"
# include "UIContainer.hpp"

namespace s3d
{
inline namespace UI1
{
/// @brief UI 要素を配置するウィンドウ
class UIWindow : public UIContainer
{
public:

struct Style
{
/// @brief 枠の太さ(ピクセル)
double borderThickness = 1.0;

/// @brief パネルの角の半径(ピクセル)
double borderRadius = 4.0;

/// @brief 背景色 | Background color
Optional<ColorF> backgroundColor = ColorF{ 1.0 };

/// @brief 無効時のオーバーレイ色 | Disabled overlay color
Optional<ColorF> disabledOverlayColor = ColorF{ 0.98, 0.7 };

/// @brief アクティブ時の枠の色 | Active border color
Optional<ColorF> activeBorderColor = ColorF{ 0.68 };

/// @brief 非アクティブ時の枠の色 | Inactive border color
Optional<ColorF> inactiveBorderColor = ColorF{ 0.72 };

/// @brief 無効時の枠の色 | Disabled border color
Optional<ColorF> disabledBorderColor = ColorF{ 0.75 };

/// @brief 影の設定 | Box shadow
Optional<BoxShadow> boxShadow = BoxShadow{ Vec2{ 2, 2 }, 24, 1 };

Padding padding = { 10, 20 };

double titleBarHeight = 36.0;

/// @brief アクティブ時のタイトルバーの色
ColorF titleBarActiveColor = ColorF{ 0.82, 0.85, 0.93 };

/// @brief 非アクティブ時のタイトルバーの色
ColorF titleBarInactiveColor = ColorF{ 0.91 };

[[nodiscard]]
static Style Default();
};

SIV3D_NODISCARD_CXX20
UIWindow() = default;

SIV3D_NODISCARD_CXX20
explicit UIWindow(UIContainerNameView name, StringView title, const RectF& rect, const Style& style = Style::Default());

[[nodiscard]]
StringView type() const noexcept override;

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

[[nodiscard]]
RectF getBounds() const noexcept override;

bool onUpdate(bool cursorCapturable = true) override;

void onDraw() const override;

void onDrawOverlay() const override;

void onDrawDebug() const override;

void setPos(const Vec2& pos) noexcept;

void setSize(const SizeF& size) noexcept;

/// @brief UI ウィンドウを作成します。
/// @param name UI コンテナとしての一意な名前
/// @param rect ウィンドウの初期領域
/// @param style スタイル
/// @return 作成されたウィンドウ
[[nodiscard]]
static std::shared_ptr<UIWindow> Create(UIContainerNameView name, StringView title, const RectF& rect, const Style& style = Style::Default());

protected:

void onPressed() override;

void onReleased() override;

private:

Style m_style;

RectF m_rect = RectF::Empty();

String m_title;

bool m_active = false;

bool m_dragging = false;

[[nodiscard]]
RoundRect getShape() const noexcept;

[[nodiscard]]
RectF getTitleBarRect() const noexcept;

[[nodiscard]]
void drawBackground() const;

[[nodiscard]]
void drawDebugBackground() const;
};
}
}
2 changes: 1 addition & 1 deletion Siv3D/src/Siv3D/UI1/SivUIContainer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ namespace s3d

String UIContainer::dumpDebugInfo() const
{
String result = U"{} ({}) {} "_fmt(m_name, type(), getBounds());
String result = U"{} ({}) {:.1f} "_fmt(m_name, type(), getBounds());

if (shouldUpdate())
{
Expand Down
5 changes: 4 additions & 1 deletion Siv3D/src/Siv3D/UI1/SivUIPanel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
//
//-----------------------------------------------

# include <Siv3D/Math.hpp>
# include <Siv3D/UI1/UIPanel.hpp>

namespace s3d
Expand Down Expand Up @@ -99,7 +100,9 @@ namespace s3d

if (m_style.boxShadow)
{
shape.drawShadow(m_style.boxShadow->offset, m_style.boxShadow->blur, m_style.boxShadow->spread, m_style.boxShadow->color);
// [Siv3D ToDo] より多くのケースで fill を false にする
const bool fill = ((m_style.boxShadow->blur * 0.5 + m_style.boxShadow->spread) < (Math::Abs(m_style.boxShadow->offset).maxComponent()));
shape.drawShadow(m_style.boxShadow->offset, m_style.boxShadow->blur, m_style.boxShadow->spread, m_style.boxShadow->color, fill);
}

if (m_style.backgroundColor)
Expand Down
Loading

0 comments on commit 1df57a3

Please sign in to comment.