summaryrefslogtreecommitdiff
path: root/plugingui
diff options
context:
space:
mode:
authorAndré Nusser <andre.nusser@googlemail.com>2018-06-10 15:13:53 +0200
committerBent Bisballe Nyeng <deva@aasimon.org>2018-08-12 11:13:52 +0200
commit3f259e92bf1a25a8db521a587b6d612e356b22bc (patch)
tree4c3d312028bcad0b0586003ed9702d4e6c38d1f8 /plugingui
parentd5c2ccc687a38e607b3532f4eb3eafa95d3b887a (diff)
Add highlight of single instruments on hits.
Diffstat (limited to 'plugingui')
-rw-r--r--plugingui/drumkittab.cc36
-rw-r--r--plugingui/drumkittab.h3
-rw-r--r--plugingui/painter.cc14
-rw-r--r--plugingui/painter.h4
4 files changed, 49 insertions, 8 deletions
diff --git a/plugingui/drumkittab.cc b/plugingui/drumkittab.cc
index c371dc9..f132aed 100644
--- a/plugingui/drumkittab.cc
+++ b/plugingui/drumkittab.cc
@@ -96,10 +96,25 @@ void DrumkitTab::buttonEvent(ButtonEvent* buttonEvent)
}
}
- if (buttonEvent->button == MouseButton::left &&
- buttonEvent->direction == GUI::Direction::down)
+ if (buttonEvent->button == MouseButton::left)
{
- triggerAudition(buttonEvent->x, buttonEvent->y);
+ if (buttonEvent->direction == GUI::Direction::down)
+ {
+ triggerAudition(buttonEvent->x, buttonEvent->y);
+ }
+ if (buttonEvent->direction == GUI::Direction::up)
+ {
+ if (shows_instrument_overlay) {
+ Painter painter(*this);
+ painter.clear();
+ painter.drawImage(drumkit_image_x, drumkit_image_y, *drumkit_image);
+ if (shows_overlay) {
+ painter.drawImage(drumkit_image_x, drumkit_image_y, *map_image);
+ }
+ redraw();
+ }
+ shows_instrument_overlay = false;
+ }
}
}
@@ -110,12 +125,12 @@ void DrumkitTab::scrollEvent(ScrollEvent* scrollEvent)
updateVelocityLabel();
velocity_label.resizeToText();
- triggerAudition(scrollEvent->x, scrollEvent->y);
+ triggerAudition(scrollEvent->x, scrollEvent->y, false);
}
void DrumkitTab::mouseLeaveEvent()
{
- if (map_image && shows_overlay) {
+ if (map_image && (shows_overlay || shows_instrument_overlay)) {
Painter painter(*this);
painter.clear();
painter.drawImage(drumkit_image_x, drumkit_image_y, *drumkit_image);
@@ -125,7 +140,7 @@ void DrumkitTab::mouseLeaveEvent()
}
}
-void DrumkitTab::triggerAudition(int x, int y)
+void DrumkitTab::triggerAudition(int x, int y, bool show_hit)
{
auto map_colour = map_image->getPixel(x - drumkit_image_x, y - drumkit_image_y);
if (map_colour.alpha() == 0.0) { return; }
@@ -140,8 +155,17 @@ void DrumkitTab::triggerAudition(int x, int y)
settings.audition_instrument = it->second;
settings.audition_velocity = current_velocity;
+ if (show_hit)
+ {
+ Painter painter(*this);
+ painter.drawRestrictedImage(drumkit_image_x, drumkit_image_y, map_colour, *map_image);
+ shows_instrument_overlay = true;
+ }
+
current_instrument = it->second;
updateInstrumentLabel();
+
+ redraw();
}
void DrumkitTab::updateVelocityLabel()
diff --git a/plugingui/drumkittab.h b/plugingui/drumkittab.h
index cd1d731..64806fd 100644
--- a/plugingui/drumkittab.h
+++ b/plugingui/drumkittab.h
@@ -65,6 +65,7 @@ private:
std::unordered_map<Colour, std::string, ColourHasher> colour_to_instrument;
bool shows_overlay{false};
+ bool shows_instrument_overlay{false};
std::unique_ptr<Image> drumkit_image;
std::unique_ptr<Image> map_image;
@@ -78,7 +79,7 @@ private:
// SettingsNotifier& settings_notifier;
// Config& config;
- void triggerAudition(int x, int y);
+ void triggerAudition(int x, int y, bool show_hit = true);
void updateVelocityLabel();
void updateInstrumentLabel();
};
diff --git a/plugingui/painter.cc b/plugingui/painter.cc
index 16e305f..acc92cb 100644
--- a/plugingui/painter.cc
+++ b/plugingui/painter.cc
@@ -401,11 +401,23 @@ void Painter::drawImage(int x0, int y0, const Drawable& image)
assert(y0 + y >= 0);
assert(x0 + x < pixbuf.width);
assert(y0 + y < pixbuf.height);
- pixbuf.addPixel(x0 + x, y0 + y, c);
+
+ if (!has_restriction || c == restriction_colour)
+ {
+ pixbuf.addPixel(x0 + x, y0 + y, c);
+ }
}
}
}
+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 df26b3e..fc4ce2b 100644
--- a/plugingui/painter.h
+++ b/plugingui/painter.h
@@ -56,6 +56,7 @@ 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 drawImageStretched(int x, int y, const Drawable& image,
int width, int height);
@@ -82,6 +83,9 @@ public:
void clear();
private:
+ bool has_restriction{false};
+ Colour restriction_colour;
+
PixelBufferAlpha& pixbuf;
Colour colour;
};