From 70aced404de0fd646c17aab47112a19422faa11f Mon Sep 17 00:00:00 2001 From: guinpen98 <83969826+guinpen98@users.noreply.github.com> Date: Wed, 3 Dec 2025 20:51:10 +0900 Subject: [PATCH 1/9] ref: circle --- Library/PAX_GRAPHICA/Circle.hpp | 126 ++++++++++++------ .../PAX_GRAPHICA/DxLib/DxLibCircleImpl.hpp | 72 ++++++++++ Library/PAX_GRAPHICA/Interface/CircleImpl.hpp | 45 +++++++ Library/PAX_GRAPHICA/Null/NullCircleImpl.hpp | 60 +++++++++ Library/PAX_GRAPHICA/SFML/SFMLCircleImpl.hpp | 74 ++++++++++ Library/PAX_GRAPHICA/SFML_Circle.hpp | 55 -------- .../PAX_GRAPHICA/Siv3D/Siv3DCircleImpl.hpp | 72 ++++++++++ .../DxLib/DxLibCircleImplIncludeTest.cpp | 3 + .../Interface/CircleImplIncludeTest.cpp | 3 + .../Null/NullCircleImplIncludeTest.cpp | 3 + .../SFML/SFMLCircleImplIncludeTest.cpp | 3 + .../PAX_GRAPHICA/SFML_CircleIncludeTest.cpp | 3 - .../Siv3D/Siv3DCircleImplIncludeTest.cpp | 3 + 13 files changed, 422 insertions(+), 100 deletions(-) create mode 100644 Library/PAX_GRAPHICA/DxLib/DxLibCircleImpl.hpp create mode 100644 Library/PAX_GRAPHICA/Interface/CircleImpl.hpp create mode 100644 Library/PAX_GRAPHICA/Null/NullCircleImpl.hpp create mode 100644 Library/PAX_GRAPHICA/SFML/SFMLCircleImpl.hpp delete mode 100644 Library/PAX_GRAPHICA/SFML_Circle.hpp create mode 100644 Library/PAX_GRAPHICA/Siv3D/Siv3DCircleImpl.hpp create mode 100644 Projects/IncludeTest/source/PAX_GRAPHICA/DxLib/DxLibCircleImplIncludeTest.cpp create mode 100644 Projects/IncludeTest/source/PAX_GRAPHICA/Interface/CircleImplIncludeTest.cpp create mode 100644 Projects/IncludeTest/source/PAX_GRAPHICA/Null/NullCircleImplIncludeTest.cpp create mode 100644 Projects/IncludeTest/source/PAX_GRAPHICA/SFML/SFMLCircleImplIncludeTest.cpp delete mode 100644 Projects/IncludeTest/source/PAX_GRAPHICA/SFML_CircleIncludeTest.cpp create mode 100644 Projects/IncludeTest/source/PAX_GRAPHICA/Siv3D/Siv3DCircleImplIncludeTest.cpp diff --git a/Library/PAX_GRAPHICA/Circle.hpp b/Library/PAX_GRAPHICA/Circle.hpp index 77a0d9fa6..5e503851c 100644 --- a/Library/PAX_GRAPHICA/Circle.hpp +++ b/Library/PAX_GRAPHICA/Circle.hpp @@ -12,66 +12,108 @@ #ifndef PAX_GRAPHICA_CIRCLE_HPP #define PAX_GRAPHICA_CIRCLE_HPP +#include + +#include +#include +#include + #if defined(PAXS_USING_SIV3D) -#include +#include #elif defined(PAXS_USING_DXLIB) -#include +#include #elif defined(PAXS_USING_SFML) -#include -#include +#include +#else +#include #endif -#include - -#include - namespace paxg { - struct Circle - { + /// @brief Circle class with Pimpl idiom for graphics library abstraction + /// @note Uses shared_ptr for value semantics and automatic resource management + struct Circle { + private: + std::shared_ptr impl; + + /// @brief Create implementation based on the active graphics library + /// @param x X-coordinate of the circle center + /// @param y Y-coordinate of the circle center + /// @param r Radius of the circle + /// @return Shared pointer to the implementation + static std::shared_ptr createImpl(float x, float y, float r) { #if defined(PAXS_USING_SIV3D) - s3d::Circle circle; - constexpr Circle(const paxs::Vector2& pos, const float r) : circle(pos.x, pos.y, r) {} - constexpr Circle(const paxs::Vector2& pos, const float r) : circle(pos.x, pos.y, r) {} - constexpr Circle(const paxs::Vector2& pos, const float r) : circle(static_cast(pos.x), static_cast(pos.y), r) {} - constexpr operator s3d::Circle() const { return circle; } + return std::make_shared(x, y, r); +#elif defined(PAXS_USING_DXLIB) + return std::make_shared(x, y, r); +#elif defined(PAXS_USING_SFML) + return std::make_shared(x, y, r); #else - float x, y, r; - constexpr Circle(const paxs::Vector2& pos, const float r) : x(static_cast(pos.x)), y(static_cast(pos.y)), r(r) {} - constexpr Circle(const paxs::Vector2& pos, const float r) : x(pos.x), y(pos.y), r(r) {} - constexpr Circle(const paxs::Vector2& pos, const float r) : x(static_cast(pos.x)), y(static_cast(pos.y)), r(r) {} + return std::make_shared(x, y, r); #endif + } + + public: + /// @brief Constructor with separate x, y coordinates and radius + /// @param x X-coordinate of the circle center + /// @param y Y-coordinate of the circle center + /// @param r Radius of the circle + Circle(float x, float y, float r) + : impl(createImpl(x, y, r)) {} + + /// @brief Constructor with Vector2 position and radius + /// @param pos Position of the circle center + /// @param r Radius of the circle + Circle(const paxs::Vector2& pos, const float r) + : impl(createImpl(static_cast(pos.x), static_cast(pos.y), r)) {} + + /// @brief Constructor with Vector2 position and radius + /// @param pos Position of the circle center + /// @param r Radius of the circle + Circle(const paxs::Vector2& pos, const float r) + : impl(createImpl(pos.x, pos.y, r)) {} + + /// @brief Constructor with Vector2 position and radius + /// @param pos Position of the circle center + /// @param r Radius of the circle + Circle(const paxs::Vector2& pos, const float r) + : impl(createImpl(static_cast(pos.x), static_cast(pos.y), r)) {} + + /// @brief Draw the circle without color void draw() const { -#if defined(PAXS_USING_SIV3D) - circle.draw(); + if (impl) { + impl->draw(); + } + } -#elif defined(PAXS_USING_SFML) - SFML_Circle::getInstance()->circle.setRadius(r); - SFML_Circle::getInstance()->circle.setPosition({ x, y }); - paxg::Window::window().draw(SFML_Circle::getInstance()->circle); -#endif + /// @brief Draw the circle with specified color + /// @param color The color to draw the circle + void draw(const Color& color) const { + if (impl) { + impl->draw(color); + } } -#if defined(PAXS_USING_SIV3D) - void draw(const paxg::Color& c_) const { - circle.draw(c_.color); + /// @brief Get the position of the circle center + /// @return Position as Vector2 + paxs::Vector2 getPosition() const { + return impl ? impl->getPosition() : paxs::Vector2(0.0f, 0.0f); } -#elif defined(PAXS_USING_DXLIB) - void draw(const paxg::Color& c_) const { - DxLib::DrawCircle( - static_cast(x), static_cast(y), static_cast(r), - DxLib::GetColor(c_.r, c_.g, c_.b), TRUE); + + /// @brief Get the radius of the circle + float getRadius() const { + return impl ? impl->getRadius() : 0.0f; } -#elif defined(PAXS_USING_SFML) - void draw(const paxg::Color& c_) const { - SFML_Circle::getInstance()->circle.setRadius(r); - SFML_Circle::getInstance()->circle.setPosition({ x, y }); - SFML_Circle::getInstance()->circle.setFillColor(c_.color); - paxg::Window::window().draw(SFML_Circle::getInstance()->circle); +#if defined(PAXS_USING_SIV3D) + /// @brief Conversion operator to s3d::Circle (Siv3D only) + operator s3d::Circle() const { + auto* siv3dImpl = dynamic_cast(impl.get()); + if (siv3dImpl) { + return siv3dImpl->getNativeCircle(); + } + return s3d::Circle(0, 0, 0); } -#else - void draw(const paxg::Color&) const {} #endif }; } diff --git a/Library/PAX_GRAPHICA/DxLib/DxLibCircleImpl.hpp b/Library/PAX_GRAPHICA/DxLib/DxLibCircleImpl.hpp new file mode 100644 index 000000000..55b543555 --- /dev/null +++ b/Library/PAX_GRAPHICA/DxLib/DxLibCircleImpl.hpp @@ -0,0 +1,72 @@ +/*########################################################################################## + + PAX SAPIENTICA Library 💀🌿🌏 + + [Planning] 2023-2024 As Project + [Production] 2023-2024 As Project + [Contact Us] wanotaitei@gmail.com https://github.com/AsPJT/PAX_SAPIENTICA + [License] Distributed under the CC0 1.0. https://creativecommons.org/publicdomain/zero/1.0/ + +##########################################################################################*/ + +#ifndef PAX_GRAPHICA_DXLIB_CIRCLE_IMPL_HPP +#define PAX_GRAPHICA_DXLIB_CIRCLE_IMPL_HPP + +#include + +#ifdef PAXS_USING_DXLIB +#include +#include +#endif + +namespace paxg { + + struct Color; + +#ifdef PAXS_USING_DXLIB + + /// @brief DxLib implementation of CircleImpl + class DxLibCircleImpl : public CircleImpl { + private: + float x, y, r; + + public: + /// @brief Constructor with position and radius + /// @param x X-coordinate of the circle center + /// @param y Y-coordinate of the circle center + /// @param r Radius of the circle + constexpr DxLibCircleImpl(float x, float y, float r) + : x(x), y(y), r(r) {} + + /// @brief Draw the circle without color + /// @note DxLib requires color parameter, so this implementation is not supported + void draw() const override { + // DxLib does not support drawing without specifying color + // This is a no-op implementation + } + + /// @brief Draw the circle with specified color + /// @param color The color to draw the circle + void draw(const Color& color) const override { + DxLib::DrawCircle( + static_cast(x), static_cast(y), static_cast(r), + DxLib::GetColor(color.r, color.g, color.b), TRUE); + } + + /// @brief Get the position of the circle center + /// @return Position as Vector2 + paxs::Vector2 getPosition() const override { + return paxs::Vector2(x, y); + } + + /// @brief Get the radius of the circle + float getRadius() const override { + return r; + } + }; + +#endif // PAXS_USING_DXLIB + +} + +#endif // !PAX_GRAPHICA_DXLIB_CIRCLE_IMPL_HPP diff --git a/Library/PAX_GRAPHICA/Interface/CircleImpl.hpp b/Library/PAX_GRAPHICA/Interface/CircleImpl.hpp new file mode 100644 index 000000000..32d6c84e7 --- /dev/null +++ b/Library/PAX_GRAPHICA/Interface/CircleImpl.hpp @@ -0,0 +1,45 @@ +/*########################################################################################## + + PAX SAPIENTICA Library 💀🌿🌏 + + [Planning] 2023-2024 As Project + [Production] 2023-2024 As Project + [Contact Us] wanotaitei@gmail.com https://github.com/AsPJT/PAX_SAPIENTICA + [License] Distributed under the CC0 1.0. https://creativecommons.org/publicdomain/zero/1.0/ + +##########################################################################################*/ + +#ifndef PAX_GRAPHICA_CIRCLE_IMPL_HPP +#define PAX_GRAPHICA_CIRCLE_IMPL_HPP + +#include + +namespace paxg { + + // Forward declarations + struct Color; + + /// @brief Abstract base class for Circle implementation (Strategy pattern) + /// @note Each graphics library provides its own implementation + class CircleImpl { + public: + virtual ~CircleImpl() = default; + + /// @brief Draw the circle without color + virtual void draw() const = 0; + + /// @brief Draw the circle with specified color + /// @param color The color to draw the circle + virtual void draw(const Color& color) const = 0; + + /// @brief Get the position of the circle center + /// @return Position as Vector2 + virtual paxs::Vector2 getPosition() const = 0; + + /// @brief Get the radius of the circle + virtual float getRadius() const = 0; + }; + +} + +#endif // !PAX_GRAPHICA_CIRCLE_IMPL_HPP diff --git a/Library/PAX_GRAPHICA/Null/NullCircleImpl.hpp b/Library/PAX_GRAPHICA/Null/NullCircleImpl.hpp new file mode 100644 index 000000000..0379a169b --- /dev/null +++ b/Library/PAX_GRAPHICA/Null/NullCircleImpl.hpp @@ -0,0 +1,60 @@ +/*########################################################################################## + + PAX SAPIENTICA Library 💀🌿🌏 + + [Planning] 2023-2024 As Project + [Production] 2023-2024 As Project + [Contact Us] wanotaitei@gmail.com https://github.com/AsPJT/PAX_SAPIENTICA + [License] Distributed under the CC0 1.0. https://creativecommons.org/publicdomain/zero/1.0/ + +##########################################################################################*/ + +#ifndef PAX_GRAPHICA_NULL_CIRCLE_IMPL_HPP +#define PAX_GRAPHICA_NULL_CIRCLE_IMPL_HPP + +#include + +namespace paxg { + + struct Color; + + /// @brief Null (no-op) implementation of CircleImpl + /// @note Used when no graphics library is available + class NullCircleImpl : public CircleImpl { + private: + float x, y, r; + + public: + /// @brief Constructor with position and radius + /// @param x X-coordinate of the circle center + /// @param y Y-coordinate of the circle center + /// @param r Radius of the circle + constexpr NullCircleImpl(float x, float y, float r) + : x(x), y(y), r(r) {} + + /// @brief Draw the circle without color (no-op) + void draw() const override { + // No operation + } + + /// @brief Draw the circle with specified color (no-op) + /// @param color The color to draw the circle (unused) + void draw(const Color&) const override { + // No operation + } + + /// @brief Get the position of the circle center + /// @return Position as Vector2 + paxs::Vector2 getPosition() const override { + return paxs::Vector2(x, y); + } + + /// @brief Get the radius of the circle + float getRadius() const override { + return r; + } + }; + +} + +#endif // !PAX_GRAPHICA_NULL_CIRCLE_IMPL_HPP diff --git a/Library/PAX_GRAPHICA/SFML/SFMLCircleImpl.hpp b/Library/PAX_GRAPHICA/SFML/SFMLCircleImpl.hpp new file mode 100644 index 000000000..5f81bc5d0 --- /dev/null +++ b/Library/PAX_GRAPHICA/SFML/SFMLCircleImpl.hpp @@ -0,0 +1,74 @@ +/*########################################################################################## + + PAX SAPIENTICA Library 💀🌿🌏 + + [Planning] 2023-2024 As Project + [Production] 2023-2024 As Project + [Contact Us] wanotaitei@gmail.com https://github.com/AsPJT/PAX_SAPIENTICA + [License] Distributed under the CC0 1.0. https://creativecommons.org/publicdomain/zero/1.0/ + +##########################################################################################*/ + +#ifndef PAX_GRAPHICA_SFML_CIRCLE_IMPL_HPP +#define PAX_GRAPHICA_SFML_CIRCLE_IMPL_HPP + +#include + +#ifdef PAXS_USING_SFML +#include +#include +#include +#endif + +namespace paxg { + + struct Color; + +#ifdef PAXS_USING_SFML + + /// @brief SFML implementation of CircleImpl + class SFMLCircleImpl : public CircleImpl { + private: + float x, y, r; + mutable sf::CircleShape circleShape; + + public: + /// @brief Constructor with position and radius + /// @param x X-coordinate of the circle center + /// @param y Y-coordinate of the circle center + /// @param r Radius of the circle + SFMLCircleImpl(float x, float y, float r) + : x(x), y(y), r(r), circleShape(r) {} + + /// @brief Draw the circle without color + void draw() const override { + circleShape.setPosition({x, y}); + Window::window().draw(circleShape); + } + + /// @brief Draw the circle with specified color + /// @param color The color to draw the circle + void draw(const Color& color) const override { + circleShape.setRadius(r); + circleShape.setPosition({x, y}); + circleShape.setFillColor(color.color); + Window::window().draw(circleShape); + } + + /// @brief Get the position of the circle center + /// @return Position as Vector2 + paxs::Vector2 getPosition() const override { + return paxs::Vector2(x, y); + } + + /// @brief Get the radius of the circle + float getRadius() const override { + return r; + } + }; + +#endif // PAXS_USING_SFML + +} + +#endif // !PAX_GRAPHICA_SFML_CIRCLE_IMPL_HPP diff --git a/Library/PAX_GRAPHICA/SFML_Circle.hpp b/Library/PAX_GRAPHICA/SFML_Circle.hpp deleted file mode 100644 index 2fdffddb0..000000000 --- a/Library/PAX_GRAPHICA/SFML_Circle.hpp +++ /dev/null @@ -1,55 +0,0 @@ -/*########################################################################################## - - PAX SAPIENTICA Library 💀🌿🌏 - - [Planning] 2023-2024 As Project - [Production] 2023-2024 As Project - [Contact Us] wanotaitei@gmail.com https://github.com/AsPJT/PAX_SAPIENTICA - [License] Distributed under the CC0 1.0. https://creativecommons.org/publicdomain/zero/1.0/ - -##########################################################################################*/ - -#ifndef PAX_GRAPHICA_SFML_CIRCLE_HPP -#define PAX_GRAPHICA_SFML_CIRCLE_HPP - -#ifdef PAXS_USING_SFML -#include -#endif - -namespace paxg { - - // 実行時定数 - class SFML_Circle { - private: - static SFML_Circle instance; - -#if defined(PAXS_USING_SFML) - SFML_Circle() {} -#else - SFML_Circle() = default; -#endif - ~SFML_Circle() = default; - - public: - // Delete copy and move operations - SFML_Circle(const SFML_Circle&) = delete; - SFML_Circle& operator=(const SFML_Circle&) = delete; - SFML_Circle(SFML_Circle&&) = delete; - SFML_Circle& operator=(SFML_Circle&&) = delete; - -#if defined(PAXS_USING_SFML) - sf::CircleShape circle; -#endif - - // インスタンスを取得 - static SFML_Circle* getInstance() { - return &instance; - } - }; - - // Static member definition - SFML_Circle SFML_Circle::instance; - -} - -#endif // !PAX_GRAPHICA_SFML_CIRCLE_HPP diff --git a/Library/PAX_GRAPHICA/Siv3D/Siv3DCircleImpl.hpp b/Library/PAX_GRAPHICA/Siv3D/Siv3DCircleImpl.hpp new file mode 100644 index 000000000..f8c04d614 --- /dev/null +++ b/Library/PAX_GRAPHICA/Siv3D/Siv3DCircleImpl.hpp @@ -0,0 +1,72 @@ +/*########################################################################################## + + PAX SAPIENTICA Library 💀🌿🌏 + + [Planning] 2023-2024 As Project + [Production] 2023-2024 As Project + [Contact Us] wanotaitei@gmail.com https://github.com/AsPJT/PAX_SAPIENTICA + [License] Distributed under the CC0 1.0. https://creativecommons.org/publicdomain/zero/1.0/ + +##########################################################################################*/ + +#ifndef PAX_GRAPHICA_SIV3D_CIRCLE_IMPL_HPP +#define PAX_GRAPHICA_SIV3D_CIRCLE_IMPL_HPP + +#include + +#ifdef PAXS_USING_SIV3D +#include +#endif + +namespace paxg { + + struct Color; + +#ifdef PAXS_USING_SIV3D + + /// @brief Siv3D implementation of CircleImpl + class Siv3DCircleImpl : public CircleImpl { + private: + s3d::Circle circle; + + public: + /// @brief Constructor with position and radius + /// @param x X-coordinate of the circle center + /// @param y Y-coordinate of the circle center + /// @param r Radius of the circle + constexpr Siv3DCircleImpl(float x, float y, float r) + : circle(x, y, r) {} + + /// @brief Draw the circle without color + void draw() const override { + circle.draw(); + } + + /// @brief Draw the circle with specified color + /// @param color The color to draw the circle + void draw(const Color& color) const override { + circle.draw(color.color); + } + + /// @brief Get the position of the circle center + /// @return Position as Vector2 + paxs::Vector2 getPosition() const override { + return paxs::Vector2(static_cast(circle.x), static_cast(circle.y)); + } + + /// @brief Get the radius of the circle + float getRadius() const override { + return static_cast(circle.r); + } + + /// @brief Get the underlying Siv3D circle + constexpr const s3d::Circle& getNativeCircle() const { + return circle; + } + }; + +#endif // PAXS_USING_SIV3D + +} + +#endif // !PAX_GRAPHICA_SIV3D_CIRCLE_IMPL_HPP diff --git a/Projects/IncludeTest/source/PAX_GRAPHICA/DxLib/DxLibCircleImplIncludeTest.cpp b/Projects/IncludeTest/source/PAX_GRAPHICA/DxLib/DxLibCircleImplIncludeTest.cpp new file mode 100644 index 000000000..a239543a8 --- /dev/null +++ b/Projects/IncludeTest/source/PAX_GRAPHICA/DxLib/DxLibCircleImplIncludeTest.cpp @@ -0,0 +1,3 @@ +#include + +int main(){} diff --git a/Projects/IncludeTest/source/PAX_GRAPHICA/Interface/CircleImplIncludeTest.cpp b/Projects/IncludeTest/source/PAX_GRAPHICA/Interface/CircleImplIncludeTest.cpp new file mode 100644 index 000000000..26fdb014d --- /dev/null +++ b/Projects/IncludeTest/source/PAX_GRAPHICA/Interface/CircleImplIncludeTest.cpp @@ -0,0 +1,3 @@ +#include + +int main(){} diff --git a/Projects/IncludeTest/source/PAX_GRAPHICA/Null/NullCircleImplIncludeTest.cpp b/Projects/IncludeTest/source/PAX_GRAPHICA/Null/NullCircleImplIncludeTest.cpp new file mode 100644 index 000000000..de2a3a4bd --- /dev/null +++ b/Projects/IncludeTest/source/PAX_GRAPHICA/Null/NullCircleImplIncludeTest.cpp @@ -0,0 +1,3 @@ +#include + +int main(){} diff --git a/Projects/IncludeTest/source/PAX_GRAPHICA/SFML/SFMLCircleImplIncludeTest.cpp b/Projects/IncludeTest/source/PAX_GRAPHICA/SFML/SFMLCircleImplIncludeTest.cpp new file mode 100644 index 000000000..634a2d1d8 --- /dev/null +++ b/Projects/IncludeTest/source/PAX_GRAPHICA/SFML/SFMLCircleImplIncludeTest.cpp @@ -0,0 +1,3 @@ +#include + +int main(){} diff --git a/Projects/IncludeTest/source/PAX_GRAPHICA/SFML_CircleIncludeTest.cpp b/Projects/IncludeTest/source/PAX_GRAPHICA/SFML_CircleIncludeTest.cpp deleted file mode 100644 index dd9c6e617..000000000 --- a/Projects/IncludeTest/source/PAX_GRAPHICA/SFML_CircleIncludeTest.cpp +++ /dev/null @@ -1,3 +0,0 @@ -#include - -int main(){} diff --git a/Projects/IncludeTest/source/PAX_GRAPHICA/Siv3D/Siv3DCircleImplIncludeTest.cpp b/Projects/IncludeTest/source/PAX_GRAPHICA/Siv3D/Siv3DCircleImplIncludeTest.cpp new file mode 100644 index 000000000..4245cff8e --- /dev/null +++ b/Projects/IncludeTest/source/PAX_GRAPHICA/Siv3D/Siv3DCircleImplIncludeTest.cpp @@ -0,0 +1,3 @@ +#include + +int main(){} From ab26b3a164e7033486123b9684d66136d94b52a8 Mon Sep 17 00:00:00 2001 From: guinpen98 <83969826+guinpen98@users.noreply.github.com> Date: Wed, 3 Dec 2025 21:50:20 +0900 Subject: [PATCH 2/9] ref: 3dmodel --- Library/PAX_GRAPHICA/3DModel.hpp | 192 ++++-------------- .../Interface/Graphics3DModelImpl.hpp | 77 +++++++ .../Null/NullGraphics3DModelImpl.hpp | 69 +++++++ .../Siv3D/Siv3DGraphics3DModelImpl.hpp | 152 ++++++++++++++ .../Graphics3DModelImplIncludeTest.cpp | 3 + .../NullGraphics3DModelImplIncludeTest.cpp | 3 + .../Siv3DGraphics3DModelImplIncludeTest.cpp | 3 + 7 files changed, 347 insertions(+), 152 deletions(-) create mode 100644 Library/PAX_GRAPHICA/Interface/Graphics3DModelImpl.hpp create mode 100644 Library/PAX_GRAPHICA/Null/NullGraphics3DModelImpl.hpp create mode 100644 Library/PAX_GRAPHICA/Siv3D/Siv3DGraphics3DModelImpl.hpp create mode 100644 Projects/IncludeTest/source/PAX_GRAPHICA/Interface/Graphics3DModelImplIncludeTest.cpp create mode 100644 Projects/IncludeTest/source/PAX_GRAPHICA/Null/NullGraphics3DModelImplIncludeTest.cpp create mode 100644 Projects/IncludeTest/source/PAX_GRAPHICA/Siv3D/Siv3DGraphics3DModelImplIncludeTest.cpp diff --git a/Library/PAX_GRAPHICA/3DModel.hpp b/Library/PAX_GRAPHICA/3DModel.hpp index 83db1c082..607ded179 100644 --- a/Library/PAX_GRAPHICA/3DModel.hpp +++ b/Library/PAX_GRAPHICA/3DModel.hpp @@ -12,205 +12,93 @@ #ifndef PAX_MAHOROBA_3D_MODEL_HPP #define PAX_MAHOROBA_3D_MODEL_HPP +#include + +#include + #if defined(PAXS_USING_SIV3D) -#include -#elif defined(PAXS_USING_DXLIB) -#include -#elif defined(PAXS_USING_SFML) -#include +#include +#else +#include #endif -#include -#include - namespace paxg { - /// @brief 3D モデル描画の設定 - struct Graphics3DModelConfig { - /// @brief カメラ設定 - struct Camera { - /// @brief 垂直視野角(度) - double verticalFOV = 40.0; - double posX = 0.0; - double posY = 3.0; - double posZ = -16.0; - } camera; - - /// @brief 背景色設定 - struct Background { - float r = 1.0f; // 赤成分 - float g = 1.0f; // 緑成分 - float b = 1.0f; // 青成分 - float a = 0.0f; // 透明度 - } background; - - /// @brief ファイルパス設定 - struct FilePaths { - std::string modelPath = "Data/3DModels/KofunOBJ/Model/Sekishitsu/KamoKitaKofun/KamoKitaKofun.obj"; - } paths; - - /// @brief モデルの回転速度(度/フレーム) - double rotationSpeed = 1.0; - }; - - /// @brief 3D モデル描画クラス + /// @brief 3D モデル描画クラス with Pimpl idiom for graphics library abstraction + /// @note Uses unique_ptr for implementation hiding and automatic resource management class Graphics3DModel { private: Graphics3DModelConfig config_; + std::unique_ptr impl_; -#ifdef PAXS_USING_SIV3D - // 回転角度 - int rotation_ = 0; - - s3d::ColorF backgroundColor_; - - // 3D モデルデータ - s3d::Model model_; - - // 描画するテクスチャの設定 - mutable s3d::MSRenderTexture renderTexture_; - - // カメラ - mutable s3d::DebugCamera3D camera_; + /// @brief Create implementation based on the active graphics library + /// @param cfg Configuration for 3D model + /// @return Unique pointer to the implementation + static std::unique_ptr createImpl(const Graphics3DModelConfig& cfg) { +#if defined(PAXS_USING_SIV3D) + return std::make_unique(cfg); +#else + return std::make_unique(cfg); #endif + } public: /// @brief デフォルト設定でコンストラクタ Graphics3DModel() : Graphics3DModel(Graphics3DModelConfig{}) {} /// @brief カスタム設定でコンストラクタ - explicit Graphics3DModel(const Graphics3DModelConfig& cfg) : config_(cfg) { -#ifdef PAXS_USING_SIV3D - // カメラ設定 - camera_ = s3d::DebugCamera3D{ - s3d::Graphics3D::GetRenderTargetSize(), - paxs::Math::degToRad(config_.camera.verticalFOV), - s3d::Vec3{ config_.camera.posX, config_.camera.posY, config_.camera.posZ } - }; - - renderTexture_ = s3d::MSRenderTexture{ - s3d::Size{s3d::Scene::Width(), s3d::Scene::Height()}, - s3d::TextureFormat::R8G8B8A8_Unorm_SRGB, - s3d::HasDepth::Yes - }; - - // 背景色を設定 - backgroundColor_ = s3d::ColorF{ - config_.background.r, - config_.background.g, - config_.background.b, - config_.background.a - }.removeSRGBCurve(); - - // 3D モデルデータをロード - const auto rootPath = s3d::Unicode::FromUTF8(paxs::AppConfig::getInstance().getRootPath()); - model_ = s3d::Model{ rootPath + s3d::Unicode::FromUTF8(config_.paths.modelPath) }; - - // モデルに付随するテクスチャをアセット管理に登録 - s3d::Model::RegisterDiffuseTextures(model_, s3d::TextureDesc::MippedSRGB); -#endif - } + explicit Graphics3DModel(const Graphics3DModelConfig& cfg) + : config_(cfg), impl_(createImpl(cfg)) {} /// @brief 回転角度を更新 - /// @brief Update rotation angle void updateRotation() { -#ifdef PAXS_USING_SIV3D - // モデルの回転更新 - ++rotation_; - if (rotation_ >= 360) rotation_ = 0; -#endif + if (impl_) { + impl_->updateRotation(); + } } /// @brief 3Dモデルを描画 - /// @brief Render 3D model void render() const { -#ifdef PAXS_USING_SIV3D - s3d::Graphics3D::SetCameraTransform(camera_); // カメラ情報を設定 - - // 3D シーンの描画 - const s3d::ScopedRenderTarget3D target{ renderTexture_.clear(backgroundColor_) }; - - // 3Dモデルの描画 - const s3d::ScopedRenderStates3D renderStates{ - s3d::BlendState::OpaqueAlphaToCoverage, - s3d::RasterizerState::SolidCullNone - }; - model_.draw( - s3d::Vec3{ 0, 0, 0 }, - s3d::Quaternion::RotateY(paxs::Math::degToRad(static_cast(rotation_))) - ); - - // RenderTexture を 2D シーンに描画 - s3d::Graphics3D::Flush(); // 現在までの 3D 描画を実行 - - // 画面サイズが変更されたら幅を変える - // 毎フレームチェックすると重いため、3フレームに1回チェック - static int resize_check_count = 0; - if (resize_check_count >= 3) { - resize_check_count = 0; - if (renderTexture_.width() != s3d::Scene::Width() - || renderTexture_.height() != s3d::Scene::Height()) { - renderTexture_ = s3d::MSRenderTexture{ - s3d::Size{s3d::Scene::Width(), s3d::Scene::Height()}, - s3d::TextureFormat::R8G8B8A8_Unorm_SRGB, - s3d::HasDepth::Yes - }; - } + if (impl_) { + impl_->render(); } - ++resize_check_count; - - renderTexture_.resolve(); // テクスチャを描画可能にする - renderTexture_.draw(0, 0); // 指定した大きさで描画 -#endif } /// @brief 設定を取得 const Graphics3DModelConfig& getConfig() const { return config_; } /// @brief 設定を更新 - void setConfig(const Graphics3DModelConfig& cfg) { config_ = cfg; } + void setConfig(const Graphics3DModelConfig& cfg) { + config_ = cfg; + impl_ = createImpl(cfg); + } /// @brief カメラ設定を更新 void setCameraConfig(const Graphics3DModelConfig::Camera& cam) { config_.camera = cam; -#ifdef PAXS_USING_SIV3D - camera_ = s3d::DebugCamera3D{ - s3d::Graphics3D::GetRenderTargetSize(), - paxs::Math::degToRad(config_.camera.verticalFOV), - s3d::Vec3{ config_.camera.posX, config_.camera.posY, config_.camera.posZ } - }; -#endif + if (impl_) { + impl_->setCameraConfig(cam); + } } /// @brief 背景色設定を更新 void setBackgroundConfig(const Graphics3DModelConfig::Background& bg) { config_.background = bg; -#ifdef PAXS_USING_SIV3D - backgroundColor_ = s3d::ColorF{ - config_.background.r, - config_.background.g, - config_.background.b, - config_.background.a - }.removeSRGBCurve(); -#endif + if (impl_) { + impl_->setBackgroundConfig(bg); + } } /// @brief 現在の回転角度を取得(度) int getRotation() const { -#ifdef PAXS_USING_SIV3D - return rotation_; -#else - return 0; -#endif + return impl_ ? impl_->getRotation() : 0; } /// @brief 回転角度を設定(度) void setRotation(int angle) { -#ifdef PAXS_USING_SIV3D - rotation_ = angle % 360; -#else - (void)angle; -#endif + if (impl_) { + impl_->setRotation(angle); + } } }; diff --git a/Library/PAX_GRAPHICA/Interface/Graphics3DModelImpl.hpp b/Library/PAX_GRAPHICA/Interface/Graphics3DModelImpl.hpp new file mode 100644 index 000000000..9952fa748 --- /dev/null +++ b/Library/PAX_GRAPHICA/Interface/Graphics3DModelImpl.hpp @@ -0,0 +1,77 @@ +/*########################################################################################## + + PAX SAPIENTICA Library 💀🌿🌏 + + [Planning] 2023-2024 As Project + [Production] 2023-2024 As Project + [Contact Us] wanotaitei@gmail.com https://github.com/AsPJT/PAX_SAPIENTICA + [License] Distributed under the CC0 1.0. https://creativecommons.org/publicdomain/zero/1.0/ + +##########################################################################################*/ + +#ifndef PAX_GRAPHICA_GRAPHICS_3D_MODEL_IMPL_HPP +#define PAX_GRAPHICA_GRAPHICS_3D_MODEL_IMPL_HPP + +#include + +namespace paxg { + + /// @brief 3D モデル描画の設定 + struct Graphics3DModelConfig { + /// @brief カメラ設定 + struct Camera { + /// @brief 垂直視野角(度) + double verticalFOV = 40.0; + double posX = 0.0; + double posY = 3.0; + double posZ = -16.0; + } camera; + + /// @brief 背景色設定 + struct Background { + float r = 1.0f; // 赤成分 + float g = 1.0f; // 緑成分 + float b = 1.0f; // 青成分 + float a = 0.0f; // 透明度 + } background; + + /// @brief ファイルパス設定 + struct FilePaths { + std::string modelPath = "Data/3DModels/KofunOBJ/Model/Sekishitsu/KamoKitaKofun/KamoKitaKofun.obj"; + } paths; + + /// @brief モデルの回転速度(度/フレーム) + double rotationSpeed = 1.0; + }; + + /// @brief Abstract base class for Graphics3DModel implementation (Strategy pattern) + /// @note Each graphics library provides its own implementation + class Graphics3DModelImpl { + public: + virtual ~Graphics3DModelImpl() = default; + + /// @brief Update rotation angle + virtual void updateRotation() = 0; + + /// @brief Render 3D model + virtual void render() const = 0; + + /// @brief Get current rotation angle (degrees) + virtual int getRotation() const = 0; + + /// @brief Set rotation angle (degrees) + /// @param angle Rotation angle in degrees + virtual void setRotation(int angle) = 0; + + /// @brief Update camera configuration + /// @param cam Camera configuration + virtual void setCameraConfig(const Graphics3DModelConfig::Camera& cam) = 0; + + /// @brief Update background configuration + /// @param bg Background configuration + virtual void setBackgroundConfig(const Graphics3DModelConfig::Background& bg) = 0; + }; + +} + +#endif // !PAX_GRAPHICA_GRAPHICS_3D_MODEL_IMPL_HPP diff --git a/Library/PAX_GRAPHICA/Null/NullGraphics3DModelImpl.hpp b/Library/PAX_GRAPHICA/Null/NullGraphics3DModelImpl.hpp new file mode 100644 index 000000000..984bbe451 --- /dev/null +++ b/Library/PAX_GRAPHICA/Null/NullGraphics3DModelImpl.hpp @@ -0,0 +1,69 @@ +/*########################################################################################## + + PAX SAPIENTICA Library 💀🌿🌏 + + [Planning] 2023-2024 As Project + [Production] 2023-2024 As Project + [Contact Us] wanotaitei@gmail.com https://github.com/AsPJT/PAX_SAPIENTICA + [License] Distributed under the CC0 1.0. https://creativecommons.org/publicdomain/zero/1.0/ + +##########################################################################################*/ + +#ifndef PAX_GRAPHICA_NULL_GRAPHICS_3D_MODEL_IMPL_HPP +#define PAX_GRAPHICA_NULL_GRAPHICS_3D_MODEL_IMPL_HPP + +#include + +namespace paxg { + + struct Graphics3DModelConfig; + + /// @brief Null (no-op) implementation of Graphics3DModelImpl + /// @note Used when no graphics library is available + class NullGraphics3DModelImpl : public Graphics3DModelImpl { + private: + int rotation_ = 0; + + public: + /// @brief Constructor with configuration + /// @param cfg Configuration for 3D model (unused) + explicit NullGraphics3DModelImpl(const Graphics3DModelConfig&) {} + + /// @brief Update rotation angle (no-op) + void updateRotation() override { + ++rotation_; + if (rotation_ >= 360) rotation_ = 0; + } + + /// @brief Render 3D model (no-op) + void render() const override { + // No operation + } + + /// @brief Get current rotation angle (degrees) + int getRotation() const override { + return rotation_; + } + + /// @brief Set rotation angle (degrees) + /// @param angle Rotation angle in degrees + void setRotation(int angle) override { + rotation_ = angle % 360; + } + + /// @brief Update camera configuration (no-op) + /// @param cam Camera configuration (unused) + void setCameraConfig(const Graphics3DModelConfig::Camera&) override { + // No operation + } + + /// @brief Update background configuration (no-op) + /// @param bg Background configuration (unused) + void setBackgroundConfig(const Graphics3DModelConfig::Background&) override { + // No operation + } + }; + +} + +#endif // !PAX_GRAPHICA_NULL_GRAPHICS_3D_MODEL_IMPL_HPP diff --git a/Library/PAX_GRAPHICA/Siv3D/Siv3DGraphics3DModelImpl.hpp b/Library/PAX_GRAPHICA/Siv3D/Siv3DGraphics3DModelImpl.hpp new file mode 100644 index 000000000..280c693ef --- /dev/null +++ b/Library/PAX_GRAPHICA/Siv3D/Siv3DGraphics3DModelImpl.hpp @@ -0,0 +1,152 @@ +/*########################################################################################## + + PAX SAPIENTICA Library 💀🌿🌏 + + [Planning] 2023-2024 As Project + [Production] 2023-2024 As Project + [Contact Us] wanotaitei@gmail.com https://github.com/AsPJT/PAX_SAPIENTICA + [License] Distributed under the CC0 1.0. https://creativecommons.org/publicdomain/zero/1.0/ + +##########################################################################################*/ + +#ifndef PAX_GRAPHICA_SIV3D_GRAPHICS_3D_MODEL_IMPL_HPP +#define PAX_GRAPHICA_SIV3D_GRAPHICS_3D_MODEL_IMPL_HPP + +#include + +#ifdef PAXS_USING_SIV3D +#include +#include +#include +#endif + +namespace paxg { + + struct Graphics3DModelConfig; + +#ifdef PAXS_USING_SIV3D + + /// @brief Siv3D implementation of Graphics3DModelImpl + class Siv3DGraphics3DModelImpl : public Graphics3DModelImpl { + private: + const Graphics3DModelConfig& config_; + int rotation_ = 0; + s3d::ColorF backgroundColor_; + s3d::Model model_; + mutable s3d::MSRenderTexture renderTexture_; + mutable s3d::DebugCamera3D camera_; + + public: + /// @brief Constructor with configuration + /// @param cfg Configuration for 3D model + explicit Siv3DGraphics3DModelImpl(const Graphics3DModelConfig& cfg) + : config_(cfg) { + // カメラ設定 + camera_ = s3d::DebugCamera3D{ + s3d::Graphics3D::GetRenderTargetSize(), + paxs::Math::degToRad(config_.camera.verticalFOV), + s3d::Vec3{ config_.camera.posX, config_.camera.posY, config_.camera.posZ } + }; + + renderTexture_ = s3d::MSRenderTexture{ + s3d::Size{s3d::Scene::Width(), s3d::Scene::Height()}, + s3d::TextureFormat::R8G8B8A8_Unorm_SRGB, + s3d::HasDepth::Yes + }; + + // 背景色を設定 + backgroundColor_ = s3d::ColorF{ + config_.background.r, + config_.background.g, + config_.background.b, + config_.background.a + }.removeSRGBCurve(); + + // 3D モデルデータをロード + const auto rootPath = s3d::Unicode::FromUTF8(paxs::AppConfig::getInstance().getRootPath()); + model_ = s3d::Model{ rootPath + s3d::Unicode::FromUTF8(config_.paths.modelPath) }; + + // モデルに付随するテクスチャをアセット管理に登録 + s3d::Model::RegisterDiffuseTextures(model_, s3d::TextureDesc::MippedSRGB); + } + + /// @brief Update rotation angle + void updateRotation() override { + ++rotation_; + if (rotation_ >= 360) rotation_ = 0; + } + + /// @brief Render 3D model + void render() const override { + s3d::Graphics3D::SetCameraTransform(camera_); + + // 3D シーンの描画 + const s3d::ScopedRenderTarget3D target{ renderTexture_.clear(backgroundColor_) }; + + // 3Dモデルの描画 + const s3d::ScopedRenderStates3D renderStates{ + s3d::BlendState::OpaqueAlphaToCoverage, + s3d::RasterizerState::SolidCullNone + }; + model_.draw( + s3d::Vec3{ 0, 0, 0 }, + s3d::Quaternion::RotateY(paxs::Math::degToRad(static_cast(rotation_))) + ); + + // RenderTexture を 2D シーンに描画 + s3d::Graphics3D::Flush(); + + // 画面サイズが変更されたら幅を変える + static int resize_check_count = 0; + if (resize_check_count >= 3) { + resize_check_count = 0; + if (renderTexture_.width() != s3d::Scene::Width() + || renderTexture_.height() != s3d::Scene::Height()) { + renderTexture_ = s3d::MSRenderTexture{ + s3d::Size{s3d::Scene::Width(), s3d::Scene::Height()}, + s3d::TextureFormat::R8G8B8A8_Unorm_SRGB, + s3d::HasDepth::Yes + }; + } + } + ++resize_check_count; + + renderTexture_.resolve(); + renderTexture_.draw(0, 0); + } + + /// @brief Get current rotation angle (degrees) + int getRotation() const override { + return rotation_; + } + + /// @brief Set rotation angle (degrees) + /// @param angle Rotation angle in degrees + void setRotation(int angle) override { + rotation_ = angle % 360; + } + + /// @brief Update camera configuration + /// @param cam Camera configuration + void setCameraConfig(const Graphics3DModelConfig::Camera& cam) override { + camera_ = s3d::DebugCamera3D{ + s3d::Graphics3D::GetRenderTargetSize(), + paxs::Math::degToRad(cam.verticalFOV), + s3d::Vec3{ cam.posX, cam.posY, cam.posZ } + }; + } + + /// @brief Update background configuration + /// @param bg Background configuration + void setBackgroundConfig(const Graphics3DModelConfig::Background& bg) override { + backgroundColor_ = s3d::ColorF{ + bg.r, bg.g, bg.b, bg.a + }.removeSRGBCurve(); + } + }; + +#endif // PAXS_USING_SIV3D + +} + +#endif // !PAX_GRAPHICA_SIV3D_GRAPHICS_3D_MODEL_IMPL_HPP diff --git a/Projects/IncludeTest/source/PAX_GRAPHICA/Interface/Graphics3DModelImplIncludeTest.cpp b/Projects/IncludeTest/source/PAX_GRAPHICA/Interface/Graphics3DModelImplIncludeTest.cpp new file mode 100644 index 000000000..a4567cc7d --- /dev/null +++ b/Projects/IncludeTest/source/PAX_GRAPHICA/Interface/Graphics3DModelImplIncludeTest.cpp @@ -0,0 +1,3 @@ +#include + +int main(){} diff --git a/Projects/IncludeTest/source/PAX_GRAPHICA/Null/NullGraphics3DModelImplIncludeTest.cpp b/Projects/IncludeTest/source/PAX_GRAPHICA/Null/NullGraphics3DModelImplIncludeTest.cpp new file mode 100644 index 000000000..d91c74fef --- /dev/null +++ b/Projects/IncludeTest/source/PAX_GRAPHICA/Null/NullGraphics3DModelImplIncludeTest.cpp @@ -0,0 +1,3 @@ +#include + +int main(){} diff --git a/Projects/IncludeTest/source/PAX_GRAPHICA/Siv3D/Siv3DGraphics3DModelImplIncludeTest.cpp b/Projects/IncludeTest/source/PAX_GRAPHICA/Siv3D/Siv3DGraphics3DModelImplIncludeTest.cpp new file mode 100644 index 000000000..c351beb4f --- /dev/null +++ b/Projects/IncludeTest/source/PAX_GRAPHICA/Siv3D/Siv3DGraphics3DModelImplIncludeTest.cpp @@ -0,0 +1,3 @@ +#include + +int main(){} From e6463ea52d7c5d6a4b84a8f7001348c04d84b51b Mon Sep 17 00:00:00 2001 From: guinpen98 <83969826+guinpen98@users.noreply.github.com> Date: Thu, 4 Dec 2025 00:29:28 +0900 Subject: [PATCH 3/9] ref: vec2 --- Library/PAX_GRAPHICA/Font.hpp | 242 +++++++++--------- Library/PAX_GRAPHICA/Line.hpp | 123 ++++----- Library/PAX_GRAPHICA/Mouse.hpp | 9 +- Library/PAX_GRAPHICA/Rect.hpp | 34 +-- Library/PAX_GRAPHICA/RoundRect.hpp | 168 ++++++------ Library/PAX_GRAPHICA/Spline2D.hpp | 117 ++++++--- Library/PAX_GRAPHICA/Triangle.hpp | 12 +- Library/PAX_GRAPHICA/Vec2.hpp | 129 ---------- .../Map/Content/Feature/FlowCurveFeature.hpp | 85 +++--- .../Map/Content/Feature/GenomeFeature.hpp | 2 +- .../Map/Content/Feature/PersonFeature.hpp | 2 +- .../Map/Content/Feature/TerritoryFeature.hpp | 17 +- .../Interaction/MapContentHitTester.hpp | 31 ++- .../Map/Content/Renderer/GeometryRenderer.hpp | 1 - .../Content/Renderer/MapFeatureRenderer.hpp | 14 +- .../Map/Simulation/SettlementRenderer.hpp | 68 +++-- .../UI/Calendar/CalendarContent.hpp | 46 ++-- Library/PAX_MAHOROBA/UI/DebugInfoPanel.hpp | 23 +- Library/PAX_MAHOROBA/UI/MenuBar/MenuBar.hpp | 13 +- Library/PAX_MAHOROBA/UI/Pulldown.hpp | 6 +- .../UI/Simulation/SimulationPanel.hpp | 1 - Library/PAX_SAPIENTICA/Core/Type/Vector2.hpp | 2 +- .../Simulation/Config/JapanProvinces.hpp | 14 +- .../source/PAX_GRAPHICA/Vec2IncludeTest.cpp | 3 - .../IntegrationTest/Source/WindowTest.cpp | 1 - .../Source/PAX_GRAPHICA/MouseUnitTest.cpp | 4 +- .../Source/PAX_GRAPHICA/TriangleUnitTest.cpp | 4 +- .../Source/PAX_GRAPHICA/Vec2UnitTest.cpp | 152 ----------- 28 files changed, 517 insertions(+), 806 deletions(-) delete mode 100644 Library/PAX_GRAPHICA/Vec2.hpp delete mode 100644 Projects/IncludeTest/source/PAX_GRAPHICA/Vec2IncludeTest.cpp delete mode 100644 Projects/UnitTest/Source/PAX_GRAPHICA/Vec2UnitTest.cpp diff --git a/Library/PAX_GRAPHICA/Font.hpp b/Library/PAX_GRAPHICA/Font.hpp index 5638d3478..69e62f47e 100644 --- a/Library/PAX_GRAPHICA/Font.hpp +++ b/Library/PAX_GRAPHICA/Font.hpp @@ -24,10 +24,10 @@ #endif #include -#include #include #include +#include #include #include @@ -51,131 +51,130 @@ namespace paxg{ /// @brief テキストを左下揃えで描画 (横:左端, 縦:下端) /// @brief Draw text with bottom-left alignment (horizontal: left, vertical: bottom) - void drawBottomLeft(const std::string& str, const paxg::Vec2i& pos, const paxg::Color& color) const { + void drawBottomLeft(const std::string& str, const paxs::Vector2& pos, const paxg::Color& color) const { if (is_outline) { font(s3d::Unicode::FromUTF8(str)).draw( outline, - s3d::Arg::bottomLeft = s3d::Vec2(pos.x(), pos.y()), + s3d::Arg::bottomLeft = s3d::Vec2(pos.x, pos.y), color.color); } else { font(s3d::Unicode::FromUTF8(str)).draw( - s3d::Arg::bottomLeft = s3d::Vec2(pos.x(), pos.y()), + s3d::Arg::bottomLeft = s3d::Vec2(pos.x, pos.y), color.color); } } /// @brief テキストを右上揃えで描画 (横:右端, 縦:上端) /// @brief Draw text with top-right alignment (horizontal: right, vertical: top) - void drawTopRight(const std::string& str, const paxg::Vec2i& pos, const paxg::Color& color) const { + void drawTopRight(const std::string& str, const paxs::Vector2& pos, const paxg::Color& color) const { if (is_outline) { font(s3d::Unicode::FromUTF8(str)).draw( outline, - s3d::Arg::topRight = s3d::Vec2(pos.x(), pos.y()), + s3d::Arg::topRight = s3d::Vec2(pos.x, pos.y), color.color); } else { font(s3d::Unicode::FromUTF8(str)).draw( - s3d::Arg::topRight = s3d::Vec2(pos.x(), pos.y()), + s3d::Arg::topRight = s3d::Vec2(pos.x, pos.y), color.color); } } /// @brief テキストを右下揃えで描画 (横:右端, 縦:下端) /// @brief Draw text with bottom-right alignment (horizontal: right, vertical: bottom) - void drawBottomRight(const std::string& str, const paxg::Vec2i& pos, const paxg::Color& color) const { + void drawBottomRight(const std::string& str, const paxs::Vector2& pos, const paxg::Color& color) const { if (is_outline) { font(s3d::Unicode::FromUTF8(str)).draw( outline, - s3d::Arg::bottomRight = s3d::Vec2(pos.x(), pos.y()), + s3d::Arg::bottomRight = s3d::Vec2(pos.x, pos.y), color.color); } else { font(s3d::Unicode::FromUTF8(str)).draw( - s3d::Arg::bottomRight = s3d::Vec2(pos.x(), pos.y()), + s3d::Arg::bottomRight = s3d::Vec2(pos.x, pos.y), color.color); } } /// @brief テキストを左上揃えで描画 (横:左端, 縦:上端) /// @brief Draw text with top-left alignment (horizontal: left, vertical: top) - void draw(const std::string& str, const paxg::Vec2i& pos, const paxg::Color& color) const { + void draw(const std::string& str, const paxs::Vector2& pos, const paxg::Color& color) const { if (is_outline) { font(s3d::Unicode::FromUTF8(str)).draw( outline, - s3d::Vec2(pos.x(), pos.y()), + s3d::Vec2(pos.x, pos.y), color.color); } else { font(s3d::Unicode::FromUTF8(str)).draw( - s3d::Vec2(pos.x(), pos.y()), + s3d::Vec2(pos.x, pos.y), color.color); } } /// @brief テキストを中央下揃えで描画 (横:中央, 縦:下端) /// @brief Draw text with bottom-center alignment (horizontal: center, vertical: bottom) - void drawBottomCenter(const std::string& str, const paxg::Vec2i& pos, const paxg::Color& color) const { + void drawBottomCenter(const std::string& str, const paxs::Vector2& pos, const paxg::Color& color) const { if (is_outline) { font(s3d::Unicode::FromUTF8(str)).draw( outline, - s3d::Arg::bottomCenter = s3d::Vec2(pos.x(), pos.y()), + s3d::Arg::bottomCenter = s3d::Vec2(pos.x, pos.y), color.color); } else { font(s3d::Unicode::FromUTF8(str)).draw( - s3d::Arg::bottomCenter = s3d::Vec2(pos.x(), pos.y()), + s3d::Arg::bottomCenter = s3d::Vec2(pos.x, pos.y), color.color); } } /// @brief テキストを中央上揃えで描画 (横:中央, 縦:上端) /// @brief Draw text with top-center alignment (horizontal: center, vertical: top) - void drawTopCenter(const std::string& str, const paxg::Vec2i& pos, const paxg::Color& color) const { + void drawTopCenter(const std::string& str, const paxs::Vector2& pos, const paxg::Color& color) const { if (is_outline) { font(s3d::Unicode::FromUTF8(str)).draw( outline, - s3d::Arg::topCenter = s3d::Vec2(pos.x(), pos.y()), + s3d::Arg::topCenter = s3d::Vec2(pos.x, pos.y), color.color); } else { font(s3d::Unicode::FromUTF8(str)).draw( - s3d::Arg::topCenter = s3d::Vec2(pos.x(), pos.y()), + s3d::Arg::topCenter = s3d::Vec2(pos.x, pos.y), color.color); } } /// @brief テキストを中央揃えで描画 (横:中央, 縦:中央) /// @brief Draw text with center alignment (horizontal: center, vertical: center) - void drawAt(const std::string& str, const paxg::Vec2i& pos, const paxg::Color& color) const { + void drawAt(const std::string& str, const paxs::Vector2& pos, const paxg::Color& color) const { if (is_outline) { font(s3d::Unicode::FromUTF8(str)).drawAt( outline, - s3d::Vec2(pos.x(), pos.y()), + s3d::Vec2(pos.x, pos.y), color.color); } else { font(s3d::Unicode::FromUTF8(str)).drawAt( - s3d::Vec2(pos.x(), pos.y()), + s3d::Vec2(pos.x, pos.y), color.color); } } - // Vec2 overloads - void drawBottomLeft(const std::string& str, const paxg::Vec2& pos, const paxg::Color& color) const { - drawBottomLeft(str, paxg::Vec2i{static_cast(pos.x()), static_cast(pos.y())}, color); + void drawBottomLeft(const std::string& str, const paxs::Vector2& pos, const paxg::Color& color) const { + drawBottomLeft(str, paxs::Vector2{pos}, color); } - void drawTopRight(const std::string& str, const paxg::Vec2& pos, const paxg::Color& color) const { - drawTopRight(str, paxg::Vec2i{static_cast(pos.x()), static_cast(pos.y())}, color); + void drawTopRight(const std::string& str, const paxs::Vector2& pos, const paxg::Color& color) const { + drawTopRight(str, paxs::Vector2{pos}, color); } - void drawBottomRight(const std::string& str, const paxg::Vec2& pos, const paxg::Color& color) const { - drawBottomRight(str, paxg::Vec2i{static_cast(pos.x()), static_cast(pos.y())}, color); + void drawBottomRight(const std::string& str, const paxs::Vector2& pos, const paxg::Color& color) const { + drawBottomRight(str, paxs::Vector2{pos}, color); } - void draw(const std::string& str, const paxg::Vec2& pos, const paxg::Color& color) const { - draw(str, paxg::Vec2i{static_cast(pos.x()), static_cast(pos.y())}, color); + void draw(const std::string& str, const paxs::Vector2& pos, const paxg::Color& color) const { + draw(str, paxs::Vector2{pos}, color); } - void drawBottomCenter(const std::string& str, const paxg::Vec2& pos, const paxg::Color& color) const { - drawBottomCenter(str, paxg::Vec2i{static_cast(pos.x()), static_cast(pos.y())}, color); + void drawBottomCenter(const std::string& str, const paxs::Vector2& pos, const paxg::Color& color) const { + drawBottomCenter(str, paxs::Vector2{pos}, color); } - void drawTopCenter(const std::string& str, const paxg::Vec2& pos, const paxg::Color& color) const { - drawTopCenter(str, paxg::Vec2i{static_cast(pos.x()), static_cast(pos.y())}, color); + void drawTopCenter(const std::string& str, const paxs::Vector2& pos, const paxg::Color& color) const { + drawTopCenter(str, paxs::Vector2{pos}, color); } - void drawAt(const std::string& str, const paxg::Vec2& pos, const paxg::Color& color) const { - drawAt(str, paxg::Vec2i{static_cast(pos.x()), static_cast(pos.y())}, color); + void drawAt(const std::string& str, const paxs::Vector2& pos, const paxg::Color& color) const { + drawAt(str, paxs::Vector2{pos}, color); } int height() const { @@ -229,7 +228,7 @@ namespace paxg{ } - void drawAlign(int align, paxg::Vec2i pos, std::string str_, const paxg::Color& color_, unsigned int edge_color = 0) const { + void drawAlign(int align, paxs::Vector2 pos, std::string str_, const paxg::Color& color_, unsigned int edge_color = 0) const { // std::size_t string_length; // align が 0左寄り 1中央寄り 2右寄り if (align < 0) align = 0; @@ -253,101 +252,100 @@ namespace paxg{ // str_len -= (char_count - string_length); // 差分を引いて文字数を調整 // } // x座標を調整して一行分描画する - DxLib::DrawNStringToHandle(pos.x() + ((align * (sizex - str_width)) / 2), pos.y(), + DxLib::DrawNStringToHandle(pos.x + ((align * (sizex - str_width)) / 2), pos.y, str_.c_str(), str_len, DxLib::GetColor(color_.r, color_.g, color_.b), font, edge_color, FALSE); // } char_count += 1; // 改行文字の分 str_ = std::string(next + 1); // 次の行の先頭にする(+1は改行文字の分) - pos.setY(pos.y() + line_space); // y座標をずらす + pos.y += line_space; // y座標をずらす } } /// @brief テキストを左下揃えで描画 (横:左端, 縦:下端) /// @brief Draw text with bottom-left alignment (horizontal: left, vertical: bottom) - void drawBottomLeft(const std::string& str, const paxg::Vec2i& pos, const paxg::Color& color) const { - if (font == -1) DxLib::DrawFormatString(pos.x(), pos.y() - 10, DxLib::GetColor(color.r, color.g, color.b), str.c_str()); - else DxLib::DrawStringToHandle(pos.x(), pos.y() - 10, str.c_str(), DxLib::GetColor(color.r, color.g, color.b), font, 0xffffffff); + void drawBottomLeft(const std::string& str, const paxs::Vector2& pos, const paxg::Color& color) const { + if (font == -1) DxLib::DrawFormatString(pos.x, pos.y - 10, DxLib::GetColor(color.r, color.g, color.b), str.c_str()); + else DxLib::DrawStringToHandle(pos.x, pos.y - 10, str.c_str(), DxLib::GetColor(color.r, color.g, color.b), font, 0xffffffff); } /// @brief テキストを右上揃えで描画 (横:右端, 縦:上端) /// @brief Draw text with top-right alignment (horizontal: right, vertical: top) - void drawTopRight(const std::string& str, const paxg::Vec2i& pos, const paxg::Color& color) const { - if (font == -1) DxLib::DrawFormatString(pos.x(), pos.y() + 10, DxLib::GetColor(color.r, color.g, color.b), str.c_str()); + void drawTopRight(const std::string& str, const paxs::Vector2& pos, const paxg::Color& color) const { + if (font == -1) DxLib::DrawFormatString(pos.x, pos.y + 10, DxLib::GetColor(color.r, color.g, color.b), str.c_str()); else { int size_x = 0, size_y = 0, line_count = 0; // 描画した時のサイズと行数を調べる DxLib::GetDrawStringSizeToHandle(&size_x, &size_y, &line_count, str.c_str(), static_cast(str.size()), font, FALSE); - DxLib::DrawStringToHandle(pos.x() - size_x, pos.y() + size_y / 2, str.c_str(), DxLib::GetColor(color.r, color.g, color.b), font, 0xffffffff); + DxLib::DrawStringToHandle(pos.x - size_x, pos.y + size_y / 2, str.c_str(), DxLib::GetColor(color.r, color.g, color.b), font, 0xffffffff); } } /// @brief テキストを右下揃えで描画 (横:右端, 縦:下端) /// @brief Draw text with bottom-right alignment (horizontal: right, vertical: bottom) - void drawBottomRight(const std::string& str, const paxg::Vec2i& pos, const paxg::Color& color) const { - if (font == -1) DxLib::DrawFormatString(pos.x(), pos.y() - 10, DxLib::GetColor(color.r, color.g, color.b), str.c_str()); + void drawBottomRight(const std::string& str, const paxs::Vector2& pos, const paxg::Color& color) const { + if (font == -1) DxLib::DrawFormatString(pos.x, pos.y - 10, DxLib::GetColor(color.r, color.g, color.b), str.c_str()); else { int size_x = 0, size_y = 0, line_count = 0; // 描画した時のサイズと行数を調べる DxLib::GetDrawStringSizeToHandle(&size_x, &size_y, &line_count, str.c_str(), static_cast(str.size()), font, FALSE); - // 文字の底部がpos.y()に来るように配置 - DxLib::DrawStringToHandle(pos.x() - size_x, pos.y() - size_y, str.c_str(), DxLib::GetColor(color.r, color.g, color.b), font, 0xffffffff); + // 文字の底部がpos.yに来るように配置 + DxLib::DrawStringToHandle(pos.x - size_x, pos.y - size_y, str.c_str(), DxLib::GetColor(color.r, color.g, color.b), font, 0xffffffff); } } /// @brief テキストを左上揃えで描画 (横:左端, 縦:上端) /// @brief Draw text with top-left alignment (horizontal: left, vertical: top) - void draw(const std::string& str, const paxg::Vec2i& pos, const paxg::Color& color) const { - if (font == -1) DxLib::DrawFormatString(pos.x(), pos.y(), DxLib::GetColor(color.r, color.g, color.b), str.c_str()); - else DxLib::DrawStringToHandle(pos.x(), pos.y(), str.c_str(), DxLib::GetColor(color.r, color.g, color.b), font, 0xffffffff); + void draw(const std::string& str, const paxs::Vector2& pos, const paxg::Color& color) const { + if (font == -1) DxLib::DrawFormatString(pos.x, pos.y, DxLib::GetColor(color.r, color.g, color.b), str.c_str()); + else DxLib::DrawStringToHandle(pos.x, pos.y, str.c_str(), DxLib::GetColor(color.r, color.g, color.b), font, 0xffffffff); } /// @brief テキストを中央下揃えで描画 (横:中央, 縦:下端) /// @brief Draw text with bottom-center alignment (horizontal: center, vertical: bottom) - void drawBottomCenter(const std::string& str, const paxg::Vec2i& pos, const paxg::Color& color) const { - if (font == -1) DxLib::DrawFormatString(pos.x(), pos.y() - 10, DxLib::GetColor(color.r, color.g, color.b), str.c_str()); + void drawBottomCenter(const std::string& str, const paxs::Vector2& pos, const paxg::Color& color) const { + if (font == -1) DxLib::DrawFormatString(pos.x, pos.y - 10, DxLib::GetColor(color.r, color.g, color.b), str.c_str()); else { int size_x = 0, size_y = 0, line_count = 0; // 描画した時のサイズと行数を調べる DxLib::GetDrawStringSizeToHandle(&size_x, &size_y, &line_count, str.c_str(), static_cast(str.size()), font, FALSE); - DxLib::DrawStringToHandle(pos.x() - size_x / 2, pos.y() - size_y / 2, str.c_str(), DxLib::GetColor(color.r, color.g, color.b), font, 0xffffffff); + DxLib::DrawStringToHandle(pos.x - size_x / 2, pos.y - size_y / 2, str.c_str(), DxLib::GetColor(color.r, color.g, color.b), font, 0xffffffff); } } /// @brief テキストを中央上揃えで描画 (横:中央, 縦:上端) /// @brief Draw text with top-center alignment (horizontal: center, vertical: top) - void drawTopCenter(const std::string& str, const paxg::Vec2i& pos, const paxg::Color& color) const { - if (font == -1) DxLib::DrawFormatString(pos.x(), pos.y() + 10, DxLib::GetColor(color.r, color.g, color.b), str.c_str()); + void drawTopCenter(const std::string& str, const paxs::Vector2& pos, const paxg::Color& color) const { + if (font == -1) DxLib::DrawFormatString(pos.x, pos.y + 10, DxLib::GetColor(color.r, color.g, color.b), str.c_str()); else { int size_x = 0, size_y = 0, line_count = 0; // 描画した時のサイズと行数を調べる DxLib::GetDrawStringSizeToHandle(&size_x, &size_y, &line_count, str.c_str(), static_cast(str.size()), font, FALSE); - DxLib::DrawStringToHandle(pos.x() - size_x / 2, pos.y() + size_y / 2, str.c_str(), DxLib::GetColor(color.r, color.g, color.b), font, 0xffffffff); + DxLib::DrawStringToHandle(pos.x - size_x / 2, pos.y + size_y / 2, str.c_str(), DxLib::GetColor(color.r, color.g, color.b), font, 0xffffffff); } } /// @brief テキストを中央揃えで描画 (横:中央, 縦:中央) /// @brief Draw text with center alignment (horizontal: center, vertical: center) - void drawAt(const std::string& str, const paxg::Vec2i& pos, const paxg::Color& color) const { - if (font == -1) DxLib::DrawFormatString(pos.x(), pos.y(), DxLib::GetColor(color.r, color.g, color.b), str.c_str()); + void drawAt(const std::string& str, const paxs::Vector2& pos, const paxg::Color& color) const { + if (font == -1) DxLib::DrawFormatString(pos.x, pos.y, DxLib::GetColor(color.r, color.g, color.b), str.c_str()); else { int size_x = 0, size_y = 0, line_count = 0; // 描画した時のサイズと行数を調べる DxLib::GetDrawStringSizeToHandle(&size_x, &size_y, &line_count, str.c_str(), static_cast(str.size()), font, FALSE); // 横方向は中央、縦方向も中央に揃える - DxLib::DrawStringToHandle(pos.x() - size_x / 2, pos.y() - size_y / 2, str.c_str(), DxLib::GetColor(color.r, color.g, color.b), font, 0xffffffff); + DxLib::DrawStringToHandle(pos.x - size_x / 2, pos.y - size_y / 2, str.c_str(), DxLib::GetColor(color.r, color.g, color.b), font, 0xffffffff); } } - // Vec2 overloads - void drawBottomLeft(const std::string& str, const paxg::Vec2& pos, const paxg::Color& color) const { - drawBottomLeft(str, paxg::Vec2i{static_cast(pos.x()), static_cast(pos.y())}, color); + void drawBottomLeft(const std::string& str, const paxs::Vector2& pos, const paxg::Color& color) const { + drawBottomLeft(str, paxs::Vector2{pos}, color); } - void drawTopRight(const std::string& str, const paxg::Vec2& pos, const paxg::Color& color) const { - drawTopRight(str, paxg::Vec2i{static_cast(pos.x()), static_cast(pos.y())}, color); + void drawTopRight(const std::string& str, const paxs::Vector2& pos, const paxg::Color& color) const { + drawTopRight(str, paxs::Vector2{pos}, color); } - void drawBottomRight(const std::string& str, const paxg::Vec2& pos, const paxg::Color& color) const { - drawBottomRight(str, paxg::Vec2i{static_cast(pos.x()), static_cast(pos.y())}, color); + void drawBottomRight(const std::string& str, const paxs::Vector2& pos, const paxg::Color& color) const { + drawBottomRight(str, paxs::Vector2{pos}, color); } - void draw(const std::string& str, const paxg::Vec2& pos, const paxg::Color& color) const { - draw(str, paxg::Vec2i{static_cast(pos.x()), static_cast(pos.y())}, color); + void draw(const std::string& str, const paxs::Vector2& pos, const paxg::Color& color) const { + draw(str, paxs::Vector2{pos}, color); } - void drawBottomCenter(const std::string& str, const paxg::Vec2& pos, const paxg::Color& color) const { - drawBottomCenter(str, paxg::Vec2i{static_cast(pos.x()), static_cast(pos.y())}, color); + void drawBottomCenter(const std::string& str, const paxs::Vector2& pos, const paxg::Color& color) const { + drawBottomCenter(str, paxs::Vector2{pos}, color); } - void drawTopCenter(const std::string& str, const paxg::Vec2& pos, const paxg::Color& color) const { - drawTopCenter(str, paxg::Vec2i{static_cast(pos.x()), static_cast(pos.y())}, color); + void drawTopCenter(const std::string& str, const paxs::Vector2& pos, const paxg::Color& color) const { + drawTopCenter(str, paxs::Vector2{pos}, color); } - void drawAt(const std::string& str, const paxg::Vec2& pos, const paxg::Color& color) const { - drawAt(str, paxg::Vec2i{static_cast(pos.x()), static_cast(pos.y())}, color); + void drawAt(const std::string& str, const paxs::Vector2& pos, const paxg::Color& color) const { + drawAt(str, paxs::Vector2{pos}, color); } int height() const { @@ -380,7 +378,7 @@ namespace paxg{ /// @brief テキストを左下揃えで描画 (横:左端, 縦:下端) /// @brief Draw text with bottom-left alignment (horizontal: left, vertical: bottom) - void drawBottomLeft(const std::string& str, const paxg::Vec2i& pos, const paxg::Color& color) const { + void drawBottomLeft(const std::string& str, const paxs::Vector2& pos, const paxg::Color& color) const { sf::Text text(font); std::wstring wstr; sf::Utf<8>::toWide(str.begin(), str.end(), std::back_inserter(wstr)); @@ -389,13 +387,13 @@ namespace paxg{ text.setFillColor(color.color); text.setOutlineColor(sf::Color::White); text.setOutlineThickness(2.0f); - text.setPosition({ static_cast(pos.x()), static_cast(pos.y() - size / 2) }); + text.setPosition({ static_cast(pos.x), static_cast(pos.y - size / 2) }); paxg::Window::window().draw(text); } /// @brief テキストを右上揃えで描画 (横:右端, 縦:上端) /// @brief Draw text with top-right alignment (horizontal: right, vertical: top) - void drawTopRight(const std::string& str, const paxg::Vec2i& pos, const paxg::Color& color) const { + void drawTopRight(const std::string& str, const paxs::Vector2& pos, const paxg::Color& color) const { sf::Text text(font); std::wstring wstr; sf::Utf<8>::toWide(str.begin(), str.end(), std::back_inserter(wstr)); @@ -404,13 +402,13 @@ namespace paxg{ text.setFillColor(color.color); text.setOutlineColor(sf::Color::White); text.setOutlineThickness(2.0f); - text.setPosition({ static_cast(pos.x() - text.getGlobalBounds().size.x), static_cast(pos.y() + size / 2) }); + text.setPosition({ static_cast(pos.x - text.getGlobalBounds().size.x), static_cast(pos.y + size / 2) }); paxg::Window::window().draw(text); } /// @brief テキストを右下揃えで描画 (横:右端, 縦:下端) /// @brief Draw text with bottom-right alignment (horizontal: right, vertical: bottom) - void drawBottomRight(const std::string& str, const paxg::Vec2i& pos, const paxg::Color& color) const { + void drawBottomRight(const std::string& str, const paxs::Vector2& pos, const paxg::Color& color) const { sf::Text text(font); std::wstring wstr; sf::Utf<8>::toWide(str.begin(), str.end(), std::back_inserter(wstr)); @@ -419,14 +417,14 @@ namespace paxg{ text.setFillColor(color.color); text.setOutlineColor(sf::Color::White); text.setOutlineThickness(2.0f); - // 文字の底部がpos.y()に来るように、テキストの高さ分上に配置 - text.setPosition({ static_cast(pos.x() - text.getGlobalBounds().size.x), static_cast(pos.y() - text.getGlobalBounds().size.y) }); + // 文字の底部がpos.yに来るように、テキストの高さ分上に配置 + text.setPosition({ static_cast(pos.x - text.getGlobalBounds().size.x), static_cast(pos.y - text.getGlobalBounds().size.y) }); paxg::Window::window().draw(text); } /// @brief テキストを左上揃えで描画 (横:左端, 縦:上端) /// @brief Draw text with top-left alignment (horizontal: left, vertical: top) - void draw(const std::string& str, const paxg::Vec2i& pos, const paxg::Color& color) const { + void draw(const std::string& str, const paxs::Vector2& pos, const paxg::Color& color) const { sf::Text text(font); std::wstring wstr; sf::Utf<8>::toWide(str.begin(), str.end(), std::back_inserter(wstr)); @@ -435,13 +433,13 @@ namespace paxg{ text.setFillColor(color.color); text.setOutlineColor(sf::Color::White); text.setOutlineThickness(2.0f); - text.setPosition({ static_cast(pos.x()), static_cast(pos.y()) }); + text.setPosition({ static_cast(pos.x), static_cast(pos.y) }); paxg::Window::window().draw(text); } /// @brief テキストを中央下揃えで描画 (横:中央, 縦:下端) /// @brief Draw text with bottom-center alignment (horizontal: center, vertical: bottom) - void drawBottomCenter(const std::string& str, const paxg::Vec2i& pos, const paxg::Color& color) const { + void drawBottomCenter(const std::string& str, const paxs::Vector2& pos, const paxg::Color& color) const { sf::Text text(font); std::wstring wstr; sf::Utf<8>::toWide(str.begin(), str.end(), std::back_inserter(wstr)); @@ -450,13 +448,13 @@ namespace paxg{ text.setFillColor(color.color); text.setOutlineColor(sf::Color::White); text.setOutlineThickness(2.0f); - text.setPosition({ static_cast(pos.x() - text.getGlobalBounds().size.x / 2), static_cast(pos.y() - size / 2) }); + text.setPosition({ static_cast(pos.x - text.getGlobalBounds().size.x / 2), static_cast(pos.y - size / 2) }); paxg::Window::window().draw(text); } /// @brief テキストを中央上揃えで描画 (横:中央, 縦:上端) /// @brief Draw text with top-center alignment (horizontal: center, vertical: top) - void drawTopCenter(const std::string& str, const paxg::Vec2i& pos, const paxg::Color& color) const { + void drawTopCenter(const std::string& str, const paxs::Vector2& pos, const paxg::Color& color) const { sf::Text text(font); std::wstring wstr; sf::Utf<8>::toWide(str.begin(), str.end(), std::back_inserter(wstr)); @@ -465,13 +463,13 @@ namespace paxg{ text.setFillColor(color.color); text.setOutlineColor(sf::Color::White); text.setOutlineThickness(2.0f); - text.setPosition({ static_cast(pos.x() - text.getGlobalBounds().size.x / 2), static_cast(pos.y() + size / 2) }); + text.setPosition({ static_cast(pos.x - text.getGlobalBounds().size.x / 2), static_cast(pos.y + size / 2) }); paxg::Window::window().draw(text); } /// @brief テキストを中央揃えで描画 (横:中央, 縦:中央) /// @brief Draw text with center alignment (horizontal: center, vertical: center) - void drawAt(const std::string& str, const paxg::Vec2i& pos, const paxg::Color& color) const { + void drawAt(const std::string& str, const paxs::Vector2& pos, const paxg::Color& color) const { sf::Text text(font); std::wstring wstr; sf::Utf<8>::toWide(str.begin(), str.end(), std::back_inserter(wstr)); @@ -483,8 +481,8 @@ namespace paxg{ // 横方向は中央、縦方向も中央に揃える const sf::FloatRect bounds = text.getGlobalBounds(); text.setPosition({ - static_cast(pos.x()) - bounds.size.x / 2, - static_cast(pos.y()) - bounds.size.y / 2 + static_cast(pos.x) - bounds.size.x / 2, + static_cast(pos.y) - bounds.size.y / 2 }); paxg::Window::window().draw(text); } @@ -504,27 +502,26 @@ namespace paxg{ // return str_.size() * size * 0.5; } - // Vec2 overloads - void drawBottomLeft(const std::string& str, const paxg::Vec2& pos, const paxg::Color& color) const { - drawBottomLeft(str, paxg::Vec2i{static_cast(pos.x()), static_cast(pos.y())}, color); + void drawBottomLeft(const std::string& str, const paxs::Vector2& pos, const paxg::Color& color) const { + drawBottomLeft(str, paxs::Vector2{pos}, color); } - void drawTopRight(const std::string& str, const paxg::Vec2& pos, const paxg::Color& color) const { - drawTopRight(str, paxg::Vec2i{static_cast(pos.x()), static_cast(pos.y())}, color); + void drawTopRight(const std::string& str, const paxs::Vector2& pos, const paxg::Color& color) const { + drawTopRight(str, paxs::Vector2{pos}, color); } - void drawBottomRight(const std::string& str, const paxg::Vec2& pos, const paxg::Color& color) const { - drawBottomRight(str, paxg::Vec2i{static_cast(pos.x()), static_cast(pos.y())}, color); + void drawBottomRight(const std::string& str, const paxs::Vector2& pos, const paxg::Color& color) const { + drawBottomRight(str, paxs::Vector2{pos}, color); } - void draw(const std::string& str, const paxg::Vec2& pos, const paxg::Color& color) const { - draw(str, paxg::Vec2i{static_cast(pos.x()), static_cast(pos.y())}, color); + void draw(const std::string& str, const paxs::Vector2& pos, const paxg::Color& color) const { + draw(str, paxs::Vector2{pos}, color); } - void drawBottomCenter(const std::string& str, const paxg::Vec2& pos, const paxg::Color& color) const { - drawBottomCenter(str, paxg::Vec2i{static_cast(pos.x()), static_cast(pos.y())}, color); + void drawBottomCenter(const std::string& str, const paxs::Vector2& pos, const paxg::Color& color) const { + drawBottomCenter(str, paxs::Vector2{pos}, color); } - void drawTopCenter(const std::string& str, const paxg::Vec2& pos, const paxg::Color& color) const { - drawTopCenter(str, paxg::Vec2i{static_cast(pos.x()), static_cast(pos.y())}, color); + void drawTopCenter(const std::string& str, const paxs::Vector2& pos, const paxg::Color& color) const { + drawTopCenter(str, paxs::Vector2{pos}, color); } - void drawAt(const std::string& str, const paxg::Vec2& pos, const paxg::Color& color) const { - drawAt(str, paxg::Vec2i{static_cast(pos.x()), static_cast(pos.y())}, color); + void drawAt(const std::string& str, const paxs::Vector2& pos, const paxg::Color& color) const { + drawAt(str, paxs::Vector2{pos}, color); } #else @@ -533,35 +530,34 @@ namespace paxg{ void setOutline([[maybe_unused]] const double inner, [[maybe_unused]] const double outer, [[maybe_unused]] const paxg::Color& color) { } - void drawBottomLeft([[maybe_unused]] const std::string& str, [[maybe_unused]] const paxg::Vec2i& pos, [[maybe_unused]] const paxg::Color& color) const { + void drawBottomLeft([[maybe_unused]] const std::string& str, [[maybe_unused]] const paxs::Vector2& pos, [[maybe_unused]] const paxg::Color& color) const { } - void drawTopRight([[maybe_unused]] const std::string& str, [[maybe_unused]] const paxg::Vec2i& pos, [[maybe_unused]] const paxg::Color& color) const { + void drawTopRight([[maybe_unused]] const std::string& str, [[maybe_unused]] const paxs::Vector2& pos, [[maybe_unused]] const paxg::Color& color) const { } - void drawBottomRight([[maybe_unused]] const std::string& str, [[maybe_unused]] const paxg::Vec2i& pos, [[maybe_unused]] const paxg::Color& color) const { + void drawBottomRight([[maybe_unused]] const std::string& str, [[maybe_unused]] const paxs::Vector2& pos, [[maybe_unused]] const paxg::Color& color) const { } - void draw([[maybe_unused]] const std::string& str, [[maybe_unused]] const paxg::Vec2i& pos, [[maybe_unused]] const paxg::Color& color) const { + void draw([[maybe_unused]] const std::string& str, [[maybe_unused]] const paxs::Vector2& pos, [[maybe_unused]] const paxg::Color& color) const { } - void drawBottomCenter([[maybe_unused]] const std::string& str, [[maybe_unused]] const paxg::Vec2i& pos, [[maybe_unused]] const paxg::Color& color) const { + void drawBottomCenter([[maybe_unused]] const std::string& str, [[maybe_unused]] const paxs::Vector2& pos, [[maybe_unused]] const paxg::Color& color) const { } - void drawTopCenter([[maybe_unused]] const std::string& str, [[maybe_unused]] const paxg::Vec2i& pos, [[maybe_unused]] const paxg::Color& color) const { + void drawTopCenter([[maybe_unused]] const std::string& str, [[maybe_unused]] const paxs::Vector2& pos, [[maybe_unused]] const paxg::Color& color) const { } - void drawAt([[maybe_unused]] const std::string& str, [[maybe_unused]] const paxg::Vec2i& pos, [[maybe_unused]] const paxg::Color& color) const { + void drawAt([[maybe_unused]] const std::string& str, [[maybe_unused]] const paxs::Vector2& pos, [[maybe_unused]] const paxg::Color& color) const { } - // Vec2 overloads - void drawBottomLeft([[maybe_unused]] const std::string& str, [[maybe_unused]] const paxg::Vec2& pos, [[maybe_unused]] const paxg::Color& color) const { + void drawBottomLeft([[maybe_unused]] const std::string& str, [[maybe_unused]] const paxs::Vector2& pos, [[maybe_unused]] const paxg::Color& color) const { } - void drawTopRight([[maybe_unused]] const std::string& str, [[maybe_unused]] const paxg::Vec2& pos, [[maybe_unused]] const paxg::Color& color) const { + void drawTopRight([[maybe_unused]] const std::string& str, [[maybe_unused]] const paxs::Vector2& pos, [[maybe_unused]] const paxg::Color& color) const { } - void drawBottomRight([[maybe_unused]] const std::string& str, [[maybe_unused]] const paxg::Vec2& pos, [[maybe_unused]] const paxg::Color& color) const { + void drawBottomRight([[maybe_unused]] const std::string& str, [[maybe_unused]] const paxs::Vector2& pos, [[maybe_unused]] const paxg::Color& color) const { } - void draw([[maybe_unused]] const std::string& str, [[maybe_unused]] const paxg::Vec2& pos, [[maybe_unused]] const paxg::Color& color) const { + void draw([[maybe_unused]] const std::string& str, [[maybe_unused]] const paxs::Vector2& pos, [[maybe_unused]] const paxg::Color& color) const { } - void drawBottomCenter([[maybe_unused]] const std::string& str, [[maybe_unused]] const paxg::Vec2& pos, [[maybe_unused]] const paxg::Color& color) const { + void drawBottomCenter([[maybe_unused]] const std::string& str, [[maybe_unused]] const paxs::Vector2& pos, [[maybe_unused]] const paxg::Color& color) const { } - void drawTopCenter([[maybe_unused]] const std::string& str, [[maybe_unused]] const paxg::Vec2& pos, [[maybe_unused]] const paxg::Color& color) const { + void drawTopCenter([[maybe_unused]] const std::string& str, [[maybe_unused]] const paxs::Vector2& pos, [[maybe_unused]] const paxg::Color& color) const { } - void drawAt([[maybe_unused]] const std::string& str, [[maybe_unused]] const paxg::Vec2& pos, [[maybe_unused]] const paxg::Color& color) const { + void drawAt([[maybe_unused]] const std::string& str, [[maybe_unused]] const paxs::Vector2& pos, [[maybe_unused]] const paxg::Color& color) const { } int height() const { diff --git a/Library/PAX_GRAPHICA/Line.hpp b/Library/PAX_GRAPHICA/Line.hpp index bd6f3c6d7..b81789dd1 100644 --- a/Library/PAX_GRAPHICA/Line.hpp +++ b/Library/PAX_GRAPHICA/Line.hpp @@ -23,9 +23,10 @@ #endif #include -#include #include +#include + namespace paxg { struct Line { @@ -34,49 +35,40 @@ namespace paxg { s3d::Line line{}; constexpr Line(const float sx, const float sy, const float ex, const float ey) : line(sx, sy, ex, ey) {} - constexpr Line(const float sx, const float sy, const paxg::Vec2i& e) - : line(sx, sy, e.x(), e.y()) {} - constexpr Line(const paxg::Vec2i& s, const paxg::Vec2i& e) - : line(s.x(), s.y(), e.x(), e.y()) {} - - // Vec2 コンストラクタ - constexpr Line(const paxg::Vec2& s, const paxg::Vec2& e) - : line(s.x(), s.y(), e.x(), e.y()) {} - - // Vec2 コンストラクタ - constexpr Line(const paxg::Vec2& s, const paxg::Vec2& e) - : line(static_cast(s.x()), static_cast(s.y()), - static_cast(e.x()), static_cast(e.y())) {} - + constexpr Line(const float sx, const float sy, const paxs::Vector2& e) + : line(sx, sy, e.x, e.y) {} + constexpr Line(const paxs::Vector2& s, const paxs::Vector2& e) + : line(s.x, s.y, e.x, e.y) {} + constexpr Line(const paxs::Vector2& s, const paxs::Vector2& e) + : line(s.x, s.y, e.x, e.y) {} + constexpr Line(const paxs::Vector2& s, const paxs::Vector2& e) + : line(static_cast(s.x), static_cast(s.y), + static_cast(e.x), static_cast(e.y)) {} void draw(const double thickness, const paxg::Color& color) const { line.draw(thickness, color.color); } - void drawArrow(const double thickness, const paxg::Vec2f& arrowSize, const paxg::Color& color) const { - line.drawArrow(thickness, s3d::Vec2(arrowSize.x(), arrowSize.y()), color.color); + void drawArrow(const double thickness, const paxs::Vector2& arrowSize, const paxg::Color& color) const { + line.drawArrow(thickness, s3d::Vec2(arrowSize.x, arrowSize.y), color.color); } #elif defined(PAXS_USING_DXLIB) float x0{}, y0{}, w0{}, h0{}; constexpr Line(const float x, const float y, const float w, const float h) : x0(x), y0(y), w0(w), h0(h) {} - constexpr Line(const paxg::Vec2i& pos, const paxg::Vec2i& size) - : x0(static_cast(pos.x())), y0(static_cast(pos.y())), - w0(static_cast(size.x())), h0(static_cast(size.y())) {} - constexpr Line(const paxg::Vec2i& pos, const float w, const float h) : - x0(static_cast(pos.x())), y0(static_cast(pos.y())), w0(w), h0(h) {} - constexpr Line(const float x, const float y, const paxg::Vec2i& size) - : x0(x), y0(y), w0(static_cast(size.x())), h0(static_cast(size.y())) {} - - // Vec2 コンストラクタ (追加) - constexpr Line(const paxg::Vec2& s, const paxg::Vec2& e) - : x0(s.x()), y0(s.y()), - w0(e.x()), h0(e.y()) {} - - // Vec2 コンストラクタ - constexpr Line(const paxg::Vec2& s, const paxg::Vec2& e) - : x0(static_cast(s.x())), y0(static_cast(s.y())), - w0(static_cast(e.x())), h0(static_cast(e.y())) {} + constexpr Line(const paxs::Vector2& pos, const paxs::Vector2& size) + : x0(static_cast(pos.x)), y0(static_cast(pos.y)), + w0(static_cast(size.x)), h0(static_cast(size.y)) {} + constexpr Line(const paxs::Vector2& pos, const float w, const float h) : + x0(static_cast(pos.x)), y0(static_cast(pos.y)), w0(w), h0(h) {} + constexpr Line(const float x, const float y, const paxs::Vector2& size) + : x0(x), y0(y), w0(static_cast(size.x)), h0(static_cast(size.y)) {} + constexpr Line(const paxs::Vector2& s, const paxs::Vector2& e) + : x0(s.x), y0(s.y), + w0(e.x), h0(e.y) {} + constexpr Line(const paxs::Vector2& s, const paxs::Vector2& e) + : x0(static_cast(s.x)), y0(static_cast(s.y)), + w0(static_cast(e.x)), h0(static_cast(e.y)) {} void draw(const double thickness, const paxg::Color& color) const { const unsigned int c = DxLib::GetColor(color.r, color.g, color.b); @@ -105,7 +97,7 @@ namespace paxg { } } - void drawArrow(const double thickness, const paxg::Vec2f& arrowSize, const paxg::Color& color) const { + void drawArrow(const double thickness, const paxs::Vector2& arrowSize, const paxg::Color& color) const { // Draw the main line draw(thickness, color); @@ -116,8 +108,8 @@ namespace paxg { if (length < 0.001f) return; // Too short to draw arrow // Adjust arrow size based on line length - const float arrowLength = arrowSize.y(); - const float arrowWidth = arrowSize.x(); + const float arrowLength = arrowSize.y; + const float arrowWidth = arrowSize.x; const float scale = (length < arrowLength) ? (length / arrowLength) : 1.0f; const float adjustedArrowLength = arrowLength * scale; const float adjustedArrowWidth = arrowWidth * scale; @@ -157,25 +149,21 @@ namespace paxg { line[0].position = sf::Vector2f(sx, sy); line[1].position = sf::Vector2f(ex, ey); } - Line(const float sx, const float sy, const paxg::Vec2i& e) { + Line(const float sx, const float sy, const paxs::Vector2& e) { line[0].position = sf::Vector2f(sx, sy); - line[1].position = sf::Vector2f(static_cast(e.x()), static_cast(e.y())); + line[1].position = sf::Vector2f(static_cast(e.x), static_cast(e.y)); } - Line(const paxg::Vec2i& s, const paxg::Vec2i& e) { - line[0].position = sf::Vector2f(static_cast(s.x()), static_cast(s.y())); - line[1].position = sf::Vector2f(static_cast(e.x()), static_cast(e.y())); + Line(const paxs::Vector2& s, const paxs::Vector2& e) { + line[0].position = sf::Vector2f(static_cast(s.x), static_cast(s.y)); + line[1].position = sf::Vector2f(static_cast(e.x), static_cast(e.y)); } - - // Vec2 コンストラクタ (追加) - Line(const paxg::Vec2& s, const paxg::Vec2& e) { - line[0].position = sf::Vector2f(s.x(), s.y()); - line[1].position = sf::Vector2f(e.x(), e.y()); + Line(const paxs::Vector2& s, const paxs::Vector2& e) { + line[0].position = sf::Vector2f(s.x, s.y); + line[1].position = sf::Vector2f(e.x, e.y); } - - // Vec2 コンストラクタ - Line(const paxg::Vec2& s, const paxg::Vec2& e) { - line[0].position = sf::Vector2f(static_cast(s.x()), static_cast(s.y())); - line[1].position = sf::Vector2f(static_cast(e.x()), static_cast(e.y())); + Line(const paxs::Vector2& s, const paxs::Vector2& e) { + line[0].position = sf::Vector2f(static_cast(s.x), static_cast(s.y)); + line[1].position = sf::Vector2f(static_cast(e.x), static_cast(e.y)); } void draw(const double /*thickness*/, const paxg::Color& color) { @@ -184,7 +172,7 @@ namespace paxg { paxg::Window::window().draw(line, 2, sf::PrimitiveType::Lines); } - void drawArrow(const double thickness, const paxg::Vec2f& arrowSize, const paxg::Color& color) { + void drawArrow(const double thickness, const paxs::Vector2& arrowSize, const paxg::Color& color) { draw(thickness, color); // ... (SFML arrow code remains the same) ... // Calculate direction vector @@ -193,8 +181,8 @@ namespace paxg { const float length = std::sqrt(dx * dx + dy * dy); if (length < 0.001f) return; - const float arrowLength = arrowSize.y(); - const float arrowWidth = arrowSize.x(); + const float arrowLength = arrowSize.y; + const float arrowWidth = arrowSize.x; const float scale = (length < arrowLength) ? (length / arrowLength) : 1.0f; const float adjustedArrowLength = arrowLength * scale; const float adjustedArrowWidth = arrowWidth * scale; @@ -234,21 +222,20 @@ namespace paxg { float sx0{}, sy0{}, ex0{}, ey0{}; constexpr Line(const float sx, const float sy, const float ex, const float ey) : sx0(sx), sy0(sy), ex0(ex), ey0(ey) {} - constexpr Line(const float sx, const float sy, const paxg::Vec2i& e) - : sx0(sx), sy0(sy), ex0(static_cast(e.x())), ey0(static_cast(e.y())) {} - constexpr Line(const paxg::Vec2i& s, const paxg::Vec2i& e) - : sx0(static_cast(s.x())), sy0(static_cast(s.y())), - ex0(static_cast(e.x())), ey0(static_cast(e.y())) {} - - constexpr Line(const paxg::Vec2& s, const paxg::Vec2& e) - : sx0(s.x()), sy0(s.y()), ex0(e.x()), ey0(e.y()) {} - - constexpr Line(const paxg::Vec2& s, const paxg::Vec2& e) - : sx0(static_cast(s.x())), sy0(static_cast(s.y())), - ex0(static_cast(e.x())), ey0(static_cast(e.y())) {} + constexpr Line(const float sx, const float sy, const paxs::Vector2& e) + : sx0(sx), sy0(sy), ex0(static_cast(e.x)), ey0(static_cast(e.y)) {} + constexpr Line(const paxs::Vector2& s, const paxs::Vector2& e) + : sx0(static_cast(s.x)), sy0(static_cast(s.y)), + ex0(static_cast(e.x)), ey0(static_cast(e.y)) {} + constexpr Line(const paxs::Vector2& s, const paxs::Vector2& e) + : sx0(s.x), sy0(s.y), ex0(e.x), ey0(e.y) {} + + constexpr Line(const paxs::Vector2& s, const paxs::Vector2& e) + : sx0(static_cast(s.x)), sy0(static_cast(s.y)), + ex0(static_cast(e.x)), ey0(static_cast(e.y)) {} void draw([[maybe_unused]] const double thickness, [[maybe_unused]] const paxg::Color& color) const {} - void drawArrow([[maybe_unused]] const double thickness, [[maybe_unused]] const paxg::Vec2f& arrowSize, [[maybe_unused]] const paxg::Color& color) const {} + void drawArrow([[maybe_unused]] const double thickness, [[maybe_unused]] const paxs::Vector2& arrowSize, [[maybe_unused]] const paxg::Color& color) const {} #endif }; } diff --git a/Library/PAX_GRAPHICA/Mouse.hpp b/Library/PAX_GRAPHICA/Mouse.hpp index 4c5513119..1033f7b9f 100644 --- a/Library/PAX_GRAPHICA/Mouse.hpp +++ b/Library/PAX_GRAPHICA/Mouse.hpp @@ -23,7 +23,6 @@ #include #endif -#include #include #include @@ -141,18 +140,18 @@ namespace paxg { } // SFML 3.0.0: より安全なマウス位置取得(std::optional) - std::optional tryGetPosition() const { + std::optional> tryGetPosition() const { #if defined(PAXS_USING_SIV3D) - return Vec2i(s3d::Cursor::Pos().x, s3d::Cursor::Pos().y); + return paxs::Vector2(s3d::Cursor::Pos().x, s3d::Cursor::Pos().y); #elif defined(PAXS_USING_DXLIB) int x = 0, y = 0; if (DxLib::GetMousePoint(&x, &y) == -1) { return std::nullopt; } - return Vec2i(x, y); + return paxs::Vector2(x, y); #elif defined(PAXS_USING_SFML) // SFML 3.0 では常に成功するが、一貫性のためoptionalを返す - return Vec2i(pos_x, pos_y); + return paxs::Vector2(pos_x, pos_y); #else return std::nullopt; #endif diff --git a/Library/PAX_GRAPHICA/Rect.hpp b/Library/PAX_GRAPHICA/Rect.hpp index 3975a7cfc..12f4a86ad 100644 --- a/Library/PAX_GRAPHICA/Rect.hpp +++ b/Library/PAX_GRAPHICA/Rect.hpp @@ -58,13 +58,13 @@ namespace paxg { rect.w = w_; rect.h = h_; } - void setPos(const Vec2i& pos_) { - rect.x = pos_.x(); - rect.y = pos_.y(); + void setPos(const paxs::Vector2& pos_) { + rect.x = pos_.x; + rect.y = pos_.y; } - void setSize(const Vec2i& size_) { - rect.w = size_.x(); - rect.h = size_.y(); + void setSize(const paxs::Vector2& size_) { + rect.w = size_.x; + rect.h = size_.y; } bool contains(const float x_, const float y_) const { return (rect.x <= x_) && (x_ <= (rect.x + rect.w)) && @@ -95,8 +95,8 @@ namespace paxg { paxs::Vector2 size() const { return paxs::Vector2(rect.getSize().x, rect.getSize().y); } void setPos(const float x_, const float y_) { rect.setPosition({ x_, y_ }); } void setSize(const float w_, const float h_) { rect.setSize(sf::Vector2f(w_, h_)); } - void setPos(const Vec2i& pos_) { rect.setPosition({ static_cast(pos_.x()), static_cast(pos_.y()) }); } - void setSize(const Vec2i& size_) { rect.setSize(sf::Vector2f(static_cast(size_.x()), static_cast(size_.y()))); } + void setPos(const paxs::Vector2& pos_) { rect.setPosition({ static_cast(pos_.x), static_cast(pos_.y) }); } + void setSize(const paxs::Vector2& size_) { rect.setSize(sf::Vector2f(static_cast(size_.x), static_cast(size_.y))); } bool contains(const float x_, const float y_) const { return x_ >= rect.getPosition().x && x_ <= (rect.getPosition().x + rect.getSize().x) && y_ >= rect.getPosition().y && y_ <= (rect.getPosition().y + rect.getSize().y); @@ -194,12 +194,12 @@ namespace paxg { /// @param spread Spread size (広がりサイズ) /// @return Reference to this for method chaining (メソッドチェーン用の自身への参照) #if defined(PAXS_USING_SIV3D) - const Rect& drawShadow(const Vec2i& offset, int blur_size, int spread) const { - rect.drawShadow({offset.x(), offset.y()}, blur_size, spread); + const Rect& drawShadow(const paxs::Vector2& offset, int blur_size, int spread) const { + rect.drawShadow({offset.x, offset.y}, blur_size, spread); return *this; } #elif defined(PAXS_USING_SFML) - const Rect& drawShadow(const Vec2i& offset, int blur_size, int spread) const { + const Rect& drawShadow(const paxs::Vector2& offset, int blur_size, int spread) const { // SFML: Simple shadow using semi-transparent rectangles // 複数の半透明矩形を重ねて簡易的な影を表現 sf::RectangleShape shadow = rect; @@ -207,8 +207,8 @@ namespace paxg { for (int i = spread + blur_size; i >= 0; --i) { shadow.setPosition(sf::Vector2f( - rect.getPosition().x + offset.x() + i, - rect.getPosition().y + offset.y() + i + rect.getPosition().x + offset.x + i, + rect.getPosition().y + offset.y + i )); shadow.setSize(sf::Vector2f( rect.getSize().x + i * 2, @@ -222,7 +222,7 @@ namespace paxg { return *this; } #elif defined(PAXS_USING_DXLIB) - const Rect& drawShadow(const Vec2i& offset, int blur_size, int spread) const { + const Rect& drawShadow(const paxs::Vector2& offset, int blur_size, int spread) const { // DxLib: Simple shadow using semi-transparent rectangles // 複数の半透明矩形を重ねて簡易的な影を表現 DxLib::SetDrawBlendMode(DX_BLENDMODE_ALPHA, 40); @@ -232,8 +232,8 @@ namespace paxg { DxLib::SetDrawBlendMode(DX_BLENDMODE_ALPHA, alpha); DxLib::DrawBox( - static_cast(pos_.x + offset.x() + i), - static_cast(pos_.y + offset.y() + i), + static_cast(pos_.x + offset.x + i), + static_cast(pos_.y + offset.y + i), static_cast(pos_.x + size_.x + i), static_cast(pos_.y + size_.y + i), DxLib::GetColor(0, 0, 0), @@ -245,7 +245,7 @@ namespace paxg { return *this; } #else - const Rect& drawShadow(const Vec2i&, int, int) const { + const Rect& drawShadow(const paxs::Vector2&, int, int) const { return *this; } #endif diff --git a/Library/PAX_GRAPHICA/RoundRect.hpp b/Library/PAX_GRAPHICA/RoundRect.hpp index 981cfddf9..8cae474c5 100644 --- a/Library/PAX_GRAPHICA/RoundRect.hpp +++ b/Library/PAX_GRAPHICA/RoundRect.hpp @@ -24,10 +24,10 @@ #include #include #include -#include #include #include +#include namespace paxg { @@ -37,12 +37,12 @@ namespace paxg { constexpr RoundRect() = default; constexpr RoundRect(const int x, const int y, const int w, const int h) : rect(x, y, w, h, w / 5) {} constexpr RoundRect(const int x, const int y, const int w, const int h, const int r) : rect(x, y, w, h, r) {} - constexpr RoundRect(const Vec2i& pos, const Vec2i& size) : rect(pos.x(), pos.y(), size.x(), size.y(), size.x() / 5) {} - constexpr RoundRect(const Vec2i& pos, const Vec2i& size, const int r) : rect(pos.x(), pos.y(), size.x(), size.y(), r) {} - constexpr RoundRect(const Vec2i& pos, const int w, const int h) : rect(pos.x(), pos.y(), w, h, w / 5) {} - constexpr RoundRect(const Vec2i& pos, const int w, const int h, const int r) : rect(pos.x(), pos.y(), w, h, r) {} - constexpr RoundRect(const int x, const int y, const Vec2i& size) : rect(x, y, size.x(), size.y(), size.x() / 5) {} - constexpr RoundRect(const int x, const int y, const Vec2i& size, const int r) : rect(x, y, size.x(), size.y(), r) {} + constexpr RoundRect(const paxs::Vector2& pos, const paxs::Vector2& size) : rect(pos.x, pos.y, size.x, size.y, size.x / 5) {} + constexpr RoundRect(const paxs::Vector2& pos, const paxs::Vector2& size, const int r) : rect(pos.x, pos.y, size.x, size.y, r) {} + constexpr RoundRect(const paxs::Vector2& pos, const int w, const int h) : rect(pos.x, pos.y, w, h, w / 5) {} + constexpr RoundRect(const paxs::Vector2& pos, const int w, const int h, const int r) : rect(pos.x, pos.y, w, h, r) {} + constexpr RoundRect(const int x, const int y, const paxs::Vector2& size) : rect(x, y, size.x, size.y, size.x / 5) {} + constexpr RoundRect(const int x, const int y, const paxs::Vector2& size, const int r) : rect(x, y, size.x, size.y, r) {} constexpr operator s3d::RoundRect() const { return rect; } void setX(const int x_) { rect.x = x_; } void setY(const int y_) { rect.y = y_; } @@ -54,8 +54,8 @@ namespace paxg { int w() const { return static_cast(rect.w); } int h() const { return static_cast(rect.h); } int r() const { return static_cast(rect.r); } - Vec2i pos() const { return Vec2i(static_cast(rect.x), static_cast(rect.y)); } - Vec2i size() const { return Vec2i(static_cast(rect.w), static_cast(rect.h)); } + paxs::Vector2 pos() const { return paxs::Vector2(static_cast(rect.x), static_cast(rect.y)); } + paxs::Vector2 size() const { return paxs::Vector2(static_cast(rect.w), static_cast(rect.h)); } void setPos(const int x_, const int y_) { rect.x = x_; rect.y = y_; @@ -64,13 +64,13 @@ namespace paxg { rect.w = w_; rect.h = h_; } - void setPos(const Vec2i& pos_) { - rect.x = pos_.x(); - rect.y = pos_.y(); + void setPos(const paxs::Vector2& pos_) { + rect.x = pos_.x; + rect.y = pos_.y; } - void setSize(const Vec2i& size_) { - rect.w = size_.x(); - rect.h = size_.y(); + void setSize(const paxs::Vector2& size_) { + rect.w = size_.x; + rect.h = size_.y; } #elif defined(PAXS_USING_SFML) @@ -80,20 +80,20 @@ namespace paxg { x0(x), y0(y), w0(w), h0(h), r0(w / 5) {} RoundRect(const int x, const int y, const int w, const int h, const int r) : x0(x), y0(y), w0(w), h0(h), r0(r) {} - RoundRect(const Vec2i& pos, const Vec2i& size) - : x0(static_cast(pos.x())), y0(static_cast(pos.y())), - w0(static_cast(size.x())), h0(static_cast(size.y())), r0(w0 / 5) {} - RoundRect(const Vec2i& pos, const Vec2i& size, const int r) - : x0(static_cast(pos.x())), y0(static_cast(pos.y())), - w0(static_cast(size.x())), h0(static_cast(size.y())), r0(r) {} - RoundRect(const Vec2i& pos, const int w, const int h) : - x0(static_cast(pos.x())), y0(static_cast(pos.y())), w0(w), h0(h), r0(w0 / 5) {} - RoundRect(const Vec2i& pos, const int w, const int h, const int r) : - x0(static_cast(pos.x())), y0(static_cast(pos.y())), w0(w), h0(h), r0(r) {} - RoundRect(const int x, const int y, const Vec2i& size) - : x0(x), y0(y), w0(static_cast(size.x())), h0(static_cast(size.y())), r0(w0 / 5) {} - RoundRect(const int x, const int y, const Vec2i& size, const int r) - : x0(x), y0(y), w0(static_cast(size.x())), h0(static_cast(size.y())), r0(r) {} + RoundRect(const paxs::Vector2& pos, const paxs::Vector2& size) + : x0(static_cast(pos.x)), y0(static_cast(pos.y)), + w0(static_cast(size.x)), h0(static_cast(size.y)), r0(w0 / 5) {} + RoundRect(const paxs::Vector2& pos, const paxs::Vector2& size, const int r) + : x0(static_cast(pos.x)), y0(static_cast(pos.y)), + w0(static_cast(size.x)), h0(static_cast(size.y)), r0(r) {} + RoundRect(const paxs::Vector2& pos, const int w, const int h) : + x0(static_cast(pos.x)), y0(static_cast(pos.y)), w0(w), h0(h), r0(w0 / 5) {} + RoundRect(const paxs::Vector2& pos, const int w, const int h, const int r) : + x0(static_cast(pos.x)), y0(static_cast(pos.y)), w0(w), h0(h), r0(r) {} + RoundRect(const int x, const int y, const paxs::Vector2& size) + : x0(x), y0(y), w0(static_cast(size.x)), h0(static_cast(size.y)), r0(w0 / 5) {} + RoundRect(const int x, const int y, const paxs::Vector2& size, const int r) + : x0(x), y0(y), w0(static_cast(size.x)), h0(static_cast(size.y)), r0(r) {} // operator sf::RectangleShape() const { return rect; } // [削除] rect メンバはもうない @@ -107,8 +107,8 @@ namespace paxg { int w() const { return w0; } int h() const { return h0; } int r() const { return r0; } - Vec2i pos() const { return Vec2i(static_cast(x0), static_cast(y0)); } - Vec2i size() const { return Vec2i(static_cast(w0), static_cast(h0)); } + paxs::Vector2 pos() const { return paxs::Vector2(static_cast(x0), static_cast(y0)); } + paxs::Vector2 size() const { return paxs::Vector2(static_cast(w0), static_cast(h0)); } void setPos(const int x_, const int y_) { x0 = x_; y0 = y_; @@ -117,62 +117,60 @@ namespace paxg { w0 = w_; h0 = h_; } - void setPos(const Vec2i& pos_) { - x0 = static_cast(pos_.x()); - y0 = static_cast(pos_.y()); + void setPos(const paxs::Vector2& pos_) { + x0 = static_cast(pos_.x); + y0 = static_cast(pos_.y); } - void setSize(const Vec2i& size_) { - w0 = static_cast(size_.x()); - h0 = static_cast(size_.y()); + void setSize(const paxs::Vector2& size_) { + w0 = static_cast(size_.x); + h0 = static_cast(size_.y); } #else - int x0{}, y0{}, w0{}, h0{}, r0{}; + paxs::Vector2 pos_{ 0, 0 }; + paxs::Vector2 size_{ 0, 0 }; + int r0{}; constexpr RoundRect() = default; constexpr RoundRect(const int x, const int y, const int w, const int h) : - x0(x), y0(y), w0(w), h0(h), r0(w0 / 5) {} + pos_(x, y), size_(w, h), r0(w / 5) {} constexpr RoundRect(const int x, const int y, const int w, const int h, const int r) : - x0(x), y0(y), w0(w), h0(h), r0(r) {} - constexpr RoundRect(const Vec2i& pos, const Vec2i& size) - : x0(static_cast(pos.x())), y0(static_cast(pos.y())), - w0(static_cast(size.x())), h0(static_cast(size.y())), r0(w0 / 5) {} - constexpr RoundRect(const Vec2i& pos, const Vec2i& size, const int r) - : x0(static_cast(pos.x())), y0(static_cast(pos.y())), - w0(static_cast(size.x())), h0(static_cast(size.y())), r0(r) {} - constexpr RoundRect(const Vec2i& pos, const int w, const int h) : - x0(static_cast(pos.x())), y0(static_cast(pos.y())), w0(w), h0(h), r0(w0 / 5) {} - constexpr RoundRect(const Vec2i& pos, const int w, const int h, const int r) : - x0(static_cast(pos.x())), y0(static_cast(pos.y())), w0(w), h0(h), r0(r) {} - constexpr RoundRect(const int x, const int y, const Vec2i& size) - : x0(x), y0(y), w0(static_cast(size.x())), h0(static_cast(size.y())), r0(w0 / 5) {} - constexpr RoundRect(const int x, const int y, const Vec2i& size, const int r) - : x0(x), y0(y), w0(static_cast(size.x())), h0(static_cast(size.y())), r0(r) {} - void setX(const int x_) { x0 = x_; } - void setY(const int y_) { y0 = y_; } - void setW(const int w_) { w0 = w_; } - void setH(const int h_) { h0 = h_; } + pos_(x, y), size_(w, h), r0(r) {} + constexpr RoundRect(const paxs::Vector2& pos, const paxs::Vector2& size) + : pos_(pos), size_(size), r0(size.x / 5) {} + constexpr RoundRect(const paxs::Vector2& pos, const paxs::Vector2& size, const int r) + : pos_(pos), size_(size), r0(r) {} + constexpr RoundRect(const paxs::Vector2& pos, const int w, const int h) : + pos_(pos), size_(w, h), r0(w / 5) {} + constexpr RoundRect(const paxs::Vector2& pos, const int w, const int h, const int r) : + pos_(pos), size_(w, h), r0(r) {} + constexpr RoundRect(const int x, const int y, const paxs::Vector2& size) + : pos_(x, y), size_(size), r0(size.x / 5) {} + constexpr RoundRect(const int x, const int y, const paxs::Vector2& size, const int r) + : pos_(x, y), size_(size), r0(r) {} + void setX(const int x_) { pos_.x = x_; } + void setY(const int y_) { pos_.y = y_; } + void setW(const int w_) { size_.x = w_; } + void setH(const int h_) { size_.y = h_; } void setR(const int r_) { r0 = r_; } - int x() const { return x0; } - int y() const { return y0; } - int w() const { return w0; } - int h() const { return h0; } + int x() const { return pos_.x; } + int y() const { return pos_.y; } + int w() const { return size_.x; } + int h() const { return size_.y; } int r() const { return r0; } - Vec2i pos() const { return Vec2i(static_cast(x0), static_cast(y0)); } - Vec2i size() const { return Vec2i(static_cast(w0), static_cast(h0)); } + paxs::Vector2 pos() const { return pos_; } + paxs::Vector2 size() const { return size_; } void setPos(const int x_, const int y_) { - x0 = x_; - y0 = y_; + pos_.x = x_; + pos_.y = y_; } void setSize(const int w_, const int h_) { - w0 = w_; - h0 = h_; + size_.x = w_; + size_.y = h_; } - void setPos(const Vec2i& pos_) { - x0 = static_cast(pos_.x()); - y0 = static_cast(pos_.y()); + void setPos(paxs::Vector2 pos) { + pos_ = pos; } - void setSize(const Vec2i& size_) { - w0 = static_cast(size_.x()); - h0 = static_cast(size_.y()); + void setSize(const paxs::Vector2& size) { + size_ = size; } #endif @@ -290,12 +288,12 @@ namespace paxg { /// @param spread Spread size (広がりサイズ) /// @return Reference to this for method chaining (メソッドチェーン用の自身への参照) #if defined(PAXS_USING_SIV3D) - const RoundRect& drawShadow(const Vec2i& offset, int blur_size, int spread) const { - rect.drawShadow({ offset.x(), offset.y() }, blur_size, spread); + const RoundRect& drawShadow(const paxs::Vector2& offset, int blur_size, int spread) const { + rect.drawShadow({ offset.x, offset.y }, blur_size, spread); return *this; } #elif defined(PAXS_USING_SFML) - const RoundRect& drawShadow(const Vec2i& offset, int blur_size, int spread) const { + const RoundRect& drawShadow(const paxs::Vector2& offset, int blur_size, int spread) const { const float base_x = static_cast(x0); const float base_y = static_cast(y0); const float base_w = static_cast(w0); @@ -307,8 +305,8 @@ namespace paxg { for (int i = spread + blur_size; i >= 0; --i) { // 影の位置とサイズ、角の丸みを計算 // (影は元の図形より 2*i 大きく、-i オフセットして中央揃えにする) - const float x = base_x + offset.x() - i; - const float y = base_y + offset.y() - i; + const float x = base_x + offset.x - i; + const float y = base_y + offset.y - i; const float w = base_w + 2.0f * i; const float h = base_h + 2.0f * i; const float r = base_r + i; @@ -322,7 +320,7 @@ namespace paxg { return *this; } #elif defined(PAXS_USING_DXLIB) - const RoundRect& drawShadow(const Vec2i& offset, int blur_size, int spread) const { + const RoundRect& drawShadow(const paxs::Vector2& offset, int blur_size, int spread) const { // DxLib: Simple shadow using semi-transparent rectangles // 複数の半透明矩形を重ねて簡易的な影を表現 DxLib::SetDrawBlendMode(DX_BLENDMODE_ALPHA, 40); @@ -333,10 +331,10 @@ namespace paxg { // DxLibの実装も影が広がるように DxLib::DrawRoundRect( - static_cast(x0 + offset.x() - i), - static_cast(y0 + offset.y() - i), - static_cast(x0 + w0 + offset.x() + i), - static_cast(y0 + h0 + offset.y() + i), + static_cast(x0 + offset.x - i), + static_cast(y0 + offset.y - i), + static_cast(x0 + w0 + offset.x + i), + static_cast(y0 + h0 + offset.y + i), r0 + i, r0 + i, // 角の丸みも広げる DxLib::GetColor(0, 0, 0), TRUE @@ -347,7 +345,7 @@ namespace paxg { return *this; } #else - const RoundRect& drawShadow(const Vec2i&, int, int) const { + const RoundRect& drawShadow(const paxs::Vector2&, int, int) const { // No platform defined: empty implementation return *this; } diff --git a/Library/PAX_GRAPHICA/Spline2D.hpp b/Library/PAX_GRAPHICA/Spline2D.hpp index da1cad2ea..6a3a5c24a 100644 --- a/Library/PAX_GRAPHICA/Spline2D.hpp +++ b/Library/PAX_GRAPHICA/Spline2D.hpp @@ -24,9 +24,10 @@ #endif #include -#include #include +#include + namespace paxg { /// @brief 2Dスプライン曲線クラス @@ -35,59 +36,94 @@ namespace paxg { #ifdef PAXS_USING_SIV3D s3d::Spline2D spline; #else - std::vector points_; + std::vector> points_; bool is_closed_ = false; // 閉じたループかどうか / Whether it's a closed loop #endif - static Vec2f calculateCatmullRom(const Vec2f& p0, const Vec2f& p1, const Vec2f& p2, const Vec2f& p3, float t) { + static paxs::Vector2 calculateCatmullRom(const paxs::Vector2& p0, const paxs::Vector2& p1, const paxs::Vector2& p2, const paxs::Vector2& p3, float t) { float t2 = t * t; float t3 = t2 * t; - float v0 = (p2.x() - p0.x()) * 0.5f; - float v1 = (p3.x() - p1.x()) * 0.5f; - float x = (2 * p1.x() - 2 * p2.x() + v0 + v1) * t3 + (-3 * p1.x() + 3 * p2.x() - 2 * v0 - v1) * t2 + v0 * t + p1.x(); + float v0 = (p2.x - p0.x) * 0.5f; + float v1 = (p3.x - p1.x) * 0.5f; + float x = (2 * p1.x - 2 * p2.x + v0 + v1) * t3 + (-3 * p1.x + 3 * p2.x - 2 * v0 - v1) * t2 + v0 * t + p1.x; - v0 = (p2.y() - p0.y()) * 0.5f; - v1 = (p3.y() - p1.y()) * 0.5f; - float y = (2 * p1.y() - 2 * p2.y() + v0 + v1) * t3 + (-3 * p1.y() + 3 * p2.y() - 2 * v0 - v1) * t2 + v0 * t + p1.y(); + v0 = (p2.y - p0.y) * 0.5f; + v1 = (p3.y - p1.y) * 0.5f; + float y = (2 * p1.y - 2 * p2.y + v0 + v1) * t3 + (-3 * p1.y + 3 * p2.y - 2 * v0 - v1) * t2 + v0 * t + p1.y; - return Vec2f{ x, y }; + return { x, y }; } /// @brief 閉じたループかどうかを自動判定し、重複する最後の点を除去 /// @brief Automatically detect closed loop and remove duplicate last point /// @return true if closed loop detected (and duplicate removed) - bool detectAndFixClosedLoop(std::vector& points) const { + bool detectAndFixClosedLoop(std::vector>& points) const { if (points.size() < 3) return false; - - const Vec2f& first = points.front(); - const Vec2f& last = points.back(); - + + const paxs::Vector2& first = points.front(); + const paxs::Vector2& last = points.back(); // 最初と最後の点が十分近ければ閉じたループとみなす // Consider it a closed loop if first and last points are close enough constexpr float threshold = 0.1f; - float dx = first.x() - last.x(); - float dy = first.y() - last.y(); + float dx = first.x - last.x; + float dy = first.y - last.y; float dist_sq = dx * dx + dy * dy; - + if (dist_sq < threshold * threshold) { // 閉じたループの場合、最後の重複点を除去 // Remove duplicate last point for closed loops points.pop_back(); return true; } - + return false; } public: Spline2D() = default; - explicit Spline2D(const std::vector& points, bool is_closed = false) { + explicit Spline2D(const std::vector>& points, bool is_closed = false) { +#ifdef PAXS_USING_SIV3D + s3d::Array siv3d_points; + for (const auto& p : points) { + siv3d_points << s3d::Vec2{ p.x, p.y }; + } + spline = s3d::Spline2D(siv3d_points); +#else + for (const auto& p : points) { + points_.emplace_back(static_cast(p.x), static_cast(p.y)); + } + + // 閉じたループを自動判定し、重複する最後の点を除去 + // Auto-detect closed loop and remove duplicate last point + if (!is_closed) { + is_closed_ = detectAndFixClosedLoop(points_); + } else { + is_closed_ = true; + // 明示的に閉じたループが指定された場合も重複チェック + // Also check for duplicates when explicitly specified as closed + if (points_.size() >= 2) { + const paxs::Vector2& first = points_.front(); + const paxs::Vector2& last = points_.back(); + constexpr float threshold = 0.1f; + float dx = first.x - last.x; + float dy = first.y - last.y; + float dist_sq = dx * dx + dy * dy; + + if (dist_sq < threshold * threshold) { + points_.pop_back(); + } + } + } +#endif + } + + explicit Spline2D(const std::vector>& points, bool is_closed = false) { #ifdef PAXS_USING_SIV3D s3d::Array siv3d_points; for (const auto& p : points) { - siv3d_points << s3d::Vec2{ p.x(), p.y() }; + siv3d_points << s3d::Vec2{ p.x, p.y }; } spline = s3d::Spline2D(siv3d_points); #else @@ -101,13 +137,13 @@ namespace paxg { // 明示的に閉じたループが指定された場合も重複チェック // Also check for duplicates when explicitly specified as closed if (points_.size() >= 2) { - const Vec2f& first = points_.front(); - const Vec2f& last = points_.back(); + const paxs::Vector2& first = points_.front(); + const paxs::Vector2& last = points_.back(); constexpr float threshold = 0.1f; - float dx = first.x() - last.x(); - float dy = first.y() - last.y(); + float dx = first.x - last.x; + float dy = first.y - last.y; float dist_sq = dx * dx + dy * dy; - + if (dist_sq < threshold * threshold) { points_.pop_back(); } @@ -116,18 +152,18 @@ namespace paxg { #endif } - explicit Spline2D(const std::vector& points, bool is_closed = false) { + explicit Spline2D(const std::vector>& points, bool is_closed = false) { #ifdef PAXS_USING_SIV3D s3d::Array siv3d_points; for (const auto& p : points) { - siv3d_points << s3d::Vec2{ static_cast(p.x()), static_cast(p.y()) }; + siv3d_points << s3d::Vec2{ static_cast(p.x), static_cast(p.y) }; } spline = s3d::Spline2D(siv3d_points); #else for (const auto& p : points) { - points_.emplace_back(static_cast(p.x()), static_cast(p.y())); + points_.emplace_back(static_cast(p.x), static_cast(p.y)); } - + // 閉じたループを自動判定し、重複する最後の点を除去 // Auto-detect closed loop and remove duplicate last point if (!is_closed) { @@ -137,13 +173,13 @@ namespace paxg { // 明示的に閉じたループが指定された場合も重複チェック // Also check for duplicates when explicitly specified as closed if (points_.size() >= 2) { - const Vec2f& first = points_.front(); - const Vec2f& last = points_.back(); + const paxs::Vector2& first = points_.front(); + const paxs::Vector2& last = points_.back(); constexpr float threshold = 0.1f; - float dx = first.x() - last.x(); - float dy = first.y() - last.y(); + float dx = first.x - last.x; + float dy = first.y - last.y; float dist_sq = dx * dx + dy * dy; - + if (dist_sq < threshold * threshold) { points_.pop_back(); } @@ -168,8 +204,8 @@ namespace paxg { for (std::size_t i = 0; i < loop_count; ++i) { // 閉じたループの場合、インデックスを循環させる // For closed loops, wrap indices around - Vec2f p0, p1, p2, p3; - + paxs::Vector2 p0, p1, p2, p3; + if (is_closed_) { // 閉じたループ:全ての点でモジュロ演算を使用 // Closed loop: use modulo for all point indices @@ -186,13 +222,12 @@ namespace paxg { p3 = (i + 2 >= point_count) ? points_[i + 1] : points_[i + 2]; } - Vec2f current_pos = p1; + paxs::Vector2 current_pos = p1; for (int j = 1; j <= divisions; ++j) { float t = static_cast(j) / divisions; - Vec2f next_pos = calculateCatmullRom(p0, p1, p2, p3, t); - - paxg::Line(current_pos.x(), current_pos.y(), next_pos.x(), next_pos.y()).draw(thickness, color); + paxs::Vector2 next_pos = calculateCatmullRom(p0, p1, p2, p3, t); + paxg::Line(current_pos.x, current_pos.y, next_pos.x, next_pos.y).draw(thickness, color); current_pos = next_pos; } diff --git a/Library/PAX_GRAPHICA/Triangle.hpp b/Library/PAX_GRAPHICA/Triangle.hpp index f5398a1cc..f69f0211f 100644 --- a/Library/PAX_GRAPHICA/Triangle.hpp +++ b/Library/PAX_GRAPHICA/Triangle.hpp @@ -23,10 +23,10 @@ #endif #include -#include #include #include +#include namespace paxg { @@ -90,8 +90,8 @@ namespace paxg { constexpr Triangle(const float center_x, const float center_y, const float radius, const float rotation = 0.0f) : center_x_(center_x), center_y_(center_y), radius_(radius), rotation_(rotation) {} - constexpr Triangle(const paxg::Vec2f& center, const float radius, const float rotation = 0.0f) - : center_x_(center.x()), center_y_(center.y()), radius_(radius), rotation_(rotation) {} + constexpr Triangle(const paxs::Vector2& center, const float radius, const float rotation = 0.0f) + : center_x_(center.x), center_y_(center.y), radius_(radius), rotation_(rotation) {} /// @brief Optimized constructor using pre-computed shape (no runtime trigonometry) /// @param center_x X coordinate of the center @@ -100,8 +100,8 @@ namespace paxg { constexpr Triangle(const float center_x, const float center_y, const TriangleShape& shape) : center_x_(center_x), center_y_(center_y), radius_(shape.radius), rotation_(shape.rotation), shape_(&shape) {} - constexpr Triangle(const paxg::Vec2f& center, const TriangleShape& shape) - : center_x_(center.x()), center_y_(center.y()), radius_(shape.radius), rotation_(shape.rotation), shape_(&shape) {} + constexpr Triangle(const paxs::Vector2& center, const TriangleShape& shape) + : center_x_(center.x), center_y_(center.y), radius_(shape.radius), rotation_(shape.rotation), shape_(&shape) {} // Getters constexpr float centerX() const { return center_x_; } @@ -113,7 +113,7 @@ namespace paxg { void setCenterX(const float x) { center_x_ = x; } void setCenterY(const float y) { center_y_ = y; } void setCenter(const float x, const float y) { center_x_ = x; center_y_ = y; } - void setCenter(const paxg::Vec2f& center) { center_x_ = center.x(); center_y_ = center.y(); } + void setCenter(const paxs::Vector2& center) { center_x_ = center.x; center_y_ = center.y; } void setRadius(const float r) { radius_ = r; } void setRotation(const float rot) { rotation_ = rot; } diff --git a/Library/PAX_GRAPHICA/Vec2.hpp b/Library/PAX_GRAPHICA/Vec2.hpp deleted file mode 100644 index 97e838b65..000000000 --- a/Library/PAX_GRAPHICA/Vec2.hpp +++ /dev/null @@ -1,129 +0,0 @@ -/*########################################################################################## - - PAX SAPIENTICA Library 💀🌿🌏 - - [Planning] 2023-2024 As Project - [Production] 2023-2024 As Project - [Contact Us] wanotaitei@gmail.com https://github.com/AsPJT/PAX_SAPIENTICA - [License] Distributed under the CC0 1.0. https://creativecommons.org/publicdomain/zero/1.0/ - -##########################################################################################*/ - -#ifndef PAX_GRAPHICA_VEC2_HPP -#define PAX_GRAPHICA_VEC2_HPP - -#include - -#if defined(PAXS_USING_SIV3D) -#include -#elif defined(PAXS_USING_DXLIB) -#include -#elif defined(PAXS_USING_SFML) -#include -#endif - -#include - -namespace paxg { - - template - struct Vec2 { - constexpr Vec2() = default; - -#if defined(PAXS_USING_SIV3D) - using NativeVec2 = typename std::conditional::value, s3d::Point, s3d::Vec2>::type; - NativeVec2 vec2{}; - - constexpr Vec2(const T x, const T y) : vec2(static_cast(x), static_cast(y)) {} - constexpr Vec2(const NativeVec2& vec2) : vec2(vec2) {} - - // 型変換コンストラクタ (conversion constructor for different numeric types) - template - constexpr Vec2(const Vec2& other) : vec2(static_cast(other.x()), static_cast(other.y())) {} - - // paxs::Vector2からの変換コンストラクタ - constexpr Vec2(const paxs::Vector2& v) : vec2(static_cast(v.x), static_cast(v.y)) {} - constexpr operator NativeVec2() const { return vec2; } - - constexpr auto x() const { return static_cast(vec2.x); } - constexpr auto y() const { return static_cast(vec2.y); } - - void setX(const T x_) { vec2.x = static_cast(x_); } - void setY(const T y_) { vec2.y = static_cast(y_); } - -#elif defined(PAXS_USING_SFML) - using NativeVec2 = sf::Vector2; - NativeVec2 vec2{}; - - constexpr Vec2(const T x, const T y) : vec2(x, y) {} - constexpr Vec2(const NativeVec2& vec2) : vec2(vec2) {} - - // 型変換コンストラクタ (conversion constructor for different numeric types) - template - constexpr Vec2(const Vec2& other) : vec2(static_cast(other.x()), static_cast(other.y())) {} - - // paxs::Vector2からの変換コンストラクタ - constexpr Vec2(const paxs::Vector2& v) : vec2(static_cast(v.x), static_cast(v.y)) {} - - operator NativeVec2() const { return vec2; } - - constexpr auto x() const { return vec2.x; } - constexpr auto y() const { return vec2.y; } - - void setX(const T x_) { vec2.x = x_; } - void setY(const T y_) { vec2.y = y_; } - -#else - T x0{}, y0{}; - - constexpr Vec2(const T x, const T y) : x0(x), y0(y) {} - - // 型変換コンストラクタ (conversion constructor for different numeric types) - template - constexpr Vec2(const Vec2& other) : x0(static_cast(other.x())), y0(static_cast(other.y())) {} - - // paxs::Vector2からの変換コンストラクタ - constexpr Vec2(const paxs::Vector2& v) : x0(static_cast(v.x)), y0(static_cast(v.y)) {} - - constexpr auto x() const { return x0; } - constexpr auto y() const { return y0; } - - void setX(const T x_) { x0 = x_; } - void setY(const T y_) { y0 = y_; } -#endif - - // 共通演算子 - Vec2 operator+(const Vec2& v_) const { - return Vec2(x() + v_.x(), y() + v_.y()); - } - - Vec2 operator-(const Vec2& v_) const { - return Vec2(x() - v_.x(), y() - v_.y()); - } - - Vec2& operator+=(const Vec2& v_) { - setX(x() + v_.x()); - setY(y() + v_.y()); - return *this; - } - - Vec2& operator-=(const Vec2& v_) { - setX(x() - v_.x()); - setY(y() - v_.y()); - return *this; - } - - bool operator==(const Vec2& v_) const { - return x() == v_.x() && y() == v_.y(); - } - - bool operator!=(const Vec2& v_) const { - return !(*this == v_); - } - }; - - using Vec2i = Vec2; - using Vec2f = Vec2; -} - -#endif // !PAX_GRAPHICA_VEC2_HPP diff --git a/Library/PAX_MAHOROBA/Map/Content/Feature/FlowCurveFeature.hpp b/Library/PAX_MAHOROBA/Map/Content/Feature/FlowCurveFeature.hpp index 4eb41cabf..1d8220336 100644 --- a/Library/PAX_MAHOROBA/Map/Content/Feature/FlowCurveFeature.hpp +++ b/Library/PAX_MAHOROBA/Map/Content/Feature/FlowCurveFeature.hpp @@ -18,7 +18,6 @@ #include #include -#include #include #include @@ -220,16 +219,13 @@ class FlowCurveFeature : public MapFeature, public ISpatiallyUpdatable { for (const auto& coord : normalized_coords) { // スクリーン座標に変換 - const paxg::Vec2 screen_pos = MapCoordinateConverter::toScreenPos( - Vector2(coord.x, coord.y), + const paxs::Vector2 screen_pos = MapCoordinateConverter::toScreenPos( + coord, context.map_view_size, context.map_view_center ); - cached_screen_points_.emplace_back( - static_cast(screen_pos.x()), - static_cast(screen_pos.y()) - ); + cached_screen_points_.emplace_back(screen_pos); } visible_ = (cached_screen_points_.size() >= 2); @@ -333,7 +329,7 @@ class FlowCurveFeature : public MapFeature, public ISpatiallyUpdatable { return group_data_; } - const std::vector& getScreenPoints() const { + const std::vector>& getScreenPoints() const { return cached_screen_points_; } @@ -341,7 +337,7 @@ class FlowCurveFeature : public MapFeature, public ISpatiallyUpdatable { FlowCurveLocationData data_; ///< フロー曲線位置データ / Flow curve location data FlowCurveLocationGroup group_data_; ///< フロー曲線グループデータ / Flow curve group data - std::vector cached_screen_points_; ///< キャッシュされたスクリーン座標列 / Cached screen points + std::vector> cached_screen_points_; ///< キャッシュされたスクリーン座標列 / Cached screen points paxg::Color color_; ///< 描画色 / Drawing color bool visible_{true}; ///< 可視性 / Visibility @@ -350,20 +346,20 @@ class FlowCurveFeature : public MapFeature, public ISpatiallyUpdatable { /// @brief Catmull-Romスプライン補間 /// @brief Catmull-Rom spline interpolation - static paxg::Vec2f calculateCatmullRom(const paxg::Vec2f& p0, const paxg::Vec2f& p1, - const paxg::Vec2f& p2, const paxg::Vec2f& p3, float t) { + static paxs::Vector2 calculateCatmullRom(const paxs::Vector2& p0, const paxs::Vector2& p1, + const paxs::Vector2& p2, const paxs::Vector2& p3, float t) { float t2 = t * t; float t3 = t2 * t; - float v0 = (p2.x() - p0.x()) * 0.5f; - float v1 = (p3.x() - p1.x()) * 0.5f; - float x = (2 * p1.x() - 2 * p2.x() + v0 + v1) * t3 + (-3 * p1.x() + 3 * p2.x() - 2 * v0 - v1) * t2 + v0 * t + p1.x(); + float v0 = (p2.x - p0.x) * 0.5f; + float v1 = (p3.x - p1.x) * 0.5f; + float x = (2 * p1.x - 2 * p2.x + v0 + v1) * t3 + (-3 * p1.x + 3 * p2.x - 2 * v0 - v1) * t2 + v0 * t + p1.x; - v0 = (p2.y() - p0.y()) * 0.5f; - v1 = (p3.y() - p1.y()) * 0.5f; - float y = (2 * p1.y() - 2 * p2.y() + v0 + v1) * t3 + (-3 * p1.y() + 3 * p2.y() - 2 * v0 - v1) * t2 + v0 * t + p1.y(); + v0 = (p2.y - p0.y) * 0.5f; + v1 = (p3.y - p1.y) * 0.5f; + float y = (2 * p1.y - 2 * p2.y + v0 + v1) * t3 + (-3 * p1.y + 3 * p2.y - 2 * v0 - v1) * t2 + v0 * t + p1.y; - return paxg::Vec2f(x, y); + return {x, y}; } /// @brief アニメーションする線分を描画 @@ -411,7 +407,7 @@ class FlowCurveFeature : public MapFeature, public ISpatiallyUpdatable { // 線分を構成する点を収集 // Collect points for the segment - std::vector segment_points; + std::vector> segment_points; segment_points.reserve(static_cast(segment_length * 20 + 2)); // スプライン曲線上の点を補間して収集 @@ -430,10 +426,10 @@ class FlowCurveFeature : public MapFeature, public ISpatiallyUpdatable { // Catmull-Rom補間用の制御点を取得 // Get control points for Catmull-Rom interpolation - paxg::Vec2f p0 = (i == 0) ? cached_screen_points_[0] : cached_screen_points_[i - 1]; - paxg::Vec2f p1 = cached_screen_points_[i]; - paxg::Vec2f p2 = cached_screen_points_[i + 1]; - paxg::Vec2f p3 = (i + 2 >= point_count) ? cached_screen_points_[i + 1] : cached_screen_points_[i + 2]; + paxs::Vector2 p0 = (i == 0) ? cached_screen_points_[0] : cached_screen_points_[i - 1]; + paxs::Vector2 p1 = cached_screen_points_[i]; + paxs::Vector2 p2 = cached_screen_points_[i + 1]; + paxs::Vector2 p3 = (i + 2 >= point_count) ? cached_screen_points_[i + 1] : cached_screen_points_[i + 2]; // このセグメント内で補間する範囲を計算 // Calculate interpolation range within this segment @@ -445,24 +441,23 @@ class FlowCurveFeature : public MapFeature, public ISpatiallyUpdatable { for (int j = start_div; j <= end_div; ++j) { float t = static_cast(j) / divisions; - paxg::Vec2f point = calculateCatmullRom(p0, p1, p2, p3, t); + paxs::Vector2 point = calculateCatmullRom(p0, p1, p2, p3, t); // 固定の左右オフセットを適用 // Apply fixed lateral offset if (std::abs(fixed_lateral_offset) > 0.01f) { // 曲線の向き(接線方向)を計算 // Calculate tangent direction - paxg::Vec2f tangent = calculateTangent(p0, p1, p2, p3, t); + paxs::Vector2 tangent = calculateTangent(p0, p1, p2, p3, t); // 接線に垂直な方向を計算(右向き) // Calculate perpendicular direction (rightward) - paxg::Vec2f perpendicular(-tangent.y(), tangent.x()); - + paxs::Vector2 perpendicular(-tangent.y, tangent.x); // 垂直方向にオフセットを適用 // Apply perpendicular offset - point = paxg::Vec2f( - point.x() + perpendicular.x() * fixed_lateral_offset, - point.y() + perpendicular.y() * fixed_lateral_offset + point = paxs::Vector2( + point.x + perpendicular.x * fixed_lateral_offset, + point.y + perpendicular.y * fixed_lateral_offset ); } @@ -487,42 +482,42 @@ class FlowCurveFeature : public MapFeature, public ISpatiallyUpdatable { // Draw small arrow at the end of segment (only for small phase offset and near-center paths) if (segment_points.size() >= 2 && phase_offset < 0.3f && std::abs(fixed_lateral_offset) < 4.0f) { const size_t last_idx = segment_points.size() - 1; - const paxg::Vec2f& prev = segment_points[last_idx - 1]; - const paxg::Vec2f& end = segment_points[last_idx]; + const paxs::Vector2& prev = segment_points[last_idx - 1]; + const paxs::Vector2& end = segment_points[last_idx]; const float arrow_length = line_width * 4.0f; const float arrow_width = line_width * 2.5f; - paxg::Line(prev, end).drawArrow(line_width * 0.6f, paxg::Vec2f(arrow_width, arrow_length), segment_color); + paxg::Line(prev, end).drawArrow(line_width * 0.6f, paxs::Vector2(arrow_width, arrow_length), segment_color); } } } /// @brief 接線ベクトルを計算(Catmull-Romスプラインの1次微分) /// @brief Calculate tangent vector (first derivative of Catmull-Rom spline) - static paxg::Vec2f calculateTangent(const paxg::Vec2f& p0, const paxg::Vec2f& p1, - const paxg::Vec2f& p2, const paxg::Vec2f& p3, float t) { + static paxs::Vector2 calculateTangent(const paxs::Vector2& p0, const paxs::Vector2& p1, + const paxs::Vector2& p2, const paxs::Vector2& p3, float t) { const float t2 = t * t; // Catmull-Romスプラインの1次微分 // First derivative of Catmull-Rom spline - const float v0_x = (p2.x() - p0.x()) * 0.5f; - const float v1_x = (p3.x() - p1.x()) * 0.5f; - const float dx = (2 * p1.x() - 2 * p2.x() + v0_x + v1_x) * 3.0f * t2 + - (-3 * p1.x() + 3 * p2.x() - 2 * v0_x - v1_x) * 2.0f * t + v0_x; + const float v0_x = (p2.x - p0.x) * 0.5f; + const float v1_x = (p3.x - p1.x) * 0.5f; + const float dx = (2 * p1.x - 2 * p2.x + v0_x + v1_x) * 3.0f * t2 + + (-3 * p1.x + 3 * p2.x - 2 * v0_x - v1_x) * 2.0f * t + v0_x; - const float v0_y = (p2.y() - p0.y()) * 0.5f; - const float v1_y = (p3.y() - p1.y()) * 0.5f; - const float dy = (2 * p1.y() - 2 * p2.y() + v0_y + v1_y) * 3.0f * t2 + - (-3 * p1.y() + 3 * p2.y() - 2 * v0_y - v1_y) * 2.0f * t + v0_y; + const float v0_y = (p2.y - p0.y) * 0.5f; + const float v1_y = (p3.y - p1.y) * 0.5f; + const float dy = (2 * p1.y - 2 * p2.y + v0_y + v1_y) * 3.0f * t2 + + (-3 * p1.y + 3 * p2.y - 2 * v0_y - v1_y) * 2.0f * t + v0_y; // 正規化(単位ベクトル化) // Normalize to unit vector const float length = std::sqrt(dx * dx + dy * dy); if (length > 0.0001f) { - return paxg::Vec2f(dx / length, dy / length); + return {dx / length, dy / length}; } - return paxg::Vec2f(1.0f, 0.0f); // デフォルト方向 / Default direction + return {1.0f, 0.0f}; // デフォルト方向 / Default direction } }; diff --git a/Library/PAX_MAHOROBA/Map/Content/Feature/GenomeFeature.hpp b/Library/PAX_MAHOROBA/Map/Content/Feature/GenomeFeature.hpp index 318ff4ad8..bd353baf0 100644 --- a/Library/PAX_MAHOROBA/Map/Content/Feature/GenomeFeature.hpp +++ b/Library/PAX_MAHOROBA/Map/Content/Feature/GenomeFeature.hpp @@ -176,7 +176,7 @@ class GenomeFeature : public MapFeature, } // テキストの矩形判定(drawBottomCenterは横中央、縦は下から描画) - // text_pos.y = pos.y() - display_size / 2 - 5(アイコンの上部から少し離す) + // text_pos.y = pos.y - display_size / 2 - 5(アイコンの上部から少し離す) // drawBottomCenterなので、そこから上にtext_heightの範囲 if (text_size.x > 0 && text_size.y > 0) { const int text_bottom_y = static_cast(pos.y) - (texture_size.y / 2) - 5; // テキスト下端 diff --git a/Library/PAX_MAHOROBA/Map/Content/Feature/PersonFeature.hpp b/Library/PAX_MAHOROBA/Map/Content/Feature/PersonFeature.hpp index 1aaf781d1..75471f778 100644 --- a/Library/PAX_MAHOROBA/Map/Content/Feature/PersonFeature.hpp +++ b/Library/PAX_MAHOROBA/Map/Content/Feature/PersonFeature.hpp @@ -175,7 +175,7 @@ class PersonFeature : public MapFeature, } // テキストの矩形判定(drawTopCenterは横中央、縦は上から描画) // draw_font_pos = {x, y - 60}から描画されるため、 - // 実際のテキスト位置は pos.y() - 60 から text_height の範囲 + // 実際のテキスト位置は pos.y - 60 から text_height の範囲 if (text_size.x > 0 && text_size.y > 0) { const int text_y = static_cast(pos.y) - 60; // テクスチャの上部(MapFeatureRenderer参照) const Rect text_rect( diff --git a/Library/PAX_MAHOROBA/Map/Content/Feature/TerritoryFeature.hpp b/Library/PAX_MAHOROBA/Map/Content/Feature/TerritoryFeature.hpp index aa3cb2374..ffd00c0da 100644 --- a/Library/PAX_MAHOROBA/Map/Content/Feature/TerritoryFeature.hpp +++ b/Library/PAX_MAHOROBA/Map/Content/Feature/TerritoryFeature.hpp @@ -17,7 +17,6 @@ #include #include -#include #include #include @@ -202,15 +201,15 @@ class TerritoryFeature : public MapFeature, public ISpatiallyUpdatable { for (const auto& coord : normalized_coords) { // スクリーン座標に変換 - const paxg::Vec2 screen_pos = MapCoordinateConverter::toScreenPos( - Vector2(coord.x, coord.y), + const paxs::Vector2 screen_pos = MapCoordinateConverter::toScreenPos( + paxs::Vector2(coord.x, coord.y), context.map_view_size, context.map_view_center ); cached_screen_points_.emplace_back( - static_cast(screen_pos.x()), - static_cast(screen_pos.y()) + static_cast(screen_pos.x), + static_cast(screen_pos.y) ); } @@ -272,7 +271,7 @@ class TerritoryFeature : public MapFeature, public ISpatiallyUpdatable { return group_data_; } - const std::vector& getScreenPoints() const { + const std::vector>& getScreenPoints() const { return cached_screen_points_; } @@ -280,9 +279,9 @@ class TerritoryFeature : public MapFeature, public ISpatiallyUpdatable { TerritoryLocationData data_; ///< 領域位置データ / Territory location data TerritoryLocationGroup group_data_; ///< 領域グループデータ / Territory group data - std::vector cached_screen_points_; ///< キャッシュされたスクリーン座標列 / Cached screen points - paxg::Color color_; ///< 描画色 / Drawing color - bool visible_{true}; ///< 可視性 / Visibility + std::vector> cached_screen_points_; ///< キャッシュされたスクリーン座標列 / Cached screen points + paxg::Color color_; ///< 描画色 / Drawing color + bool visible_{ true }; }; } // namespace paxs diff --git a/Library/PAX_MAHOROBA/Map/Content/Interaction/MapContentHitTester.hpp b/Library/PAX_MAHOROBA/Map/Content/Interaction/MapContentHitTester.hpp index 757d3485a..67a546e79 100644 --- a/Library/PAX_MAHOROBA/Map/Content/Interaction/MapContentHitTester.hpp +++ b/Library/PAX_MAHOROBA/Map/Content/Interaction/MapContentHitTester.hpp @@ -12,13 +12,12 @@ #ifndef PAX_MAHOROBA_MAP_CONTENT_HIT_TESTER_HPP #define PAX_MAHOROBA_MAP_CONTENT_HIT_TESTER_HPP -#include #include -#include #include #include -#include + +#include namespace paxs { @@ -39,24 +38,24 @@ class MapContentHitTester { static bool circleHitTest( int mouse_x, int mouse_y, - const paxg::Vec2i& center, + const paxs::Vector2& center, int radius ) { - const int dx = mouse_x - center.x(); - const int dy = mouse_y - center.y(); + const int dx = mouse_x - center.x; + const int dy = mouse_y - center.y; return (dx * dx + dy * dy) <= (radius * radius); } - /// @brief 円形ヒット判定 (Vec2版) - /// @brief Circle hit test (Vec2 version) + /// @brief 円形ヒット判定 + /// @brief Circle hit test static bool circleHitTest( int mouse_x, int mouse_y, - const paxg::Vec2& center, + const paxs::Vector2& center, int radius ) { - const double dx = static_cast(mouse_x) - center.x(); - const double dy = static_cast(mouse_y) - center.y(); + const double dx = static_cast(mouse_x) - center.x; + const double dy = static_cast(mouse_y) - center.y; return (dx * dx + dy * dy) <= static_cast(radius * radius); } @@ -87,7 +86,7 @@ class MapContentHitTester { [[maybe_unused]] int mouse_x, [[maybe_unused]] int mouse_y, [[maybe_unused]] const std::string& text, - [[maybe_unused]] const paxg::Vec2i& pos, + [[maybe_unused]] const paxs::Vector2& pos, [[maybe_unused]] paxg::Font* font, [[maybe_unused]] const char* align = "topCenter" ) { @@ -125,7 +124,7 @@ class MapContentHitTester { /// @brief Calculate text bounding box (public method) static paxg::Rect getTextBoundingRect( [[maybe_unused]] const std::string& text, - const paxg::Vec2i& pos, + const paxs::Vector2& pos, [[maybe_unused]] paxg::Font* font, [[maybe_unused]] const char* align ) { @@ -134,8 +133,8 @@ class MapContentHitTester { // return paxg::Rect{0, 0, 0, 0}; // } // const auto text_size = font->getSize(text); - // float x = static_cast(pos.x()); - // float y = static_cast(pos.y()); + // float x = static_cast(pos.x); + // float y = static_cast(pos.y); // // アライメントに応じて位置を調整 // if (std::string(align).find("Center") != std::string::npos) { // x -= text_size.x / 2.0f; @@ -150,7 +149,7 @@ class MapContentHitTester { // return paxg::Rect{x, y, text_size.x, text_size.y}; // 仮実装:position周辺の矩形を返す - return paxg::Rect{static_cast(pos.x()), static_cast(pos.y()), 100.0f, 20.0f}; + return paxg::Rect{static_cast(pos.x), static_cast(pos.y), 100.0f, 20.0f}; } }; diff --git a/Library/PAX_MAHOROBA/Map/Content/Renderer/GeometryRenderer.hpp b/Library/PAX_MAHOROBA/Map/Content/Renderer/GeometryRenderer.hpp index cdc827324..8d0016f74 100644 --- a/Library/PAX_MAHOROBA/Map/Content/Renderer/GeometryRenderer.hpp +++ b/Library/PAX_MAHOROBA/Map/Content/Renderer/GeometryRenderer.hpp @@ -15,7 +15,6 @@ #include #include -#include #include #include diff --git a/Library/PAX_MAHOROBA/Map/Content/Renderer/MapFeatureRenderer.hpp b/Library/PAX_MAHOROBA/Map/Content/Renderer/MapFeatureRenderer.hpp index 8c89d6f8d..6860f10c4 100644 --- a/Library/PAX_MAHOROBA/Map/Content/Renderer/MapFeatureRenderer.hpp +++ b/Library/PAX_MAHOROBA/Map/Content/Renderer/MapFeatureRenderer.hpp @@ -110,7 +110,7 @@ class MapFeatureRenderer : public GeometryRenderer { } // テキスト位置(肖像画の上部) - const paxg::Vec2 draw_font_pos = paxg::Vec2{ draw_pos.x, draw_pos.y - 60 }; + const paxs::Vector2 draw_font_pos{ draw_pos.x, draw_pos.y - 60 }; const std::string name = feature.getName(); if (!name.empty()) { @@ -172,18 +172,18 @@ class MapFeatureRenderer : public GeometryRenderer { /// @param texture_map テクスチャマップ / Texture map /// @brief 警告用のテクスチャを描画(テクスチャが見つからない場合) /// @brief Draw warning texture when texture is not found - static void drawWarningTexture(const paxg::Vec2& pos, int size) { + static void drawWarningTexture(const paxs::Vector2& pos, int size) { // 赤い四角形で警告表示 paxg::Rect( - static_cast(pos.x() - size / 2), - static_cast(pos.y() - size / 2), + static_cast(pos.x - size / 2), + static_cast(pos.y - size / 2), static_cast(size), static_cast(size) ).draw(paxg::Color(255, 0, 0, 180)); // 半透明の赤 // 中央に白い×印を描画 - const float center_x = static_cast(pos.x()); - const float center_y = static_cast(pos.y()); + const float center_x = static_cast(pos.x); + const float center_y = static_cast(pos.y); const float half_size = static_cast(size) * 0.3f; // ×印の線(太さ3ピクセル) @@ -236,7 +236,7 @@ class MapFeatureRenderer : public GeometryRenderer { const std::string name = feature.getName(); if (!name.empty()) { // テクスチャの上部に名前を描画 - const paxg::Vec2 text_pos = paxg::Vec2{ + const paxs::Vector2 text_pos{ draw_pos.x, draw_pos.y - (display_size / 2) - 5 // アイコンの上部から少し離す }; diff --git a/Library/PAX_MAHOROBA/Map/Simulation/SettlementRenderer.hpp b/Library/PAX_MAHOROBA/Map/Simulation/SettlementRenderer.hpp index f179376f1..91c3b0343 100644 --- a/Library/PAX_MAHOROBA/Map/Simulation/SettlementRenderer.hpp +++ b/Library/PAX_MAHOROBA/Map/Simulation/SettlementRenderer.hpp @@ -202,20 +202,20 @@ namespace paxs { continue; } - const paxg::Vec2 end_pos = MapCoordinateConverter::toScreenPos( + const paxs::Vector2 end_pos = MapCoordinateConverter::toScreenPos( end_coord, map_view_size, map_view_center); const auto start_coord = positionToWebMercator(share.first); - const paxg::Vec2 start_pos = MapCoordinateConverter::toScreenPos( + const paxs::Vector2 start_pos = MapCoordinateConverter::toScreenPos( start_coord, map_view_size, map_view_center); // 青銅交換を表す直線の矢印を描画 paxg::Line{ start_pos, end_pos } - .drawArrow(MOVEMENT_LINE_WIDTH, paxg::Vec2f{ 8.0f, 16.0f }, BRONZE_SHARE_COLOR); + .drawArrow(MOVEMENT_LINE_WIDTH, paxs::Vector2{ 8.0f, 16.0f }, BRONZE_SHARE_COLOR); } } @@ -236,7 +236,7 @@ namespace paxs { continue; } - const paxg::Vec2 draw_pos = MapCoordinateConverter::toScreenPos( + const paxs::Vector2 draw_pos = MapCoordinateConverter::toScreenPos( coordinate, map_view_size, map_view_center); @@ -245,47 +245,45 @@ namespace paxs { if (settlement.getPositions().size() >= 1) { // スプライン曲線で移動履歴を描画 - std::vector spline_points; + std::vector> spline_points; spline_points.emplace_back(draw_pos); for (auto&& p : settlement.getPositions()) { const auto one_coord = positionToWebMercator(paxs::Vector2(p.x, p.y)); - const paxg::Vec2 one_pos = MapCoordinateConverter::toScreenPos( + const paxs::Vector2 one_pos = MapCoordinateConverter::toScreenPos( one_coord, map_view_size, map_view_center); - spline_points.emplace_back(paxg::Vec2f{ - static_cast(one_pos.x()), static_cast(one_pos.y()) }); + spline_points.emplace_back(one_pos); } const auto old_coord = positionToWebMercator(settlement.getOldPosition()); - const paxg::Vec2 old_pos = MapCoordinateConverter::toScreenPos( + const paxs::Vector2 old_pos = MapCoordinateConverter::toScreenPos( old_coord, map_view_size, map_view_center); - spline_points.emplace_back(paxg::Vec2f{ - static_cast(old_pos.x()), static_cast(old_pos.y()) }); + spline_points.emplace_back(old_pos); paxg::Spline2D(spline_points).draw(MOVEMENT_LINE_WIDTH, paxg::Color(0, 0, 0)); // 矢印を描画 const auto first_coord = positionToWebMercator(settlement.getPositions()[0]); - const paxg::Vec2 first_pos = MapCoordinateConverter::toScreenPos( + const paxs::Vector2 first_pos = MapCoordinateConverter::toScreenPos( first_coord, map_view_size, map_view_center); paxg::Line{ first_pos, draw_pos } - .drawArrow(MOVEMENT_ARROW_LINE_WIDTH, paxg::Vec2f{ 8.0f, 16.0f }, paxg::Color(0, 0, 0)); + .drawArrow(MOVEMENT_ARROW_LINE_WIDTH, paxs::Vector2{ 8.0f, 16.0f }, paxg::Color(0, 0, 0)); } else { // 単純な移動線 const auto old_coord = positionToWebMercator(settlement.getOldPosition()); - const paxg::Vec2 old_pos = MapCoordinateConverter::toScreenPos( + const paxs::Vector2 old_pos = MapCoordinateConverter::toScreenPos( old_coord, map_view_size, map_view_center); paxg::Line{ old_pos, draw_pos } - .drawArrow(MOVEMENT_LINE_WIDTH, paxg::Vec2f{ 8.0f, 16.0f }, paxg::Color(0, 0, 0)); + .drawArrow(MOVEMENT_LINE_WIDTH, paxs::Vector2{ 8.0f, 16.0f }, paxg::Color(0, 0, 0)); } } } @@ -300,13 +298,13 @@ namespace paxs { if (marriage_pos.sx == -1 || marriage_pos.sx == 0) continue; - const paxg::Vec2 draw_pos = MapCoordinateConverter::toScreenPos( + const paxs::Vector2 draw_pos = MapCoordinateConverter::toScreenPos( coordinate, map_view_size, map_view_center); const auto old_coord = positionToWebMercator(paxs::Vector2(marriage_pos.sx, marriage_pos.sy)); - const paxg::Vec2 old_pos = MapCoordinateConverter::toScreenPos( + const paxs::Vector2 old_pos = MapCoordinateConverter::toScreenPos( old_coord, map_view_size, map_view_center); @@ -314,7 +312,7 @@ namespace paxs { const paxg::Color marriage_color = marriage_pos.is_matrilocality ? MARRIAGE_COLOR_MATRILOCAL : MARRIAGE_COLOR_PATRILOCAL; paxg::Line{ old_pos, draw_pos } - .drawArrow(MOVEMENT_LINE_WIDTH, paxg::Vec2f{ 8.0f, 16.0f }, marriage_color); + .drawArrow(MOVEMENT_LINE_WIDTH, paxs::Vector2{ 8.0f, 16.0f }, marriage_color); } } @@ -330,7 +328,7 @@ namespace paxs { SimulationConstants::getInstance().getStartArea().y; const paxs::WebMercatorDeg start_coordinate = positionToWebMercator(paxs::Vector2(0, 0)); - const paxg::Vec2f draw_start_pos = paxg::Vec2f{ + const paxs::Vector2 draw_start_pos { static_cast((start_coordinate.x - (map_view_center.x - map_view_size.x / 2)) / map_view_size.x * double(paxg::Window::width())), static_cast(double(paxg::Window::height()) - @@ -340,7 +338,7 @@ namespace paxs { const paxs::WebMercatorDeg end_coordinate = positionToWebMercator( paxs::Vector2(area_width * 256, area_height * 256)); - const paxg::Vec2f draw_end_pos = paxg::Vec2f{ + const paxs::Vector2 draw_end_pos { static_cast((end_coordinate.x - (map_view_center.x - map_view_size.x / 2)) / map_view_size.x * double(paxg::Window::width())), static_cast(double(paxg::Window::height()) - @@ -351,32 +349,32 @@ namespace paxs { const paxs::WebMercatorDeg tile_coordinate = positionToWebMercator( paxs::Vector2(SimulationConstants::getInstance().cell_group_length, SimulationConstants::getInstance().cell_group_length)); - const paxg::Vec2f tile_pos = paxg::Vec2f{ + const paxs::Vector2 tile_pos { static_cast((tile_coordinate.x - (map_view_center.x - map_view_size.x / 2)) / - map_view_size.x * double(paxg::Window::width())) - draw_start_pos.x(), + map_view_size.x * double(paxg::Window::width())) - draw_start_pos.x, static_cast(double(paxg::Window::height()) - ((tile_coordinate.y - (map_view_center.y - map_view_size.y / 2)) / - map_view_size.y * double(paxg::Window::height()))) - draw_start_pos.y() + map_view_size.y * double(paxg::Window::height()))) - draw_start_pos.y }; // 外枠線を描画 - paxg::Line(draw_start_pos.x(), draw_start_pos.y(), - draw_start_pos.x(), draw_end_pos.y()).draw(GRID_OUTER_LINE_WIDTH, paxg::Color(0, 0, 0)); - paxg::Line(draw_start_pos.x(), draw_start_pos.y(), - draw_end_pos.x(), draw_start_pos.y()).draw(GRID_OUTER_LINE_WIDTH, paxg::Color(0, 0, 0)); - paxg::Line(draw_end_pos.x(), draw_start_pos.y(), - draw_end_pos.x(), draw_end_pos.y()).draw(GRID_OUTER_LINE_WIDTH, paxg::Color(0, 0, 0)); - paxg::Line(draw_start_pos.x(), draw_end_pos.y(), - draw_end_pos.x(), draw_end_pos.y()).draw(GRID_OUTER_LINE_WIDTH, paxg::Color(0, 0, 0)); + paxg::Line(draw_start_pos.x, draw_start_pos.y, + draw_start_pos.x, draw_end_pos.y).draw(GRID_OUTER_LINE_WIDTH, paxg::Color(0, 0, 0)); + paxg::Line(draw_start_pos.x, draw_start_pos.y, + draw_end_pos.x, draw_start_pos.y).draw(GRID_OUTER_LINE_WIDTH, paxg::Color(0, 0, 0)); + paxg::Line(draw_end_pos.x, draw_start_pos.y, + draw_end_pos.x, draw_end_pos.y).draw(GRID_OUTER_LINE_WIDTH, paxg::Color(0, 0, 0)); + paxg::Line(draw_start_pos.x, draw_end_pos.y, + draw_end_pos.x, draw_end_pos.y).draw(GRID_OUTER_LINE_WIDTH, paxg::Color(0, 0, 0)); // 垂直グリッド線 - for (float i = draw_start_pos.x(); i < draw_end_pos.x(); i += tile_pos.x()) { - paxg::Line(i, draw_start_pos.y(), i, draw_end_pos.y()).draw( + for (float i = draw_start_pos.x; i < draw_end_pos.x; i += tile_pos.x) { + paxg::Line(i, draw_start_pos.y, i, draw_end_pos.y).draw( GRID_INNER_LINE_WIDTH, paxg::Color(0, 0, 0)); } // 水平グリッド線 - for (float i = draw_start_pos.y(); i < draw_end_pos.y(); i += tile_pos.y()) { - paxg::Line(draw_start_pos.x(), i, draw_end_pos.x(), i).draw( + for (float i = draw_start_pos.y; i < draw_end_pos.y; i += tile_pos.y) { + paxg::Line(draw_start_pos.x, i, draw_end_pos.x, i).draw( GRID_INNER_LINE_WIDTH, paxg::Color(0, 0, 0)); } } diff --git a/Library/PAX_MAHOROBA/UI/Calendar/CalendarContent.hpp b/Library/PAX_MAHOROBA/UI/Calendar/CalendarContent.hpp index f0d59e09f..c150374c4 100644 --- a/Library/PAX_MAHOROBA/UI/Calendar/CalendarContent.hpp +++ b/Library/PAX_MAHOROBA/UI/Calendar/CalendarContent.hpp @@ -14,7 +14,6 @@ #include #include -#include #include #include @@ -150,7 +149,7 @@ namespace paxs { } (*one_font).drawTopRight(*text_str, - paxg::Vec2i(static_cast(ui_layout_.koyomi_font_x), static_cast(ui_layout_.koyomi_font_y + i * (paxg::FontConfig::KOYOMI_FONT_SIZE * 4 / 3))), paxg::Color(0, 0, 0)); + paxs::Vector2(static_cast(ui_layout_.koyomi_font_x), static_cast(ui_layout_.koyomi_font_y + (i * paxg::FontConfig::KOYOMI_FONT_SIZE * 4 / 3))), paxg::Color(0, 0, 0)); // Get localized unit strings const std::string* unit_year = Fonts().getLocalesText(calendar_ui_domain_key, unit_year_key); @@ -158,30 +157,30 @@ namespace paxs { const std::string* unit_day = Fonts().getLocalesText(calendar_ui_domain_key, unit_day_key); if (unit_year != nullptr) { - (*one_font).drawTopRight(*unit_year, paxg::Vec2i(static_cast((120 * paxg::FontConfig::KOYOMI_FONT_SIZE / 30.0) + ui_layout_.koyomi_font_x), static_cast(ui_layout_.koyomi_font_y + i * (paxg::FontConfig::KOYOMI_FONT_SIZE * 4 / 3))), paxg::Color(0, 0, 0)); + (*one_font).drawTopRight(*unit_year, paxs::Vector2(static_cast((120 * paxg::FontConfig::KOYOMI_FONT_SIZE / 30.0) + ui_layout_.koyomi_font_x), static_cast(ui_layout_.koyomi_font_y + (i * paxg::FontConfig::KOYOMI_FONT_SIZE * 4 / 3))), paxg::Color(0, 0, 0)); } else { PAXS_WARNING("[CalendarContent] Missing unit_year text"); } if (unit_month != nullptr) { - (*one_font).drawTopRight(*unit_month, paxg::Vec2i(static_cast((220 * paxg::FontConfig::KOYOMI_FONT_SIZE / 30.0) + ui_layout_.koyomi_font_x), static_cast(ui_layout_.koyomi_font_y + i * (paxg::FontConfig::KOYOMI_FONT_SIZE * 4 / 3))), paxg::Color(0, 0, 0)); + (*one_font).drawTopRight(*unit_month, paxs::Vector2(static_cast((220 * paxg::FontConfig::KOYOMI_FONT_SIZE / 30.0) + ui_layout_.koyomi_font_x), static_cast(ui_layout_.koyomi_font_y + (i * paxg::FontConfig::KOYOMI_FONT_SIZE * 4 / 3))), paxg::Color(0, 0, 0)); } else { PAXS_WARNING("[CalendarContent] Missing unit_month text"); } if (unit_day != nullptr) { - (*one_font).drawTopRight(*unit_day, paxg::Vec2i(static_cast((300 * paxg::FontConfig::KOYOMI_FONT_SIZE / 30.0) + ui_layout_.koyomi_font_x), static_cast(ui_layout_.koyomi_font_y + i * (paxg::FontConfig::KOYOMI_FONT_SIZE * 4 / 3))), paxg::Color(0, 0, 0)); + (*one_font).drawTopRight(*unit_day, paxs::Vector2(static_cast((300 * paxg::FontConfig::KOYOMI_FONT_SIZE / 30.0) + ui_layout_.koyomi_font_x), static_cast(ui_layout_.koyomi_font_y + (i * paxg::FontConfig::KOYOMI_FONT_SIZE * 4 / 3))), paxg::Color(0, 0, 0)); } else { PAXS_WARNING("[CalendarContent] Missing unit_day text"); } - (*one_font).drawTopRight(std::to_string(date_year), paxg::Vec2i(static_cast((85 * paxg::FontConfig::KOYOMI_FONT_SIZE / 30) + ui_layout_.koyomi_font_x), static_cast(ui_layout_.koyomi_font_y + i * (paxg::FontConfig::KOYOMI_FONT_SIZE * 4 / 3))), paxg::Color(0, 0, 0)); - (*one_font).drawTopRight(std::to_string(date_month), paxg::Vec2i(static_cast((190 * paxg::FontConfig::KOYOMI_FONT_SIZE / 30) + ui_layout_.koyomi_font_x), static_cast(ui_layout_.koyomi_font_y + i * (paxg::FontConfig::KOYOMI_FONT_SIZE * 4 / 3))), paxg::Color(0, 0, 0)); - (*one_font).drawTopRight(std::to_string(date_day), paxg::Vec2i(static_cast((270 * paxg::FontConfig::KOYOMI_FONT_SIZE / 30) + ui_layout_.koyomi_font_x), static_cast(ui_layout_.koyomi_font_y + i * (paxg::FontConfig::KOYOMI_FONT_SIZE * 4 / 3))), paxg::Color(0, 0, 0)); + (*one_font).drawTopRight(std::to_string(date_year), paxs::Vector2(static_cast((85 * paxg::FontConfig::KOYOMI_FONT_SIZE / 30) + ui_layout_.koyomi_font_x), static_cast(ui_layout_.koyomi_font_y + (i * paxg::FontConfig::KOYOMI_FONT_SIZE * 4 / 3))), paxg::Color(0, 0, 0)); + (*one_font).drawTopRight(std::to_string(date_month), paxs::Vector2(static_cast((190 * paxg::FontConfig::KOYOMI_FONT_SIZE / 30) + ui_layout_.koyomi_font_x), static_cast(ui_layout_.koyomi_font_y + (i * paxg::FontConfig::KOYOMI_FONT_SIZE * 4 / 3))), paxg::Color(0, 0, 0)); + (*one_font).drawTopRight(std::to_string(date_day), paxs::Vector2(static_cast((270 * paxg::FontConfig::KOYOMI_FONT_SIZE / 30) + ui_layout_.koyomi_font_x), static_cast(ui_layout_.koyomi_font_y + (i * paxg::FontConfig::KOYOMI_FONT_SIZE * 4 / 3))), paxg::Color(0, 0, 0)); if (date_lm) { const std::string* unit_leap = Fonts().getLocalesText(calendar_ui_domain_key, unit_leap_key); if (unit_leap != nullptr) { - (*one_font).drawTopRight(*unit_leap, paxg::Vec2i(static_cast(( - (date_month < 10) ? int(167 * paxg::FontConfig::KOYOMI_FONT_SIZE / 30.0) + ui_layout_.koyomi_font_x : int(152 * paxg::FontConfig::KOYOMI_FONT_SIZE / 30.0) + ui_layout_.koyomi_font_x - )), static_cast(ui_layout_.koyomi_font_y + i * (paxg::FontConfig::KOYOMI_FONT_SIZE * 4 / 3))), paxg::Color(0, 0, 0)); + (*one_font).drawTopRight(*unit_leap, paxs::Vector2(static_cast( + (date_month < 10) ? (167 * paxg::FontConfig::KOYOMI_FONT_SIZE / 30.0) + ui_layout_.koyomi_font_x : (152 * paxg::FontConfig::KOYOMI_FONT_SIZE / 30.0) + ui_layout_.koyomi_font_x + ), static_cast(ui_layout_.koyomi_font_y + (i * paxg::FontConfig::KOYOMI_FONT_SIZE * 4 / 3))), paxg::Color(0, 0, 0)); } else { PAXS_WARNING("[CalendarContent] Missing unit_leap text for leap month"); } @@ -191,11 +190,11 @@ namespace paxs { case paxs::cal::DateOutputType::name_and_value: { (*one_font).drawTopRight(*text_str, - paxg::Vec2i(static_cast(ui_layout_.koyomi_font_x), static_cast(ui_layout_.koyomi_font_y + i * (paxg::FontConfig::KOYOMI_FONT_SIZE * 4 / 3))), paxg::Color(0, 0, 0)); + paxs::Vector2(ui_layout_.koyomi_font_x, ui_layout_.koyomi_font_y + (i * paxg::FontConfig::KOYOMI_FONT_SIZE * 4 / 3)), paxg::Color(0, 0, 0)); std::visit([&](const auto& x) { date_day = int(x.getDay()); }, koyomi_.date_list[i].date); - (*one_font).drawTopRight(std::to_string(date_day), paxg::Vec2i(static_cast(int(300 * paxg::FontConfig::KOYOMI_FONT_SIZE / 30.0) + ui_layout_.koyomi_font_x), static_cast(ui_layout_.koyomi_font_y + i * (paxg::FontConfig::KOYOMI_FONT_SIZE * 4 / 3))), paxg::Color(0, 0, 0)); + (*one_font).drawTopRight(std::to_string(date_day), paxs::Vector2(static_cast((300 * paxg::FontConfig::KOYOMI_FONT_SIZE / 30.0) + ui_layout_.koyomi_font_x), static_cast(ui_layout_.koyomi_font_y + (i * paxg::FontConfig::KOYOMI_FONT_SIZE * 4 / 3))), paxg::Color(0, 0, 0)); break; } default: @@ -291,23 +290,22 @@ namespace paxs { if (text_str != nullptr) { (*one_font).drawTopRight(*text_str, - paxg::Vec2i(static_cast(ui_layout_.koyomi_font_en_x), static_cast(ui_layout_.koyomi_font_en_y + i * (paxg::FontConfig::KOYOMI_FONT_SIZE * 4 / 3))), paxg::Color(0, 0, 0)); + paxs::Vector2(ui_layout_.koyomi_font_en_x, static_cast(ui_layout_.koyomi_font_en_y + (i * paxg::FontConfig::KOYOMI_FONT_SIZE * 4 / 3))), paxg::Color(0, 0, 0)); } - (*one_font).drawTopRight(",", paxg::Vec2i(static_cast(int(95 * paxg::FontConfig::KOYOMI_FONT_SIZE / 30.0) + ui_layout_.koyomi_font_en_x), static_cast(ui_layout_.koyomi_font_en_y + i * (paxg::FontConfig::KOYOMI_FONT_SIZE * 4 / 3))), paxg::Color(0, 0, 0)); - (*one_font).drawTopRight(",", paxg::Vec2i(static_cast(int(235 * paxg::FontConfig::KOYOMI_FONT_SIZE / 30.0) + ui_layout_.koyomi_font_en_x), static_cast(ui_layout_.koyomi_font_en_y + i * (paxg::FontConfig::KOYOMI_FONT_SIZE * 4 / 3))), paxg::Color(0, 0, 0)); - (*one_font).drawTopRight("th", paxg::Vec2i(static_cast(int(315 * paxg::FontConfig::KOYOMI_FONT_SIZE / 30.0) + ui_layout_.koyomi_font_en_x), static_cast(ui_layout_.koyomi_font_en_y + i * (paxg::FontConfig::KOYOMI_FONT_SIZE * 4 / 3))), paxg::Color(0, 0, 0)); - - (*one_font).drawTopRight(std::to_string(date_year), paxg::Vec2i(static_cast(int(en_cal_name_pos_x * paxg::FontConfig::KOYOMI_FONT_SIZE / 30.0) + ui_layout_.koyomi_font_en_x), static_cast(ui_layout_.koyomi_font_en_y + i * (paxg::FontConfig::KOYOMI_FONT_SIZE * 4 / 3))), paxg::Color(0, 0, 0)); - (*one_font).drawTopRight(std::string(koyomi_.month_name[date_month]), paxg::Vec2i(static_cast(int(220 * paxg::FontConfig::KOYOMI_FONT_SIZE / 30.0) + ui_layout_.koyomi_font_en_x), static_cast(ui_layout_.koyomi_font_en_y + i * (paxg::FontConfig::KOYOMI_FONT_SIZE * 4 / 3))), paxg::Color(0, 0, 0)); - (*one_font).drawTopRight(std::to_string(date_day), paxg::Vec2i(static_cast(int(280 * paxg::FontConfig::KOYOMI_FONT_SIZE / 30.0) + ui_layout_.koyomi_font_en_x), static_cast(ui_layout_.koyomi_font_en_y + i * (paxg::FontConfig::KOYOMI_FONT_SIZE * 4 / 3))), paxg::Color(0, 0, 0)); + (*one_font).drawTopRight(",", paxs::Vector2(static_cast((95 * paxg::FontConfig::KOYOMI_FONT_SIZE / 30.0) + ui_layout_.koyomi_font_en_x), static_cast(ui_layout_.koyomi_font_en_y + (i * paxg::FontConfig::KOYOMI_FONT_SIZE * 4 / 3))), paxg::Color(0, 0, 0)); + (*one_font).drawTopRight(",", paxs::Vector2(static_cast((235 * paxg::FontConfig::KOYOMI_FONT_SIZE / 30.0) + ui_layout_.koyomi_font_en_x), static_cast(ui_layout_.koyomi_font_en_y + (i * paxg::FontConfig::KOYOMI_FONT_SIZE * 4 / 3))), paxg::Color(0, 0, 0)); + (*one_font).drawTopRight("th", paxs::Vector2(static_cast((315 * paxg::FontConfig::KOYOMI_FONT_SIZE / 30.0) + ui_layout_.koyomi_font_en_x), static_cast(ui_layout_.koyomi_font_en_y + (i * paxg::FontConfig::KOYOMI_FONT_SIZE * 4 / 3))), paxg::Color(0, 0, 0)); + (*one_font).drawTopRight(std::to_string(date_year), paxs::Vector2(static_cast(en_cal_name_pos_x * paxg::FontConfig::KOYOMI_FONT_SIZE / 30.0) + ui_layout_.koyomi_font_en_x, static_cast(ui_layout_.koyomi_font_en_y + (i * paxg::FontConfig::KOYOMI_FONT_SIZE * 4 / 3))), paxg::Color(0, 0, 0)); + (*one_font).drawTopRight(std::string(koyomi_.month_name[date_month]), paxs::Vector2(static_cast(220 * paxg::FontConfig::KOYOMI_FONT_SIZE / 30.0) + ui_layout_.koyomi_font_en_x, static_cast(ui_layout_.koyomi_font_en_y + (i * paxg::FontConfig::KOYOMI_FONT_SIZE * 4 / 3))), paxg::Color(0, 0, 0)); + (*one_font).drawTopRight(std::to_string(date_day), paxs::Vector2(static_cast(280 * paxg::FontConfig::KOYOMI_FONT_SIZE / 30.0) + ui_layout_.koyomi_font_en_x, static_cast(ui_layout_.koyomi_font_en_y + (i * paxg::FontConfig::KOYOMI_FONT_SIZE * 4 / 3))), paxg::Color(0, 0, 0)); if (date_lm) { const std::string* unit_leap = Fonts().getLocalesText(calendar_ui_domain_key, unit_leap_key); if (unit_leap != nullptr) { - (*one_font).drawTopRight(*unit_leap, paxg::Vec2i(static_cast(( - int(152 * paxg::FontConfig::KOYOMI_FONT_SIZE / 30.0) + ui_layout_.koyomi_font_en_x - )), static_cast(ui_layout_.koyomi_font_en_y + i * (paxg::FontConfig::KOYOMI_FONT_SIZE * 4 / 3))), paxg::Color(0, 0, 0)); + (*one_font).drawTopRight(*unit_leap, paxs::Vector2(static_cast(( + (152 * paxg::FontConfig::KOYOMI_FONT_SIZE / 30.0) + ui_layout_.koyomi_font_en_x + )), static_cast(ui_layout_.koyomi_font_en_y + (i * paxg::FontConfig::KOYOMI_FONT_SIZE * 4 / 3))), paxg::Color(0, 0, 0)); } } break; diff --git a/Library/PAX_MAHOROBA/UI/DebugInfoPanel.hpp b/Library/PAX_MAHOROBA/UI/DebugInfoPanel.hpp index 300d5cd4b..8782d27d9 100644 --- a/Library/PAX_MAHOROBA/UI/DebugInfoPanel.hpp +++ b/Library/PAX_MAHOROBA/UI/DebugInfoPanel.hpp @@ -14,7 +14,6 @@ #include #include -#include #include #include @@ -80,13 +79,13 @@ namespace paxs { if (mag_label_ptr != nullptr) { font->draw( *mag_label_ptr, - paxg::Vec2i(text_x, text_y + line_height * current_line++), + paxs::Vector2(text_x, text_y + line_height * current_line++), paxg::Color(0, 0, 0) ); } font->draw( std::to_string(map_viewport_.getHeight()), - paxg::Vec2i(text_x + 10, text_y + line_height * current_line++), + paxs::Vector2(text_x + 10, text_y + line_height * current_line++), paxg::Color(0, 0, 0) ); @@ -99,13 +98,13 @@ namespace paxs { if (xyz_label_ptr != nullptr) { font->draw( *xyz_label_ptr, - paxg::Vec2i(text_x, text_y + line_height * current_line++), + paxs::Vector2(text_x, text_y + line_height * current_line++), paxg::Color(0, 0, 0) ); } font->draw( std::to_string(z_magnification), - paxg::Vec2i(text_x + 10, text_y + line_height * current_line++), + paxs::Vector2(text_x + 10, text_y + line_height * current_line++), paxg::Color(0, 0, 0) ); @@ -117,13 +116,13 @@ namespace paxs { if (merc_lon_label_ptr != nullptr) { font->draw( *merc_lon_label_ptr, - paxg::Vec2i(text_x, text_y + line_height * current_line++), + paxs::Vector2(text_x, text_y + line_height * current_line++), paxg::Color(0, 0, 0) ); } font->draw( std::to_string(map_viewport_center.x), - paxg::Vec2i(text_x + 10, text_y + line_height * current_line++), + paxs::Vector2(text_x + 10, text_y + line_height * current_line++), paxg::Color(0, 0, 0) ); @@ -135,13 +134,13 @@ namespace paxs { if (merc_lat_label_ptr != nullptr) { font->draw( *merc_lat_label_ptr, - paxg::Vec2i(text_x, text_y + line_height * current_line++), + paxs::Vector2(text_x, text_y + line_height * current_line++), paxg::Color(0, 0, 0) ); } font->draw( std::to_string(map_viewport_center.y), - paxg::Vec2i(text_x + 10, text_y + line_height * current_line++), + paxs::Vector2(text_x + 10, text_y + line_height * current_line++), paxg::Color(0, 0, 0) ); @@ -153,7 +152,7 @@ namespace paxs { if (lat_label_ptr != nullptr) { font->draw( *lat_label_ptr, - paxg::Vec2i(text_x, text_y + line_height * current_line++), + paxs::Vector2(text_x, text_y + line_height * current_line++), paxg::Color(0, 0, 0) ); } @@ -161,7 +160,7 @@ namespace paxs { const paxs::WebMercatorDeg merc_coord(paxs::Vector2(map_viewport_center.x, map_viewport_center.y)); font->draw( std::to_string(merc_coord.toEPSG4326_WGS84DegY()), - paxg::Vec2i(text_x + 10, text_y + line_height * current_line++), + paxs::Vector2(text_x + 10, text_y + line_height * current_line++), paxg::Color(0, 0, 0) ); @@ -195,7 +194,7 @@ namespace paxs { big_year_font->drawBottomRight( std::to_string(date_year), - paxg::Vec2i(big_year_x, big_year_y), + paxs::Vector2(big_year_x, big_year_y), paxg::Color(0, 0, 0) ); } diff --git a/Library/PAX_MAHOROBA/UI/MenuBar/MenuBar.hpp b/Library/PAX_MAHOROBA/UI/MenuBar/MenuBar.hpp index 14979e1c8..bdd8bad64 100644 --- a/Library/PAX_MAHOROBA/UI/MenuBar/MenuBar.hpp +++ b/Library/PAX_MAHOROBA/UI/MenuBar/MenuBar.hpp @@ -42,7 +42,6 @@ namespace paxs { public: MenuBar(const paxs::FeatureVisibilityManager& visible_manager) : language_selector_(paxs::MurMur3::calcHash("Language"), - paxs::Vector2{ 3000, 0 }, paxs::PulldownDisplayType::SelectedValue, true ) { @@ -54,9 +53,9 @@ namespace paxs { github_button_.init(language_selector_); // 言語選択のコールバックを設定(キーベース) - language_selector_.setOnSelectionChanged([this](std::uint_least32_t key, bool is_selected) { + language_selector_.setOnSelectionChanged([](std::uint_least32_t key, bool is_selected) { (void)is_selected; - handleLanguageChanged(key); + paxs::EventBus::getInstance().publish(LanguageChangeCommandEvent(key)); }); // メニューバーにメニュー項目を追加(FontSystem経由) @@ -100,14 +99,6 @@ namespace paxs { return language_selector_.getRect().height(); } - /// @brief 言語変更時のハンドラー(コールバック駆動、キーベース) - /// @brief Language change handler (callback-driven, key-based) - /// @param language_key 選択された言語のキー / Selected language key - void handleLanguageChanged(std::uint_least32_t language_key) { - // EventBus経由で言語変更コマンドを発行(キーのみ) - paxs::EventBus::getInstance().publish(LanguageChangeCommandEvent(language_key)); - } - /// @brief メニュー項目トグル時のハンドラー(コールバック駆動) void handleMenuItemToggled(const paxs::MenuBarType menu_type, std::size_t item_index, bool is_checked) { // item_indexはDropDownMenuの内部インデックス(0はヘッダー、1以降が実際の項目) diff --git a/Library/PAX_MAHOROBA/UI/Pulldown.hpp b/Library/PAX_MAHOROBA/UI/Pulldown.hpp index dc800dca0..f8127c565 100644 --- a/Library/PAX_MAHOROBA/UI/Pulldown.hpp +++ b/Library/PAX_MAHOROBA/UI/Pulldown.hpp @@ -50,7 +50,7 @@ namespace paxs { std::vector is_items; // 項目が TRUE か FALSE になっているか格納 paxs::UnorderedMap item_index_key{}; // 項目の Key を格納 - paxg::Rect rect; + paxg::Rect rect{ 3000.0f, 0.0f, 0.0f, 0.0f }; // プルダウンの矩形 PulldownDisplayType display_type{}; // 表示タイプ (SelectedValue or FixedHeader) bool is_one_font = false; @@ -162,11 +162,9 @@ namespace paxs { /// @param is_one_font_ 単一フォントを使用するか Pulldown( const std::uint_least32_t domain_hash_, - const paxg::Vec2i& pos_ = { 0,0 }, PulldownDisplayType display_type_ = PulldownDisplayType::SelectedValue, const bool is_one_font_ = false) - : rect{ static_cast(pos_.x()), static_cast(pos_.y()),0, 0 } - , display_type(display_type_) + : display_type(display_type_) , is_one_font(is_one_font_) , domain_hash(domain_hash_) { } diff --git a/Library/PAX_MAHOROBA/UI/Simulation/SimulationPanel.hpp b/Library/PAX_MAHOROBA/UI/Simulation/SimulationPanel.hpp index 773150aaa..37d91341c 100644 --- a/Library/PAX_MAHOROBA/UI/Simulation/SimulationPanel.hpp +++ b/Library/PAX_MAHOROBA/UI/Simulation/SimulationPanel.hpp @@ -156,7 +156,6 @@ namespace paxs { #endif simulation_pulldown( paxs::MurMur3::calcHash("SimulationModels"), - paxs::Vector2{3000, 0}, paxs::PulldownDisplayType::SelectedValue, false ) diff --git a/Library/PAX_SAPIENTICA/Core/Type/Vector2.hpp b/Library/PAX_SAPIENTICA/Core/Type/Vector2.hpp index 7fdbc27f5..d9185576f 100644 --- a/Library/PAX_SAPIENTICA/Core/Type/Vector2.hpp +++ b/Library/PAX_SAPIENTICA/Core/Type/Vector2.hpp @@ -22,7 +22,7 @@ namespace paxs { /// @brief 2D Vector class. template struct Vector2 { - constexpr explicit Vector2() noexcept = default; + constexpr explicit Vector2() noexcept : x(0), y(0) {} constexpr Vector2(T x, T y) noexcept : x(x), y(y) {} T x; diff --git a/Library/PAX_SAPIENTICA/Simulation/Config/JapanProvinces.hpp b/Library/PAX_SAPIENTICA/Simulation/Config/JapanProvinces.hpp index 3a11221b0..7aeba9b6f 100644 --- a/Library/PAX_SAPIENTICA/Simulation/Config/JapanProvinces.hpp +++ b/Library/PAX_SAPIENTICA/Simulation/Config/JapanProvinces.hpp @@ -378,8 +378,11 @@ namespace paxs { std::uint_least8_t getLanguage(const std::uint_least8_t id, std::mt19937& gen) noexcept { for (const auto& district : district_list) { if (district.id == id) { - auto& weight_list = language_region_list.at(district.language_region_hash); - return weight_list.id[weight_list.dist(gen)]; + auto* const weight_list = language_region_list.try_get(district.language_region_hash); + if (weight_list == nullptr) { + break; + } + return weight_list->id[weight_list->dist(gen)]; } } PAXS_WARNING("Failed to get District: " + std::to_string(id)); @@ -397,8 +400,11 @@ namespace paxs { std::uint_least8_t getMtDNA(const std::uint_least8_t id, std::mt19937& gen) noexcept { for (const auto& district : district_list) { if (district.id == id) { - auto& weight_list = mtdna_region_list.at(district.mtdna_region_hash); - return weight_list.id[weight_list.dist(gen)]; + auto* const weight_list = mtdna_region_list.try_get(district.mtdna_region_hash); + if (weight_list == nullptr) { + break; + } + return weight_list->id[weight_list->dist(gen)]; } } PAXS_WARNING("Failed to get District: " + std::to_string(id)); diff --git a/Projects/IncludeTest/source/PAX_GRAPHICA/Vec2IncludeTest.cpp b/Projects/IncludeTest/source/PAX_GRAPHICA/Vec2IncludeTest.cpp deleted file mode 100644 index fe4a0b6e4..000000000 --- a/Projects/IncludeTest/source/PAX_GRAPHICA/Vec2IncludeTest.cpp +++ /dev/null @@ -1,3 +0,0 @@ -#include - -int main(){} diff --git a/Projects/IntegrationTest/Source/WindowTest.cpp b/Projects/IntegrationTest/Source/WindowTest.cpp index 7207bdfc3..409f6a201 100644 --- a/Projects/IntegrationTest/Source/WindowTest.cpp +++ b/Projects/IntegrationTest/Source/WindowTest.cpp @@ -13,7 +13,6 @@ #include #include #include -#include #include #include diff --git a/Projects/UnitTest/Source/PAX_GRAPHICA/MouseUnitTest.cpp b/Projects/UnitTest/Source/PAX_GRAPHICA/MouseUnitTest.cpp index ddf52d7d4..2c6bc293c 100644 --- a/Projects/UnitTest/Source/PAX_GRAPHICA/MouseUnitTest.cpp +++ b/Projects/UnitTest/Source/PAX_GRAPHICA/MouseUnitTest.cpp @@ -120,8 +120,8 @@ TEST(MouseUnitTest, OptionalUsagePattern) { if (auto pos = mouse->tryGetPosition()) { // If we have a position, use it - ASSERT_TRUE(pos->x() >= -1); - ASSERT_TRUE(pos->y() >= -1); + ASSERT_TRUE(pos->x >= -1); + ASSERT_TRUE(pos->y >= -1); } else { // If we don't have a position, handle gracefully #if !defined(PAXS_USING_SIV3D) && !defined(PAXS_USING_SFML) && !defined(PAXS_USING_DXLIB) diff --git a/Projects/UnitTest/Source/PAX_GRAPHICA/TriangleUnitTest.cpp b/Projects/UnitTest/Source/PAX_GRAPHICA/TriangleUnitTest.cpp index bd813b202..6cd5e1c24 100644 --- a/Projects/UnitTest/Source/PAX_GRAPHICA/TriangleUnitTest.cpp +++ b/Projects/UnitTest/Source/PAX_GRAPHICA/TriangleUnitTest.cpp @@ -35,7 +35,7 @@ TEST(TriangleUnitTest, ParameterizedConstruction) { // Test Vec2f constructor TEST(TriangleUnitTest, Vec2fConstruction) { - paxg::Vec2f center(150.0f, 250.0f); + paxs::Vector2 center(150.0f, 250.0f); paxg::Triangle triangle(center, 30.0f, 1.5708f); EXPECT_FLOAT_EQ(triangle.centerX(), 150.0f); EXPECT_FLOAT_EQ(triangle.centerY(), 250.0f); @@ -57,7 +57,7 @@ TEST(TriangleUnitTest, Setters) { EXPECT_FLOAT_EQ(triangle.centerX(), 100.0f); EXPECT_FLOAT_EQ(triangle.centerY(), 150.0f); - paxg::Vec2f newCenter(200.0f, 300.0f); + paxs::Vector2 newCenter(200.0f, 300.0f); triangle.setCenter(newCenter); EXPECT_FLOAT_EQ(triangle.centerX(), 200.0f); EXPECT_FLOAT_EQ(triangle.centerY(), 300.0f); diff --git a/Projects/UnitTest/Source/PAX_GRAPHICA/Vec2UnitTest.cpp b/Projects/UnitTest/Source/PAX_GRAPHICA/Vec2UnitTest.cpp deleted file mode 100644 index 687188d52..000000000 --- a/Projects/UnitTest/Source/PAX_GRAPHICA/Vec2UnitTest.cpp +++ /dev/null @@ -1,152 +0,0 @@ -/*########################################################################################## - - PAX SAPIENTICA Library 💀🌿🌏 - - [Planning] 2023-2024 As Project - [Production] 2023-2024 As Project - [Contact Us] wanotaitei@gmail.com https://github.com/AsPJT/PAX_SAPIENTICA - [License] Distributed under the CC0 1.0. https://creativecommons.org/publicdomain/zero/1.0/ - -##########################################################################################*/ - -#include - -#include - -// Test Vec2 construction -TEST(Vec2UnitTest, IntConstruction) { - paxg::Vec2i v1; - ASSERT_EQ(v1.x(), 0); - ASSERT_EQ(v1.y(), 0); - - paxg::Vec2i v2(10, 20); - ASSERT_EQ(v2.x(), 10); - ASSERT_EQ(v2.y(), 20); -} - -// Test Vec2 construction -TEST(Vec2UnitTest, FloatConstruction) { - paxg::Vec2f v1; - ASSERT_FLOAT_EQ(v1.x(), 0.0f); - ASSERT_FLOAT_EQ(v1.y(), 0.0f); - - paxg::Vec2f v2(3.14f, 2.71f); - ASSERT_FLOAT_EQ(v2.x(), 3.14f); - ASSERT_FLOAT_EQ(v2.y(), 2.71f); -} - -// Test addition operator -TEST(Vec2UnitTest, AdditionOperator) { - paxg::Vec2i v1(10, 20); - paxg::Vec2i v2(5, 8); - paxg::Vec2i result = v1 + v2; - ASSERT_EQ(result.x(), 15); - ASSERT_EQ(result.y(), 28); - - paxg::Vec2f vf1(1.5f, 2.5f); - paxg::Vec2f vf2(0.5f, 1.0f); - paxg::Vec2f resultf = vf1 + vf2; - ASSERT_FLOAT_EQ(resultf.x(), 2.0f); - ASSERT_FLOAT_EQ(resultf.y(), 3.5f); -} - -// Test subtraction operator -TEST(Vec2UnitTest, SubtractionOperator) { - paxg::Vec2i v1(10, 20); - paxg::Vec2i v2(3, 5); - paxg::Vec2i result = v1 - v2; - ASSERT_EQ(result.x(), 7); - ASSERT_EQ(result.y(), 15); - - paxg::Vec2f vf1(5.0f, 3.0f); - paxg::Vec2f vf2(2.0f, 1.5f); - paxg::Vec2f resultf = vf1 - vf2; - ASSERT_FLOAT_EQ(resultf.x(), 3.0f); - ASSERT_FLOAT_EQ(resultf.y(), 1.5f); -} - -// Test += operator -TEST(Vec2UnitTest, AdditionAssignmentOperator) { - paxg::Vec2i v(10, 20); - v += paxg::Vec2i(5, 3); - ASSERT_EQ(v.x(), 15); - ASSERT_EQ(v.y(), 23); - - paxg::Vec2f vf(1.0f, 2.0f); - vf += paxg::Vec2f(0.5f, 1.5f); - ASSERT_FLOAT_EQ(vf.x(), 1.5f); - ASSERT_FLOAT_EQ(vf.y(), 3.5f); -} - -// Test -= operator -TEST(Vec2UnitTest, SubtractionAssignmentOperator) { - paxg::Vec2i v(10, 20); - v -= paxg::Vec2i(3, 8); - ASSERT_EQ(v.x(), 7); - ASSERT_EQ(v.y(), 12); - - paxg::Vec2f vf(5.0f, 3.0f); - vf -= paxg::Vec2f(1.0f, 0.5f); - ASSERT_FLOAT_EQ(vf.x(), 4.0f); - ASSERT_FLOAT_EQ(vf.y(), 2.5f); -} - -// Test equality operator -TEST(Vec2UnitTest, EqualityOperator) { - paxg::Vec2i v1(10, 20); - paxg::Vec2i v2(10, 20); - paxg::Vec2i v3(11, 20); - ASSERT_TRUE(v1 == v2); - ASSERT_FALSE(v1 == v3); - - paxg::Vec2f vf1(1.0f, 2.0f); - paxg::Vec2f vf2(1.0f, 2.0f); - paxg::Vec2f vf3(1.0f, 2.1f); - ASSERT_TRUE(vf1 == vf2); - ASSERT_FALSE(vf1 == vf3); -} - -// Test inequality operator -TEST(Vec2UnitTest, InequalityOperator) { - paxg::Vec2i v1(10, 20); - paxg::Vec2i v2(11, 20); - paxg::Vec2i v3(10, 20); - ASSERT_TRUE(v1 != v2); - ASSERT_FALSE(v1 != v3); - - paxg::Vec2f vf1(1.0f, 2.0f); - paxg::Vec2f vf2(1.1f, 2.0f); - paxg::Vec2f vf3(1.0f, 2.0f); - ASSERT_TRUE(vf1 != vf2); - ASSERT_FALSE(vf1 != vf3); -} - -// Test template instantiation -TEST(Vec2UnitTest, TypeAliases) { - // Ensure Vec2i and Vec2f are properly instantiated - paxg::Vec2i vi(1, 2); - paxg::Vec2f vf(1.0f, 2.0f); - - ASSERT_EQ(sizeof(vi), sizeof(paxg::Vec2)); - ASSERT_EQ(sizeof(vf), sizeof(paxg::Vec2)); -} - -// Test zero vectors -TEST(Vec2UnitTest, ZeroVectors) { - paxg::Vec2i vi; - ASSERT_EQ(vi.x(), 0); - ASSERT_EQ(vi.y(), 0); - - paxg::Vec2f vf; - ASSERT_FLOAT_EQ(vf.x(), 0.0f); - ASSERT_FLOAT_EQ(vf.y(), 0.0f); -} - -// Test chain operations -TEST(Vec2UnitTest, ChainOperations) { - paxg::Vec2i v(10, 20); - v += paxg::Vec2i(5, 5); - v -= paxg::Vec2i(3, 2); - ASSERT_EQ(v.x(), 12); - ASSERT_EQ(v.y(), 23); -} From 75a0834e93d46f56f0c90e6b36027f15a52db584 Mon Sep 17 00:00:00 2001 From: guinpen98 <83969826+guinpen98@users.noreply.github.com> Date: Thu, 4 Dec 2025 01:01:56 +0900 Subject: [PATCH 4/9] ref: color --- Library/PAX_GRAPHICA/Color.hpp | 99 ++++++++++++++----- Library/PAX_GRAPHICA/ColorF.hpp | 50 ---------- .../PAX_GRAPHICA/DxLib/DxLibCircleImpl.hpp | 2 - Library/PAX_GRAPHICA/Font.hpp | 44 ++++----- Library/PAX_GRAPHICA/Interface/CircleImpl.hpp | 4 +- Library/PAX_GRAPHICA/Line.hpp | 4 +- Library/PAX_GRAPHICA/Null/NullCircleImpl.hpp | 2 - Library/PAX_GRAPHICA/Rect.hpp | 18 ++-- Library/PAX_GRAPHICA/RenderTexture.hpp | 2 +- Library/PAX_GRAPHICA/RoundRect.hpp | 18 ++-- Library/PAX_GRAPHICA/SFML/SFMLCircleImpl.hpp | 4 +- Library/PAX_GRAPHICA/SFML/SFMLWindowImpl.hpp | 4 +- Library/PAX_GRAPHICA/ScopedRenderTarget.hpp | 2 +- .../PAX_GRAPHICA/Siv3D/Siv3DCircleImpl.hpp | 4 +- .../PAX_GRAPHICA/Siv3D/Siv3DWindowImpl.hpp | 4 +- Library/PAX_GRAPHICA/Spline2D.hpp | 2 +- Library/PAX_GRAPHICA/ToggleButton.hpp | 16 +-- Library/PAX_GRAPHICA/Triangle.hpp | 6 +- Library/PAX_GRAPHICA/Window.hpp | 4 +- .../PAX_MAHOROBA/Rendering/ShadowRenderer.hpp | 2 +- .../source/PAX_GRAPHICA/ColorFIncludeTest.cpp | 3 - 21 files changed, 141 insertions(+), 153 deletions(-) delete mode 100644 Library/PAX_GRAPHICA/ColorF.hpp delete mode 100644 Projects/IncludeTest/source/PAX_GRAPHICA/ColorFIncludeTest.cpp diff --git a/Library/PAX_GRAPHICA/Color.hpp b/Library/PAX_GRAPHICA/Color.hpp index fe58bbb98..c227e4f1b 100644 --- a/Library/PAX_GRAPHICA/Color.hpp +++ b/Library/PAX_GRAPHICA/Color.hpp @@ -13,9 +13,10 @@ #define PAX_GRAPHICA_COLOR_HPP #include +#include #if defined(PAXS_USING_SIV3D) -#include +#include #elif defined(PAXS_USING_DXLIB) #include #elif defined(PAXS_USING_SFML) @@ -24,34 +25,84 @@ namespace paxg { - // R 赤 - // G 緑 - // B 青 - // A 不透明度 - struct Color { + /// @brief Generic color template class supporting both integer (0-255) and floating-point (0.0-1.0) colors + /// @tparam T Component type (int or double) + /// @brief RGBAカラーを扱う汎用テンプレートクラス(整数版と浮動小数点版の両方に対応) + template + struct ColorT { + static_assert(std::is_same_v || std::is_same_v, + "Color component type must be int or double"); + + // Component values (RGBA) + T r, g, b, a; + + /// @brief Constructor with RGBA components + /// @param r_ Red component + /// @param g_ Green component + /// @param b_ Blue component + /// @param a_ Alpha component (default: 255 for int, 1.0 for double) + constexpr ColorT(T r_, T g_, T b_, T a_ = std::is_same_v ? T(255) : T(1.0)) + : r(r_), g(g_), b(b_), a(a_) {} + + /// @brief Constructor with grayscale and alpha + /// @param rgb Grayscale value + /// @param a_ Alpha component (default: 255 for int, 1.0 for double) + constexpr ColorT(T rgb, T a_ = std::is_same_v ? T(255) : T(1.0)) + : r(rgb), g(rgb), b(rgb), a(a_) {} + #if defined(PAXS_USING_SIV3D) - s3d::Color color; - constexpr Color(const int r, const int g, const int b, const int a = 255) : - color(static_cast(r), - static_cast(g), - static_cast(b), - static_cast(a)) {} - operator s3d::Color() const { return color; } + // Siv3D conversion operators + // Use std::conditional to select the correct Siv3D type based on T + using Siv3DColorType = typename std::conditional_t< + std::is_same_v, + s3d::ColorF, + s3d::Color + >; + + /// @brief Convert to Siv3D color type (s3d::Color or s3d::ColorF) + operator Siv3DColorType() const { + if constexpr (std::is_same_v) { + return s3d::ColorF(r, g, b, a); + } else { + return s3d::Color( + static_cast(r), + static_cast(g), + static_cast(b), + static_cast(a) + ); + } + } #elif defined(PAXS_USING_SFML) - sf::Color color; - constexpr Color(const int r, const int g, const int b, const int a = 255) : color( - static_cast(r), - static_cast(g), - static_cast(b), - static_cast(a)) {} - operator sf::Color() const { return color; } -#else - int r, g, b, a = 255; - constexpr Color(int r, int g, int b, int a = 255) : r(r), g(g), b(b), a(a) {} + // SFML only supports integer colors (sf::Color) + template + operator typename std::enable_if_t, sf::Color>() const { + return sf::Color( + static_cast(r), + static_cast(g), + static_cast(b), + static_cast(a) + ); + } #endif + + // Equality operators + constexpr bool operator==(const ColorT& other) const { + return r == other.r && g == other.g && b == other.b && a == other.a; + } + + constexpr bool operator!=(const ColorT& other) const { + return !(*this == other); + } }; -} + // Type aliases for backward compatibility and convenience + /// @brief Integer-based color (0-255 range) - backward compatible with old Color + using Color = ColorT; + + /// @brief Floating-point color (0.0-1.0 range) - backward compatible with old ColorF + using ColorF = ColorT; + +} // namespace paxg #endif // !PAX_GRAPHICA_COLOR_HPP diff --git a/Library/PAX_GRAPHICA/ColorF.hpp b/Library/PAX_GRAPHICA/ColorF.hpp deleted file mode 100644 index 977f1c41d..000000000 --- a/Library/PAX_GRAPHICA/ColorF.hpp +++ /dev/null @@ -1,50 +0,0 @@ -/*########################################################################################## - - PAX SAPIENTICA Library 💀🌿🌏 - - [Planning] 2023-2024 As Project - [Production] 2023-2024 As Project - [Contact Us] wanotaitei@gmail.com https://github.com/AsPJT/PAX_SAPIENTICA - [License] Distributed under the CC0 1.0. https://creativecommons.org/publicdomain/zero/1.0/ - -##########################################################################################*/ - -#ifndef PAX_GRAPHICA_COLOR_F_HPP -#define PAX_GRAPHICA_COLOR_F_HPP - -#if defined(PAXS_USING_SIV3D) -#include -#endif - -namespace paxg { - - /// @brief Floating-point color class (0.0-1.0 range) - /// @brief 浮動小数点カラークラス(0.0-1.0の範囲) - struct ColorF { - double r, g, b, a; - - /// @brief Constructor with RGB and alpha - /// @param r_ Red component (0.0-1.0) - /// @param g_ Green component (0.0-1.0) - /// @param b_ Blue component (0.0-1.0) - /// @param a_ Alpha component (0.0-1.0) - constexpr ColorF(double r_, double g_, double b_, double a_ = 1.0) - : r(r_), g(g_), b(b_), a(a_) {} - - /// @brief Constructor with grayscale and alpha - /// @param rgb Grayscale value (0.0-1.0) - /// @param a_ Alpha component (0.0-1.0) - constexpr ColorF(double rgb, double a_) - : r(rgb), g(rgb), b(rgb), a(a_) {} - -#if defined(PAXS_USING_SIV3D) - /// @brief Convert to Siv3D ColorF - operator s3d::ColorF() const { - return s3d::ColorF(r, g, b, a); - } -#endif - }; - -} // namespace paxg - -#endif // !PAX_GRAPHICA_COLOR_F_HPP diff --git a/Library/PAX_GRAPHICA/DxLib/DxLibCircleImpl.hpp b/Library/PAX_GRAPHICA/DxLib/DxLibCircleImpl.hpp index 55b543555..5efc95e9f 100644 --- a/Library/PAX_GRAPHICA/DxLib/DxLibCircleImpl.hpp +++ b/Library/PAX_GRAPHICA/DxLib/DxLibCircleImpl.hpp @@ -21,8 +21,6 @@ namespace paxg { - struct Color; - #ifdef PAXS_USING_DXLIB /// @brief DxLib implementation of CircleImpl diff --git a/Library/PAX_GRAPHICA/Font.hpp b/Library/PAX_GRAPHICA/Font.hpp index 69e62f47e..bcb6b58a7 100644 --- a/Library/PAX_GRAPHICA/Font.hpp +++ b/Library/PAX_GRAPHICA/Font.hpp @@ -46,7 +46,7 @@ namespace paxg{ s3d::TextStyle outline{}; void setOutline(const double inner, const double outer, const paxg::Color& color) { is_outline = true; - outline = s3d::TextStyle::Outline(inner, outer, color.color); + outline = s3d::TextStyle::Outline(inner, outer, color); } /// @brief テキストを左下揃えで描画 (横:左端, 縦:下端) @@ -56,12 +56,12 @@ namespace paxg{ font(s3d::Unicode::FromUTF8(str)).draw( outline, s3d::Arg::bottomLeft = s3d::Vec2(pos.x, pos.y), - color.color); + color); } else { font(s3d::Unicode::FromUTF8(str)).draw( s3d::Arg::bottomLeft = s3d::Vec2(pos.x, pos.y), - color.color); + color); } } /// @brief テキストを右上揃えで描画 (横:右端, 縦:上端) @@ -71,12 +71,12 @@ namespace paxg{ font(s3d::Unicode::FromUTF8(str)).draw( outline, s3d::Arg::topRight = s3d::Vec2(pos.x, pos.y), - color.color); + color); } else { font(s3d::Unicode::FromUTF8(str)).draw( s3d::Arg::topRight = s3d::Vec2(pos.x, pos.y), - color.color); + color); } } /// @brief テキストを右下揃えで描画 (横:右端, 縦:下端) @@ -86,12 +86,12 @@ namespace paxg{ font(s3d::Unicode::FromUTF8(str)).draw( outline, s3d::Arg::bottomRight = s3d::Vec2(pos.x, pos.y), - color.color); + color); } else { font(s3d::Unicode::FromUTF8(str)).draw( s3d::Arg::bottomRight = s3d::Vec2(pos.x, pos.y), - color.color); + color); } } /// @brief テキストを左上揃えで描画 (横:左端, 縦:上端) @@ -101,12 +101,12 @@ namespace paxg{ font(s3d::Unicode::FromUTF8(str)).draw( outline, s3d::Vec2(pos.x, pos.y), - color.color); + color); } else { font(s3d::Unicode::FromUTF8(str)).draw( s3d::Vec2(pos.x, pos.y), - color.color); + color); } } /// @brief テキストを中央下揃えで描画 (横:中央, 縦:下端) @@ -116,12 +116,12 @@ namespace paxg{ font(s3d::Unicode::FromUTF8(str)).draw( outline, s3d::Arg::bottomCenter = s3d::Vec2(pos.x, pos.y), - color.color); + color); } else { font(s3d::Unicode::FromUTF8(str)).draw( s3d::Arg::bottomCenter = s3d::Vec2(pos.x, pos.y), - color.color); + color); } } /// @brief テキストを中央上揃えで描画 (横:中央, 縦:上端) @@ -131,12 +131,12 @@ namespace paxg{ font(s3d::Unicode::FromUTF8(str)).draw( outline, s3d::Arg::topCenter = s3d::Vec2(pos.x, pos.y), - color.color); + color); } else { font(s3d::Unicode::FromUTF8(str)).draw( s3d::Arg::topCenter = s3d::Vec2(pos.x, pos.y), - color.color); + color); } } /// @brief テキストを中央揃えで描画 (横:中央, 縦:中央) @@ -146,12 +146,12 @@ namespace paxg{ font(s3d::Unicode::FromUTF8(str)).drawAt( outline, s3d::Vec2(pos.x, pos.y), - color.color); + color); } else { font(s3d::Unicode::FromUTF8(str)).drawAt( s3d::Vec2(pos.x, pos.y), - color.color); + color); } } @@ -384,7 +384,7 @@ namespace paxg{ sf::Utf<8>::toWide(str.begin(), str.end(), std::back_inserter(wstr)); text.setString(wstr); text.setCharacterSize(size); - text.setFillColor(color.color); + text.setFillColor(color); text.setOutlineColor(sf::Color::White); text.setOutlineThickness(2.0f); text.setPosition({ static_cast(pos.x), static_cast(pos.y - size / 2) }); @@ -399,7 +399,7 @@ namespace paxg{ sf::Utf<8>::toWide(str.begin(), str.end(), std::back_inserter(wstr)); text.setString(wstr); text.setCharacterSize(size); - text.setFillColor(color.color); + text.setFillColor(color); text.setOutlineColor(sf::Color::White); text.setOutlineThickness(2.0f); text.setPosition({ static_cast(pos.x - text.getGlobalBounds().size.x), static_cast(pos.y + size / 2) }); @@ -414,7 +414,7 @@ namespace paxg{ sf::Utf<8>::toWide(str.begin(), str.end(), std::back_inserter(wstr)); text.setString(wstr); text.setCharacterSize(size); - text.setFillColor(color.color); + text.setFillColor(color); text.setOutlineColor(sf::Color::White); text.setOutlineThickness(2.0f); // 文字の底部がpos.yに来るように、テキストの高さ分上に配置 @@ -430,7 +430,7 @@ namespace paxg{ sf::Utf<8>::toWide(str.begin(), str.end(), std::back_inserter(wstr)); text.setString(wstr); text.setCharacterSize(size); - text.setFillColor(color.color); + text.setFillColor(color); text.setOutlineColor(sf::Color::White); text.setOutlineThickness(2.0f); text.setPosition({ static_cast(pos.x), static_cast(pos.y) }); @@ -445,7 +445,7 @@ namespace paxg{ sf::Utf<8>::toWide(str.begin(), str.end(), std::back_inserter(wstr)); text.setString(wstr); text.setCharacterSize(size); - text.setFillColor(color.color); + text.setFillColor(color); text.setOutlineColor(sf::Color::White); text.setOutlineThickness(2.0f); text.setPosition({ static_cast(pos.x - text.getGlobalBounds().size.x / 2), static_cast(pos.y - size / 2) }); @@ -460,7 +460,7 @@ namespace paxg{ sf::Utf<8>::toWide(str.begin(), str.end(), std::back_inserter(wstr)); text.setString(wstr); text.setCharacterSize(size); - text.setFillColor(color.color); + text.setFillColor(color); text.setOutlineColor(sf::Color::White); text.setOutlineThickness(2.0f); text.setPosition({ static_cast(pos.x - text.getGlobalBounds().size.x / 2), static_cast(pos.y + size / 2) }); @@ -475,7 +475,7 @@ namespace paxg{ sf::Utf<8>::toWide(str.begin(), str.end(), std::back_inserter(wstr)); text.setString(wstr); text.setCharacterSize(size); - text.setFillColor(color.color); + text.setFillColor(color); text.setOutlineColor(sf::Color::White); text.setOutlineThickness(2.0f); // 横方向は中央、縦方向も中央に揃える diff --git a/Library/PAX_GRAPHICA/Interface/CircleImpl.hpp b/Library/PAX_GRAPHICA/Interface/CircleImpl.hpp index 32d6c84e7..f450478d6 100644 --- a/Library/PAX_GRAPHICA/Interface/CircleImpl.hpp +++ b/Library/PAX_GRAPHICA/Interface/CircleImpl.hpp @@ -12,13 +12,11 @@ #ifndef PAX_GRAPHICA_CIRCLE_IMPL_HPP #define PAX_GRAPHICA_CIRCLE_IMPL_HPP +#include #include namespace paxg { - // Forward declarations - struct Color; - /// @brief Abstract base class for Circle implementation (Strategy pattern) /// @note Each graphics library provides its own implementation class CircleImpl { diff --git a/Library/PAX_GRAPHICA/Line.hpp b/Library/PAX_GRAPHICA/Line.hpp index b81789dd1..40abc0357 100644 --- a/Library/PAX_GRAPHICA/Line.hpp +++ b/Library/PAX_GRAPHICA/Line.hpp @@ -45,11 +45,11 @@ namespace paxg { : line(static_cast(s.x), static_cast(s.y), static_cast(e.x), static_cast(e.y)) {} void draw(const double thickness, const paxg::Color& color) const { - line.draw(thickness, color.color); + line.draw(thickness, color); } void drawArrow(const double thickness, const paxs::Vector2& arrowSize, const paxg::Color& color) const { - line.drawArrow(thickness, s3d::Vec2(arrowSize.x, arrowSize.y), color.color); + line.drawArrow(thickness, s3d::Vec2(arrowSize.x, arrowSize.y), color); } #elif defined(PAXS_USING_DXLIB) diff --git a/Library/PAX_GRAPHICA/Null/NullCircleImpl.hpp b/Library/PAX_GRAPHICA/Null/NullCircleImpl.hpp index 0379a169b..884b9a4bf 100644 --- a/Library/PAX_GRAPHICA/Null/NullCircleImpl.hpp +++ b/Library/PAX_GRAPHICA/Null/NullCircleImpl.hpp @@ -16,8 +16,6 @@ namespace paxg { - struct Color; - /// @brief Null (no-op) implementation of CircleImpl /// @note Used when no graphics library is available class NullCircleImpl : public CircleImpl { diff --git a/Library/PAX_GRAPHICA/Rect.hpp b/Library/PAX_GRAPHICA/Rect.hpp index 12f4a86ad..48fdcc88f 100644 --- a/Library/PAX_GRAPHICA/Rect.hpp +++ b/Library/PAX_GRAPHICA/Rect.hpp @@ -169,7 +169,7 @@ namespace paxg { #if defined(PAXS_USING_SIV3D) void draw(const paxg::Color& c_) const { - rect.draw(c_.color); + rect.draw(c_); } #elif defined(PAXS_USING_DXLIB) void draw(const paxg::Color& c_) const { @@ -180,7 +180,7 @@ namespace paxg { #elif defined(PAXS_USING_SFML) void draw(const paxg::Color& c_) const { sf::RectangleShape rect2 = rect; - rect2.setFillColor(c_.color); + rect2.setFillColor(c_); Window::window().draw(rect2); } #else @@ -267,7 +267,7 @@ namespace paxg { #if defined(PAXS_USING_SIV3D) void drawAt(const paxg::Color&) const { - // rect.draw(c_.color); + // rect.draw(c_); } #elif defined(PAXS_USING_DXLIB) void drawAt(const paxg::Color& c_) const { @@ -278,7 +278,7 @@ namespace paxg { #elif defined(PAXS_USING_SFML) void drawAt(const paxg::Color& c_) const { sf::RectangleShape rect2 = rect; - rect2.setFillColor(c_.color); + rect2.setFillColor(c_); Window::window().draw(rect2); } #else @@ -287,7 +287,7 @@ namespace paxg { #if defined(PAXS_USING_SIV3D) void drawFrame(const double inner_thickness, const double outer_thickness, const paxg::Color& color_) const { - rect.drawFrame(inner_thickness, outer_thickness, color_.color); + rect.drawFrame(inner_thickness, outer_thickness, color_); } #elif defined(PAXS_USING_DXLIB) @@ -316,25 +316,25 @@ namespace paxg { sf::RectangleShape rect1(sf::Vector2f( rect.getSize().x + static_cast(outer_thickness * 2), static_cast(outer_thickness + inner_thickness))); rect1.setPosition({ rect.getPosition().x - static_cast(outer_thickness), rect.getPosition().y - static_cast(outer_thickness) }); - rect1.setFillColor(c_.color); + rect1.setFillColor(c_); Window::window().draw(rect1); sf::RectangleShape rect2(sf::Vector2f( rect.getSize().x + static_cast(outer_thickness * 2), static_cast(outer_thickness + inner_thickness))); rect2.setPosition({ rect.getPosition().x - static_cast(outer_thickness), rect.getPosition().y + rect.getSize().y - static_cast(inner_thickness) }); - rect2.setFillColor(c_.color); + rect2.setFillColor(c_); Window::window().draw(rect2); sf::RectangleShape rect3(sf::Vector2f( static_cast(outer_thickness + inner_thickness), static_cast(rect.getSize().y + outer_thickness * 2))); rect3.setPosition({ static_cast(rect.getPosition().x - outer_thickness), static_cast(rect.getPosition().y - outer_thickness) }); - rect3.setFillColor(c_.color); + rect3.setFillColor(c_); Window::window().draw(rect3); sf::RectangleShape rect4(sf::Vector2f( static_cast(outer_thickness + inner_thickness), static_cast(rect.getSize().y + outer_thickness * 2))); rect4.setPosition({ static_cast(rect.getPosition().x + rect.getSize().x - inner_thickness), static_cast(rect.getPosition().y - outer_thickness) }); - rect4.setFillColor(c_.color); + rect4.setFillColor(c_); Window::window().draw(rect4); } diff --git a/Library/PAX_GRAPHICA/RenderTexture.hpp b/Library/PAX_GRAPHICA/RenderTexture.hpp index d4d5cdf82..3d048faa5 100644 --- a/Library/PAX_GRAPHICA/RenderTexture.hpp +++ b/Library/PAX_GRAPHICA/RenderTexture.hpp @@ -14,7 +14,7 @@ #include -#include +#include #include #if defined(PAXS_USING_SIV3D) diff --git a/Library/PAX_GRAPHICA/RoundRect.hpp b/Library/PAX_GRAPHICA/RoundRect.hpp index 8cae474c5..060654c90 100644 --- a/Library/PAX_GRAPHICA/RoundRect.hpp +++ b/Library/PAX_GRAPHICA/RoundRect.hpp @@ -263,7 +263,7 @@ namespace paxg { #if defined(PAXS_USING_SIV3D) void draw(const paxg::Color& c_) const { - rect.draw(c_.color); + rect.draw(c_); } #elif defined(PAXS_USING_DXLIB) void draw(const paxg::Color& c_) const { @@ -275,7 +275,7 @@ namespace paxg { void draw(const paxg::Color& c_) const { drawInternal(static_cast(x0), static_cast(y0), static_cast(w0), static_cast(h0), - static_cast(r0), c_.color); + static_cast(r0), c_); } #else void draw(const paxg::Color&) const {} @@ -370,7 +370,7 @@ namespace paxg { #if defined(PAXS_USING_SIV3D) void drawAt(const paxg::Color&) const { - // rect.draw(c_.color); // 元のコードでもコメントアウトされていた + // rect.draw(c_); // 元のコードでもコメントアウトされていた } #elif defined(PAXS_USING_DXLIB) void drawAt(const paxg::Color& c_) const { @@ -384,7 +384,7 @@ namespace paxg { drawInternal(static_cast(x0) - static_cast(w0) / 2.0f, static_cast(y0) - static_cast(h0) / 2.0f, static_cast(w0), static_cast(h0), - static_cast(r0), c_.color); + static_cast(r0), c_); } #else void drawAt(const paxg::Color&) const {} @@ -392,7 +392,7 @@ namespace paxg { #if defined(PAXS_USING_SIV3D) void drawFrame(const double inner_thickness, const double outer_thickness, const paxg::Color& color_) const { - rect.drawFrame(inner_thickness, outer_thickness, color_.color); + rect.drawFrame(inner_thickness, outer_thickness, color_); } #elif defined(PAXS_USING_DXLIB) @@ -425,25 +425,25 @@ namespace paxg { sf::RectangleShape rect1(sf::Vector2f( static_cast(w + outer_thickness * 2), static_cast(outer_thickness + inner_thickness))); rect1.setPosition({ x - static_cast(outer_thickness), y - static_cast(outer_thickness) }); - rect1.setFillColor(c_.color); + rect1.setFillColor(c_); Window::window().draw(rect1); sf::RectangleShape rect2(sf::Vector2f( static_cast(w + outer_thickness * 2), static_cast(outer_thickness + inner_thickness))); rect2.setPosition({ x - static_cast(outer_thickness), y + h - static_cast(inner_thickness) }); - rect2.setFillColor(c_.color); + rect2.setFillColor(c_); Window::window().draw(rect2); sf::RectangleShape rect3(sf::Vector2f( static_cast(outer_thickness + inner_thickness), static_cast(h + outer_thickness * 2))); rect3.setPosition({ x - static_cast(outer_thickness), y - static_cast(outer_thickness) }); - rect3.setFillColor(c_.color); + rect3.setFillColor(c_); Window::window().draw(rect3); sf::RectangleShape rect4(sf::Vector2f( static_cast(outer_thickness + inner_thickness), static_cast(h + outer_thickness * 2))); rect4.setPosition({ x + static_cast(w - inner_thickness), y - static_cast(outer_thickness) }); - rect4.setFillColor(c_.color); + rect4.setFillColor(c_); Window::window().draw(rect4); } #else diff --git a/Library/PAX_GRAPHICA/SFML/SFMLCircleImpl.hpp b/Library/PAX_GRAPHICA/SFML/SFMLCircleImpl.hpp index 5f81bc5d0..e07680198 100644 --- a/Library/PAX_GRAPHICA/SFML/SFMLCircleImpl.hpp +++ b/Library/PAX_GRAPHICA/SFML/SFMLCircleImpl.hpp @@ -22,8 +22,6 @@ namespace paxg { - struct Color; - #ifdef PAXS_USING_SFML /// @brief SFML implementation of CircleImpl @@ -51,7 +49,7 @@ namespace paxg { void draw(const Color& color) const override { circleShape.setRadius(r); circleShape.setPosition({x, y}); - circleShape.setFillColor(color.color); + circleShape.setFillColor(color); Window::window().draw(circleShape); } diff --git a/Library/PAX_GRAPHICA/SFML/SFMLWindowImpl.hpp b/Library/PAX_GRAPHICA/SFML/SFMLWindowImpl.hpp index 0f40fd5e3..cc642f819 100644 --- a/Library/PAX_GRAPHICA/SFML/SFMLWindowImpl.hpp +++ b/Library/PAX_GRAPHICA/SFML/SFMLWindowImpl.hpp @@ -68,7 +68,7 @@ namespace paxg { bool upd = paxg::SFML_Event::getInstance()->update(m_window); if (upd) { // ウィンドウが開いている場合のみクリア - m_window.clear(backgroundColor.color); + m_window.clear(backgroundColor); } return upd; } @@ -184,7 +184,7 @@ namespace paxg { } void clear() override { - m_window.clear(backgroundColor.color); + m_window.clear(backgroundColor); } void display() override { diff --git a/Library/PAX_GRAPHICA/ScopedRenderTarget.hpp b/Library/PAX_GRAPHICA/ScopedRenderTarget.hpp index 28c9e5f56..33e4480c4 100644 --- a/Library/PAX_GRAPHICA/ScopedRenderTarget.hpp +++ b/Library/PAX_GRAPHICA/ScopedRenderTarget.hpp @@ -17,7 +17,7 @@ #include #endif -#include +#include #include namespace paxg { diff --git a/Library/PAX_GRAPHICA/Siv3D/Siv3DCircleImpl.hpp b/Library/PAX_GRAPHICA/Siv3D/Siv3DCircleImpl.hpp index f8c04d614..c707bc58d 100644 --- a/Library/PAX_GRAPHICA/Siv3D/Siv3DCircleImpl.hpp +++ b/Library/PAX_GRAPHICA/Siv3D/Siv3DCircleImpl.hpp @@ -20,8 +20,6 @@ namespace paxg { - struct Color; - #ifdef PAXS_USING_SIV3D /// @brief Siv3D implementation of CircleImpl @@ -45,7 +43,7 @@ namespace paxg { /// @brief Draw the circle with specified color /// @param color The color to draw the circle void draw(const Color& color) const override { - circle.draw(color.color); + circle.draw(color); } /// @brief Get the position of the circle center diff --git a/Library/PAX_GRAPHICA/Siv3D/Siv3DWindowImpl.hpp b/Library/PAX_GRAPHICA/Siv3D/Siv3DWindowImpl.hpp index 45cf63ab0..8ad1f87f6 100644 --- a/Library/PAX_GRAPHICA/Siv3D/Siv3DWindowImpl.hpp +++ b/Library/PAX_GRAPHICA/Siv3D/Siv3DWindowImpl.hpp @@ -73,11 +73,11 @@ namespace paxg { } void setBackgroundColor(const Color color) override { - s3d::Scene::SetBackground(color.color); + s3d::Scene::SetBackground(color); } void setLetterbox(const Color color) override { - s3d::Scene::SetLetterbox(color.color); + s3d::Scene::SetLetterbox(color); } void setResizable(bool resizable) override { diff --git a/Library/PAX_GRAPHICA/Spline2D.hpp b/Library/PAX_GRAPHICA/Spline2D.hpp index 6a3a5c24a..01277b2b9 100644 --- a/Library/PAX_GRAPHICA/Spline2D.hpp +++ b/Library/PAX_GRAPHICA/Spline2D.hpp @@ -190,7 +190,7 @@ namespace paxg { void draw(double thickness, const paxg::Color& color) const { #ifdef PAXS_USING_SIV3D - spline.draw(thickness, s3d::ColorF(color.color)); + spline.draw(thickness, s3d::ColorF(color)); #else if (points_.size() < 2) return; diff --git a/Library/PAX_GRAPHICA/ToggleButton.hpp b/Library/PAX_GRAPHICA/ToggleButton.hpp index f0f63d077..d0ad12155 100644 --- a/Library/PAX_GRAPHICA/ToggleButton.hpp +++ b/Library/PAX_GRAPHICA/ToggleButton.hpp @@ -156,13 +156,13 @@ namespace paxg { #if defined(PAXS_USING_SIV3D) // Left circle - s3d::Circle(x_ + radius, y_ + radius, radius).draw(bg_color.color); + s3d::Circle(x_ + radius, y_ + radius, radius).draw(bg_color); // Center rectangle - s3d::Rect(x_ + radius, y_, width_ - height_, height_).draw(bg_color.color); + s3d::Rect(x_ + radius, y_, width_ - height_, height_).draw(bg_color); // Right circle - s3d::Circle(x_ + width_ - radius, y_ + radius, radius).draw(bg_color.color); + s3d::Circle(x_ + width_ - radius, y_ + radius, radius).draw(bg_color); // Knob const float knob_radius = height_ * 0.4f; @@ -173,7 +173,7 @@ namespace paxg { s3d::Circle(knob_x + 2, knob_y + 2, knob_radius).draw(s3d::ColorF(0, 0, 0, 0.2)); // Knob circle - s3d::Circle(knob_x, knob_y, knob_radius).draw(color_knob_.color); + s3d::Circle(knob_x, knob_y, knob_radius).draw(color_knob_); #elif defined(PAXS_USING_DXLIB) // Get RGB values from bg_color for DxLib @@ -275,20 +275,20 @@ namespace paxg { sf::CircleShape left_circle(radius); left_circle.setOrigin(sf::Vector2f(radius, radius)); left_circle.setPosition(sf::Vector2f(x_ + radius, y_ + radius)); - left_circle.setFillColor(bg_color.color); + left_circle.setFillColor(bg_color); paxg::Window::window().draw(left_circle); // Center rectangle sf::RectangleShape center_rect(sf::Vector2f(width_ - height_, height_)); center_rect.setPosition(sf::Vector2f(x_ + radius, y_)); - center_rect.setFillColor(bg_color.color); + center_rect.setFillColor(bg_color); paxg::Window::window().draw(center_rect); // Right circle sf::CircleShape right_circle(radius); right_circle.setOrigin(sf::Vector2f(radius, radius)); right_circle.setPosition(sf::Vector2f(x_ + width_ - radius, y_ + radius)); - right_circle.setFillColor(bg_color.color); + right_circle.setFillColor(bg_color); paxg::Window::window().draw(right_circle); // Knob @@ -307,7 +307,7 @@ namespace paxg { sf::CircleShape knob(knob_radius); knob.setOrigin(sf::Vector2f(knob_radius, knob_radius)); knob.setPosition(sf::Vector2f(knob_x, knob_y)); - knob.setFillColor(color_knob_.color); + knob.setFillColor(color_knob_); paxg::Window::window().draw(knob); #else (void)radius; diff --git a/Library/PAX_GRAPHICA/Triangle.hpp b/Library/PAX_GRAPHICA/Triangle.hpp index f69f0211f..eea614081 100644 --- a/Library/PAX_GRAPHICA/Triangle.hpp +++ b/Library/PAX_GRAPHICA/Triangle.hpp @@ -129,8 +129,8 @@ namespace paxg { #if defined(PAXS_USING_SIV3D) const float siv3dSides = circumRadiusToSiv3dSides(radius_); s3d::Triangle{ { center_x_, center_y_ }, siv3dSides, rotation_ } - .draw(s3d::ColorF{ color.color }); - s3d::Triangle{ center_x_, center_y_, radius_, rotation_ }.draw(s3d::ColorF{ color.color }); + .draw(s3d::ColorF{ color }); + s3d::Triangle{ center_x_, center_y_, radius_, rotation_ }.draw(s3d::ColorF{ color }); #elif defined(PAXS_USING_SFML) sf::ConvexShape triangle; @@ -161,7 +161,7 @@ namespace paxg { )); } - triangle.setFillColor(color.color); + triangle.setFillColor(color); paxg::Window::window().draw(triangle); #elif defined(PAXS_USING_DXLIB) diff --git a/Library/PAX_GRAPHICA/Window.hpp b/Library/PAX_GRAPHICA/Window.hpp index 5770575cf..d55a83107 100644 --- a/Library/PAX_GRAPHICA/Window.hpp +++ b/Library/PAX_GRAPHICA/Window.hpp @@ -15,8 +15,6 @@ #include #include -#include - #if defined(PAXS_USING_SIV3D) #include #elif defined(PAXS_USING_DXLIB) @@ -29,6 +27,8 @@ #include +#include + namespace paxg { /// @brief Singleton window manager with strategy pattern for multi-library support diff --git a/Library/PAX_MAHOROBA/Rendering/ShadowRenderer.hpp b/Library/PAX_MAHOROBA/Rendering/ShadowRenderer.hpp index d887dcdca..c208bedea 100644 --- a/Library/PAX_MAHOROBA/Rendering/ShadowRenderer.hpp +++ b/Library/PAX_MAHOROBA/Rendering/ShadowRenderer.hpp @@ -14,7 +14,7 @@ #include -#include +#include #include #include #include diff --git a/Projects/IncludeTest/source/PAX_GRAPHICA/ColorFIncludeTest.cpp b/Projects/IncludeTest/source/PAX_GRAPHICA/ColorFIncludeTest.cpp deleted file mode 100644 index 061e5fdef..000000000 --- a/Projects/IncludeTest/source/PAX_GRAPHICA/ColorFIncludeTest.cpp +++ /dev/null @@ -1,3 +0,0 @@ -#include - -int main(){} From d195723aed53d23532dd30b938b868559d87d3db Mon Sep 17 00:00:00 2001 From: guinpen98 <83969826+guinpen98@users.noreply.github.com> Date: Thu, 4 Dec 2025 01:40:37 +0900 Subject: [PATCH 5/9] ref: font --- .../PAX_GRAPHICA/DxLib/DxLibCircleImpl.hpp | 11 +- Library/PAX_GRAPHICA/DxLib/DxLibFontImpl.hpp | 180 ++++++ Library/PAX_GRAPHICA/Font.hpp | 586 +++--------------- Library/PAX_GRAPHICA/Interface/FontImpl.hpp | 72 +++ Library/PAX_GRAPHICA/Null/NullFontImpl.hpp | 75 +++ Library/PAX_GRAPHICA/SFML/SFMLCircleImpl.hpp | 13 +- Library/PAX_GRAPHICA/SFML/SFMLFontImpl.hpp | 164 +++++ Library/PAX_GRAPHICA/SFML/SFMLTextureImpl.hpp | 8 +- Library/PAX_GRAPHICA/SFML/SFMLWindowImpl.hpp | 3 +- .../PAX_GRAPHICA/Siv3D/Siv3DCircleImpl.hpp | 11 +- Library/PAX_GRAPHICA/Siv3D/Siv3DFontImpl.hpp | 159 +++++ .../Siv3D/Siv3DGraphics3DModelImpl.hpp | 12 +- .../Siv3D/Siv3DRenderTextureImpl.hpp | 4 +- .../PAX_GRAPHICA/Siv3D/Siv3DTextureImpl.hpp | 3 +- .../DxLib/DxLibFontImplIncludeTest.cpp | 3 + .../Interface/FontImplIncludeTest.cpp | 3 + .../Null/NullFontImplIncludeTest.cpp | 3 + .../SFML/SFMLFontImplIncludeTest.cpp | 3 + .../Siv3D/Siv3DFontImplIncludeTest.cpp | 3 + 19 files changed, 776 insertions(+), 540 deletions(-) create mode 100644 Library/PAX_GRAPHICA/DxLib/DxLibFontImpl.hpp create mode 100644 Library/PAX_GRAPHICA/Interface/FontImpl.hpp create mode 100644 Library/PAX_GRAPHICA/Null/NullFontImpl.hpp create mode 100644 Library/PAX_GRAPHICA/SFML/SFMLFontImpl.hpp create mode 100644 Library/PAX_GRAPHICA/Siv3D/Siv3DFontImpl.hpp create mode 100644 Projects/IncludeTest/source/PAX_GRAPHICA/DxLib/DxLibFontImplIncludeTest.cpp create mode 100644 Projects/IncludeTest/source/PAX_GRAPHICA/Interface/FontImplIncludeTest.cpp create mode 100644 Projects/IncludeTest/source/PAX_GRAPHICA/Null/NullFontImplIncludeTest.cpp create mode 100644 Projects/IncludeTest/source/PAX_GRAPHICA/SFML/SFMLFontImplIncludeTest.cpp create mode 100644 Projects/IncludeTest/source/PAX_GRAPHICA/Siv3D/Siv3DFontImplIncludeTest.cpp diff --git a/Library/PAX_GRAPHICA/DxLib/DxLibCircleImpl.hpp b/Library/PAX_GRAPHICA/DxLib/DxLibCircleImpl.hpp index 5efc95e9f..f148aa89e 100644 --- a/Library/PAX_GRAPHICA/DxLib/DxLibCircleImpl.hpp +++ b/Library/PAX_GRAPHICA/DxLib/DxLibCircleImpl.hpp @@ -12,17 +12,14 @@ #ifndef PAX_GRAPHICA_DXLIB_CIRCLE_IMPL_HPP #define PAX_GRAPHICA_DXLIB_CIRCLE_IMPL_HPP -#include - #ifdef PAXS_USING_DXLIB #include + #include -#endif +#include namespace paxg { -#ifdef PAXS_USING_DXLIB - /// @brief DxLib implementation of CircleImpl class DxLibCircleImpl : public CircleImpl { private: @@ -63,8 +60,8 @@ namespace paxg { } }; -#endif // PAXS_USING_DXLIB - } +#endif // PAXS_USING_DXLIB + #endif // !PAX_GRAPHICA_DXLIB_CIRCLE_IMPL_HPP diff --git a/Library/PAX_GRAPHICA/DxLib/DxLibFontImpl.hpp b/Library/PAX_GRAPHICA/DxLib/DxLibFontImpl.hpp new file mode 100644 index 000000000..282cef8e7 --- /dev/null +++ b/Library/PAX_GRAPHICA/DxLib/DxLibFontImpl.hpp @@ -0,0 +1,180 @@ +/*########################################################################################## + + PAX SAPIENTICA Library 💀🌿🌏 + + [Planning] 2023-2024 As Project + [Production] 2023-2024 As Project + [Contact Us] wanotaitei@gmail.com https://github.com/AsPJT/PAX_SAPIENTICA + [License] Distributed under the CC0 1.0. https://creativecommons.org/publicdomain/zero/1.0/ + +##########################################################################################*/ + +#ifndef PAX_GRAPHICA_DXLIB_FONT_IMPL_HPP +#define PAX_GRAPHICA_DXLIB_FONT_IMPL_HPP + +#ifdef PAXS_USING_DXLIB +#include + +#include + +#include +#include + +#include +#include +#include +#include + +namespace paxg { + + /// @brief DxLib font implementation + /// @brief DxLibフォント実装 + class DxLibFontImpl : public FontImpl { + private: + int font{ -1 }; + int h{ 0 }; + + void drawAlign(int align, paxs::Vector2 pos, std::string str_, const Color& color_, unsigned int edge_color = 0) const { + // align が 0左寄り 1中央寄り 2右寄り + if (align < 0) align = 0; + if (align > 2) align = 2; + std::size_t str_len = str_.size(); // 全体の文字数を得る + int sizex; int sizey; int line_count; // 描画した時のサイズと行数を調べる + DxLib::GetDrawStringSizeToHandle(&sizex, &sizey, &line_count, str_.c_str(), static_cast(str_len), font, FALSE); + const char* last = &(str_[0]) + str_len; // 終端を得る + const char* next; // 次の改行ポイント + int line_space = DxLib::GetFontLineSpaceToHandle(font); // 一行の縦幅を得る + int str_width; // 一行の横幅 + std::size_t char_count = 0; // 描画した文字数をカウント + for (int i = 0; i < line_count; i++) { // 行数分、繰り返す + next = DxLib::strstrDx(str_.c_str(), "\n"); // 次の改行ポイントを探す + if (next == NULL) next = last; // 改行が見つからない場合は最終行ということなので終端を代入 + str_len = next - &(str_[0]); // この行の文字数を得る + str_width = DxLib::GetDrawNStringWidthToHandle(str_.c_str(), str_len, font, FALSE); // この行の横幅を得る + char_count += str_len; // この行の文字数を足す + // x座標を調整して一行分描画する + DxLib::DrawNStringToHandle(pos.x + ((align * (sizex - str_width)) / 2), pos.y, + str_.c_str(), str_len, DxLib::GetColor(color_.r, color_.g, color_.b), font, edge_color, FALSE); + char_count += 1; // 改行文字の分 + str_ = std::string(next + 1); // 次の行の先頭にする(+1は改行文字の分) + pos.y += line_space; // y座標をずらす + } + } + + public: + DxLibFontImpl(int size, const std::string& path, int buffer_thickness) { + // 文字コードをUTF-8に統一 + DxLib::SetUseCharCodeFormat(DX_CHARCODEFORMAT_UTF8); + + if (path.empty()) { + // デフォルトフォントを使用 + font = DxLib::CreateFontToHandle(NULL, size, -1, + (buffer_thickness <= 0) ? DX_FONTTYPE_NORMAL : +#ifdef PAXS_PLATFORM_ANDROID + DX_FONTTYPE_EDGE +#else + DX_FONTTYPE_ANTIALIASING_8X8 +#endif + ); + } else { + // 外部フォントファイルを使用 + const std::string full_path = paxs::AppConfig::getInstance().getRootPath() + path; + int font_data_handle = DxLib::LoadFontDataToHandle(full_path.c_str(), buffer_thickness); + + if (font_data_handle == -1) { + PAXS_WARNING("Failed to load font data: " + full_path); + // フォールバック: デフォルトフォント + font = DxLib::CreateFontToHandle(NULL, size, -1, + (buffer_thickness <= 0) ? DX_FONTTYPE_NORMAL : DX_FONTTYPE_ANTIALIASING_8X8); + } else { + font = DxLib::CreateFontToHandle(NULL, size, -1, + (buffer_thickness <= 0) ? DX_FONTTYPE_NORMAL : DX_FONTTYPE_ANTIALIASING_8X8, + -1, -1, FALSE, font_data_handle); + } + } + + // フォント間隔を0に明示(他のライブラリと同じ挙動にする) + if (font != -1) { + DxLib::SetFontSpaceToHandle(font, 0); + } + + h = size; + } + + void setOutline(double /*inner*/, double /*outer*/, const Color& /*color*/) override { + // DxLib doesn't support outline in this implementation + } + + void drawBottomLeft(const std::string& str, const paxs::Vector2& pos, const Color& color) const override { + if (font == -1) DxLib::DrawFormatString(pos.x, pos.y - 10, DxLib::GetColor(color.r, color.g, color.b), str.c_str()); + else DxLib::DrawStringToHandle(pos.x, pos.y - 10, str.c_str(), DxLib::GetColor(color.r, color.g, color.b), font, 0xffffffff); + } + + void drawTopRight(const std::string& str, const paxs::Vector2& pos, const Color& color) const override { + if (font == -1) DxLib::DrawFormatString(pos.x, pos.y + 10, DxLib::GetColor(color.r, color.g, color.b), str.c_str()); + else { + int size_x = 0, size_y = 0, line_count = 0; + DxLib::GetDrawStringSizeToHandle(&size_x, &size_y, &line_count, str.c_str(), static_cast(str.size()), font, FALSE); + DxLib::DrawStringToHandle(pos.x - size_x, pos.y + size_y / 2, str.c_str(), DxLib::GetColor(color.r, color.g, color.b), font, 0xffffffff); + } + } + + void drawBottomRight(const std::string& str, const paxs::Vector2& pos, const Color& color) const override { + if (font == -1) DxLib::DrawFormatString(pos.x, pos.y - 10, DxLib::GetColor(color.r, color.g, color.b), str.c_str()); + else { + int size_x = 0, size_y = 0, line_count = 0; + DxLib::GetDrawStringSizeToHandle(&size_x, &size_y, &line_count, str.c_str(), static_cast(str.size()), font, FALSE); + DxLib::DrawStringToHandle(pos.x - size_x, pos.y - size_y, str.c_str(), DxLib::GetColor(color.r, color.g, color.b), font, 0xffffffff); + } + } + + void draw(const std::string& str, const paxs::Vector2& pos, const Color& color) const override { + if (font == -1) DxLib::DrawFormatString(pos.x, pos.y, DxLib::GetColor(color.r, color.g, color.b), str.c_str()); + else DxLib::DrawStringToHandle(pos.x, pos.y, str.c_str(), DxLib::GetColor(color.r, color.g, color.b), font, 0xffffffff); + } + + void drawBottomCenter(const std::string& str, const paxs::Vector2& pos, const Color& color) const override { + if (font == -1) DxLib::DrawFormatString(pos.x, pos.y - 10, DxLib::GetColor(color.r, color.g, color.b), str.c_str()); + else { + int size_x = 0, size_y = 0, line_count = 0; + DxLib::GetDrawStringSizeToHandle(&size_x, &size_y, &line_count, str.c_str(), static_cast(str.size()), font, FALSE); + DxLib::DrawStringToHandle(pos.x - size_x / 2, pos.y - size_y / 2, str.c_str(), DxLib::GetColor(color.r, color.g, color.b), font, 0xffffffff); + } + } + + void drawTopCenter(const std::string& str, const paxs::Vector2& pos, const Color& color) const override { + if (font == -1) DxLib::DrawFormatString(pos.x, pos.y + 10, DxLib::GetColor(color.r, color.g, color.b), str.c_str()); + else { + int size_x = 0, size_y = 0, line_count = 0; + DxLib::GetDrawStringSizeToHandle(&size_x, &size_y, &line_count, str.c_str(), static_cast(str.size()), font, FALSE); + DxLib::DrawStringToHandle(pos.x - size_x / 2, pos.y + size_y / 2, str.c_str(), DxLib::GetColor(color.r, color.g, color.b), font, 0xffffffff); + } + } + + void drawAt(const std::string& str, const paxs::Vector2& pos, const Color& color) const override { + if (font == -1) DxLib::DrawFormatString(pos.x, pos.y, DxLib::GetColor(color.r, color.g, color.b), str.c_str()); + else { + int size_x = 0, size_y = 0, line_count = 0; + DxLib::GetDrawStringSizeToHandle(&size_x, &size_y, &line_count, str.c_str(), static_cast(str.size()), font, FALSE); + DxLib::DrawStringToHandle(pos.x - size_x / 2, pos.y - size_y / 2, str.c_str(), DxLib::GetColor(color.r, color.g, color.b), font, 0xffffffff); + } + } + + int height() const override { + if (font == -1) return h; + return DxLib::GetFontLineSpaceToHandle(font); + } + + int width(const std::string& str) override { + if (font == -1) return static_cast(static_cast(str.size()) * h * 0.5); + int w = 0, h_temp = 0; + DxLib::GetDrawStringSizeToHandle(&w, &h_temp, NULL, str.c_str(), static_cast(str.size()), font, FALSE); + return w; + } + }; + +} // namespace paxg + +#endif // PAXS_USING_DXLIB + +#endif // !PAX_GRAPHICA_DXLIB_FONT_IMPL_HPP diff --git a/Library/PAX_GRAPHICA/Font.hpp b/Library/PAX_GRAPHICA/Font.hpp index bcb6b58a7..32dc88138 100644 --- a/Library/PAX_GRAPHICA/Font.hpp +++ b/Library/PAX_GRAPHICA/Font.hpp @@ -12,565 +12,143 @@ #ifndef PAX_GRAPHICA_FONT_HPP #define PAX_GRAPHICA_FONT_HPP +#include #include +#include +#include +#include + +// Include platform-specific implementations #if defined(PAXS_USING_SIV3D) -#include + #include #elif defined(PAXS_USING_DXLIB) -#include + #include #elif defined(PAXS_USING_SFML) -#include -#include + #include +#else + #include #endif -#include -#include +namespace paxg { -#include -#include -#include -#include - -namespace paxg{ + /// @brief Font wrapper using Pimpl idiom + /// @brief Pimplイディオムを使用したフォントラッパー struct Font { - constexpr Font() = default; -#if defined(PAXS_USING_SIV3D) - s3d::Font font{}; - Font(const int size_, const std::string& path, const int buffer_thickness) { - font = (path.size() == 0) ? - s3d::Font(s3d::FontMethod::SDF, size_) : - s3d::Font(s3d::FontMethod::SDF, size_, s3d::Unicode::FromUTF8(paxs::AppConfig::getInstance().getRootPath() + path)); - font.setBufferThickness(buffer_thickness); - } - bool is_outline = false; - s3d::TextStyle outline{}; - void setOutline(const double inner, const double outer, const paxg::Color& color) { - is_outline = true; - outline = s3d::TextStyle::Outline(inner, outer, color); - } + private: + std::shared_ptr impl; - /// @brief テキストを左下揃えで描画 (横:左端, 縦:下端) - /// @brief Draw text with bottom-left alignment (horizontal: left, vertical: bottom) - void drawBottomLeft(const std::string& str, const paxs::Vector2& pos, const paxg::Color& color) const { - if (is_outline) { - font(s3d::Unicode::FromUTF8(str)).draw( - outline, - s3d::Arg::bottomLeft = s3d::Vec2(pos.x, pos.y), - color); - } - else { - font(s3d::Unicode::FromUTF8(str)).draw( - s3d::Arg::bottomLeft = s3d::Vec2(pos.x, pos.y), - color); - } - } - /// @brief テキストを右上揃えで描画 (横:右端, 縦:上端) - /// @brief Draw text with top-right alignment (horizontal: right, vertical: top) - void drawTopRight(const std::string& str, const paxs::Vector2& pos, const paxg::Color& color) const { - if (is_outline) { - font(s3d::Unicode::FromUTF8(str)).draw( - outline, - s3d::Arg::topRight = s3d::Vec2(pos.x, pos.y), - color); - } - else { - font(s3d::Unicode::FromUTF8(str)).draw( - s3d::Arg::topRight = s3d::Vec2(pos.x, pos.y), - color); - } - } - /// @brief テキストを右下揃えで描画 (横:右端, 縦:下端) - /// @brief Draw text with bottom-right alignment (horizontal: right, vertical: bottom) - void drawBottomRight(const std::string& str, const paxs::Vector2& pos, const paxg::Color& color) const { - if (is_outline) { - font(s3d::Unicode::FromUTF8(str)).draw( - outline, - s3d::Arg::bottomRight = s3d::Vec2(pos.x, pos.y), - color); - } - else { - font(s3d::Unicode::FromUTF8(str)).draw( - s3d::Arg::bottomRight = s3d::Vec2(pos.x, pos.y), - color); - } - } - /// @brief テキストを左上揃えで描画 (横:左端, 縦:上端) - /// @brief Draw text with top-left alignment (horizontal: left, vertical: top) - void draw(const std::string& str, const paxs::Vector2& pos, const paxg::Color& color) const { - if (is_outline) { - font(s3d::Unicode::FromUTF8(str)).draw( - outline, - s3d::Vec2(pos.x, pos.y), - color); - } - else { - font(s3d::Unicode::FromUTF8(str)).draw( - s3d::Vec2(pos.x, pos.y), - color); - } - } - /// @brief テキストを中央下揃えで描画 (横:中央, 縦:下端) - /// @brief Draw text with bottom-center alignment (horizontal: center, vertical: bottom) - void drawBottomCenter(const std::string& str, const paxs::Vector2& pos, const paxg::Color& color) const { - if (is_outline) { - font(s3d::Unicode::FromUTF8(str)).draw( - outline, - s3d::Arg::bottomCenter = s3d::Vec2(pos.x, pos.y), - color); - } - else { - font(s3d::Unicode::FromUTF8(str)).draw( - s3d::Arg::bottomCenter = s3d::Vec2(pos.x, pos.y), - color); - } - } - /// @brief テキストを中央上揃えで描画 (横:中央, 縦:上端) - /// @brief Draw text with top-center alignment (horizontal: center, vertical: top) - void drawTopCenter(const std::string& str, const paxs::Vector2& pos, const paxg::Color& color) const { - if (is_outline) { - font(s3d::Unicode::FromUTF8(str)).draw( - outline, - s3d::Arg::topCenter = s3d::Vec2(pos.x, pos.y), - color); - } - else { - font(s3d::Unicode::FromUTF8(str)).draw( - s3d::Arg::topCenter = s3d::Vec2(pos.x, pos.y), - color); - } - } - /// @brief テキストを中央揃えで描画 (横:中央, 縦:中央) - /// @brief Draw text with center alignment (horizontal: center, vertical: center) - void drawAt(const std::string& str, const paxs::Vector2& pos, const paxg::Color& color) const { - if (is_outline) { - font(s3d::Unicode::FromUTF8(str)).drawAt( - outline, - s3d::Vec2(pos.x, pos.y), - color); - } - else { - font(s3d::Unicode::FromUTF8(str)).drawAt( - s3d::Vec2(pos.x, pos.y), - color); - } - } - - void drawBottomLeft(const std::string& str, const paxs::Vector2& pos, const paxg::Color& color) const { - drawBottomLeft(str, paxs::Vector2{pos}, color); - } - void drawTopRight(const std::string& str, const paxs::Vector2& pos, const paxg::Color& color) const { - drawTopRight(str, paxs::Vector2{pos}, color); - } - void drawBottomRight(const std::string& str, const paxs::Vector2& pos, const paxg::Color& color) const { - drawBottomRight(str, paxs::Vector2{pos}, color); - } - void draw(const std::string& str, const paxs::Vector2& pos, const paxg::Color& color) const { - draw(str, paxs::Vector2{pos}, color); - } - void drawBottomCenter(const std::string& str, const paxs::Vector2& pos, const paxg::Color& color) const { - drawBottomCenter(str, paxs::Vector2{pos}, color); - } - void drawTopCenter(const std::string& str, const paxs::Vector2& pos, const paxg::Color& color) const { - drawTopCenter(str, paxs::Vector2{pos}, color); - } - void drawAt(const std::string& str, const paxs::Vector2& pos, const paxg::Color& color) const { - drawAt(str, paxs::Vector2{pos}, color); - } - - int height() const { - return font.height(); - } - int width(const std::string& str_) { - return static_cast(font(s3d::Unicode::FromUTF8(str_)).region().w); - } + public: + constexpr Font() = default; + /// @brief Construct a font + /// @brief フォントを構築 + /// @param size_ Font size + /// @param path Font file path (empty for default font) + /// @param buffer_thickness Buffer thickness for rendering + Font(int size_, const std::string& path = "", int buffer_thickness = 0) { +#if defined(PAXS_USING_SIV3D) + impl = std::make_shared(size_, path, buffer_thickness); #elif defined(PAXS_USING_DXLIB) - int font{ -1 }; int h{ 0 }; - Font(const int size_, const std::string& path, const int buffer_thickness) { - // 文字コードをUTF-8に統一 - DxLib::SetUseCharCodeFormat(DX_CHARCODEFORMAT_UTF8); - - if (path.size() == 0) { - // デフォルトフォントを使用 - font = DxLib::CreateFontToHandle(NULL, size_, -1, - (buffer_thickness <= 0) ? DX_FONTTYPE_NORMAL : -#ifdef PAXS_PLATFORM_ANDROID - DX_FONTTYPE_EDGE + impl = std::make_shared(size_, path, buffer_thickness); +#elif defined(PAXS_USING_SFML) + impl = std::make_shared(size_, path, buffer_thickness); #else - DX_FONTTYPE_ANTIALIASING_8X8 + impl = std::make_shared(size_, path, buffer_thickness); #endif - ); - } else { - // 外部フォントファイルを使用 - const std::string full_path = paxs::AppConfig::getInstance().getRootPath() + path; - int font_data_handle = DxLib::LoadFontDataToHandle(full_path.c_str(), buffer_thickness); - - if (font_data_handle == -1) { - PAXS_WARNING("Failed to load font data: " + full_path); - // フォールバック: デフォルトフォント - font = DxLib::CreateFontToHandle(NULL, size_, -1, - (buffer_thickness <= 0) ? DX_FONTTYPE_NORMAL : DX_FONTTYPE_ANTIALIASING_8X8); - } else { - font = DxLib::CreateFontToHandle(NULL, size_, -1, - (buffer_thickness <= 0) ? DX_FONTTYPE_NORMAL : DX_FONTTYPE_ANTIALIASING_8X8, - -1, -1, FALSE, font_data_handle); - } - } - - // フォント間隔を0に明示(他のライブラリと同じ挙動にする) - if (font != -1) { - DxLib::SetFontSpaceToHandle(font, 0); - } - - h = size_; - } - void setOutline(const double inner, const double outer, const paxg::Color& color) const { - } - void drawAlign(int align, paxs::Vector2 pos, std::string str_, const paxg::Color& color_, unsigned int edge_color = 0) const { - // std::size_t string_length; - // align が 0左寄り 1中央寄り 2右寄り - if (align < 0) align = 0; - if (align > 2) align = 2; - std::size_t str_len = str_.size(); // 全体の文字数を得る - int sizex; int sizey; int line_count; // 描画した時のサイズと行数を調べる - DxLib::GetDrawStringSizeToHandle(&sizex, &sizey, &line_count, str_.c_str(), static_cast(str_len), font, FALSE); - const char* last = &(str_[0]) + str_len; // 終端を得る - const char* next; // 次の改行ポイント - int line_space = DxLib::GetFontLineSpaceToHandle(font); // 一行の縦幅を得る - int str_width; // 一行の横幅 - std::size_t char_count = 0; // 描画した文字数をカウント - for (int i = 0; i < line_count; i++) { // 行数分、繰り返す - next = DxLib::strstrDx(str_.c_str(), "\n"); // 次の改行ポイントを探す - if (next == NULL) next = last; // 改行が見つからない場合は最終行ということなので終端を代入 - str_len = next - &(str_[0]); // この行の文字数を得る - str_width = DxLib::GetDrawNStringWidthToHandle(str_.c_str(), str_len, font, FALSE); // この行の横幅を得る - // if (char_count < string_length) { // 描画した文字数がまだ指定範囲を超えていない場合 - char_count += str_len; // この行の文字数を足す - // if (char_count > string_length) { // この行の中に指定した終端がある場合 - // str_len -= (char_count - string_length); // 差分を引いて文字数を調整 - // } - // x座標を調整して一行分描画する - DxLib::DrawNStringToHandle(pos.x + ((align * (sizex - str_width)) / 2), pos.y, - str_.c_str(), str_len, DxLib::GetColor(color_.r, color_.g, color_.b), font, edge_color, FALSE); - // } - char_count += 1; // 改行文字の分 - str_ = std::string(next + 1); // 次の行の先頭にする(+1は改行文字の分) - pos.y += line_space; // y座標をずらす - } + /// @brief Set outline effect + /// @brief アウトライン効果を設定 + void setOutline(double inner, double outer, const Color& color) { + if (impl) impl->setOutline(inner, outer, color); } - /// @brief テキストを左下揃えで描画 (横:左端, 縦:下端) /// @brief Draw text with bottom-left alignment (horizontal: left, vertical: bottom) - void drawBottomLeft(const std::string& str, const paxs::Vector2& pos, const paxg::Color& color) const { - if (font == -1) DxLib::DrawFormatString(pos.x, pos.y - 10, DxLib::GetColor(color.r, color.g, color.b), str.c_str()); - else DxLib::DrawStringToHandle(pos.x, pos.y - 10, str.c_str(), DxLib::GetColor(color.r, color.g, color.b), font, 0xffffffff); - } - /// @brief テキストを右上揃えで描画 (横:右端, 縦:上端) - /// @brief Draw text with top-right alignment (horizontal: right, vertical: top) - void drawTopRight(const std::string& str, const paxs::Vector2& pos, const paxg::Color& color) const { - if (font == -1) DxLib::DrawFormatString(pos.x, pos.y + 10, DxLib::GetColor(color.r, color.g, color.b), str.c_str()); - else { - int size_x = 0, size_y = 0, line_count = 0; // 描画した時のサイズと行数を調べる - DxLib::GetDrawStringSizeToHandle(&size_x, &size_y, &line_count, str.c_str(), static_cast(str.size()), font, FALSE); - DxLib::DrawStringToHandle(pos.x - size_x, pos.y + size_y / 2, str.c_str(), DxLib::GetColor(color.r, color.g, color.b), font, 0xffffffff); - } - } - /// @brief テキストを右下揃えで描画 (横:右端, 縦:下端) - /// @brief Draw text with bottom-right alignment (horizontal: right, vertical: bottom) - void drawBottomRight(const std::string& str, const paxs::Vector2& pos, const paxg::Color& color) const { - if (font == -1) DxLib::DrawFormatString(pos.x, pos.y - 10, DxLib::GetColor(color.r, color.g, color.b), str.c_str()); - else { - int size_x = 0, size_y = 0, line_count = 0; // 描画した時のサイズと行数を調べる - DxLib::GetDrawStringSizeToHandle(&size_x, &size_y, &line_count, str.c_str(), static_cast(str.size()), font, FALSE); - // 文字の底部がpos.yに来るように配置 - DxLib::DrawStringToHandle(pos.x - size_x, pos.y - size_y, str.c_str(), DxLib::GetColor(color.r, color.g, color.b), font, 0xffffffff); - } - } - /// @brief テキストを左上揃えで描画 (横:左端, 縦:上端) - /// @brief Draw text with top-left alignment (horizontal: left, vertical: top) - void draw(const std::string& str, const paxs::Vector2& pos, const paxg::Color& color) const { - if (font == -1) DxLib::DrawFormatString(pos.x, pos.y, DxLib::GetColor(color.r, color.g, color.b), str.c_str()); - else DxLib::DrawStringToHandle(pos.x, pos.y, str.c_str(), DxLib::GetColor(color.r, color.g, color.b), font, 0xffffffff); - } - /// @brief テキストを中央下揃えで描画 (横:中央, 縦:下端) - /// @brief Draw text with bottom-center alignment (horizontal: center, vertical: bottom) - void drawBottomCenter(const std::string& str, const paxs::Vector2& pos, const paxg::Color& color) const { - if (font == -1) DxLib::DrawFormatString(pos.x, pos.y - 10, DxLib::GetColor(color.r, color.g, color.b), str.c_str()); - else { - int size_x = 0, size_y = 0, line_count = 0; // 描画した時のサイズと行数を調べる - DxLib::GetDrawStringSizeToHandle(&size_x, &size_y, &line_count, str.c_str(), static_cast(str.size()), font, FALSE); - DxLib::DrawStringToHandle(pos.x - size_x / 2, pos.y - size_y / 2, str.c_str(), DxLib::GetColor(color.r, color.g, color.b), font, 0xffffffff); - } - } - /// @brief テキストを中央上揃えで描画 (横:中央, 縦:上端) - /// @brief Draw text with top-center alignment (horizontal: center, vertical: top) - void drawTopCenter(const std::string& str, const paxs::Vector2& pos, const paxg::Color& color) const { - if (font == -1) DxLib::DrawFormatString(pos.x, pos.y + 10, DxLib::GetColor(color.r, color.g, color.b), str.c_str()); - else { - int size_x = 0, size_y = 0, line_count = 0; // 描画した時のサイズと行数を調べる - DxLib::GetDrawStringSizeToHandle(&size_x, &size_y, &line_count, str.c_str(), static_cast(str.size()), font, FALSE); - DxLib::DrawStringToHandle(pos.x - size_x / 2, pos.y + size_y / 2, str.c_str(), DxLib::GetColor(color.r, color.g, color.b), font, 0xffffffff); - } - } - /// @brief テキストを中央揃えで描画 (横:中央, 縦:中央) - /// @brief Draw text with center alignment (horizontal: center, vertical: center) - void drawAt(const std::string& str, const paxs::Vector2& pos, const paxg::Color& color) const { - if (font == -1) DxLib::DrawFormatString(pos.x, pos.y, DxLib::GetColor(color.r, color.g, color.b), str.c_str()); - else { - int size_x = 0, size_y = 0, line_count = 0; // 描画した時のサイズと行数を調べる - DxLib::GetDrawStringSizeToHandle(&size_x, &size_y, &line_count, str.c_str(), static_cast(str.size()), font, FALSE); - // 横方向は中央、縦方向も中央に揃える - DxLib::DrawStringToHandle(pos.x - size_x / 2, pos.y - size_y / 2, str.c_str(), DxLib::GetColor(color.r, color.g, color.b), font, 0xffffffff); - } + /// @brief テキストを左下揃えで描画 (横:左端, 縦:下端) + void drawBottomLeft(const std::string& str, const paxs::Vector2& pos, const Color& color) const { + if (impl) impl->drawBottomLeft(str, pos, color); } - void drawBottomLeft(const std::string& str, const paxs::Vector2& pos, const paxg::Color& color) const { + void drawBottomLeft(const std::string& str, const paxs::Vector2& pos, const Color& color) const { drawBottomLeft(str, paxs::Vector2{pos}, color); } - void drawTopRight(const std::string& str, const paxs::Vector2& pos, const paxg::Color& color) const { - drawTopRight(str, paxs::Vector2{pos}, color); - } - void drawBottomRight(const std::string& str, const paxs::Vector2& pos, const paxg::Color& color) const { - drawBottomRight(str, paxs::Vector2{pos}, color); - } - void draw(const std::string& str, const paxs::Vector2& pos, const paxg::Color& color) const { - draw(str, paxs::Vector2{pos}, color); - } - void drawBottomCenter(const std::string& str, const paxs::Vector2& pos, const paxg::Color& color) const { - drawBottomCenter(str, paxs::Vector2{pos}, color); - } - void drawTopCenter(const std::string& str, const paxs::Vector2& pos, const paxg::Color& color) const { - drawTopCenter(str, paxs::Vector2{pos}, color); - } - void drawAt(const std::string& str, const paxs::Vector2& pos, const paxg::Color& color) const { - drawAt(str, paxs::Vector2{pos}, color); - } - - int height() const { - if (font == -1) return h; - // DxLibで実際の行高さを取得(他のライブラリと同じ挙動にする) - return DxLib::GetFontLineSpaceToHandle(font); - } - int width(const std::string& str_) { - if (font == -1) return static_cast(static_cast(str_.size()) * h * 0.5); - // DxLibで実際の文字列幅を取得(フォントハンドルを使用) - int w = 0, h_temp = 0; - DxLib::GetDrawStringSizeToHandle(&w, &h_temp, NULL, str_.c_str(), static_cast(str_.size()), font, FALSE); - return w; - } - -#elif defined(PAXS_USING_SFML) - sf::Font font{}; - int size = 0; - Font(const int size_, const std::string& path, const int /*buffer_thickness*/) { - size = size_; - if (path.size() == 0) return; - if (!font.openFromFile(paxs::AppConfig::getInstance().getRootPath() + path)) { - PAXS_WARNING(path + " is missing."); - } - } - - void setOutline(const double /*inner*/, const double /*outer*/, const paxg::Color& /*color*/) { + /// @brief Draw text with top-right alignment (horizontal: right, vertical: top) + /// @brief テキストを右上揃えで描画 (横:右端, 縦:上端) + void drawTopRight(const std::string& str, const paxs::Vector2& pos, const Color& color) const { + if (impl) impl->drawTopRight(str, pos, color); } - /// @brief テキストを左下揃えで描画 (横:左端, 縦:下端) - /// @brief Draw text with bottom-left alignment (horizontal: left, vertical: bottom) - void drawBottomLeft(const std::string& str, const paxs::Vector2& pos, const paxg::Color& color) const { - sf::Text text(font); - std::wstring wstr; - sf::Utf<8>::toWide(str.begin(), str.end(), std::back_inserter(wstr)); - text.setString(wstr); - text.setCharacterSize(size); - text.setFillColor(color); - text.setOutlineColor(sf::Color::White); - text.setOutlineThickness(2.0f); - text.setPosition({ static_cast(pos.x), static_cast(pos.y - size / 2) }); - paxg::Window::window().draw(text); - } - - /// @brief テキストを右上揃えで描画 (横:右端, 縦:上端) - /// @brief Draw text with top-right alignment (horizontal: right, vertical: top) - void drawTopRight(const std::string& str, const paxs::Vector2& pos, const paxg::Color& color) const { - sf::Text text(font); - std::wstring wstr; - sf::Utf<8>::toWide(str.begin(), str.end(), std::back_inserter(wstr)); - text.setString(wstr); - text.setCharacterSize(size); - text.setFillColor(color); - text.setOutlineColor(sf::Color::White); - text.setOutlineThickness(2.0f); - text.setPosition({ static_cast(pos.x - text.getGlobalBounds().size.x), static_cast(pos.y + size / 2) }); - paxg::Window::window().draw(text); + void drawTopRight(const std::string& str, const paxs::Vector2& pos, const Color& color) const { + drawTopRight(str, paxs::Vector2{pos}, color); } - /// @brief テキストを右下揃えで描画 (横:右端, 縦:下端) /// @brief Draw text with bottom-right alignment (horizontal: right, vertical: bottom) - void drawBottomRight(const std::string& str, const paxs::Vector2& pos, const paxg::Color& color) const { - sf::Text text(font); - std::wstring wstr; - sf::Utf<8>::toWide(str.begin(), str.end(), std::back_inserter(wstr)); - text.setString(wstr); - text.setCharacterSize(size); - text.setFillColor(color); - text.setOutlineColor(sf::Color::White); - text.setOutlineThickness(2.0f); - // 文字の底部がpos.yに来るように、テキストの高さ分上に配置 - text.setPosition({ static_cast(pos.x - text.getGlobalBounds().size.x), static_cast(pos.y - text.getGlobalBounds().size.y) }); - paxg::Window::window().draw(text); + /// @brief テキストを右下揃えで描画 (横:右端, 縦:下端) + void drawBottomRight(const std::string& str, const paxs::Vector2& pos, const Color& color) const { + if (impl) impl->drawBottomRight(str, pos, color); } - /// @brief テキストを左上揃えで描画 (横:左端, 縦:上端) - /// @brief Draw text with top-left alignment (horizontal: left, vertical: top) - void draw(const std::string& str, const paxs::Vector2& pos, const paxg::Color& color) const { - sf::Text text(font); - std::wstring wstr; - sf::Utf<8>::toWide(str.begin(), str.end(), std::back_inserter(wstr)); - text.setString(wstr); - text.setCharacterSize(size); - text.setFillColor(color); - text.setOutlineColor(sf::Color::White); - text.setOutlineThickness(2.0f); - text.setPosition({ static_cast(pos.x), static_cast(pos.y) }); - paxg::Window::window().draw(text); + void drawBottomRight(const std::string& str, const paxs::Vector2& pos, const Color& color) const { + drawBottomRight(str, paxs::Vector2{pos}, color); } - /// @brief テキストを中央下揃えで描画 (横:中央, 縦:下端) - /// @brief Draw text with bottom-center alignment (horizontal: center, vertical: bottom) - void drawBottomCenter(const std::string& str, const paxs::Vector2& pos, const paxg::Color& color) const { - sf::Text text(font); - std::wstring wstr; - sf::Utf<8>::toWide(str.begin(), str.end(), std::back_inserter(wstr)); - text.setString(wstr); - text.setCharacterSize(size); - text.setFillColor(color); - text.setOutlineColor(sf::Color::White); - text.setOutlineThickness(2.0f); - text.setPosition({ static_cast(pos.x - text.getGlobalBounds().size.x / 2), static_cast(pos.y - size / 2) }); - paxg::Window::window().draw(text); + /// @brief Draw text with top-left alignment (horizontal: left, vertical: top) + /// @brief テキストを左上揃えで描画 (横:左端, 縦:上端) + void draw(const std::string& str, const paxs::Vector2& pos, const Color& color) const { + if (impl) impl->draw(str, pos, color); } - /// @brief テキストを中央上揃えで描画 (横:中央, 縦:上端) - /// @brief Draw text with top-center alignment (horizontal: center, vertical: top) - void drawTopCenter(const std::string& str, const paxs::Vector2& pos, const paxg::Color& color) const { - sf::Text text(font); - std::wstring wstr; - sf::Utf<8>::toWide(str.begin(), str.end(), std::back_inserter(wstr)); - text.setString(wstr); - text.setCharacterSize(size); - text.setFillColor(color); - text.setOutlineColor(sf::Color::White); - text.setOutlineThickness(2.0f); - text.setPosition({ static_cast(pos.x - text.getGlobalBounds().size.x / 2), static_cast(pos.y + size / 2) }); - paxg::Window::window().draw(text); + void draw(const std::string& str, const paxs::Vector2& pos, const Color& color) const { + draw(str, paxs::Vector2{pos}, color); } - /// @brief テキストを中央揃えで描画 (横:中央, 縦:中央) - /// @brief Draw text with center alignment (horizontal: center, vertical: center) - void drawAt(const std::string& str, const paxs::Vector2& pos, const paxg::Color& color) const { - sf::Text text(font); - std::wstring wstr; - sf::Utf<8>::toWide(str.begin(), str.end(), std::back_inserter(wstr)); - text.setString(wstr); - text.setCharacterSize(size); - text.setFillColor(color); - text.setOutlineColor(sf::Color::White); - text.setOutlineThickness(2.0f); - // 横方向は中央、縦方向も中央に揃える - const sf::FloatRect bounds = text.getGlobalBounds(); - text.setPosition({ - static_cast(pos.x) - bounds.size.x / 2, - static_cast(pos.y) - bounds.size.y / 2 - }); - paxg::Window::window().draw(text); + /// @brief Draw text with bottom-center alignment (horizontal: center, vertical: bottom) + /// @brief テキストを中央下揃えで描画 (横:中央, 縦:下端) + void drawBottomCenter(const std::string& str, const paxs::Vector2& pos, const Color& color) const { + if (impl) impl->drawBottomCenter(str, pos, color); } - int height() const { - return size; + void drawBottomCenter(const std::string& str, const paxs::Vector2& pos, const Color& color) const { + drawBottomCenter(str, paxs::Vector2{pos}, color); } - int width(const std::string& str_) { - sf::Text text(font); - std::wstring wstr; - sf::Utf<8>::toWide(str_.begin(), str_.end(), std::back_inserter(wstr)); - text.setString(wstr); - text.setCharacterSize(size); - - return static_cast(text.getGlobalBounds().size.x); - // return str_.size() * size * 0.5; + /// @brief Draw text with top-center alignment (horizontal: center, vertical: top) + /// @brief テキストを中央上揃えで描画 (横:中央, 縦:上端) + void drawTopCenter(const std::string& str, const paxs::Vector2& pos, const Color& color) const { + if (impl) impl->drawTopCenter(str, pos, color); } - void drawBottomLeft(const std::string& str, const paxs::Vector2& pos, const paxg::Color& color) const { - drawBottomLeft(str, paxs::Vector2{pos}, color); - } - void drawTopRight(const std::string& str, const paxs::Vector2& pos, const paxg::Color& color) const { - drawTopRight(str, paxs::Vector2{pos}, color); - } - void drawBottomRight(const std::string& str, const paxs::Vector2& pos, const paxg::Color& color) const { - drawBottomRight(str, paxs::Vector2{pos}, color); - } - void draw(const std::string& str, const paxs::Vector2& pos, const paxg::Color& color) const { - draw(str, paxs::Vector2{pos}, color); - } - void drawBottomCenter(const std::string& str, const paxs::Vector2& pos, const paxg::Color& color) const { - drawBottomCenter(str, paxs::Vector2{pos}, color); - } - void drawTopCenter(const std::string& str, const paxs::Vector2& pos, const paxg::Color& color) const { + void drawTopCenter(const std::string& str, const paxs::Vector2& pos, const Color& color) const { drawTopCenter(str, paxs::Vector2{pos}, color); } - void drawAt(const std::string& str, const paxs::Vector2& pos, const paxg::Color& color) const { - drawAt(str, paxs::Vector2{pos}, color); - } - -#else - Font([[maybe_unused]] const int size_, [[maybe_unused]] const std::string& path, [[maybe_unused]] const int buffer_thickness) { - } - void setOutline([[maybe_unused]] const double inner, [[maybe_unused]] const double outer, [[maybe_unused]] const paxg::Color& color) { - } - void drawBottomLeft([[maybe_unused]] const std::string& str, [[maybe_unused]] const paxs::Vector2& pos, [[maybe_unused]] const paxg::Color& color) const { - } - void drawTopRight([[maybe_unused]] const std::string& str, [[maybe_unused]] const paxs::Vector2& pos, [[maybe_unused]] const paxg::Color& color) const { - } - void drawBottomRight([[maybe_unused]] const std::string& str, [[maybe_unused]] const paxs::Vector2& pos, [[maybe_unused]] const paxg::Color& color) const { - } - void draw([[maybe_unused]] const std::string& str, [[maybe_unused]] const paxs::Vector2& pos, [[maybe_unused]] const paxg::Color& color) const { - } - void drawBottomCenter([[maybe_unused]] const std::string& str, [[maybe_unused]] const paxs::Vector2& pos, [[maybe_unused]] const paxg::Color& color) const { - } - void drawTopCenter([[maybe_unused]] const std::string& str, [[maybe_unused]] const paxs::Vector2& pos, [[maybe_unused]] const paxg::Color& color) const { - } - void drawAt([[maybe_unused]] const std::string& str, [[maybe_unused]] const paxs::Vector2& pos, [[maybe_unused]] const paxg::Color& color) const { + /// @brief Draw text with center alignment (horizontal: center, vertical: center) + /// @brief テキストを中央揃えで描画 (横:中央, 縦:中央) + void drawAt(const std::string& str, const paxs::Vector2& pos, const Color& color) const { + if (impl) impl->drawAt(str, pos, color); } - void drawBottomLeft([[maybe_unused]] const std::string& str, [[maybe_unused]] const paxs::Vector2& pos, [[maybe_unused]] const paxg::Color& color) const { - } - void drawTopRight([[maybe_unused]] const std::string& str, [[maybe_unused]] const paxs::Vector2& pos, [[maybe_unused]] const paxg::Color& color) const { - } - void drawBottomRight([[maybe_unused]] const std::string& str, [[maybe_unused]] const paxs::Vector2& pos, [[maybe_unused]] const paxg::Color& color) const { - } - void draw([[maybe_unused]] const std::string& str, [[maybe_unused]] const paxs::Vector2& pos, [[maybe_unused]] const paxg::Color& color) const { - } - void drawBottomCenter([[maybe_unused]] const std::string& str, [[maybe_unused]] const paxs::Vector2& pos, [[maybe_unused]] const paxg::Color& color) const { - } - void drawTopCenter([[maybe_unused]] const std::string& str, [[maybe_unused]] const paxs::Vector2& pos, [[maybe_unused]] const paxg::Color& color) const { - } - void drawAt([[maybe_unused]] const std::string& str, [[maybe_unused]] const paxs::Vector2& pos, [[maybe_unused]] const paxg::Color& color) const { + void drawAt(const std::string& str, const paxs::Vector2& pos, const Color& color) const { + drawAt(str, paxs::Vector2{pos}, color); } + /// @brief Get font height + /// @brief フォントの高さを取得 int height() const { - return 0; + return impl ? impl->height() : 0; } - int width([[maybe_unused]] const std::string& str_) { - return 0; + + /// @brief Get text width + /// @brief テキストの幅を取得 + int width(const std::string& str) { + return impl ? impl->width(str) : 0; } -#endif }; - /// @brief フォント設定の定数 /// @brief Font configuration constants + /// @brief フォント設定の定数 struct FontConfig { // プルダウンメニューのフォント設定 static constexpr int PULLDOWN_FONT_SIZE = @@ -586,6 +164,6 @@ namespace paxg{ static constexpr int KOYOMI_FONT_BUFFER_THICKNESS = 3; }; -} +} // namespace paxg #endif // !PAX_GRAPHICA_FONT_HPP diff --git a/Library/PAX_GRAPHICA/Interface/FontImpl.hpp b/Library/PAX_GRAPHICA/Interface/FontImpl.hpp new file mode 100644 index 000000000..178592fbe --- /dev/null +++ b/Library/PAX_GRAPHICA/Interface/FontImpl.hpp @@ -0,0 +1,72 @@ +/*########################################################################################## + + PAX SAPIENTICA Library 💀🌿🌏 + + [Planning] 2023-2024 As Project + [Production] 2023-2024 As Project + [Contact Us] wanotaitei@gmail.com https://github.com/AsPJT/PAX_SAPIENTICA + [License] Distributed under the CC0 1.0. https://creativecommons.org/publicdomain/zero/1.0/ + +##########################################################################################*/ + +#ifndef PAX_GRAPHICA_FONT_IMPL_HPP +#define PAX_GRAPHICA_FONT_IMPL_HPP + +#include + +#include + +#include + +namespace paxg { + + /// @brief Abstract base class for font implementations + /// @brief フォント実装の抽象基底クラス + class FontImpl { + public: + virtual ~FontImpl() = default; + + /// @brief Set outline effect + /// @brief アウトライン効果を設定 + virtual void setOutline(double inner, double outer, const Color& color) = 0; + + /// @brief Draw text with bottom-left alignment (horizontal: left, vertical: bottom) + /// @brief テキストを左下揃えで描画 (横:左端, 縦:下端) + virtual void drawBottomLeft(const std::string& str, const paxs::Vector2& pos, const Color& color) const = 0; + + /// @brief Draw text with top-right alignment (horizontal: right, vertical: top) + /// @brief テキストを右上揃えで描画 (横:右端, 縦:上端) + virtual void drawTopRight(const std::string& str, const paxs::Vector2& pos, const Color& color) const = 0; + + /// @brief Draw text with bottom-right alignment (horizontal: right, vertical: bottom) + /// @brief テキストを右下揃えで描画 (横:右端, 縦:下端) + virtual void drawBottomRight(const std::string& str, const paxs::Vector2& pos, const Color& color) const = 0; + + /// @brief Draw text with top-left alignment (horizontal: left, vertical: top) + /// @brief テキストを左上揃えで描画 (横:左端, 縦:上端) + virtual void draw(const std::string& str, const paxs::Vector2& pos, const Color& color) const = 0; + + /// @brief Draw text with bottom-center alignment (horizontal: center, vertical: bottom) + /// @brief テキストを中央下揃えで描画 (横:中央, 縦:下端) + virtual void drawBottomCenter(const std::string& str, const paxs::Vector2& pos, const Color& color) const = 0; + + /// @brief Draw text with top-center alignment (horizontal: center, vertical: top) + /// @brief テキストを中央上揃えで描画 (横:中央, 縦:上端) + virtual void drawTopCenter(const std::string& str, const paxs::Vector2& pos, const Color& color) const = 0; + + /// @brief Draw text with center alignment (horizontal: center, vertical: center) + /// @brief テキストを中央揃えで描画 (横:中央, 縦:中央) + virtual void drawAt(const std::string& str, const paxs::Vector2& pos, const Color& color) const = 0; + + /// @brief Get font height + /// @brief フォントの高さを取得 + virtual int height() const = 0; + + /// @brief Get text width + /// @brief テキストの幅を取得 + virtual int width(const std::string& str) = 0; + }; + +} // namespace paxg + +#endif // !PAX_GRAPHICA_FONT_IMPL_HPP diff --git a/Library/PAX_GRAPHICA/Null/NullFontImpl.hpp b/Library/PAX_GRAPHICA/Null/NullFontImpl.hpp new file mode 100644 index 000000000..631b4ef8b --- /dev/null +++ b/Library/PAX_GRAPHICA/Null/NullFontImpl.hpp @@ -0,0 +1,75 @@ +/*########################################################################################## + + PAX SAPIENTICA Library 💀🌿🌏 + + [Planning] 2023-2024 As Project + [Production] 2023-2024 As Project + [Contact Us] wanotaitei@gmail.com https://github.com/AsPJT/PAX_SAPIENTICA + [License] Distributed under the CC0 1.0. https://creativecommons.org/publicdomain/zero/1.0/ + +##########################################################################################*/ + +#ifndef PAX_GRAPHICA_NULL_FONT_IMPL_HPP +#define PAX_GRAPHICA_NULL_FONT_IMPL_HPP + +#include + +#include +#include + +#include + +namespace paxg { + + /// @brief Null font implementation (no-op) + /// @brief Nullフォント実装(何もしない) + class NullFontImpl : public FontImpl { + public: + NullFontImpl(int /*size*/, const std::string& /*path*/, int /*buffer_thickness*/) { + // No operation + } + + void setOutline(double /*inner*/, double /*outer*/, const Color& /*color*/) override { + // No operation + } + + void drawBottomLeft(const std::string& /*str*/, const paxs::Vector2& /*pos*/, const Color& /*color*/) const override { + // No operation + } + + void drawTopRight(const std::string& /*str*/, const paxs::Vector2& /*pos*/, const Color& /*color*/) const override { + // No operation + } + + void drawBottomRight(const std::string& /*str*/, const paxs::Vector2& /*pos*/, const Color& /*color*/) const override { + // No operation + } + + void draw(const std::string& /*str*/, const paxs::Vector2& /*pos*/, const Color& /*color*/) const override { + // No operation + } + + void drawBottomCenter(const std::string& /*str*/, const paxs::Vector2& /*pos*/, const Color& /*color*/) const override { + // No operation + } + + void drawTopCenter(const std::string& /*str*/, const paxs::Vector2& /*pos*/, const Color& /*color*/) const override { + // No operation + } + + void drawAt(const std::string& /*str*/, const paxs::Vector2& /*pos*/, const Color& /*color*/) const override { + // No operation + } + + int height() const override { + return 0; + } + + int width(const std::string& /*str*/) override { + return 0; + } + }; + +} // namespace paxg + +#endif // !PAX_GRAPHICA_NULL_FONT_IMPL_HPP diff --git a/Library/PAX_GRAPHICA/SFML/SFMLCircleImpl.hpp b/Library/PAX_GRAPHICA/SFML/SFMLCircleImpl.hpp index e07680198..5676abe34 100644 --- a/Library/PAX_GRAPHICA/SFML/SFMLCircleImpl.hpp +++ b/Library/PAX_GRAPHICA/SFML/SFMLCircleImpl.hpp @@ -12,18 +12,15 @@ #ifndef PAX_GRAPHICA_SFML_CIRCLE_IMPL_HPP #define PAX_GRAPHICA_SFML_CIRCLE_IMPL_HPP -#include - #ifdef PAXS_USING_SFML #include -#include + #include -#endif +#include +#include namespace paxg { -#ifdef PAXS_USING_SFML - /// @brief SFML implementation of CircleImpl class SFMLCircleImpl : public CircleImpl { private: @@ -65,8 +62,8 @@ namespace paxg { } }; -#endif // PAXS_USING_SFML - } +#endif // PAXS_USING_SFML + #endif // !PAX_GRAPHICA_SFML_CIRCLE_IMPL_HPP diff --git a/Library/PAX_GRAPHICA/SFML/SFMLFontImpl.hpp b/Library/PAX_GRAPHICA/SFML/SFMLFontImpl.hpp new file mode 100644 index 000000000..15cfd3d2d --- /dev/null +++ b/Library/PAX_GRAPHICA/SFML/SFMLFontImpl.hpp @@ -0,0 +1,164 @@ +/*########################################################################################## + + PAX SAPIENTICA Library 💀🌿🌏 + + [Planning] 2023-2024 As Project + [Production] 2023-2024 As Project + [Contact Us] wanotaitei@gmail.com https://github.com/AsPJT/PAX_SAPIENTICA + [License] Distributed under the CC0 1.0. https://creativecommons.org/publicdomain/zero/1.0/ + +##########################################################################################*/ + +#ifndef PAX_GRAPHICA_SFML_FONT_IMPL_HPP +#define PAX_GRAPHICA_SFML_FONT_IMPL_HPP + +#ifdef PAXS_USING_SFML +#include + +#include +#include + +#include +#include +#include + +#include +#include +#include + +namespace paxg { + + /// @brief SFML font implementation + /// @brief SFMLフォント実装 + class SFMLFontImpl : public FontImpl { + private: + sf::Font font{}; + int size = 0; + + public: + SFMLFontImpl(int size_, const std::string& path, int /*buffer_thickness*/) { + size = size_; + if (path.empty()) return; + if (!font.openFromFile(paxs::AppConfig::getInstance().getRootPath() + path)) { + PAXS_WARNING(path + " is missing."); + } + } + + void setOutline(double /*inner*/, double /*outer*/, const Color& /*color*/) override { + // SFML doesn't support outline in this implementation + } + + void drawBottomLeft(const std::string& str, const paxs::Vector2& pos, const Color& color) const override { + sf::Text text(font); + std::wstring wstr; + sf::Utf<8>::toWide(str.begin(), str.end(), std::back_inserter(wstr)); + text.setString(wstr); + text.setCharacterSize(size); + text.setFillColor(color); + text.setOutlineColor(sf::Color::White); + text.setOutlineThickness(2.0f); + text.setPosition({ static_cast(pos.x), static_cast(pos.y - size / 2) }); + Window::window().draw(text); + } + + void drawTopRight(const std::string& str, const paxs::Vector2& pos, const Color& color) const override { + sf::Text text(font); + std::wstring wstr; + sf::Utf<8>::toWide(str.begin(), str.end(), std::back_inserter(wstr)); + text.setString(wstr); + text.setCharacterSize(size); + text.setFillColor(color); + text.setOutlineColor(sf::Color::White); + text.setOutlineThickness(2.0f); + text.setPosition({ static_cast(pos.x - text.getGlobalBounds().size.x), static_cast(pos.y + size / 2) }); + Window::window().draw(text); + } + + void drawBottomRight(const std::string& str, const paxs::Vector2& pos, const Color& color) const override { + sf::Text text(font); + std::wstring wstr; + sf::Utf<8>::toWide(str.begin(), str.end(), std::back_inserter(wstr)); + text.setString(wstr); + text.setCharacterSize(size); + text.setFillColor(color); + text.setOutlineColor(sf::Color::White); + text.setOutlineThickness(2.0f); + text.setPosition({ static_cast(pos.x - text.getGlobalBounds().size.x), static_cast(pos.y - text.getGlobalBounds().size.y) }); + Window::window().draw(text); + } + + void draw(const std::string& str, const paxs::Vector2& pos, const Color& color) const override { + sf::Text text(font); + std::wstring wstr; + sf::Utf<8>::toWide(str.begin(), str.end(), std::back_inserter(wstr)); + text.setString(wstr); + text.setCharacterSize(size); + text.setFillColor(color); + text.setOutlineColor(sf::Color::White); + text.setOutlineThickness(2.0f); + text.setPosition({ static_cast(pos.x), static_cast(pos.y) }); + Window::window().draw(text); + } + + void drawBottomCenter(const std::string& str, const paxs::Vector2& pos, const Color& color) const override { + sf::Text text(font); + std::wstring wstr; + sf::Utf<8>::toWide(str.begin(), str.end(), std::back_inserter(wstr)); + text.setString(wstr); + text.setCharacterSize(size); + text.setFillColor(color); + text.setOutlineColor(sf::Color::White); + text.setOutlineThickness(2.0f); + text.setPosition({ static_cast(pos.x - text.getGlobalBounds().size.x / 2), static_cast(pos.y - size / 2) }); + Window::window().draw(text); + } + + void drawTopCenter(const std::string& str, const paxs::Vector2& pos, const Color& color) const override { + sf::Text text(font); + std::wstring wstr; + sf::Utf<8>::toWide(str.begin(), str.end(), std::back_inserter(wstr)); + text.setString(wstr); + text.setCharacterSize(size); + text.setFillColor(color); + text.setOutlineColor(sf::Color::White); + text.setOutlineThickness(2.0f); + text.setPosition({ static_cast(pos.x - text.getGlobalBounds().size.x / 2), static_cast(pos.y + size / 2) }); + Window::window().draw(text); + } + + void drawAt(const std::string& str, const paxs::Vector2& pos, const Color& color) const override { + sf::Text text(font); + std::wstring wstr; + sf::Utf<8>::toWide(str.begin(), str.end(), std::back_inserter(wstr)); + text.setString(wstr); + text.setCharacterSize(size); + text.setFillColor(color); + text.setOutlineColor(sf::Color::White); + text.setOutlineThickness(2.0f); + const sf::FloatRect bounds = text.getGlobalBounds(); + text.setPosition({ + static_cast(pos.x) - bounds.size.x / 2, + static_cast(pos.y) - bounds.size.y / 2 + }); + Window::window().draw(text); + } + + int height() const override { + return size; + } + + int width(const std::string& str) override { + sf::Text text(font); + std::wstring wstr; + sf::Utf<8>::toWide(str.begin(), str.end(), std::back_inserter(wstr)); + text.setString(wstr); + text.setCharacterSize(size); + return static_cast(text.getGlobalBounds().size.x); + } + }; + +} // namespace paxg + +#endif // PAXS_USING_SFML + +#endif // !PAX_GRAPHICA_SFML_FONT_IMPL_HPP diff --git a/Library/PAX_GRAPHICA/SFML/SFMLTextureImpl.hpp b/Library/PAX_GRAPHICA/SFML/SFMLTextureImpl.hpp index 7677a8c05..e31d0ed22 100644 --- a/Library/PAX_GRAPHICA/SFML/SFMLTextureImpl.hpp +++ b/Library/PAX_GRAPHICA/SFML/SFMLTextureImpl.hpp @@ -14,14 +14,16 @@ #if defined(PAXS_USING_SFML) +#include // std::min を使用するために追加 +#include // std::min がfloatで曖昧な場合のため (fminでも可) + #include + #include #include #include -#include -#include // std::min を使用するために追加 -#include // std::min がfloatで曖昧な場合のため (fminでも可) +#include namespace paxg { diff --git a/Library/PAX_GRAPHICA/SFML/SFMLWindowImpl.hpp b/Library/PAX_GRAPHICA/SFML/SFMLWindowImpl.hpp index cc642f819..3bf1c638c 100644 --- a/Library/PAX_GRAPHICA/SFML/SFMLWindowImpl.hpp +++ b/Library/PAX_GRAPHICA/SFML/SFMLWindowImpl.hpp @@ -16,12 +16,13 @@ #include -#include #include +#include #include #include #include + namespace paxg { class SFMLWindowImpl : public WindowImpl { diff --git a/Library/PAX_GRAPHICA/Siv3D/Siv3DCircleImpl.hpp b/Library/PAX_GRAPHICA/Siv3D/Siv3DCircleImpl.hpp index c707bc58d..b899e1c99 100644 --- a/Library/PAX_GRAPHICA/Siv3D/Siv3DCircleImpl.hpp +++ b/Library/PAX_GRAPHICA/Siv3D/Siv3DCircleImpl.hpp @@ -12,15 +12,12 @@ #ifndef PAX_GRAPHICA_SIV3D_CIRCLE_IMPL_HPP #define PAX_GRAPHICA_SIV3D_CIRCLE_IMPL_HPP -#include - #ifdef PAXS_USING_SIV3D #include -#endif -namespace paxg { +#include -#ifdef PAXS_USING_SIV3D +namespace paxg { /// @brief Siv3D implementation of CircleImpl class Siv3DCircleImpl : public CircleImpl { @@ -63,8 +60,8 @@ namespace paxg { } }; -#endif // PAXS_USING_SIV3D - } +#endif // PAXS_USING_SIV3D + #endif // !PAX_GRAPHICA_SIV3D_CIRCLE_IMPL_HPP diff --git a/Library/PAX_GRAPHICA/Siv3D/Siv3DFontImpl.hpp b/Library/PAX_GRAPHICA/Siv3D/Siv3DFontImpl.hpp new file mode 100644 index 000000000..79a4434e0 --- /dev/null +++ b/Library/PAX_GRAPHICA/Siv3D/Siv3DFontImpl.hpp @@ -0,0 +1,159 @@ +/*########################################################################################## + + PAX SAPIENTICA Library 💀🌿🌏 + + [Planning] 2023-2024 As Project + [Production] 2023-2024 As Project + [Contact Us] wanotaitei@gmail.com https://github.com/AsPJT/PAX_SAPIENTICA + [License] Distributed under the CC0 1.0. https://creativecommons.org/publicdomain/zero/1.0/ + +##########################################################################################*/ + +#ifndef PAX_GRAPHICA_SIV3D_FONT_IMPL_HPP +#define PAX_GRAPHICA_SIV3D_FONT_IMPL_HPP + +#ifdef PAXS_USING_SIV3D +#include + +#include + +#include +#include +#include +#include + +namespace paxg { + + /// @brief Siv3D font implementation + /// @brief Siv3Dフォント実装 + class Siv3DFontImpl : public FontImpl { + private: + s3d::Font font{}; + bool is_outline = false; + s3d::TextStyle outline{}; + + public: + Siv3DFontImpl(int size, const std::string& path, int buffer_thickness) { + font = (path.empty()) ? + s3d::Font(s3d::FontMethod::SDF, size) : + s3d::Font(s3d::FontMethod::SDF, size, s3d::Unicode::FromUTF8(paxs::AppConfig::getInstance().getRootPath() + path)); + font.setBufferThickness(buffer_thickness); + } + + void setOutline(double inner, double outer, const Color& color) override { + is_outline = true; + outline = s3d::TextStyle::Outline(inner, outer, color); + } + + void drawBottomLeft(const std::string& str, const paxs::Vector2& pos, const Color& color) const override { + if (is_outline) { + font(s3d::Unicode::FromUTF8(str)).draw( + outline, + s3d::Arg::bottomLeft = s3d::Vec2(pos.x, pos.y), + color); + } + else { + font(s3d::Unicode::FromUTF8(str)).draw( + s3d::Arg::bottomLeft = s3d::Vec2(pos.x, pos.y), + color); + } + } + + void drawTopRight(const std::string& str, const paxs::Vector2& pos, const Color& color) const override { + if (is_outline) { + font(s3d::Unicode::FromUTF8(str)).draw( + outline, + s3d::Arg::topRight = s3d::Vec2(pos.x, pos.y), + color); + } + else { + font(s3d::Unicode::FromUTF8(str)).draw( + s3d::Arg::topRight = s3d::Vec2(pos.x, pos.y), + color); + } + } + + void drawBottomRight(const std::string& str, const paxs::Vector2& pos, const Color& color) const override { + if (is_outline) { + font(s3d::Unicode::FromUTF8(str)).draw( + outline, + s3d::Arg::bottomRight = s3d::Vec2(pos.x, pos.y), + color); + } + else { + font(s3d::Unicode::FromUTF8(str)).draw( + s3d::Arg::bottomRight = s3d::Vec2(pos.x, pos.y), + color); + } + } + + void draw(const std::string& str, const paxs::Vector2& pos, const Color& color) const override { + if (is_outline) { + font(s3d::Unicode::FromUTF8(str)).draw( + outline, + s3d::Vec2(pos.x, pos.y), + color); + } + else { + font(s3d::Unicode::FromUTF8(str)).draw( + s3d::Vec2(pos.x, pos.y), + color); + } + } + + void drawBottomCenter(const std::string& str, const paxs::Vector2& pos, const Color& color) const override { + if (is_outline) { + font(s3d::Unicode::FromUTF8(str)).draw( + outline, + s3d::Arg::bottomCenter = s3d::Vec2(pos.x, pos.y), + color); + } + else { + font(s3d::Unicode::FromUTF8(str)).draw( + s3d::Arg::bottomCenter = s3d::Vec2(pos.x, pos.y), + color); + } + } + + void drawTopCenter(const std::string& str, const paxs::Vector2& pos, const Color& color) const override { + if (is_outline) { + font(s3d::Unicode::FromUTF8(str)).draw( + outline, + s3d::Arg::topCenter = s3d::Vec2(pos.x, pos.y), + color); + } + else { + font(s3d::Unicode::FromUTF8(str)).draw( + s3d::Arg::topCenter = s3d::Vec2(pos.x, pos.y), + color); + } + } + + void drawAt(const std::string& str, const paxs::Vector2& pos, const Color& color) const override { + if (is_outline) { + font(s3d::Unicode::FromUTF8(str)).drawAt( + outline, + s3d::Vec2(pos.x, pos.y), + color); + } + else { + font(s3d::Unicode::FromUTF8(str)).drawAt( + s3d::Vec2(pos.x, pos.y), + color); + } + } + + int height() const override { + return font.height(); + } + + int width(const std::string& str) override { + return static_cast(font(s3d::Unicode::FromUTF8(str)).region().w); + } + }; + +} // namespace paxg + +#endif // PAXS_USING_SIV3D + +#endif // !PAX_GRAPHICA_SIV3D_FONT_IMPL_HPP diff --git a/Library/PAX_GRAPHICA/Siv3D/Siv3DGraphics3DModelImpl.hpp b/Library/PAX_GRAPHICA/Siv3D/Siv3DGraphics3DModelImpl.hpp index 280c693ef..3361763e7 100644 --- a/Library/PAX_GRAPHICA/Siv3D/Siv3DGraphics3DModelImpl.hpp +++ b/Library/PAX_GRAPHICA/Siv3D/Siv3DGraphics3DModelImpl.hpp @@ -12,20 +12,18 @@ #ifndef PAX_GRAPHICA_SIV3D_GRAPHICS_3D_MODEL_IMPL_HPP #define PAX_GRAPHICA_SIV3D_GRAPHICS_3D_MODEL_IMPL_HPP -#include - #ifdef PAXS_USING_SIV3D #include + +#include + #include #include -#endif namespace paxg { struct Graphics3DModelConfig; -#ifdef PAXS_USING_SIV3D - /// @brief Siv3D implementation of Graphics3DModelImpl class Siv3DGraphics3DModelImpl : public Graphics3DModelImpl { private: @@ -145,8 +143,8 @@ namespace paxg { } }; -#endif // PAXS_USING_SIV3D - } +#endif // PAXS_USING_SIV3D + #endif // !PAX_GRAPHICA_SIV3D_GRAPHICS_3D_MODEL_IMPL_HPP diff --git a/Library/PAX_GRAPHICA/Siv3D/Siv3DRenderTextureImpl.hpp b/Library/PAX_GRAPHICA/Siv3D/Siv3DRenderTextureImpl.hpp index ffdfb7cf6..93489ce1c 100644 --- a/Library/PAX_GRAPHICA/Siv3D/Siv3DRenderTextureImpl.hpp +++ b/Library/PAX_GRAPHICA/Siv3D/Siv3DRenderTextureImpl.hpp @@ -12,11 +12,11 @@ #ifndef PAX_GRAPHICA_SIV3D_RENDER_TEXTURE_IMPL_HPP #define PAX_GRAPHICA_SIV3D_RENDER_TEXTURE_IMPL_HPP -#include - #if defined(PAXS_USING_SIV3D) #include +#include + namespace paxg { /// @brief Siv3D implementation of render texture diff --git a/Library/PAX_GRAPHICA/Siv3D/Siv3DTextureImpl.hpp b/Library/PAX_GRAPHICA/Siv3D/Siv3DTextureImpl.hpp index 64299353e..f5212ed92 100644 --- a/Library/PAX_GRAPHICA/Siv3D/Siv3DTextureImpl.hpp +++ b/Library/PAX_GRAPHICA/Siv3D/Siv3DTextureImpl.hpp @@ -20,6 +20,7 @@ #include #include + namespace paxg { class Siv3DTextureImpl : public TextureImpl { @@ -97,6 +98,6 @@ namespace paxg { } // namespace paxg -#endif // defined(PAXS_USING_SIV3D) +#endif // PAXS_USING_SIV3D #endif // !PAX_GRAPHICA_SIV3D_TEXTURE_IMPL_HPP diff --git a/Projects/IncludeTest/source/PAX_GRAPHICA/DxLib/DxLibFontImplIncludeTest.cpp b/Projects/IncludeTest/source/PAX_GRAPHICA/DxLib/DxLibFontImplIncludeTest.cpp new file mode 100644 index 000000000..91a35ebbc --- /dev/null +++ b/Projects/IncludeTest/source/PAX_GRAPHICA/DxLib/DxLibFontImplIncludeTest.cpp @@ -0,0 +1,3 @@ +#include + +int main(){} diff --git a/Projects/IncludeTest/source/PAX_GRAPHICA/Interface/FontImplIncludeTest.cpp b/Projects/IncludeTest/source/PAX_GRAPHICA/Interface/FontImplIncludeTest.cpp new file mode 100644 index 000000000..c1d9dc4be --- /dev/null +++ b/Projects/IncludeTest/source/PAX_GRAPHICA/Interface/FontImplIncludeTest.cpp @@ -0,0 +1,3 @@ +#include + +int main(){} diff --git a/Projects/IncludeTest/source/PAX_GRAPHICA/Null/NullFontImplIncludeTest.cpp b/Projects/IncludeTest/source/PAX_GRAPHICA/Null/NullFontImplIncludeTest.cpp new file mode 100644 index 000000000..fbd76db87 --- /dev/null +++ b/Projects/IncludeTest/source/PAX_GRAPHICA/Null/NullFontImplIncludeTest.cpp @@ -0,0 +1,3 @@ +#include + +int main(){} diff --git a/Projects/IncludeTest/source/PAX_GRAPHICA/SFML/SFMLFontImplIncludeTest.cpp b/Projects/IncludeTest/source/PAX_GRAPHICA/SFML/SFMLFontImplIncludeTest.cpp new file mode 100644 index 000000000..3f624128c --- /dev/null +++ b/Projects/IncludeTest/source/PAX_GRAPHICA/SFML/SFMLFontImplIncludeTest.cpp @@ -0,0 +1,3 @@ +#include + +int main(){} diff --git a/Projects/IncludeTest/source/PAX_GRAPHICA/Siv3D/Siv3DFontImplIncludeTest.cpp b/Projects/IncludeTest/source/PAX_GRAPHICA/Siv3D/Siv3DFontImplIncludeTest.cpp new file mode 100644 index 000000000..f765d11a6 --- /dev/null +++ b/Projects/IncludeTest/source/PAX_GRAPHICA/Siv3D/Siv3DFontImplIncludeTest.cpp @@ -0,0 +1,3 @@ +#include + +int main(){} From 595616826f61fa79c1d2986fcbb751c491872465 Mon Sep 17 00:00:00 2001 From: guinpen98 <83969826+guinpen98@users.noreply.github.com> Date: Thu, 4 Dec 2025 02:20:25 +0900 Subject: [PATCH 6/9] ref: spline --- .../Components/GenericSpline2DImpl.hpp | 225 +++++++++++++++ .../PAX_GRAPHICA/DxLib/DxLibTextureImpl.hpp | 5 +- .../PAX_GRAPHICA/DxLib/DxLibWindowImpl.hpp | 3 +- .../PAX_GRAPHICA/Interface/Spline2DImpl.hpp | 33 +++ Library/PAX_GRAPHICA/Network.hpp | 53 +++- Library/PAX_GRAPHICA/SFML/SFMLTextureImpl.hpp | 5 +- Library/PAX_GRAPHICA/SFML/SFMLWindowImpl.hpp | 3 +- .../Siv3D/Siv3DRenderTextureImpl.hpp | 2 +- .../PAX_GRAPHICA/Siv3D/Siv3DSpline2DImpl.hpp | 83 ++++++ .../PAX_GRAPHICA/Siv3D/Siv3DTextureImpl.hpp | 3 +- .../PAX_GRAPHICA/Siv3D/Siv3DWindowImpl.hpp | 3 +- Library/PAX_GRAPHICA/Spline2D.hpp | 261 ++++-------------- Library/PAX_GRAPHICA/System.hpp | 89 ------ .../PAX_MAHOROBA/UI/MenuBar/GitHubButton.hpp | 4 +- .../UI/Widget/UIPanelBackground.hpp | 2 + .../GenericSpline2DImplIncludeTest.cpp | 3 + .../Interface/Spline2DImplIncludeTest.cpp | 3 + .../Siv3D/Siv3DSpline2DImplIncludeTest.cpp | 3 + .../source/PAX_GRAPHICA/SystemIncludeTest.cpp | 3 - 19 files changed, 474 insertions(+), 312 deletions(-) create mode 100644 Library/PAX_GRAPHICA/Components/GenericSpline2DImpl.hpp create mode 100644 Library/PAX_GRAPHICA/Interface/Spline2DImpl.hpp create mode 100644 Library/PAX_GRAPHICA/Siv3D/Siv3DSpline2DImpl.hpp delete mode 100644 Library/PAX_GRAPHICA/System.hpp create mode 100644 Projects/IncludeTest/source/PAX_GRAPHICA/Components/GenericSpline2DImplIncludeTest.cpp create mode 100644 Projects/IncludeTest/source/PAX_GRAPHICA/Interface/Spline2DImplIncludeTest.cpp create mode 100644 Projects/IncludeTest/source/PAX_GRAPHICA/Siv3D/Siv3DSpline2DImplIncludeTest.cpp delete mode 100644 Projects/IncludeTest/source/PAX_GRAPHICA/SystemIncludeTest.cpp diff --git a/Library/PAX_GRAPHICA/Components/GenericSpline2DImpl.hpp b/Library/PAX_GRAPHICA/Components/GenericSpline2DImpl.hpp new file mode 100644 index 000000000..66e421928 --- /dev/null +++ b/Library/PAX_GRAPHICA/Components/GenericSpline2DImpl.hpp @@ -0,0 +1,225 @@ +/*########################################################################################## + + PAX SAPIENTICA Library 💀🌿🌏 + + [Planning] 2023-2024 As Project + [Production] 2023-2024 As Project + [Contact Us] wanotaitei@gmail.com https://github.com/AsPJT/PAX_SAPIENTICA + [License] Distributed under the CC0 1.0. https://creativecommons.org/publicdomain/zero/1.0/ + +##########################################################################################*/ + +#ifndef PAX_GRAPHICA_COMPONENTS_GENERIC_SPLINE_2D_IMPL_HPP +#define PAX_GRAPHICA_COMPONENTS_GENERIC_SPLINE_2D_IMPL_HPP + +#include + +#include +#include +#include + +#include + +namespace paxg { + + /// @brief Generic self-implemented 2D spline using Catmull-Rom interpolation + /// @note This implementation is used for SFML, DxLib, and Null (fallback) + class GenericSpline2DImpl : public Spline2DImpl { + private: + std::vector> points_; + bool is_closed_ = false; // 閉じたループかどうか / Whether it's a closed loop + + /// @brief Calculate Catmull-Rom interpolation for a single point + /// @param p0 Point before p1 + /// @param p1 Start point of the segment + /// @param p2 End point of the segment + /// @param p3 Point after p2 + /// @param t Interpolation parameter [0, 1] + /// @return Interpolated point + static paxs::Vector2 calculateCatmullRom( + const paxs::Vector2& p0, + const paxs::Vector2& p1, + const paxs::Vector2& p2, + const paxs::Vector2& p3, + float t) { + float t2 = t * t; + float t3 = t2 * t; + + float v0 = (p2.x - p0.x) * 0.5f; + float v1 = (p3.x - p1.x) * 0.5f; + float x = (2 * p1.x - 2 * p2.x + v0 + v1) * t3 + (-3 * p1.x + 3 * p2.x - 2 * v0 - v1) * t2 + v0 * t + p1.x; + + v0 = (p2.y - p0.y) * 0.5f; + v1 = (p3.y - p1.y) * 0.5f; + float y = (2 * p1.y - 2 * p2.y + v0 + v1) * t3 + (-3 * p1.y + 3 * p2.y - 2 * v0 - v1) * t2 + v0 * t + p1.y; + + return { x, y }; + } + + /// @brief 閉じたループかどうかを自動判定し、重複する最後の点を除去 + /// @brief Automatically detect closed loop and remove duplicate last point + /// @param points Point list to check + /// @return true if closed loop detected (and duplicate removed) + bool detectAndFixClosedLoop(std::vector>& points) const { + if (points.size() < 3) return false; + + const paxs::Vector2& first = points.front(); + const paxs::Vector2& last = points.back(); + // 最初と最後の点が十分近ければ閉じたループとみなす + // Consider it a closed loop if first and last points are close enough + constexpr float threshold = 0.1f; + float dx = first.x - last.x; + float dy = first.y - last.y; + float dist_sq = dx * dx + dy * dy; + + if (dist_sq < threshold * threshold) { + // 閉じたループの場合、最後の重複点を除去 + // Remove duplicate last point for closed loops + points.pop_back(); + return true; + } + + return false; + } + + public: + /// @brief Constructor with Vector2 points + /// @param points Control points for the spline + /// @param is_closed Whether the spline is explicitly a closed loop + GenericSpline2DImpl(const std::vector>& points, bool is_closed = false) { + for (const auto& p : points) { + points_.emplace_back(static_cast(p.x), static_cast(p.y)); + } + + // 閉じたループを自動判定し、重複する最後の点を除去 + // Auto-detect closed loop and remove duplicate last point + if (!is_closed) { + is_closed_ = detectAndFixClosedLoop(points_); + } else { + is_closed_ = true; + // 明示的に閉じたループが指定された場合も重複チェック + // Also check for duplicates when explicitly specified as closed + if (points_.size() >= 2) { + const paxs::Vector2& first = points_.front(); + const paxs::Vector2& last = points_.back(); + constexpr float threshold = 0.1f; + float dx = first.x - last.x; + float dy = first.y - last.y; + float dist_sq = dx * dx + dy * dy; + + if (dist_sq < threshold * threshold) { + points_.pop_back(); + } + } + } + } + + /// @brief Constructor with Vector2 points + /// @param points Control points for the spline + /// @param is_closed Whether the spline is explicitly a closed loop + GenericSpline2DImpl(const std::vector>& points, bool is_closed = false) + : points_(points) { + // 閉じたループを自動判定し、重複する最後の点を除去 + // Auto-detect closed loop and remove duplicate last point + if (!is_closed) { + is_closed_ = detectAndFixClosedLoop(points_); + } else { + is_closed_ = true; + // 明示的に閉じたループが指定された場合も重複チェック + // Also check for duplicates when explicitly specified as closed + if (points_.size() >= 2) { + const paxs::Vector2& first = points_.front(); + const paxs::Vector2& last = points_.back(); + constexpr float threshold = 0.1f; + float dx = first.x - last.x; + float dy = first.y - last.y; + float dist_sq = dx * dx + dy * dy; + + if (dist_sq < threshold * threshold) { + points_.pop_back(); + } + } + } + } + + /// @brief Constructor with Vector2 points + /// @param points Control points for the spline + /// @param is_closed Whether the spline is explicitly a closed loop + GenericSpline2DImpl(const std::vector>& points, bool is_closed = false) { + for (const auto& p : points) { + points_.emplace_back(static_cast(p.x), static_cast(p.y)); + } + + // 閉じたループを自動判定し、重複する最後の点を除去 + // Auto-detect closed loop and remove duplicate last point + if (!is_closed) { + is_closed_ = detectAndFixClosedLoop(points_); + } else { + is_closed_ = true; + // 明示的に閉じたループが指定された場合も重複チェック + // Also check for duplicates when explicitly specified as closed + if (points_.size() >= 2) { + const paxs::Vector2& first = points_.front(); + const paxs::Vector2& last = points_.back(); + constexpr float threshold = 0.1f; + float dx = first.x - last.x; + float dy = first.y - last.y; + float dist_sq = dx * dx + dy * dy; + + if (dist_sq < threshold * threshold) { + points_.pop_back(); + } + } + } + } + + /// @brief Draw the spline with specified thickness and color + /// @param thickness Line thickness + /// @param color Line color + void draw(double thickness, const Color& color) const override { + if (points_.size() < 2) return; + + const int divisions = 20; + const std::size_t point_count = points_.size(); + + // 閉じたループの場合、最後の点から最初の点への繋ぎも描画 + // For closed loops, also draw the connection from the last point to the first + const std::size_t loop_count = is_closed_ ? point_count : (point_count - 1); + + for (std::size_t i = 0; i < loop_count; ++i) { + // 閉じたループの場合、インデックスを循環させる + // For closed loops, wrap indices around + paxs::Vector2 p0, p1, p2, p3; + + if (is_closed_) { + // 閉じたループ:全ての点でモジュロ演算を使用 + // Closed loop: use modulo for all point indices + p0 = points_[(i + point_count - 1) % point_count]; + p1 = points_[i]; + p2 = points_[(i + 1) % point_count]; + p3 = points_[(i + 2) % point_count]; + } else { + // 開いた曲線:既存のロジック + // Open curve: existing logic + p0 = (i == 0) ? points_[0] : points_[i - 1]; + p1 = points_[i]; + p2 = points_[i + 1]; + p3 = (i + 2 >= point_count) ? points_[i + 1] : points_[i + 2]; + } + + paxs::Vector2 current_pos = p1; + + for (int j = 1; j <= divisions; ++j) { + float t = static_cast(j) / divisions; + paxs::Vector2 next_pos = calculateCatmullRom(p0, p1, p2, p3, t); + paxg::Line(current_pos.x, current_pos.y, next_pos.x, next_pos.y).draw(thickness, color); + + current_pos = next_pos; + } + } + } + }; + +} // namespace paxg + +#endif // !PAX_GRAPHICA_COMPONENTS_GENERIC_SPLINE_2D_IMPL_HPP diff --git a/Library/PAX_GRAPHICA/DxLib/DxLibTextureImpl.hpp b/Library/PAX_GRAPHICA/DxLib/DxLibTextureImpl.hpp index d3c428c5b..44ed1873d 100644 --- a/Library/PAX_GRAPHICA/DxLib/DxLibTextureImpl.hpp +++ b/Library/PAX_GRAPHICA/DxLib/DxLibTextureImpl.hpp @@ -12,8 +12,7 @@ #ifndef PAX_GRAPHICA_DXLIB_TEXTURE_IMPL_HPP #define PAX_GRAPHICA_DXLIB_TEXTURE_IMPL_HPP -#if defined(PAXS_USING_DXLIB) - +#ifdef PAXS_USING_DXLIB #include #include @@ -200,6 +199,6 @@ namespace paxg { } // namespace paxg -#endif // defined(PAXS_USING_DXLIB) +#endif // PAXS_USING_DXLIB #endif // !PAX_GRAPHICA_DXLIB_TEXTURE_IMPL_HPP diff --git a/Library/PAX_GRAPHICA/DxLib/DxLibWindowImpl.hpp b/Library/PAX_GRAPHICA/DxLib/DxLibWindowImpl.hpp index f17780c56..f281ca1fd 100644 --- a/Library/PAX_GRAPHICA/DxLib/DxLibWindowImpl.hpp +++ b/Library/PAX_GRAPHICA/DxLib/DxLibWindowImpl.hpp @@ -12,8 +12,7 @@ #ifndef PAX_GRAPHICA_DXLIB_WINDOW_IMPL_HPP #define PAX_GRAPHICA_DXLIB_WINDOW_IMPL_HPP -#if defined(PAXS_USING_DXLIB) - +#ifdef PAXS_USING_DXLIB #include #include diff --git a/Library/PAX_GRAPHICA/Interface/Spline2DImpl.hpp b/Library/PAX_GRAPHICA/Interface/Spline2DImpl.hpp new file mode 100644 index 000000000..979e60c8d --- /dev/null +++ b/Library/PAX_GRAPHICA/Interface/Spline2DImpl.hpp @@ -0,0 +1,33 @@ +/*########################################################################################## + + PAX SAPIENTICA Library 💀🌿🌏 + + [Planning] 2023-2024 As Project + [Production] 2023-2024 As Project + [Contact Us] wanotaitei@gmail.com https://github.com/AsPJT/PAX_SAPIENTICA + [License] Distributed under the CC0 1.0. https://creativecommons.org/publicdomain/zero/1.0/ + +##########################################################################################*/ + +#ifndef PAX_GRAPHICA_INTERFACE_SPLINE_2D_IMPL_HPP +#define PAX_GRAPHICA_INTERFACE_SPLINE_2D_IMPL_HPP + +#include + +namespace paxg { + + /// @brief Abstract interface for 2D spline implementations + /// @note Different graphics libraries may have different spline implementations + class Spline2DImpl { + public: + virtual ~Spline2DImpl() = default; + + /// @brief Draw the spline with specified thickness and color + /// @param thickness Line thickness + /// @param color Line color + virtual void draw(double thickness, const Color& color) const = 0; + }; + +} // namespace paxg + +#endif // !PAX_GRAPHICA_INTERFACE_SPLINE_2D_IMPL_HPP diff --git a/Library/PAX_GRAPHICA/Network.hpp b/Library/PAX_GRAPHICA/Network.hpp index 5bce7f4d7..e33245e4d 100644 --- a/Library/PAX_GRAPHICA/Network.hpp +++ b/Library/PAX_GRAPHICA/Network.hpp @@ -22,6 +22,7 @@ #include #elif defined(PAXS_USING_SFML) +#include #include #include @@ -37,13 +38,63 @@ #include #endif // PAXS_PLATFORM_MACOS, PAXS_PLATFORM_WINDOWS, PAXS_PLATFORM_LINUX -#endif // PAXS_USING_SFML + +#elif defined(PAXS_USING_DXLIB) +#include + +#endif // PAXS_USING_SIV3D, PAXS_USING_SFML, PAXS_USING_DXLIB namespace paxg { /// @brief ネットワーク関連の機能を提供するクラス class Network { public: + /// @brief URLをブラウザで開く + /// @param url 開くURL + /// @return 成功した場合true + static bool launchBrowser(const std::string& url) { +#if defined(PAXS_USING_SIV3D) + return s3d::System::LaunchBrowser(s3d::Unicode::FromUTF8(url)); +#elif defined(PAXS_USING_SFML) + // macOS +#if defined(PAXS_PLATFORM_MACOS) + std::string command = "open \"" + url + "\""; + return std::system(command.c_str()) == 0; +#elif defined(PAXS_PLATFORM_WINDOWS) + // Windows + std::string command = "start \"\" \"" + url + "\""; + return std::system(command.c_str()) == 0; +#elif defined(PAXS_PLATFORM_LINUX) + // Linux + std::string command = "xdg-open \"" + url + "\""; + return std::system(command.c_str()) == 0; +#else + (void)url; + return false; +#endif +#elif defined(PAXS_USING_DXLIB) +#if defined(PAXS_PLATFORM_ANDROID) + // Android - JNI経由でブラウザを開く + // Note: 実装には ANativeActivity へのアクセスが必要 + // 現時点ではスタブとして false を返す + (void)url; + return false; +#else + // Windows/その他のDxLib環境 +#if defined(PAXS_PLATFORM_WINDOWS) + std::string command = "start \"\" \"" + url + "\""; + return std::system(command.c_str()) == 0; +#else + (void)url; + return false; +#endif // PAXS_PLATFORM_WINDOWS +#endif // PAXS_PLATFORM_ANDROID +#else + (void)url; + return false; +#endif + } + /// @brief URLからファイルをダウンロードして保存する /// @param url ダウンロード元のURL /// @param save_path 保存先のファイルパス(アセットルートからの相対パス) diff --git a/Library/PAX_GRAPHICA/SFML/SFMLTextureImpl.hpp b/Library/PAX_GRAPHICA/SFML/SFMLTextureImpl.hpp index e31d0ed22..fe347b8bf 100644 --- a/Library/PAX_GRAPHICA/SFML/SFMLTextureImpl.hpp +++ b/Library/PAX_GRAPHICA/SFML/SFMLTextureImpl.hpp @@ -12,8 +12,7 @@ #ifndef PAX_GRAPHICA_SFML_TEXTURE_IMPL_HPP #define PAX_GRAPHICA_SFML_TEXTURE_IMPL_HPP -#if defined(PAXS_USING_SFML) - +#ifdef PAXS_USING_SFML #include // std::min を使用するために追加 #include // std::min がfloatで曖昧な場合のため (fminでも可) @@ -174,6 +173,6 @@ namespace paxg { } // namespace paxg -#endif // defined(PAXS_USING_SFML) +#endif // PAXS_USING_SFML #endif // !PAX_GRAPHICA_SFML_TEXTURE_IMPL_HPP diff --git a/Library/PAX_GRAPHICA/SFML/SFMLWindowImpl.hpp b/Library/PAX_GRAPHICA/SFML/SFMLWindowImpl.hpp index 3bf1c638c..e5e8ee7db 100644 --- a/Library/PAX_GRAPHICA/SFML/SFMLWindowImpl.hpp +++ b/Library/PAX_GRAPHICA/SFML/SFMLWindowImpl.hpp @@ -12,8 +12,7 @@ #ifndef PAX_GRAPHICA_SFML_WINDOW_IMPL_HPP #define PAX_GRAPHICA_SFML_WINDOW_IMPL_HPP -#if defined(PAXS_USING_SFML) - +#ifdef PAXS_USING_SFML #include #include diff --git a/Library/PAX_GRAPHICA/Siv3D/Siv3DRenderTextureImpl.hpp b/Library/PAX_GRAPHICA/Siv3D/Siv3DRenderTextureImpl.hpp index 93489ce1c..101fb2774 100644 --- a/Library/PAX_GRAPHICA/Siv3D/Siv3DRenderTextureImpl.hpp +++ b/Library/PAX_GRAPHICA/Siv3D/Siv3DRenderTextureImpl.hpp @@ -12,7 +12,7 @@ #ifndef PAX_GRAPHICA_SIV3D_RENDER_TEXTURE_IMPL_HPP #define PAX_GRAPHICA_SIV3D_RENDER_TEXTURE_IMPL_HPP -#if defined(PAXS_USING_SIV3D) +#ifdef PAXS_USING_SIV3D #include #include diff --git a/Library/PAX_GRAPHICA/Siv3D/Siv3DSpline2DImpl.hpp b/Library/PAX_GRAPHICA/Siv3D/Siv3DSpline2DImpl.hpp new file mode 100644 index 000000000..677459f1d --- /dev/null +++ b/Library/PAX_GRAPHICA/Siv3D/Siv3DSpline2DImpl.hpp @@ -0,0 +1,83 @@ +/*########################################################################################## + + PAX SAPIENTICA Library 💀🌿🌏 + + [Planning] 2023-2024 As Project + [Production] 2023-2024 As Project + [Contact Us] wanotaitei@gmail.com https://github.com/AsPJT/PAX_SAPIENTICA + [License] Distributed under the CC0 1.0. https://creativecommons.org/publicdomain/zero/1.0/ + +##########################################################################################*/ + +#ifndef PAX_GRAPHICA_SIV3D_SPLINE_2D_IMPL_HPP +#define PAX_GRAPHICA_SIV3D_SPLINE_2D_IMPL_HPP + +#ifdef PAXS_USING_SIV3D +#include + +#include + +#include +#include +#include + +namespace paxg { + + /// @brief Siv3D-specific implementation of 2D spline using s3d::Spline2D + class Siv3DSpline2DImpl : public Spline2DImpl { + private: + s3d::Spline2D spline; + + public: + /// @brief Constructor with Vector2 points + /// @param points Control points for the spline + /// @param is_closed Whether the spline is a closed loop (unused for Siv3D) + Siv3DSpline2DImpl(const std::vector>& points, bool /*is_closed*/ = false) { + s3d::Array siv3d_points; + for (const auto& p : points) { + siv3d_points << s3d::Vec2{ p.x, p.y }; + } + spline = s3d::Spline2D(siv3d_points); + } + + /// @brief Constructor with Vector2 points + /// @param points Control points for the spline + /// @param is_closed Whether the spline is a closed loop (unused for Siv3D) + Siv3DSpline2DImpl(const std::vector>& points, bool /*is_closed*/ = false) { + s3d::Array siv3d_points; + for (const auto& p : points) { + siv3d_points << s3d::Vec2{ p.x, p.y }; + } + spline = s3d::Spline2D(siv3d_points); + } + + /// @brief Constructor with Vector2 points + /// @param points Control points for the spline + /// @param is_closed Whether the spline is a closed loop (unused for Siv3D) + Siv3DSpline2DImpl(const std::vector>& points, bool /*is_closed*/ = false) { + s3d::Array siv3d_points; + for (const auto& p : points) { + siv3d_points << s3d::Vec2{ static_cast(p.x), static_cast(p.y) }; + } + spline = s3d::Spline2D(siv3d_points); + } + + /// @brief Draw the spline with specified thickness and color + /// @param thickness Line thickness + /// @param color Line color + void draw(double thickness, const Color& color) const override { + spline.draw(thickness, s3d::ColorF(color)); + } + + /// @brief Get the native Siv3D spline object + /// @return Reference to the s3d::Spline2D object + const s3d::Spline2D& getNativeSpline() const { + return spline; + } + }; + +} // namespace paxg + +#endif // PAXS_USING_SIV3D + +#endif // !PAX_GRAPHICA_SIV3D_SPLINE_2D_IMPL_HPP diff --git a/Library/PAX_GRAPHICA/Siv3D/Siv3DTextureImpl.hpp b/Library/PAX_GRAPHICA/Siv3D/Siv3DTextureImpl.hpp index f5212ed92..f4c344012 100644 --- a/Library/PAX_GRAPHICA/Siv3D/Siv3DTextureImpl.hpp +++ b/Library/PAX_GRAPHICA/Siv3D/Siv3DTextureImpl.hpp @@ -12,8 +12,7 @@ #ifndef PAX_GRAPHICA_SIV3D_TEXTURE_IMPL_HPP #define PAX_GRAPHICA_SIV3D_TEXTURE_IMPL_HPP -#if defined(PAXS_USING_SIV3D) - +#ifdef PAXS_USING_SIV3D #include #include diff --git a/Library/PAX_GRAPHICA/Siv3D/Siv3DWindowImpl.hpp b/Library/PAX_GRAPHICA/Siv3D/Siv3DWindowImpl.hpp index 8ad1f87f6..dad05aed3 100644 --- a/Library/PAX_GRAPHICA/Siv3D/Siv3DWindowImpl.hpp +++ b/Library/PAX_GRAPHICA/Siv3D/Siv3DWindowImpl.hpp @@ -12,8 +12,7 @@ #ifndef PAX_GRAPHICA_SIV3D_WINDOW_IMPL_HPP #define PAX_GRAPHICA_SIV3D_WINDOW_IMPL_HPP -#if defined(PAXS_USING_SIV3D) - +#ifdef PAXS_USING_SIV3D #include #include diff --git a/Library/PAX_GRAPHICA/Spline2D.hpp b/Library/PAX_GRAPHICA/Spline2D.hpp index 01277b2b9..590f9a193 100644 --- a/Library/PAX_GRAPHICA/Spline2D.hpp +++ b/Library/PAX_GRAPHICA/Spline2D.hpp @@ -12,232 +12,89 @@ #ifndef PAX_GRAPHICA_SPLINE_2D_HPP #define PAX_GRAPHICA_SPLINE_2D_HPP -#include -#include - -#if defined(PAXS_USING_SIV3D) -#include -#elif defined(PAXS_USING_DXLIB) -#include -#elif defined(PAXS_USING_SFML) -#include -#endif +#include #include -#include +#include #include +#if defined(PAXS_USING_SIV3D) +#include +#else +#include +#endif + namespace paxg { - /// @brief 2Dスプライン曲線クラス + /// @brief 2D spline class with Pimpl idiom for graphics library abstraction + /// @note Uses shared_ptr for value semantics and automatic resource management + /// @note Siv3D uses native s3d::Spline2D, others use self-implemented Catmull-Rom interpolation class Spline2D { private: -#ifdef PAXS_USING_SIV3D - s3d::Spline2D spline; + std::shared_ptr impl; + + /// @brief Create implementation based on the active graphics library + /// @tparam T Vector component type (int, float, or double) + /// @param points Control points for the spline + /// @param is_closed Whether the spline is a closed loop + /// @return Shared pointer to the implementation + template + static std::shared_ptr createImpl(const std::vector>& points, bool is_closed) { +#if defined(PAXS_USING_SIV3D) + return std::make_shared(points, is_closed); #else - std::vector> points_; - bool is_closed_ = false; // 閉じたループかどうか / Whether it's a closed loop + return std::make_shared(points, is_closed); #endif - - static paxs::Vector2 calculateCatmullRom(const paxs::Vector2& p0, const paxs::Vector2& p1, const paxs::Vector2& p2, const paxs::Vector2& p3, float t) { - float t2 = t * t; - float t3 = t2 * t; - - float v0 = (p2.x - p0.x) * 0.5f; - float v1 = (p3.x - p1.x) * 0.5f; - float x = (2 * p1.x - 2 * p2.x + v0 + v1) * t3 + (-3 * p1.x + 3 * p2.x - 2 * v0 - v1) * t2 + v0 * t + p1.x; - - v0 = (p2.y - p0.y) * 0.5f; - v1 = (p3.y - p1.y) * 0.5f; - float y = (2 * p1.y - 2 * p2.y + v0 + v1) * t3 + (-3 * p1.y + 3 * p2.y - 2 * v0 - v1) * t2 + v0 * t + p1.y; - - return { x, y }; - } - - /// @brief 閉じたループかどうかを自動判定し、重複する最後の点を除去 - /// @brief Automatically detect closed loop and remove duplicate last point - /// @return true if closed loop detected (and duplicate removed) - bool detectAndFixClosedLoop(std::vector>& points) const { - if (points.size() < 3) return false; - - const paxs::Vector2& first = points.front(); - const paxs::Vector2& last = points.back(); - // 最初と最後の点が十分近ければ閉じたループとみなす - // Consider it a closed loop if first and last points are close enough - constexpr float threshold = 0.1f; - float dx = first.x - last.x; - float dy = first.y - last.y; - float dist_sq = dx * dx + dy * dy; - - if (dist_sq < threshold * threshold) { - // 閉じたループの場合、最後の重複点を除去 - // Remove duplicate last point for closed loops - points.pop_back(); - return true; - } - - return false; } public: + /// @brief Default constructor Spline2D() = default; - explicit Spline2D(const std::vector>& points, bool is_closed = false) { -#ifdef PAXS_USING_SIV3D - s3d::Array siv3d_points; - for (const auto& p : points) { - siv3d_points << s3d::Vec2{ p.x, p.y }; + /// @brief Constructor with Vector2 points + /// @param points Control points for the spline + /// @param is_closed Whether the spline is a closed loop (default: false, auto-detected for Generic) + explicit Spline2D(const std::vector>& points, bool is_closed = false) + : impl(createImpl(points, is_closed)) {} + + /// @brief Constructor with Vector2 points + /// @param points Control points for the spline + /// @param is_closed Whether the spline is a closed loop (default: false, auto-detected for Generic) + explicit Spline2D(const std::vector>& points, bool is_closed = false) + : impl(createImpl(points, is_closed)) {} + + /// @brief Constructor with Vector2 points + /// @param points Control points for the spline + /// @param is_closed Whether the spline is a closed loop (default: false, auto-detected for Generic) + explicit Spline2D(const std::vector>& points, bool is_closed = false) + : impl(createImpl(points, is_closed)) {} + + /// @brief Draw the spline with specified thickness and color + /// @param thickness Line thickness + /// @param color Line color + void draw(double thickness, const Color& color) const { + if (impl) { + impl->draw(thickness, color); } - spline = s3d::Spline2D(siv3d_points); -#else - for (const auto& p : points) { - points_.emplace_back(static_cast(p.x), static_cast(p.y)); - } - - // 閉じたループを自動判定し、重複する最後の点を除去 - // Auto-detect closed loop and remove duplicate last point - if (!is_closed) { - is_closed_ = detectAndFixClosedLoop(points_); - } else { - is_closed_ = true; - // 明示的に閉じたループが指定された場合も重複チェック - // Also check for duplicates when explicitly specified as closed - if (points_.size() >= 2) { - const paxs::Vector2& first = points_.front(); - const paxs::Vector2& last = points_.back(); - constexpr float threshold = 0.1f; - float dx = first.x - last.x; - float dy = first.y - last.y; - float dist_sq = dx * dx + dy * dy; - - if (dist_sq < threshold * threshold) { - points_.pop_back(); - } - } - } -#endif } - explicit Spline2D(const std::vector>& points, bool is_closed = false) { -#ifdef PAXS_USING_SIV3D - s3d::Array siv3d_points; - for (const auto& p : points) { - siv3d_points << s3d::Vec2{ p.x, p.y }; - } - spline = s3d::Spline2D(siv3d_points); -#else - points_ = points; - // 閉じたループを自動判定し、重複する最後の点を除去 - // Auto-detect closed loop and remove duplicate last point - if (!is_closed) { - is_closed_ = detectAndFixClosedLoop(points_); - } else { - is_closed_ = true; - // 明示的に閉じたループが指定された場合も重複チェック - // Also check for duplicates when explicitly specified as closed - if (points_.size() >= 2) { - const paxs::Vector2& first = points_.front(); - const paxs::Vector2& last = points_.back(); - constexpr float threshold = 0.1f; - float dx = first.x - last.x; - float dy = first.y - last.y; - float dist_sq = dx * dx + dy * dy; - - if (dist_sq < threshold * threshold) { - points_.pop_back(); - } - } - } -#endif + /// @brief Draw the spline with default thickness (1.0) and specified color + /// @param color Line color + void draw(const Color& color) const { + draw(1.0, color); } - explicit Spline2D(const std::vector>& points, bool is_closed = false) { -#ifdef PAXS_USING_SIV3D - s3d::Array siv3d_points; - for (const auto& p : points) { - siv3d_points << s3d::Vec2{ static_cast(p.x), static_cast(p.y) }; - } - spline = s3d::Spline2D(siv3d_points); -#else - for (const auto& p : points) { - points_.emplace_back(static_cast(p.x), static_cast(p.y)); - } - - // 閉じたループを自動判定し、重複する最後の点を除去 - // Auto-detect closed loop and remove duplicate last point - if (!is_closed) { - is_closed_ = detectAndFixClosedLoop(points_); - } else { - is_closed_ = true; - // 明示的に閉じたループが指定された場合も重複チェック - // Also check for duplicates when explicitly specified as closed - if (points_.size() >= 2) { - const paxs::Vector2& first = points_.front(); - const paxs::Vector2& last = points_.back(); - constexpr float threshold = 0.1f; - float dx = first.x - last.x; - float dy = first.y - last.y; - float dist_sq = dx * dx + dy * dy; - - if (dist_sq < threshold * threshold) { - points_.pop_back(); - } - } +#if defined(PAXS_USING_SIV3D) + /// @brief Conversion operator to s3d::Spline2D (Siv3D only) + operator s3d::Spline2D() const { + auto* siv3dImpl = dynamic_cast(impl.get()); + if (siv3dImpl) { + return siv3dImpl->getNativeSpline(); } -#endif + return s3d::Spline2D(); } - - void draw(double thickness, const paxg::Color& color) const { -#ifdef PAXS_USING_SIV3D - spline.draw(thickness, s3d::ColorF(color)); -#else - if (points_.size() < 2) return; - - const int divisions = 20; - const std::size_t point_count = points_.size(); - - // 閉じたループの場合、最後の点から最初の点への繋ぎも描画 - // For closed loops, also draw the connection from the last point to the first - const std::size_t loop_count = is_closed_ ? point_count : (point_count - 1); - - for (std::size_t i = 0; i < loop_count; ++i) { - // 閉じたループの場合、インデックスを循環させる - // For closed loops, wrap indices around - paxs::Vector2 p0, p1, p2, p3; - - if (is_closed_) { - // 閉じたループ:全ての点でモジュロ演算を使用 - // Closed loop: use modulo for all point indices - p0 = points_[(i + point_count - 1) % point_count]; - p1 = points_[i]; - p2 = points_[(i + 1) % point_count]; - p3 = points_[(i + 2) % point_count]; - } else { - // 開いた曲線:既存のロジック - // Open curve: existing logic - p0 = (i == 0) ? points_[0] : points_[i - 1]; - p1 = points_[i]; - p2 = points_[i + 1]; - p3 = (i + 2 >= point_count) ? points_[i + 1] : points_[i + 2]; - } - - paxs::Vector2 current_pos = p1; - - for (int j = 1; j <= divisions; ++j) { - float t = static_cast(j) / divisions; - paxs::Vector2 next_pos = calculateCatmullRom(p0, p1, p2, p3, t); - paxg::Line(current_pos.x, current_pos.y, next_pos.x, next_pos.y).draw(thickness, color); - - current_pos = next_pos; - } - } #endif - } - - void draw(const Color& color) const { - draw(1.0, color); - } }; } // namespace paxg diff --git a/Library/PAX_GRAPHICA/System.hpp b/Library/PAX_GRAPHICA/System.hpp deleted file mode 100644 index 06017a9f3..000000000 --- a/Library/PAX_GRAPHICA/System.hpp +++ /dev/null @@ -1,89 +0,0 @@ -/*########################################################################################## - - PAX SAPIENTICA Library 💀🌿🌏 - - [Planning] 2023-2024 As Project - [Production] 2023-2024 As Project - [Contact Us] wanotaitei@gmail.com https://github.com/AsPJT/PAX_SAPIENTICA - [License] Distributed under the CC0 1.0. https://creativecommons.org/publicdomain/zero/1.0/ - -##########################################################################################*/ - -#ifndef PAX_GRAPHICA_SYSTEM_HPP -#define PAX_GRAPHICA_SYSTEM_HPP - -#include - -#include - -#if defined(PAXS_USING_SIV3D) -#include - -#elif defined(PAXS_USING_SFML) -#include - -#elif defined(PAXS_USING_DXLIB) -#include - -#if defined(PAXS_PLATFORM_ANDROID) -#include -#include -#endif // PAXS_PLATFORM_ANDROID - -#endif - -namespace paxg { - - /// @brief システム関連の機能を提供するクラス - class System { - public: - /// @brief URLをブラウザで開く - /// @param url 開くURL - /// @return 成功した場合true - static bool launchBrowser(const std::string& url) { -#if defined(PAXS_USING_SIV3D) - return s3d::System::LaunchBrowser(s3d::Unicode::FromUTF8(url)); -#elif defined(PAXS_USING_SFML) - // macOS -#if defined(PAXS_PLATFORM_MACOS) - std::string command = "open \"" + url + "\""; - return std::system(command.c_str()) == 0; -#elif defined(PAXS_PLATFORM_WINDOWS) - // Windows - std::string command = "start \"\" \"" + url + "\""; - return std::system(command.c_str()) == 0; -#elif defined(PAXS_PLATFORM_LINUX) - // Linux - std::string command = "xdg-open \"" + url + "\""; - return std::system(command.c_str()) == 0; -#else - (void)url; - return false; -#endif -#elif defined(PAXS_USING_DXLIB) -#if defined(PAXS_PLATFORM_ANDROID) - // Android - JNI経由でブラウザを開く - // Note: 実装には ANativeActivity へのアクセスが必要 - // 現時点ではスタブとして false を返す - (void)url; - return false; -#else - // Windows/その他のDxLib環境 -#if defined(PAXS_PLATFORM_WINDOWS) - std::string command = "start \"\" \"" + url + "\""; - return std::system(command.c_str()) == 0; -#else - (void)url; - return false; -#endif // PAXS_PLATFORM_WINDOWS -#endif // PAXS_USING_DXLIB -#else - (void)url; - return false; -#endif - } - }; - -} // namespace paxg - -#endif // !PAX_GRAPHICA_SYSTEM_HPP diff --git a/Library/PAX_MAHOROBA/UI/MenuBar/GitHubButton.hpp b/Library/PAX_MAHOROBA/UI/MenuBar/GitHubButton.hpp index 680e3f05e..6316ac6b4 100644 --- a/Library/PAX_MAHOROBA/UI/MenuBar/GitHubButton.hpp +++ b/Library/PAX_MAHOROBA/UI/MenuBar/GitHubButton.hpp @@ -12,8 +12,8 @@ #ifndef PAX_MAHOROBA_UI_GITHUB_BUTTON_HPP #define PAX_MAHOROBA_UI_GITHUB_BUTTON_HPP +#include #include -#include #include #include @@ -41,7 +41,7 @@ namespace paxs { // クリック時にGitHubリポジトリを開く if (event.left_button_state == MouseButtonState::Pressed) { - paxg::System::launchBrowser("https://github.com/AsPJT/PAX_SAPIENTICA"); + paxg::Network::launchBrowser("https://github.com/AsPJT/PAX_SAPIENTICA"); } return EventHandlingResult::Handled(); } diff --git a/Library/PAX_MAHOROBA/UI/Widget/UIPanelBackground.hpp b/Library/PAX_MAHOROBA/UI/Widget/UIPanelBackground.hpp index f296ed1d1..d8fcf12aa 100644 --- a/Library/PAX_MAHOROBA/UI/Widget/UIPanelBackground.hpp +++ b/Library/PAX_MAHOROBA/UI/Widget/UIPanelBackground.hpp @@ -19,6 +19,8 @@ #include #include +#include + namespace paxs { /// @brief UIパネルの背景を描画するクラス diff --git a/Projects/IncludeTest/source/PAX_GRAPHICA/Components/GenericSpline2DImplIncludeTest.cpp b/Projects/IncludeTest/source/PAX_GRAPHICA/Components/GenericSpline2DImplIncludeTest.cpp new file mode 100644 index 000000000..77c5d62e6 --- /dev/null +++ b/Projects/IncludeTest/source/PAX_GRAPHICA/Components/GenericSpline2DImplIncludeTest.cpp @@ -0,0 +1,3 @@ +#include + +int main(){} diff --git a/Projects/IncludeTest/source/PAX_GRAPHICA/Interface/Spline2DImplIncludeTest.cpp b/Projects/IncludeTest/source/PAX_GRAPHICA/Interface/Spline2DImplIncludeTest.cpp new file mode 100644 index 000000000..ebf9c5f1f --- /dev/null +++ b/Projects/IncludeTest/source/PAX_GRAPHICA/Interface/Spline2DImplIncludeTest.cpp @@ -0,0 +1,3 @@ +#include + +int main(){} diff --git a/Projects/IncludeTest/source/PAX_GRAPHICA/Siv3D/Siv3DSpline2DImplIncludeTest.cpp b/Projects/IncludeTest/source/PAX_GRAPHICA/Siv3D/Siv3DSpline2DImplIncludeTest.cpp new file mode 100644 index 000000000..6720f389c --- /dev/null +++ b/Projects/IncludeTest/source/PAX_GRAPHICA/Siv3D/Siv3DSpline2DImplIncludeTest.cpp @@ -0,0 +1,3 @@ +#include + +int main(){} diff --git a/Projects/IncludeTest/source/PAX_GRAPHICA/SystemIncludeTest.cpp b/Projects/IncludeTest/source/PAX_GRAPHICA/SystemIncludeTest.cpp deleted file mode 100644 index 8599a5c9a..000000000 --- a/Projects/IncludeTest/source/PAX_GRAPHICA/SystemIncludeTest.cpp +++ /dev/null @@ -1,3 +0,0 @@ -#include - -int main(){} From e5f7321cee4fe10ce9ff6d86d4ab82f76db82ec1 Mon Sep 17 00:00:00 2001 From: guinpen98 Date: Thu, 4 Dec 2025 16:38:11 +0900 Subject: [PATCH 7/9] fix: build error --- Library/PAX_GRAPHICA/Color.hpp | 13 +++++++ Library/PAX_GRAPHICA/Line.hpp | 4 +- Library/PAX_GRAPHICA/Rect.hpp | 4 +- Library/PAX_GRAPHICA/RoundRect.hpp | 38 +++++++++---------- .../PAX_GRAPHICA/Siv3D/Siv3DCircleImpl.hpp | 4 +- Library/PAX_GRAPHICA/Siv3D/Siv3DFontImpl.hpp | 30 +++++++-------- .../PAX_GRAPHICA/Siv3D/Siv3DWindowImpl.hpp | 4 +- Library/PAX_GRAPHICA/Texture.hpp | 2 +- Library/PAX_GRAPHICA/ToggleButton.hpp | 8 ++-- .../Map/Content/Update/UpdateContext.hpp | 6 +-- 10 files changed, 63 insertions(+), 50 deletions(-) diff --git a/Library/PAX_GRAPHICA/Color.hpp b/Library/PAX_GRAPHICA/Color.hpp index c227e4f1b..e53d2b259 100644 --- a/Library/PAX_GRAPHICA/Color.hpp +++ b/Library/PAX_GRAPHICA/Color.hpp @@ -50,6 +50,19 @@ namespace paxg { constexpr ColorT(T rgb, T a_ = std::is_same_v ? T(255) : T(1.0)) : r(rgb), g(rgb), b(rgb), a(a_) {} + /// @brief Conversion constructor from ColorT to ColorT + /// @brief ColorTからColorTへの変換コンストラクタ + template + constexpr ColorT(const ColorT& other, typename std::enable_if_t>* = nullptr) + : r(other.r / 255.0), g(other.g / 255.0), b(other.b / 255.0), a(other.a / 255.0) {} + + /// @brief Conversion constructor from ColorT to ColorT + /// @brief ColorTからColorTへの変換コンストラクタ + template + constexpr ColorT(const ColorT& other, typename std::enable_if_t>* = nullptr) + : r(static_cast(other.r * 255.0)), g(static_cast(other.g * 255.0)), + b(static_cast(other.b * 255.0)), a(static_cast(other.a * 255.0)) {} + #if defined(PAXS_USING_SIV3D) // Siv3D conversion operators // Use std::conditional to select the correct Siv3D type based on T diff --git a/Library/PAX_GRAPHICA/Line.hpp b/Library/PAX_GRAPHICA/Line.hpp index 40abc0357..769ac671e 100644 --- a/Library/PAX_GRAPHICA/Line.hpp +++ b/Library/PAX_GRAPHICA/Line.hpp @@ -45,11 +45,11 @@ namespace paxg { : line(static_cast(s.x), static_cast(s.y), static_cast(e.x), static_cast(e.y)) {} void draw(const double thickness, const paxg::Color& color) const { - line.draw(thickness, color); + line.draw(thickness, paxg::ColorF(color)); } void drawArrow(const double thickness, const paxs::Vector2& arrowSize, const paxg::Color& color) const { - line.drawArrow(thickness, s3d::Vec2(arrowSize.x, arrowSize.y), color); + line.drawArrow(thickness, s3d::Vec2(arrowSize.x, arrowSize.y), paxg::ColorF(color)); } #elif defined(PAXS_USING_DXLIB) diff --git a/Library/PAX_GRAPHICA/Rect.hpp b/Library/PAX_GRAPHICA/Rect.hpp index 48fdcc88f..031d18031 100644 --- a/Library/PAX_GRAPHICA/Rect.hpp +++ b/Library/PAX_GRAPHICA/Rect.hpp @@ -169,7 +169,7 @@ namespace paxg { #if defined(PAXS_USING_SIV3D) void draw(const paxg::Color& c_) const { - rect.draw(c_); + rect.draw(paxg::ColorF(c_)); } #elif defined(PAXS_USING_DXLIB) void draw(const paxg::Color& c_) const { @@ -287,7 +287,7 @@ namespace paxg { #if defined(PAXS_USING_SIV3D) void drawFrame(const double inner_thickness, const double outer_thickness, const paxg::Color& color_) const { - rect.drawFrame(inner_thickness, outer_thickness, color_); + rect.drawFrame(inner_thickness, outer_thickness, paxg::ColorF(color_)); } #elif defined(PAXS_USING_DXLIB) diff --git a/Library/PAX_GRAPHICA/RoundRect.hpp b/Library/PAX_GRAPHICA/RoundRect.hpp index 060654c90..8fa7c44eb 100644 --- a/Library/PAX_GRAPHICA/RoundRect.hpp +++ b/Library/PAX_GRAPHICA/RoundRect.hpp @@ -251,7 +251,7 @@ namespace paxg { #elif defined(PAXS_USING_DXLIB) DxLib::DrawRoundRect( - static_cast(x0), static_cast(y0), static_cast(x0 + w0), static_cast(y0 + h0), r0, r0, + pos_.x, pos_.y, pos_.x + size_.x, pos_.y + size_.y, r0, r0, DxLib::GetColor(255, 255, 255), TRUE); #elif defined(PAXS_USING_SFML) @@ -263,12 +263,12 @@ namespace paxg { #if defined(PAXS_USING_SIV3D) void draw(const paxg::Color& c_) const { - rect.draw(c_); + rect.draw(paxg::ColorF(c_)); } #elif defined(PAXS_USING_DXLIB) void draw(const paxg::Color& c_) const { DxLib::DrawRoundRect( - static_cast(x0), static_cast(y0), static_cast(x0 + w0), static_cast(y0 + h0), r0, r0, + pos_.x, pos_.y, pos_.x + size_.x, pos_.y + size_.y, r0, r0, DxLib::GetColor(c_.r, c_.g, c_.b), TRUE); } #elif defined(PAXS_USING_SFML) @@ -331,10 +331,10 @@ namespace paxg { // DxLibの実装も影が広がるように DxLib::DrawRoundRect( - static_cast(x0 + offset.x - i), - static_cast(y0 + offset.y - i), - static_cast(x0 + w0 + offset.x + i), - static_cast(y0 + h0 + offset.y + i), + pos_.x + offset.x - i, + pos_.y + offset.y - i, + pos_.x + size_.x + offset.x + i, + pos_.y + size_.y + offset.y + i, r0 + i, r0 + i, // 角の丸みも広げる DxLib::GetColor(0, 0, 0), TRUE @@ -356,7 +356,7 @@ namespace paxg { // rect.draw(); // 元のコードでもコメントアウトされていた #elif defined(PAXS_USING_DXLIB) DxLib::DrawRoundRect( - static_cast(x0 - w0 / 2), static_cast(y0 - h0 / 2), static_cast(x0 + w0 / 2), static_cast(y0 + h0 / 2), r0, r0, + pos_.x - size_.x / 2, pos_.y - size_.y / 2, pos_.x + size_.x / 2, pos_.y + size_.y / 2, r0, r0, DxLib::GetColor(255, 255, 255), TRUE); #elif defined(PAXS_USING_SFML) @@ -375,7 +375,7 @@ namespace paxg { #elif defined(PAXS_USING_DXLIB) void drawAt(const paxg::Color& c_) const { DxLib::DrawRoundRect( - static_cast(x0 - w0 / 2), static_cast(y0 - h0 / 2), static_cast(x0 + w0 / 2), static_cast(y0 + h0 / 2), r0, r0, + pos_.x - size_.x / 2, pos_.y - size_.y / 2, pos_.x + size_.x / 2, pos_.y + size_.y / 2, r0, r0, DxLib::GetColor(c_.r, c_.g, c_.b), TRUE); } #elif defined(PAXS_USING_SFML) @@ -392,26 +392,26 @@ namespace paxg { #if defined(PAXS_USING_SIV3D) void drawFrame(const double inner_thickness, const double outer_thickness, const paxg::Color& color_) const { - rect.drawFrame(inner_thickness, outer_thickness, color_); + rect.drawFrame(inner_thickness, outer_thickness, paxg::ColorF(color_)); } #elif defined(PAXS_USING_DXLIB) void drawFrame(const double inner_thickness, const double outer_thickness, const paxg::Color& color_) const { DxLib::DrawBox( - static_cast(x0 - outer_thickness), static_cast(y0 - outer_thickness), - static_cast(x0 + w0 + outer_thickness), static_cast(y0 + inner_thickness), + static_cast(pos_.x - outer_thickness), static_cast(pos_.y - outer_thickness), + static_cast(pos_.x + size_.x + outer_thickness), static_cast(pos_.y + inner_thickness), DxLib::GetColor(color_.r, color_.g, color_.b), TRUE); DxLib::DrawBox( - static_cast(x0 - outer_thickness), static_cast(y0 + h0 - inner_thickness), - static_cast(x0 + w0 + outer_thickness), static_cast(y0 + h0 + outer_thickness), + static_cast(pos_.x - outer_thickness), static_cast(pos_.y + size_.y - inner_thickness), + static_cast(pos_.x + size_.x + outer_thickness), static_cast(pos_.y + size_.y + outer_thickness), DxLib::GetColor(color_.r, color_.g, color_.b), TRUE); DxLib::DrawBox( - static_cast(x0 - outer_thickness), static_cast(y0 - outer_thickness), - static_cast(x0 + inner_thickness), static_cast(y0 + h0 + outer_thickness), + static_cast(pos_.x - outer_thickness), static_cast(pos_.y - outer_thickness), + static_cast(pos_.x + inner_thickness), static_cast(pos_.y + size_.y + outer_thickness), DxLib::GetColor(color_.r, color_.g, color_.b), TRUE); DxLib::DrawBox( - static_cast(x0 + w0 - inner_thickness), static_cast(y0 - outer_thickness), - static_cast(x0 + w0 + outer_thickness), static_cast(y0 + h0 + outer_thickness), + static_cast(pos_.x + size_.x - inner_thickness), static_cast(pos_.y - outer_thickness), + static_cast(pos_.x + size_.x + outer_thickness), static_cast(pos_.y + size_.y + outer_thickness), DxLib::GetColor(color_.r, color_.g, color_.b), TRUE); } @@ -457,7 +457,7 @@ namespace paxg { #elif defined(PAXS_USING_DXLIB) int mx = 0, my = 0; DxLib::GetMousePoint(&mx, &my); - return (mx >= x0 && my >= y0 && mx < x0 + w0 && my < y0 + h0); + return (mx >= pos_.x && my >= pos_.y && mx < pos_.x + size_.x && my < pos_.y + size_.y); #elif defined(PAXS_USING_SFML) return sf::RectangleShape{}.getGlobalBounds().contains( diff --git a/Library/PAX_GRAPHICA/Siv3D/Siv3DCircleImpl.hpp b/Library/PAX_GRAPHICA/Siv3D/Siv3DCircleImpl.hpp index b899e1c99..dc50c2704 100644 --- a/Library/PAX_GRAPHICA/Siv3D/Siv3DCircleImpl.hpp +++ b/Library/PAX_GRAPHICA/Siv3D/Siv3DCircleImpl.hpp @@ -39,8 +39,8 @@ namespace paxg { /// @brief Draw the circle with specified color /// @param color The color to draw the circle - void draw(const Color& color) const override { - circle.draw(color); + void draw(const paxg::Color& color) const override { + circle.draw(paxg::ColorF(color)); } /// @brief Get the position of the circle center diff --git a/Library/PAX_GRAPHICA/Siv3D/Siv3DFontImpl.hpp b/Library/PAX_GRAPHICA/Siv3D/Siv3DFontImpl.hpp index 79a4434e0..b38f9ce4d 100644 --- a/Library/PAX_GRAPHICA/Siv3D/Siv3DFontImpl.hpp +++ b/Library/PAX_GRAPHICA/Siv3D/Siv3DFontImpl.hpp @@ -42,7 +42,7 @@ namespace paxg { void setOutline(double inner, double outer, const Color& color) override { is_outline = true; - outline = s3d::TextStyle::Outline(inner, outer, color); + outline = s3d::TextStyle::Outline(inner, outer, paxg::ColorF(color)); } void drawBottomLeft(const std::string& str, const paxs::Vector2& pos, const Color& color) const override { @@ -50,12 +50,12 @@ namespace paxg { font(s3d::Unicode::FromUTF8(str)).draw( outline, s3d::Arg::bottomLeft = s3d::Vec2(pos.x, pos.y), - color); + paxg::ColorF(color)); } else { font(s3d::Unicode::FromUTF8(str)).draw( s3d::Arg::bottomLeft = s3d::Vec2(pos.x, pos.y), - color); + paxg::ColorF(color)); } } @@ -64,12 +64,12 @@ namespace paxg { font(s3d::Unicode::FromUTF8(str)).draw( outline, s3d::Arg::topRight = s3d::Vec2(pos.x, pos.y), - color); + paxg::ColorF(color)); } else { font(s3d::Unicode::FromUTF8(str)).draw( s3d::Arg::topRight = s3d::Vec2(pos.x, pos.y), - color); + paxg::ColorF(color)); } } @@ -78,12 +78,12 @@ namespace paxg { font(s3d::Unicode::FromUTF8(str)).draw( outline, s3d::Arg::bottomRight = s3d::Vec2(pos.x, pos.y), - color); + paxg::ColorF(color)); } else { font(s3d::Unicode::FromUTF8(str)).draw( s3d::Arg::bottomRight = s3d::Vec2(pos.x, pos.y), - color); + paxg::ColorF(color)); } } @@ -92,12 +92,12 @@ namespace paxg { font(s3d::Unicode::FromUTF8(str)).draw( outline, s3d::Vec2(pos.x, pos.y), - color); + paxg::ColorF(color)); } else { font(s3d::Unicode::FromUTF8(str)).draw( s3d::Vec2(pos.x, pos.y), - color); + paxg::ColorF(color)); } } @@ -106,12 +106,12 @@ namespace paxg { font(s3d::Unicode::FromUTF8(str)).draw( outline, s3d::Arg::bottomCenter = s3d::Vec2(pos.x, pos.y), - color); + paxg::ColorF(color)); } else { font(s3d::Unicode::FromUTF8(str)).draw( s3d::Arg::bottomCenter = s3d::Vec2(pos.x, pos.y), - color); + paxg::ColorF(color)); } } @@ -120,12 +120,12 @@ namespace paxg { font(s3d::Unicode::FromUTF8(str)).draw( outline, s3d::Arg::topCenter = s3d::Vec2(pos.x, pos.y), - color); + paxg::ColorF(color)); } else { font(s3d::Unicode::FromUTF8(str)).draw( s3d::Arg::topCenter = s3d::Vec2(pos.x, pos.y), - color); + paxg::ColorF(color)); } } @@ -134,12 +134,12 @@ namespace paxg { font(s3d::Unicode::FromUTF8(str)).drawAt( outline, s3d::Vec2(pos.x, pos.y), - color); + paxg::ColorF(color)); } else { font(s3d::Unicode::FromUTF8(str)).drawAt( s3d::Vec2(pos.x, pos.y), - color); + paxg::ColorF(color)); } } diff --git a/Library/PAX_GRAPHICA/Siv3D/Siv3DWindowImpl.hpp b/Library/PAX_GRAPHICA/Siv3D/Siv3DWindowImpl.hpp index dad05aed3..a661057d8 100644 --- a/Library/PAX_GRAPHICA/Siv3D/Siv3DWindowImpl.hpp +++ b/Library/PAX_GRAPHICA/Siv3D/Siv3DWindowImpl.hpp @@ -72,11 +72,11 @@ namespace paxg { } void setBackgroundColor(const Color color) override { - s3d::Scene::SetBackground(color); + s3d::Scene::SetBackground(paxg::ColorF(color)); } void setLetterbox(const Color color) override { - s3d::Scene::SetLetterbox(color); + s3d::Scene::SetLetterbox(paxg::ColorF(color)); } void setResizable(bool resizable) override { diff --git a/Library/PAX_GRAPHICA/Texture.hpp b/Library/PAX_GRAPHICA/Texture.hpp index af0b066e1..d3719ee4e 100644 --- a/Library/PAX_GRAPHICA/Texture.hpp +++ b/Library/PAX_GRAPHICA/Texture.hpp @@ -1,4 +1,4 @@ -/*########################################################################################## +/*########################################################################################## PAX SAPIENTICA Library 💀🌿🌏 diff --git a/Library/PAX_GRAPHICA/ToggleButton.hpp b/Library/PAX_GRAPHICA/ToggleButton.hpp index d0ad12155..78397b3a5 100644 --- a/Library/PAX_GRAPHICA/ToggleButton.hpp +++ b/Library/PAX_GRAPHICA/ToggleButton.hpp @@ -156,13 +156,13 @@ namespace paxg { #if defined(PAXS_USING_SIV3D) // Left circle - s3d::Circle(x_ + radius, y_ + radius, radius).draw(bg_color); + s3d::Circle(x_ + radius, y_ + radius, radius).draw(paxg::ColorF(bg_color)); // Center rectangle - s3d::Rect(x_ + radius, y_, width_ - height_, height_).draw(bg_color); + s3d::Rect(x_ + radius, y_, width_ - height_, height_).draw(paxg::ColorF(bg_color)); // Right circle - s3d::Circle(x_ + width_ - radius, y_ + radius, radius).draw(bg_color); + s3d::Circle(x_ + width_ - radius, y_ + radius, radius).draw(paxg::ColorF(bg_color)); // Knob const float knob_radius = height_ * 0.4f; @@ -173,7 +173,7 @@ namespace paxg { s3d::Circle(knob_x + 2, knob_y + 2, knob_radius).draw(s3d::ColorF(0, 0, 0, 0.2)); // Knob circle - s3d::Circle(knob_x, knob_y, knob_radius).draw(color_knob_); + s3d::Circle(knob_x, knob_y, knob_radius).draw(paxg::ColorF(color_knob_)); #elif defined(PAXS_USING_DXLIB) // Get RGB values from bg_color for DxLib diff --git a/Library/PAX_MAHOROBA/Map/Content/Update/UpdateContext.hpp b/Library/PAX_MAHOROBA/Map/Content/Update/UpdateContext.hpp index b350af92b..97e43ce6f 100644 --- a/Library/PAX_MAHOROBA/Map/Content/Update/UpdateContext.hpp +++ b/Library/PAX_MAHOROBA/Map/Content/Update/UpdateContext.hpp @@ -45,7 +45,7 @@ struct SpatialContext : BaseContext { /// @details 経度が±180°で循環するため、3つのラップ座標(-360°, 0°, +360°)のいずれかが範囲内にあるかチェックします /// @details Checks if any of the three wrapped coordinates (-360°, 0°, +360°) are within bounds since longitude wraps at ±180° [[nodiscard]] bool isInViewBounds(Vector2 mercator_pos, double margin = 1.6) const { - const Rect view_rect = Rect::fromCenter( + const paxs::Rect view_rect = paxs::Rect::fromCenter( map_view_center, map_view_size * margin ); @@ -81,7 +81,7 @@ struct TemporalContext : BaseContext { /// @details 経度が±180°で循環するため、3つのラップ座標(-360°, 0°, +360°)のいずれかが範囲内にあるかチェックします /// @details Checks if any of the three wrapped coordinates (-360°, 0°, +360°) are within bounds since longitude wraps at ±180° [[nodiscard]] bool isInViewBounds(Vector2 mercator_pos, double margin = 1.6) const { - const Rect view_rect = Rect::fromCenter( + const paxs::Rect view_rect = paxs::Rect::fromCenter( map_view_center, map_view_size * margin ); @@ -170,7 +170,7 @@ struct UnifiedContext : BaseContext { /// @brief 座標がビューの範囲内にあるかチェック(SpatialContextと同じ実装) /// @brief Check if coordinates are within view bounds (same as SpatialContext) [[nodiscard]] bool isInViewBounds(Vector2 mercator_pos, double margin = 1.6) const { - const Rect view_rect = Rect::fromCenter( + const paxs::Rect view_rect = paxs::Rect::fromCenter( map_view_center, map_view_size * margin ); From 0cac966a5e326a8bdd264899fe95912c780725b3 Mon Sep 17 00:00:00 2001 From: guinpen98 <83969826+guinpen98@users.noreply.github.com> Date: Thu, 4 Dec 2025 17:02:32 +0900 Subject: [PATCH 8/9] ref: Triangle --- Library/PAX_GRAPHICA/DxLib/Triangle.hpp | 101 +++++++++ Library/PAX_GRAPHICA/Interface/Triangle.hpp | 68 ++++++ Library/PAX_GRAPHICA/Null/Triangle.hpp | 63 ++++++ Library/PAX_GRAPHICA/SFML/Triangle.hpp | 101 +++++++++ Library/PAX_GRAPHICA/Siv3D/Triangle.hpp | 90 ++++++++ Library/PAX_GRAPHICA/Triangle.hpp | 195 +----------------- .../DxLib/TriangleIncludeTest.cpp | 3 + .../Interface/TriangleIncludeTest.cpp | 3 + .../PAX_GRAPHICA/Null/TriangleIncludeTest.cpp | 3 + .../PAX_GRAPHICA/SFML/TriangleIncludeTest.cpp | 3 + .../Siv3D/TriangleIncludeTest.cpp | 3 + 11 files changed, 447 insertions(+), 186 deletions(-) create mode 100644 Library/PAX_GRAPHICA/DxLib/Triangle.hpp create mode 100644 Library/PAX_GRAPHICA/Interface/Triangle.hpp create mode 100644 Library/PAX_GRAPHICA/Null/Triangle.hpp create mode 100644 Library/PAX_GRAPHICA/SFML/Triangle.hpp create mode 100644 Library/PAX_GRAPHICA/Siv3D/Triangle.hpp create mode 100644 Projects/IncludeTest/source/PAX_GRAPHICA/DxLib/TriangleIncludeTest.cpp create mode 100644 Projects/IncludeTest/source/PAX_GRAPHICA/Interface/TriangleIncludeTest.cpp create mode 100644 Projects/IncludeTest/source/PAX_GRAPHICA/Null/TriangleIncludeTest.cpp create mode 100644 Projects/IncludeTest/source/PAX_GRAPHICA/SFML/TriangleIncludeTest.cpp create mode 100644 Projects/IncludeTest/source/PAX_GRAPHICA/Siv3D/TriangleIncludeTest.cpp diff --git a/Library/PAX_GRAPHICA/DxLib/Triangle.hpp b/Library/PAX_GRAPHICA/DxLib/Triangle.hpp new file mode 100644 index 000000000..a593d567a --- /dev/null +++ b/Library/PAX_GRAPHICA/DxLib/Triangle.hpp @@ -0,0 +1,101 @@ +/*########################################################################################## + + PAX SAPIENTICA Library 💀🌿🌏 + + [Planning] 2023-2024 As Project + [Production] 2023-2024 As Project + [Contact Us] wanotaitei@gmail.com https://github.com/AsPJT/PAX_SAPIENTICA + [License] Distributed under the CC0 1.0. https://creativecommons.org/publicdomain/zero/1.0/ + +##########################################################################################*/ + +#ifndef PAX_GRAPHICA_DXLIB_TRIANGLE_HPP +#define PAX_GRAPHICA_DXLIB_TRIANGLE_HPP + +#ifdef PAXS_USING_DXLIB +#include + +#include + +#include + +namespace paxg { + + // TriangleShape Implementation + inline constexpr TriangleShape::TriangleShape(const float radius_, const float rotation_) + : offset1_x(radius_ * constexprCos(rotation_ - paxs::Math::piHalf())) + , offset1_y(radius_ * constexprSin(rotation_ - paxs::Math::piHalf())) + , offset2_x(radius_ * constexprCos(rotation_ - paxs::Math::piHalf() + paxs::Math::pi2() / 3.0f)) + , offset2_y(radius_ * constexprSin(rotation_ - paxs::Math::piHalf() + paxs::Math::pi2() / 3.0f)) + , offset3_x(radius_ * constexprCos(rotation_ - paxs::Math::piHalf() + paxs::Math::pi2() * 2.0f / 3.0f)) + , offset3_y(radius_ * constexprSin(rotation_ - paxs::Math::piHalf() + paxs::Math::pi2() * 2.0f / 3.0f)) + , radius(radius_) + , rotation(rotation_) + {} + + inline constexpr float TriangleShape::constexprSin(float x) { + while (x > paxs::Math::pi()) x -= paxs::Math::pi2(); + while (x < -paxs::Math::pi()) x += paxs::Math::pi2(); + const float x2 = x * x; + return x * (1.0f - x2 / 6.0f * (1.0f - x2 / 20.0f * (1.0f - x2 / 42.0f))); + } + + inline constexpr float TriangleShape::constexprCos(float x) { + return constexprSin(x + paxs::Math::piHalf()); + } + + // Triangle Implementation + inline constexpr Triangle::Triangle() = default; + + inline constexpr Triangle::Triangle(const float center_x, const float center_y, const float radius, const float rotation) + : center_x_(center_x), center_y_(center_y), radius_(radius), rotation_(rotation) {} + + inline constexpr Triangle::Triangle(const paxs::Vector2& center, const float radius, const float rotation) + : center_x_(center.x), center_y_(center.y), radius_(radius), rotation_(rotation) {} + + inline constexpr Triangle::Triangle(const float center_x, const float center_y, const TriangleShape& shape) + : center_x_(center_x), center_y_(center_y), radius_(shape.radius), rotation_(shape.rotation), shape_(&shape) {} + + inline constexpr Triangle::Triangle(const paxs::Vector2& center, const TriangleShape& shape) + : center_x_(center.x), center_y_(center.y), radius_(shape.radius), rotation_(shape.rotation), shape_(&shape) {} + + inline constexpr float Triangle::centerX() const { return center_x_; } + inline constexpr float Triangle::centerY() const { return center_y_; } + inline constexpr float Triangle::radius() const { return radius_; } + inline constexpr float Triangle::rotation() const { return rotation_; } + + inline void Triangle::setCenterX(const float x) { center_x_ = x; } + inline void Triangle::setCenterY(const float y) { center_y_ = y; } + inline void Triangle::setCenter(const float x, const float y) { center_x_ = x; center_y_ = y; } + inline void Triangle::setCenter(const paxs::Vector2& center) { center_x_ = center.x; center_y_ = center.y; } + inline void Triangle::setRadius(const float r) { radius_ = r; } + inline void Triangle::setRotation(const float rot) { rotation_ = rot; } + + inline void Triangle::draw(const paxg::Color& color) const { + if (shape_) { + const int x1 = static_cast(center_x_ + shape_->offset1_x); + const int y1 = static_cast(center_y_ + shape_->offset1_y); + const int x2 = static_cast(center_x_ + shape_->offset2_x); + const int y2 = static_cast(center_y_ + shape_->offset2_y); + const int x3 = static_cast(center_x_ + shape_->offset3_x); + const int y3 = static_cast(center_y_ + shape_->offset3_y); + DxLib::DrawTriangle(x1, y1, x2, y2, x3, y3, DxLib::GetColor(color.r, color.g, color.b), TRUE); + } else { + const float angle1 = rotation_ - paxs::Math::piHalf(); + const float angle2 = angle1 + paxs::Math::pi2() / 3.0f; + const float angle3 = angle2 + paxs::Math::pi2() / 3.0f; + const int x1 = static_cast(center_x_ + radius_ * std::cos(angle1)); + const int y1 = static_cast(center_y_ + radius_ * std::sin(angle1)); + const int x2 = static_cast(center_x_ + radius_ * std::cos(angle2)); + const int y2 = static_cast(center_y_ + radius_ * std::sin(angle2)); + const int x3 = static_cast(center_x_ + radius_ * std::cos(angle3)); + const int y3 = static_cast(center_y_ + radius_ * std::sin(angle3)); + DxLib::DrawTriangle(x1, y1, x2, y2, x3, y3, DxLib::GetColor(color.r, color.g, color.b), TRUE); + } + } + +} // namespace paxg + +#endif // PAXS_USING_DXLIB + +#endif // PAX_GRAPHICA_DXLIB_TRIANGLE_HPP diff --git a/Library/PAX_GRAPHICA/Interface/Triangle.hpp b/Library/PAX_GRAPHICA/Interface/Triangle.hpp new file mode 100644 index 000000000..7f4d1fae4 --- /dev/null +++ b/Library/PAX_GRAPHICA/Interface/Triangle.hpp @@ -0,0 +1,68 @@ +/*########################################################################################## + + PAX SAPIENTICA Library 💀🌿🌏 + + [Planning] 2023-2024 As Project + [Production] 2023-2024 As Project + [Contact Us] wanotaitei@gmail.com https://github.com/AsPJT/PAX_SAPIENTICA + [License] Distributed under the CC0 1.0. https://creativecommons.org/publicdomain/zero/1.0/ + +##########################################################################################*/ + +#ifndef PAX_GRAPHICA_INTERFACE_TRIANGLE_HPP +#define PAX_GRAPHICA_INTERFACE_TRIANGLE_HPP + +#include +#include +#include + +namespace paxg { + + struct TriangleShape; + + struct Triangle { + private: + float center_x_{}; + float center_y_{}; + float radius_{}; + float rotation_{}; + const TriangleShape* shape_{ nullptr }; + + public: + constexpr Triangle(); + constexpr Triangle(const float center_x, const float center_y, const float radius, const float rotation = 0.0f); + constexpr Triangle(const paxs::Vector2& center, const float radius, const float rotation = 0.0f); + constexpr Triangle(const float center_x, const float center_y, const TriangleShape& shape); + constexpr Triangle(const paxs::Vector2& center, const TriangleShape& shape); + + constexpr float centerX() const; + constexpr float centerY() const; + constexpr float radius() const; + constexpr float rotation() const; + + void setCenterX(const float x); + void setCenterY(const float y); + void setCenter(const float x, const float y); + void setCenter(const paxs::Vector2& center); + void setRadius(const float r); + void setRotation(const float rot); + + void draw(const paxg::Color& color = paxg::Color(0, 0, 0)) const; + }; + + struct TriangleShape { + float offset1_x, offset1_y; + float offset2_x, offset2_y; + float offset3_x, offset3_y; + float radius, rotation; + + constexpr TriangleShape(const float radius_, const float rotation_); + + private: + static constexpr float constexprSin(float x); + static constexpr float constexprCos(float x); + }; + +} // namespace paxg + +#endif // PAX_GRAPHICA_INTERFACE_TRIANGLE_HPP diff --git a/Library/PAX_GRAPHICA/Null/Triangle.hpp b/Library/PAX_GRAPHICA/Null/Triangle.hpp new file mode 100644 index 000000000..7cddb5523 --- /dev/null +++ b/Library/PAX_GRAPHICA/Null/Triangle.hpp @@ -0,0 +1,63 @@ +/*########################################################################################## + + PAX SAPIENTICA Library 💀🌿🌏 + + [Planning] 2023-2024 As Project + [Production] 2023-2024 As Project + [Contact Us] wanotaitei@gmail.com https://github.com/AsPJT/PAX_SAPIENTICA + [License] Distributed under the CC0 1.0. https://creativecommons.org/publicdomain/zero/1.0/ + +##########################################################################################*/ + +#ifndef PAX_GRAPHICA_NULL_TRIANGLE_HPP +#define PAX_GRAPHICA_NULL_TRIANGLE_HPP + +#include + +namespace paxg { + + // TriangleShape Implementation + inline constexpr TriangleShape::TriangleShape(const float radius_, const float rotation_) + : offset1_x(0.0f), offset1_y(0.0f), + offset2_x(0.0f), offset2_y(0.0f), + offset3_x(0.0f), offset3_y(0.0f), + radius(radius_), rotation(rotation_) + {} + + inline constexpr float TriangleShape::constexprSin(float) { return 0.0f; } + inline constexpr float TriangleShape::constexprCos(float) { return 0.0f; } + + // Triangle Implementation + inline constexpr Triangle::Triangle() = default; + + inline constexpr Triangle::Triangle(const float center_x, const float center_y, const float radius, const float rotation) + : center_x_(center_x), center_y_(center_y), radius_(radius), rotation_(rotation) {} + + inline constexpr Triangle::Triangle(const paxs::Vector2& center, const float radius, const float rotation) + : center_x_(center.x), center_y_(center.y), radius_(radius), rotation_(rotation) {} + + inline constexpr Triangle::Triangle(const float center_x, const float center_y, const TriangleShape& shape) + : center_x_(center_x), center_y_(center_y), radius_(shape.radius), rotation_(shape.rotation), shape_(&shape) {} + + inline constexpr Triangle::Triangle(const paxs::Vector2& center, const TriangleShape& shape) + : center_x_(center.x), center_y_(center.y), radius_(shape.radius), rotation_(shape.rotation), shape_(&shape) {} + + inline constexpr float Triangle::centerX() const { return center_x_; } + inline constexpr float Triangle::centerY() const { return center_y_; } + inline constexpr float Triangle::radius() const { return radius_; } + inline constexpr float Triangle::rotation() const { return rotation_; } + + inline void Triangle::setCenterX(const float x) { center_x_ = x; } + inline void Triangle::setCenterY(const float y) { center_y_ = y; } + inline void Triangle::setCenter(const float x, const float y) { center_x_ = x; center_y_ = y; } + inline void Triangle::setCenter(const paxs::Vector2& center) { center_x_ = center.x; center_y_ = center.y; } + inline void Triangle::setRadius(const float r) { radius_ = r; } + inline void Triangle::setRotation(const float rot) { rotation_ = rot; } + + inline void Triangle::draw(const paxg::Color&) const { + // Do nothing + } + +} // namespace paxg + +#endif // PAX_GRAPHICA_NULL_TRIANGLE_HPP diff --git a/Library/PAX_GRAPHICA/SFML/Triangle.hpp b/Library/PAX_GRAPHICA/SFML/Triangle.hpp new file mode 100644 index 000000000..b117b2d81 --- /dev/null +++ b/Library/PAX_GRAPHICA/SFML/Triangle.hpp @@ -0,0 +1,101 @@ +/*########################################################################################## + + PAX SAPIENTICA Library 💀🌿🌏 + + [Planning] 2023-2024 As Project + [Production] 2023-2024 As Project + [Contact Us] wanotaitei@gmail.com https://github.com/AsPJT/PAX_SAPIENTICA + [License] Distributed under the CC0 1.0. https://creativecommons.org/publicdomain/zero/1.0/ + +##########################################################################################*/ + +#ifndef PAX_GRAPHICA_SFML_TRIANGLE_HPP +#define PAX_GRAPHICA_SFML_TRIANGLE_HPP + +#ifdef PAXS_USING_SFML +#include + +#include + +#include +#include + +namespace paxg { + + // TriangleShape Implementation + inline constexpr TriangleShape::TriangleShape(const float radius_, const float rotation_) + : offset1_x(radius_ * constexprCos(rotation_ - paxs::Math::piHalf())) + , offset1_y(radius_ * constexprSin(rotation_ - paxs::Math::piHalf())) + , offset2_x(radius_ * constexprCos(rotation_ - paxs::Math::piHalf() + paxs::Math::pi2() / 3.0f)) + , offset2_y(radius_ * constexprSin(rotation_ - paxs::Math::piHalf() + paxs::Math::pi2() / 3.0f)) + , offset3_x(radius_ * constexprCos(rotation_ - paxs::Math::piHalf() + paxs::Math::pi2() * 2.0f / 3.0f)) + , offset3_y(radius_ * constexprSin(rotation_ - paxs::Math::piHalf() + paxs::Math::pi2() * 2.0f / 3.0f)) + , radius(radius_) + , rotation(rotation_) + {} + + inline constexpr float TriangleShape::constexprSin(float x) { + while (x > paxs::Math::pi()) x -= paxs::Math::pi2(); + while (x < -paxs::Math::pi()) x += paxs::Math::pi2(); + const float x2 = x * x; + return x * (1.0f - x2 / 6.0f * (1.0f - x2 / 20.0f * (1.0f - x2 / 42.0f))); + } + + inline constexpr float TriangleShape::constexprCos(float x) { + return constexprSin(x + paxs::Math::piHalf()); + } + + // Triangle Implementation + inline constexpr Triangle::Triangle() = default; + + inline constexpr Triangle::Triangle(const float center_x, const float center_y, const float radius, const float rotation) + : center_x_(center_x), center_y_(center_y), radius_(radius), rotation_(rotation) {} + + inline constexpr Triangle::Triangle(const paxs::Vector2& center, const float radius, const float rotation) + : center_x_(center.x), center_y_(center.y), radius_(radius), rotation_(rotation) {} + + inline constexpr Triangle::Triangle(const float center_x, const float center_y, const TriangleShape& shape) + : center_x_(center_x), center_y_(center_y), radius_(shape.radius), rotation_(shape.rotation), shape_(&shape) {} + + inline constexpr Triangle::Triangle(const paxs::Vector2& center, const TriangleShape& shape) + : center_x_(center.x), center_y_(center.y), radius_(shape.radius), rotation_(shape.rotation), shape_(&shape) {} + + inline constexpr float Triangle::centerX() const { return center_x_; } + inline constexpr float Triangle::centerY() const { return center_y_; } + inline constexpr float Triangle::radius() const { return radius_; } + inline constexpr float Triangle::rotation() const { return rotation_; } + + inline void Triangle::setCenterX(const float x) { center_x_ = x; } + inline void Triangle::setCenterY(const float y) { center_y_ = y; } + inline void Triangle::setCenter(const float x, const float y) { center_x_ = x; center_y_ = y; } + inline void Triangle::setCenter(const paxs::Vector2& center) { center_x_ = center.x; center_y_ = center.y; } + inline void Triangle::setRadius(const float r) { radius_ = r; } + inline void Triangle::setRotation(const float rot) { rotation_ = rot; } + + inline void Triangle::draw(const paxg::Color& color) const { + sf::ConvexShape triangle; + triangle.setPointCount(3); + + if (shape_) { + triangle.setPoint(0, sf::Vector2f(center_x_ + shape_->offset1_x, center_y_ + shape_->offset1_y)); + triangle.setPoint(1, sf::Vector2f(center_x_ + shape_->offset2_x, center_y_ + shape_->offset2_y)); + triangle.setPoint(2, sf::Vector2f(center_x_ + shape_->offset3_x, center_y_ + shape_->offset3_y)); + } else { + const float angle1 = rotation_ - paxs::Math::piHalf(); + const float angle2 = angle1 + paxs::Math::pi2() / 3.0f; + const float angle3 = angle2 + paxs::Math::pi2() / 3.0f; + + triangle.setPoint(0, sf::Vector2f(center_x_ + radius_ * std::cos(angle1), center_y_ + radius_ * std::sin(angle1))); + triangle.setPoint(1, sf::Vector2f(center_x_ + radius_ * std::cos(angle2), center_y_ + radius_ * std::sin(angle2))); + triangle.setPoint(2, sf::Vector2f(center_x_ + radius_ * std::cos(angle3), center_y_ + radius_ * std::sin(angle3))); + } + + triangle.setFillColor(color); + paxg::Window::window().draw(triangle); + } + +} // namespace paxg + +#endif // PAXS_USING_SFML + +#endif // PAX_GRAPHICA_SFML_TRIANGLE_HPP diff --git a/Library/PAX_GRAPHICA/Siv3D/Triangle.hpp b/Library/PAX_GRAPHICA/Siv3D/Triangle.hpp new file mode 100644 index 000000000..ccf091427 --- /dev/null +++ b/Library/PAX_GRAPHICA/Siv3D/Triangle.hpp @@ -0,0 +1,90 @@ +/*########################################################################################## + + PAX SAPIENTICA Library 💀🌿🌏 + + [Planning] 2023-2024 As Project + [Production] 2023-2024 As Project + [Contact Us] wanotaitei@gmail.com https://github.com/AsPJT/PAX_SAPIENTICA + [License] Distributed under the CC0 1.0. https://creativecommons.org/publicdomain/zero/1.0/ + +##########################################################################################*/ + +#ifndef PAX_GRAPHICA_SIV3D_TRIANGLE_HPP +#define PAX_GRAPHICA_SIV3D_TRIANGLE_HPP + +#ifdef PAXS_USING_SIV3D +#include + +#include + +namespace paxg { + + // TriangleShape Implementation + inline constexpr TriangleShape::TriangleShape(const float radius_, const float rotation_) + : offset1_x(radius_ * constexprCos(rotation_ - paxs::Math::piHalf())) + , offset1_y(radius_ * constexprSin(rotation_ - paxs::Math::piHalf())) + , offset2_x(radius_ * constexprCos(rotation_ - paxs::Math::piHalf() + paxs::Math::pi2() / 3.0f)) + , offset2_y(radius_ * constexprSin(rotation_ - paxs::Math::piHalf() + paxs::Math::pi2() / 3.0f)) + , offset3_x(radius_ * constexprCos(rotation_ - paxs::Math::piHalf() + paxs::Math::pi2() * 2.0f / 3.0f)) + , offset3_y(radius_ * constexprSin(rotation_ - paxs::Math::piHalf() + paxs::Math::pi2() * 2.0f / 3.0f)) + , radius(radius_) + , rotation(rotation_) + {} + + inline constexpr float TriangleShape::constexprSin(float x) { + while (x > paxs::Math::pi()) x -= paxs::Math::pi2(); + while (x < -paxs::Math::pi()) x += paxs::Math::pi2(); + const float x2 = x * x; + return x * (1.0f - x2 / 6.0f * (1.0f - x2 / 20.0f * (1.0f - x2 / 42.0f))); + } + + inline constexpr float TriangleShape::constexprCos(float x) { + return constexprSin(x + paxs::Math::piHalf()); + } + + // Triangle Implementation + inline constexpr Triangle::Triangle() = default; + + inline constexpr Triangle::Triangle(const float center_x, const float center_y, const float radius, const float rotation) + : center_x_(center_x), center_y_(center_y), radius_(radius), rotation_(rotation) {} + + inline constexpr Triangle::Triangle(const paxs::Vector2& center, const float radius, const float rotation) + : center_x_(center.x), center_y_(center.y), radius_(radius), rotation_(rotation) {} + + inline constexpr Triangle::Triangle(const float center_x, const float center_y, const TriangleShape& shape) + : center_x_(center_x), center_y_(center_y), radius_(shape.radius), rotation_(shape.rotation), shape_(&shape) {} + + inline constexpr Triangle::Triangle(const paxs::Vector2& center, const TriangleShape& shape) + : center_x_(center.x), center_y_(center.y), radius_(shape.radius), rotation_(shape.rotation), shape_(&shape) {} + + inline constexpr float Triangle::centerX() const { return center_x_; } + inline constexpr float Triangle::centerY() const { return center_y_; } + inline constexpr float Triangle::radius() const { return radius_; } + inline constexpr float Triangle::rotation() const { return rotation_; } + + inline void Triangle::setCenterX(const float x) { center_x_ = x; } + inline void Triangle::setCenterY(const float y) { center_y_ = y; } + inline void Triangle::setCenter(const float x, const float y) { center_x_ = x; center_y_ = y; } + inline void Triangle::setCenter(const paxs::Vector2& center) { center_x_ = center.x; center_y_ = center.y; } + inline void Triangle::setRadius(const float r) { radius_ = r; } + inline void Triangle::setRotation(const float rot) { rotation_ = rot; } + + namespace { // Anonymous namespace for implementation details + static constexpr float circumRadiusToSiv3dSides(const float circumRadius) { + return circumRadius * paxs::Math::sqrt3(); + } + } + + inline void Triangle::draw(const paxg::Color& color) const { + const float siv3dSides = circumRadiusToSiv3dSides(radius_); + s3d::Triangle{ { center_x_, center_y_ }, siv3dSides, rotation_ } + .draw(s3d::ColorF{ color }); + s3d::Triangle{ center_x_, center_y_, radius_, rotation_ }.draw(s3d::ColorF{ color }); + } + +} // namespace paxg + + +#endif // PAXS_USING_SIV3D + +#endif // PAX_GRAPHICA_SIV3D_TRIANGLE_HPP diff --git a/Library/PAX_GRAPHICA/Triangle.hpp b/Library/PAX_GRAPHICA/Triangle.hpp index eea614081..add03414d 100644 --- a/Library/PAX_GRAPHICA/Triangle.hpp +++ b/Library/PAX_GRAPHICA/Triangle.hpp @@ -2,201 +2,24 @@ PAX SAPIENTICA Library 💀🌿🌏 - [Planning] 2023-2025 As Project - [Production] 2023-2025 As Project - [Contact Us] wanotaitei@gmail.com https://github.com/AsPJT/PAX_SAPIENTICA - [License] Distributed under the CC0 1.0. https://creativecommons.org/publicdomain/zero/1.0/ + [Planning] 2023-2024 As Project + [Production] 2023-2024 As Project + [Contact Us] wanotaitei@gmail.com https://github.com/AsPJT/PAX_SAPIENTICA + [License] Distributed under the CC0 1.0. https://creativecommons.org/publicdomain/zero/1.0/ ##########################################################################################*/ #ifndef PAX_GRAPHICA_TRIANGLE_HPP #define PAX_GRAPHICA_TRIANGLE_HPP -#include - #if defined(PAXS_USING_SIV3D) -#include +#include #elif defined(PAXS_USING_DXLIB) -#include +#include #elif defined(PAXS_USING_SFML) -#include -#endif - -#include -#include - -#include -#include - -namespace paxg { - - /// @brief Compile-time calculation of triangle vertex offsets - /// @details Precomputes relative positions of triangle vertices for a given radius and rotation - struct TriangleShape { - float offset1_x, offset1_y; - float offset2_x, offset2_y; - float offset3_x, offset3_y; - float radius, rotation; - - /// @brief Constexpr constructor that calculates vertex offsets at compile time - /// @param radius Radius of the circumscribed circle - /// @param rotation Rotation angle in radians - constexpr TriangleShape(const float radius_, const float rotation_) - : offset1_x(radius_ * constexprCos(rotation_ - paxs::Math::piHalf())) - , offset1_y(radius_ * constexprSin(rotation_ - paxs::Math::piHalf())) - , offset2_x(radius_ * constexprCos(rotation_ - paxs::Math::piHalf() + paxs::Math::pi2() / 3.0f)) - , offset2_y(radius_ * constexprSin(rotation_ - paxs::Math::piHalf() + paxs::Math::pi2() / 3.0f)) - , offset3_x(radius_ * constexprCos(rotation_ - paxs::Math::piHalf() + paxs::Math::pi2() * 2.0f / 3.0f)) - , offset3_y(radius_ * constexprSin(rotation_ - paxs::Math::piHalf() + paxs::Math::pi2() * 2.0f / 3.0f)) - , radius(radius_) - , rotation(rotation_) - {} - - private: - // Constexpr implementations of trigonometric functions (Taylor series approximation) - static constexpr float constexprSin(float x) { - // Normalize to [-π, π] - while (x > paxs::Math::pi()) x -= paxs::Math::pi2(); - while (x < -paxs::Math::pi()) x += paxs::Math::pi2(); - // Taylor series: sin(x) ≈ x - x³/3! + x⁵/5! - x⁷/7! - const float x2 = x * x; - return x * (1.0f - x2 / 6.0f * (1.0f - x2 / 20.0f * (1.0f - x2 / 42.0f))); - } - - static constexpr float constexprCos(float x) { - // cos(x) = sin(x + π/2) - return constexprSin(x + paxs::Math::piHalf()); - } - }; - - /// @brief Triangle class that draws a triangle with center, radius and rotation - /// @details Provides a cross-platform abstraction for drawing triangles - struct Triangle { - private: - float center_x_{}; - float center_y_{}; - float radius_{}; - float rotation_{}; // Rotation angle in radians (0 = pointing right, π = pointing down) - const TriangleShape* shape_{ nullptr }; // Optional pre-computed shape (for static triangles) - - public: - constexpr Triangle() = default; - - /// @brief Constructor with center position, radius, and rotation angle - /// @param center_x X coordinate of the center - /// @param center_y Y coordinate of the center - /// @param radius Radius of the circumscribed circle - /// @param rotation Rotation angle in radians (0 = right, π/2 = down, π = left, 3π/2 = up) - constexpr Triangle(const float center_x, const float center_y, const float radius, const float rotation = 0.0f) - : center_x_(center_x), center_y_(center_y), radius_(radius), rotation_(rotation) {} - - constexpr Triangle(const paxs::Vector2& center, const float radius, const float rotation = 0.0f) - : center_x_(center.x), center_y_(center.y), radius_(radius), rotation_(rotation) {} - - /// @brief Optimized constructor using pre-computed shape (no runtime trigonometry) - /// @param center_x X coordinate of the center - /// @param center_y Y coordinate of the center - /// @param shape Pre-computed triangle shape (typically constexpr static) - constexpr Triangle(const float center_x, const float center_y, const TriangleShape& shape) - : center_x_(center_x), center_y_(center_y), radius_(shape.radius), rotation_(shape.rotation), shape_(&shape) {} - - constexpr Triangle(const paxs::Vector2& center, const TriangleShape& shape) - : center_x_(center.x), center_y_(center.y), radius_(shape.radius), rotation_(shape.rotation), shape_(&shape) {} - - // Getters - constexpr float centerX() const { return center_x_; } - constexpr float centerY() const { return center_y_; } - constexpr float radius() const { return radius_; } - constexpr float rotation() const { return rotation_; } - - // Setters - void setCenterX(const float x) { center_x_ = x; } - void setCenterY(const float y) { center_y_ = y; } - void setCenter(const float x, const float y) { center_x_ = x; center_y_ = y; } - void setCenter(const paxs::Vector2& center) { center_x_ = center.x; center_y_ = center.y; } - void setRadius(const float r) { radius_ = r; } - void setRotation(const float rot) { rotation_ = rot; } - -#if defined(PAXS_USING_SIV3D) - static constexpr float circumRadiusToSiv3dSides(const float circumRadius) { - // Siv3Dは sides を受け取って内部で ×(1/√3) してるので、逆にこっちは ×√3 する - return circumRadius * paxs::Math::sqrt3(); - } -#endif - - /// @brief Draw the triangle with specified color (defaults to black) - void draw(const paxg::Color& color = paxg::Color(0, 0, 0)) const { -#if defined(PAXS_USING_SIV3D) - const float siv3dSides = circumRadiusToSiv3dSides(radius_); - s3d::Triangle{ { center_x_, center_y_ }, siv3dSides, rotation_ } - .draw(s3d::ColorF{ color }); - s3d::Triangle{ center_x_, center_y_, radius_, rotation_ }.draw(s3d::ColorF{ color }); - -#elif defined(PAXS_USING_SFML) - sf::ConvexShape triangle; - triangle.setPointCount(3); - - if (shape_) { - // Use pre-computed shape (no trigonometry) - triangle.setPoint(0, sf::Vector2f(center_x_ + shape_->offset1_x, center_y_ + shape_->offset1_y)); - triangle.setPoint(1, sf::Vector2f(center_x_ + shape_->offset2_x, center_y_ + shape_->offset2_y)); - triangle.setPoint(2, sf::Vector2f(center_x_ + shape_->offset3_x, center_y_ + shape_->offset3_y)); - } else { - // Calculate vertices at runtime (for dynamic triangles) - const float angle1 = rotation_ - paxs::Math::piHalf(); // -π/2 - const float angle2 = angle1 + paxs::Math::pi2() / 3.0f; // +2π/3 - const float angle3 = angle2 + paxs::Math::pi2() / 3.0f; // +2π/3 - - triangle.setPoint(0, sf::Vector2f( - center_x_ + radius_ * std::cos(angle1), - center_y_ + radius_ * std::sin(angle1) - )); - triangle.setPoint(1, sf::Vector2f( - center_x_ + radius_ * std::cos(angle2), - center_y_ + radius_ * std::sin(angle2) - )); - triangle.setPoint(2, sf::Vector2f( - center_x_ + radius_ * std::cos(angle3), - center_y_ + radius_ * std::sin(angle3) - )); - } - - triangle.setFillColor(color); - paxg::Window::window().draw(triangle); - -#elif defined(PAXS_USING_DXLIB) - if (shape_) { - // Use pre-computed shape (no trigonometry) - const int x1 = static_cast(center_x_ + shape_->offset1_x); - const int y1 = static_cast(center_y_ + shape_->offset1_y); - const int x2 = static_cast(center_x_ + shape_->offset2_x); - const int y2 = static_cast(center_y_ + shape_->offset2_y); - const int x3 = static_cast(center_x_ + shape_->offset3_x); - const int y3 = static_cast(center_y_ + shape_->offset3_y); - - DxLib::DrawTriangle(x1, y1, x2, y2, x3, y3, DxLib::GetColor(color.r, color.g, color.b), TRUE); - } else { - // Calculate vertices at runtime (for dynamic triangles) - const float angle1 = rotation_ - paxs::Math::piHalf(); // -π/2 - const float angle2 = angle1 + paxs::Math::pi2() / 3.0f; // +2π/3 - const float angle3 = angle2 + paxs::Math::pi2() / 3.0f; // +2π/3 - - const int x1 = static_cast(center_x_ + radius_ * std::cos(angle1)); - const int y1 = static_cast(center_y_ + radius_ * std::sin(angle1)); - const int x2 = static_cast(center_x_ + radius_ * std::cos(angle2)); - const int y2 = static_cast(center_y_ + radius_ * std::sin(angle2)); - const int x3 = static_cast(center_x_ + radius_ * std::cos(angle3)); - const int y3 = static_cast(center_y_ + radius_ * std::sin(angle3)); - - DxLib::DrawTriangle(x1, y1, x2, y2, x3, y3, DxLib::GetColor(color.r, color.g, color.b), TRUE); - } +#include #else - (void)color; - (void)shape_; // Suppress unused warning for Siv3D builds +#include #endif - } - }; - -} // namespace paxg -#endif // !PAX_GRAPHICA_TRIANGLE_HPP +#endif // PAX_GRAPHICA_TRIANGLE_HPP diff --git a/Projects/IncludeTest/source/PAX_GRAPHICA/DxLib/TriangleIncludeTest.cpp b/Projects/IncludeTest/source/PAX_GRAPHICA/DxLib/TriangleIncludeTest.cpp new file mode 100644 index 000000000..608fde0c4 --- /dev/null +++ b/Projects/IncludeTest/source/PAX_GRAPHICA/DxLib/TriangleIncludeTest.cpp @@ -0,0 +1,3 @@ +#include + +int main(){} diff --git a/Projects/IncludeTest/source/PAX_GRAPHICA/Interface/TriangleIncludeTest.cpp b/Projects/IncludeTest/source/PAX_GRAPHICA/Interface/TriangleIncludeTest.cpp new file mode 100644 index 000000000..248c8970d --- /dev/null +++ b/Projects/IncludeTest/source/PAX_GRAPHICA/Interface/TriangleIncludeTest.cpp @@ -0,0 +1,3 @@ +#include + +int main(){} diff --git a/Projects/IncludeTest/source/PAX_GRAPHICA/Null/TriangleIncludeTest.cpp b/Projects/IncludeTest/source/PAX_GRAPHICA/Null/TriangleIncludeTest.cpp new file mode 100644 index 000000000..822a2463e --- /dev/null +++ b/Projects/IncludeTest/source/PAX_GRAPHICA/Null/TriangleIncludeTest.cpp @@ -0,0 +1,3 @@ +#include + +int main(){} diff --git a/Projects/IncludeTest/source/PAX_GRAPHICA/SFML/TriangleIncludeTest.cpp b/Projects/IncludeTest/source/PAX_GRAPHICA/SFML/TriangleIncludeTest.cpp new file mode 100644 index 000000000..0cf389723 --- /dev/null +++ b/Projects/IncludeTest/source/PAX_GRAPHICA/SFML/TriangleIncludeTest.cpp @@ -0,0 +1,3 @@ +#include + +int main(){} diff --git a/Projects/IncludeTest/source/PAX_GRAPHICA/Siv3D/TriangleIncludeTest.cpp b/Projects/IncludeTest/source/PAX_GRAPHICA/Siv3D/TriangleIncludeTest.cpp new file mode 100644 index 000000000..74579ce3c --- /dev/null +++ b/Projects/IncludeTest/source/PAX_GRAPHICA/Siv3D/TriangleIncludeTest.cpp @@ -0,0 +1,3 @@ +#include + +int main(){} From eae076a55df72b6275eb81fd40ca225b9222a076 Mon Sep 17 00:00:00 2001 From: guinpen98 <83969826+guinpen98@users.noreply.github.com> Date: Thu, 4 Dec 2025 17:52:39 +0900 Subject: [PATCH 9/9] fix: test --- .../Source/PAX_GRAPHICA/NetworkUnitTest.cpp | 9 ++++++++ .../Source/PAX_GRAPHICA/SystemUnitTest.cpp | 23 ------------------- 2 files changed, 9 insertions(+), 23 deletions(-) delete mode 100644 Projects/UnitTest/Source/PAX_GRAPHICA/SystemUnitTest.cpp diff --git a/Projects/UnitTest/Source/PAX_GRAPHICA/NetworkUnitTest.cpp b/Projects/UnitTest/Source/PAX_GRAPHICA/NetworkUnitTest.cpp index 1c6597d12..54d9243b3 100644 --- a/Projects/UnitTest/Source/PAX_GRAPHICA/NetworkUnitTest.cpp +++ b/Projects/UnitTest/Source/PAX_GRAPHICA/NetworkUnitTest.cpp @@ -27,3 +27,12 @@ TEST(NetworkTest, DownloadFileDoesNotCrash) { std::filesystem::remove("test_output.tmp"); } } + +// launchBrowser のテスト(実際にブラウザを開くわけにはいかないので、単に呼び出せることを確認) +TEST(SystemTest, LaunchBrowserDoesNotCrash) { + // URLが空でも呼び出せることを確認 + EXPECT_NO_THROW(paxg::Network::launchBrowser("")); + + // 正しいURLでも呼び出せることを確認(実際には開かない) + EXPECT_NO_THROW(paxg::Network::launchBrowser("https://github.com/AsPJT/PAX_SAPIENTICA")); +} diff --git a/Projects/UnitTest/Source/PAX_GRAPHICA/SystemUnitTest.cpp b/Projects/UnitTest/Source/PAX_GRAPHICA/SystemUnitTest.cpp deleted file mode 100644 index 78454b2d9..000000000 --- a/Projects/UnitTest/Source/PAX_GRAPHICA/SystemUnitTest.cpp +++ /dev/null @@ -1,23 +0,0 @@ -/*########################################################################################## - - PAX SAPIENTICA Library 💀🌿🌏 - - [Planning] 2023-2024 As Project - [Production] 2023-2024 As Project - [Contact Us] wanotaitei@gmail.com https://github.com/AsPJT/PAX_SAPIENTICA - [License] Distributed under the CC0 1.0. https://creativecommons.org/publicdomain/zero/1.0/ - -##########################################################################################*/ - -#include - -#include - -// launchBrowser のテスト(実際にブラウザを開くわけにはいかないので、単に呼び出せることを確認) -TEST(SystemTest, LaunchBrowserDoesNotCrash) { - // URLが空でも呼び出せることを確認 - EXPECT_NO_THROW(paxg::System::launchBrowser("")); - - // 正しいURLでも呼び出せることを確認(実際には開かない) - EXPECT_NO_THROW(paxg::System::launchBrowser("https://github.com/AsPJT/PAX_SAPIENTICA")); -}