LCOV - code coverage report
Current view: top level - sd/source/ui/slidesorter/view - SlsFramePainter.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 95 97 97.9 %
Date: 2015-06-13 12:38:46 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             : #include "SlsFramePainter.hxx"
      21             : #include <vcl/outdev.hxx>
      22             : #include <vcl/bmpacc.hxx>
      23             : 
      24             : namespace sd { namespace slidesorter { namespace view {
      25             : 
      26         192 : FramePainter::FramePainter (const BitmapEx& rShadowBitmap)
      27             :     : maTopLeft(rShadowBitmap,-1,-1),
      28             :       maTop(rShadowBitmap,0,-1),
      29             :       maTopRight(rShadowBitmap,+1,-1),
      30             :       maLeft(rShadowBitmap,-1,0),
      31             :       maRight(rShadowBitmap,+1,0),
      32             :       maBottomLeft(rShadowBitmap,-1,+1),
      33             :       maBottom(rShadowBitmap,0,+1),
      34             :       maBottomRight(rShadowBitmap,+1,+1),
      35             :       maCenter(rShadowBitmap,0,0),
      36         192 :       mbIsValid(false)
      37             : {
      38         384 :     if (rShadowBitmap.GetSizePixel().Width() == rShadowBitmap.GetSizePixel().Height()
      39         192 :         && (rShadowBitmap.GetSizePixel().Width()-1)%2 == 0
      40         384 :         && ((rShadowBitmap.GetSizePixel().Width()-1)/2)%2 == 1)
      41             :     {
      42         192 :         mbIsValid = true;
      43             :     }
      44             :     else
      45             :     {
      46             :         OSL_ASSERT(rShadowBitmap.GetSizePixel().Width() == rShadowBitmap.GetSizePixel().Height());
      47             :         OSL_ASSERT((rShadowBitmap.GetSizePixel().Width()-1)%2 == 0);
      48             :         OSL_ASSERT(((rShadowBitmap.GetSizePixel().Width()-1)/2)%2 == 1);
      49             :     }
      50         192 : }
      51             : 
      52         192 : FramePainter::~FramePainter()
      53             : {
      54         192 : }
      55             : 
      56         320 : void FramePainter::PaintFrame (
      57             :     OutputDevice& rDevice,
      58             :     const Rectangle& rBox) const
      59             : {
      60         320 :     if ( ! mbIsValid)
      61         320 :         return;
      62             : 
      63             :     // Paint the shadow.
      64         320 :     maTopLeft.PaintCorner(rDevice, rBox.TopLeft());
      65         320 :     maTopRight.PaintCorner(rDevice, rBox.TopRight());
      66         320 :     maBottomLeft.PaintCorner(rDevice, rBox.BottomLeft());
      67         320 :     maBottomRight.PaintCorner(rDevice, rBox.BottomRight());
      68         320 :     maLeft.PaintSide(rDevice, rBox.TopLeft(), rBox.BottomLeft(), maTopLeft, maBottomLeft);
      69         320 :     maRight.PaintSide(rDevice, rBox.TopRight(), rBox.BottomRight(), maTopRight, maBottomRight);
      70         320 :     maTop.PaintSide(rDevice, rBox.TopLeft(), rBox.TopRight(), maTopLeft, maTopRight);
      71         320 :     maBottom.PaintSide(rDevice, rBox.BottomLeft(), rBox.BottomRight(), maBottomLeft, maBottomRight);
      72         320 :     maCenter.PaintCenter(rDevice,rBox);
      73             : }
      74             : 
      75          64 : void FramePainter::AdaptColor (
      76             :     const Color aNewColor,
      77             :     const bool bEraseCenter)
      78             : {
      79             :     // Get the source color.
      80          64 :     if (maCenter.maBitmap.IsEmpty())
      81           0 :         return;
      82          64 :     BitmapReadAccess* pReadAccess = maCenter.maBitmap.GetBitmap().AcquireReadAccess();
      83          64 :     if (pReadAccess == NULL)
      84           0 :         return;
      85          64 :     const Color aSourceColor = pReadAccess->GetColor(0,0);
      86          64 :     Bitmap::ReleaseAccess(pReadAccess);
      87             : 
      88             :     // Erase the center bitmap.
      89          64 :     if (bEraseCenter)
      90          64 :         maCenter.maBitmap.SetEmpty();
      91             : 
      92             :     // Replace the color in all bitmaps.
      93          64 :     maTopLeft.maBitmap.Replace(aSourceColor, aNewColor, 0);
      94          64 :     maTop.maBitmap.Replace(aSourceColor, aNewColor, 0);
      95          64 :     maTopRight.maBitmap.Replace(aSourceColor, aNewColor, 0);
      96          64 :     maLeft.maBitmap.Replace(aSourceColor, aNewColor, 0);
      97          64 :     maCenter.maBitmap.Replace(aSourceColor, aNewColor, 0);
      98          64 :     maRight.maBitmap.Replace(aSourceColor, aNewColor, 0);
      99          64 :     maBottomLeft.maBitmap.Replace(aSourceColor, aNewColor, 0);
     100          64 :     maBottom.maBitmap.Replace(aSourceColor, aNewColor, 0);
     101          64 :     maBottomRight.maBitmap.Replace(aSourceColor, aNewColor, 0);
     102             : }
     103             : 
     104             : //===== FramePainter::OffsetBitmap ============================================
     105             : 
     106        1728 : FramePainter::OffsetBitmap::OffsetBitmap (
     107             :     const BitmapEx& rBitmap,
     108             :     const sal_Int32 nHorizontalPosition,
     109             :     const sal_Int32 nVerticalPosition)
     110             :     : maBitmap(),
     111        1728 :       maOffset()
     112             : {
     113             :     OSL_ASSERT(nHorizontalPosition>=-1 && nHorizontalPosition<=+1);
     114             :     OSL_ASSERT(nVerticalPosition>=-1 && nVerticalPosition<=+1);
     115             : 
     116        1728 :     const sal_Int32 nS (1);
     117        1728 :     const sal_Int32 nC (::std::max<sal_Int32>(0,(rBitmap.GetSizePixel().Width()-nS)/2));
     118        1728 :     const sal_Int32 nO (nC/2);
     119             : 
     120             :     const Point aOrigin(
     121         576 :         nHorizontalPosition<0 ? 0 : (nHorizontalPosition == 0 ? nC : nC+nS),
     122        2304 :         nVerticalPosition<0 ? 0 : (nVerticalPosition == 0 ? nC : nC+nS));
     123             :     const Size aSize(
     124             :         nHorizontalPosition==0 ? nS : nC,
     125        1728 :         nVerticalPosition==0 ? nS : nC);
     126        1728 :     maBitmap = BitmapEx(rBitmap, aOrigin, aSize);
     127        1728 :     if (maBitmap.IsEmpty())
     128        1728 :         return;
     129             :     maOffset = Point(
     130             :         nHorizontalPosition<0 ? -nO : nHorizontalPosition>0 ? -nO : 0,
     131        1728 :         nVerticalPosition<0 ? -nO : nVerticalPosition>0 ? -nO : 0);
     132             : 
     133             :     // Enlarge the side bitmaps so that painting the frame requires less
     134             :     // paint calls.
     135        1728 :     const sal_Int32 nSideBitmapSize (64);
     136        1728 :     if (nHorizontalPosition == 0 && nVerticalPosition == 0)
     137             :     {
     138         192 :         maBitmap.Scale(Size(nSideBitmapSize,nSideBitmapSize));
     139             :     }
     140        1536 :     else if (nHorizontalPosition == 0)
     141             :     {
     142         384 :         maBitmap.Scale(Size(nSideBitmapSize,aSize.Height()));
     143             :     }
     144        1152 :     else if (nVerticalPosition == 0)
     145             :     {
     146         384 :         maBitmap.Scale(Size(maBitmap.GetSizePixel().Width(), nSideBitmapSize));
     147             :     }
     148             : }
     149             : 
     150        1280 : void FramePainter::OffsetBitmap::PaintCorner (
     151             :     OutputDevice& rDevice,
     152             :     const Point& rAnchor) const
     153             : {
     154        1280 :     if ( ! maBitmap.IsEmpty())
     155        1280 :         rDevice.DrawBitmapEx(rAnchor+maOffset, maBitmap);
     156        1280 : }
     157             : 
     158        1280 : void FramePainter::OffsetBitmap::PaintSide (
     159             :     OutputDevice& rDevice,
     160             :     const Point& rAnchor1,
     161             :     const Point& rAnchor2,
     162             :     const OffsetBitmap& rCornerBitmap1,
     163             :     const OffsetBitmap& rCornerBitmap2) const
     164             : {
     165        1280 :     if (maBitmap.IsEmpty())
     166        1280 :         return;
     167             : 
     168        1280 :     const Size aBitmapSize (maBitmap.GetSizePixel());
     169        1280 :     if (rAnchor1.Y() == rAnchor2.Y())
     170             :     {
     171             :         // Side is horizontal.
     172         640 :         const sal_Int32 nY (rAnchor1.Y() + maOffset.Y());
     173             :         const sal_Int32 nLeft (
     174         640 :             rAnchor1.X()
     175         640 :             + rCornerBitmap1.maBitmap.GetSizePixel().Width()
     176        1280 :             + rCornerBitmap1.maOffset.X());
     177             :         const sal_Int32 nRight (
     178         640 :             rAnchor2.X()
     179         640 :             + rCornerBitmap2.maOffset.X()\
     180        1280 :             - 1);
     181        1920 :         for (sal_Int32 nX=nLeft; nX<=nRight; nX+=aBitmapSize.Width())
     182             :         {
     183             :             rDevice.DrawBitmapEx(
     184             :                 Point(nX,nY),
     185        2560 :                 Size(std::min(aBitmapSize.Width(),static_cast<long>(nRight-nX+1)),aBitmapSize.Height()),
     186        2560 :                 maBitmap);
     187             :         }
     188             :     }
     189         640 :     else if (rAnchor1.X() == rAnchor2.X())
     190             :     {
     191             :         // Side is vertical.
     192         640 :         const sal_Int32 nX (rAnchor1.X() + maOffset.X());
     193             :         const sal_Int32 nTop (
     194         640 :             rAnchor1.Y()
     195         640 :             + rCornerBitmap1.maBitmap.GetSizePixel().Height()
     196        1280 :             + rCornerBitmap1.maOffset.Y());
     197             :         const sal_Int32 nBottom (
     198         640 :             rAnchor2.Y()
     199         640 :             + rCornerBitmap2.maOffset.Y()
     200        1280 :             - 1);
     201        2452 :         for (sal_Int32 nY=nTop; nY<=nBottom; nY+=aBitmapSize.Height())
     202             :         {
     203             :             rDevice.DrawBitmapEx(
     204             :                 Point(nX,nY),
     205        3624 :                 Size(aBitmapSize.Width(), std::min(aBitmapSize.Height(), static_cast<long>(nBottom-nY+1))),
     206        3624 :                 maBitmap);
     207             :         }
     208             :     }
     209             :     else
     210             :     {
     211             :         // Diagonal sides indicatee an error.
     212             :         OSL_ASSERT(false);
     213             :     }
     214             : }
     215             : 
     216         320 : void FramePainter::OffsetBitmap::PaintCenter (
     217             :     OutputDevice& rDevice,
     218             :     const Rectangle& rBox) const
     219             : {
     220         320 :     const Size aBitmapSize (maBitmap.GetSizePixel());
     221        1226 :     for (long nY=rBox.Top(); nY<=rBox.Bottom(); nY+=aBitmapSize.Height())
     222        2718 :         for (long nX=rBox.Left(); nX<=rBox.Right(); nX+=aBitmapSize.Width())
     223             :             rDevice.DrawBitmapEx(
     224             :                 Point(nX,nY),
     225             :                 Size(
     226        3624 :                     ::std::min(aBitmapSize.Width(), rBox.Right()-nX+1),
     227        3624 :                     std::min(aBitmapSize.Height(), rBox.Bottom()-nY+1)),
     228        5436 :                 maBitmap);
     229         320 : }
     230             : 
     231             : } } } // end of namespace sd::slidesorter::view
     232             : 
     233             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11