1*25b11142SAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 3*25b11142SAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 4*25b11142SAndrew Rist * or more contributor license agreements. See the NOTICE file 5*25b11142SAndrew Rist * distributed with this work for additional information 6*25b11142SAndrew Rist * regarding copyright ownership. The ASF licenses this file 7*25b11142SAndrew Rist * to you under the Apache License, Version 2.0 (the 8*25b11142SAndrew Rist * "License"); you may not use this file except in compliance 9*25b11142SAndrew Rist * with the License. You may obtain a copy of the License at 10cdf0e10cSrcweir * 11*25b11142SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12cdf0e10cSrcweir * 13*25b11142SAndrew Rist * Unless required by applicable law or agreed to in writing, 14*25b11142SAndrew Rist * software distributed under the License is distributed on an 15*25b11142SAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16*25b11142SAndrew Rist * KIND, either express or implied. See the License for the 17*25b11142SAndrew Rist * specific language governing permissions and limitations 18*25b11142SAndrew Rist * under the License. 19cdf0e10cSrcweir * 20*25b11142SAndrew Rist *************************************************************/ 21*25b11142SAndrew Rist 22*25b11142SAndrew Rist 23cdf0e10cSrcweir 24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove 25cdf0e10cSrcweir #include "precompiled_cppcanvas.hxx" 26cdf0e10cSrcweir 27cdf0e10cSrcweir #include <rtl/logfile.hxx> 28cdf0e10cSrcweir #include <com/sun/star/rendering/XCanvas.hpp> 29cdf0e10cSrcweir 30cdf0e10cSrcweir #include <tools/gen.hxx> 31cdf0e10cSrcweir #include <vcl/canvastools.hxx> 32cdf0e10cSrcweir 33cdf0e10cSrcweir #include <basegfx/range/b2drange.hxx> 34cdf0e10cSrcweir #include <basegfx/point/b2dpoint.hxx> 35cdf0e10cSrcweir #include <basegfx/tools/canvastools.hxx> 36cdf0e10cSrcweir #include <canvas/canvastools.hxx> 37cdf0e10cSrcweir 38cdf0e10cSrcweir #include <boost/utility.hpp> 39cdf0e10cSrcweir 40cdf0e10cSrcweir #include "pointaction.hxx" 41cdf0e10cSrcweir #include "outdevstate.hxx" 42cdf0e10cSrcweir #include "cppcanvas/canvas.hxx" 43cdf0e10cSrcweir #include "mtftools.hxx" 44cdf0e10cSrcweir 45cdf0e10cSrcweir 46cdf0e10cSrcweir using namespace ::com::sun::star; 47cdf0e10cSrcweir 48cdf0e10cSrcweir namespace cppcanvas 49cdf0e10cSrcweir { 50cdf0e10cSrcweir namespace internal 51cdf0e10cSrcweir { 52cdf0e10cSrcweir namespace 53cdf0e10cSrcweir { 54cdf0e10cSrcweir class PointAction : public Action, private ::boost::noncopyable 55cdf0e10cSrcweir { 56cdf0e10cSrcweir public: 57cdf0e10cSrcweir PointAction( const ::basegfx::B2DPoint&, 58cdf0e10cSrcweir const CanvasSharedPtr&, 59cdf0e10cSrcweir const OutDevState& ); 60cdf0e10cSrcweir PointAction( const ::basegfx::B2DPoint&, 61cdf0e10cSrcweir const CanvasSharedPtr&, 62cdf0e10cSrcweir const OutDevState&, 63cdf0e10cSrcweir const ::Color& ); 64cdf0e10cSrcweir 65cdf0e10cSrcweir virtual bool render( const ::basegfx::B2DHomMatrix& rTransformation ) const; 66cdf0e10cSrcweir virtual bool render( const ::basegfx::B2DHomMatrix& rTransformation, 67cdf0e10cSrcweir const Subset& rSubset ) const; 68cdf0e10cSrcweir 69cdf0e10cSrcweir virtual ::basegfx::B2DRange getBounds( const ::basegfx::B2DHomMatrix& rTransformation ) const; 70cdf0e10cSrcweir virtual ::basegfx::B2DRange getBounds( const ::basegfx::B2DHomMatrix& rTransformation, 71cdf0e10cSrcweir const Subset& rSubset ) const; 72cdf0e10cSrcweir 73cdf0e10cSrcweir virtual sal_Int32 getActionCount() const; 74cdf0e10cSrcweir 75cdf0e10cSrcweir private: 76cdf0e10cSrcweir // default: disabled copy/assignment 77cdf0e10cSrcweir PointAction(const PointAction&); 78cdf0e10cSrcweir PointAction& operator = ( const PointAction& ); 79cdf0e10cSrcweir 80cdf0e10cSrcweir ::basegfx::B2DPoint maPoint; 81cdf0e10cSrcweir CanvasSharedPtr mpCanvas; 82cdf0e10cSrcweir ::com::sun::star::rendering::RenderState maState; 83cdf0e10cSrcweir }; 84cdf0e10cSrcweir PointAction(const::basegfx::B2DPoint & rPoint,const CanvasSharedPtr & rCanvas,const OutDevState & rState)85cdf0e10cSrcweir PointAction::PointAction( const ::basegfx::B2DPoint& rPoint, 86cdf0e10cSrcweir const CanvasSharedPtr& rCanvas, 87cdf0e10cSrcweir const OutDevState& rState ) : 88cdf0e10cSrcweir maPoint( rPoint ), 89cdf0e10cSrcweir mpCanvas( rCanvas ), 90cdf0e10cSrcweir maState() 91cdf0e10cSrcweir { 92cdf0e10cSrcweir tools::initRenderState(maState,rState); 93cdf0e10cSrcweir maState.DeviceColor = rState.lineColor; 94cdf0e10cSrcweir } 95cdf0e10cSrcweir PointAction(const::basegfx::B2DPoint & rPoint,const CanvasSharedPtr & rCanvas,const OutDevState & rState,const::Color & rAltColor)96cdf0e10cSrcweir PointAction::PointAction( const ::basegfx::B2DPoint& rPoint, 97cdf0e10cSrcweir const CanvasSharedPtr& rCanvas, 98cdf0e10cSrcweir const OutDevState& rState, 99cdf0e10cSrcweir const ::Color& rAltColor ) : 100cdf0e10cSrcweir maPoint( rPoint ), 101cdf0e10cSrcweir mpCanvas( rCanvas ), 102cdf0e10cSrcweir maState() 103cdf0e10cSrcweir { 104cdf0e10cSrcweir tools::initRenderState(maState,rState); 105cdf0e10cSrcweir maState.DeviceColor = ::vcl::unotools::colorToDoubleSequence( 106cdf0e10cSrcweir rAltColor, 107cdf0e10cSrcweir rCanvas->getUNOCanvas()->getDevice()->getDeviceColorSpace() ); 108cdf0e10cSrcweir } 109cdf0e10cSrcweir render(const::basegfx::B2DHomMatrix & rTransformation) const110cdf0e10cSrcweir bool PointAction::render( const ::basegfx::B2DHomMatrix& rTransformation ) const 111cdf0e10cSrcweir { 112cdf0e10cSrcweir RTL_LOGFILE_CONTEXT( aLog, "::cppcanvas::internal::PointAction::render()" ); 113cdf0e10cSrcweir RTL_LOGFILE_CONTEXT_TRACE1( aLog, "::cppcanvas::internal::PointAction: 0x%X", this ); 114cdf0e10cSrcweir 115cdf0e10cSrcweir rendering::RenderState aLocalState( maState ); 116cdf0e10cSrcweir ::canvas::tools::prependToRenderState(aLocalState, rTransformation); 117cdf0e10cSrcweir 118cdf0e10cSrcweir mpCanvas->getUNOCanvas()->drawPoint( ::basegfx::unotools::point2DFromB2DPoint(maPoint), 119cdf0e10cSrcweir mpCanvas->getViewState(), 120cdf0e10cSrcweir aLocalState ); 121cdf0e10cSrcweir 122cdf0e10cSrcweir return true; 123cdf0e10cSrcweir } 124cdf0e10cSrcweir render(const::basegfx::B2DHomMatrix & rTransformation,const Subset & rSubset) const125cdf0e10cSrcweir bool PointAction::render( const ::basegfx::B2DHomMatrix& rTransformation, 126cdf0e10cSrcweir const Subset& rSubset ) const 127cdf0e10cSrcweir { 128cdf0e10cSrcweir // point only contains a single action, fail if subset 129cdf0e10cSrcweir // requests different range 130cdf0e10cSrcweir if( rSubset.mnSubsetBegin != 0 || 131cdf0e10cSrcweir rSubset.mnSubsetEnd != 1 ) 132cdf0e10cSrcweir return false; 133cdf0e10cSrcweir 134cdf0e10cSrcweir return render( rTransformation ); 135cdf0e10cSrcweir } 136cdf0e10cSrcweir getBounds(const::basegfx::B2DHomMatrix & rTransformation) const137cdf0e10cSrcweir ::basegfx::B2DRange PointAction::getBounds( const ::basegfx::B2DHomMatrix& rTransformation ) const 138cdf0e10cSrcweir { 139cdf0e10cSrcweir rendering::RenderState aLocalState( maState ); 140cdf0e10cSrcweir ::canvas::tools::prependToRenderState(aLocalState, rTransformation); 141cdf0e10cSrcweir 142cdf0e10cSrcweir return tools::calcDevicePixelBounds( ::basegfx::B2DRange( maPoint.getX()-1, 143cdf0e10cSrcweir maPoint.getY()-1, 144cdf0e10cSrcweir maPoint.getX()+1, 145cdf0e10cSrcweir maPoint.getY()+1 ), 146cdf0e10cSrcweir mpCanvas->getViewState(), 147cdf0e10cSrcweir aLocalState ); 148cdf0e10cSrcweir } 149cdf0e10cSrcweir getBounds(const::basegfx::B2DHomMatrix & rTransformation,const Subset & rSubset) const150cdf0e10cSrcweir ::basegfx::B2DRange PointAction::getBounds( const ::basegfx::B2DHomMatrix& rTransformation, 151cdf0e10cSrcweir const Subset& rSubset ) const 152cdf0e10cSrcweir { 153cdf0e10cSrcweir // point only contains a single action, empty bounds 154cdf0e10cSrcweir // if subset requests different range 155cdf0e10cSrcweir if( rSubset.mnSubsetBegin != 0 || 156cdf0e10cSrcweir rSubset.mnSubsetEnd != 1 ) 157cdf0e10cSrcweir return ::basegfx::B2DRange(); 158cdf0e10cSrcweir 159cdf0e10cSrcweir return getBounds( rTransformation ); 160cdf0e10cSrcweir } 161cdf0e10cSrcweir getActionCount() const162cdf0e10cSrcweir sal_Int32 PointAction::getActionCount() const 163cdf0e10cSrcweir { 164cdf0e10cSrcweir return 1; 165cdf0e10cSrcweir } 166cdf0e10cSrcweir } 167cdf0e10cSrcweir createPointAction(const::basegfx::B2DPoint & rPoint,const CanvasSharedPtr & rCanvas,const OutDevState & rState)168cdf0e10cSrcweir ActionSharedPtr PointActionFactory::createPointAction( const ::basegfx::B2DPoint& rPoint, 169cdf0e10cSrcweir const CanvasSharedPtr& rCanvas, 170cdf0e10cSrcweir const OutDevState& rState ) 171cdf0e10cSrcweir { 172cdf0e10cSrcweir return ActionSharedPtr( new PointAction( rPoint, rCanvas, rState ) ); 173cdf0e10cSrcweir } 174cdf0e10cSrcweir createPointAction(const::basegfx::B2DPoint & rPoint,const CanvasSharedPtr & rCanvas,const OutDevState & rState,const::Color & rColor)175cdf0e10cSrcweir ActionSharedPtr PointActionFactory::createPointAction( const ::basegfx::B2DPoint& rPoint, 176cdf0e10cSrcweir const CanvasSharedPtr& rCanvas, 177cdf0e10cSrcweir const OutDevState& rState, 178cdf0e10cSrcweir const ::Color& rColor ) 179cdf0e10cSrcweir { 180cdf0e10cSrcweir return ActionSharedPtr( new PointAction( rPoint, rCanvas, rState, rColor ) ); 181cdf0e10cSrcweir } 182cdf0e10cSrcweir } 183cdf0e10cSrcweir } 184