LCOV - code coverage report
Current view: top level - solver/unxlngi6.pro/inc/basegfx/color - bcolormodifier.hxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 21 27 77.8 %
Date: 2012-08-25 Functions: 12 17 70.6 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 9 20 45.0 %

           Branch data     Line data    Source code
       1                 :            : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2                 :            : /*************************************************************************
       3                 :            :  *
       4                 :            :  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
       5                 :            :  *
       6                 :            :  * Copyright 2000, 2010 Oracle and/or its affiliates.
       7                 :            :  *
       8                 :            :  * OpenOffice.org - a multi-platform office productivity suite
       9                 :            :  *
      10                 :            :  * This file is part of OpenOffice.org.
      11                 :            :  *
      12                 :            :  * OpenOffice.org is free software: you can redistribute it and/or modify
      13                 :            :  * it under the terms of the GNU Lesser General Public License version 3
      14                 :            :  * only, as published by the Free Software Foundation.
      15                 :            :  *
      16                 :            :  * OpenOffice.org is distributed in the hope that it will be useful,
      17                 :            :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
      18                 :            :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      19                 :            :  * GNU Lesser General Public License version 3 for more details
      20                 :            :  * (a copy is included in the LICENSE file that accompanied this code).
      21                 :            :  *
      22                 :            :  * You should have received a copy of the GNU Lesser General Public License
      23                 :            :  * version 3 along with OpenOffice.org.  If not, see
      24                 :            :  * <http://www.openoffice.org/license.html>
      25                 :            :  * for a copy of the LGPLv3 License.
      26                 :            :  *
      27                 :            :  ************************************************************************/
      28                 :            : 
      29                 :            : #ifndef _BGFX_COLOR_BCOLORMODIFIER_HXX
      30                 :            : #define _BGFX_COLOR_BCOLORMODIFIER_HXX
      31                 :            : 
      32                 :            : #include <basegfx/color/bcolor.hxx>
      33                 :            : #include <vector>
      34                 :            : #include <basegfx/basegfxdllapi.h>
      35                 :            : 
      36                 :            : //////////////////////////////////////////////////////////////////////////////
      37                 :            : 
      38                 :            : namespace basegfx
      39                 :            : {
      40                 :            :     /** Descriptor for type of color modification
      41                 :            :     */
      42                 :            :     enum BColorModifyMode
      43                 :            :     {
      44                 :            :         BCOLORMODIFYMODE_REPLACE,       // replace all color with local color
      45                 :            :         BCOLORMODIFYMODE_INTERPOLATE,   // interpolate color between given and local with local value
      46                 :            :         BCOLORMODIFYMODE_GRAY,          // convert color to gray
      47                 :            :         BCOLORMODIFYMODE_BLACKANDWHITE  // convert color to B&W, local value is treshhold
      48                 :            :     };
      49                 :            : 
      50                 :            :     /** Class to hold a color, value and mode for a color modification. Color modification is
      51                 :            :         done calling the getModifiedColor() method
      52                 :            :     */
      53                 :       3558 :     class BASEGFX_DLLPUBLIC BColorModifier
      54                 :            :     {
      55                 :            :     protected:
      56                 :            :         ::basegfx::BColor                           maBColor;
      57                 :            :         double                                      mfValue;
      58                 :            :         BColorModifyMode                            meMode;
      59                 :            : 
      60                 :            :     public:
      61                 :        680 :         BColorModifier(
      62                 :            :             const ::basegfx::BColor& rBColor,
      63                 :            :             double fValue = 0.5,
      64                 :            :             BColorModifyMode eMode = BCOLORMODIFYMODE_REPLACE)
      65                 :            :         :   maBColor(rBColor),
      66                 :            :             mfValue(fValue),
      67                 :        680 :             meMode(eMode)
      68                 :        680 :         {}
      69                 :            : 
      70                 :            :         // compare operator(s)
      71                 :          0 :         bool operator==(const BColorModifier& rCompare) const
      72                 :            :         {
      73 [ #  # ][ #  # ]:          0 :             return (maBColor == rCompare.maBColor && mfValue == rCompare.mfValue && meMode == rCompare.meMode);
                 [ #  # ]
      74                 :            :         }
      75                 :            : 
      76                 :            :         bool operator!=(const BColorModifier& rCompare) const
      77                 :            :         {
      78                 :            :             return !(operator==(rCompare));
      79                 :            :         }
      80                 :            : 
      81                 :            :         // data access
      82                 :          0 :         const ::basegfx::BColor& getBColor() const { return maBColor; }
      83                 :            :         double getValue() const { return mfValue; }
      84                 :          0 :         BColorModifyMode getMode() const { return meMode; }
      85                 :            : 
      86                 :            :         // compute modified color
      87                 :            :         ::basegfx::BColor getModifiedColor(const ::basegfx::BColor& aSourceColor) const;
      88                 :            :     };
      89                 :            : 
      90                 :            :     /** Class to hold a stack of BColorModifiers and to get the modified color with
      91                 :            :         applying all existing entry changes
      92                 :            :     */
      93                 :     103266 :     class BASEGFX_DLLPUBLIC BColorModifierStack
      94                 :            :     {
      95                 :            :     protected:
      96                 :            :         ::std::vector< BColorModifier >             maBColorModifiers;
      97                 :            : 
      98                 :            :     public:
      99                 :     518228 :         sal_uInt32 count() const
     100                 :            :         {
     101                 :     518228 :             return maBColorModifiers.size();
     102                 :            :         }
     103                 :            : 
     104                 :          0 :         const BColorModifier& getBColorModifier(sal_uInt32 nIndex) const
     105                 :            :         {
     106                 :            :             OSL_ENSURE(nIndex < count(), "BColorModifierStack: Access out of range (!)");
     107                 :          0 :             return maBColorModifiers[nIndex];
     108                 :            :         }
     109                 :            : 
     110                 :     448515 :         ::basegfx::BColor getModifiedColor(const ::basegfx::BColor& rSource) const
     111                 :            :         {
     112         [ +  + ]:     448515 :             if(count())
     113                 :            :             {
     114                 :      17647 :                 ::basegfx::BColor aRetval(rSource);
     115                 :      17647 :                 ::std::vector< BColorModifier >::const_iterator aEnd(maBColorModifiers.end());
     116                 :            : 
     117 [ +  - ][ +  + ]:      35505 :                 while(aEnd != maBColorModifiers.begin())
     118                 :            :                 {
     119 [ +  - ][ +  - ]:      17858 :                     aRetval = (--aEnd)->getModifiedColor(aRetval);
         [ +  - ][ +  - ]
     120                 :            :                 }
     121                 :            : 
     122                 :      17647 :                 return aRetval;
     123                 :            :             }
     124                 :            :             else
     125                 :            :             {
     126                 :     448515 :                 return rSource;
     127                 :            :             }
     128                 :            :         }
     129                 :            : 
     130                 :        726 :         void push(const BColorModifier& rNew)
     131                 :            :         {
     132                 :        726 :             maBColorModifiers.push_back(rNew);
     133                 :        726 :         }
     134                 :            : 
     135                 :        726 :         void pop()
     136                 :            :         {
     137                 :        726 :             maBColorModifiers.pop_back();
     138                 :        726 :         }
     139                 :            :     };
     140                 :            : } // end of namespace basegfx
     141                 :            : 
     142                 :            : #endif // _BGFX_COLOR_BCOLORMODIFIER_HXX
     143                 :            : 
     144                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10