Update ooo320-m1
[ooovba.git] / canvas / source / vcl / canvascustomsprite.cxx
blob3055d05a356ea2d5bc12fb52e6b74878ceaad508
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: canvascustomsprite.cxx,v $
10 * $Revision: 1.15 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_canvas.hxx"
34 #include <canvas/debug.hxx>
35 #include <tools/diagnose_ex.h>
36 #include <canvas/verbosetrace.hxx>
38 #include <rtl/math.hxx>
40 #include <vcl/outdev.hxx>
41 #include <vcl/bitmap.hxx>
42 #include <vcl/alpha.hxx>
43 #include <vcl/bitmapex.hxx>
44 #include <vcl/canvastools.hxx>
46 #include <basegfx/matrix/b2dhommatrix.hxx>
47 #include <basegfx/point/b2dpoint.hxx>
48 #include <basegfx/tools/canvastools.hxx>
49 #include <basegfx/polygon/b2dpolygon.hxx>
50 #include <basegfx/polygon/b2dpolygontools.hxx>
51 #include <basegfx/polygon/b2dpolypolygontools.hxx>
52 #include <basegfx/numeric/ftools.hxx>
54 #include <canvas/canvastools.hxx>
56 #include "canvascustomsprite.hxx"
59 using namespace ::com::sun::star;
62 namespace vclcanvas
65 CanvasCustomSprite::CanvasCustomSprite( const geometry::RealSize2D& rSpriteSize,
66 rendering::XGraphicDevice& rDevice,
67 const ::canvas::SpriteSurface::Reference& rOwningSpriteCanvas,
68 const OutDevProviderSharedPtr& rOutDevProvider,
69 bool bShowSpriteBounds )
71 ENSURE_OR_THROW( rOwningSpriteCanvas.get() &&
72 rOutDevProvider,
73 "CanvasCustomSprite::CanvasCustomSprite(): Invalid sprite canvas" );
75 // setup back buffer
76 // -----------------
78 const ::Size aSize(
79 static_cast<sal_Int32>( ::std::max( 1.0,
80 ceil( rSpriteSize.Width ))), // round up to nearest int,
81 // enforce sprite to have at
82 // least (1,1) pixel size
83 static_cast<sal_Int32>( ::std::max( 1.0,
84 ceil( rSpriteSize.Height ))) );
86 // create content backbuffer in screen depth
87 BackBufferSharedPtr pBackBuffer( new BackBuffer( rOutDevProvider->getOutDev() ) );
88 pBackBuffer->setSize( aSize );
90 // create mask backbuffer, with one bit color depth
91 BackBufferSharedPtr pBackBufferMask( new BackBuffer( rOutDevProvider->getOutDev(),
92 true ) );
93 pBackBufferMask->setSize( aSize );
95 // TODO(F1): Implement alpha vdev (could prolly enable
96 // antialiasing again, then)
98 // disable font antialiasing (causes ugly shadows otherwise)
99 pBackBuffer->getOutDev().SetAntialiasing( ANTIALIASING_DISABLE_TEXT );
100 pBackBufferMask->getOutDev().SetAntialiasing( ANTIALIASING_DISABLE_TEXT );
102 // set mask vdev drawmode, such that everything is painted
103 // black. That leaves us with a binary image, white for
104 // background, black for painted content
105 pBackBufferMask->getOutDev().SetDrawMode( DRAWMODE_BLACKLINE | DRAWMODE_BLACKFILL | DRAWMODE_BLACKTEXT |
106 DRAWMODE_BLACKGRADIENT | DRAWMODE_BLACKBITMAP );
109 // setup canvas helper
110 // -------------------
112 // always render into back buffer, don't preserve state (it's
113 // our private VDev, after all), have notion of alpha
114 maCanvasHelper.init( rDevice,
115 pBackBuffer,
116 false,
117 true );
118 maCanvasHelper.setBackgroundOutDev( pBackBufferMask );
121 // setup sprite helper
122 // -------------------
124 maSpriteHelper.init( rSpriteSize,
125 rOwningSpriteCanvas,
126 pBackBuffer,
127 pBackBufferMask,
128 bShowSpriteBounds );
130 // clear sprite to 100% transparent
131 maCanvasHelper.clear();
134 void SAL_CALL CanvasCustomSprite::disposing()
136 tools::LocalGuard aGuard;
138 // forward to parent
139 CanvasCustomSpriteBaseT::disposing();
142 #define IMPLEMENTATION_NAME "VCLCanvas.CanvasCustomSprite"
143 #define SERVICE_NAME "com.sun.star.rendering.CanvasCustomSprite"
145 ::rtl::OUString SAL_CALL CanvasCustomSprite::getImplementationName() throw( uno::RuntimeException )
147 return ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( IMPLEMENTATION_NAME ) );
150 sal_Bool SAL_CALL CanvasCustomSprite::supportsService( const ::rtl::OUString& ServiceName ) throw( uno::RuntimeException )
152 return ServiceName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM ( SERVICE_NAME ) );
155 uno::Sequence< ::rtl::OUString > SAL_CALL CanvasCustomSprite::getSupportedServiceNames() throw( uno::RuntimeException )
157 uno::Sequence< ::rtl::OUString > aRet(1);
158 aRet[0] = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM ( SERVICE_NAME ) );
160 return aRet;
163 // Sprite
164 void CanvasCustomSprite::redraw( OutputDevice& rOutDev,
165 bool bBufferedUpdate ) const
167 tools::LocalGuard aGuard;
169 redraw( rOutDev, maSpriteHelper.getPosPixel(), bBufferedUpdate );
172 void CanvasCustomSprite::redraw( OutputDevice& rOutDev,
173 const ::basegfx::B2DPoint& rOrigOutputPos,
174 bool bBufferedUpdate ) const
176 tools::LocalGuard aGuard;
178 maSpriteHelper.redraw( rOutDev,
179 rOrigOutputPos,
180 mbSurfaceDirty,
181 bBufferedUpdate );
183 mbSurfaceDirty = false;
186 bool CanvasCustomSprite::repaint( const GraphicObjectSharedPtr& rGrf,
187 const rendering::ViewState& viewState,
188 const rendering::RenderState& renderState,
189 const ::Point& rPt,
190 const ::Size& rSz,
191 const GraphicAttr& rAttr ) const
193 tools::LocalGuard aGuard;
195 mbSurfaceDirty = true;
197 return maCanvasHelper.repaint( rGrf, viewState, renderState, rPt, rSz, rAttr );