#include "mimage.h"

#include "texture/texture.h"

void mimage::on_paint(mirage_paint_context& in_context) {
	if (!image_) {
		return;
	}

	in_context.drawer().make_image(
		{ 0, 0 },
		in_context.geo().get_local_size(),
		in_context.geo(),
		image_->get_image(),
		sampler_type::default_,
		{ color_ }
	);
}

void mimage::set_image(const std::shared_ptr<texture>& in_image) {
	image_ = in_image;
}

void mimage::set_sampler(sampler_type in_type) {
	sampler_ = texture_sampler_builder::get_sampler(in_type);
}

Eigen::Vector2f mimage::compute_desired_size(float in_layout_scale_multiplier) const {
	if (image_) {
		return image_->get_size().cast<float>();
	}
	return { 20, 20 };
}
