Skip to content

Commit

Permalink
Use melatonin stackblur for drawing shadows
Browse files Browse the repository at this point in the history
  • Loading branch information
timothyschoen committed Dec 11, 2023
1 parent 6188add commit b32891c
Show file tree
Hide file tree
Showing 26 changed files with 486 additions and 1,178 deletions.
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,6 @@
[submodule "Libraries/concurrentqueue"]
path = Libraries/concurrentqueue
url = https://github.com/cameron314/concurrentqueue.git
[submodule "Libraries/melatonin_blur"]
path = Libraries/melatonin_blur
url = https://github.com/sudara/melatonin_blur.git
1 change: 1 addition & 0 deletions Libraries/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ cmake_policy(SET CMP0091 NEW)
set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>")

add_subdirectory(JUCE)
juce_add_module(melatonin_blur)

if(${CMAKE_VERSION} VERSION_GREATER_EQUAL "3.21")
set(MESSAGE_QUIET ON)
Expand Down
1 change: 1 addition & 0 deletions Libraries/melatonin_blur
Submodule melatonin_blur added at 2356c3
2 changes: 1 addition & 1 deletion Source/Components/ArrowPopupMenu.h
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ class ArrowPopupMenu : public Component
g.saveState();
g.reduceClipRegion(arrowBounds.toNearestInt());

StackShadow::renderDropShadow(g, arrowOutline, Colour(0, 0, 0).withAlpha(0.3f), 7, { 0, targetArea.getY() <= menuBounds.getY() ? 2 : -2 });
StackShadow::renderDropShadow(g, arrowOutline, Colour(0, 0, 0).withAlpha(0.3f), 8, { 0, targetArea.getY() <= menuBounds.getY() ? 1 : -1 });

g.restoreState();
}
Expand Down
4 changes: 2 additions & 2 deletions Source/Components/CheckedTooltip.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

#include <utility>

#include "Utility/StackShadow.h"
#include "Utility/StackDropShadower.h"
#include "Constants.h"

