Browse Source

Add some stuff to NanoImage to make it usable

gh-pages
falkTX 11 years ago
parent
commit
c689d18ffa
2 changed files with 51 additions and 5 deletions
  1. +18
    -5
      dgl/NanoVG.hpp
  2. +33
    -0
      dgl/src/NanoVG.cpp

+ 18
- 5
dgl/NanoVG.hpp View File

@@ -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
};

// -----------------------------------------------------------------------


+ 33
- 0
dgl/src/NanoVG.cpp View File

@@ -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



Loading…
Cancel
Save