Files
ReJUI/include/JUI/Widgets/NineSlice.hpp

83 lines
3.3 KiB
C++

/// Josh's User Interface Library
/// A C++20 Library for creating, styling, and rendering of a UI/UX widgets.
/// Developed and Maintained by Josh O'Leary @ Redacted Software.
/// Special Thanks to William Tomasine II and Maxine Hayes.
/// (c) 2024 Redacted Software
/// This work is dedicated to the public domain.
/// @file NineSlice.hpp
/// @desc A widget that implements 9-slice scaling on an image.
/// @edit 2025-2-2
/// https://en.wikipedia.org/wiki/9-slice_scaling
#pragma once
#include <JUI/Base/Widget.hpp>
#include <JUI/Widgets/Rect.hpp>
#include <JUI/Base/ImageBase.hpp>
namespace JUI
{
class NineSliceRect : public Rect, public ImageBase {
public:
NineSliceRect();
explicit NineSliceRect(Widget* parent);
NineSliceRect(Widget* parent, JGL::Texture* texture);
/// 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;
/// 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);
/// Sets the bounds of the quadrant for the 'Top-Right' slice of the 9-slice.
void TopRightQuad(const AABB2D& quad);
/// Sets the bounds of the quadrant for the 'Bottom-Left' slice of the 9-slice.
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;
};
}