62 lines
1.8 KiB
C++
62 lines
1.8 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 UDim2.hpp
|
|
/// @desc Universal Dimensions 2D Class
|
|
/// @edit 2024-07-10
|
|
|
|
|
|
#pragma once
|
|
|
|
#include <J3ML/LinearAlgebra.h>
|
|
#include <JUI/UDim.hpp>
|
|
|
|
namespace JUI
|
|
{
|
|
|
|
using namespace J3ML::LinearAlgebra;
|
|
|
|
/// Funky Coordinate system purpose-built for screen positioning
|
|
/// Contains an X and Y UDim, each containing an integer "Pixels", and fractional "Scale" (0-1) value.
|
|
/// GUI Elements use this type to describe their sizing in relation to their parent.
|
|
/// @see UDim.hpp
|
|
class UDim2
|
|
{
|
|
public: // Properties
|
|
UDim X;
|
|
UDim Y;
|
|
public: // Constructors
|
|
UDim2();
|
|
|
|
UDim2(int px, int py, float sx, float sy) {
|
|
X = {px, sx};
|
|
Y = {py, sy};
|
|
}
|
|
UDim2(Vector2 pixels, Vector2 scale) {
|
|
X = {static_cast<int>(pixels.x), scale.x};
|
|
Y = {static_cast<int>(pixels.y), scale.y};
|
|
}
|
|
static UDim2 FromPixels(int x, int y) { return {x, y, 0, 0}; }
|
|
static UDim2 FromScale(float x, float y) { return {0, 0, x, y}; }
|
|
public: // Operators
|
|
UDim2 operator +(const UDim2& rhs) const;
|
|
UDim2 operator -(const UDim2& rhs) const;
|
|
UDim2 operator *(float rhs) const;
|
|
UDim2 operator /(float rhs) const;
|
|
UDim2 &operator=(const UDim2 &) = default;
|
|
public: // Methods
|
|
Vector2 GetScale() const {
|
|
return {X.Scale, Y.Scale};
|
|
}
|
|
Vector2 GetPixels() const {
|
|
return {X.Pixels, Y.Pixels};
|
|
}
|
|
protected:
|
|
private:
|
|
};
|
|
|
|
} |