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:
@@ -199,7 +199,18 @@ BackgroundImage::Show(BackgroundImageInfo *info, BView *view)
|
|||||||
// else fall thru
|
// else fall thru
|
||||||
case kScaledToFit:
|
case kScaledToFit:
|
||||||
if (fIsDesktop) {
|
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;
|
followFlags = B_FOLLOW_ALL;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -224,6 +235,30 @@ BackgroundImage::Show(BackgroundImageInfo *info, BView *view)
|
|||||||
fShowingBitmap = info;
|
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
|
void
|
||||||
BackgroundImage::Remove()
|
BackgroundImage::Remove()
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -115,6 +115,10 @@ private:
|
|||||||
|
|
||||||
void Add(BackgroundImageInfo *);
|
void Add(BackgroundImageInfo *);
|
||||||
|
|
||||||
|
float BRectRatio(BRect rect);
|
||||||
|
float BRectHorizontalOverlap(BRect hostRect, BRect resizedRect);
|
||||||
|
float BRectVerticalOverlap(BRect hostRect, BRect resizedRect);
|
||||||
|
|
||||||
bool fIsDesktop;
|
bool fIsDesktop;
|
||||||
BNode fDefinedByNode;
|
BNode fDefinedByNode;
|
||||||
BView *fView;
|
BView *fView;
|
||||||
|
|||||||
@@ -299,7 +299,18 @@ BackgroundImage::Show(BackgroundImageInfo* info, BView* view)
|
|||||||
// else fall thru
|
// else fall thru
|
||||||
case kScaledToFit:
|
case kScaledToFit:
|
||||||
if (fIsDesktop) {
|
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;
|
followFlags = B_FOLLOW_ALL;
|
||||||
break;
|
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
|
void
|
||||||
BackgroundImage::Remove()
|
BackgroundImage::Remove()
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -139,6 +139,10 @@ private:
|
|||||||
// no public constructor, GetBackgroundImage factory function is
|
// no public constructor, GetBackgroundImage factory function is
|
||||||
// used instead
|
// used instead
|
||||||
|
|
||||||
|
float BRectRatio(BRect rect);
|
||||||
|
float BRectHorizontalOverlap(BRect hostRect, BRect resizedRect);
|
||||||
|
float BRectVerticalOverlap(BRect hostRect, BRect resizedRect);
|
||||||
|
|
||||||
bool fIsDesktop;
|
bool fIsDesktop;
|
||||||
BNode fDefinedByNode;
|
BNode fDefinedByNode;
|
||||||
BView* fView;
|
BView* fView;
|
||||||
|
|||||||
Reference in New Issue
Block a user