[Libreoffice-commits] core.git: include/vcl vcl/source

Chris Sherlock chris.sherlock79 at gmail.com
Mon Apr 7 01:01:47 PDT 2014


 include/vcl/outdev.hxx     |    3 +
 vcl/source/gdi/outdev4.cxx |  133 +++++++++++++++++++--------------------------
 2 files changed, 61 insertions(+), 75 deletions(-)

New commits:
commit 48d85514470e7b44b110157d39fd67855f0a794c
Author: Chris Sherlock <chris.sherlock79 at gmail.com>
Date:   Mon Apr 7 17:54:42 2014 +1000

    Refactored OutputDevice::DrawGradient
    
    There are two version of OutputDevice::DrawGradient(). They both have
    common code, I have moved this into their own private functions to
    allow for code reuse.
    
    The first function checks to see if the drawing mode is
    DRAWMODE_BLACKGRADIENT, DRAWMODE_WHITEGRADIENT or
    DRAWMODE_SETTINGSGRADIENT (for Window background color) - this
    just sets the color to black (for XOR operations), white (mainly
    used for printing) or the background color of a Window (not sure
    what this is used for!).
    
    The second function sets grayscale start and end colors.
    
    Change-Id: Idaa85c3b5cfbd8a211fd7b0714eeb8e5b9e9e434
    Reviewed-on: https://gerrit.libreoffice.org/8880
    Reviewed-by: Chris Sherlock <chris.sherlock79 at gmail.com>
    Tested-by: Chris Sherlock <chris.sherlock79 at gmail.com>

diff --git a/include/vcl/outdev.hxx b/include/vcl/outdev.hxx
index 037d6d1..5c09082 100644
--- a/include/vcl/outdev.hxx
+++ b/include/vcl/outdev.hxx
@@ -866,6 +866,9 @@ private:
 
     bool                        DrawTransparentNatively( const PolyPolygon& rPolyPoly, sal_uInt16 nTransparencePercent );
 
+    Color                       GetSingleColorGradientFill();
+    void                        SetGrayscaleColors( Gradient &rGradient );
+
 public:
     virtual                     ~OutputDevice();
 
diff --git a/vcl/source/gdi/outdev4.cxx b/vcl/source/gdi/outdev4.cxx
index b84b8b8..7e3ff3f 100644
--- a/vcl/source/gdi/outdev4.cxx
+++ b/vcl/source/gdi/outdev4.cxx
@@ -549,6 +549,60 @@ void OutputDevice::ImplDrawComplexGradient( const Rectangle& rRect,
     }
 }
 
