From 1fe164e36f0996fb07f62de0ac38199943818095 Mon Sep 17 00:00:00 2001 From: Bent Bisballe Nyeng Date: Sat, 7 Mar 2020 21:08:29 +0100 Subject: Re-enable drumkit image hover effect. --- plugingui/drumkittab.cc | 2 +- plugingui/painter.cc | 72 ++++++++++++------------------------------------- plugingui/painter.h | 3 ++- 3 files changed, 20 insertions(+), 57 deletions(-) diff --git a/plugingui/drumkittab.cc b/plugingui/drumkittab.cc index c3ee62e..8d85f1e 100644 --- a/plugingui/drumkittab.cc +++ b/plugingui/drumkittab.cc @@ -270,7 +270,7 @@ void DrumkitTab::init(std::string const& image_file, if(it == colours.end()) { // XXX: avoids low alpha values due to feathering of edges - colours.emplace_back(colour.red(), colour.green(), colour.blue(), 0.7); + colours.emplace_back(colour.red(), colour.green(), colour.blue(), 178); colour_index_to_positions.emplace_back(); } diff --git a/plugingui/painter.cc b/plugingui/painter.cc index d3f28ff..bad5318 100644 --- a/plugingui/painter.cc +++ b/plugingui/painter.cc @@ -389,10 +389,7 @@ void Painter::drawImage(int x0, int y0, const Drawable& image) assert(x0 + x < pixbuf.width); assert(y0 + y < pixbuf.height); - if (!has_restriction || c == restriction_colour) - { - pixbuf.addPixel(x0 + x, y0 + y, c); - } + pixbuf.addPixel(x0 + x, y0 + y, c); } } } @@ -417,8 +414,9 @@ void Painter::drawImage(int x0, int y0, const Drawable& image) } } -#if 0 -void Painter::drawImage(int x0, int y0, const Drawable& image) +void Painter::drawRestrictedImage(int x0, int y0, + const Colour& restriction_colour, + const Drawable& image) { int fw = image.width(); int fh = image.height(); @@ -439,64 +437,28 @@ void Painter::drawImage(int x0, int y0, const Drawable& image) return; } - if(image.hasAlpha()) + for(std::size_t y = -1 * std::min(0, y0); y < (std::size_t)fh; ++y) { - for(std::size_t y = -1 * std::min(0, y0); y < (std::size_t)fh; ++y) + for(std::size_t x = -1 * std::min(0, x0); x < (std::size_t)fw; ++x) { - for(std::size_t x = -1 * std::min(0, x0); x < (std::size_t)fw; ++x) - { - assert(x >= 0); - assert(y >= 0); - assert(x < image.width()); - assert(y < image.height()); - auto& c = image.getPixel(x, y); + assert(x >= 0); + assert(y >= 0); + assert(x < image.width()); + assert(y < image.height()); + auto& c = image.getPixel(x, y); - assert(x0 + x >= 0); - assert(y0 + y >= 0); - assert(x0 + x < pixbuf.width); - assert(y0 + y < pixbuf.height); + assert(x0 + x >= 0); + assert(y0 + y >= 0); + assert(x0 + x < pixbuf.width); + assert(y0 + y < pixbuf.height); - if (!has_restriction || c == restriction_colour) - { - pixbuf.addPixel(x0 + x, y0 + y, c); - } - } - } - } - else - { - for(std::size_t y = -1 * std::min(0, y0); y < (std::size_t)fh; ++y) - { - for(std::size_t x = -1 * std::min(0, x0); x < (std::size_t)fw; ++x) + if(c == restriction_colour) { - assert(x >= 0); - assert(y >= 0); - assert(x < image.width()); - assert(y < image.height()); - auto& c = image.getPixel(x, y); - - assert(x0 + x >= 0); - assert(y0 + y >= 0); - assert(x0 + x < pixbuf.width); - assert(y0 + y < pixbuf.height); - - if (!has_restriction || c == restriction_colour) - { - pixbuf.setPixel(x0 + x, y0 + y, c); - } + pixbuf.setPixel(x0 + x, y0 + y, c); } } } } -#endif - -void Painter::drawRestrictedImage(int x0, int y0, Colour const& colour, const Drawable& image) -{ - has_restriction = true; - restriction_colour = colour; - drawImage(x0, y0, image); - has_restriction = false; -} void Painter::drawImageStretched(int x0, int y0, const Drawable& image, int width, int height) diff --git a/plugingui/painter.h b/plugingui/painter.h index 2630b0c..d1a8e56 100644 --- a/plugingui/painter.h +++ b/plugingui/painter.h @@ -56,7 +56,8 @@ public: void drawCircle(int x, int y, double r); void drawFilledCircle(int x, int y, int r); void drawImage(int x, int y, const Drawable& image); - void drawRestrictedImage(int x0, int y0, Colour const& colour, const Drawable& image); + void drawRestrictedImage(int x0, int y0, const Colour& restriction_colour, + const Drawable& image); void drawImageStretched(int x, int y, const Drawable& image, int width, int height); -- cgit v1.2.3