Added ImageBase::Draw overload that takes size of parent object to compute scale for image.
This commit is contained in:
@@ -20,7 +20,9 @@ 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 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:
|
||||
@@ -46,6 +48,9 @@ namespace JUI
|
||||
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::Texture* texture;
|
||||
|
@@ -1,15 +1,33 @@
|
||||
#include <JUI/Base/ImageBase.hpp>
|
||||
#include <JGL/JGL.h>
|
||||
#include <JUI/JUI.hpp>
|
||||
|
||||
using namespace JGL;
|
||||
|
||||
namespace JUI
|
||||
{
|
||||
void ImageBase::Draw(const Vector2 &pos, const Vector2 &size) {
|
||||
//J2D::Begin();
|
||||
void ImageBase::Draw(const Vector2 &pos) {
|
||||
if (texture == nullptr) {
|
||||
UILogs("Attempt to draw ImageBase that has nullptr texture!");
|
||||
return;
|
||||
}
|
||||
|
||||
// TODO: Support image rotation in the widget.
|
||||
J2D::DrawSprite(*texture, pos, 0, origin, scale, image_color);
|
||||
//J2D::End();
|
||||
|
||||
}
|
||||
|
||||
void ImageBase::Draw(const Vector2 &pos, const Vector2 &size) {
|
||||
if (texture == nullptr) {
|
||||
UILogs("Attempt to draw ImageBase that has nullptr texture!");
|
||||
return;
|
||||
}
|
||||
|
||||
Vector2 overridden_scale = size / Vector2(texture->GetDimensions());
|
||||
|
||||
|
||||
// TODO: Support image rotation in the widget.
|
||||
J2D::DrawSprite(*texture, pos, 0, origin, overridden_scale, image_color);
|
||||
}
|
||||
|
||||
ImageBase::ImageBase()
|
||||
@@ -39,5 +57,7 @@ namespace JUI
|
||||
Vector2 ImageBase::Scale() const { return scale;}
|
||||
|
||||
Vector2 ImageBase::Origin() const { return origin;}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user