LCOV - code coverage report
Current view: top level - sd/source/ui/slidesorter/view - SlsFramePainter.cxx (source / functions) Hit Total Coverage
Test: commit 0e63ca4fde4e446f346e35849c756a30ca294aab Lines: 94 96 97.9 %
Date: 2014-04-11 Functions: 8 8 100.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /*
       3             :  * This file is part of the LibreOffice project.
       4             :  *
       5             :  * This Source Code Form is subject to the terms of the Mozilla Public
       6             :  * License, v. 2.0. If a copy of the MPL was not distributed with this
       7             :  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
       8             :  *
       9             :  * This file incorporates work covered by the following license notice:
      10             :  *
      11             :  *   Licensed to the Apache Software Foundation (ASF) under one or more
      12             :  *   contributor license agreements. See the NOTICE file distributed
      13             :  *   with this work for additional information regarding copyright
      14             :  *   ownership. The ASF licenses this file to you under the Apache
      15             :  *   License, Version 2.0 (the "License"); you may not use this file
      16             :  *   except in compliance with the License. You may obtain a copy of
      17             :  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
      18             :  */
      19             : 
      20             : 
      21             : #include "SlsFramePainter.hxx"
      22             : #include <vcl/outdev.hxx>
      23             : #include <vcl/bmpacc.hxx>
      24             : 
      25             : 
      26             : namespace sd { namespace slidesorter { namespace view {
      27             : 
      28         189 : FramePainter::FramePainter (const BitmapEx& rShadowBitmap)
      29             :     : maTopLeft(rShadowBitmap,-1,-1),
      30             :       maTop(rShadowBitmap,0,-1),
      31             :       maTopRight(rShadowBitmap,+1,-1),
      32             :       maLeft(rShadowBitmap,-1,0),
      33             :       maRight(rShadowBitmap,+1,0),
      34             :       maBottomLeft(rShadowBitmap,-1,+1),
      35             :       maBottom(rShadowBitmap,0,+1),
      36             :       maBottomRight(rShadowBitmap,+1,+1),
      37             :       maCenter(rShadowBitmap,0,0),
      38         189 :       mbIsValid(false)
      39             : {
      40         378 :     if (rShadowBitmap.GetSizePixel().Width() == rShadowBitmap.GetSizePixel().Height()
      41         189 :         && (rShadowBitmap.GetSizePixel().Width()-1)%2 == 0
      42         378 :         && ((rShadowBitmap.GetSizePixel().Width()-1)/2)%2 == 1)
      43             :     {
      44         189 :         mbIsValid = true;
      45             :     }
      46             :     else
      47             :     {
      48             :         OSL_ASSERT(rShadowBitmap.GetSizePixel().Width() == rShadowBitmap.GetSizePixel().Height());
      49             :         OSL_ASSERT((rShadowBitmap.GetSizePixel().Width()-1)%2 == 0);
      50             :         OSL_ASSERT(((rShadowBitmap.GetSizePixel().Width()-1)/2)%2 == 1);
      51             :     }
      52         189 : }
      53             : 
      54             : 
      55             : 
      56             : 
      57         189 : FramePainter::~FramePainter (void)
      58             : {
      59         189 : }
      60             : 
      61             : 
      62             : 
      63             : 
      64          74 : void FramePainter::PaintFrame (
      65             :     OutputDevice& rDevice,
      66             :     const Rectangle aBox) const
      67             : {
      68          74 :     if ( ! mbIsValid)
      69          74 :         return;
      70             : 
      71             :     // Paint the shadow.
      72          74 :     maTopLeft.PaintCorner(rDevice, aBox.TopLeft());
      73          74 :     maTopRight.PaintCorner(rDevice, aBox.TopRight());
      74          74 :     maBottomLeft.PaintCorner(rDevice, aBox.BottomLeft());
      75          74 :     maBottomRight.PaintCorner(rDevice, aBox.BottomRight());
      76          74 :     maLeft.PaintSide(rDevice, aBox.TopLeft(), aBox.BottomLeft(), maTopLeft, maBottomLeft);
      77          74 :     maRight.PaintSide(rDevice, aBox.TopRight(), aBox.BottomRight(), maTopRight, maBottomRight);
      78          74 :     maTop.PaintSide(rDevice, aBox.TopLeft(), aBox.TopRight(), maTopLeft, maTopRight);
      79          74 :     maBottom.PaintSide(rDevice, aBox.BottomLeft(), aBox.BottomRight(), maBottomLeft, maBottomRight);
      80          74 :     maCenter.PaintCenter(rDevice,aBox);
      81             : }
      82             : 
      83             : 
      84             : 
      85             : 
      86          63 : void FramePainter::AdaptColor (
      87             :     const Color aNewColor,
      88             :     const bool bEraseCenter)
      89             : {
      90             :     // Get the source color.
      91          63 :     if (maCenter.maBitmap.IsEmpty())
      92           0 :         return;
      93          63 :     BitmapReadAccess* pReadAccess = maCenter.maBitmap.GetBitmap().AcquireReadAccess();
      94          63 :     if (pReadAccess == NULL)
      95           0 :         return;
      96          63 :     const Color aSourceColor = pReadAccess->GetColor(0,0);
      97          63 :     maCenter.maBitmap.GetBitmap().ReleaseAccess(pReadAccess);
      98             : 
      99             :     // Erase the center bitmap.
     100          63 :     if (bEraseCenter)
     101          63 :         maCenter.maBitmap.SetEmpty();
     102             : 
     103             :     // Replace the color in all bitmaps.
     104          63 :     maTopLeft.maBitmap.Replace(aSourceColor, aNewColor, 0);
     105          63 :     maTop.maBitmap.Replace(aSourceColor, aNewColor, 0);
     106          63 :     maTopRight.maBitmap.Replace(aSourceColor, aNewColor, 0);
     107          63 :     maLeft.maBitmap.Replace(aSourceColor, aNewColor, 0);
     108          63 :     maCenter.maBitmap.Replace(aSourceColor, aNewColor, 0);
     109          63 :     maRight.maBitmap.Replace(aSourceColor, aNewColor, 0);
     110          63 :     maBottomLeft.maBitmap.Replace(aSourceColor, aNewColor, 0);
     111          63 :     maBottom.maBitmap.Replace(aSourceColor, aNewColor, 0);
     112          63 :     maBottomRight.maBitmap.Replace(aSourceColor, aNewColor, 0);
     113             : }
     114             : 
     115             : 
     116             : 
     117             : 
     118             : //===== FramePainter::OffsetBitmap ============================================
     119             : 
     120        1701 : FramePainter::OffsetBitmap::OffsetBitmap (
     121             :     const BitmapEx& rBitmap,
     122             :     const sal_Int32 nHorizontalPosition,
     123             :     const sal_Int32 nVerticalPosition)
     124             :     : maBitmap(),
     125        1701 :       maOffset()
     126             : {
     127             :     OSL_ASSERT(nHorizontalPosition>=-1 && nHorizontalPosition<=+1);
     128             :     OSL_ASSERT(nVerticalPosition>=-1 && nVerticalPosition<=+1);
     129             : 
     130        1701 :     const sal_Int32 nS (1);
     131        1701 :     const sal_Int32 nC (::std::max<sal_Int32>(0,(rBitmap.GetSizePixel().Width()-nS)/2));
     132        1701 :     const sal_Int32 nO (nC/2);
     133             : 
     134             :     const Point aOrigin(
     135             :         nHorizontalPosition<0 ? 0 : (nHorizontalPosition == 0 ? nC : nC+nS),
     136        1701 :         nVerticalPosition<0 ? 0 : (nVerticalPosition == 0 ? nC : nC+nS));
     137             :     const Size aSize(
     138             :         nHorizontalPosition==0 ? nS : nC,
     139        1701 :         nVerticalPosition==0 ? nS : nC);
     140        1701 :     maBitmap = BitmapEx(rBitmap, aOrigin, aSize);
     141        1701 :     if (maBitmap.IsEmpty())
     142        1701 :         return;
     143             :     maOffset = Point(
     144             :         nHorizontalPosition<0 ? -nO : nHorizontalPosition>0 ? -nO : 0,
     145        1701 :         nVerticalPosition<0 ? -nO : nVerticalPosition>0 ? -nO : 0);
     146             : 
     147             :     // Enlarge the side bitmaps so that painting the frame requires less
     148             :     // paint calls.
     149        1701 :     const sal_Int32 nSideBitmapSize (64);
     150        1701 :     if (nHorizontalPosition == 0 && nVerticalPosition == 0)
     151             :     {
     152         189 :         maBitmap.Scale(Size(nSideBitmapSize,nSideBitmapSize));
     153             :     }
     154        1512 :     else if (nHorizontalPosition == 0)
     155             :     {
     156         378 :         maBitmap.Scale(Size(nSideBitmapSize,aSize.Height()));
     157             :     }
     158        1134 :     else if (nVerticalPosition == 0)
     159             :     {
     160         378 :         maBitmap.Scale(Size(maBitmap.GetSizePixel().Width(), nSideBitmapSize));
     161             :     }
     162             : }
     163             : 
     164             : 
     165             : 
     166             : 
     167         296 : void FramePainter::OffsetBitmap::PaintCorner (
     168             :     OutputDevice& rDevice,
     169             :     const Point& rAnchor) const
     170             : {
     171         296 :     if ( ! maBitmap.IsEmpty())
     172         296 :         rDevice.DrawBitmapEx(rAnchor+maOffset, maBitmap);
     173         296 : }
     174             : 
     175             : 
     176             : 
     177             : 
     178         296 : void FramePainter::OffsetBitmap::PaintSide (
     179             :     OutputDevice& rDevice,
     180             :     const Point& rAnchor1,
     181             :     const Point& rAnchor2,
     182             :     const OffsetBitmap& rCornerBitmap1,
     183             :     const OffsetBitmap& rCornerBitmap2) const
     184             : {
     185         296 :     if (maBitmap.IsEmpty())
     186         296 :         return;
     187             : 
     188         296 :     const Size aBitmapSize (maBitmap.GetSizePixel());
     189         296 :     if (rAnchor1.Y() == rAnchor2.Y())
     190             :     {
     191             :         // Side is horizontal.
     192         148 :         const sal_Int32 nY (rAnchor1.Y() + maOffset.Y());
     193             :         const sal_Int32 nLeft (
     194         148 :             rAnchor1.X()
     195         148 :             + rCornerBitmap1.maBitmap.GetSizePixel().Width()
     196         148 :             + rCornerBitmap1.maOffset.X());
     197             :         const sal_Int32 nRight (
     198         148 :             rAnchor2.X()
     199         148 :             + rCornerBitmap2.maOffset.X()\
     200         148 :             - 1);
     201         592 :         for (sal_Int32 nX=nLeft; nX<=nRight; nX+=aBitmapSize.Width())
     202             :         {
     203             :             rDevice.DrawBitmapEx(
     204             :                 Point(nX,nY),
     205         888 :                 Size(std::min(aBitmapSize.Width(),static_cast<long>(nRight-nX+1)),aBitmapSize.Height()),
     206         888 :                 maBitmap);
     207             :         }
     208             :     }
     209         148 :     else if (rAnchor1.X() == rAnchor2.X())
     210             :     {
     211             :         // Side is vertical.
     212         148 :         const sal_Int32 nX (rAnchor1.X() + maOffset.X());
     213             :         const sal_Int32 nTop (
     214         148 :             rAnchor1.Y()
     215         148 :             + rCornerBitmap1.maBitmap.GetSizePixel().Height()
     216         148 :             + rCornerBitmap1.maOffset.Y());
     217             :         const sal_Int32 nBottom (
     218         148 :             rAnchor2.Y()
     219         148 :             + rCornerBitmap2.maOffset.Y()
     220         148 :             - 1);
     221         672 :         for (sal_Int32 nY=nTop; nY<=nBottom; nY+=aBitmapSize.Height())
     222             :         {
     223             :             rDevice.DrawBitmapEx(
     224             :                 Point(nX,nY),
     225        1048 :                 Size(aBitmapSize.Width(), std::min(aBitmapSize.Height(), static_cast<long>(nBottom-nY+1))),
     226        1048 :                 maBitmap);
     227             :         }
     228             :     }
     229             :     else
     230             :     {
     231             :         // Diagonal sides indicatee an error.
     232             :         OSL_ASSERT(false);
     233             :     }
     234             : }
     235             : 
     236             : 
     237             : 
     238             : 
     239          74 : void FramePainter::OffsetBitmap::PaintCenter (
     240             :     OutputDevice& rDevice,
     241             :     const Rectangle& rBox) const
     242             : {
     243          74 :     const Size aBitmapSize (maBitmap.GetSizePixel());
     244         344 :     for (sal_Int32 nY=rBox.Top(); nY<=rBox.Bottom(); nY+=aBitmapSize.Height())
     245        1080 :         for (sal_Int32 nX=rBox.Left(); nX<=rBox.Right(); nX+=aBitmapSize.Width())
     246             :             rDevice.DrawBitmapEx(
     247             :                 Point(nX,nY),
     248             :                 Size(
     249        1620 :                     ::std::min(aBitmapSize.Width(), rBox.Right()-nX+1),
     250        1620 :                     std::min(aBitmapSize.Height(), rBox.Bottom()-nY+1)),
     251        2430 :                 maBitmap);
     252          74 : }
     253             : 
     254             : 
     255             : 
     256             : } } } // end of namespace sd::slidesorter::view
     257             : 
     258             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10