Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions Library/PAX_GRAPHICA/Circle.hpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/*##########################################################################################
/*##########################################################################################

PAX SAPIENTICA Library 💀🌿🌏

Expand Down Expand Up @@ -42,7 +42,7 @@ namespace paxg {
#else
float x, y, r;
constexpr Circle(const float x, const float y, const float r) : x(x), y(y), r(r) {}
constexpr Circle(const Vec2& pos, const float r) : x(pos.x), y(pos.y), r(r) {}
constexpr Circle(const Vec2& pos, const float r) : x(pos.x()), y(pos.y()), r(r) {}
#endif
void draw() const override {
#if defined(PAXS_USING_SIV3D)
Expand All @@ -56,4 +56,4 @@ namespace paxg {
};
}

#endif // !PAX_GRAPHICA_CIRCLE_HPP
#endif // !PAX_GRAPHICA_CIRCLE_HPP
22 changes: 15 additions & 7 deletions Library/PAX_GRAPHICA/Color.hpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/*##########################################################################################
/*##########################################################################################

PAX SAPIENTICA Library 💀🌿🌏

Expand All @@ -24,21 +24,29 @@

namespace paxg {

// R 赤
// G 緑
// B 青
// A 不透明度
struct Color {
#if defined(PAXS_USING_SIV3D)
s3d::Color color;
constexpr Color(const int r, const int g, const int b, const int a) : color(r, g, b, a) {}
constexpr s3d::Color() const { return color; }
constexpr Color(const int r, const int g, const int b, const int a = 255) :
color(static_cast<s3d::Color::value_type>(r),
static_cast<s3d::Color::value_type>(g),
static_cast<s3d::Color::value_type>(b),
static_cast<s3d::Color::value_type>(a)) {}
operator s3d::Color() const { return color; }
#elif defined(PAXS_USING_SFML)
sf::Color color;
Color(const int r, const int g, const int b, const int a) : color(r, g, b, a) {}
Color(const int r, const int g, const int b, const int a = 255) : color(r, g, b, a) {}
operator sf::Color() const { return color; }
#else
int r, g, b, a;
constexpr Color(int r, int g, int b, int a) : r(r), g(g), b(b), a(a) {}
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) {}
#endif
};

}

#endif // !PAX_GRAPHICA_COLOR_HPP
#endif // !PAX_GRAPHICA_COLOR_HPP
4 changes: 2 additions & 2 deletions Library/PAX_GRAPHICA/Graphics.hpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/*##########################################################################################
/*##########################################################################################

PAX SAPIENTICA Library 💀🌿🌏

Expand All @@ -21,4 +21,4 @@
#include <PAX_GRAPHICA/Texture.hpp>
#include <PAX_GRAPHICA/Window.hpp>

#endif // !PAX_GRAPHICA_GRAPHICS_HPP
#endif // !PAX_GRAPHICA_GRAPHICS_HPP
5 changes: 3 additions & 2 deletions Library/PAX_GRAPHICA/IDrawable.hpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/*##########################################################################################
/*##########################################################################################

PAX SAPIENTICA Library 💀🌿🌏

Expand Down Expand Up @@ -27,8 +27,9 @@ namespace paxg {
virtual void draw() const = 0;

virtual void drawAt(const Vec2f& pos) const = 0;
virtual void drawAt(const Vec2i& pos) const = 0;
};

}

#endif // !PAX_GRAPHICA_IDRAWABLE_HPP
#endif // !PAX_GRAPHICA_IDRAWABLE_HPP
6 changes: 3 additions & 3 deletions Library/PAX_GRAPHICA/Image.hpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/*##########################################################################################
/*##########################################################################################

PAX SAPIENTICA Library 💀🌿🌏

Expand Down Expand Up @@ -30,7 +30,7 @@ namespace paxg {
{
#if defined(PAXS_USING_SIV3D)
s3d::Image image;
constexpr Image(const paxg::String& path) : image(path) {}
Image(const paxg::String& path) : image(path.string) {}
constexpr operator s3d::Image() const { return image; }
#elif defined(PAXS_USING_SFML)
sf::Image image;
Expand All @@ -42,4 +42,4 @@ namespace paxg {
};
}

#endif // !PAX_GRAPHICA_IMAGE_HPP
#endif // !PAX_GRAPHICA_IMAGE_HPP
227 changes: 213 additions & 14 deletions Library/PAX_GRAPHICA/Rect.hpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/*##########################################################################################
/*##########################################################################################

PAX SAPIENTICA Library 💀🌿🌏

Expand Down Expand Up @@ -28,38 +28,237 @@

namespace paxg {

struct Line {
constexpr Line() = default;
#if defined(PAXS_USING_SIV3D)
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 Vec2i& e)
: line(sx, sy, e.x(), e.y()) {}
constexpr Line(const Vec2i& s, const Vec2i& e)
: line(s.x(), s.y(), e.x(), e.y()) {}

void draw(const double thickness, const paxg::Color& color) const {
line.draw(thickness, 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 Vec2i& pos, const Vec2i& size)
: x0(static_cast<float>(pos.x())), y0(static_cast<float>(pos.y())),
w0(static_cast<float>(size.x())), h0(static_cast<float>(size.y())) {}
constexpr Line(const Vec2i& pos, const float w, const float h) :
x0(static_cast<float>(pos.x())), y0(static_cast<float>(pos.y())), w0(w), h0(h) {}
constexpr Line(const float x, const float y, const Vec2i& size)
: x0(x), y0(y), w0(static_cast<float>(size.x())), h0(static_cast<float>(size.y())) {}

void draw(const double thickness, const paxg::Color& color) const {
// 直線の場合
if (y0 == h0 || x0 == w0) {
const int x1 = static_cast<int>(x0 - thickness / 2);
const int y1 = static_cast<int>(y0 - thickness / 2);
const int w1 = static_cast<int>(w0 + thickness / 2);
const int h1 = static_cast<int>(h0 + thickness / 2);

DxLib::DrawBox(
x1,
y1,
(w1 == x1) ? w1 + 1 : w1,
(h1 == y1) ? h1 + 1 : h1,
DxLib::GetColor(color.r, color.g, color.b), TRUE);
}
}
#else
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 Vec2i& e)
: sx0(sx), sy0(sy), ex0(e.x()), ey0(e.y()) {}
constexpr Line(const Vec2i& s, const Vec2i& e)
: sx0(s.x()), sy0(s.y()), ex0(e.x()), ey0(e.y()) {}

void draw(const double thickness, const paxg::Color& color) const {
}
#endif
};

struct Rect : public paxg::IDrawable {
#if defined(PAXS_USING_SIV3D)
s3d::RectF rect;
constexpr (const float x, const float y, const float w, const float h) : rect(x, y, w, h) {}
constexpr Rect(const Vec2& pos, const Vec2& size) : rect(pos.x, pos.y, size.x, size.y) {}
constexpr Rect(const Vec2& pos, const float w, const float h) : rect(pos.x, pos.y, w, h) {}
constexpr Rect(const float x, const float y, const Vec2& size) : rect(x, y, size.x, size.y) {}
s3d::RectF rect{};
constexpr Rect() = default;
constexpr Rect(const float x, const float y, const float w, const float h) : rect(x, y, w, h) {}
constexpr Rect(const Vec2i& pos, const Vec2i& size) : rect(pos.x(), pos.y(), size.x(), size.y()) {}
constexpr Rect(const Vec2i& pos, const float w, const float h) : rect(pos.x(), pos.y(), w, h) {}
constexpr Rect(const float x, const float y, const Vec2i& size) : rect(x, y, size.x(), size.y()) {}
constexpr operator s3d::RectF() const { return rect; }
void setX(const float x_) { rect.x = x_; }
void setY(const float y_) { rect.y = y_; }
void setW(const float w_) { rect.w = w_; }
void setH(const float h_) { rect.h = h_; }
float x() const { return static_cast<float>(rect.x); }
float y() const { return static_cast<float>(rect.y); }
float w() const { return static_cast<float>(rect.w); }
float h() const { return static_cast<float>(rect.h); }
Vec2i pos() const { return Vec2i(static_cast<int>(rect.x), static_cast<int>(rect.y)); }
Vec2i size() const { return Vec2i(static_cast<int>(rect.w), static_cast<int>(rect.h)); }
void setPos(const float x_, const float y_) {
rect.x = x_;
rect.y = y_;
}
void setSize(const float w_, const float h_) {
rect.w = w_;
rect.h = h_;
}
void setPos(const Vec2i pos_) {
rect.x = pos_.x();
rect.y = pos_.y();
}
void setSize(const Vec2i size_) {
rect.w = size_.x();
rect.h = size_.y();
}

#elif defined(PAXS_USING_SFML)
sf::RectangleShape rect;
sf::RectangleShape rect{};
constexpr Rect() = default;
Rect(const float x, const float y, const float w, const float h) : rect(sf::Vector2f(w, h)) { rect.setPosition(x, y); }
Rect(const sf::Vector2i& pos, const sf::Vector2i& size) : rect(sf::Vector2f(size.x, size.y)) { rect.setPosition(pos.x, pos.y); }
Rect(const sf::Vector2i& pos, const float w, const float h) : rect(sf::Vector2f(w, h)) { rect.setPosition(pos.x, pos.y); }
Rect(const float x, const float y, const sf::Vector2i& size) : rect(sf::Vector2f(size.x, size.y)) { rect.setPosition(x, y); }
operator sf::RectangleShape() const { return rect; }
void setX(const float x_) { rect.x = x_; }
void setY(const float y_) { rect.y = y_; }
void setW(const float w_) { rect.w = w_; }
void setH(const float h_) { rect.h = h_; }
float x() const { return rect.x; }
float y() const { return rect.y; }
float w() const { return rect.w; }
float h() const { return rect.h; }
Vec2i pos() const { return Vec2i(rect.x, rect.y); }
Vec2i size() const { return Vec2i(rect.w, rect.h); }
void setPos(const float x_, const float y_) {
rect.x = x_;
rect.y = y_;
}
void setSize(const float w_, const float h_) {
rect.w = w_;
rect.h = h_;
}
void setPos(const Vec2i pos_) {
rect.x = pos_.x();
rect.y = pos_.y();
}
void setSize(const Vec2i size_) {
rect.w = size_.x();
rect.h = size_.y();
}
#else
float x, y, w, h;
constexpr Rect(const float x, const float y, const float w, const float h) : x(x), y(y), w(w), h(h) {}
constexpr Rect(const Vec2& pos, const Vec2& size) : x(pos.x), y(pos.y), w(size.x), h(size.y) {}
constexpr Rect(const Vec2& pos, const float w, const float h) : x(pos.x), y(pos.y), w(w), h(h) {}
constexpr Rect(const float x, const float y, const Vec2& size) : x(x), y(y), w(size.x), h(size.y) {}
float x0{}, y0{}, w0{}, h0{};
constexpr Rect() = default;
constexpr Rect(const float x, const float y, const float w, const float h) :
x0(x), y0(y), w0(w), h0(h) {}
constexpr Rect(const Vec2i& pos, const Vec2i& size)
: x0(static_cast<float>(pos.x())), y0(static_cast<float>(pos.y())),
w0(static_cast<float>(size.x())), h0(static_cast<float>(size.y())) {}
constexpr Rect(const Vec2i& pos, const float w, const float h) :
x0(static_cast<float>(pos.x())), y0(static_cast<float>(pos.y())), w0(w), h0(h) {}
constexpr Rect(const float x, const float y, const Vec2i& size)
: x0(x), y0(y), w0(static_cast<float>(size.x())), h0(static_cast<float>(size.y())) {}
void setX(const float x_) { x0 = x_; }
void setY(const float y_) { y0 = y_; }
void setW(const float w_) { w0 = w_; }
void setH(const float h_) { h0 = h_; }
float x() const { return x0; }
float y() const { return y0; }
float w() const { return w0; }
float h() const { return h0; }
Vec2i pos() const { return Vec2i(x0, y0); }
Vec2i size() const { return Vec2i(w0, h0); }
void setPos(const float x_, const float y_) {
x0 = x_;
y0 = y_;
}
void setSize(const float w_, const float h_) {
w0 = w_;
h0 = h_;
}
void setPos(const Vec2i pos_) {
x0 = static_cast<float>(pos_.x());
y0 = static_cast<float>(pos_.y());
}
void setSize(const Vec2i size_) {
w0 = static_cast<float>(size_.x());
h0 = static_cast<float>(size_.y());
}
#endif
void draw() const override {
#if defined(PAXS_USING_SIV3D)
rect.draw();
#elif defined(PAXS_USING_SFML)
Window::window.draw(rect);
#elif defined(PAXS_USING_DXLIB)
DxLib::DrawBox(x0, y0, x0 + w0, y0 + h0, DxLib::GetColor(255, 255, 255), TRUE);
#endif
}
void draw(const paxg::Color& c_) const {
#if defined(PAXS_USING_SIV3D)
rect.draw(c_.color);
#elif defined(PAXS_USING_SFML)
Window::window.draw(c_);
#elif defined(PAXS_USING_DXLIB)
DxLib::DrawBox(x0, y0, x0 + w0, y0 + h0, DxLib::GetColor(c_.r, c_.g, c_.b), TRUE);
#endif
}

void drawFrame(const double inner_thickness, const double outer_thickness, const paxg::Color& color_) const {
#if defined(PAXS_USING_SIV3D)
rect.drawFrame(inner_thickness, outer_thickness, color_.color);
#elif defined(PAXS_USING_SFML)
Window::window.draw(color_);
#elif defined(PAXS_USING_DXLIB)
DxLib::DrawBox(
x0 - outer_thickness, y0 - outer_thickness,
x0 + w0 + outer_thickness, y0 + inner_thickness,
DxLib::GetColor(color_.r, color_.g, color_.b), TRUE);
DxLib::DrawBox(
x0 - outer_thickness, y0 + h0 - inner_thickness,
x0 + w0 + outer_thickness, y0 + h0 + outer_thickness,
DxLib::GetColor(color_.r, color_.g, color_.b), TRUE);
DxLib::DrawBox(
x0 - outer_thickness, y0 - outer_thickness,
x0 + inner_thickness, y0 + h0 + outer_thickness,
DxLib::GetColor(color_.r, color_.g, color_.b), TRUE);
DxLib::DrawBox(
x0 + w0 - inner_thickness, y0 - outer_thickness,
x0 + w0 + outer_thickness, y0 + h0 + outer_thickness,
DxLib::GetColor(color_.r, color_.g, color_.b), TRUE);
#endif
}

bool leftClicked() const {
#if defined(PAXS_USING_SIV3D)
return rect.leftClicked();
#else
return false;
#endif
}
bool mouseOver() const {
#if defined(PAXS_USING_SIV3D)
return rect.mouseOver();
#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);
#else
return false;
#endif
}

void drawAt(const Vec2f& pos) const override {}
void drawAt(const Vec2f&) const override {}
void drawAt(const Vec2i&) const override {}
};
}

#endif // !PAX_GRAPHICA_RECT_HPP
#endif // !PAX_GRAPHICA_RECT_HPP
Loading