[Escher] Image setter for the ImageView

Change-Id: I18c5083c130ba5602cb8279ecb6c1a51692bacbe
This commit is contained in:
Romain Goyet
2016-10-03 12:02:16 +02:00
parent 7bc830da4f
commit dbab72fced
2 changed files with 14 additions and 3 deletions

View File

@@ -6,7 +6,8 @@
class ImageView : public ChildlessView {
public:
ImageView(const Image * image);
ImageView();
void setImage(const Image * image);
void drawRect(KDContext * ctx, KDRect rect) const override;
private:
const Image * m_image;

View File

@@ -3,14 +3,24 @@ extern "C" {
#include <assert.h>
}
ImageView::ImageView(const Image * image) :
ImageView::ImageView() :
ChildlessView(),
m_image(image)
m_image(nullptr)
{
}
void ImageView::drawRect(KDContext * ctx, KDRect rect) const {
if (m_image == nullptr) {
return;
}
assert(bounds().width() == m_image->width());
assert(bounds().height() == m_image->height());
ctx->fillRectWithPixels(bounds(), m_image->pixels(), nullptr);
}
void ImageView::setImage(const Image * image) {
if (image != m_image) {
m_image = image;
markRectAsDirty(bounds());
}
}