Files
ReJUI/include/JUI/Base/ImageBase.hpp

67 lines
2.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 ImageBase.hpp
/// @desc Base implementation for image drawing that is employed by widgets that wish to draw images.
/// @edit 2024-08-05
#pragma once
#include <Color4.hpp>
#include <J3ML/LinearAlgebra/Vector2.hpp>
#include <JGL/types/Texture.h>
#include <JGL/types/RenderTarget.h>
using J3ML::LinearAlgebra::Vector2;
namespace JUI {
/// The ImageBase class is an object that handles managing and rendering a texture reference.
/// This class is used as a mixin on widgets that must render images. i.e. Image class.
/// This object is complex, stateful, and manages resources. Do not use this as a general-purpose texture data type.
/// @see JGL::Texture and JGL::RenderTarget for more suitable classes.
class ImageBase
{
public:
/// The default constructor initializes this ImageBase with a null pointer texture.
ImageBase();
ImageBase(JGL::RenderTarget *content);
/// This constructor initializes this ImageBase with a JGL::Texture pointer.
explicit ImageBase(JGL::Texture* texture);
public:
[[nodiscard]] JGL::RenderTarget* RenderTarget() const { return texture;}
/// Returns the texture pointer held by this object.
[[nodiscard]] const JGL::Texture* Content() const;
/// Returns the color of this object. The texture is rendered with this color.
[[nodiscard]] Color4 Color() const;
/// Returns the scale factor of this object. The texture is scaled with this value.
[[nodiscard]] Vector2 Scale() const;
/// Returns the origin factor of this object. The texture's origin is determined by this value.
[[nodiscard]] Vector2 Origin() const;
/// Sets the texture of this object.
void Content(const JGL::Texture* content);
void Content(JGL::RenderTarget* content);
/// Sets the color of this object.
void Color(const Color4& newColor);
/// Sets the scale factor of this object.
void Scale(const Vector2& newScale);
void Origin(const Vector2& newOrigin);
public:
/// Draws the image at the given position, with the instances' scale and origin.
void Draw(const Vector2& pos);
/// Draws the image at the given pos, manually scaled to fit the given size.
void Draw(const Vector2& pos, const Vector2& size);
protected:
JGL::RenderTarget* texture;
Color4 image_color = Color4(255,255,255);
Vector2 scale = Vector2(1,1);
Vector2 origin = Vector2(0,0);
private:
};
}