#include "stdafx.h"
#include "Texture.h"

namespace gui {

	Texture::Texture() {
		// Create an 1x1 image to make it possible to create the texture.
		imageRef = new (this) Image(1, 1);
	}

	Texture::Texture(Image *image) : imageRef(image) {}

	Image *Texture::image() {
		return imageRef;
	}

	void Texture::image(Image *newImage) {
		this->imageRef = newImage;
		markDirty(0);
	}

	Color Texture::sample(Point coords) {
		if (imageRef->width() == 0 || imageRef->height() == 0)
			return Color();

		return imageRef->get(Point(coords.x * Float(imageRef->width()),
								coords.y * Float(imageRef->height())));
	}

}
