1 /************************************************************** 2 * 3 * Licensed to the Apache Software Foundation (ASF) under one 4 * or more contributor license agreements. See the NOTICE file 5 * distributed with this work for additional information 6 * regarding copyright ownership. The ASF licenses this file 7 * to you under the Apache License, Version 2.0 (the 8 * "License"); you may not use this file except in compliance 9 * with the License. You may obtain a copy of the License at 10 * 11 * http://www.apache.org/licenses/LICENSE-2.0 12 * 13 * Unless required by applicable law or agreed to in writing, 14 * software distributed under the License is distributed on an 15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 * KIND, either express or implied. See the License for the 17 * specific language governing permissions and limitations 18 * under the License. 19 * 20 *************************************************************/ 21 22 // MARKER(update_precomp.py): autogen include statement, do not remove 23 #include "precompiled_drawinglayer.hxx" 24 25 #include <drawinglayer/primitive2d/wallpaperprimitive2d.hxx> 26 #include <drawinglayer/primitive2d/bitmapprimitive2d.hxx> 27 #include <drawinglayer/primitive2d/drawinglayer_primitivetypes2d.hxx> 28 #include <drawinglayer/primitive2d/fillgraphicprimitive2d.hxx> 29 #include <basegfx/polygon/b2dpolygontools.hxx> 30 #include <basegfx/polygon/b2dpolygon.hxx> 31 #include <drawinglayer/primitive2d/maskprimitive2d.hxx> 32 #include <basegfx/matrix/b2dhommatrixtools.hxx> 33 #include <vcl/graph.hxx> 34 35 namespace drawinglayer 36 { 37 namespace primitive2d 38 { create2DDecomposition(const geometry::ViewInformation2D &) const39 Primitive2DSequence WallpaperBitmapPrimitive2D::create2DDecomposition(const geometry::ViewInformation2D& /*rViewInformation*/) const 40 { 41 Primitive2DSequence aRetval; 42 43 if(!getLocalObjectRange().isEmpty() && !getBitmapEx().IsEmpty()) 44 { 45 // get bitmap PIXEL size 46 const Size& rPixelSize = getBitmapEx().GetSizePixel(); 47 48 if(rPixelSize.Width() > 0 && rPixelSize.Height() > 0) 49 { 50 if(WALLPAPER_SCALE == getWallpaperStyle()) 51 { 52 // shortcut for scale; use simple BitmapPrimitive2D 53 basegfx::B2DHomMatrix aObjectTransform; 54 55 aObjectTransform.set(0, 0, getLocalObjectRange().getWidth()); 56 aObjectTransform.set(1, 1, getLocalObjectRange().getHeight()); 57 aObjectTransform.set(0, 2, getLocalObjectRange().getMinX()); 58 aObjectTransform.set(1, 2, getLocalObjectRange().getMinY()); 59 60 Primitive2DReference xReference( 61 new BitmapPrimitive2D( 62 getBitmapEx(), 63 aObjectTransform)); 64 65 aRetval = Primitive2DSequence(&xReference, 1); 66 } 67 else 68 { 69 // transform to logic size 70 basegfx::B2DHomMatrix aInverseViewTransformation(getViewTransformation()); 71 aInverseViewTransformation.invert(); 72 basegfx::B2DVector aLogicSize(rPixelSize.Width(), rPixelSize.Height()); 73 aLogicSize = aInverseViewTransformation * aLogicSize; 74 75 // apply layout 76 basegfx::B2DPoint aTargetTopLeft(getLocalObjectRange().getMinimum()); 77 bool bUseTargetTopLeft(true); 78 bool bNeedsClipping(false); 79 80 switch(getWallpaperStyle()) 81 { 82 default: //case WALLPAPER_TILE :, also WALLPAPER_NULL and WALLPAPER_APPLICATIONGRADIENT 83 { 84 bUseTargetTopLeft = false; 85 break; 86 } 87 case WALLPAPER_SCALE : 88 { 89 // handled by shortcut above 90 break; 91 } 92 case WALLPAPER_TOPLEFT : 93 { 94 // nothing to do 95 break; 96 } 97 case WALLPAPER_TOP : 98 { 99 const basegfx::B2DPoint aCenter(getLocalObjectRange().getCenter()); 100 aTargetTopLeft.setX(aCenter.getX() - (aLogicSize.getX() * 0.5)); 101 break; 102 } 103 case WALLPAPER_TOPRIGHT : 104 { 105 aTargetTopLeft.setX(getLocalObjectRange().getMaxX() - aLogicSize.getX()); 106 break; 107 } 108 case WALLPAPER_LEFT : 109 { 110 const basegfx::B2DPoint aCenter(getLocalObjectRange().getCenter()); 111 aTargetTopLeft.setY(aCenter.getY() - (aLogicSize.getY() * 0.5)); 112 break; 113 } 114 case WALLPAPER_CENTER : 115 { 116 const basegfx::B2DPoint aCenter(getLocalObjectRange().getCenter()); 117 aTargetTopLeft = aCenter - (aLogicSize * 0.5); 118 break; 119 } 120 case WALLPAPER_RIGHT : 121 { 122 const basegfx::B2DPoint aCenter(getLocalObjectRange().getCenter()); 123 aTargetTopLeft.setX(getLocalObjectRange().getMaxX() - aLogicSize.getX()); 124 aTargetTopLeft.setY(aCenter.getY() - (aLogicSize.getY() * 0.5)); 125 break; 126 } 127 case WALLPAPER_BOTTOMLEFT : 128 { 129 aTargetTopLeft.setY(getLocalObjectRange().getMaxY() - aLogicSize.getY()); 130 break; 131 } 132 case WALLPAPER_BOTTOM : 133 { 134 const basegfx::B2DPoint aCenter(getLocalObjectRange().getCenter()); 135 aTargetTopLeft.setX(aCenter.getX() - (aLogicSize.getX() * 0.5)); 136 aTargetTopLeft.setY(getLocalObjectRange().getMaxY() - aLogicSize.getY()); 137 break; 138 } 139 case WALLPAPER_BOTTOMRIGHT : 140 { 141 aTargetTopLeft = getLocalObjectRange().getMaximum() - aLogicSize; 142 break; 143 } 144 } 145 146 if(bUseTargetTopLeft) 147 { 148 // fill target range 149 const basegfx::B2DRange aTargetRange(aTargetTopLeft, aTargetTopLeft + aLogicSize); 150 151 // create aligned, single BitmapPrimitive2D 152 basegfx::B2DHomMatrix aObjectTransform; 153 154 aObjectTransform.set(0, 0, aTargetRange.getWidth()); 155 aObjectTransform.set(1, 1, aTargetRange.getHeight()); 156 aObjectTransform.set(0, 2, aTargetRange.getMinX()); 157 aObjectTransform.set(1, 2, aTargetRange.getMinY()); 158 159 Primitive2DReference xReference( 160 new BitmapPrimitive2D( 161 getBitmapEx(), 162 aObjectTransform)); 163 aRetval = Primitive2DSequence(&xReference, 1); 164 165 // clip when not completely inside object range 166 bNeedsClipping = !getLocalObjectRange().isInside(aTargetRange); 167 } 168 else 169 { 170 // WALLPAPER_TILE, WALLPAPER_NULL, WALLPAPER_APPLICATIONGRADIENT 171 // convert to relative positions 172 const basegfx::B2DVector aRelativeSize( 173 aLogicSize.getX() / (getLocalObjectRange().getWidth() ? getLocalObjectRange().getWidth() : 1.0), 174 aLogicSize.getY() / (getLocalObjectRange().getHeight() ? getLocalObjectRange().getHeight() : 1.0)); 175 basegfx::B2DPoint aRelativeTopLeft(0.0, 0.0); 176 177 if(WALLPAPER_TILE != getWallpaperStyle()) 178 { 179 aRelativeTopLeft.setX(0.5 - aRelativeSize.getX()); 180 aRelativeTopLeft.setY(0.5 - aRelativeSize.getY()); 181 } 182 183 // prepare FillGraphicAttribute 184 const attribute::FillGraphicAttribute aFillGraphicAttribute( 185 Graphic(getBitmapEx()), 186 basegfx::B2DRange(aRelativeTopLeft, aRelativeTopLeft+ aRelativeSize), 187 true); 188 189 // create ObjectTransform 190 const basegfx::B2DHomMatrix aObjectTransform( 191 basegfx::tools::createScaleTranslateB2DHomMatrix( 192 getLocalObjectRange().getRange(), 193 getLocalObjectRange().getMinimum())); 194 195 // create FillBitmapPrimitive 196 const drawinglayer::primitive2d::Primitive2DReference xFillBitmap( 197 new drawinglayer::primitive2d::FillGraphicPrimitive2D( 198 aObjectTransform, 199 aFillGraphicAttribute)); 200 aRetval = Primitive2DSequence(&xFillBitmap, 1); 201 202 // always embed tiled fill to clipping 203 bNeedsClipping = true; 204 } 205 206 if(bNeedsClipping) 207 { 208 // embed to clipping; this is necessary for tiled fills 209 const basegfx::B2DPolyPolygon aPolyPolygon( 210 basegfx::tools::createPolygonFromRect(getLocalObjectRange())); 211 const drawinglayer::primitive2d::Primitive2DReference xClippedFill( 212 new drawinglayer::primitive2d::MaskPrimitive2D( 213 aPolyPolygon, 214 aRetval)); 215 aRetval = Primitive2DSequence(&xClippedFill, 1); 216 } 217 } 218 } 219 } 220 221 return aRetval; 222 } 223 WallpaperBitmapPrimitive2D(const basegfx::B2DRange & rObjectRange,const BitmapEx & rBitmapEx,WallpaperStyle eWallpaperStyle)224 WallpaperBitmapPrimitive2D::WallpaperBitmapPrimitive2D( 225 const basegfx::B2DRange& rObjectRange, 226 const BitmapEx& rBitmapEx, 227 WallpaperStyle eWallpaperStyle) 228 : ViewTransformationDependentPrimitive2D(), 229 maObjectRange(rObjectRange), 230 maBitmapEx(rBitmapEx), 231 meWallpaperStyle(eWallpaperStyle) 232 { 233 } 234 operator ==(const BasePrimitive2D & rPrimitive) const235 bool WallpaperBitmapPrimitive2D::operator==(const BasePrimitive2D& rPrimitive) const 236 { 237 if(ViewTransformationDependentPrimitive2D::operator==(rPrimitive)) 238 { 239 const WallpaperBitmapPrimitive2D& rCompare = (WallpaperBitmapPrimitive2D&)rPrimitive; 240 241 return (getLocalObjectRange() == rCompare.getLocalObjectRange() 242 && getBitmapEx() == rCompare.getBitmapEx() 243 && getWallpaperStyle() == rCompare.getWallpaperStyle()); 244 } 245 246 return false; 247 } 248 getB2DRange(const geometry::ViewInformation2D &) const249 basegfx::B2DRange WallpaperBitmapPrimitive2D::getB2DRange(const geometry::ViewInformation2D& /*rViewInformation*/) const 250 { 251 return getLocalObjectRange(); 252 } 253 254 // provide unique ID 255 ImplPrimitrive2DIDBlock(WallpaperBitmapPrimitive2D, PRIMITIVE2D_ID_WALLPAPERBITMAPPRIMITIVE2D) 256 } // end of namespace primitive2d 257 } // end of namespace drawinglayer 258 259 /* vim: set noet sw=4 ts=4: */ 260