From a8eea6e9c1f32d5562594656c68dc4b9f985b790 Mon Sep 17 00:00:00 2001 From: Bent Bisballe Nyeng Date: Sat, 14 Nov 2020 09:46:34 +0100 Subject: Add x_offset to drawable::line to be able to have drawImage render images outside the parent area. --- plugingui/drawable.h | 3 ++- plugingui/image.cc | 4 ++-- plugingui/image.h | 5 +++-- plugingui/painter.cc | 12 ++++++------ plugingui/texture.cc | 4 ++-- plugingui/texture.h | 3 ++- plugingui/texturedbox.cc | 2 +- plugingui/texturedbox.h | 3 ++- 8 files changed, 20 insertions(+), 16 deletions(-) (limited to 'plugingui') diff --git a/plugingui/drawable.h b/plugingui/drawable.h index e793a27..95492d6 100644 --- a/plugingui/drawable.h +++ b/plugingui/drawable.h @@ -43,7 +43,8 @@ public: virtual std::size_t height() const = 0; virtual const Colour& getPixel(std::size_t x, std::size_t y) const = 0; - virtual const std::uint8_t* line(std::size_t y) const = 0; + virtual const std::uint8_t* line(std::size_t y, + std::size_t x_offset = 0) const = 0; virtual bool hasAlpha() const = 0; }; diff --git a/plugingui/image.cc b/plugingui/image.cc index 1b858ad..118203e 100644 --- a/plugingui/image.cc +++ b/plugingui/image.cc @@ -198,9 +198,9 @@ const Colour& Image::getPixel(size_t x, size_t y) const return image_data[x + y * _width]; } -const std::uint8_t* Image::line(std::size_t y) const +const std::uint8_t* Image::line(std::size_t y, std::size_t x_offset) const { - return image_data_raw.data() + y * _width * 4; + return image_data_raw.data() + y * _width * 4 + x_offset * 4; } bool Image::hasAlpha() const diff --git a/plugingui/image.h b/plugingui/image.h index 4d140ab..d162a75 100644 --- a/plugingui/image.h +++ b/plugingui/image.h @@ -50,13 +50,14 @@ public: size_t height() const override; const Colour& getPixel(size_t x, size_t y) const override; - const std::uint8_t* line(std::size_t y) const override; + const std::uint8_t* line(std::size_t y, + std::size_t x_offset = 0) const override; bool hasAlpha() const override; bool isValid() const; -private: +protected: void setError(); bool valid{false}; diff --git a/plugingui/painter.cc b/plugingui/painter.cc index f2fc66a..f746f83 100644 --- a/plugingui/painter.cc +++ b/plugingui/painter.cc @@ -437,21 +437,21 @@ void Painter::drawImage(int x0, int y0, const Drawable& image) } else { - std::size_t x = -1 * std::min(0, x0); + std::size_t x_offset = -1 * std::min(0, x0); for(std::size_t y = -1 * std::min(0, y0); y < (std::size_t)fh; ++y) { - pixbuf.blendLine(x + x0, y + y0, image.line(y), - std::min((int)image.width(), fw - (int)x)); + pixbuf.blendLine(x_offset + x0, y + y0, image.line(y, x_offset), + std::min((int)image.width(), fw - (int)x_offset)); } } } else { - std::size_t x = -1 * std::min(0, x0); + std::size_t x_offset = -1 * std::min(0, x0); for(std::size_t y = -1 * std::min(0, y0); y < (std::size_t)fh; ++y) { - pixbuf.writeLine(x + x0, y + y0, image.line(y), - std::min((int)image.width(), fw - (int)x)); + pixbuf.writeLine(x_offset + x0, y + y0, image.line(y, x_offset), + std::min((int)image.width(), fw - (int)x_offset)); } } } diff --git a/plugingui/texture.cc b/plugingui/texture.cc index a5908cb..8cd7040 100644 --- a/plugingui/texture.cc +++ b/plugingui/texture.cc @@ -59,9 +59,9 @@ const Colour& Texture::getPixel(size_t x, size_t y) const return image.getPixel(x + _x, y + _y); } -const std::uint8_t* Texture::line(std::size_t y) const +const std::uint8_t* Texture::line(std::size_t y, std::size_t x_offset) const { - return image.line(y + _y) + _x * 4; + return image.line(y + _y) + _x * 4 + x_offset * 4; } bool Texture::hasAlpha() const diff --git a/plugingui/texture.h b/plugingui/texture.h index e5b0472..c751ed4 100644 --- a/plugingui/texture.h +++ b/plugingui/texture.h @@ -49,7 +49,8 @@ public: size_t height() const override; const Colour& getPixel(size_t x, size_t y) const override; - const std::uint8_t* line(std::size_t y) const override; + const std::uint8_t* line(std::size_t y, + std::size_t x_offset = 0) const override; bool hasAlpha() const override; private: diff --git a/plugingui/texturedbox.cc b/plugingui/texturedbox.cc index 21bf946..e48353a 100644 --- a/plugingui/texturedbox.cc +++ b/plugingui/texturedbox.cc @@ -133,7 +133,7 @@ const Colour& TexturedBox::getPixel(std::size_t x, std::size_t y) const return outOfRange; } -const std::uint8_t* TexturedBox::line(std::size_t y) const +const std::uint8_t* TexturedBox::line(std::size_t y, std::size_t x_offset) const { // TODO: Gather line into temporary buffer? return nullptr; diff --git a/plugingui/texturedbox.h b/plugingui/texturedbox.h index 0ff0490..7aa3967 100644 --- a/plugingui/texturedbox.h +++ b/plugingui/texturedbox.h @@ -89,7 +89,8 @@ public: void setSize(std::size_t width, std::size_t height); const Colour& getPixel(std::size_t x, std::size_t y) const override; - const std::uint8_t* line(std::size_t y) const override; + const std::uint8_t* line(std::size_t y, + std::size_t x_offset = 0) const override; bool hasAlpha() const override; private: -- cgit v1.2.3