Author: korli Date: 2011-01-07 21:44:27 +0100 (Fri, 07 Jan 2011) New Revision: 40144 Changeset: http://dev.haiku-os.org/changeset/40144 Ticket: http://dev.haiku-os.org/ticket/4720 Modified: haiku/trunk/src/kits/tracker/BackgroundImage.cpp haiku/trunk/src/kits/tracker/BackgroundImage.h haiku/trunk/src/preferences/backgrounds/BackgroundImage.cpp haiku/trunk/src/preferences/backgrounds/BackgroundImage.h Log: Applied patch from engleek with fix hints from devheart (bug #4720): Scale to fit now keeps the aspect ratio by cutting horizontally or vertically. Modified: haiku/trunk/src/kits/tracker/BackgroundImage.cpp =================================================================== --- haiku/trunk/src/kits/tracker/BackgroundImage.cpp 2011-01-07 19:00:23 UTC (rev 40143) +++ haiku/trunk/src/kits/tracker/BackgroundImage.cpp 2011-01-07 20:44:27 UTC (rev 40144) @@ -199,7 +199,18 @@ // 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 @@ 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() { Modified: haiku/trunk/src/kits/tracker/BackgroundImage.h =================================================================== --- haiku/trunk/src/kits/tracker/BackgroundImage.h 2011-01-07 19:00:23 UTC (rev 40143) +++ haiku/trunk/src/kits/tracker/BackgroundImage.h 2011-01-07 20:44:27 UTC (rev 40144) @@ -115,6 +115,10 @@ 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; Modified: haiku/trunk/src/preferences/backgrounds/BackgroundImage.cpp =================================================================== --- haiku/trunk/src/preferences/backgrounds/BackgroundImage.cpp 2011-01-07 19:00:23 UTC (rev 40143) +++ haiku/trunk/src/preferences/backgrounds/BackgroundImage.cpp 2011-01-07 20:44:27 UTC (rev 40144) @@ -299,7 +299,18 @@ // 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 @@ } +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() { Modified: haiku/trunk/src/preferences/backgrounds/BackgroundImage.h =================================================================== --- haiku/trunk/src/preferences/backgrounds/BackgroundImage.h 2011-01-07 19:00:23 UTC (rev 40143) +++ haiku/trunk/src/preferences/backgrounds/BackgroundImage.h 2011-01-07 20:44:27 UTC (rev 40144) @@ -139,6 +139,10 @@ // 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;