fdo#74697 Add Bluez 5 support for impress remote.
[LibreOffice.git] / drawinglayer / source / primitive2d / wallpaperprimitive2d.cxx
blobbf3c5f81bde17f2460e7360a7effa7575affb60a
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include <drawinglayer/primitive2d/wallpaperprimitive2d.hxx>
21 #include <drawinglayer/primitive2d/bitmapprimitive2d.hxx>
22 #include <drawinglayer/primitive2d/drawinglayer_primitivetypes2d.hxx>
23 #include <drawinglayer/primitive2d/fillbitmapprimitive2d.hxx>
24 #include <basegfx/polygon/b2dpolygontools.hxx>
25 #include <basegfx/polygon/b2dpolygon.hxx>
26 #include <drawinglayer/primitive2d/maskprimitive2d.hxx>
28 //////////////////////////////////////////////////////////////////////////////
30 namespace drawinglayer
32 namespace primitive2d
34 Primitive2DSequence WallpaperBitmapPrimitive2D::create2DDecomposition(const geometry::ViewInformation2D& /*rViewInformation*/) const
36 Primitive2DSequence aRetval;
38 if(!getLocalObjectRange().isEmpty() && !getBitmapEx().IsEmpty())
40 // get bitmap PIXEL size
41 const Size& rPixelSize = getBitmapEx().GetSizePixel();
43 if(rPixelSize.Width() > 0 && rPixelSize.Height() > 0)
45 if(WALLPAPER_SCALE == getWallpaperStyle())
47 // shortcut for scale; use simple BitmapPrimitive2D
48 basegfx::B2DHomMatrix aObjectTransform;
50 aObjectTransform.set(0, 0, getLocalObjectRange().getWidth());
51 aObjectTransform.set(1, 1, getLocalObjectRange().getHeight());
52 aObjectTransform.set(0, 2, getLocalObjectRange().getMinX());
53 aObjectTransform.set(1, 2, getLocalObjectRange().getMinY());
55 Primitive2DReference xReference(
56 new BitmapPrimitive2D(
57 getBitmapEx(),
58 aObjectTransform));
60 aRetval = Primitive2DSequence(&xReference, 1);
62 else
64 // transform to logic size
65 basegfx::B2DHomMatrix aInverseViewTransformation(getViewTransformation());
66 aInverseViewTransformation.invert();
67 basegfx::B2DVector aLogicSize(rPixelSize.Width(), rPixelSize.Height());
68 aLogicSize = aInverseViewTransformation * aLogicSize;
70 // apply laout
71 basegfx::B2DPoint aTargetTopLeft(getLocalObjectRange().getMinimum());
72 bool bUseTargetTopLeft(true);
73 bool bNeedsClipping(false);
75 switch(getWallpaperStyle())
77 default: //case WALLPAPER_TILE :, also WALLPAPER_NULL and WALLPAPER_APPLICATIONGRADIENT
79 bUseTargetTopLeft = false;
80 break;
82 case WALLPAPER_SCALE :
84 // handled by shortcut above
85 break;
87 case WALLPAPER_TOPLEFT :
89 // nothing to do
90 break;
92 case WALLPAPER_TOP :
94 const basegfx::B2DPoint aCenter(getLocalObjectRange().getCenter());
95 aTargetTopLeft.setX(aCenter.getX() - (aLogicSize.getX() * 0.5));
96 break;
98 case WALLPAPER_TOPRIGHT :
100 aTargetTopLeft.setX(getLocalObjectRange().getMaxX() - aLogicSize.getX());
101 break;
103 case WALLPAPER_LEFT :
105 const basegfx::B2DPoint aCenter(getLocalObjectRange().getCenter());
106 aTargetTopLeft.setY(aCenter.getY() - (aLogicSize.getY() * 0.5));
107 break;
109 case WALLPAPER_CENTER :
111 const basegfx::B2DPoint aCenter(getLocalObjectRange().getCenter());
112 aTargetTopLeft = aCenter - (aLogicSize * 0.5);
113 break;
115 case WALLPAPER_RIGHT :
117 const basegfx::B2DPoint aCenter(getLocalObjectRange().getCenter());
118 aTargetTopLeft.setX(getLocalObjectRange().getMaxX() - aLogicSize.getX());
119 aTargetTopLeft.setY(aCenter.getY() - (aLogicSize.getY() * 0.5));
120 break;
122 case WALLPAPER_BOTTOMLEFT :
124 aTargetTopLeft.setY(getLocalObjectRange().getMaxY() - aLogicSize.getY());
125 break;
127 case WALLPAPER_BOTTOM :
129 const basegfx::B2DPoint aCenter(getLocalObjectRange().getCenter());
130 aTargetTopLeft.setX(aCenter.getX() - (aLogicSize.getX() * 0.5));
131 aTargetTopLeft.setY(getLocalObjectRange().getMaxY() - aLogicSize.getY());
132 break;
134 case WALLPAPER_BOTTOMRIGHT :
136 aTargetTopLeft = getLocalObjectRange().getMaximum() - aLogicSize;
137 break;
141 if(bUseTargetTopLeft)
143 // fill target range
144 const basegfx::B2DRange aTargetRange(aTargetTopLeft, aTargetTopLeft + aLogicSize);
146 // create aligned, single BitmapPrimitive2D
147 basegfx::B2DHomMatrix aObjectTransform;
149 aObjectTransform.set(0, 0, aTargetRange.getWidth());
150 aObjectTransform.set(1, 1, aTargetRange.getHeight());
151 aObjectTransform.set(0, 2, aTargetRange.getMinX());
152 aObjectTransform.set(1, 2, aTargetRange.getMinY());
154 Primitive2DReference xReference(
155 new BitmapPrimitive2D(
156 getBitmapEx(),
157 aObjectTransform));
158 aRetval = Primitive2DSequence(&xReference, 1);
160 // clip when not completely inside object range
161 bNeedsClipping = !getLocalObjectRange().isInside(aTargetRange);
163 else
165 // WALLPAPER_TILE, WALLPAPER_NULL, WALLPAPER_APPLICATIONGRADIENT
166 // convert to relative positions
167 const basegfx::B2DVector aRelativeSize(
168 aLogicSize.getX() / (getLocalObjectRange().getWidth() ? getLocalObjectRange().getWidth() : 1.0),
169 aLogicSize.getY() / (getLocalObjectRange().getHeight() ? getLocalObjectRange().getHeight() : 1.0));
170 basegfx::B2DPoint aRelativeTopLeft(0.0, 0.0);
172 if(WALLPAPER_TILE != getWallpaperStyle())
174 aRelativeTopLeft.setX(0.5 - aRelativeSize.getX());
175 aRelativeTopLeft.setY(0.5 - aRelativeSize.getY());
178 // prepare FillBitmapAttribute
179 const attribute::FillBitmapAttribute aFillBitmapAttribute(
180 getBitmapEx(),
181 aRelativeTopLeft,
182 aRelativeSize,
183 true);
185 // create ObjectTransform
186 basegfx::B2DHomMatrix aObjectTransform;
188 aObjectTransform.set(0, 0, getLocalObjectRange().getWidth());
189 aObjectTransform.set(1, 1, getLocalObjectRange().getHeight());
190 aObjectTransform.set(0, 2, getLocalObjectRange().getMinX());
191 aObjectTransform.set(1, 2, getLocalObjectRange().getMinY());
193 // create FillBitmapPrimitive
194 const drawinglayer::primitive2d::Primitive2DReference xFillBitmap(
195 new drawinglayer::primitive2d::FillBitmapPrimitive2D(
196 aObjectTransform,
197 aFillBitmapAttribute));
198 aRetval = Primitive2DSequence(&xFillBitmap, 1);
200 // always embed tiled fill to clipping
201 bNeedsClipping = true;
204 if(bNeedsClipping)
206 // embed to clipping; this is necessary for tiled fills
207 const basegfx::B2DPolyPolygon aPolyPolygon(
208 basegfx::tools::createPolygonFromRect(getLocalObjectRange()));
209 const drawinglayer::primitive2d::Primitive2DReference xClippedFill(
210 new drawinglayer::primitive2d::MaskPrimitive2D(
211 aPolyPolygon,
212 aRetval));
213 aRetval = Primitive2DSequence(&xClippedFill, 1);
219 return aRetval;
222 WallpaperBitmapPrimitive2D::WallpaperBitmapPrimitive2D(
223 const basegfx::B2DRange& rObjectRange,
224 const BitmapEx& rBitmapEx,
225 WallpaperStyle eWallpaperStyle)
226 : ViewTransformationDependentPrimitive2D(),
227 maObjectRange(rObjectRange),
228 maBitmapEx(rBitmapEx),
229 meWallpaperStyle(eWallpaperStyle)
233 bool WallpaperBitmapPrimitive2D::operator==(const BasePrimitive2D& rPrimitive) const
235 if(ViewTransformationDependentPrimitive2D::operator==(rPrimitive))
237 const WallpaperBitmapPrimitive2D& rCompare = (WallpaperBitmapPrimitive2D&)rPrimitive;
239 return (getLocalObjectRange() == rCompare.getLocalObjectRange()
240 && getBitmapEx() == rCompare.getBitmapEx()
241 && getWallpaperStyle() == rCompare.getWallpaperStyle());
244 return false;
247 basegfx::B2DRange WallpaperBitmapPrimitive2D::getB2DRange(const geometry::ViewInformation2D& /*rViewInformation*/) const
249 return getLocalObjectRange();
252 // provide unique ID
253 ImplPrimitive2DIDBlock(WallpaperBitmapPrimitive2D, PRIMITIVE2D_ID_WALLPAPERBITMAPPRIMITIVE2D)
254 } // end of namespace primitive2d
255 } // end of namespace drawinglayer
257 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */