DPF

DISTRHO Plugin Framework
Log | Files | Refs | Submodules | README | LICENSE

commit c689d18ffa3059ba12cea7a4f883525edae0d500
parent 52a8f482389daa30a44c5fa85e80ce2aac44bf50
Author: falkTX <falktx@gmail.com>
Date:   Sat, 24 May 2014 15:40:59 +0100

Add some stuff to NanoImage to make it usable

Diffstat:
Mdgl/NanoVG.hpp | 23++++++++++++++++++-----
Mdgl/src/NanoVG.cpp | 33+++++++++++++++++++++++++++++++++
2 files changed, 51 insertions(+), 5 deletions(-)

diff --git a/dgl/NanoVG.hpp b/dgl/NanoVG.hpp @@ -38,11 +38,21 @@ class NanoImage { public: /** + Constructor for null image. + */ + NanoImage() noexcept; + + /** Destructor. */ ~NanoImage(); /** + Check if this is a valid image. + */ + bool isValid() const noexcept; + + /** Get size. */ Size<int> getSize() const; @@ -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 @@ -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<int> 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