mirror of
https://github.com/FunKey-Project/RetroFE.git
synced 2025-12-14 18:58:52 +01:00
Fixed min/max scaling.
This commit is contained in:
parent
5db3d3f174
commit
6184e89e81
@ -62,59 +62,125 @@ float ViewInfo::GetYRelativeToOrigin() const
|
|||||||
|
|
||||||
float ViewInfo::GetHeight() 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)
|
float scaleH = MaxHeight / height;
|
||||||
{
|
float scaleW = MaxWidth / width;
|
||||||
value = ImageHeight * Width / ImageWidth;
|
|
||||||
}
|
|
||||||
|
|
||||||
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 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)
|
if(Height == -1 && Width == -1)
|
||||||
{
|
{
|
||||||
value = ImageWidth;
|
return ImageHeight;
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
if (Width == -1 && ImageHeight != 0)
|
|
||||||
{
|
|
||||||
value = ImageWidth * Height / ImageHeight;
|
|
||||||
}
|
|
||||||
if (value < MinWidth)
|
|
||||||
{
|
|
||||||
value = MinWidth;
|
|
||||||
}
|
|
||||||
else if (value > MaxWidth)
|
|
||||||
{
|
|
||||||
value = MaxWidth;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
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
|
float ViewInfo::GetXOffset() const
|
||||||
{
|
{
|
||||||
return XOffset;
|
return XOffset;
|
||||||
|
|||||||
@ -31,6 +31,7 @@ public:
|
|||||||
|
|
||||||
float GetHeight() const;
|
float GetHeight() const;
|
||||||
float GetWidth() const;
|
float GetWidth() const;
|
||||||
|
|
||||||
float GetAngle() const;
|
float GetAngle() const;
|
||||||
void SetAngle(float angle);
|
void SetAngle(float angle);
|
||||||
float GetImageHeight() const;
|
float GetImageHeight() const;
|
||||||
@ -87,6 +88,8 @@ public:
|
|||||||
static const int AlignBottom = -5;
|
static const int AlignBottom = -5;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
float GetAbsoluteHeight() const;
|
||||||
|
float GetAbsoluteWidth() const;
|
||||||
float X;
|
float X;
|
||||||
float Y;
|
float Y;
|
||||||
float XOrigin;
|
float XOrigin;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user