Ticket #4720: wallpaper-fix.2.diff

File wallpaper-fix.2.diff, 4.0 KB (added by engleek, 10 years ago)

Third version, with three extra private methods to apply the 80 chars style rule in a nicer way and improve modularity. Hopefully this won't have too much of a negative impact on performance.

  • src/preferences/backgrounds/BackgroundImage.cpp

     
    299299            // else fall thru
    300300        case kScaledToFit:
    301301            if (fIsDesktop) {
    302                 destinationBitmapBounds = viewBounds;
     302                if (BRectRatio(destinationBitmapBounds)
     303                    >= BRectRatio(viewBounds)) {
     304                    float overlap = BRectHorizontalOverlap(viewBounds,
     305                        destinationBitmapBounds);
     306                    destinationBitmapBounds.Set(-overlap, 0,
     307                        viewBounds.Width() + overlap, viewBounds.Height());
     308                } else {
     309                    float overlap = BRectVerticalOverlap(viewBounds,
     310                        destinationBitmapBounds);
     311                    destinationBitmapBounds.Set(0, -overlap,
     312                        viewBounds.Width(), viewBounds.Height() + overlap);
     313                }
    303314                followFlags = B_FOLLOW_ALL;
    304315                break;
    305316            }
     
    334345}
    335346
    336347
     348float
     349BackgroundImage::BRectRatio(BRect rect)
     350{
     351    return rect.Width() / rect.Height();
     352}
     353
     354
     355float
     356BackgroundImage::BRectHorizontalOverlap(BRect hostRect, BRect resizedRect)
     357{
     358    return (((hostRect.Height() / resizedRect.Height())
     359        * resizedRect.Width()) - hostRect.Height()) / 2;
     360}
     361
     362
     363float
     364BackgroundImage::BRectVerticalOverlap(BRect hostRect, BRect resizedRect)
     365{
     366    return (((hostRect.Width() / resizedRect.Width())
     367        * resizedRect.Height()) - hostRect.Width()) / 2;
     368}
     369
     370
    337371void
    338372BackgroundImage::Remove()
    339373{
  • src/preferences/backgrounds/BackgroundImage.h

     
    139139        // no public constructor, GetBackgroundImage factory function is
    140140        // used instead
    141141
     142    float BRectRatio(BRect rect);
     143    float BRectHorizontalOverlap(BRect hostRect, BRect resizedRect);
     144    float BRectVerticalOverlap(BRect hostRect, BRect resizedRect);
     145
    142146    bool fIsDesktop;
    143147    BNode fDefinedByNode;
    144148    BView* fView;
  • src/kits/tracker/BackgroundImage.cpp

     
    199199            // else fall thru
    200200        case kScaledToFit:
    201201            if (fIsDesktop) {
    202                 destinationBitmapBounds = viewBounds;
     202                if (BRectRatio(destinationBitmapBounds)
     203                    >= BRectRatio(viewBounds)) {
     204                    float overlap = BRectHorizontalOverlap(viewBounds,
     205                        destinationBitmapBounds);
     206                    destinationBitmapBounds.Set(-overlap, 0,
     207                        viewBounds.Width() + overlap, viewBounds.Height());
     208                } else {
     209                    float overlap = BRectVerticalOverlap(viewBounds,
     210                        destinationBitmapBounds);
     211                    destinationBitmapBounds.Set(0, -overlap,
     212                        viewBounds.Width(), viewBounds.Height() + overlap);
     213                }
    203214                followFlags = B_FOLLOW_ALL;
    204215                break;
    205216            }
     
    224235    fShowingBitmap = info;
    225236}
    226237
     238
     239float
     240BackgroundImage::BRectRatio(BRect rect)
     241{
     242    return rect.Width() / rect.Height();
     243}
     244
     245
     246float
     247BackgroundImage::BRectHorizontalOverlap(BRect hostRect, BRect resizedRect)
     248{
     249    return (((hostRect.Height() / resizedRect.Height())
     250        * resizedRect.Width()) - hostRect.Height()) / 2;
     251}
     252
     253
     254float
     255BackgroundImage::BRectVerticalOverlap(BRect hostRect, BRect resizedRect)
     256{
     257    return (((hostRect.Width() / resizedRect.Width())
     258        * resizedRect.Height()) - hostRect.Width()) / 2;
     259}
     260
     261
    227262void
    228263BackgroundImage::Remove()
    229264{
  • src/kits/tracker/BackgroundImage.h

     
    115115
    116116    void Add(BackgroundImageInfo *);
    117117
     118    float BRectRatio(BRect rect);
     119    float BRectHorizontalOverlap(BRect hostRect, BRect resizedRect);
     120    float BRectVerticalOverlap(BRect hostRect, BRect resizedRect);
     121
    118122    bool fIsDesktop;
    119123    BNode fDefinedByNode;
    120124    BView *fView;