1- /* ##########################################################################################
1+ /* ##########################################################################################
22
33 PAX SAPIENTICA Library 💀🌿🌏
44
2828
2929namespace 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