| @@ -496,18 +496,20 @@ public: | |||||
| if (svgFileStream.get() != nullptr) | if (svgFileStream.get() != nullptr) | ||||
| { | { | ||||
| svgDrawable.reset (dynamic_cast<DrawableComposite*> (Drawable::createFromImageDataStream (*svgFileStream))); | |||||
| svgDrawable = Drawable::createFromImageDataStream (*svgFileStream); | |||||
| if (svgDrawable.get() != nullptr) | |||||
| if (svgDrawable != nullptr) | |||||
| { | { | ||||
| // to make our icon the right size, we'll set its bounding box to the size and position that we want. | // to make our icon the right size, we'll set its bounding box to the size and position that we want. | ||||
| svgDrawable->setBoundingBox ({ -100.0f, -100.0f, 200.0f, 200.0f }); | |||||
| if (auto comp = dynamic_cast<DrawableComposite*> (svgDrawable.get())) | |||||
| comp->setBoundingBox ({ -100.0f, -100.0f, 200.0f, 200.0f }); | |||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| Time lastSVGLoadTime; | Time lastSVGLoadTime; | ||||
| std::unique_ptr<DrawableComposite> svgDrawable; | |||||
| std::unique_ptr<Drawable> svgDrawable; | |||||
| }; | }; | ||||
| //============================================================================== | //============================================================================== | ||||
| @@ -632,12 +632,14 @@ private: | |||||
| case edit_copy: return createButtonFromZipFileSVG (itemId, "copy", "edit-copy.svg"); | case edit_copy: return createButtonFromZipFileSVG (itemId, "copy", "edit-copy.svg"); | ||||
| case edit_cut: return createButtonFromZipFileSVG (itemId, "cut", "edit-cut.svg"); | case edit_cut: return createButtonFromZipFileSVG (itemId, "cut", "edit-cut.svg"); | ||||
| case edit_paste: return createButtonFromZipFileSVG (itemId, "paste", "edit-paste.svg"); | case edit_paste: return createButtonFromZipFileSVG (itemId, "paste", "edit-paste.svg"); | ||||
| case juceLogoButton: | case juceLogoButton: | ||||
| { | { | ||||
| auto* drawable = new DrawableImage(); | |||||
| auto drawable = std::make_unique<DrawableImage>(); | |||||
| drawable->setImage (getImageFromAssets ("juce_icon.png")); | drawable->setImage (getImageFromAssets ("juce_icon.png")); | ||||
| return new ToolbarButton (itemId, "juce!", drawable, nullptr); | |||||
| return new ToolbarButton (itemId, "juce!", std::move (drawable), {}); | |||||
| } | } | ||||
| case customComboBox: return new CustomToolbarComboBox (itemId); | case customComboBox: return new CustomToolbarComboBox (itemId); | ||||
| default: break; | default: break; | ||||
| } | } | ||||
| @@ -670,8 +672,8 @@ private: | |||||
| } | } | ||||
| } | } | ||||
| auto* image = iconsFromZipFile[iconNames.indexOf (filename)]->createCopy(); | |||||
| return new ToolbarButton (itemId, text, image, nullptr); | |||||
| auto* image = iconsFromZipFile[iconNames.indexOf (filename)]; | |||||
| return new ToolbarButton (itemId, text, image->createCopy(), {}); | |||||
| } | } | ||||
| // Demonstrates how to put a custom component into a toolbar - this one contains | // Demonstrates how to put a custom component into a toolbar - this one contains | ||||
| @@ -210,8 +210,8 @@ public: | |||||
| dontAskAgainButton.setToggleState (getGlobalProperties().getValue (Ids::dontQueryForUpdate, {}).isNotEmpty(), dontSendNotification); | dontAskAgainButton.setToggleState (getGlobalProperties().getValue (Ids::dontQueryForUpdate, {}).isNotEmpty(), dontSendNotification); | ||||
| addAndMakeVisible (dontAskAgainButton); | addAndMakeVisible (dontAskAgainButton); | ||||
| juceIcon.reset (Drawable::createFromImageData (BinaryData::juce_icon_png, BinaryData::juce_icon_pngSize)); | |||||
| juceIcon = Drawable::createFromImageData (BinaryData::juce_icon_png, | |||||
| BinaryData::juce_icon_pngSize); | |||||
| lookAndFeelChanged(); | lookAndFeelChanged(); | ||||
| setSize (500, 280); | setSize (500, 280); | ||||
| @@ -109,7 +109,7 @@ private: | |||||
| if (drawable == nullptr) | if (drawable == nullptr) | ||||
| if (auto svg = parseXML (file)) | if (auto svg = parseXML (file)) | ||||
| drawable.reset (Drawable::createFromSVG (*svg)); | |||||
| drawable = Drawable::createFromSVG (*svg); | |||||
| facts.removeEmptyStrings (true); | facts.removeEmptyStrings (true); | ||||
| } | } | ||||
| @@ -188,8 +188,8 @@ const Drawable* BinaryResources::getDrawable (const String& name) const | |||||
| if (auto* res = const_cast<BinaryResources::BinaryResource*> (getResource (name))) | if (auto* res = const_cast<BinaryResources::BinaryResource*> (getResource (name))) | ||||
| { | { | ||||
| if (res->drawable == nullptr && res->data.getSize() > 0) | if (res->drawable == nullptr && res->data.getSize() > 0) | ||||
| res->drawable.reset (Drawable::createFromImageData (res->data.getData(), | |||||
| res->data.getSize())); | |||||
| res->drawable = Drawable::createFromImageData (res->data.getData(), | |||||
| res->data.getSize()); | |||||
| return res->drawable.get(); | return res->drawable.get(); | ||||
| } | } | ||||
| @@ -40,7 +40,7 @@ struct LogoComponent : public Component | |||||
| LogoComponent() | LogoComponent() | ||||
| { | { | ||||
| if (auto svg = parseXML (BinaryData::background_logo_svg)) | if (auto svg = parseXML (BinaryData::background_logo_svg)) | ||||
| logo.reset (Drawable::createFromSVG (*svg)); | |||||
| logo = Drawable::createFromSVG (*svg); | |||||
| else | else | ||||
| jassertfalse; | jassertfalse; | ||||
| } | } | ||||
| @@ -41,12 +41,12 @@ public: | |||||
| // svg for thumbnail icon | // svg for thumbnail icon | ||||
| auto svg = parseXML (thumbSvg); | auto svg = parseXML (thumbSvg); | ||||
| jassert (svg != nullptr); | jassert (svg != nullptr); | ||||
| thumb.reset (Drawable::createFromSVG (*svg)); | |||||
| thumb = Drawable::createFromSVG (*svg); | |||||
| // svg for thumbnail background highlight | // svg for thumbnail background highlight | ||||
| auto backSvg = parseXML (BinaryData::wizard_Highlight_svg); | auto backSvg = parseXML (BinaryData::wizard_Highlight_svg); | ||||
| jassert (backSvg != nullptr); | jassert (backSvg != nullptr); | ||||
| hoverBackground.reset (Drawable::createFromSVG (*backSvg)); | |||||
| hoverBackground = Drawable::createFromSVG (*backSvg); | |||||
| name = buttonName; | name = buttonName; | ||||
| @@ -84,12 +84,7 @@ public: | |||||
| expectEquals (derivedObject->getReferenceCount(), 1); | expectEquals (derivedObject->getReferenceCount(), 1); | ||||
| baseArray.add (baseObjectPtr); | baseArray.add (baseObjectPtr); | ||||
| #if JUCE_STRICT_REFCOUNTEDPOINTER | |||||
| baseArray.add (derivedObjectPtr); | |||||
| #else | |||||
| baseArray.add (derivedObjectPtr.get()); | baseArray.add (derivedObjectPtr.get()); | ||||
| #endif | |||||
| for (auto o : baseArray) | for (auto o : baseArray) | ||||
| expectEquals (o->getReferenceCount(), 2); | expectEquals (o->getReferenceCount(), 2); | ||||
| @@ -37,9 +37,12 @@ DrawableButton::~DrawableButton() | |||||
| } | } | ||||
| //============================================================================== | //============================================================================== | ||||
| static Drawable* copyDrawableIfNotNull (const Drawable* const d) | |||||
| static std::unique_ptr<Drawable> copyDrawableIfNotNull (const Drawable* const d) | |||||
| { | { | ||||
| return d != nullptr ? d->createCopy() : nullptr; | |||||
| if (d != nullptr) | |||||
| return d->createCopy(); | |||||
| return {}; | |||||
| } | } | ||||
| void DrawableButton::setImages (const Drawable* normal, | void DrawableButton::setImages (const Drawable* normal, | ||||
| @@ -53,14 +56,14 @@ void DrawableButton::setImages (const Drawable* normal, | |||||
| { | { | ||||
| jassert (normal != nullptr); // you really need to give it at least a normal image.. | jassert (normal != nullptr); // you really need to give it at least a normal image.. | ||||
| normalImage .reset (copyDrawableIfNotNull (normal)); | |||||
| overImage .reset (copyDrawableIfNotNull (over)); | |||||
| downImage .reset (copyDrawableIfNotNull (down)); | |||||
| disabledImage .reset (copyDrawableIfNotNull (disabled)); | |||||
| normalImageOn .reset (copyDrawableIfNotNull (normalOn)); | |||||
| overImageOn .reset (copyDrawableIfNotNull (overOn)); | |||||
| downImageOn .reset (copyDrawableIfNotNull (downOn)); | |||||
| disabledImageOn .reset (copyDrawableIfNotNull (disabledOn)); | |||||
| normalImage = copyDrawableIfNotNull (normal); | |||||
| overImage = copyDrawableIfNotNull (over); | |||||
| downImage = copyDrawableIfNotNull (down); | |||||
| disabledImage = copyDrawableIfNotNull (disabled); | |||||
| normalImageOn = copyDrawableIfNotNull (normalOn); | |||||
| overImageOn = copyDrawableIfNotNull (overOn); | |||||
| downImageOn = copyDrawableIfNotNull (downOn); | |||||
| disabledImageOn = copyDrawableIfNotNull (disabledOn); | |||||
| currentImage = nullptr; | currentImage = nullptr; | ||||
| @@ -183,7 +183,7 @@ private: | |||||
| //============================================================================== | //============================================================================== | ||||
| ButtonStyle style; | ButtonStyle style; | ||||
| std::unique_ptr<Drawable> normalImage, overImage, downImage, disabledImage, | std::unique_ptr<Drawable> normalImage, overImage, downImage, disabledImage, | ||||
| normalImageOn, overImageOn, downImageOn, disabledImageOn; | |||||
| normalImageOn, overImageOn, downImageOn, disabledImageOn; | |||||
| Drawable* currentImage = nullptr; | Drawable* currentImage = nullptr; | ||||
| int edgeIndent = 3; | int edgeIndent = 3; | ||||
| @@ -28,11 +28,11 @@ namespace juce | |||||
| { | { | ||||
| ToolbarButton::ToolbarButton (const int iid, const String& buttonText, | ToolbarButton::ToolbarButton (const int iid, const String& buttonText, | ||||
| Drawable* const normalIm, Drawable* const toggledOnIm) | |||||
| std::unique_ptr<Drawable> normalIm, | |||||
| std::unique_ptr<Drawable> toggledOnIm) | |||||
| : ToolbarItemComponent (iid, buttonText, true), | : ToolbarItemComponent (iid, buttonText, true), | ||||
| normalImage (normalIm), | |||||
| toggledOnImage (toggledOnIm), | |||||
| currentImage (nullptr) | |||||
| normalImage (std::move (normalIm)), | |||||
| toggledOnImage (std::move (toggledOnIm)) | |||||
| { | { | ||||
| jassert (normalImage != nullptr); | jassert (normalImage != nullptr); | ||||
| } | } | ||||
| @@ -62,8 +62,8 @@ public: | |||||
| */ | */ | ||||
| ToolbarButton (int itemId, | ToolbarButton (int itemId, | ||||
| const String& labelText, | const String& labelText, | ||||
| Drawable* normalImage, | |||||
| Drawable* toggledOnImage); | |||||
| std::unique_ptr<Drawable> normalImage, | |||||
| std::unique_ptr<Drawable> toggledOnImage); | |||||
| /** Destructor. */ | /** Destructor. */ | ||||
| ~ToolbarButton() override; | ~ToolbarButton() override; | ||||
| @@ -87,7 +87,7 @@ public: | |||||
| private: | private: | ||||
| //============================================================================== | //============================================================================== | ||||
| std::unique_ptr<Drawable> normalImage, toggledOnImage; | std::unique_ptr<Drawable> normalImage, toggledOnImage; | ||||
| Drawable* currentImage; | |||||
| Drawable* currentImage = nullptr; | |||||
| void updateDrawable(); | void updateDrawable(); | ||||
| Drawable* getImageToUse() const; | Drawable* getImageToUse() const; | ||||
| @@ -110,11 +110,11 @@ DrawableComposite* Drawable::getParent() const | |||||
| return dynamic_cast<DrawableComposite*> (getParentComponent()); | return dynamic_cast<DrawableComposite*> (getParentComponent()); | ||||
| } | } | ||||
| void Drawable::setClipPath (Drawable* clipPath) | |||||
| void Drawable::setClipPath (std::unique_ptr<Drawable> clipPath) | |||||
| { | { | ||||
| if (drawableClipPath.get() != clipPath) | |||||
| if (drawableClipPath != clipPath) | |||||
| { | { | ||||
| drawableClipPath.reset (clipPath); | |||||
| drawableClipPath = std::move (clipPath); | |||||
| repaint(); | repaint(); | ||||
| } | } | ||||
| } | } | ||||
| @@ -166,9 +166,9 @@ void Drawable::setTransformToFit (const Rectangle<float>& area, RectanglePlaceme | |||||
| } | } | ||||
| //============================================================================== | //============================================================================== | ||||
| Drawable* Drawable::createFromImageData (const void* data, const size_t numBytes) | |||||
| std::unique_ptr<Drawable> Drawable::createFromImageData (const void* data, const size_t numBytes) | |||||
| { | { | ||||
| Drawable* result = nullptr; | |||||
| std::unique_ptr<Drawable> result; | |||||
| auto image = ImageFileFormat::loadFrom (data, numBytes); | auto image = ImageFileFormat::loadFrom (data, numBytes); | ||||
| @@ -176,7 +176,7 @@ Drawable* Drawable::createFromImageData (const void* data, const size_t numBytes | |||||
| { | { | ||||
| auto* di = new DrawableImage(); | auto* di = new DrawableImage(); | ||||
| di->setImage (image); | di->setImage (image); | ||||
| result = di; | |||||
| result.reset (di); | |||||
| } | } | ||||
| else | else | ||||
| { | { | ||||
| @@ -186,18 +186,14 @@ Drawable* Drawable::createFromImageData (const void* data, const size_t numBytes | |||||
| std::unique_ptr<XmlElement> outer (doc.getDocumentElement (true)); | std::unique_ptr<XmlElement> outer (doc.getDocumentElement (true)); | ||||
| if (outer != nullptr && outer->hasTagName ("svg")) | if (outer != nullptr && outer->hasTagName ("svg")) | ||||
| { | |||||
| std::unique_ptr<XmlElement> svg (doc.getDocumentElement()); | |||||
| if (svg != nullptr) | |||||
| if (auto svg = doc.getDocumentElement()) | |||||
| result = Drawable::createFromSVG (*svg); | result = Drawable::createFromSVG (*svg); | ||||
| } | |||||
| } | } | ||||
| return result; | return result; | ||||
| } | } | ||||
| Drawable* Drawable::createFromImageDataStream (InputStream& dataSource) | |||||
| std::unique_ptr<Drawable> Drawable::createFromImageDataStream (InputStream& dataSource) | |||||
| { | { | ||||
| MemoryOutputStream mo; | MemoryOutputStream mo; | ||||
| mo << dataSource; | mo << dataSource; | ||||
| @@ -205,11 +201,14 @@ Drawable* Drawable::createFromImageDataStream (InputStream& dataSource) | |||||
| return createFromImageData (mo.getData(), mo.getDataSize()); | return createFromImageData (mo.getData(), mo.getDataSize()); | ||||
| } | } | ||||
| Drawable* Drawable::createFromImageFile (const File& file) | |||||
| std::unique_ptr<Drawable> Drawable::createFromImageFile (const File& file) | |||||
| { | { | ||||
| FileInputStream fin (file); | FileInputStream fin (file); | ||||
| return fin.openedOk() ? createFromImageDataStream (fin) : nullptr; | |||||
| if (fin.openedOk()) | |||||
| return createFromImageDataStream (fin); | |||||
| return {}; | |||||
| } | } | ||||
| } // namespace juce | } // namespace juce | ||||
| @@ -54,7 +54,7 @@ public: | |||||
| Use this to create a new copy of this and any sub-objects in the tree. | Use this to create a new copy of this and any sub-objects in the tree. | ||||
| */ | */ | ||||
| virtual Drawable* createCopy() const = 0; | |||||
| virtual std::unique_ptr<Drawable> createCopy() const = 0; | |||||
| /** Creates a path that describes the outline of this drawable. */ | /** Creates a path that describes the outline of this drawable. */ | ||||
| virtual Path getOutlineAsPath() const = 0; | virtual Path getOutlineAsPath() const = 0; | ||||
| @@ -123,9 +123,9 @@ public: | |||||
| DrawableComposite* getParent() const; | DrawableComposite* getParent() const; | ||||
| /** Sets a the clipping region of this drawable using another drawable. | /** Sets a the clipping region of this drawable using another drawable. | ||||
| The drawbale passed in ill be deleted when no longer needed. | |||||
| The drawbale passed in will be deleted when no longer needed. | |||||
| */ | */ | ||||
| void setClipPath (Drawable* drawableClipPath); | |||||
| void setClipPath (std::unique_ptr<Drawable> drawableClipPath); | |||||
| //============================================================================== | //============================================================================== | ||||
| /** Tries to turn some kind of image file into a drawable. | /** Tries to turn some kind of image file into a drawable. | ||||
| @@ -133,21 +133,21 @@ public: | |||||
| The data could be an image that the ImageFileFormat class understands, or it | The data could be an image that the ImageFileFormat class understands, or it | ||||
| could be SVG. | could be SVG. | ||||
| */ | */ | ||||
| static Drawable* createFromImageData (const void* data, size_t numBytes); | |||||
| static std::unique_ptr<Drawable> createFromImageData (const void* data, size_t numBytes); | |||||
| /** Tries to turn a stream containing some kind of image data into a drawable. | /** Tries to turn a stream containing some kind of image data into a drawable. | ||||
| The data could be an image that the ImageFileFormat class understands, or it | The data could be an image that the ImageFileFormat class understands, or it | ||||
| could be SVG. | could be SVG. | ||||
| */ | */ | ||||
| static Drawable* createFromImageDataStream (InputStream& dataSource); | |||||
| static std::unique_ptr<Drawable> createFromImageDataStream (InputStream& dataSource); | |||||
| /** Tries to turn a file containing some kind of image data into a drawable. | /** Tries to turn a file containing some kind of image data into a drawable. | ||||
| The data could be an image that the ImageFileFormat class understands, or it | The data could be an image that the ImageFileFormat class understands, or it | ||||
| could be SVG. | could be SVG. | ||||
| */ | */ | ||||
| static Drawable* createFromImageFile (const File& file); | |||||
| static std::unique_ptr<Drawable> createFromImageFile (const File& file); | |||||
| /** Attempts to parse an SVG (Scalable Vector Graphics) document, and to turn this | /** Attempts to parse an SVG (Scalable Vector Graphics) document, and to turn this | ||||
| into a Drawable tree. | into a Drawable tree. | ||||
| @@ -158,7 +158,7 @@ public: | |||||
| SVG is a pretty large and complex spec, and this doesn't aim to be a full | SVG is a pretty large and complex spec, and this doesn't aim to be a full | ||||
| implementation, but it can return the basic vector objects. | implementation, but it can return the basic vector objects. | ||||
| */ | */ | ||||
| static Drawable* createFromSVG (const XmlElement& svgDocument); | |||||
| static std::unique_ptr<Drawable> createFromSVG (const XmlElement& svgDocument); | |||||
| /** Attempts to parse an SVG (Scalable Vector Graphics) document from a file, | /** Attempts to parse an SVG (Scalable Vector Graphics) document from a file, | ||||
| and to turn this into a Drawable tree. | and to turn this into a Drawable tree. | ||||
| @@ -172,7 +172,7 @@ public: | |||||
| Any references to references to external image files will be relative to | Any references to references to external image files will be relative to | ||||
| the parent directory of the file passed. | the parent directory of the file passed. | ||||
| */ | */ | ||||
| static Drawable* createFromSVGFile (const File& svgFile); | |||||
| static std::unique_ptr<Drawable> createFromSVGFile (const File& svgFile); | |||||
| /** Parses an SVG path string and returns it. */ | /** Parses an SVG path string and returns it. */ | ||||
| static Path parseSVGPath (const String& svgPath); | static Path parseSVGPath (const String& svgPath); | ||||
| @@ -40,7 +40,7 @@ DrawableComposite::DrawableComposite (const DrawableComposite& other) | |||||
| { | { | ||||
| for (auto* c : other.getChildren()) | for (auto* c : other.getChildren()) | ||||
| if (auto* d = dynamic_cast<const Drawable*> (c)) | if (auto* d = dynamic_cast<const Drawable*> (c)) | ||||
| addAndMakeVisible (d->createCopy()); | |||||
| addAndMakeVisible (d->createCopy().release()); | |||||
| } | } | ||||
| DrawableComposite::~DrawableComposite() | DrawableComposite::~DrawableComposite() | ||||
| @@ -48,9 +48,9 @@ DrawableComposite::~DrawableComposite() | |||||
| deleteAllChildren(); | deleteAllChildren(); | ||||
| } | } | ||||
| Drawable* DrawableComposite::createCopy() const | |||||
| std::unique_ptr<Drawable> DrawableComposite::createCopy() const | |||||
| { | { | ||||
| return new DrawableComposite (*this); | |||||
| return std::make_unique<DrawableComposite> (*this); | |||||
| } | } | ||||
| //============================================================================== | //============================================================================== | ||||
| @@ -91,7 +91,7 @@ public: | |||||
| //============================================================================== | //============================================================================== | ||||
| /** @internal */ | /** @internal */ | ||||
| Drawable* createCopy() const override; | |||||
| std::unique_ptr<Drawable> createCopy() const override; | |||||
| /** @internal */ | /** @internal */ | ||||
| Rectangle<float> getDrawableBounds() const override; | Rectangle<float> getDrawableBounds() const override; | ||||
| /** @internal */ | /** @internal */ | ||||
| @@ -45,9 +45,9 @@ DrawableImage::~DrawableImage() | |||||
| { | { | ||||
| } | } | ||||
| Drawable* DrawableImage::createCopy() const | |||||
| std::unique_ptr<Drawable> DrawableImage::createCopy() const | |||||
| { | { | ||||
| return new DrawableImage (*this); | |||||
| return std::make_unique<DrawableImage> (*this); | |||||
| } | } | ||||
| //============================================================================== | //============================================================================== | ||||
| @@ -90,7 +90,7 @@ public: | |||||
| /** @internal */ | /** @internal */ | ||||
| bool hitTest (int x, int y) override; | bool hitTest (int x, int y) override; | ||||
| /** @internal */ | /** @internal */ | ||||
| Drawable* createCopy() const override; | |||||
| std::unique_ptr<Drawable> createCopy() const override; | |||||
| /** @internal */ | /** @internal */ | ||||
| Rectangle<float> getDrawableBounds() const override; | Rectangle<float> getDrawableBounds() const override; | ||||
| /** @internal */ | /** @internal */ | ||||
| @@ -35,9 +35,9 @@ DrawablePath::DrawablePath (const DrawablePath& other) : DrawableShape (other) | |||||
| setPath (other.path); | setPath (other.path); | ||||
| } | } | ||||
| Drawable* DrawablePath::createCopy() const | |||||
| std::unique_ptr<Drawable> DrawablePath::createCopy() const | |||||
| { | { | ||||
| return new DrawablePath (*this); | |||||
| return std::make_unique<DrawablePath> (*this); | |||||
| } | } | ||||
| void DrawablePath::setPath (const Path& newPath) | void DrawablePath::setPath (const Path& newPath) | ||||
| @@ -67,7 +67,7 @@ public: | |||||
| //============================================================================== | //============================================================================== | ||||
| /** @internal */ | /** @internal */ | ||||
| Drawable* createCopy() const override; | |||||
| std::unique_ptr<Drawable> createCopy() const override; | |||||
| private: | private: | ||||
| //============================================================================== | //============================================================================== | ||||
| @@ -38,9 +38,9 @@ DrawableRectangle::DrawableRectangle (const DrawableRectangle& other) | |||||
| rebuildPath(); | rebuildPath(); | ||||
| } | } | ||||
| Drawable* DrawableRectangle::createCopy() const | |||||
| std::unique_ptr<Drawable> DrawableRectangle::createCopy() const | |||||
| { | { | ||||
| return new DrawableRectangle (*this); | |||||
| return std::make_unique<DrawableRectangle> (*this); | |||||
| } | } | ||||
| //============================================================================== | //============================================================================== | ||||
| @@ -62,7 +62,7 @@ public: | |||||
| //============================================================================== | //============================================================================== | ||||
| /** @internal */ | /** @internal */ | ||||
| Drawable* createCopy() const override; | |||||
| std::unique_ptr<Drawable> createCopy() const override; | |||||
| private: | private: | ||||
| Parallelogram<float> bounds; | Parallelogram<float> bounds; | ||||
| @@ -52,9 +52,9 @@ DrawableText::~DrawableText() | |||||
| { | { | ||||
| } | } | ||||
| Drawable* DrawableText::createCopy() const | |||||
| std::unique_ptr<Drawable> DrawableText::createCopy() const | |||||
| { | { | ||||
| return new DrawableText (*this); | |||||
| return std::make_unique<DrawableText> (*this); | |||||
| } | } | ||||
| //============================================================================== | //============================================================================== | ||||
| @@ -92,7 +92,7 @@ public: | |||||
| /** @internal */ | /** @internal */ | ||||
| void paint (Graphics&) override; | void paint (Graphics&) override; | ||||
| /** @internal */ | /** @internal */ | ||||
| Drawable* createCopy() const override; | |||||
| std::unique_ptr<Drawable> createCopy() const override; | |||||
| /** @internal */ | /** @internal */ | ||||
| Rectangle<float> getDrawableBounds() const override; | Rectangle<float> getDrawableBounds() const override; | ||||
| /** @internal */ | /** @internal */ | ||||
| @@ -809,7 +809,7 @@ private: | |||||
| if (drawableClipPath->getNumChildComponents() > 0) | if (drawableClipPath->getNumChildComponents() > 0) | ||||
| { | { | ||||
| setCommonAttributes (*drawableClipPath, xmlPath); | setCommonAttributes (*drawableClipPath, xmlPath); | ||||
| target.setClipPath (drawableClipPath.release()); | |||||
| target.setClipPath (std::move (drawableClipPath)); | |||||
| return true; | return true; | ||||
| } | } | ||||
| } | } | ||||
| @@ -1696,32 +1696,32 @@ private: | |||||
| //============================================================================== | //============================================================================== | ||||
| Drawable* Drawable::createFromSVG (const XmlElement& svgDocument) | |||||
| std::unique_ptr<Drawable> Drawable::createFromSVG (const XmlElement& svgDocument) | |||||
| { | { | ||||
| if (! svgDocument.hasTagNameIgnoringNamespace ("svg")) | if (! svgDocument.hasTagNameIgnoringNamespace ("svg")) | ||||
| return nullptr; | |||||
| return {}; | |||||
| SVGState state (&svgDocument); | SVGState state (&svgDocument); | ||||
| return state.parseSVGElement (SVGState::XmlPath (&svgDocument, nullptr)); | |||||
| return std::unique_ptr<Drawable> (state.parseSVGElement (SVGState::XmlPath (&svgDocument, nullptr))); | |||||
| } | } | ||||
| Drawable* Drawable::createFromSVGFile (const File& svgFile) | |||||
| std::unique_ptr<Drawable> Drawable::createFromSVGFile (const File& svgFile) | |||||
| { | { | ||||
| XmlDocument doc (svgFile); | XmlDocument doc (svgFile); | ||||
| std::unique_ptr<XmlElement> outer (doc.getDocumentElement (true)); | |||||
| if (outer != nullptr && outer->hasTagName ("svg")) | |||||
| if (auto outer = doc.getDocumentElement (true)) | |||||
| { | { | ||||
| std::unique_ptr<XmlElement> svgDocument (doc.getDocumentElement()); | |||||
| if (svgDocument != nullptr) | |||||
| if (outer->hasTagName ("svg")) | |||||
| { | { | ||||
| SVGState state (svgDocument.get(), svgFile); | |||||
| return state.parseSVGElement (SVGState::XmlPath (svgDocument.get(), nullptr)); | |||||
| if (auto svgDocument = doc.getDocumentElement()) | |||||
| { | |||||
| SVGState state (svgDocument.get(), svgFile); | |||||
| return std::unique_ptr<Drawable> (state.parseSVGElement (SVGState::XmlPath (svgDocument.get(), nullptr))); | |||||
| } | |||||
| } | } | ||||
| } | } | ||||
| return nullptr; | |||||
| return {}; | |||||
| } | } | ||||
| Path Drawable::parseSVGPath (const String& svgPath) | Path Drawable::parseSVGPath (const String& svgPath) | ||||
| @@ -2315,14 +2315,14 @@ Button* LookAndFeel_V2::createTabBarExtrasButton() | |||||
| dp.setFill (Colour (0x59000000)); | dp.setFill (Colour (0x59000000)); | ||||
| DrawableComposite normalImage; | DrawableComposite normalImage; | ||||
| normalImage.addAndMakeVisible (ellipse.createCopy()); | |||||
| normalImage.addAndMakeVisible (dp.createCopy()); | |||||
| normalImage.addAndMakeVisible (ellipse.createCopy().release()); | |||||
| normalImage.addAndMakeVisible (dp.createCopy().release()); | |||||
| dp.setFill (Colour (0xcc000000)); | dp.setFill (Colour (0xcc000000)); | ||||
| DrawableComposite overImage; | DrawableComposite overImage; | ||||
| overImage.addAndMakeVisible (ellipse.createCopy()); | |||||
| overImage.addAndMakeVisible (dp.createCopy()); | |||||
| overImage.addAndMakeVisible (ellipse.createCopy().release()); | |||||
| overImage.addAndMakeVisible (dp.createCopy().release()); | |||||
| auto db = new DrawableButton ("tabs", DrawableButton::ImageFitted); | auto db = new DrawableButton ("tabs", DrawableButton::ImageFitted); | ||||
| db->setImages (&normalImage, &overImage, nullptr); | db->setImages (&normalImage, &overImage, nullptr); | ||||
| @@ -2653,7 +2653,7 @@ void LookAndFeel_V2::layoutFileBrowserComponent (FileBrowserComponent& browserCo | |||||
| } | } | ||||
| //============================================================================== | //============================================================================== | ||||
| static Drawable* createDrawableFromSVG (const char* data) | |||||
| static std::unique_ptr<Drawable> createDrawableFromSVG (const char* data) | |||||
| { | { | ||||
| auto xml = parseXML (data); | auto xml = parseXML (data); | ||||
| jassert (xml != nullptr); | jassert (xml != nullptr); | ||||
| @@ -2663,7 +2663,7 @@ static Drawable* createDrawableFromSVG (const char* data) | |||||
| const Drawable* LookAndFeel_V2::getDefaultFolderImage() | const Drawable* LookAndFeel_V2::getDefaultFolderImage() | ||||
| { | { | ||||
| if (folderImage == nullptr) | if (folderImage == nullptr) | ||||
| folderImage.reset (createDrawableFromSVG (R"svgdata( | |||||
| folderImage = createDrawableFromSVG (R"svgdata( | |||||
| <svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="706" height="532"> | <svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="706" height="532"> | ||||
| <defs> | <defs> | ||||
| <linearGradient id="a"> | <linearGradient id="a"> | ||||
| @@ -2678,7 +2678,7 @@ const Drawable* LookAndFeel_V2::getDefaultFolderImage() | |||||
| <path d="M608.6 136.8L235.2 208a22.7 22.7 0 0 0-16 19l-40.8 241c1.7 8.4 9.6 14.5 17.8 12.3l380-104c8-2.2 10.7-10.2 12.3-18.4l38-210.1c.4-15.4-10.4-11.8-18-11.1z" display="block" fill="url(#c)" opacity=".8" stroke="#446c98" stroke-width="7"/> | <path d="M608.6 136.8L235.2 208a22.7 22.7 0 0 0-16 19l-40.8 241c1.7 8.4 9.6 14.5 17.8 12.3l380-104c8-2.2 10.7-10.2 12.3-18.4l38-210.1c.4-15.4-10.4-11.8-18-11.1z" display="block" fill="url(#c)" opacity=".8" stroke="#446c98" stroke-width="7"/> | ||||
| </g> | </g> | ||||
| </svg> | </svg> | ||||
| )svgdata")); | |||||
| )svgdata"); | |||||
| return folderImage.get(); | return folderImage.get(); | ||||
| } | } | ||||
| @@ -2686,12 +2686,12 @@ const Drawable* LookAndFeel_V2::getDefaultFolderImage() | |||||
| const Drawable* LookAndFeel_V2::getDefaultDocumentFileImage() | const Drawable* LookAndFeel_V2::getDefaultDocumentFileImage() | ||||
| { | { | ||||
| if (documentImage == nullptr) | if (documentImage == nullptr) | ||||
| documentImage.reset (createDrawableFromSVG (R"svgdata( | |||||
| documentImage = createDrawableFromSVG (R"svgdata( | |||||
| <svg version="1" viewBox="-10 -10 450 600" xmlns="http://www.w3.org/2000/svg"> | <svg version="1" viewBox="-10 -10 450 600" xmlns="http://www.w3.org/2000/svg"> | ||||
| <path d="M17 0h290l120 132v426c0 10-8 19-17 19H17c-9 0-17-9-17-19V19C0 8 8 0 17 0z" fill="#e5e5e5" stroke="#888888" stroke-width="7"/> | <path d="M17 0h290l120 132v426c0 10-8 19-17 19H17c-9 0-17-9-17-19V19C0 8 8 0 17 0z" fill="#e5e5e5" stroke="#888888" stroke-width="7"/> | ||||
| <path d="M427 132H324c-9 0-17-9-17-19V0l120 132z" fill="#ccc"/> | <path d="M427 132H324c-9 0-17-9-17-19V0l120 132z" fill="#ccc"/> | ||||
| </svg> | </svg> | ||||
| )svgdata")); | |||||
| )svgdata"); | |||||
| return documentImage.get(); | return documentImage.get(); | ||||
| } | } | ||||
| @@ -1331,7 +1331,7 @@ PopupMenu::Item& PopupMenu::Item::operator= (const Item& other) | |||||
| text = other.text; | text = other.text; | ||||
| itemID = other.itemID; | itemID = other.itemID; | ||||
| subMenu.reset (createCopyIfNotNull (other.subMenu.get())); | subMenu.reset (createCopyIfNotNull (other.subMenu.get())); | ||||
| image.reset (other.image != nullptr ? other.image->createCopy() : nullptr); | |||||
| image = other.image != nullptr ? other.image->createCopy() : std::unique_ptr<Drawable>(); | |||||
| customComponent = other.customComponent; | customComponent = other.customComponent; | ||||
| customCallback = other.customCallback; | customCallback = other.customCallback; | ||||
| commandManager = other.commandManager; | commandManager = other.commandManager; | ||||
| @@ -1365,16 +1365,16 @@ void PopupMenu::addItem (int itemResultID, const String& itemText, bool isActive | |||||
| addItem (i); | addItem (i); | ||||
| } | } | ||||
| static Drawable* createDrawableFromImage (const Image& im) | |||||
| static std::unique_ptr<Drawable> createDrawableFromImage (const Image& im) | |||||
| { | { | ||||
| if (im.isValid()) | if (im.isValid()) | ||||
| { | { | ||||
| auto d = new DrawableImage(); | auto d = new DrawableImage(); | ||||
| d->setImage (im); | d->setImage (im); | ||||
| return d; | |||||
| return std::unique_ptr<Drawable> (d); | |||||
| } | } | ||||
| return nullptr; | |||||
| return {}; | |||||
| } | } | ||||
| void PopupMenu::addItem (int itemResultID, const String& itemText, bool isActive, bool isTicked, const Image& iconToUse) | void PopupMenu::addItem (int itemResultID, const String& itemText, bool isActive, bool isTicked, const Image& iconToUse) | ||||
| @@ -1382,21 +1382,22 @@ void PopupMenu::addItem (int itemResultID, const String& itemText, bool isActive | |||||
| addItem (itemResultID, itemText, isActive, isTicked, createDrawableFromImage (iconToUse)); | addItem (itemResultID, itemText, isActive, isTicked, createDrawableFromImage (iconToUse)); | ||||
| } | } | ||||
| void PopupMenu::addItem (int itemResultID, const String& itemText, bool isActive, bool isTicked, Drawable* iconToUse) | |||||
| void PopupMenu::addItem (int itemResultID, const String& itemText, bool isActive, | |||||
| bool isTicked, std::unique_ptr<Drawable> iconToUse) | |||||
| { | { | ||||
| Item i; | Item i; | ||||
| i.text = itemText; | i.text = itemText; | ||||
| i.itemID = itemResultID; | i.itemID = itemResultID; | ||||
| i.isEnabled = isActive; | i.isEnabled = isActive; | ||||
| i.isTicked = isTicked; | i.isTicked = isTicked; | ||||
| i.image.reset (iconToUse); | |||||
| i.image = std::move (iconToUse); | |||||
| addItem (i); | addItem (i); | ||||
| } | } | ||||
| void PopupMenu::addCommandItem (ApplicationCommandManager* commandManager, | void PopupMenu::addCommandItem (ApplicationCommandManager* commandManager, | ||||
| const CommandID commandID, | const CommandID commandID, | ||||
| const String& displayName, | const String& displayName, | ||||
| Drawable* iconToUse) | |||||
| std::unique_ptr<Drawable> iconToUse) | |||||
| { | { | ||||
| jassert (commandManager != nullptr && commandID != 0); | jassert (commandManager != nullptr && commandID != 0); | ||||
| @@ -1411,13 +1412,13 @@ void PopupMenu::addCommandItem (ApplicationCommandManager* commandManager, | |||||
| i.commandManager = commandManager; | i.commandManager = commandManager; | ||||
| i.isEnabled = target != nullptr && (info.flags & ApplicationCommandInfo::isDisabled) == 0; | i.isEnabled = target != nullptr && (info.flags & ApplicationCommandInfo::isDisabled) == 0; | ||||
| i.isTicked = (info.flags & ApplicationCommandInfo::isTicked) != 0; | i.isTicked = (info.flags & ApplicationCommandInfo::isTicked) != 0; | ||||
| i.image.reset (iconToUse); | |||||
| i.image = std::move (iconToUse); | |||||
| addItem (i); | addItem (i); | ||||
| } | } | ||||
| } | } | ||||
| void PopupMenu::addColouredItem (int itemResultID, const String& itemText, Colour itemTextColour, | void PopupMenu::addColouredItem (int itemResultID, const String& itemText, Colour itemTextColour, | ||||
| bool isActive, bool isTicked, Drawable* iconToUse) | |||||
| bool isActive, bool isTicked, std::unique_ptr<Drawable> iconToUse) | |||||
| { | { | ||||
| Item i; | Item i; | ||||
| i.text = itemText; | i.text = itemText; | ||||
| @@ -1425,7 +1426,7 @@ void PopupMenu::addColouredItem (int itemResultID, const String& itemText, Colou | |||||
| i.colour = itemTextColour; | i.colour = itemTextColour; | ||||
| i.isEnabled = isActive; | i.isEnabled = isActive; | ||||
| i.isTicked = isTicked; | i.isTicked = isTicked; | ||||
| i.image.reset (iconToUse); | |||||
| i.image = std::move (iconToUse); | |||||
| addItem (i); | addItem (i); | ||||
| } | } | ||||
| @@ -1438,7 +1439,7 @@ void PopupMenu::addColouredItem (int itemResultID, const String& itemText, Colou | |||||
| i.colour = itemTextColour; | i.colour = itemTextColour; | ||||
| i.isEnabled = isActive; | i.isEnabled = isActive; | ||||
| i.isTicked = isTicked; | i.isTicked = isTicked; | ||||
| i.image.reset (createDrawableFromImage (iconToUse)); | |||||
| i.image = createDrawableFromImage (iconToUse); | |||||
| addItem (i); | addItem (i); | ||||
| } | } | ||||
| @@ -1472,7 +1473,7 @@ void PopupMenu::addSubMenu (const String& subMenuName, const PopupMenu& subMenu, | |||||
| } | } | ||||
| void PopupMenu::addSubMenu (const String& subMenuName, const PopupMenu& subMenu, bool isActive, | void PopupMenu::addSubMenu (const String& subMenuName, const PopupMenu& subMenu, bool isActive, | ||||
| Drawable* iconToUse, bool isTicked, int itemResultID) | |||||
| std::unique_ptr<Drawable> iconToUse, bool isTicked, int itemResultID) | |||||
| { | { | ||||
| Item i; | Item i; | ||||
| i.text = subMenuName; | i.text = subMenuName; | ||||
| @@ -1480,7 +1481,7 @@ void PopupMenu::addSubMenu (const String& subMenuName, const PopupMenu& subMenu, | |||||
| i.subMenu.reset (new PopupMenu (subMenu)); | i.subMenu.reset (new PopupMenu (subMenu)); | ||||
| i.isEnabled = isActive && (itemResultID != 0 || subMenu.getNumItems() > 0); | i.isEnabled = isActive && (itemResultID != 0 || subMenu.getNumItems() > 0); | ||||
| i.isTicked = isTicked; | i.isTicked = isTicked; | ||||
| i.image.reset (iconToUse); | |||||
| i.image = std::move (iconToUse); | |||||
| addItem (i); | addItem (i); | ||||
| } | } | ||||
| @@ -231,7 +231,7 @@ public: | |||||
| const String& itemText, | const String& itemText, | ||||
| bool isEnabled, | bool isEnabled, | ||||
| bool isTicked, | bool isTicked, | ||||
| Drawable* iconToUse); | |||||
| std::unique_ptr<Drawable> iconToUse); | |||||
| /** Adds an item that represents one of the commands in a command manager object. | /** Adds an item that represents one of the commands in a command manager object. | ||||
| @@ -247,7 +247,7 @@ public: | |||||
| void addCommandItem (ApplicationCommandManager* commandManager, | void addCommandItem (ApplicationCommandManager* commandManager, | ||||
| CommandID commandID, | CommandID commandID, | ||||
| const String& displayName = String(), | const String& displayName = String(), | ||||
| Drawable* iconToUse = nullptr); | |||||
| std::unique_ptr<Drawable> iconToUse = {}); | |||||
| /** Appends a text item with a special colour. | /** Appends a text item with a special colour. | ||||
| @@ -273,7 +273,7 @@ public: | |||||
| Colour itemTextColour, | Colour itemTextColour, | ||||
| bool isEnabled, | bool isEnabled, | ||||
| bool isTicked, | bool isTicked, | ||||
| Drawable* iconToUse); | |||||
| std::unique_ptr<Drawable> iconToUse); | |||||
| /** Appends a custom menu item. | /** Appends a custom menu item. | ||||
| @@ -344,7 +344,7 @@ public: | |||||
| void addSubMenu (const String& subMenuName, | void addSubMenu (const String& subMenuName, | ||||
| const PopupMenu& subMenu, | const PopupMenu& subMenu, | ||||
| bool isEnabled, | bool isEnabled, | ||||
| Drawable* iconToUse, | |||||
| std::unique_ptr<Drawable> iconToUse, | |||||
| bool isTicked = false, | bool isTicked = false, | ||||
| int itemResultID = 0); | int itemResultID = 0); | ||||