diff options
author | André Nusser <andre.nusser@googlemail.com> | 2018-06-10 13:53:06 +0200 |
---|---|---|
committer | Bent Bisballe Nyeng <deva@aasimon.org> | 2018-08-12 11:13:52 +0200 |
commit | b64e858af397e51c1f1bad95a1747a54a85ab744 (patch) | |
tree | 9ebfee051a86b16906ab850eb75af0d1bc70b98c /plugingui/drumkittab.cc | |
parent | 3d218d5991a253f8d6a12db73908bead34d3e2da (diff) |
Add instrument label and highlight of drums.
Diffstat (limited to 'plugingui/drumkittab.cc')
-rw-r--r-- | plugingui/drumkittab.cc | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/plugingui/drumkittab.cc b/plugingui/drumkittab.cc index d9123ea..74d4a64 100644 --- a/plugingui/drumkittab.cc +++ b/plugingui/drumkittab.cc @@ -29,6 +29,9 @@ #include <iomanip> #include <sstream> +// FIXME +#include <iostream> + #include "cpp11fix.h" // required for c++11 #include "painter.h" #include "settings.h" @@ -50,6 +53,9 @@ DrumkitTab::DrumkitTab(Widget* parent, velocity_label.move(10, height()-velocity_label.height()-5); updateVelocityLabel(); velocity_label.resizeToText(); + + instrument_name_label.move(velocity_label.width()+30, height()-instrument_name_label.height()-5); + updateInstrumentLabel(); } void DrumkitTab::resize(std::size_t width, std::size_t height) @@ -66,10 +72,33 @@ void DrumkitTab::resize(std::size_t width, std::size_t height) } velocity_label.move(10, height-velocity_label.height()-5); + instrument_name_label.move(velocity_label.width()+30, height-instrument_name_label.height()-5); } void DrumkitTab::buttonEvent(ButtonEvent* buttonEvent) { + if (map_image) { + if (buttonEvent->button == MouseButton::right) { + if (buttonEvent->direction == GUI::Direction::down) { + Painter painter(*this); + painter.drawImage(drumkit_image_x, drumkit_image_y, *map_image); + redraw(); + + shows_overlay = true; + return; + } + if (buttonEvent->direction == GUI::Direction::up) { + Painter painter(*this); + painter.clear(); + painter.drawImage(drumkit_image_x, drumkit_image_y, *drumkit_image); + redraw(); + + shows_overlay = false; + return; + } + } + } + if (buttonEvent->button == MouseButton::left && buttonEvent->direction == GUI::Direction::down) { @@ -87,9 +116,22 @@ void DrumkitTab::scrollEvent(ScrollEvent* scrollEvent) triggerAudition(scrollEvent->x, scrollEvent->y); } +void DrumkitTab::mouseLeaveEvent() +{ + if (map_image && shows_overlay) { + Painter painter(*this); + painter.clear(); + painter.drawImage(drumkit_image_x, drumkit_image_y, *drumkit_image); + redraw(); + + shows_overlay = false; + } +} + void DrumkitTab::triggerAudition(int x, int y) { auto map_colour = map_image->getPixel(x - drumkit_image_x, y - drumkit_image_y); + if (map_colour.alpha() == 0.0) { return; } auto it = colour_to_instrument.find(map_colour); if (it == colour_to_instrument.end()) @@ -100,6 +142,9 @@ void DrumkitTab::triggerAudition(int x, int y) ++settings.audition_counter; settings.audition_instrument = it->second; settings.audition_velocity = current_velocity; + + current_instrument = it->second; + updateInstrumentLabel(); } void DrumkitTab::updateVelocityLabel() @@ -109,6 +154,12 @@ void DrumkitTab::updateVelocityLabel() velocity_label.setText("Velocity: " + stream.str()); } +void DrumkitTab::updateInstrumentLabel() +{ + instrument_name_label.setText("Instrument: " + current_instrument); + instrument_name_label.resizeToText(); +} + void DrumkitTab::loadImageFiles(std::string const& image_file, std::string const& map_file) { drumkit_image = std::make_unique<Image>(image_file); |