LCOV - code coverage report
Current view: top level - sfx2/source/sidebar - DrawHelper.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 36 51 70.6 %
Date: 2015-06-13 12:38:46 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         274 : void DrawHelper::DrawBorder(vcl::RenderContext& rRenderContext, const Rectangle& rBox, const SvBorder& rBorderSize,
      28             :                             const Paint& rHorizontalPaint, const Paint& rVerticalPaint)
      29             : {
      30             :     // Draw top line.
      31         548 :     DrawHorizontalLine(rRenderContext, rBox.Left(), rBox.Right(),
      32         822 :                        rBox.Top(), rBorderSize.Top(), rHorizontalPaint);
      33             : 
      34             :     // Draw bottom line.
      35         822 :     DrawHorizontalLine(rRenderContext, rBox.Left() + rBorderSize.Left(), rBox.Right(),
      36         822 :                        rBox.Bottom() - rBorderSize.Bottom() + 1, rBorderSize.Bottom(),
      37        1644 :                        rHorizontalPaint);
      38             :     // Draw left line.
      39         822 :     DrawVerticalLine(rRenderContext, rBox.Top() + rBorderSize.Top(), rBox.Bottom(),
      40        1096 :                      rBox.Left(), rBorderSize.Left(), rVerticalPaint);
      41             :     // Draw right line.
      42        1096 :     DrawVerticalLine(rRenderContext, rBox.Top() + rBorderSize.Top(), rBox.Bottom() - rBorderSize.Bottom(),
      43        1370 :                      rBox.Right() - rBorderSize.Right() + 1, rBorderSize.Right(), rVerticalPaint);
      44         274 : }
      45             : 
      46         690 : void DrawHelper::DrawHorizontalLine(vcl::RenderContext& rRenderContext, const sal_Int32 nLeft, const sal_Int32 nRight,
      47             :                                     const sal_Int32 nY, const sal_Int32 nHeight, const Paint& rPaint)
      48             : {
      49         690 :     switch (rPaint.GetType())
      50             :     {
      51             :         case Paint::ColorPaint:
      52             :         {
      53         690 :             const Color aColor(rPaint.GetColor());
      54         690 :             rRenderContext.SetLineColor(aColor);
      55        1654 :             for (sal_Int32 nYOffset = 0; nYOffset < nHeight; ++nYOffset)
      56             :             {
      57         964 :                 rRenderContext.DrawLine(Point(nLeft, nY + nYOffset),
      58        1928 :                                         Point(nRight, nY + nYOffset));
      59             :             }
      60         690 :             break;
      61             :         }
      62             :         case Paint::GradientPaint:
      63           0 :             rRenderContext.DrawGradient(Rectangle(nLeft, nY, nRight, nY + nHeight - 1),
      64           0 :                                         rPaint.GetGradient());
      65           0 :             break;
      66             : 
      67             :         case Paint::NoPaint:
      68             :         default:
      69           0 :             break;
      70             :     }
      71         690 : }
      72             : 
      73         548 : void DrawHelper::DrawVerticalLine(vcl::RenderContext& rRenderContext, const sal_Int32 nTop, const sal_Int32 nBottom,
      74             :                                   const sal_Int32 nX, const sal_Int32 nWidth, const Paint& rPaint)
      75             : {
      76         548 :     switch (rPaint.GetType())
      77             :     {
      78             :         case Paint::ColorPaint:
      79             :         {
      80         548 :             const Color aColor(rPaint.GetColor());
      81         548 :             rRenderContext.SetLineColor(aColor);
      82        1370 :             for (sal_Int32 nXOffset = 0; nXOffset < nWidth; ++nXOffset)
      83             :             {
      84         822 :                 rRenderContext.DrawLine(Point(nX + nXOffset, nTop),
      85        1644 :                                         Point(nX + nXOffset, nBottom));
      86             :             }
      87         548 :             break;
      88             :         }
      89             :         case Paint::GradientPaint:
      90           0 :             rRenderContext.DrawGradient(Rectangle(nX, nTop, nX + nWidth - 1, nBottom),
      91           0 :                                         rPaint.GetGradient());
      92           0 :             break;
      93             : 
      94             :         case Paint::NoPaint:
      95             :         default:
      96           0 :             break;
      97             :     }
      98         548 : }
      99             : 
     100       10978 : void DrawHelper::DrawRoundedRectangle(vcl::RenderContext& rRenderContext, const Rectangle& rBox, const sal_Int32 nCornerRadius,
     101             :                                       const Color& rBorderColor, const Paint& rFillPaint)
     102             : {
     103       10978 :     rRenderContext.SetLineColor(rBorderColor);
     104       10978 :     switch (rFillPaint.GetType())
     105             :     {
     106             :         case Paint::ColorPaint:
     107           0 :             rRenderContext.SetFillColor(rFillPaint.GetColor());
     108           0 :             rRenderContext.DrawRect(rBox, nCornerRadius, nCornerRadius);
     109           0 :             break;
     110             : 
     111             :         case Paint::GradientPaint:
     112           0 :             rRenderContext.DrawGradient(rBox, rFillPaint.GetGradient());
     113           0 :             rRenderContext.SetFillColor();
     114           0 :             rRenderContext.DrawRect(rBox, nCornerRadius, nCornerRadius);
     115           0 :             break;
     116             : 
     117             :         case Paint::NoPaint:
     118             :         default:
     119       10978 :             rRenderContext.SetFillColor();
     120       10978 :             rRenderContext.DrawRect(rBox, nCornerRadius, nCornerRadius);
     121       10978 :             break;
     122             :     }
     123       10978 : }
     124             : 
     125             : } } // end of namespace sfx2::sidebar
     126             : 
     127             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11