Skip to content

Commit 7db0ef5

Browse files
committed
Multi-platform support for PAX_GRAPHICA.
1 parent 938678f commit 7db0ef5

39 files changed

+1530
-478
lines changed

Library/PAX_GRAPHICA/Circle.hpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/*##########################################################################################
1+
/*##########################################################################################
22
33
PAX SAPIENTICA Library 💀🌿🌏
44
@@ -42,7 +42,7 @@ namespace paxg {
4242
#else
4343
float x, y, r;
4444
constexpr Circle(const float x, const float y, const float r) : x(x), y(y), r(r) {}
45-
constexpr Circle(const Vec2& pos, const float r) : x(pos.x), y(pos.y), r(r) {}
45+
constexpr Circle(const Vec2& pos, const float r) : x(pos.x()), y(pos.y()), r(r) {}
4646
#endif
4747
void draw() const override {
4848
#if defined(PAXS_USING_SIV3D)
@@ -56,4 +56,4 @@ namespace paxg {
5656
};
5757
}
5858

59-
#endif // !PAX_GRAPHICA_CIRCLE_HPP
59+
#endif // !PAX_GRAPHICA_CIRCLE_HPP

Library/PAX_GRAPHICA/Color.hpp

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/*##########################################################################################
1+
/*##########################################################################################
22
33
PAX SAPIENTICA Library 💀🌿🌏
44
@@ -24,21 +24,29 @@
2424

2525
namespace paxg {
2626

27+
// R 赤
28+
// G 緑
29+
// B 青
30+
// A 不透明度
2731
struct Color {
2832
#if defined(PAXS_USING_SIV3D)
2933
s3d::Color color;
30-
constexpr Color(const int r, const int g, const int b, const int a) : color(r, g, b, a) {}
31-
constexpr s3d::Color() const { return color; }
34+
constexpr Color(const int r, const int g, const int b, const int a = 255) :
35+
color(static_cast<s3d::Color::value_type>(r),
36+
static_cast<s3d::Color::value_type>(g),
37+
static_cast<s3d::Color::value_type>(b),
38+
static_cast<s3d::Color::value_type>(a)) {}
39+
operator s3d::Color() const { return color; }
3240
#elif defined(PAXS_USING_SFML)
3341
sf::Color color;
34-
Color(const int r, const int g, const int b, const int a) : color(r, g, b, a) {}
42+
Color(const int r, const int g, const int b, const int a = 255) : color(r, g, b, a) {}
3543
operator sf::Color() const { return color; }
3644
#else
37-
int r, g, b, a;
38-
constexpr Color(int r, int g, int b, int a) : r(r), g(g), b(b), a(a) {}
45+
int r, g, b, a = 255;
46+
constexpr Color(int r, int g, int b, int a = 255) : r(r), g(g), b(b), a(a) {}
3947
#endif
4048
};
4149

4250
}
4351

44-
#endif // !PAX_GRAPHICA_COLOR_HPP
52+
#endif // !PAX_GRAPHICA_COLOR_HPP

Library/PAX_GRAPHICA/Graphics.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/*##########################################################################################
1+
/*##########################################################################################
22
33
PAX SAPIENTICA Library 💀🌿🌏
44
@@ -21,4 +21,4 @@
2121
#include <PAX_GRAPHICA/Texture.hpp>
2222
#include <PAX_GRAPHICA/Window.hpp>
2323

24-
#endif // !PAX_GRAPHICA_GRAPHICS_HPP
24+
#endif // !PAX_GRAPHICA_GRAPHICS_HPP

Library/PAX_GRAPHICA/IDrawable.hpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/*##########################################################################################
1+
/*##########################################################################################
22
33
PAX SAPIENTICA Library 💀🌿🌏
44
@@ -27,8 +27,9 @@ namespace paxg {
2727
virtual void draw() const = 0;
2828

2929
virtual void drawAt(const Vec2f& pos) const = 0;
30+
virtual void drawAt(const Vec2i& pos) const = 0;
3031
};
3132

3233
}
3334

34-
#endif // !PAX_GRAPHICA_IDRAWABLE_HPP
35+
#endif // !PAX_GRAPHICA_IDRAWABLE_HPP

Library/PAX_GRAPHICA/Image.hpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/*##########################################################################################
1+
/*##########################################################################################
22
33
PAX SAPIENTICA Library 💀🌿🌏
44
@@ -30,7 +30,7 @@ namespace paxg {
3030
{
3131
#if defined(PAXS_USING_SIV3D)
3232
s3d::Image image;
33-
constexpr Image(const paxg::String& path) : image(path) {}
33+
Image(const paxg::String& path) : image(path.string) {}
3434
constexpr operator s3d::Image() const { return image; }
3535
#elif defined(PAXS_USING_SFML)
3636
sf::Image image;
@@ -42,4 +42,4 @@ namespace paxg {
4242
};
4343
}
4444

45-
#endif // !PAX_GRAPHICA_IMAGE_HPP
45+
#endif // !PAX_GRAPHICA_IMAGE_HPP

Library/PAX_GRAPHICA/Rect.hpp

Lines changed: 213 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/*##########################################################################################
1+
/*##########################################################################################
22
33
PAX SAPIENTICA Library 💀🌿🌏
44
@@ -28,38 +28,237 @@
2828

2929
namespace paxg {
3030

31+
struct Line {
32+
constexpr Line() = default;
33+
#if defined(PAXS_USING_SIV3D)
34+
s3d::Line line{};
35+
constexpr Line(const float sx, const float sy, const float ex, const float ey)
36+
: line(sx, sy, ex, ey) {}
37+
constexpr Line(const float sx, const float sy, const Vec2i& e)
38+
: line(sx, sy, e.x(), e.y()) {}
39+
constexpr Line(const Vec2i& s, const Vec2i& e)
40+
: line(s.x(), s.y(), e.x(), e.y()) {}
41+
42+
void draw(const double thickness, const paxg::Color& color) const {
43+
line.draw(thickness, color.color);
44+
}
45+
#elif defined(PAXS_USING_DXLIB)
46+
float x0{}, y0{}, w0{}, h0{};
47+
constexpr Line(const float x, const float y, const float w, const float h) :
48+
x0(x), y0(y), w0(w), h0(h) {}
49+
constexpr Line(const Vec2i& pos, const Vec2i& size)
50+
: x0(static_cast<float>(pos.x())), y0(static_cast<float>(pos.y())),
51+
w0(static_cast<float>(size.x())), h0(static_cast<float>(size.y())) {}
52+
constexpr Line(const Vec2i& pos, const float w, const float h) :
53+
x0(static_cast<float>(pos.x())), y0(static_cast<float>(pos.y())), w0(w), h0(h) {}
54+
constexpr Line(const float x, const float y, const Vec2i& size)
55+
: x0(x), y0(y), w0(static_cast<float>(size.x())), h0(static_cast<float>(size.y())) {}
56+
57+
void draw(const double thickness, const paxg::Color& color) const {
58+
// 直線の場合
59+
if (y0 == h0 || x0 == w0) {
60+
const int x1 = static_cast<int>(x0 - thickness / 2);
61+
const int y1 = static_cast<int>(y0 - thickness / 2);
62+
const int w1 = static_cast<int>(w0 + thickness / 2);
63+
const int h1 = static_cast<int>(h0 + thickness / 2);
64+
65+
DxLib::DrawBox(
66+
x1,
67+
y1,
68+
(w1 == x1) ? w1 + 1 : w1,
69+
(h1 == y1) ? h1 + 1 : h1,
70+
DxLib::GetColor(color.r, color.g, color.b), TRUE);
71+
}
72+
}
73+
#else
74+
float sx0{}, sy0{}, ex0{}, ey0{};
75+
constexpr Line(const float sx, const float sy, const float ex, const float ey)
76+
: sx0(sx), sy0(sy), ex0(ex), ey0(ey) {}
77+
constexpr Line(const float sx, const float sy, const Vec2i& e)
78+
: sx0(sx), sy0(sy), ex0(e.x()), ey0(e.y()) {}
79+
constexpr Line(const Vec2i& s, const Vec2i& e)
80+
: sx0(s.x()), sy0(s.y()), ex0(e.x()), ey0(e.y()) {}
81+
82+
void draw(const double thickness, const paxg::Color& color) const {
83+
}
84+
#endif
85+
};
86+
3187
struct Rect : public paxg::IDrawable {
3288
#if defined(PAXS_USING_SIV3D)
33-
s3d::RectF rect;
34-
constexpr (const float x, const float y, const float w, const float h) : rect(x, y, w, h) {}
35-
constexpr Rect(const Vec2& pos, const Vec2& size) : rect(pos.x, pos.y, size.x, size.y) {}
36-
constexpr Rect(const Vec2& pos, const float w, const float h) : rect(pos.x, pos.y, w, h) {}
37-
constexpr Rect(const float x, const float y, const Vec2& size) : rect(x, y, size.x, size.y) {}
89+
s3d::RectF rect{};
90+
constexpr Rect() = default;
91+
constexpr Rect(const float x, const float y, const float w, const float h) : rect(x, y, w, h) {}
92+
constexpr Rect(const Vec2i& pos, const Vec2i& size) : rect(pos.x(), pos.y(), size.x(), size.y()) {}
93+
constexpr Rect(const Vec2i& pos, const float w, const float h) : rect(pos.x(), pos.y(), w, h) {}
94+
constexpr Rect(const float x, const float y, const Vec2i& size) : rect(x, y, size.x(), size.y()) {}
3895
constexpr operator s3d::RectF() const { return rect; }
96+
void setX(const float x_) { rect.x = x_; }
97+
void setY(const float y_) { rect.y = y_; }
98+
void setW(const float w_) { rect.w = w_; }
99+
void setH(const float h_) { rect.h = h_; }
100+
float x() const { return static_cast<float>(rect.x); }
101+
float y() const { return static_cast<float>(rect.y); }
102+
float w() const { return static_cast<float>(rect.w); }
103+
float h() const { return static_cast<float>(rect.h); }
104+
Vec2i pos() const { return Vec2i(static_cast<int>(rect.x), static_cast<int>(rect.y)); }
105+
Vec2i size() const { return Vec2i(static_cast<int>(rect.w), static_cast<int>(rect.h)); }
106+
void setPos(const float x_, const float y_) {
107+
rect.x = x_;
108+
rect.y = y_;
109+
}
110+
void setSize(const float w_, const float h_) {
111+
rect.w = w_;
112+
rect.h = h_;
113+
}
114+
void setPos(const Vec2i pos_) {
115+
rect.x = pos_.x();
116+
rect.y = pos_.y();
117+
}
118+
void setSize(const Vec2i size_) {
119+
rect.w = size_.x();
120+
rect.h = size_.y();
121+
}
122+
39123
#elif defined(PAXS_USING_SFML)
40-
sf::RectangleShape rect;
124+
sf::RectangleShape rect{};
125+
constexpr Rect() = default;
41126
Rect(const float x, const float y, const float w, const float h) : rect(sf::Vector2f(w, h)) { rect.setPosition(x, y); }
42127
Rect(const sf::Vector2i& pos, const sf::Vector2i& size) : rect(sf::Vector2f(size.x, size.y)) { rect.setPosition(pos.x, pos.y); }
43128
Rect(const sf::Vector2i& pos, const float w, const float h) : rect(sf::Vector2f(w, h)) { rect.setPosition(pos.x, pos.y); }
44129
Rect(const float x, const float y, const sf::Vector2i& size) : rect(sf::Vector2f(size.x, size.y)) { rect.setPosition(x, y); }
45130
operator sf::RectangleShape() const { return rect; }
131+
void setX(const float x_) { rect.x = x_; }
132+
void setY(const float y_) { rect.y = y_; }
133+
void setW(const float w_) { rect.w = w_; }
134+
void setH(const float h_) { rect.h = h_; }
135+
float x() const { return rect.x; }
136+
float y() const { return rect.y; }
137+
float w() const { return rect.w; }
138+
float h() const { return rect.h; }
139+
Vec2i pos() const { return Vec2i(rect.x, rect.y); }
140+
Vec2i size() const { return Vec2i(rect.w, rect.h); }
141+
void setPos(const float x_, const float y_) {
142+
rect.x = x_;
143+
rect.y = y_;
144+
}
145+
void setSize(const float w_, const float h_) {
146+
rect.w = w_;
147+
rect.h = h_;
148+
}
149+
void setPos(const Vec2i pos_) {
150+
rect.x = pos_.x();
151+
rect.y = pos_.y();
152+
}
153+
void setSize(const Vec2i size_) {
154+
rect.w = size_.x();
155+
rect.h = size_.y();
156+
}
46157
#else
47-
float x, y, w, h;
48-
constexpr Rect(const float x, const float y, const float w, const float h) : x(x), y(y), w(w), h(h) {}
49-
constexpr Rect(const Vec2& pos, const Vec2& size) : x(pos.x), y(pos.y), w(size.x), h(size.y) {}
50-
constexpr Rect(const Vec2& pos, const float w, const float h) : x(pos.x), y(pos.y), w(w), h(h) {}
51-
constexpr Rect(const float x, const float y, const Vec2& size) : x(x), y(y), w(size.x), h(size.y) {}
158+
float x0{}, y0{}, w0{}, h0{};
159+
constexpr Rect() = default;
160+
constexpr Rect(const float x, const float y, const float w, const float h) :
161+
x0(x), y0(y), w0(w), h0(h) {}
162+
constexpr Rect(const Vec2i& pos, const Vec2i& size)
163+
: x0(static_cast<float>(pos.x())), y0(static_cast<float>(pos.y())),
164+
w0(static_cast<float>(size.x())), h0(static_cast<float>(size.y())) {}
165+
constexpr Rect(const Vec2i& pos, const float w, const float h) :
166+
x0(static_cast<float>(pos.x())), y0(static_cast<float>(pos.y())), w0(w), h0(h) {}
167+
constexpr Rect(const float x, const float y, const Vec2i& size)
168+
: x0(x), y0(y), w0(static_cast<float>(size.x())), h0(static_cast<float>(size.y())) {}
169+
void setX(const float x_) { x0 = x_; }
170+
void setY(const float y_) { y0 = y_; }
171+
void setW(const float w_) { w0 = w_; }
172+
void setH(const float h_) { h0 = h_; }
173+
float x() const { return x0; }
174+
float y() const { return y0; }
175+
float w() const { return w0; }
176+
float h() const { return h0; }
177+
Vec2i pos() const { return Vec2i(x0, y0); }
178+
Vec2i size() const { return Vec2i(w0, h0); }
179+
void setPos(const float x_, const float y_) {
180+
x0 = x_;
181+
y0 = y_;
182+
}
183+
void setSize(const float w_, const float h_) {
184+
w0 = w_;
185+
h0 = h_;
186+
}
187+
void setPos(const Vec2i pos_) {
188+
x0 = static_cast<float>(pos_.x());
189+
y0 = static_cast<float>(pos_.y());
190+
}
191+
void setSize(const Vec2i size_) {
192+
w0 = static_cast<float>(size_.x());
193+
h0 = static_cast<float>(size_.y());
194+
}
52195
#endif
53196
void draw() const override {
54197
#if defined(PAXS_USING_SIV3D)
55198
rect.draw();
56199
#elif defined(PAXS_USING_SFML)
57200
Window::window.draw(rect);
201+
#elif defined(PAXS_USING_DXLIB)
202+
DxLib::DrawBox(x0, y0, x0 + w0, y0 + h0, DxLib::GetColor(255, 255, 255), TRUE);
203+
#endif
204+
}
205+
void draw(const paxg::Color& c_) const {
206+
#if defined(PAXS_USING_SIV3D)
207+
rect.draw(c_.color);
208+
#elif defined(PAXS_USING_SFML)
209+
Window::window.draw(c_);
210+
#elif defined(PAXS_USING_DXLIB)
211+
DxLib::DrawBox(x0, y0, x0 + w0, y0 + h0, DxLib::GetColor(c_.r, c_.g, c_.b), TRUE);
212+
#endif
213+
}
214+
215+
void drawFrame(const double inner_thickness, const double outer_thickness, const paxg::Color& color_) const {
216+
#if defined(PAXS_USING_SIV3D)
217+
rect.drawFrame(inner_thickness, outer_thickness, color_.color);
218+
#elif defined(PAXS_USING_SFML)
219+
Window::window.draw(color_);
220+
#elif defined(PAXS_USING_DXLIB)
221+
DxLib::DrawBox(
222+
x0 - outer_thickness, y0 - outer_thickness,
223+
x0 + w0 + outer_thickness, y0 + inner_thickness,
224+
DxLib::GetColor(color_.r, color_.g, color_.b), TRUE);
225+
DxLib::DrawBox(
226+
x0 - outer_thickness, y0 + h0 - inner_thickness,
227+
x0 + w0 + outer_thickness, y0 + h0 + outer_thickness,
228+
DxLib::GetColor(color_.r, color_.g, color_.b), TRUE);
229+
DxLib::DrawBox(
230+
x0 - outer_thickness, y0 - outer_thickness,
231+
x0 + inner_thickness, y0 + h0 + outer_thickness,
232+
DxLib::GetColor(color_.r, color_.g, color_.b), TRUE);
233+
DxLib::DrawBox(
234+
x0 + w0 - inner_thickness, y0 - outer_thickness,
235+
x0 + w0 + outer_thickness, y0 + h0 + outer_thickness,
236+
DxLib::GetColor(color_.r, color_.g, color_.b), TRUE);
237+
#endif
238+
}
239+
240+
bool leftClicked() const {
241+
#if defined(PAXS_USING_SIV3D)
242+
return rect.leftClicked();
243+
#else
244+
return false;
245+
#endif
246+
}
247+
bool mouseOver() const {
248+
#if defined(PAXS_USING_SIV3D)
249+
return rect.mouseOver();
250+
#elif defined(PAXS_USING_DXLIB)
251+
int mx = 0, my = 0;
252+
DxLib::GetMousePoint(&mx, &my);
253+
return (mx >= x0 && my >= y0 && mx < x0 + w0 && my < y0 + h0);
254+
#else
255+
return false;
58256
#endif
59257
}
60258

61-
void drawAt(const Vec2f& pos) const override {}
259+
void drawAt(const Vec2f&) const override {}
260+
void drawAt(const Vec2i&) const override {}
62261
};
63262
}
64263

65-
#endif // !PAX_GRAPHICA_RECT_HPP
264+
#endif // !PAX_GRAPHICA_RECT_HPP

0 commit comments

Comments
 (0)