Fixed min/max scaling.

This commit is contained in:
emb 2015-02-09 20:03:49 -06:00
parent 5db3d3f174
commit 6184e89e81
2 changed files with 100 additions and 31 deletions

View File

@ -62,59 +62,125 @@ float ViewInfo::GetYRelativeToOrigin() const
float ViewInfo::GetHeight() const
{
float value = Height;
float height = GetAbsoluteHeight();
float width = GetAbsoluteWidth();
if(Height == -1 && Width == -1)
if (height < MinHeight || width < MinWidth)
{
value = ImageHeight;
float scaleH = MinHeight / height;
float scaleW = MinWidth / width;
if(width >= MinWidth && height < MinHeight)
{
height = MinHeight;
}
else if(width < MinWidth && height >= MinHeight)
{
height = scaleW * height;
}
else
{
height = (scaleH > scaleW) ? (MinHeight) : (height * scaleW);
}
}
else
if (width > MaxWidth || height > MaxHeight)
{
if (Height == -1 && ImageWidth != 0)
{
value = ImageHeight * Width / ImageWidth;
}
float scaleH = MaxHeight / height;
float scaleW = MaxWidth / width;
if (value < MinHeight)
if(width <= MaxWidth && height > MaxHeight)
{
value = MinHeight;
height = MaxHeight;
}
else if (value > MaxHeight)
if(width > MaxWidth && height <= MaxHeight)
{
value = MaxHeight;
height = scaleW * height;
}
else
{
height = (scaleH < scaleW) ? (MaxHeight) : (height * scaleW);
}
}
return value;
return height;
}
float ViewInfo::GetWidth() const
{
float value = Width;
float height = GetAbsoluteHeight();
float width = GetAbsoluteWidth();
if (height < MinHeight || width < MinWidth)
{
float scaleH = MinHeight / height;
float scaleW = MinWidth / width;
if(height >= MinHeight && width < MinWidth)
{
width = MinWidth;
}
else if(height < MinHeight && width >= MinWidth)
{
width = scaleH * width;
}
else
{
width = (scaleH > scaleW) ? (MinWidth) : (width * scaleH);
}
}
if (width > MaxWidth || height > MaxHeight)
{
float scaleH = MaxHeight / height;
float scaleW = MaxWidth / width;
if(height <= MaxHeight && width > MaxWidth)
{
width = MaxWidth;
}
if(height > MaxHeight && width <= MaxWidth)
{
width = scaleH * width;
}
else
{
width = (scaleH > scaleW) ? (MaxWidth) : (width * scaleH);
}
}
return width;
}
float ViewInfo::GetAbsoluteHeight() const
{
if(Height == -1 && Width == -1)
{
value = ImageWidth;
}
else
{
if (Width == -1 && ImageHeight != 0)
{
value = ImageWidth * Height / ImageHeight;
}
if (value < MinWidth)
{
value = MinWidth;
}
else if (value > MaxWidth)
{
value = MaxWidth;
}
return ImageHeight;
}
return value;
if (Height == -1 && ImageWidth != 0)
{
return ImageHeight * Width / ImageWidth;
}
return Height;
}
float ViewInfo::GetAbsoluteWidth() const
{
if(Height == -1 && Width == -1)
{
return ImageWidth;
}
if (Width == -1 && ImageHeight != 0)
{
return ImageWidth * Height / ImageHeight;
}
return Width;
}
float ViewInfo::GetXOffset() const
{
return XOffset;

View File

@ -31,6 +31,7 @@ public:
float GetHeight() const;
float GetWidth() const;
float GetAngle() const;
void SetAngle(float angle);
float GetImageHeight() const;
@ -87,6 +88,8 @@ public:
static const int AlignBottom = -5;
private:
float GetAbsoluteHeight() const;
float GetAbsoluteWidth() const;
float X;
float Y;
float XOrigin;