1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2000, 2010 Oracle and/or its affiliates.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * This file is part of OpenOffice.org.
11 * OpenOffice.org is free software: you can redistribute it and/or modify
12 * it under the terms of the GNU Lesser General Public License version 3
13 * only, as published by the Free Software Foundation.
15 * OpenOffice.org is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU Lesser General Public License version 3 for more details
19 * (a copy is included in the LICENSE file that accompanied this code).
21 * You should have received a copy of the GNU Lesser General Public License
22 * version 3 along with OpenOffice.org. If not, see
23 * <http://www.openoffice.org/license.html>
24 * for a copy of the LGPLv3 License.
26 ************************************************************************/
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_canvas.hxx"
31 #include <ctype.h> // don't ask. msdev breaks otherwise...
32 #include <canvas/debug.hxx>
33 #include <canvas/verbosetrace.hxx>
34 #include <tools/diagnose_ex.h>
36 #include <rtl/logfile.hxx>
37 #include <rtl/math.hxx>
39 #include <canvas/canvastools.hxx>
41 #include <basegfx/matrix/b2dhommatrix.hxx>
42 #include <basegfx/point/b2dpoint.hxx>
43 #include <basegfx/tools/canvastools.hxx>
44 #include <basegfx/numeric/ftools.hxx>
45 #include <basegfx/polygon/b2dpolypolygontools.hxx>
46 #include <basegfx/polygon/b2dpolygontools.hxx>
47 #include <basegfx/polygon/b2dpolypolygonrasterconverter.hxx>
48 #include <basegfx/polygon/b2dpolygontriangulator.hxx>
49 #include <basegfx/polygon/b2dpolygoncutandtouch.hxx>
51 #include "dx_canvascustomsprite.hxx"
52 #include "dx_spritehelper.hxx"
53 #include "dx_impltools.hxx"
57 using namespace ::com::sun::star
;
61 SpriteHelper::SpriteHelper() :
64 mbTextureDirty( true ),
65 mbShowSpriteBounds( false )
69 void SpriteHelper::init( const geometry::RealSize2D
& rSpriteSize
,
70 const SpriteCanvasRef
& rSpriteCanvas
,
71 const IDXRenderModuleSharedPtr
& rRenderModule
,
72 const DXSurfaceBitmapSharedPtr rBitmap
,
73 bool bShowSpriteBounds
)
75 ENSURE_OR_THROW( rSpriteCanvas
.get() &&
78 "SpriteHelper::init(): Invalid device, sprite canvas or surface" );
80 mpSpriteCanvas
= rSpriteCanvas
;
82 mbTextureDirty
= true;
83 mbShowSpriteBounds
= bShowSpriteBounds
;
85 // also init base class
86 CanvasCustomSpriteHelper::init( rSpriteSize
,
87 rSpriteCanvas
.get() );
90 void SpriteHelper::disposing()
93 mpSpriteCanvas
.clear();
96 CanvasCustomSpriteHelper::disposing();
99 ::basegfx::B2DPolyPolygon
SpriteHelper::polyPolygonFromXPolyPolygon2D( uno::Reference
< rendering::XPolyPolygon2D
>& xPoly
) const
101 return tools::polyPolygonFromXPolyPolygon2D( xPoly
);
104 bool SpriteHelper::needRedraw() const
107 !mpSpriteCanvas
.get() )
109 return false; // we're disposed, no redraw necessary
113 ::basegfx::fTools::equalZero( getAlpha() ) )
115 return false; // sprite is invisible
121 void SpriteHelper::redraw( bool& io_bSurfaceDirty
) const
124 !mpSpriteCanvas
.get() )
126 return; // we're disposed
129 const ::basegfx::B2DPoint
& rPos( getPosPixel() );
130 const double fAlpha( getAlpha() );
133 !::basegfx::fTools::equalZero( fAlpha
) )
136 // TODO(Q2): For the time being, Device does not take a target
137 // surface, but always unconditionally renders to the
138 // background buffer.
140 // log output pos in device pixel
141 VERBOSE_TRACE( "SpriteHelper::redraw(): output pos is (%f, %f)",
145 const double fAlpha( getAlpha() );
146 const ::basegfx::B2DVector
& rSize( getSizePixel() );
147 const ::basegfx::B2DHomMatrix
& rTransform( getTransformation() );
148 const uno::Reference
< rendering::XPolyPolygon2D
>& xClip( getClip() );
150 mbTextureDirty
= false;
151 io_bSurfaceDirty
= false; // state taken, and processed.
153 ::basegfx::B2DPolyPolygon aClipPath
; // empty for no clip
154 bool bIsClipRectangular( false ); // false, if no
158 // setup and apply clip (if any)
159 // =================================
163 aClipPath
= tools::polyPolygonFromXPolyPolygon2D( xClip
);
165 const sal_Int32
nNumClipPolygons( aClipPath
.count() );
166 if( nNumClipPolygons
)
168 // TODO(P2): hold rectangle attribute directly
169 // at the XPolyPolygon2D
171 // check whether the clip is rectangular
172 if( nNumClipPolygons
== 1 )
173 if( ::basegfx::tools::isRectangle( aClipPath
.getB2DPolygon( 0 ) ) )
174 bIsClipRectangular
= true;
178 const ::basegfx::B2DRectangle
aSourceRect( 0.0,
183 // draw simple rectangular area if no clip is set.
184 if( !aClipPath
.count() )
186 mpBitmap
->draw(fAlpha
,rPos
,rTransform
);
188 else if( bIsClipRectangular
)
190 // apply a simple rect clip
191 // ========================
193 ::basegfx::B2DRectangle
aClipBounds(
194 ::basegfx::tools::getRange( aClipPath
) );
195 aClipBounds
.intersect( aSourceRect
);
197 mpBitmap
->draw(fAlpha
,rPos
,aClipBounds
,rTransform
);
201 // apply clip the hard way
202 // =======================
204 mpBitmap
->draw(fAlpha
,rPos
,aClipPath
,rTransform
);
207 if( mbShowSpriteBounds
)
209 if( aClipPath
.count() )
211 // TODO(F2): Re-enable debug output