diff options
author | Chris Sherlock <chris.sherlock79@gmail.com> | 2014-04-07 17:54:42 +1000 |
---|---|---|
committer | Chris Sherlock <chris.sherlock79@gmail.com> | 2014-04-07 03:01:24 -0500 |
commit | 48d85514470e7b44b110157d39fd67855f0a794c (patch) | |
tree | 3f9723e0a8f3f7f4fdb9c2f26a376204d4b919d0 | |
parent | 3eac9b17198b3c94666869b18f9230be6f14c60c (diff) |
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@gmail.com>
Tested-by: Chris Sherlock <chris.sherlock79@gmail.com>
-rw-r--r-- | include/vcl/outdev.hxx | 3 | ||||
-rw-r--r-- | vcl/source/gdi/outdev4.cxx | 133 |
2 files changed, 61 insertions, 75 deletions
diff --git a/include/vcl/outdev.hxx b/include/vcl/outdev.hxx index 037d6d12746f..5c090822c525 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 b84b8b80504b..7e3ff3f42bee 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 ); |