| @@ -1514,11 +1514,6 @@ void Project::Item::setID (const String& newID) { state.setProperty (Ids::ID, | |||||
| std::unique_ptr<Drawable> Project::Item::loadAsImageFile() const | std::unique_ptr<Drawable> Project::Item::loadAsImageFile() const | ||||
| { | { | ||||
| const MessageManagerLock mml (ThreadPoolJob::getCurrentThreadPoolJob()); | |||||
| if (! mml.lockWasGained()) | |||||
| return nullptr; | |||||
| if (isValid()) | if (isValid()) | ||||
| return Drawable::createFromImageFile (getFile()); | return Drawable::createFromImageFile (getFile()); | ||||
| @@ -167,23 +167,15 @@ void Drawable::setTransformToFit (const Rectangle<float>& area, RectanglePlaceme | |||||
| //============================================================================== | //============================================================================== | ||||
| std::unique_ptr<Drawable> Drawable::createFromImageData (const void* data, const size_t numBytes) | std::unique_ptr<Drawable> Drawable::createFromImageData (const void* data, const size_t numBytes) | ||||
| { | { | ||||
| std::unique_ptr<Drawable> result; | |||||
| auto image = ImageFileFormat::loadFrom (data, numBytes); | auto image = ImageFileFormat::loadFrom (data, numBytes); | ||||
| if (image.isValid()) | if (image.isValid()) | ||||
| { | |||||
| auto* di = new DrawableImage(); | |||||
| di->setImage (image); | |||||
| result.reset (di); | |||||
| } | |||||
| else | |||||
| { | |||||
| if (auto svg = parseXMLIfTagMatches (String::createStringFromData (data, (int) numBytes), "svg")) | |||||
| result = Drawable::createFromSVG (*svg); | |||||
| } | |||||
| return std::make_unique<DrawableImage> (image); | |||||
| if (auto svg = parseXMLIfTagMatches (String::createStringFromData (data, (int) numBytes), "svg")) | |||||
| return Drawable::createFromSVG (*svg); | |||||
| return result; | |||||
| return {}; | |||||
| } | } | ||||
| std::unique_ptr<Drawable> Drawable::createFromImageDataStream (InputStream& dataSource) | std::unique_ptr<Drawable> Drawable::createFromImageDataStream (InputStream& dataSource) | ||||
| @@ -40,6 +40,11 @@ DrawableImage::DrawableImage (const DrawableImage& other) | |||||
| setBounds (other.getBounds()); | setBounds (other.getBounds()); | ||||
| } | } | ||||
| DrawableImage::DrawableImage (const Image& imageToUse) | |||||
| { | |||||
| setImageInternal (imageToUse); | |||||
| } | |||||
| DrawableImage::~DrawableImage() | DrawableImage::~DrawableImage() | ||||
| { | { | ||||
| } | } | ||||
| @@ -52,13 +57,8 @@ std::unique_ptr<Drawable> DrawableImage::createCopy() const | |||||
| //============================================================================== | //============================================================================== | ||||
| void DrawableImage::setImage (const Image& imageToUse) | void DrawableImage::setImage (const Image& imageToUse) | ||||
| { | { | ||||
| if (image != imageToUse) | |||||
| { | |||||
| image = imageToUse; | |||||
| setBounds (image.getBounds()); | |||||
| setBoundingBox (image.getBounds().toFloat()); | |||||
| if (setImageInternal (imageToUse)) | |||||
| repaint(); | repaint(); | ||||
| } | |||||
| } | } | ||||
| void DrawableImage::setOpacity (const float newOpacity) | void DrawableImage::setOpacity (const float newOpacity) | ||||
| @@ -133,6 +133,20 @@ Path DrawableImage::getOutlineAsPath() const | |||||
| return {}; // not applicable for images | return {}; // not applicable for images | ||||
| } | } | ||||
| //============================================================================== | |||||
| bool DrawableImage::setImageInternal (const Image& imageToUse) | |||||
| { | |||||
| if (image != imageToUse) | |||||
| { | |||||
| image = imageToUse; | |||||
| setBounds (image.getBounds()); | |||||
| setBoundingBox (image.getBounds().toFloat()); | |||||
| return true; | |||||
| } | |||||
| return false; | |||||
| } | |||||
| //============================================================================== | //============================================================================== | ||||
| std::unique_ptr<AccessibilityHandler> DrawableImage::createAccessibilityHandler() | std::unique_ptr<AccessibilityHandler> DrawableImage::createAccessibilityHandler() | ||||
| { | { | ||||
| @@ -41,6 +41,9 @@ public: | |||||
| DrawableImage(); | DrawableImage(); | ||||
| DrawableImage (const DrawableImage&); | DrawableImage (const DrawableImage&); | ||||
| /** Sets the image that this drawable will render. */ | |||||
| explicit DrawableImage (const Image& imageToUse); | |||||
| /** Destructor. */ | /** Destructor. */ | ||||
| ~DrawableImage() override; | ~DrawableImage() override; | ||||
| @@ -98,6 +101,9 @@ public: | |||||
| std::unique_ptr<AccessibilityHandler> createAccessibilityHandler() override; | std::unique_ptr<AccessibilityHandler> createAccessibilityHandler() override; | ||||
| private: | private: | ||||
| //============================================================================== | |||||
| bool setImageInternal (const Image&); | |||||
| //============================================================================== | //============================================================================== | ||||
| Image image; | Image image; | ||||
| float opacity = 1.0f; | float opacity = 1.0f; | ||||