summaryrefslogtreecommitdiff
path: root/vcl/source/gdi/bmpacc3.cxx
diff options
context:
space:
mode:
authorRüdiger Timm <rt@openoffice.org>2004-05-21 13:38:19 +0000
committerRüdiger Timm <rt@openoffice.org>2004-05-21 13:38:19 +0000
commite394b447585e5c60b18ee6e9b2c459cb71e2fcd3 (patch)
treefcb03568f5983bd6a9c646e68db3073bded2f828 /vcl/source/gdi/bmpacc3.cxx
parent312887adb87cb7ea9f83ebc35bd103ca35a4a1ed (diff)
INTEGRATION: CWS bmpres01 (1.2.36); FILE MERGED
2004/02/13 13:06:13 ka 1.2.36.2: #i22149#: support for alpha masks (cleanup) 2004/02/11 16:15:08 ka 1.2.36.1: #i22149#: added alpha mask support for Images/ImageLists
Diffstat (limited to 'vcl/source/gdi/bmpacc3.cxx')
-rw-r--r--vcl/source/gdi/bmpacc3.cxx418
1 files changed, 255 insertions, 163 deletions
diff --git a/vcl/source/gdi/bmpacc3.cxx b/vcl/source/gdi/bmpacc3.cxx
index d4b9d2b455f4..996b0930a8ce 100644
--- a/vcl/source/gdi/bmpacc3.cxx
+++ b/vcl/source/gdi/bmpacc3.cxx
@@ -2,9 +2,9 @@
*
* $RCSfile: bmpacc3.cxx,v $
*
- * $Revision: 1.2 $
+ * $Revision: 1.3 $
*
- * last change: $Author: vg $ $Date: 2004-01-06 13:33:48 $
+ * last change: $Author: rt $ $Date: 2004-05-21 14:38:19 $
*
* The Contents of this file are made available subject to the terms of
* either of the following licenses
@@ -79,148 +79,218 @@
// - BitmapWriteAccess -
// ---------------------
-void BitmapWriteAccess::Erase( const Color& rColor )
+void BitmapWriteAccess::SetLineColor()
{
- const BitmapColor aOldFillColor( maFillColor );
- const Point aPoint;
- const Rectangle aRect( aPoint, maBitmap.GetSizePixel() );
+ delete mpLineColor;
+ mpLineColor = NULL;
+}
- SetFillColor( rColor );
- FillRect( aRect );
- maFillColor = aOldFillColor;
+// ------------------------------------------------------------------
+
+void BitmapWriteAccess::SetLineColor( const Color& rColor )
+{
+ delete mpLineColor;
+
+ if( rColor.GetTransparency() == 255 )
+ mpLineColor = NULL;
+ else
+ mpLineColor = new BitmapColor( HasPalette() ? (BYTE) GetBestPaletteIndex( rColor ) : rColor );
}
// ------------------------------------------------------------------
-void BitmapWriteAccess::DrawLine( const Point& rStart, const Point& rEnd )
+Color BitmapWriteAccess::GetLineColor() const
{
- long nX;
- long nY;
+ Color aRet;
- ImplInitDraw();
+ if( mpLineColor )
+ aRet = (const Color&) *mpLineColor;
+ else
+ aRet.SetTransparency( 255 );
- if ( rStart.X() == rEnd.X() )
- {
- // vertikale Line
- const long nEndY = rEnd.Y();
+ return aRet;
+}
- nX = rStart.X();
- nY = rStart.Y();
+// ------------------------------------------------------------------
- if ( nEndY > nY )
- {
- for (; nY <= nEndY; nY++ )
- SetPixel( nY, nX, maLineColor );
- }
- else
- {
- for (; nY >= nEndY; nY-- )
- SetPixel( nY, nX, maLineColor );
- }
- }
- else if ( rStart.Y() == rEnd.Y() )
- {
- // horizontale Line
- const long nEndX = rEnd.X();
+void BitmapWriteAccess::SetFillColor()
+{
+ delete mpFillColor;
+ mpFillColor = NULL;
+}
- nX = rStart.X();
- nY = rStart.Y();
+// ------------------------------------------------------------------
- if ( nEndX > nX )
- {
- for (; nX <= nEndX; nX++ )
- SetPixel( nY, nX, maLineColor );
- }
- else
- {
- for (; nX >= nEndX; nX-- )
- SetPixel( nY, nX, maLineColor );
- }
- }
+void BitmapWriteAccess::SetFillColor( const Color& rColor )
+{
+ delete mpFillColor;
+
+ if( rColor.GetTransparency() == 255 )
+ mpFillColor = NULL;
else
+ mpFillColor = new BitmapColor( HasPalette() ? (BYTE) GetBestPaletteIndex( rColor ) : rColor );
+}
+
+// ------------------------------------------------------------------
+
+Color BitmapWriteAccess::GetFillColor() const
+{
+ Color aRet;
+
+ if( mpFillColor )
+ aRet = (const Color&) *mpFillColor;
+ else
+ aRet.SetTransparency( 255 );
+
+ return aRet;
+}
+
+// ------------------------------------------------------------------
+
+void BitmapWriteAccess::Erase( const Color& rColor )
+{
+ BitmapColor* pOldFillColor = mpFillColor ? new BitmapColor( *mpFillColor ) : NULL;
+ const Point aPoint;
+ const Rectangle aRect( aPoint, maBitmap.GetSizePixel() );
+
+ SetFillColor( rColor );
+ FillRect( aRect );
+ delete mpFillColor;
+ mpFillColor = pOldFillColor;
+}
+
+// ------------------------------------------------------------------
+
+void BitmapWriteAccess::DrawLine( const Point& rStart, const Point& rEnd )
+{
+ if( mpLineColor )
{
- const long nDX = labs( rEnd.X() - rStart.X() );
- const long nDY = labs( rEnd.Y() - rStart.Y() );
- long nX1;
- long nY1;
- long nX2;
- long nY2;
-
- if ( nDX >= nDY )
+ const BitmapColor& rLineColor = *mpLineColor;
+ long nX, nY;
+
+ if ( rStart.X() == rEnd.X() )
{
- if ( rStart.X() < rEnd.X() )
+ // vertikale Line
+ const long nEndY = rEnd.Y();
+
+ nX = rStart.X();
+ nY = rStart.Y();
+
+ if ( nEndY > nY )
{
- nX1 = rStart.X();
- nY1 = rStart.Y();
- nX2 = rEnd.X();
- nY2 = rEnd.Y();
+ for (; nY <= nEndY; nY++ )
+ SetPixel( nY, nX, rLineColor );
}
else
{
- nX1 = rEnd.X();
- nY1 = rEnd.Y();
- nX2 = rStart.X();
- nY2 = rStart.Y();
+ for (; nY >= nEndY; nY-- )
+ SetPixel( nY, nX, rLineColor );
}
+ }
+ else if ( rStart.Y() == rEnd.Y() )
+ {
+ // horizontale Line
+ const long nEndX = rEnd.X();
- const long nDYX = ( nDY - nDX ) << 1;
- const long nDY2 = nDY << 1;
- long nD = nDY2 - nDX;
- BOOL bPos = nY1 < nY2;
+ nX = rStart.X();
+ nY = rStart.Y();
- for ( nX = nX1, nY = nY1; nX <= nX2; nX++ )
+ if ( nEndX > nX )
{
- SetPixel( nY, nX, maLineColor );
-
- if ( nD < 0 )
- nD += nDY2;
- else
- {
- nD += nDYX;
-
- if ( bPos )
- nY++;
- else
- nY--;
- }
+ for (; nX <= nEndX; nX++ )
+ SetPixel( nY, nX, rLineColor );
+ }
+ else
+ {
+ for (; nX >= nEndX; nX-- )
+ SetPixel( nY, nX, rLineColor );
}
}
else
{
- if ( rStart.Y() < rEnd.Y() )
+ const long nDX = labs( rEnd.X() - rStart.X() );
+ const long nDY = labs( rEnd.Y() - rStart.Y() );
+ long nX1;
+ long nY1;
+ long nX2;
+ long nY2;
+
+ if ( nDX >= nDY )
{
- nX1 = rStart.X();
- nY1 = rStart.Y();
- nX2 = rEnd.X();
- nY2 = rEnd.Y();
+ if ( rStart.X() < rEnd.X() )
+ {
+ nX1 = rStart.X();
+ nY1 = rStart.Y();
+ nX2 = rEnd.X();
+ nY2 = rEnd.Y();
+ }
+ else
+ {
+ nX1 = rEnd.X();
+ nY1 = rEnd.Y();
+ nX2 = rStart.X();
+ nY2 = rStart.Y();
+ }
+
+ const long nDYX = ( nDY - nDX ) << 1;
+ const long nDY2 = nDY << 1;
+ long nD = nDY2 - nDX;
+ BOOL bPos = nY1 < nY2;
+
+ for ( nX = nX1, nY = nY1; nX <= nX2; nX++ )
+ {
+ SetPixel( nY, nX, rLineColor );
+
+ if ( nD < 0 )
+ nD += nDY2;
+ else
+ {
+ nD += nDYX;
+
+ if ( bPos )
+ nY++;
+ else
+ nY--;
+ }
+ }
}
else
{
- nX1 = rEnd.X();
- nY1 = rEnd.Y();
- nX2 = rStart.X();
- nY2 = rStart.Y();
- }
-
- const long nDYX = ( nDX - nDY ) << 1;
- const long nDY2 = nDX << 1;
- long nD = nDY2 - nDY;
- BOOL bPos = nX1 < nX2;
+ if ( rStart.Y() < rEnd.Y() )
+ {
+ nX1 = rStart.X();
+ nY1 = rStart.Y();
+ nX2 = rEnd.X();
+ nY2 = rEnd.Y();
+ }
+ else
+ {
+ nX1 = rEnd.X();
+ nY1 = rEnd.Y();
+ nX2 = rStart.X();
+ nY2 = rStart.Y();
+ }
- for ( nX = nX1, nY = nY1; nY <= nY2; nY++ )
- {
- SetPixel( nY, nX, maLineColor );
+ const long nDYX = ( nDX - nDY ) << 1;
+ const long nDY2 = nDX << 1;
+ long nD = nDY2 - nDY;
+ BOOL bPos = nX1 < nX2;
- if ( nD < 0 )
- nD += nDY2;
- else
+ for ( nX = nX1, nY = nY1; nY <= nY2; nY++ )
{
- nD += nDYX;
+ SetPixel( nY, nX, rLineColor );
- if ( bPos )
- nX++;
+ if ( nD < 0 )
+ nD += nDY2;
else
- nX--;
+ {
+ nD += nDYX;
+
+ if ( bPos )
+ nX++;
+ else
+ nX--;
+ }
}
}
}
@@ -229,50 +299,57 @@ void BitmapWriteAccess::DrawLine( const Point& rStart, const Point& rEnd )
// ------------------------------------------------------------------
-void BitmapWriteAccess::DrawRect( const Rectangle& rRect )
+void BitmapWriteAccess::FillRect( const Rectangle& rRect )
{
- ImplInitDraw();
- FillRect( rRect );
- DrawLine( rRect.TopLeft(), rRect.TopRight() );
- DrawLine( rRect.TopRight(), rRect.BottomRight() );
- DrawLine( rRect.BottomRight(), rRect.BottomLeft() );
- DrawLine( rRect.BottomLeft(), rRect.TopLeft() );
+ if( mpFillColor )
+ {
+ const BitmapColor& rFillColor = *mpFillColor;
+ Point aPoint;
+ Rectangle aRect( aPoint, maBitmap.GetSizePixel() );
+
+ aRect.Intersection( rRect );
+
+ if( !aRect.IsEmpty() )
+ {
+ const long nStartX = rRect.Left();
+ const long nStartY = rRect.Top();
+ const long nEndX = rRect.Right();
+ const long nEndY = rRect.Bottom();
+
+ for( long nY = nStartY; nY <= nEndY; nY++ )
+ for( long nX = nStartX; nX <= nEndX; nX++ )
+ SetPixel( nY, nX, rFillColor );
+ }
+ }
}
// ------------------------------------------------------------------
-void BitmapWriteAccess::FillRect( const Rectangle& rRect )
+void BitmapWriteAccess::DrawRect( const Rectangle& rRect )
{
- Point aPoint;
- Rectangle aRect( aPoint, maBitmap.GetSizePixel() );
+ if( mpFillColor )
+ FillRect( rRect );
- aRect.Intersection( rRect );
-
- if( !aRect.IsEmpty() )
+ if( mpLineColor && ( !mpFillColor || ( *mpFillColor != *mpLineColor ) ) )
{
- const long nStartX = rRect.TopLeft().X();
- const long nStartY = rRect.TopLeft().Y();
- const long nEndX = rRect.BottomRight().X();
- const long nEndY = rRect.BottomRight().Y();
-
- ImplInitDraw();
-
- for( long nY = nStartY; nY <= nEndY; nY++ )
- for( long nX = nStartX; nX <= nEndX; nX++ )
- SetPixel( nY, nX, maFillColor );
+ DrawLine( rRect.TopLeft(), rRect.TopRight() );
+ DrawLine( rRect.TopRight(), rRect.BottomRight() );
+ DrawLine( rRect.BottomRight(), rRect.BottomLeft() );
+ DrawLine( rRect.BottomLeft(), rRect.TopLeft() );
}
}
// ------------------------------------------------------------------
-void BitmapWriteAccess::DrawPolygon( const Polygon& rPoly )
+void BitmapWriteAccess::FillPolygon( const Polygon& rPoly )
{
const USHORT nSize = rPoly.GetSize();
- if( nSize )
+ if( nSize && mpFillColor )
{
- Region aRegion( rPoly );
- Rectangle aRect;
+ const BitmapColor& rFillColor = *mpFillColor;
+ Region aRegion( rPoly );
+ Rectangle aRect;
aRegion.Intersect( Rectangle( Point(), Size( Width(), Height() ) ) );
@@ -280,37 +357,46 @@ void BitmapWriteAccess::DrawPolygon( const Polygon& rPoly )
{
RegionHandle aRegHandle( aRegion.BeginEnumRects() );
- ImplInitDraw();
-
while( aRegion.GetNextEnumRect( aRegHandle, aRect ) )
for( long nY = aRect.Top(), nEndY = aRect.Bottom(); nY <= nEndY; nY++ )
for( long nX = aRect.Left(), nEndX = aRect.Right(); nX <= nEndX; nX++ )
- SetPixel( nY, nX, maFillColor );
+ SetPixel( nY, nX, rFillColor );
aRegion.EndEnumRects( aRegHandle );
}
+ }
+}
- if( maLineColor != maFillColor )
- {
- for( USHORT i = 0, nSize1 = nSize - 1; i < nSize1; i++ )
- DrawLine( rPoly[ i ], rPoly[ i + 1 ] );
+// ------------------------------------------------------------------
- if( rPoly[ nSize - 1 ] != rPoly[ 0 ] )
- DrawLine( rPoly[ nSize - 1 ], rPoly[ 0 ] );
- }
+void BitmapWriteAccess::DrawPolygon( const Polygon& rPoly )
+{
+ if( mpFillColor )
+ FillPolygon( rPoly );
+
+ if( mpLineColor && ( !mpFillColor || ( *mpFillColor != *mpLineColor ) ) )
+ {
+ const USHORT nSize = rPoly.GetSize();
+
+ for( USHORT i = 0, nSize1 = nSize - 1; i < nSize1; i++ )
+ DrawLine( rPoly[ i ], rPoly[ i + 1 ] );
+
+ if( rPoly[ nSize - 1 ] != rPoly[ 0 ] )
+ DrawLine( rPoly[ nSize - 1 ], rPoly[ 0 ] );
}
}
// ------------------------------------------------------------------
-void BitmapWriteAccess::DrawPolyPolygon( const PolyPolygon& rPolyPoly )
+void BitmapWriteAccess::FillPolyPolygon( const PolyPolygon& rPolyPoly )
{
const USHORT nCount = rPolyPoly.Count();
- if( nCount )
+ if( nCount && mpFillColor )
{
- Region aRegion( rPolyPoly );
- Rectangle aRect;
+ const BitmapColor& rFillColor = *mpFillColor;
+ Region aRegion( rPolyPoly );
+ Rectangle aRect;
aRegion.Intersect( Rectangle( Point(), Size( Width(), Height() ) ) );
@@ -318,31 +404,37 @@ void BitmapWriteAccess::DrawPolyPolygon( const PolyPolygon& rPolyPoly )
{
RegionHandle aRegHandle( aRegion.BeginEnumRects() );
- ImplInitDraw();
-
while( aRegion.GetNextEnumRect( aRegHandle, aRect ) )
for( long nY = aRect.Top(), nEndY = aRect.Bottom(); nY <= nEndY; nY++ )
for( long nX = aRect.Left(), nEndX = aRect.Right(); nX <= nEndX; nX++ )
- SetPixel( nY, nX, maFillColor );
+ SetPixel( nY, nX, rFillColor );
aRegion.EndEnumRects( aRegHandle );
}
+ }
+}
+
+// ------------------------------------------------------------------
- if( maLineColor != maFillColor )
+void BitmapWriteAccess::DrawPolyPolygon( const PolyPolygon& rPolyPoly )
+{
+ if( mpFillColor )
+ FillPolyPolygon( rPolyPoly );
+
+ if( mpLineColor && ( !mpFillColor || ( *mpFillColor != *mpLineColor ) ) )
+ {
+ for( USHORT n = 0, nCount = rPolyPoly.Count(); n < nCount; )
{
- for( USHORT n = 0; n < nCount; )
- {
- const Polygon& rPoly = rPolyPoly[ n++ ];
- const USHORT nSize = rPoly.GetSize();
+ const Polygon& rPoly = rPolyPoly[ n++ ];
+ const USHORT nSize = rPoly.GetSize();
- if( nSize )
- {
- for( USHORT i = 0, nSize1 = nSize - 1; i < nSize1; i++ )
- DrawLine( rPoly[ i ], rPoly[ i + 1 ] );
+ if( nSize )
+ {
+ for( USHORT i = 0, nSize1 = nSize - 1; i < nSize1; i++ )
+ DrawLine( rPoly[ i ], rPoly[ i + 1 ] );
- if( rPoly[ nSize - 1 ] != rPoly[ 0 ] )
- DrawLine( rPoly[ nSize - 1 ], rPoly[ 0 ] );
- }
+ if( rPoly[ nSize - 1 ] != rPoly[ 0 ] )
+ DrawLine( rPoly[ nSize - 1 ], rPoly[ 0 ] );
}
}
}