diff --git a/modules/juce_gui_basics/mouse/juce_DragAndDropContainer.cpp b/modules/juce_gui_basics/mouse/juce_DragAndDropContainer.cpp index 2e9c44b2c4..23ef0ba986 100644 --- a/modules/juce_gui_basics/mouse/juce_DragAndDropContainer.cpp +++ b/modules/juce_gui_basics/mouse/juce_DragAndDropContainer.cpp @@ -43,7 +43,7 @@ public: imageOffset (offset), hasCheckedForExternalDrag (false) { - setSize (im.getWidth(), im.getHeight()); + updateSize(); if (mouseDragSource == nullptr) mouseDragSource = sourceComponent; @@ -160,6 +160,13 @@ public: forceMouseCursorUpdate(); } + void updateImage (const Image& newImage) + { + image = newImage; + updateSize(); + repaint(); + } + void timerCallback() override { forceMouseCursorUpdate(); @@ -207,6 +214,11 @@ private: bool hasCheckedForExternalDrag; Time lastTimeOverTarget; + void updateSize() + { + setSize (image.getWidth(), image.getHeight()); + } + void forceMouseCursorUpdate() { Desktop::getInstance().getMainMouseSource().forceMouseCursorUpdate(); @@ -472,6 +484,12 @@ var DragAndDropContainer::getCurrentDragDescription() const : var(); } +void DragAndDropContainer::setCurrentDragImage (const Image& newImage) +{ + if (dragImageComponent != nullptr) + dragImageComponent->updateImage (newImage); +} + DragAndDropContainer* DragAndDropContainer::findParentDragContainerFor (Component* c) { return c != nullptr ? c->findParentComponentOfClass() : nullptr; diff --git a/modules/juce_gui_basics/mouse/juce_DragAndDropContainer.h b/modules/juce_gui_basics/mouse/juce_DragAndDropContainer.h index 072f35ee18..a8d4be62af 100644 --- a/modules/juce_gui_basics/mouse/juce_DragAndDropContainer.h +++ b/modules/juce_gui_basics/mouse/juce_DragAndDropContainer.h @@ -102,6 +102,9 @@ public: */ var getCurrentDragDescription() const; + /** If a drag is in progress, this allows the image being shown to be dynamically updated. */ + void setCurrentDragImage (const Image& newImage); + /** Utility to find the DragAndDropContainer for a given Component. This will search up this component's parent hierarchy looking for the first