diff --git a/vstgui/lib/crowcolumnview.cpp b/vstgui/lib/crowcolumnview.cpp index a795892f6..e74ec6233 100644 --- a/vstgui/lib/crowcolumnview.cpp +++ b/vstgui/lib/crowcolumnview.cpp @@ -1,4 +1,4 @@ -// This file is part of VSTGUI. It is subject to the license terms +// This file is part of VSTGUI. It is subject to the license terms // in the LICENSE file found in the top-level directory of this // distribution and at http://github.com/steinbergmedia/vstgui/LICENSE @@ -135,38 +135,38 @@ CPoint computeRectOffset (const CPoint& parent, const CPoint& rect, const Alignm CRect computeGroupRect (const CRect& parent, const CRects& children, const Alignment alignment, const Style style, double spacing) { - CPoint maxSize; - if (style == Style::kRow) - { - for (const auto& rect : children) - { - if (maxSize.x < rect.getWidth ()) - maxSize.x = rect.getWidth (); - - maxSize.y = maxSize.y + rect.getHeight () + spacing; - } - - // Remove the last spacing again - if (!children.empty()) - maxSize.y -= spacing; - } - else - { - for (const auto& rect : children) - { - if (maxSize.y < rect.getHeight ()) - maxSize.y = rect.getHeight (); - - maxSize.x = maxSize.x + rect.getWidth () + spacing; - } - - // Remove the last spacing again - if (!children.empty()) - maxSize.x -= spacing; - } - - const auto offset = computeRectOffset (parent.getSize (), maxSize, alignment); - return CRect().setSize(maxSize).offset(offset); + CPoint maxSize; + if (style == Style::kRow) + { + for (const auto& rect : children) + { + if (maxSize.x < rect.getWidth ()) + maxSize.x = rect.getWidth (); + + maxSize.y = maxSize.y + rect.getHeight () + spacing; + } + + // Remove the last spacing again + if (!children.empty ()) + maxSize.y -= spacing; + } + else + { + for (const auto& rect : children) + { + if (maxSize.y < rect.getHeight ()) + maxSize.y = rect.getHeight (); + + maxSize.x = maxSize.x + rect.getWidth () + spacing; + } + + // Remove the last spacing again + if (!children.empty ()) + maxSize.x -= spacing; + } + + const auto offset = computeRectOffset (parent.getSize (), maxSize, alignment); + return CRect ().setSize (maxSize).offset (offset); } //-------------------------------------------------------------------------------- @@ -230,7 +230,8 @@ class AutoLayout } //-------------------------------------------------------------------------------- -CRowColumnView::CRowColumnView (const CRect& size, Style style, LayoutStyle layoutStyle, CCoord spacing, const CRect& margin) +CRowColumnView::CRowColumnView (const CRect& size, Style style, LayoutStyle layoutStyle, + CCoord spacing, const CRect& margin) : CAutoLayoutContainerView (size) , style (style) , layoutStyle (layoutStyle) @@ -287,10 +288,7 @@ void CRowColumnView::setLayoutStyle (LayoutStyle inLayoutStyle) } //-------------------------------------------------------------------------------- -bool CRowColumnView::isAnimateViewResizing () const -{ - return hasBit (flags, kAnimateViewResizing); -} +bool CRowColumnView::isAnimateViewResizing () const { return hasBit (flags, kAnimateViewResizing); } //-------------------------------------------------------------------------------- void CRowColumnView::setAnimateViewResizing (bool state) @@ -299,10 +297,7 @@ void CRowColumnView::setAnimateViewResizing (bool state) } //-------------------------------------------------------------------------------- -bool CRowColumnView::hideClippedSubviews () const -{ - return hasBit (flags, kHideClippedSubViews); -} +bool CRowColumnView::hideClippedSubviews () const { return hasBit (flags, kHideClippedSubViews); } //-------------------------------------------------------------------------------- void CRowColumnView::setHideClippedSubviews (bool state) @@ -317,7 +312,9 @@ void CRowColumnView::resizeSubView (CView* view, const CRect& newSize) { if (isAttached () && isAnimateViewResizing () && viewResizeAnimationTime > 0) { - view->addAnimation ("CRowColumnResizing", new Animation::ViewSizeAnimation (newSize, false), new Animation::LinearTimingFunction (viewResizeAnimationTime)); + view->addAnimation ("CRowColumnResizing", + new Animation::ViewSizeAnimation (newSize, false), + new Animation::LinearTimingFunction (viewResizeAnimationTime)); } else { @@ -459,8 +456,11 @@ bool CRowColumnView::sizeToFit () if (viewSize != getViewSize ()) { invalid (); + auto autosizeState = getAutosizingEnabled (); + setAutosizingEnabled (false); CViewContainer::setViewSize (viewSize); CViewContainer::setMouseableArea (viewSize); + setAutosizingEnabled (autosizeState); invalid (); } return true; @@ -482,10 +482,7 @@ CMessageResult CRowColumnView::notify (CBaseObject* sender, IdStringPtr message) //-------------------------------------------------------------------------------- //-------------------------------------------------------------------------------- //-------------------------------------------------------------------------------- -CAutoLayoutContainerView::CAutoLayoutContainerView (const CRect& size) -: CViewContainer (size) -{ -} +CAutoLayoutContainerView::CAutoLayoutContainerView (const CRect& size) : CViewContainer (size) {} //-------------------------------------------------------------------------------- bool CAutoLayoutContainerView::attached (CView* parent) @@ -543,4 +540,3 @@ bool CAutoLayoutContainerView::changeViewZOrder (CView* view, uint32_t newIndex) } } // VSTGUI - diff --git a/vstgui/lib/platform/win32/direct2d/d2dfont.cpp b/vstgui/lib/platform/win32/direct2d/d2dfont.cpp index 6454512ba..02eeca7cc 100644 --- a/vstgui/lib/platform/win32/direct2d/d2dfont.cpp +++ b/vstgui/lib/platform/win32/direct2d/d2dfont.cpp @@ -49,16 +49,13 @@ struct CustomFonts return false; } - CustomFonts () + CustomFonts (const UTF8String& resourceBasePath) { - auto winFactory = getPlatformFactory ().asWin32Factory (); - if (!winFactory) + if (resourceBasePath.empty ()) return; - auto basePath = winFactory->getResourceBasePath (); - if (!basePath) - return; - *basePath += "Fonts\\*"; - auto files = getDirectoryContents (*basePath); + auto basePath = resourceBasePath; + basePath += "Fonts\\*"; + auto files = getDirectoryContents (basePath); if (files.empty ()) return; auto factory = getDWriteFactory (); @@ -106,6 +103,7 @@ struct CustomFonts return result; } #else + CustomFonts (const UTF8String& resourceBasePath) {} IDWriteFontCollection* getFontCollection () { return nullptr; } bool contains (const WCHAR*, DWRITE_FONT_WEIGHT, DWRITE_FONT_STRETCH, DWRITE_FONT_STYLE) { @@ -116,14 +114,9 @@ struct CustomFonts //----------------------------------------------------------------------------- static std::unique_ptr customFonts; -static std::once_flag customFontsOnceFlag; //----------------------------------------------------------------------------- -static CustomFonts* getCustomFonts () -{ - std::call_once (customFontsOnceFlag, [] () { customFonts = std::make_unique (); }); - return customFonts.get (); -} +static CustomFonts* getCustomFonts () { return customFonts.get (); } //----------------------------------------------------------------------------- static void gatherFonts (const FontFamilyCallback& callback, IDWriteFontCollection* collection) @@ -198,8 +191,14 @@ bool D2DFont::getAllFontFamilies (const FontFamilyCallback& callback) return true; } +//------------------------------------------------------------------------ +void D2DFont::initialize (const UTF8String& resourceBasePath) +{ + D2DFontPrivate::customFonts = std::make_unique (resourceBasePath); +} + //----------------------------------------------------------------------------- -void D2DFont::terminate () { D2DFontPrivate::customFonts = nullptr; } +void D2DFont::terminate () { D2DFontPrivate::customFonts.reset (); } //----------------------------------------------------------------------------- D2DFont::D2DFont (const UTF8String& name, const CCoord& size, const int32_t& style) diff --git a/vstgui/lib/platform/win32/direct2d/d2dfont.h b/vstgui/lib/platform/win32/direct2d/d2dfont.h index 044e7f8fb..55c128d49 100644 --- a/vstgui/lib/platform/win32/direct2d/d2dfont.h +++ b/vstgui/lib/platform/win32/direct2d/d2dfont.h @@ -28,6 +28,7 @@ class D2DFont final : public IPlatformFont, public IFontPainter static bool getAllFontFamilies (const FontFamilyCallback& callback); + static void initialize (const UTF8String& resourceBasePath); static void terminate (); protected: diff --git a/vstgui/lib/platform/win32/win32factory.cpp b/vstgui/lib/platform/win32/win32factory.cpp index 1b17040f1..c32be2e48 100644 --- a/vstgui/lib/platform/win32/win32factory.cpp +++ b/vstgui/lib/platform/win32/win32factory.cpp @@ -141,6 +141,7 @@ HINSTANCE Win32Factory::getInstance () const noexcept void Win32Factory::setResourceBasePath (const UTF8String& path) const noexcept { impl->setBasePath (path); + D2DFont::initialize (path); } //----------------------------------------------------------------------------- diff --git a/vstgui/plugin-bindings/vst3editor.cpp b/vstgui/plugin-bindings/vst3editor.cpp index b515f5dd5..a98e14ab1 100644 --- a/vstgui/plugin-bindings/vst3editor.cpp +++ b/vstgui/plugin-bindings/vst3editor.cpp @@ -1881,6 +1881,7 @@ bool VST3Editor::enableEditing (bool state) openUIEditorController = nullptr; if (state) { + editingEnabled = true; // update uiDesc file path to absolute if possible if (UIAttributes* attributes = description->getCustomAttributes ("VST3Editor", true)) { @@ -1904,7 +1905,6 @@ bool VST3Editor::enableEditing (bool state) CView* view = editController->createEditView (); if (view) { - editingEnabled = true; CCoord width = view->getWidth (); CCoord height = view->getHeight (); @@ -1954,15 +1954,19 @@ bool VST3Editor::enableEditing (bool state) CCoord width = view->getWidth () * scaleFactor; CCoord height = view->getHeight () * scaleFactor; - if (canResize () == Steinberg::kResultTrue) + if (canResize () == Steinberg::kResultTrue && nonEditRect.isEmpty ()) { Steinberg::ViewRect tmp; if (getRect ().getWidth () != width) tmp.right = getRect ().getWidth (); if (getRect ().getHeight () != height) tmp.bottom = getRect ().getHeight (); - if (tmp.getWidth () && tmp.getHeight ()) + if (tmp.getWidth () || tmp.getHeight ()) { + if (tmp.getWidth () == 0) + tmp.right = width; + if (tmp.getHeight () == 0) + tmp.bottom = width; checkSizeConstraint (&tmp); nonEditRect.setWidth (tmp.getWidth ()); nonEditRect.setHeight (tmp.getHeight ()); @@ -1975,9 +1979,10 @@ bool VST3Editor::enableEditing (bool state) getFrame ()->invalid (); if (nonEditRect.isEmpty () == false) { - rect.right = rect.left + (Steinberg::int32)nonEditRect.getWidth (); - rect.bottom = rect.top + (Steinberg::int32)nonEditRect.getHeight (); - plugFrame->resizeView (this, &rect); + Steinberg::ViewRect tmpRect = rect; + tmpRect.right = tmpRect.left + (Steinberg::int32)nonEditRect.getWidth (); + tmpRect.bottom = tmpRect.top + (Steinberg::int32)nonEditRect.getHeight (); + plugFrame->resizeView (this, &tmpRect); } else { diff --git a/vstgui/plugin-bindings/vst3editor.h b/vstgui/plugin-bindings/vst3editor.h index dad962ed8..850144705 100644 --- a/vstgui/plugin-bindings/vst3editor.h +++ b/vstgui/plugin-bindings/vst3editor.h @@ -1,4 +1,4 @@ -// This file is part of VSTGUI. It is subject to the license terms +// This file is part of VSTGUI. It is subject to the license terms // in the LICENSE file found in the top-level directory of this // distribution and at http://github.com/steinbergmedia/vstgui/LICENSE @@ -217,7 +217,7 @@ class VST3Editor : public Steinberg::Vst::VSTGUIEditor, double contentScaleFactor {1.}; double zoomFactor {1.}; std::vector allowedZoomFactors; - + CPoint minSize; CPoint maxSize; CRect nonEditRect;