Use the custom background image on main panel only

This commit is contained in:
Jean Pierre Cimalando 2021-04-04 01:54:20 +02:00
parent f7df0b2abb
commit c0b142af8f
2 changed files with 36 additions and 9 deletions

View file

@ -136,6 +136,9 @@ struct Editor::Impl : EditorController::Receiver, IControlListener {
SKnobCCBox* volumeCCKnob_ = nullptr; SKnobCCBox* volumeCCKnob_ = nullptr;
SKnobCCBox* panCCKnob_ = nullptr; SKnobCCBox* panCCKnob_ = nullptr;
SharedPointer<CBitmap> backgroundBitmap_;
SharedPointer<CBitmap> defaultBackgroundBitmap_;
CControl* getSecondaryCCControl(unsigned cc) CControl* getSecondaryCCControl(unsigned cc)
{ {
switch (cc) { switch (cc) {
@ -217,6 +220,7 @@ struct Editor::Impl : EditorController::Receiver, IControlListener {
void performCCEndEdit(unsigned cc); void performCCEndEdit(unsigned cc);
void setActivePanel(unsigned panelId); void setActivePanel(unsigned panelId);
void applyBackgroundForCurrentPanel();
static void formatLabel(CTextLabel* label, const char* fmt, ...); static void formatLabel(CTextLabel* label, const char* fmt, ...);
static void vformatLabel(CTextLabel* label, const char* fmt, va_list ap); static void vformatLabel(CTextLabel* label, const char* fmt, va_list ap);
@ -560,6 +564,10 @@ void Editor::Impl::createFrameContents()
SharedPointer<CBitmap> background = owned(new CBitmap("background.png")); SharedPointer<CBitmap> background = owned(new CBitmap("background.png"));
SharedPointer<CBitmap> knob48 = owned(new CBitmap("knob48.png")); SharedPointer<CBitmap> knob48 = owned(new CBitmap("knob48.png"));
SharedPointer<CBitmap> logoText = owned(new CBitmap("logo_text.png")); SharedPointer<CBitmap> logoText = owned(new CBitmap("logo_text.png"));
defaultBackgroundBitmap_ = background;
backgroundBitmap_ = background;
{ {
const CColor frameBackground = { 0xd3, 0xd7, 0xcf }; const CColor frameBackground = { 0xd3, 0xd7, 0xcf };
@ -1041,6 +1049,8 @@ void Editor::Impl::createFrameContents()
panel->setVisible(currentPanel == activePanel_); panel->setVisible(currentPanel == activePanel_);
} }
applyBackgroundForCurrentPanel();
} }
void Editor::Impl::chooseSfzFile() void Editor::Impl::chooseSfzFile()
@ -1547,10 +1557,21 @@ void Editor::Impl::updateSWLastLabel(unsigned sw, const char* label)
void Editor::Impl::updateBackgroundImage(const char* filepath) void Editor::Impl::updateBackgroundImage(const char* filepath)
{ {
SharedPointer<CBitmap> bitmap = loadAnyFormatImage(filepath); backgroundBitmap_ = loadAnyFormatImage(filepath);
if (!bitmap) if (!backgroundBitmap_)
bitmap = owned(new CBitmap("background.png")); backgroundBitmap_ = defaultBackgroundBitmap_;
applyBackgroundForCurrentPanel();
}
void Editor::Impl::applyBackgroundForCurrentPanel()
{
CBitmap* bitmap;
if (activePanel_ == kPanelGeneral)
bitmap = backgroundBitmap_;
else
bitmap = defaultBackgroundBitmap_;
downscaleToWidthAndHeight(bitmap, imageContainer_->getViewSize().getSize()); downscaleToWidthAndHeight(bitmap, imageContainer_->getViewSize().getSize());
imageContainer_->setBackground(bitmap); imageContainer_->setBackground(bitmap);
@ -1610,6 +1631,7 @@ void Editor::Impl::setActivePanel(unsigned panelId)
if (subPanels_[panelId]) if (subPanels_[panelId])
subPanels_[panelId]->setVisible(true); subPanels_[panelId]->setVisible(true);
activePanel_ = panelId; activePanel_ = panelId;
applyBackgroundForCurrentPanel();
} }
} }

View file

@ -60,23 +60,28 @@ SharedPointer<CBitmap> loadAnyFormatImage(const fs::path& filePath)
return bitmap; return bitmap;
} }
void downscaleToWidthAndHeight(VSTGUI::CBitmap* bitmap, VSTGUI::CPoint frameSize) void downscaleToWidthAndHeight(CBitmap* bitmap, CPoint frameSize)
{ {
if (!bitmap) if (!bitmap)
return; return;
PlatformBitmapPtr platformBitmap = bitmap->getPlatformBitmap();
if (!platformBitmap)
return;
CPoint bitmapSize = platformBitmap->getSize();
CCoord frameW = frameSize.x; CCoord frameW = frameSize.x;
CCoord frameH = frameSize.y; CCoord frameH = frameSize.y;
CCoord bitmapW = bitmap->getWidth(); CCoord bitmapW = bitmapSize.x;
CCoord bitmapH = bitmap->getHeight(); CCoord bitmapH = bitmapSize.y;
CCoord scale = 1.0; CCoord scale = 1.0;
if (bitmapW > frameW || bitmapH > frameH) { if (bitmapW > frameW || bitmapH > frameH) {
CCoord xScale = bitmapW / frameW; CCoord xScale = bitmapW / frameW;
CCoord yScale = bitmapH / frameH; CCoord yScale = bitmapH / frameH;
scale = (xScale > yScale) ? xScale : yScale; scale = (xScale > yScale) ? xScale : yScale;
} }
if (PlatformBitmapPtr platformBitmap = bitmap->getPlatformBitmap()) platformBitmap->setScaleFactor(scale);
platformBitmap->setScaleFactor(scale);
} }