+Color OutputDevice::GetSingleColorGradientFill()
+{
+    Color aColor;
+
+    // we should never call on this function if any of these aren't set!
+    assert( mnDrawMode & ( DRAWMODE_BLACKGRADIENT | DRAWMODE_WHITEGRADIENT | DRAWMODE_SETTINGSGRADIENT) );
+
+    if ( mnDrawMode & DRAWMODE_BLACKGRADIENT )
+        aColor = Color( COL_BLACK );
+    else if ( mnDrawMode & DRAWMODE_WHITEGRADIENT )
+        aColor = Color( COL_WHITE );
+    else if ( mnDrawMode & DRAWMODE_SETTINGSGRADIENT )
+        aColor = GetSettings().GetStyleSettings().GetWindowColor();
+
+    if ( mnDrawMode & DRAWMODE_GHOSTEDGRADIENT )
+    {
+        aColor = Color( ( aColor.GetRed() >> 1 ) | 0x80,
+                        ( aColor.GetGreen() >> 1 ) | 0x80,
+                        ( aColor.GetBlue() >> 1 ) | 0x80 );
+    }
+
+    return aColor;
+}
+
+void OutputDevice::SetGrayscaleColors( Gradient &rGradient )
+{
+    // this should only be called with the drawing mode is for grayscale or ghosted gradients
+    assert ( mnDrawMode & ( DRAWMODE_GRAYGRADIENT | DRAWMODE_GHOSTEDGRADIENT ) );
+
+    Color aStartCol( rGradient.GetStartColor() );
+    Color aEndCol( rGradient.GetEndColor() );
+
+    if ( mnDrawMode & DRAWMODE_GRAYGRADIENT )
+    {
+        sal_uInt8 cStartLum = aStartCol.GetLuminance(), cEndLum = aEndCol.GetLuminance();
+        aStartCol = Color( cStartLum, cStartLum, cStartLum );
+        aEndCol = Color( cEndLum, cEndLum, cEndLum );
+    }
+
+    if ( mnDrawMode & DRAWMODE_GHOSTEDGRADIENT )
+    {
+        aStartCol = Color( ( aStartCol.GetRed() >> 1 ) | 0x80,
+                           ( aStartCol.GetGreen() >> 1 ) | 0x80,
+                           ( aStartCol.GetBlue() >> 1 ) | 0x80 );
+
+        aEndCol = Color( ( aEndCol.GetRed() >> 1 ) | 0x80,
+                         ( aEndCol.GetGreen() >> 1 ) | 0x80,
+                         ( aEndCol.GetBlue() >> 1 ) | 0x80 );
+    }
+
+    rGradient.SetStartColor( aStartCol );
+    rGradient.SetEndColor( aEndCol );
+}
+
 void OutputDevice::DrawGradient( const Rectangle& rRect,
                                  const Gradient& rGradient )
 {
@@ -559,21 +613,8 @@ void OutputDevice::DrawGradient( const Rectangle& rRect,
     }
     else if ( mnDrawMode & ( DRAWMODE_BLACKGRADIENT | DRAWMODE_WHITEGRADIENT | DRAWMODE_SETTINGSGRADIENT) )
     {
-        Color aColor;
-
-        if ( mnDrawMode & DRAWMODE_BLACKGRADIENT )
-            aColor = Color( COL_BLACK );
-        else if ( mnDrawMode & DRAWMODE_WHITEGRADIENT )
-            aColor = Color( COL_WHITE );
-        else if ( mnDrawMode & DRAWMODE_SETTINGSGRADIENT )
-            aColor = GetSettings().GetStyleSettings().GetWindowColor();
 
-        if ( mnDrawMode & DRAWMODE_GHOSTEDGRADIENT )
-        {
-            aColor = Color( ( aColor.GetRed() >> 1 ) | 0x80,
-                            ( aColor.GetGreen() >> 1 ) | 0x80,
-                            ( aColor.GetBlue() >> 1 ) | 0x80 );
-        }
+        Color aColor = GetSingleColorGradientFill();
 
         Push( PUSH_LINECOLOR | PUSH_FILLCOLOR );
         SetLineColor( aColor );
@@ -587,29 +628,7 @@ void OutputDevice::DrawGradient( const Rectangle& rRect,
 
     if ( mnDrawMode & ( DRAWMODE_GRAYGRADIENT | DRAWMODE_GHOSTEDGRADIENT ) )
     {
-        Color aStartCol( aGradient.GetStartColor() );
-        Color aEndCol( aGradient.GetEndColor() );
-
-        if ( mnDrawMode & DRAWMODE_GRAYGRADIENT )
-        {
-            sal_uInt8 cStartLum = aStartCol.GetLuminance(), cEndLum = aEndCol.GetLuminance();
-            aStartCol = Color( cStartLum, cStartLum, cStartLum );
-            aEndCol = Color( cEndLum, cEndLum, cEndLum );
-        }
-
-        if ( mnDrawMode & DRAWMODE_GHOSTEDGRADIENT )
-        {
-            aStartCol = Color( ( aStartCol.GetRed() >> 1 ) | 0x80,
-                               ( aStartCol.GetGreen() >> 1 ) | 0x80,
-                               ( aStartCol.GetBlue() >> 1 ) | 0x80 );
-
-            aEndCol = Color( ( aEndCol.GetRed() >> 1 ) | 0x80,
-                             ( aEndCol.GetGreen() >> 1 ) | 0x80,
-                             ( aEndCol.GetBlue() >> 1 ) | 0x80 );
-        }
-
-        aGradient.SetStartColor( aStartCol );
-        aGradient.SetEndColor( aEndCol );
+        SetGrayscaleColors( aGradient );
     }
 
     if( mpMetaFile )
@@ -816,21 +835,7 @@ void OutputDevice::DrawGradient( const PolyPolygon& rPolyPoly,
     {
         if ( mnDrawMode & ( DRAWMODE_BLACKGRADIENT | DRAWMODE_WHITEGRADIENT | DRAWMODE_SETTINGSGRADIENT) )
         {
-            Color aColor;
-
-            if ( mnDrawMode & DRAWMODE_BLACKGRADIENT )
-                aColor = Color( COL_BLACK );
-            else if ( mnDrawMode & DRAWMODE_WHITEGRADIENT )
-                aColor = Color( COL_WHITE );
-            else if ( mnDrawMode & DRAWMODE_SETTINGSGRADIENT )
-                aColor = GetSettings().GetStyleSettings().GetWindowColor();
-
-            if ( mnDrawMode & DRAWMODE_GHOSTEDGRADIENT )
-            {
-                aColor = Color( ( aColor.GetRed() >> 1 ) | 0x80,
-                                ( aColor.GetGreen() >> 1 ) | 0x80,
-                                ( aColor.GetBlue() >> 1 ) | 0x80 );
-            }
+            Color aColor = GetSingleColorGradientFill();
 
             Push( PUSH_LINECOLOR | PUSH_FILLCOLOR );
             SetLineColor( aColor );
@@ -859,29 +864,7 @@ void OutputDevice::DrawGradient( const PolyPolygon& rPolyPoly,
 
         if ( mnDrawMode & ( DRAWMODE_GRAYGRADIENT | DRAWMODE_GHOSTEDGRADIENT ) )
         {
-            Color aStartCol( aGradient.GetStartColor() );
-            Color aEndCol( aGradient.GetEndColor() );
-
-            if ( mnDrawMode & DRAWMODE_GRAYGRADIENT )
-            {
-                sal_uInt8 cStartLum = aStartCol.GetLuminance(), cEndLum = aEndCol.GetLuminance();
-                aStartCol = Color( cStartLum, cStartLum, cStartLum );
-                aEndCol = Color( cEndLum, cEndLum, cEndLum );
-            }
-
-            if ( mnDrawMode & DRAWMODE_GHOSTEDGRADIENT )
-            {
-                aStartCol = Color( ( aStartCol.GetRed() >> 1 ) | 0x80,
-                                   ( aStartCol.GetGreen() >> 1 ) | 0x80,
-                                   ( aStartCol.GetBlue() >> 1 ) | 0x80 );
-
-                aEndCol = Color( ( aEndCol.GetRed() >> 1 ) | 0x80,
-                                 ( aEndCol.GetGreen() >> 1 ) | 0x80,
-                                 ( aEndCol.GetBlue() >> 1 ) | 0x80 );
-            }
-
-            aGradient.SetStartColor( aStartCol );
-            aGradient.SetEndColor( aEndCol );
+            SetGrayscaleColors( aGradient );
         }
 
         ClipAndDrawGradientToBounds ( aGradient, rPolyPoly );


More information about the Libreoffice-commits mailing list