diff --git a/dgl/NanoVG.hpp b/dgl/NanoVG.hpp index 666bd023..37caa475 100644 --- a/dgl/NanoVG.hpp +++ b/dgl/NanoVG.hpp @@ -37,11 +37,21 @@ START_NAMESPACE_DGL class NanoImage { public: + /** + Constructor for null image. + */ + NanoImage() noexcept; + /** Destructor. */ ~NanoImage(); + /** + Check if this is a valid image. + */ + bool isValid() const noexcept; + /** Get size. */ @@ -52,6 +62,12 @@ public: */ void updateImage(const uchar* data); + /** + Operator =. + Takes the image data from @a img, invalidating it. + */ + NanoImage operator=(NanoImage img) noexcept; + protected: /** Constructors are protected. @@ -62,12 +78,9 @@ protected: NanoImage(int w, int h, const uchar* data); private: - NVGcontext* const fContext; - const int fImageId; + NVGcontext* fContext; + int fImageId; friend class NanoVG; - - DISTRHO_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(NanoImage) - DISTRHO_PREVENT_HEAP_ALLOCATION }; // ----------------------------------------------------------------------- diff --git a/dgl/src/NanoVG.cpp b/dgl/src/NanoVG.cpp index 3e888a34..b4e31032 100644 --- a/dgl/src/NanoVG.cpp +++ b/dgl/src/NanoVG.cpp @@ -85,6 +85,20 @@ NanoVG::Paint::operator NVGpaint() const noexcept static NVGcontext* sLastContext = nullptr; +NanoImage::NanoImage() noexcept + : fContext(nullptr), + fImageId(0) {} + +#if 0 +NanoImage::NanoImage(NanoImage& img) noexcept + : fContext(img.fContext), + fImageId(img.fImageId) +{ + img.fContext = nullptr; + img.fImageId = 0; +} +#endif + NanoImage::NanoImage(const char* filename) : fContext(sLastContext), fImageId((fContext != nullptr) ? nvgCreateImage(fContext, filename) : 0) {} @@ -103,6 +117,11 @@ NanoImage::~NanoImage() nvgDeleteImage(fContext, fImageId); } +bool NanoImage::isValid() const noexcept +{ + return (fContext != nullptr && fImageId != 0); +} + Size NanoImage::getSize() const { int w=0, h=0; @@ -119,6 +138,20 @@ void NanoImage::updateImage(const uchar* data) nvgUpdateImage(fContext, fImageId, data); } +NanoImage NanoImage::operator=(NanoImage img) noexcept +{ + if (fContext != nullptr && fImageId != 0) + nvgDeleteImage(fContext, fImageId); + + fContext = img.fContext; + fImageId = img.fImageId; + + img.fContext = nullptr; + img.fImageId = 0; + + return *this; +} + // ----------------------------------------------------------------------- // NanoVG