Applied patch from engleek with fix hints from devheart (bug #4720):

Scale to fit now keeps the aspect ratio by cutting horizontally or vertically.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@40144 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Jérôme Duval 2011-01-07 20:44:27 +00:00
parent 79de91c19b
commit 523ce58a8f
4 changed files with 79 additions and 2 deletions

View File

@ -199,7 +199,18 @@ BackgroundImage::Show(BackgroundImageInfo *info, BView *view)
// else fall thru
case kScaledToFit:
if (fIsDesktop) {
destinationBitmapBounds = viewBounds;
if (BRectRatio(destinationBitmapBounds)
>= BRectRatio(viewBounds)) {
float overlap = BRectHorizontalOverlap(viewBounds,
destinationBitmapBounds);
destinationBitmapBounds.Set(-overlap, 0,
viewBounds.Width() + overlap, viewBounds.Height());
} else {
float overlap = BRectVerticalOverlap(viewBounds,
destinationBitmapBounds);
destinationBitmapBounds.Set(0, -overlap,
viewBounds.Width(), viewBounds.Height() + overlap);
}
followFlags = B_FOLLOW_ALL;
break;
}
@ -224,6 +235,30 @@ BackgroundImage::Show(BackgroundImageInfo *info, BView *view)
fShowingBitmap = info;
}
float
BackgroundImage::BRectRatio(BRect rect)
{
return rect.Width() / rect.Height();
}
float
BackgroundImage::BRectHorizontalOverlap(BRect hostRect, BRect resizedRect)
{
return ((hostRect.Height() / resizedRect.Height() * resizedRect.Width())
- hostRect.Width()) / 2;
}
float
BackgroundImage::BRectVerticalOverlap(BRect hostRect, BRect resizedRect)
{
return ((hostRect.Width() / resizedRect.Width() * resizedRect.Height())
- hostRect.Height()) / 2;
}
void
BackgroundImage::Remove()
{

View File

@ -115,6 +115,10 @@ private:
void Add(BackgroundImageInfo *);
float BRectRatio(BRect rect);
float BRectHorizontalOverlap(BRect hostRect, BRect resizedRect);
float BRectVerticalOverlap(BRect hostRect, BRect resizedRect);
bool fIsDesktop;
BNode fDefinedByNode;
BView *fView;

View File

@ -299,7 +299,18 @@ BackgroundImage::Show(BackgroundImageInfo* info, BView* view)
// else fall thru
case kScaledToFit:
if (fIsDesktop) {
destinationBitmapBounds = viewBounds;
if (BRectRatio(destinationBitmapBounds)
>= BRectRatio(viewBounds)) {
float overlap = BRectHorizontalOverlap(viewBounds,
destinationBitmapBounds);
destinationBitmapBounds.Set(-overlap, 0,
viewBounds.Width() + overlap, viewBounds.Height());
} else {
float overlap = BRectVerticalOverlap(viewBounds,
destinationBitmapBounds);
destinationBitmapBounds.Set(0, -overlap,
viewBounds.Width(), viewBounds.Height() + overlap);
}
followFlags = B_FOLLOW_ALL;
break;
}
@ -334,6 +345,29 @@ BackgroundImage::Show(BackgroundImageInfo* info, BView* view)
}
float
BackgroundImage::BRectRatio(BRect rect)
{
return rect.Width() / rect.Height();
}
float
BackgroundImage::BRectHorizontalOverlap(BRect hostRect, BRect resizedRect)
{
return ((hostRect.Height() / resizedRect.Height() * resizedRect.Width())
- hostRect.Width()) / 2;
}
float
BackgroundImage::BRectVerticalOverlap(BRect hostRect, BRect resizedRect)
{
return ((hostRect.Width() / resizedRect.Width() * resizedRect.Height())
- hostRect.Height()) / 2;
}
void
BackgroundImage::Remove()
{

View File

@ -139,6 +139,10 @@ private:
// no public constructor, GetBackgroundImage factory function is
// used instead
float BRectRatio(BRect rect);
float BRectHorizontalOverlap(BRect hostRect, BRect resizedRect);
float BRectVerticalOverlap(BRect hostRect, BRect resizedRect);
bool fIsDesktop;
BNode fDefinedByNode;
BView* fView;