diff options
author | Takeshi Kurosawa <taken.spc@gmail.com> | 2011-02-01 14:40:58 +0900 |
---|---|---|
committer | Thorsten Behrens <tbehrens@novell.com> | 2011-02-08 11:29:47 +0100 |
commit | 5e5abcdd6fcc2d87160baddc83c8c324ed211450 (patch) | |
tree | bed8e5acdfb6047bae5aec0b63475a97bf0c3cad /vcl/source | |
parent | 5c7c8cd6ef60a77cdc37816734383229fbea75fc (diff) |
Encapsulate calculation of gradient bounding box to Gradient::GetBoundRect
Export filters need to get gradient bounding box.
Signed-off-by: Thorsten Behrens <tbehrens@novell.com>
Diffstat (limited to 'vcl/source')
-rw-r--r-- | vcl/source/gdi/gradient.cxx | 93 | ||||
-rw-r--r-- | vcl/source/gdi/outdev4.cxx | 91 |
2 files changed, 104 insertions, 80 deletions
diff --git a/vcl/source/gdi/gradient.cxx b/vcl/source/gdi/gradient.cxx index 80572a1b9457..9c0d8ee07043 100644 --- a/vcl/source/gdi/gradient.cxx +++ b/vcl/source/gdi/gradient.cxx @@ -245,6 +245,99 @@ void Gradient::SetSteps( USHORT nSteps ) // ----------------------------------------------------------------------- +void Gradient::GetBoundRect( const Rectangle& rRect, Rectangle& rBoundRect, Point& rCenter ) const +{ + Rectangle aRect( rRect ); + USHORT nAngle = GetAngle() % 3600; + + if( GetStyle() == GRADIENT_LINEAR || GetStyle() == GRADIENT_AXIAL ) + { + aRect.Left()--; + aRect.Top()--; + aRect.Right()++; + aRect.Bottom()++; + + const double fAngle = nAngle * F_PI1800; + const double fWidth = aRect.GetWidth(); + const double fHeight = aRect.GetHeight(); + double fDX = fWidth * fabs( cos( fAngle ) ) + fHeight * fabs( sin( fAngle ) ); + double fDY = fHeight * fabs( cos( fAngle ) ) + fWidth * fabs( sin( fAngle ) ); + + fDX = ( fDX - fWidth ) * 0.5 + 0.5; + fDY = ( fDY - fHeight ) * 0.5 + 0.5; + + aRect.Left() -= (long) fDX; + aRect.Right() += (long) fDX; + aRect.Top() -= (long) fDY; + aRect.Bottom() += (long) fDY; + + rBoundRect = aRect; + rCenter = rRect.Center(); + } + else + { + + if( GetStyle() == GRADIENT_SQUARE || GetStyle() == GRADIENT_RECT ) + { + const double fAngle = nAngle * F_PI1800; + const double fWidth = aRect.GetWidth(); + const double fHeight = aRect.GetHeight(); + double fDX = fWidth * fabs( cos( fAngle ) ) + fHeight * fabs( sin( fAngle ) ); + double fDY = fHeight * fabs( cos( fAngle ) ) + fWidth * fabs( sin( fAngle ) ); + + fDX = ( fDX - fWidth ) * 0.5 + 0.5; + fDY = ( fDY - fHeight ) * 0.5 + 0.5; + + aRect.Left() -= (long) fDX; + aRect.Right() += (long) fDX; + aRect.Top() -= (long) fDY; + aRect.Bottom() += (long) fDY; + } + + Size aSize( aRect.GetSize() ); + + if( GetStyle() == GRADIENT_RADIAL ) + { + // Radien-Berechnung fuer Kreis + aSize.Width() = (long)(0.5 + sqrt((double)aSize.Width()*(double)aSize.Width() + (double)aSize.Height()*(double)aSize.Height())); + aSize.Height() = aSize.Width(); + } + else if( GetStyle() == GRADIENT_ELLIPTICAL ) + { + // Radien-Berechnung fuer Ellipse + aSize.Width() = (long)( 0.5 + (double) aSize.Width() * 1.4142 ); + aSize.Height() = (long)( 0.5 + (double) aSize.Height() * 1.4142 ); + } + else if( GetStyle() == GRADIENT_SQUARE ) + { + if ( aSize.Width() > aSize.Height() ) + aSize.Height() = aSize.Width(); + else + aSize.Width() = aSize.Height(); + } + + // neue Mittelpunkte berechnen + long nZWidth = aRect.GetWidth() * (long) GetOfsX() / 100; + long nZHeight = aRect.GetHeight() * (long) GetOfsY() / 100; + long nBorderX = (long) GetBorder() * aSize.Width() / 100; + long nBorderY = (long) GetBorder() * aSize.Height() / 100; + rCenter = Point( aRect.Left() + nZWidth, aRect.Top() + nZHeight ); + + // Rand beruecksichtigen + aSize.Width() -= nBorderX; + aSize.Height() -= nBorderY; + + // Ausgaberechteck neu setzen + aRect.Left() = rCenter.X() - ( aSize.Width() >> 1 ); + aRect.Top() = rCenter.Y() - ( aSize.Height() >> 1 ); + + aRect.SetSize( aSize ); + rBoundRect = rRect; + } +} + +// ----------------------------------------------------------------------- + Gradient& Gradient::operator=( const Gradient& rGradient ) { DBG_CHKTHIS( Gradient, NULL ); diff --git a/vcl/source/gdi/outdev4.cxx b/vcl/source/gdi/outdev4.cxx index 3a1644ebf7aa..2fd02378c9b0 100644 --- a/vcl/source/gdi/outdev4.cxx +++ b/vcl/source/gdi/outdev4.cxx @@ -175,42 +175,25 @@ void OutputDevice::ImplDrawLinearGradient( const Rectangle& rRect, BOOL bMtf, const PolyPolygon* pClipPolyPoly ) { // rotiertes BoundRect ausrechnen - Rectangle aRect = rRect; - aRect.Left()--; - aRect.Top()--; - aRect.Right()++; - aRect.Bottom()++; - USHORT nAngle = rGradient.GetAngle() % 3600; - double fAngle = nAngle * F_PI1800; - double fWidth = aRect.GetWidth(); - double fHeight = aRect.GetHeight(); - double fDX = fWidth * fabs( cos( fAngle ) ) + - fHeight * fabs( sin( fAngle ) ); - double fDY = fHeight * fabs( cos( fAngle ) ) + - fWidth * fabs( sin( fAngle ) ); - fDX = (fDX - fWidth) * 0.5 + 0.5; - fDY = (fDY - fHeight) * 0.5 + 0.5; - aRect.Left() -= (long)fDX; - aRect.Right() += (long)fDX; - aRect.Top() -= (long)fDY; - aRect.Bottom() += (long)fDY; + Rectangle aRect; + Point aCenter; + USHORT nAngle = rGradient.GetAngle() % 3600; + + rGradient.GetBoundRect( rRect, aRect, aCenter ); // Rand berechnen und Rechteck neu setzen - Point aCenter = rRect.Center(); Rectangle aFullRect = aRect; long nBorder = (long)rGradient.GetBorder() * aRect.GetHeight() / 100; - BOOL bLinear; // Rand berechnen und Rechteck neu setzen fuer linearen Farbverlauf - if ( rGradient.GetStyle() == GRADIENT_LINEAR ) + bool bLinear = (rGradient.GetStyle() == GRADIENT_LINEAR); + if ( bLinear ) { - bLinear = TRUE; aRect.Top() += nBorder; } // Rand berechnen und Rechteck neu setzen fuer axiale Farbverlauf else { - bLinear = FALSE; nBorder >>= 1; aRect.Top() += nBorder; @@ -430,7 +413,8 @@ void OutputDevice::ImplDrawComplexGradient( const Rectangle& rRect, // Virtuelle Device werden auch ausgeklammert, da einige Treiber // ansonsten zu langsam sind PolyPolygon* pPolyPoly; - Rectangle aRect( rRect ); + Rectangle aRect; + Point aCenter; Color aStartCol( rGradient.GetStartColor() ); Color aEndCol( rGradient.GetEndColor() ); long nStartRed = ( (long) aStartCol.GetRed() * rGradient.GetStartIntensity() ) / 100; @@ -445,66 +429,13 @@ void OutputDevice::ImplDrawComplexGradient( const Rectangle& rRect, long nStepCount = rGradient.GetSteps(); USHORT nAngle = rGradient.GetAngle() % 3600; + rGradient.GetBoundRect( rRect, aRect, aCenter ); + if( (meRasterOp != ROP_OVERPAINT) || (meOutDevType != OUTDEV_WINDOW) || bMtf ) pPolyPoly = new PolyPolygon( 2 ); else pPolyPoly = NULL; - if( rGradient.GetStyle() == GRADIENT_SQUARE || rGradient.GetStyle() == GRADIENT_RECT ) - { - const double fAngle = nAngle * F_PI1800; - const double fWidth = aRect.GetWidth(); - const double fHeight = aRect.GetHeight(); - double fDX = fWidth * fabs( cos( fAngle ) ) + fHeight * fabs( sin( fAngle ) ); - double fDY = fHeight * fabs( cos( fAngle ) ) + fWidth * fabs( sin( fAngle ) ); - - fDX = ( fDX - fWidth ) * 0.5 + 0.5; - fDY = ( fDY - fHeight ) * 0.5 + 0.5; - - aRect.Left() -= (long) fDX; - aRect.Right() += (long) fDX; - aRect.Top() -= (long) fDY; - aRect.Bottom() += (long) fDY; - } - - Size aSize( aRect.GetSize() ); - - if( rGradient.GetStyle() == GRADIENT_RADIAL ) - { - // Radien-Berechnung fuer Kreis - aSize.Width() = (long)(0.5 + sqrt((double)aSize.Width()*(double)aSize.Width() + (double)aSize.Height()*(double)aSize.Height())); - aSize.Height() = aSize.Width(); - } - else if( rGradient.GetStyle() == GRADIENT_ELLIPTICAL ) - { - // Radien-Berechnung fuer Ellipse - aSize.Width() = (long)( 0.5 + (double) aSize.Width() * 1.4142 ); - aSize.Height() = (long)( 0.5 + (double) aSize.Height() * 1.4142 ); - } - else if( rGradient.GetStyle() == GRADIENT_SQUARE ) - { - if ( aSize.Width() > aSize.Height() ) - aSize.Height() = aSize.Width(); - else - aSize.Width() = aSize.Height(); - } - - // neue Mittelpunkte berechnen - long nZWidth = aRect.GetWidth() * (long) rGradient.GetOfsX() / 100; - long nZHeight = aRect.GetHeight() * (long) rGradient.GetOfsY() / 100; - long nBorderX = (long) rGradient.GetBorder() * aSize.Width() / 100; - long nBorderY = (long) rGradient.GetBorder() * aSize.Height() / 100; - Point aCenter( aRect.Left() + nZWidth, aRect.Top() + nZHeight ); - - // Rand beruecksichtigen - aSize.Width() -= nBorderX; - aSize.Height() -= nBorderY; - - // Ausgaberechteck neu setzen - aRect.Left() = aCenter.X() - ( aSize.Width() >> 1 ); - aRect.Top() = aCenter.Y() - ( aSize.Height() >> 1 ); - - aRect.SetSize( aSize ); long nMinRect = Min( aRect.GetWidth(), aRect.GetHeight() ); // Anzahl der Schritte berechnen, falls nichts uebergeben wurde |