From b64e858af397e51c1f1bad95a1747a54a85ab744 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Nusser?= Date: Sun, 10 Jun 2018 13:53:06 +0200 Subject: Add instrument label and highlight of drums. --- plugingui/colour.cc | 4 +++- plugingui/colour.h | 2 +- plugingui/drumkittab.cc | 51 +++++++++++++++++++++++++++++++++++++++++++++++++ plugingui/drumkittab.h | 8 +++++++- 4 files changed, 62 insertions(+), 3 deletions(-) diff --git a/plugingui/colour.cc b/plugingui/colour.cc index 70aa562..02d03c6 100644 --- a/plugingui/colour.cc +++ b/plugingui/colour.cc @@ -62,7 +62,9 @@ Colour& Colour::operator=(const Colour& other) bool Colour::operator==(const Colour& other) const { - return data == other.data; + return data[0] == other.data[0] && + data[1] == other.data[1] && + data[2] == other.data[2]; } bool Colour::operator!=(const Colour& other) const diff --git a/plugingui/colour.h b/plugingui/colour.h index 232b0b9..0bfe80d 100644 --- a/plugingui/colour.h +++ b/plugingui/colour.h @@ -59,7 +59,7 @@ struct ColourHasher // TODO: replace by something reasonable std::size_t operator()(const Colour& colour) const { - return 7*colour.red() + 11*colour.green() + 13*colour.blue() + 17*colour.alpha(); + return 7*colour.red() + 11*colour.green() + 13*colour.blue()/* + 17*colour.alpha()*/; } }; 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 #include +// FIXME +#include + #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_file); diff --git a/plugingui/drumkittab.h b/plugingui/drumkittab.h index 89f37be..cd1d731 100644 --- a/plugingui/drumkittab.h +++ b/plugingui/drumkittab.h @@ -55,12 +55,16 @@ public: void resize(std::size_t width, std::size_t height) override; void buttonEvent(ButtonEvent* buttonEvent) override; void scrollEvent(ScrollEvent* scrollEvent) override; + void mouseLeaveEvent() override; void loadImageFiles(std::string const& image_file, std::string const& map_file); private: - float current_velocity = .5; + float current_velocity{.5}; + std::string current_instrument{""}; + std::unordered_map colour_to_instrument; + bool shows_overlay{false}; std::unique_ptr drumkit_image; std::unique_ptr map_image; @@ -68,6 +72,7 @@ private: int drumkit_image_y; Label velocity_label{this}; + Label instrument_name_label{this}; Settings& settings; // SettingsNotifier& settings_notifier; @@ -75,6 +80,7 @@ private: void triggerAudition(int x, int y); void updateVelocityLabel(); + void updateInstrumentLabel(); }; } // GUI:: -- cgit v1.2.3