Implemented NineSliceRect widget.
This commit is contained in:
@@ -19,35 +19,33 @@
|
||||
|
||||
namespace JUI
|
||||
{
|
||||
|
||||
class NineSliceRect : public Rect, public ImageBase {
|
||||
|
||||
public:
|
||||
AABB2D top_left_quad {{0,0},{96,96}};
|
||||
AABB2D top_right_quad {{384-96,0},{96,96}};
|
||||
AABB2D bottom_left_quad { {0, 378-96}, {96, 96}};
|
||||
AABB2D bottom_right_quad { {384-96, 378-96}, {96, 96}};
|
||||
NineSliceRect();
|
||||
explicit NineSliceRect(Widget* parent);
|
||||
NineSliceRect(Widget* parent, JGL::Texture* texture);
|
||||
|
||||
AABB2D top_quad { {96, 0}, {192, 96} };
|
||||
AABB2D bottom_quad { {96, 378-96}, {192, 96} };
|
||||
AABB2D right_quad {{384-(96), 96}, {96, 378-(96*2)}};
|
||||
AABB2D left_quad {{0, 96}, {96, 378-(96*2)}};
|
||||
/// Returns the bounds of the 'Top-Left' slice of the 9-slice.
|
||||
[[nodiscard]] AABB2D TopLeftQuad() const;
|
||||
/// Returns the bounds of the 'Top-Right' slice of the 9-slice.
|
||||
[[nodiscard]] AABB2D TopRightQuad() const;
|
||||
/// Returns the bounds of the 'Bottom-Left' slice of the 9-slice.
|
||||
[[nodiscard]] AABB2D BottomLeftQuad() const;
|
||||
/// Returns the bounds of the 'Bottom-Right' slice of the 9-slice.
|
||||
[[nodiscard]] AABB2D BottomRightQuad() const;
|
||||
|
||||
AABB2D center_quad;
|
||||
public:
|
||||
NineSliceRect() : Rect(), ImageBase() {}
|
||||
explicit NineSliceRect(Widget* parent) : Rect(parent), ImageBase() {}
|
||||
NineSliceRect(Widget* parent, JGL::Texture* texture) : Rect(parent), ImageBase(texture) {}
|
||||
|
||||
AABB2D TopLeftQuad() const;
|
||||
AABB2D TopRightQuad() const;
|
||||
AABB2D BottomLeftQuad() const;
|
||||
AABB2D BottomRightQuad() const;
|
||||
|
||||
AABB2D TopQuad() const;
|
||||
AABB2D LeftQuad() const;
|
||||
AABB2D RightQuad() const;
|
||||
AABB2D BottomQuad() const;
|
||||
|
||||
AABB2D CenterQuad() const;
|
||||
/// Returns the bounds of the 'Top' slice of the 9-slice.
|
||||
[[nodiscard]] AABB2D TopQuad() const;
|
||||
/// Returns the bounds of the 'Left' slice of the 9-slice.
|
||||
[[nodiscard]] AABB2D LeftQuad() const;
|
||||
/// Returns the bounds of the 'Right' slice of the 9-slice.
|
||||
[[nodiscard]] AABB2D RightQuad() const;
|
||||
/// Returns the bounds of the 'Bottom' slice of the 9-slice.
|
||||
[[nodiscard]] AABB2D BottomQuad() const;
|
||||
/// Returns the bounds of the 'Center' slice of the 9-slice.
|
||||
[[nodiscard]] AABB2D CenterQuad() const;
|
||||
|
||||
/// Sets the bounds of the quadrant for the 'Top-Left' slice of the 9-slice.
|
||||
void TopLeftQuad(const AABB2D& quad);
|
||||
@@ -57,16 +55,29 @@ namespace JUI
|
||||
void BottomLeftQuad(const AABB2D& quad);
|
||||
/// Sets the bounds of the quadrant for the 'Bottom-Right' slice of the 9-slice.
|
||||
void BottomRightQuad(const AABB2D& quad);
|
||||
|
||||
/// Sets the bounds of the quadrant for the 'Top' slice of the 9-slice.
|
||||
void TopQuad(const AABB2D& quad);
|
||||
/// Sets the bounds of the quadrant for the 'Right' slice of the 9-slice.
|
||||
void RightQuad(const AABB2D& quad);
|
||||
/// Sets the bounds of the quadrant for the 'Bottom' slice of the 9-slice.
|
||||
void BottomQuad(const AABB2D& quad);
|
||||
/// Sets the bounds of the quadrant for the 'Left' slice of the 9-slice.
|
||||
void LeftQuad(const AABB2D& quad);
|
||||
|
||||
/// Sets the bounds of the quadrant for the 'Center' slice of the 9-slice.
|
||||
void CenterQuad(const AABB2D& quad);
|
||||
|
||||
|
||||
|
||||
void Draw() override;
|
||||
protected:
|
||||
AABB2D top_left_quad;
|
||||
AABB2D top_right_quad;
|
||||
AABB2D bottom_left_quad;
|
||||
AABB2D bottom_right_quad;
|
||||
|
||||
AABB2D top_quad;
|
||||
AABB2D bottom_quad;
|
||||
AABB2D right_quad;
|
||||
AABB2D left_quad;
|
||||
|
||||
AABB2D center_quad;
|
||||
};
|
||||
}
|
11
main.cpp
11
main.cpp
@@ -236,6 +236,17 @@ JUI::Scene* CreateScene() {
|
||||
nineslice->Content(slicer);
|
||||
nineslice->Size({100_percent, 100_percent});
|
||||
nineslice->BGColor(Colors::Transparent);
|
||||
nineslice->TopLeftQuad({{0,0},{96,96}});
|
||||
nineslice->TopRightQuad({{384-96,0},{96,96}});
|
||||
nineslice->BottomLeftQuad({ {0, 378-96}, {96, 96}});
|
||||
nineslice->BottomRightQuad({ {384-96, 378-96}, {96, 96}});
|
||||
|
||||
nineslice->TopQuad({ {96, 0}, {192, 96} });
|
||||
nineslice->BottomQuad({ {96, 378-96}, {192, 96} });
|
||||
nineslice->RightQuad({{384-(96), 96}, {96, 378-(96*2)}});
|
||||
nineslice->LeftQuad({{0, 96}, {96, 378-(96*2)}});
|
||||
|
||||
nineslice->CenterQuad({{96, 96}, {384-(96*2), 378-(96*2)}});
|
||||
|
||||
|
||||
auto darkie = new JUI::Image(win_element->GetViewportInstance(), sample_texture);
|
||||
|
@@ -101,8 +101,21 @@ namespace JUI
|
||||
|
||||
// Draw Center Quad
|
||||
|
||||
auto c_quad = CenterQuad();
|
||||
Vector2 c_computed_pos = abs_pos + tl_quad.maxPoint;
|
||||
Vector2 c_scaling = Vector2(abs_width_minus_corners, abs_height_minus_corners) / c_quad.maxPoint;
|
||||
|
||||
JGL::J2D::DrawPartialSprite(texture, c_computed_pos, c_quad.minPoint, c_quad.maxPoint, 0, {0,0}, c_scaling);
|
||||
|
||||
|
||||
JGL::J2D::End();
|
||||
}
|
||||
|
||||
NineSliceRect::NineSliceRect() : Rect(), ImageBase() {}
|
||||
|
||||
NineSliceRect::NineSliceRect(Widget *parent) : Rect(parent), ImageBase() {}
|
||||
|
||||
NineSliceRect::NineSliceRect(Widget *parent, JGL::Texture *texture) : Rect(parent), ImageBase(texture) {}
|
||||
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user