From 3d218d5991a253f8d6a12db73908bead34d3e2da Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Nusser?= Date: Sat, 9 Jun 2018 19:26:20 +0200 Subject: Center drumkit image of drumkit tab. --- plugingui/drumkittab.cc | 7 +++++-- plugingui/drumkittab.h | 3 +++ 2 files changed, 8 insertions(+), 2 deletions(-) (limited to 'plugingui') diff --git a/plugingui/drumkittab.cc b/plugingui/drumkittab.cc index 1dccb52..d9123ea 100644 --- a/plugingui/drumkittab.cc +++ b/plugingui/drumkittab.cc @@ -59,7 +59,10 @@ void DrumkitTab::resize(std::size_t width, std::size_t height) if (drumkit_image) { Painter painter(*this); painter.clear(); - painter.drawImage(0 , 0, *drumkit_image); + + drumkit_image_x = (this->width()-drumkit_image->width())/2; + drumkit_image_y = (this->height()-drumkit_image->height())/2; + painter.drawImage(drumkit_image_x, drumkit_image_y, *drumkit_image); } velocity_label.move(10, height-velocity_label.height()-5); @@ -86,7 +89,7 @@ void DrumkitTab::scrollEvent(ScrollEvent* scrollEvent) void DrumkitTab::triggerAudition(int x, int y) { - auto map_colour = map_image->getPixel(x, y); + auto map_colour = map_image->getPixel(x - drumkit_image_x, y - drumkit_image_y); auto it = colour_to_instrument.find(map_colour); if (it == colour_to_instrument.end()) diff --git a/plugingui/drumkittab.h b/plugingui/drumkittab.h index 5fe234a..89f37be 100644 --- a/plugingui/drumkittab.h +++ b/plugingui/drumkittab.h @@ -64,6 +64,9 @@ private: std::unique_ptr drumkit_image; std::unique_ptr map_image; + int drumkit_image_x; + int drumkit_image_y; + Label velocity_label{this}; Settings& settings; -- cgit v1.2.3