class CheckedTooltip : public TooltipWindow {
Expand All @@ -18,7 +18,7 @@ class CheckedTooltip : public TooltipWindow {
Component* target, std::function<bool(Component*)> checkTooltip = [](Component*) { return true; }, int timeout = 500)
: TooltipWindow(target, timeout)
, checker(std::move(checkTooltip))
, tooltipShadow(DropShadow(Colour(0, 0, 0).withAlpha(0.2f), 4, { 0, 0 }), Corners::defaultCornerRadius)
, tooltipShadow(DropShadow(Colour(0, 0, 0).withAlpha(0.2f), 5, { 0, 0 }), Corners::defaultCornerRadius)
{
setOpaque(false);
tooltipShadow.setOwner(this);
Expand Down
6 changes: 3 additions & 3 deletions Source/Components/ColourPicker.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ class Eyedropper : public Timer

Path shadowPath;
shadowPath.addEllipse(bounds.reduced(2));
StackShadow::renderDropShadow(g, shadowPath, Colours::black.withAlpha(0.85f), 7, { 0, 2 }, 0);
StackShadow::renderDropShadow(g, shadowPath, Colours::black.withAlpha(0.85f), 8, { 0, 1 }, 0);

g.setColour(colour);
g.fillEllipse(bounds);
Expand Down Expand Up @@ -595,7 +595,7 @@ class ColourPicker : public Component {

Path shadowPath;
shadowPath.addEllipse(bounds);
StackShadow::renderDropShadow(g, shadowPath, Colours::black.withAlpha(0.75f), 5, { 0, 0 }, 0);
StackShadow::renderDropShadow(g, shadowPath, Colours::black.withAlpha(0.75f), 6, { 0, 0 }, 0);

auto hs = owner.getHS();
auto colour = Colour::fromHSV(hs.first, hs.second, 1.0f, 1.0f);
Expand Down Expand Up @@ -700,7 +700,7 @@ class ColourPicker : public Component {

Path shadowPath;
shadowPath.addEllipse(bounds.reduced(2));
StackShadow::renderDropShadow(g, shadowPath, Colours::black.withAlpha(0.75f), 5, { 0, 2 }, 0);
StackShadow::renderDropShadow(g, shadowPath, Colours::black.withAlpha(0.75f), 6, { 0, 1 }, 0);

g.setColour(owner.getCurrentColour());
g.fillEllipse(bounds);
Expand Down
2 changes: 1 addition & 1 deletion Source/Components/PropertiesPanel.h
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ class PropertiesPanel : public Component {
if (parent.drawShadowAndOutline) {
Path p;
p.addRoundedRectangle(propertyBounds.reduced(3.0f), Corners::largeCornerRadius);
StackShadow::renderDropShadow(g, p, Colour(0, 0, 0).withAlpha(0.4f), 6, { 0, 1 });
StackShadow::renderDropShadow(g, p, Colour(0, 0, 0).withAlpha(0.4f), 7, { 0, 1 });
}

g.setColour(findColour(parent.panelColour));
Expand Down
2 changes: 1 addition & 1 deletion Source/Components/SuggestionComponent.h
Original file line number Diff line number Diff line change
Expand Up @@ -443,7 +443,7 @@ class SuggestionComponent : public Component
} else {
Path localPath;
localPath.addRoundedRectangle(b.toFloat().reduced(6.0f), Corners::defaultCornerRadius);
StackShadow::renderDropShadow(g, localPath, Colour(0, 0, 0).withAlpha(0.6f), 12, { 0, 2 });
StackShadow::renderDropShadow(g, localPath, Colour(0, 0, 0).withAlpha(0.6f), 13, { 0, 1 });
}

g.setColour(findColour(PlugDataColour::popupMenuBackgroundColourId));
Expand Down
2 changes: 1 addition & 1 deletion Source/Components/TouchSelectionHelper.h
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ class TouchSelectionHelper : public Component {

Path p;
p.addRoundedRectangle(b.reduced(3.0f), Corners::largeCornerRadius);
StackShadow::renderDropShadow(g, p, Colour(0, 0, 0).withAlpha(0.4f), 8, { 0, 1 });
StackShadow::renderDropShadow(g, p, Colour(0, 0, 0).withAlpha(0.4f), 9, { 0, 1 });

g.setColour(findColour(PlugDataColour::toolbarBackgroundColourId));
g.fillRoundedRectangle(b.toFloat(), Corners::largeCornerRadius);
Expand Down
2 changes: 1 addition & 1 deletion Source/Dialogs/ConnectionMessageDisplay.h
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ class ConnectionMessageDisplay
auto internalBounds = getLocalBounds().reduced(8).toFloat();
messageDisplay.addRoundedRectangle(internalBounds, Corners::defaultCornerRadius);

StackShadow::renderDropShadow(g, messageDisplay, Colour(0, 0, 0).withAlpha(0.3f), 6);
StackShadow::renderDropShadow(g, messageDisplay, Colour(0, 0, 0).withAlpha(0.3f), 7);

g.setColour(findColour(PlugDataColour::outlineColourId));
g.fillRoundedRectangle(internalBounds.expanded(1), Corners::defaultCornerRadius);
Expand Down
2 changes: 1 addition & 1 deletion Source/Dialogs/Deken.h
Original file line number Diff line number Diff line change
Expand Up @@ -759,7 +759,7 @@ class Deken : public Component

Path shadowPath;
shadowPath.addRoundedRectangle(shadowX, shadowY, shadowWidth, shadowHeight, Corners::largeCornerRadius);
StackShadow::renderDropShadow(g, shadowPath, Colour(0, 0, 0).withAlpha(0.4f), 6, { 0, 1 });
StackShadow::renderDropShadow(g, shadowPath, Colour(0, 0, 0).withAlpha(0.4f), 7, { 0, 1 });
}

ListBox listBox;
Expand Down
6 changes: 3 additions & 3 deletions Source/Dialogs/PatchStorage.h
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ class PatchFullDisplay : public Component {
{
Path p;
p.addRoundedRectangle(b.reduced(3.0f), Corners::largeCornerRadius);
StackShadow::renderDropShadow(g, p, Colour(0, 0, 0).withAlpha(0.4f), 6, { 0, 1 });
StackShadow::renderDropShadow(g, p, Colour(0, 0, 0).withAlpha(0.4f), 7, { 0, 1 });

g.setColour(findColour(PlugDataColour::panelForegroundColourId));
g.fillRoundedRectangle(b.toFloat(), Corners::largeCornerRadius);
Expand All @@ -259,7 +259,7 @@ class PatchFullDisplay : public Component {
// Drag image shadow
Path p;
p.addRoundedRectangle(image.getBounds().reduced(1.0f), Corners::largeCornerRadius);
StackShadow::renderDropShadow(g, p, Colour(0, 0, 0).withAlpha(0.4f), 6, { 0, 1 });
StackShadow::renderDropShadow(g, p, Colour(0, 0, 0).withAlpha(0.4f), 7, { 0, 1 });

topArea.removeFromBottom(90); // space for download button
topArea = topArea.reduced(16);
Expand Down Expand Up @@ -379,7 +379,7 @@ class PatchDisplay : public Component {

Path p;
p.addRoundedRectangle(b.reduced(3.0f), Corners::largeCornerRadius);
StackShadow::renderDropShadow(g, p, Colour(0, 0, 0).withAlpha(0.4f), 6, { 0, 1 });
StackShadow::renderDropShadow(g, p, Colour(0, 0, 0).withAlpha(0.4f), 7, { 0, 1 });

if (isMouseOver()) {
g.setColour(findColour(PlugDataColour::panelActiveBackgroundColourId));
Expand Down
6 changes: 3 additions & 3 deletions Source/Dialogs/PathsAndLibrariesPanel.h
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ class SearchPathPanel : public Component

Path p;
p.addRoundedRectangle(resetButtonBounds.reduced(3.0f), Corners::largeCornerRadius);
StackShadow::renderDropShadow(g, p, Colour(0, 0, 0).withAlpha(0.4f), 6, { 0, 1 });
StackShadow::renderDropShadow(g, p, Colour(0, 0, 0).withAlpha(0.4f), 7, { 0, 1 });

g.setColour(findColour(PlugDataColour::panelForegroundColourId));
g.fillRoundedRectangle(resetButtonBounds, Corners::largeCornerRadius);
Expand All @@ -176,7 +176,7 @@ class SearchPathPanel : public Component

p = Path();
p.addRoundedRectangle(propertyBounds.reduced(3.0f), Corners::largeCornerRadius);
StackShadow::renderDropShadow(g, p, Colour(0, 0, 0).withAlpha(0.4f), 6, { 0, 1 });
StackShadow::renderDropShadow(g, p, Colour(0, 0, 0).withAlpha(0.4f), 7, { 0, 1 });

g.setColour(findColour(PlugDataColour::panelForegroundColourId));
g.fillRoundedRectangle(propertyBounds, Corners::largeCornerRadius);
Expand Down Expand Up @@ -514,7 +514,7 @@ class LibraryLoadPanel : public Component

Path p;
p.addRoundedRectangle(propertyBounds.reduced(3.0f), Corners::largeCornerRadius);
StackShadow::renderDropShadow(g, p, Colour(0, 0, 0).withAlpha(0.4f), 6, { 0, 1 });
StackShadow::renderDropShadow(g, p, Colour(0, 0, 0).withAlpha(0.4f), 7, { 0, 1 });

g.setColour(findColour(PlugDataColour::panelForegroundColourId));
g.fillRoundedRectangle(propertyBounds, Corners::largeCornerRadius);
Expand Down
2 changes: 1 addition & 1 deletion Source/Dialogs/TextEditorDialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -2130,7 +2130,7 @@ struct TextEditorDialog : public Component {
auto shadowPath = Path();
shadowPath.addRoundedRectangle(getLocalBounds().reduced(20), Corners::windowCornerRadius);

StackShadow::renderDropShadow(g, shadowPath, Colour(0, 0, 0).withAlpha(0.6f), 12.0f);
StackShadow::renderDropShadow(g, shadowPath, Colour(0, 0, 0).withAlpha(0.6f), 13.0f);

auto b = getLocalBounds().reduced(15);

Expand Down
4 changes: 2 additions & 2 deletions Source/LookAndFeel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,7 @@ void PlugDataLook::drawCallOutBoxBackground(CallOutBox& box, Graphics& g, Path c
cachedImage = { Image::ARGB, box.getWidth(), box.getHeight(), true };
Graphics g2(cachedImage);

StackShadow::renderDropShadow(g2, path, Colour(0, 0, 0).withAlpha(0.3f), 7, { 0, 2 });
StackShadow::renderDropShadow(g2, path, Colour(0, 0, 0).withAlpha(0.3f), 8, { 0, 1 });
}

g.setColour(Colours::black);
Expand Down Expand Up @@ -793,7 +793,7 @@ void PlugDataLook::drawPopupMenuBackgroundWithOptions(Graphics& g, int width, in
if (Desktop::canUseSemiTransparentWindows()) {
Path shadowPath;
shadowPath.addRoundedRectangle(Rectangle<float>(0.0f, 0.0f, width, height).reduced(10.0f), Corners::defaultCornerRadius);
StackShadow::renderDropShadow(g, shadowPath, Colour(0, 0, 0).withAlpha(0.6f), 10, { 0, 1 });
StackShadow::renderDropShadow(g, shadowPath, Colour(0, 0, 0).withAlpha(0.6f), 11, { 0, 1 });

g.setColour(background);

Expand Down
2 changes: 1 addition & 1 deletion Source/Object.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -610,7 +610,7 @@ void Object::resized()

Path objectShadow;
objectShadow.addRoundedRectangle(getLocalBounds().reduced(Object::margin - 2), Corners::objectCornerRadius);
StackShadow::renderDropShadow(g, objectShadow, findColour(PlugDataColour::dataColourId), 5, { 0, 0 }, 0);
StackShadow::renderDropShadow(g, objectShadow, findColour(PlugDataColour::dataColourId), 6, { 0, 0 }, 0);
g.restoreState();
}
}
Expand Down
2 changes: 1 addition & 1 deletion Source/Sidebar/AutomationPanel.h
Original file line number Diff line number Diff line change
Expand Up @@ -482,7 +482,7 @@ class DraggedItemDropShadow : public Component
auto rect = getLocalBounds().reduced(14, 7);
Path shadowPath;
shadowPath.addRoundedRectangle(rect, Corners::defaultCornerRadius);
StackShadow::renderDropShadow(g, shadowPath, Colours::black.withAlpha(0.3f), 6);
StackShadow::renderDropShadow(g, shadowPath, Colours::black.withAlpha(0.3f), 7);
}

private:
Expand Down
2 changes: 1 addition & 1 deletion Source/Sidebar/PaletteItem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ void PaletteItem::paint(Graphics& g)
Path dropShadowPath;
dropShadowPath.addRoundedRectangle(bounds.reduced(4.0f), 5.0f);
auto dropShadowColour = findColour(PlugDataColour::objectSelectedOutlineColourId);
StackShadow::renderDropShadow(g, dropShadowPath, dropShadowColour.withAlpha(0.5f), 6);
StackShadow::renderDropShadow(g, dropShadowPath, dropShadowColour.withAlpha(0.5f), 7);
}
auto outlineColour = isItemDragged ? PlugDataColour::objectSelectedOutlineColourId : PlugDataColour::objectOutlineColourId;

Expand Down
6 changes: 3 additions & 3 deletions Source/Standalone/PlugDataWindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -463,7 +463,7 @@ class PlugDataWindow : public DocumentWindow
setDropShadowEnabled(true);
#elif JUCE_WINDOWS
setDropShadowEnabled(false);
dropShadower = std::make_unique<StackDropShadower>(DropShadow(Colour(0, 0, 0).withAlpha(0.8f), 22, { 0, 3 }));
dropShadower = std::make_unique<StackDropShadower>(DropShadow(Colour(0, 0, 0).withAlpha(0.8f), 23, { 0, 2 }));
dropShadower->setOwner(this);
#endif
} else {
Expand Down Expand Up @@ -583,8 +583,8 @@ class PlugDataWindow : public DocumentWindow
Path localPath;
localPath.addRoundedRectangle(b.toFloat().reduced(22.0f), Corners::windowCornerRadius);

int radius = isActiveWindow() ? 21 : 16;
StackShadow::renderDropShadow(g, localPath, Colour(0, 0, 0).withAlpha(0.6f), radius, { 0, 3 });
int radius = isActiveWindow() ? 22 : 17;
StackShadow::renderDropShadow(g, localPath, Colour(0, 0, 0).withAlpha(0.6f), radius, { 0, 2 });
}
}
#endif
Expand Down
2 changes: 1 addition & 1 deletion Source/Tabbar/TabBarButtonComponent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ ScaledImage TabBarButtonComponent::generateTabBarButtonImage()
g.addTransform(AffineTransform::scale(scale));
Path path;
path.addRoundedRectangle(bounds.reduced(14), 5.0f);
StackShadow::renderDropShadow(g, path, Colour(0, 0, 0).withAlpha(0.3f), 6, { 0, 2 }, scale);
StackShadow::renderDropShadow(g, path, Colour(0, 0, 0).withAlpha(0.3f), 7, { 0, 1 }, scale);
g.setOpacity(1.0f);
drawTabButton(g, textBounds.withPosition(10, 10));

Expand Down
2 changes: 1 addition & 1 deletion Source/Tabbar/Tabbar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ class ButtonBar::GhostTab : public Component {
void paint(Graphics& g) override
{
if (tab) {
StackShadow::renderDropShadow(g, shadowPath, Colour(0, 0, 0).withAlpha(0.3f), 4);
StackShadow::renderDropShadow(g, shadowPath, Colour(0, 0, 0).withAlpha(0.3f), 5);
lnf.drawTabButton(*tab, g, true, true, true);
}
}
Expand Down
2 changes: 1 addition & 1 deletion Source/Utility/Autosave.h
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ class AutosaveHistoryComponent : public Component {

Path shadowPath;
shadowPath.addRoundedRectangle(bounds.reduced(3).toFloat(), Corners::largeCornerRadius);
StackShadow::renderDropShadow(g, shadowPath, Colour(0, 0, 0).withAlpha(0.4f), 6, { 0, 1 });
StackShadow::renderDropShadow(g, shadowPath, Colour(0, 0, 0).withAlpha(0.4f), 7, { 0, 1 });

g.setColour(findColour(PlugDataColour::panelForegroundColourId));
g.fillRoundedRectangle(bounds.toFloat(), Corners::defaultCornerRadius);
Expand Down
1 change: 1 addition & 0 deletions Source/Utility/OSUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
// WARRANTIES, see the file, "LICENSE.txt," in this distribution.
*/


#if !defined(__APPLE__)
# include <raw_keyboard_input/raw_keyboard_input.cpp>
#endif
Expand Down
Loading

0 comments on commit b32891c

Please sign in to comment.