summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBent Bisballe Nyeng <deva@aasimon.org>2020-04-09 16:43:46 +0200
committerBent Bisballe Nyeng <deva@aasimon.org>2020-04-09 16:59:59 +0200
commitccf6e828c570151b447449a10d759a4031a3c076 (patch)
treea5e98c4abe01e92cf45d54dfbb0bf8443b2bfe94
parent7386cfe7b6ed831c83137debffb6c54a50dd4992 (diff)
WIP: Highlioghts and clicks re-enabled.scale_kit_image
-rw-r--r--plugingui/drumkitimage.cc84
-rw-r--r--plugingui/drumkitimage.h14
-rw-r--r--plugingui/drumkittab.h4
-rw-r--r--plugingui/painter.cc7
4 files changed, 82 insertions, 27 deletions
diff --git a/plugingui/drumkitimage.cc b/plugingui/drumkitimage.cc
index 95f4054..e9ed020 100644
--- a/plugingui/drumkitimage.cc
+++ b/plugingui/drumkitimage.cc
@@ -35,31 +35,43 @@ namespace GUI
DrumKitImage::DrumKitImage(Widget* parent)
: Widget(parent)
{
+ click_overlay.setVisible(false);
}
void DrumKitImage::setImages(const std::string& imagefile,
const std::string& overlayfile)
{
- overlay.setOverlay(overlayfile);
image = std::make_unique<Image>(imagefile);
+ overlay = std::make_unique<Image>(overlayfile);
+
+ hover_overlay.setOverlay(*overlay);
+ click_overlay.setOverlay(*overlay);
+
+ scale = (float)width() / image->width();
+
redraw();
}
void DrumKitImage::clearImages()
{
- overlay.clearOverlay();
+ hover_overlay.clearOverlay();
+ click_overlay.clearOverlay();
image.reset();
+ overlay.reset();
redraw();
}
void DrumKitImage::resize(std::size_t width, std::size_t height)
{
Widget::resize(width, height);
- overlay.resize(width, height);
+ hover_overlay.resize(width, height);
+ click_overlay.resize(width, height);
+ scale = (float)width / image->width();
}
void DrumKitImage::buttonEvent(ButtonEvent* buttonEvent)
{
+ click_overlay.setVisible(buttonEvent->direction == Direction::down);
}
void DrumKitImage::scrollEvent(ScrollEvent* scrollEvent)
@@ -68,8 +80,16 @@ void DrumKitImage::scrollEvent(ScrollEvent* scrollEvent)
void DrumKitImage::mouseMoveEvent(MouseMoveEvent* mouseMoveEvent)
{
+ if(overlay)
+ {
+ auto scale = (float)width() / image->width();
+ auto colour = overlay->getPixel(mouseMoveEvent->x / scale,
+ mouseMoveEvent->y / scale);
+ hover_overlay.setColour(colour);
+ click_overlay.setColour(colour);
+ }
+
Widget::mouseMoveEvent(mouseMoveEvent);
- //redraw();
}
void DrumKitImage::mouseLeaveEvent()
@@ -81,13 +101,11 @@ void DrumKitImage::repaintEvent(RepaintEvent* repaintEvent)
Painter painter(*this);
painter.clear();
- auto drumkit_scale = (float)width() / image->width();
-
if(image)
{
painter.drawImageStretched(0, 0, *image,
- image->width() * drumkit_scale,
- image->height() * drumkit_scale,
+ image->width() * scale,
+ image->height() * scale,
Filter::Linear);
}
}
@@ -97,45 +115,69 @@ DrumKitImage::Overlay::Overlay(Widget* parent)
{
}
-void DrumKitImage::Overlay::setOverlay(const std::string& overlayfile)
+void DrumKitImage::Overlay::setOverlay(const Image& overlay)
{
- overlay = std::make_unique<Image>(overlayfile);
+ this->overlay = &overlay;
+ scale = (float)width() / overlay.width();
+ needs_repaint = true;
redraw();
}
void DrumKitImage::Overlay::clearOverlay()
{
- overlay.reset();
+ overlay = nullptr;
redraw();
}
-static auto has_highlight_colour = false;
+void DrumKitImage::Overlay::setColour(const Colour& colour)
+{
+ if(highlight_colour != colour)
+ {
+ highlight_colour = colour;
+ highlight_colour.data()[3] = 64;
+ needs_repaint = true;
+ redraw();
+ }
+}
void DrumKitImage::Overlay::buttonEvent(ButtonEvent* buttonEvent)
{
- has_highlight_colour = !has_highlight_colour;
- redraw();
+ // Propagate event to parent
+ parent->buttonEvent(buttonEvent);
}
void DrumKitImage::Overlay::mouseMoveEvent(MouseMoveEvent* mouseMoveEvent)
{
+ // Propagate event to parent
+ parent->mouseMoveEvent(mouseMoveEvent);
+}
+
+void DrumKitImage::Overlay::resize(std::size_t width, std::size_t height)
+{
+ Widget::resize(width, height);
+ scale = (float)width / overlay->width();
+ needs_repaint = true;
}
void DrumKitImage::Overlay::repaintEvent(RepaintEvent* repaintEvent)
{
+ if(!needs_repaint)
+ {
+ return;
+ }
+
Painter painter(*this);
painter.clear();
- auto drumkit_scale = (float)width() / overlay->width();
- auto colour = Colour(0.0f, 0, 0, .8f);
-
- if(overlay && has_highlight_colour)
+ if(overlay)
{
- painter.drawRestrictedImageStretched(0, 0, colour, *overlay,
- overlay->width() * drumkit_scale,
- overlay->height() * drumkit_scale,
+ painter.drawRestrictedImageStretched(0, 0, highlight_colour, *overlay,
+ overlay->width() * scale,
+ overlay->height() * scale,
Filter::Nearest);
}
+
+ needs_repaint = false;
}
} // GUI::
diff --git a/plugingui/drumkitimage.h b/plugingui/drumkitimage.h
index 2a9f27a..c92a1f6 100644
--- a/plugingui/drumkitimage.h
+++ b/plugingui/drumkitimage.h
@@ -59,20 +59,28 @@ private:
public:
Overlay(Widget* parent);
- void setOverlay(const std::string& overlayfile);
+ void setOverlay(const Image& image);
void clearOverlay();
+ void setColour(const Colour& colour);
// From Widget:
void buttonEvent(ButtonEvent* buttonEvent) override;
void mouseMoveEvent(MouseMoveEvent* mouseMoveEvent) override;
+ void resize(std::size_t width, std::size_t height) override;
void repaintEvent(RepaintEvent* repaintEvent) override;
private:
- std::unique_ptr<Image> overlay;
+ const Image* overlay{nullptr};
+ bool needs_repaint{true};
+ Colour highlight_colour;
+ float scale{1.0f};
};
- Overlay overlay{this};
+ Overlay hover_overlay{this};
+ Overlay click_overlay{this};
std::unique_ptr<Image> image;
+ std::unique_ptr<Image> overlay;
+ float scale{1.0f};
};
} // GUI::
diff --git a/plugingui/drumkittab.h b/plugingui/drumkittab.h
index 50fc421..8fd5087 100644
--- a/plugingui/drumkittab.h
+++ b/plugingui/drumkittab.h
@@ -91,8 +91,8 @@ private:
{Colour(248./255, 221./255, 37./255), "Tom4"}
};
- bool shows_overlay{false};
- bool shows_instrument_overlay{false};
+ //bool shows_overlay{false};
+ //bool shows_instrument_overlay{false};
std::unique_ptr<Image> drumkit_image;
std::unique_ptr<Image> map_image;
diff --git a/plugingui/painter.cc b/plugingui/painter.cc
index cc7c66e..7f7b6c8 100644
--- a/plugingui/painter.cc
+++ b/plugingui/painter.cc
@@ -496,7 +496,12 @@ void Painter::drawRestrictedImageStretched(int x0, int y0,
auto& c = image.getPixel(lx, ly);
if(c == restriction_colour && c.alpha() > 0)
{
- pixbuf.addPixel(x0 + x, y0 + y, restriction_colour);
+ Colour col(restriction_colour);
+ int alpha = col.data()[3];
+ alpha *= c.alpha();
+ col.data()[3] = alpha / 255;
+ pixbuf.addPixel(x0 + x, y0 + y, col);
+ //pixbuf.addPixel(x0 + x, y0 + y, restriction_colour);
}
}
}