From 54838a283cd4fdfd5a1a44c5ef6ca0051872f107 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Nusser?= Date: Fri, 19 May 2017 19:08:32 +0200 Subject: Add inline drumgizmo logo. The details (which are marked with TODO) have to be changed when we actually get a logo from the drumkits. --- plugin/drumgizmo_plugin.cc | 100 +++++++++++++++++++++++++++++++-------------- plugin/drumgizmo_plugin.h | 4 ++ 2 files changed, 73 insertions(+), 31 deletions(-) (limited to 'plugin') diff --git a/plugin/drumgizmo_plugin.cc b/plugin/drumgizmo_plugin.cc index 168eb58..2b7f4b9 100644 --- a/plugin/drumgizmo_plugin.cc +++ b/plugin/drumgizmo_plugin.cc @@ -200,48 +200,86 @@ void DrumGizmoPlugin::onInlineRedraw(std::size_t width, std::size_t max_height, InlineDrawContext& context) { - std::size_t height = std::min(std::size_t(11), max_height); - if(!context.data || - (context.width != width) || - (context.height != height) || - settingsGetter.number_of_files.hasChanged() || - settingsGetter.number_of_files_loaded.hasChanged() || - settingsGetter.drumkit_load_status.hasChanged()) + std::size_t bar_height = bar_red.height(); + std::size_t image_height = ((double)width / inline_display_image.width()) * inline_display_image.height(); + + bool show_bar{false}; + bool show_image{false}; + std::size_t height = 0; + + if(bar_height <= max_height) { + show_bar = true; + height += bar_height; + } + if(bar_height + image_height <= max_height) { + show_image = true; + height += image_height; + } + + bool context_needs_update = + !context.data || + context.width != width || + context.height != height; + bool bar_needs_update = + settingsGetter.number_of_files.hasChanged() || + settingsGetter.number_of_files_loaded.hasChanged() || + settingsGetter.drumkit_load_status.hasChanged() || + context_needs_update; + bool image_needs_update = inline_image_first_draw || context_needs_update; + // TODO: settingsGetter.inline_image_filename.hasChanged(); + bool something_needs_update = + context_needs_update || + bar_needs_update || + image_needs_update; + + if (something_needs_update) { context.width = width; context.height = height; assert(context.width * context.height <= sizeof(inlineDisplayBuffer)); context.data = (unsigned char*)inlineDisplayBuffer; - box.setSize(context.width, context.height); - InlineCanvas canvas(context); GUI::Painter painter(canvas); - painter.clear(); - painter.drawImage(0, 0, box); - - double progress = - (double)settingsGetter.number_of_files_loaded.getValue() / - (double)settingsGetter.number_of_files.getValue(); - int brd = 4; - int val = (width - (2 * brd)) * progress; + if(show_bar && bar_needs_update) + { + box.setSize(context.width, bar_height); + painter.drawImage(0, height - bar_height, box); + + double progress = + (double)settingsGetter.number_of_files_loaded.getValue() / + (double)settingsGetter.number_of_files.getValue(); + + int brd = 4; + int val = (width - (2 * brd)) * progress; + + switch(settingsGetter.drumkit_load_status.getValue()) + { + case LoadStatus::Error: + bar_red.setSize(val, bar_height); + painter.drawImage(brd, height - bar_height, bar_red); + break; + case LoadStatus::Done: + bar_green.setSize(val, bar_height); + painter.drawImage(brd, height - bar_height, bar_green); + break; + case LoadStatus::Loading: + case LoadStatus::Idle: + bar_blue.setSize(val, bar_height); + painter.drawImage(brd, height - bar_height, bar_blue); + break; + } + } - switch(settingsGetter.drumkit_load_status.getValue()) + if(show_image && image_needs_update) { - case LoadStatus::Error: - bar_red.setSize(val, height); - painter.drawImage(brd, 0, bar_red); - break; - case LoadStatus::Done: - bar_green.setSize(val, height); - painter.drawImage(brd, 0, bar_green); - break; - case LoadStatus::Loading: - case LoadStatus::Idle: - bar_blue.setSize(val, height); - painter.drawImage(brd, 0, bar_blue); - break; + // TODO: load new image and remove the bool + inline_image_first_draw = false; + + painter.setColour(.5); + painter.drawFilledRectangle(0, 0, width, image_height); + painter.drawImageStretched(0, 0, inline_display_image, width, image_height); } // Convert to correct pixel format diff --git a/plugin/drumgizmo_plugin.h b/plugin/drumgizmo_plugin.h index 98c6c26..36bf016 100644 --- a/plugin/drumgizmo_plugin.h +++ b/plugin/drumgizmo_plugin.h @@ -43,6 +43,7 @@ #include #include +#include class DrumGizmoPlugin #ifdef LV2 @@ -201,7 +202,10 @@ private: std::shared_ptr plugin_gui; std::shared_ptr drumgizmo; + std::uint32_t inlineDisplayBuffer[1024*1024]; + GUI::Image inline_display_image{":resources/logo.png"}; + bool inline_image_first_draw{true}; static constexpr std::size_t width{750}; static constexpr std::size_t height{400}; -- cgit v1.2.3