diff --git a/src/kits/tracker/BackgroundImage.cpp b/src/kits/tracker/BackgroundImage.cpp index 27d41a4367..bb2056aa87 100644 --- a/src/kits/tracker/BackgroundImage.cpp +++ b/src/kits/tracker/BackgroundImage.cpp @@ -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() { diff --git a/src/kits/tracker/BackgroundImage.h b/src/kits/tracker/BackgroundImage.h index 56f9f9cacc..cba8f75405 100644 --- a/src/kits/tracker/BackgroundImage.h +++ b/src/kits/tracker/BackgroundImage.h @@ -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; diff --git a/src/preferences/backgrounds/BackgroundImage.cpp b/src/preferences/backgrounds/BackgroundImage.cpp index c7ffcdb21c..d6c34a648c 100644 --- a/src/preferences/backgrounds/BackgroundImage.cpp +++ b/src/preferences/backgrounds/BackgroundImage.cpp @@ -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() { diff --git a/src/preferences/backgrounds/BackgroundImage.h b/src/preferences/backgrounds/BackgroundImage.h index c42787795b..aa11a711df 100644 --- a/src/preferences/backgrounds/BackgroundImage.h +++ b/src/preferences/backgrounds/BackgroundImage.h @@ -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;