LCOV - code coverage report
Current view: top level - sfx2/source/sidebar - DrawHelper.cxx (source / functions) Hit Total Coverage
Test: commit 0e63ca4fde4e446f346e35849c756a30ca294aab Lines: 35 50 70.0 %
Date: 2014-04-11 Functions: 4 4 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 "DrawHelper.hxx"
      21             : #include "Paint.hxx"
      22             : 
      23             : #include <vcl/lineinfo.hxx>
      24             : 
      25             : namespace sfx2 { namespace sidebar {
      26             : 
      27          42 : void DrawHelper::DrawBorder (
      28             :     OutputDevice& rDevice,
      29             :     const Rectangle rBox,
      30             :     const SvBorder aBorderSize,
      31             :     const Paint& rHorizontalPaint,
      32             :     const Paint& rVerticalPaint)
      33             : {
      34             :     // Draw top line.
      35             :     DrawHorizontalLine(
      36             :         rDevice,
      37             :         rBox.Left(),
      38             :         rBox.Right(),
      39             :         rBox.Top(),
      40             :         aBorderSize.Top(),
      41          42 :         rHorizontalPaint);
      42             :     // Draw bottom line.
      43             :     DrawHorizontalLine(
      44             :         rDevice,
      45          42 :         rBox.Left()+aBorderSize.Left(),
      46             :         rBox.Right(),
      47          42 :         rBox.Bottom()-aBorderSize.Bottom()+1,
      48             :         aBorderSize.Bottom(),
      49         126 :         rHorizontalPaint);
      50             :     // Draw left line.
      51             :     DrawVerticalLine(
      52             :         rDevice,
      53          42 :         rBox.Top()+aBorderSize.Top(),
      54             :         rBox.Bottom(),
      55             :         rBox.Left(),
      56             :         aBorderSize.Left(),
      57          84 :         rVerticalPaint);
      58             :     // Draw right line.
      59             :     DrawVerticalLine(
      60             :         rDevice,
      61          42 :         rBox.Top()+aBorderSize.Top(),
      62          42 :         rBox.Bottom()-aBorderSize.Bottom(),
      63          42 :         rBox.Right()-aBorderSize.Right()+1,
      64             :         aBorderSize.Right(),
      65         168 :         rVerticalPaint);
      66          42 : }
      67             : 
      68         105 : void DrawHelper::DrawHorizontalLine(
      69             :     OutputDevice& rDevice,
      70             :     const sal_Int32 nLeft,
      71             :     const sal_Int32 nRight,
      72             :     const sal_Int32 nY,
      73             :     const sal_Int32 nHeight,
      74             :     const Paint& rPaint)
      75             : {
      76         105 :     switch (rPaint.GetType())
      77             :     {
      78             :         case Paint::NoPaint:
      79             :         default:
      80           0 :             break;
      81             : 
      82             :         case Paint::ColorPaint:
      83             :         {
      84         105 :             const Color aColor (rPaint.GetColor());
      85         105 :             rDevice.SetLineColor(aColor);
      86         252 :             for (sal_Int32 nYOffset=0; nYOffset<nHeight; ++nYOffset)
      87             :                 rDevice.DrawLine(
      88             :                     Point(nLeft,nY+nYOffset),
      89         147 :                     Point(nRight,nY+nYOffset));
      90         105 :             break;
      91             :         }
      92             :         case Paint::GradientPaint:
      93             :             rDevice.DrawGradient(
      94             :                 Rectangle(
      95             :                     nLeft,
      96             :                     nY,
      97             :                     nRight,
      98           0 :                     nY+nHeight-1),
      99           0 :                 rPaint.GetGradient());
     100           0 :             break;
     101             :     }
     102         105 : }
     103             : 
     104          84 : void DrawHelper::DrawVerticalLine(
     105             :     OutputDevice& rDevice,
     106             :     const sal_Int32 nTop,
     107             :     const sal_Int32 nBottom,
     108             :     const sal_Int32 nX,
     109             :     const sal_Int32 nWidth,
     110             :     const Paint& rPaint)
     111             : {
     112          84 :     switch (rPaint.GetType())
     113             :     {
     114             :         case Paint::NoPaint:
     115             :         default:
     116           0 :             break;
     117             : 
     118             :         case Paint::ColorPaint:
     119             :         {
     120          84 :             const Color aColor (rPaint.GetColor());
     121          84 :             rDevice.SetLineColor(aColor);
     122         210 :             for (sal_Int32 nXOffset=0; nXOffset<nWidth; ++nXOffset)
     123             :                 rDevice.DrawLine(
     124             :                     Point(nX+nXOffset, nTop),
     125         126 :                     Point(nX+nXOffset, nBottom));
     126          84 :             break;
     127             :         }
     128             :         case Paint::GradientPaint:
     129             :             rDevice.DrawGradient(
     130             :                 Rectangle(
     131             :                     nX,
     132             :                     nTop,
     133           0 :                     nX+nWidth-1,
     134             :                     nBottom),
     135           0 :                 rPaint.GetGradient());
     136           0 :             break;
     137             :     }
     138          84 : }
     139             : 
     140         128 : void DrawHelper::DrawRoundedRectangle (
     141             :     OutputDevice& rDevice,
     142             :     const Rectangle& rBox,
     143             :     const sal_Int32 nCornerRadius,
     144             :     const Color& rBorderColor,
     145             :     const Paint& rFillPaint)
     146             : {
     147         128 :     rDevice.SetLineColor(rBorderColor);
     148         128 :     switch(rFillPaint.GetType())
     149             :     {
     150             :         case Paint::NoPaint:
     151             :         default:
     152         128 :             rDevice.SetFillColor();
     153         128 :             rDevice.DrawRect(rBox, nCornerRadius, nCornerRadius);
     154         128 :             break;
     155             : 
     156             :         case Paint::ColorPaint:
     157           0 :             rDevice.SetFillColor(rFillPaint.GetColor());
     158           0 :             rDevice.DrawRect(rBox, nCornerRadius, nCornerRadius);
     159           0 :             break;
     160             : 
     161             :         case Paint::GradientPaint:
     162             :             rDevice.DrawGradient(
     163             :                 rBox,
     164           0 :                 rFillPaint.GetGradient());
     165           0 :             rDevice.SetFillColor();
     166           0 :             rDevice.DrawRect(rBox, nCornerRadius, nCornerRadius);
     167           0 :             break;
     168             :     }
     169         128 : }
     170             : 
     171             : } } // end of namespace sfx2::sidebar
     172             : 
     173             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10