Fixed SliderComponent going beyond its min/max values.

Defensive measures against a possible SVG reinitialization bug.
This commit is contained in:
Aloshi 2014-03-22 18:17:14 -05:00
parent d18140536a
commit cf836c0f8a
3 changed files with 19 additions and 6 deletions

View file

@ -85,10 +85,10 @@ void SliderComponent::render(const Eigen::Affine3f& parentTrans)
void SliderComponent::setValue(float value)
{
mValue = value;
if(value < mMin)
value = mMin;
else if(value > mMax)
value = mMax;
if(mValue < mMin)
mValue = mMin;
else if(mValue > mMax)
mValue = mMax;
onValueChanged();
}

View file

@ -2,12 +2,14 @@
#include "../nanosvg/nanosvg.h"
#include "../nanosvg/nanosvgrast.h"
#include "../Log.h"
#include "../Util.h"
#define DPI 96
SVGResource::SVGResource(const std::string& path, bool tile) : TextureResource(path, tile), mSVGImage(NULL)
{
assert(tile == false);
mLastWidth = 0;
mLastHeight = 0;
}
SVGResource::~SVGResource()
@ -40,11 +42,20 @@ void SVGResource::initFromMemory(const char* file, size_t length)
return;
}
rasterizeAt((int)mSVGImage->width, (int)mSVGImage->height);
if(mLastWidth && mLastHeight)
rasterizeAt(mLastWidth, mLastHeight);
else
rasterizeAt((int)round(mSVGImage->width), (int)round(mSVGImage->height));
}
void SVGResource::rasterizeAt(size_t width, size_t height)
{
if(width != (int)round(mSVGImage->width) && height != (int)round(mSVGImage->height))
{
mLastWidth = width;
mLastHeight = height;
}
if(!mSVGImage)
return;

View file

@ -22,4 +22,6 @@ protected:
void deinitSVG();
NSVGimage* mSVGImage;
size_t mLastWidth;
size_t mLastHeight;
};