Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*
3 : : * This file is part of the LibreOffice project.
4 : : *
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/.
8 : : *
9 : : * This file incorporates work covered by the following license notice:
10 : : *
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 .
18 : : */
19 : :
20 : :
21 : : #include "SlsFramePainter.hxx"
22 : : #include <vcl/outdev.hxx>
23 : : #include <vcl/bmpacc.hxx>
24 : :
25 : :
26 : : namespace sd { namespace slidesorter { namespace view {
27 : :
28 : 390 : FramePainter::FramePainter (const BitmapEx& rShadowBitmap)
29 : : : maTopLeft(rShadowBitmap,-1,-1),
30 : : maTop(rShadowBitmap,0,-1),
31 : : maTopRight(rShadowBitmap,+1,-1),
32 : : maLeft(rShadowBitmap,-1,0),
33 : : maRight(rShadowBitmap,+1,0),
34 : : maBottomLeft(rShadowBitmap,-1,+1),
35 : : maBottom(rShadowBitmap,0,+1),
36 : : maBottomRight(rShadowBitmap,+1,+1),
37 : : maCenter(rShadowBitmap,0,0),
38 [ + - ][ + - ]: 390 : mbIsValid(false)
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ][ + - ]
39 : : {
40 [ + - + - : 1170 : if (rShadowBitmap.GetSizePixel().Width() == rShadowBitmap.GetSizePixel().Height()
+ - ][ + - ]
41 : 390 : && (rShadowBitmap.GetSizePixel().Width()-1)%2 == 0
42 : 390 : && ((rShadowBitmap.GetSizePixel().Width()-1)/2)%2 == 1)
43 : : {
44 : 390 : mbIsValid = true;
45 : : }
46 : : else
47 : : {
48 : : OSL_ASSERT(rShadowBitmap.GetSizePixel().Width() == rShadowBitmap.GetSizePixel().Height());
49 : : OSL_ASSERT((rShadowBitmap.GetSizePixel().Width()-1)%2 == 0);
50 : : OSL_ASSERT(((rShadowBitmap.GetSizePixel().Width()-1)/2)%2 == 1);
51 : : }
52 : 390 : }
53 : :
54 : :
55 : :
56 : :
57 [ + - ][ + - ]: 390 : FramePainter::~FramePainter (void)
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ][ + - ]
58 : : {
59 : 390 : }
60 : :
61 : :
62 : :
63 : :
64 : 147 : void FramePainter::PaintFrame (
65 : : OutputDevice& rDevice,
66 : : const Rectangle aBox) const
67 : : {
68 [ - + ]: 147 : if ( ! mbIsValid)
69 : 147 : return;
70 : :
71 : : // Paint the shadow.
72 [ + - ]: 147 : maTopLeft.PaintCorner(rDevice, aBox.TopLeft());
73 [ + - ]: 147 : maTopRight.PaintCorner(rDevice, aBox.TopRight());
74 [ + - ]: 147 : maBottomLeft.PaintCorner(rDevice, aBox.BottomLeft());
75 [ + - ]: 147 : maBottomRight.PaintCorner(rDevice, aBox.BottomRight());
76 [ + - ]: 147 : maLeft.PaintSide(rDevice, aBox.TopLeft(), aBox.BottomLeft(), maTopLeft, maBottomLeft);
77 [ + - ][ + - ]: 147 : maRight.PaintSide(rDevice, aBox.TopRight(), aBox.BottomRight(), maTopRight, maBottomRight);
78 [ + - ]: 147 : maTop.PaintSide(rDevice, aBox.TopLeft(), aBox.TopRight(), maTopLeft, maTopRight);
79 [ + - ][ + - ]: 147 : maBottom.PaintSide(rDevice, aBox.BottomLeft(), aBox.BottomRight(), maBottomLeft, maBottomRight);
80 : 147 : maCenter.PaintCenter(rDevice,aBox);
81 : : }
82 : :
83 : :
84 : :
85 : :
86 : 130 : void FramePainter::AdaptColor (
87 : : const Color aNewColor,
88 : : const bool bEraseCenter)
89 : : {
90 : : // Get the source color.
91 [ + - ][ + - ]: 130 : if (maCenter.maBitmap.IsEmpty())
92 : : return;
93 [ + - ][ + - ]: 130 : BitmapReadAccess* pReadAccess = maCenter.maBitmap.GetBitmap().AcquireReadAccess();
[ + - ]
94 [ + - ]: 130 : if (pReadAccess == NULL)
95 : : return;
96 [ + - ][ + - ]: 130 : const Color aSourceColor = pReadAccess->GetColor(0,0);
97 [ + - ][ + - ]: 130 : maCenter.maBitmap.GetBitmap().ReleaseAccess(pReadAccess);
[ + - ]
98 : :
99 : : // Erase the center bitmap.
100 [ + - ]: 130 : if (bEraseCenter)
101 [ + - ]: 130 : maCenter.maBitmap.SetEmpty();
102 : :
103 : : // Replace the color in all bitmaps.
104 [ + - ]: 130 : maTopLeft.maBitmap.Replace(aSourceColor, aNewColor, 0);
105 [ + - ]: 130 : maTop.maBitmap.Replace(aSourceColor, aNewColor, 0);
106 [ + - ]: 130 : maTopRight.maBitmap.Replace(aSourceColor, aNewColor, 0);
107 [ + - ]: 130 : maLeft.maBitmap.Replace(aSourceColor, aNewColor, 0);
108 [ + - ]: 130 : maCenter.maBitmap.Replace(aSourceColor, aNewColor, 0);
109 [ + - ]: 130 : maRight.maBitmap.Replace(aSourceColor, aNewColor, 0);
110 [ + - ]: 130 : maBottomLeft.maBitmap.Replace(aSourceColor, aNewColor, 0);
111 [ + - ]: 130 : maBottom.maBitmap.Replace(aSourceColor, aNewColor, 0);
112 [ + - ]: 130 : maBottomRight.maBitmap.Replace(aSourceColor, aNewColor, 0);
113 : : }
114 : :
115 : :
116 : :
117 : :
118 : : //===== FramePainter::OffsetBitmap ============================================
119 : :
120 : 3510 : FramePainter::OffsetBitmap::OffsetBitmap (
121 : : const BitmapEx& rBitmap,
122 : : const sal_Int32 nHorizontalPosition,
123 : : const sal_Int32 nVerticalPosition)
124 : : : maBitmap(),
125 : 3510 : maOffset()
126 : : {
127 : : OSL_ASSERT(nHorizontalPosition>=-1 && nHorizontalPosition<=+1);
128 : : OSL_ASSERT(nVerticalPosition>=-1 && nVerticalPosition<=+1);
129 : :
130 : 3510 : const sal_Int32 nS (1);
131 [ + - ]: 3510 : const sal_Int32 nC (::std::max<sal_Int32>(0,(rBitmap.GetSizePixel().Width()-nS)/2));
132 : 3510 : const sal_Int32 nO (nC/2);
133 : :
134 : : const Point aOrigin(
135 : : nHorizontalPosition<0 ? 0 : (nHorizontalPosition == 0 ? nC : nC+nS),
136 [ + + ][ + + ]: 3510 : nVerticalPosition<0 ? 0 : (nVerticalPosition == 0 ? nC : nC+nS));
[ + + ][ + + ]
137 : : const Size aSize(
138 : : nHorizontalPosition==0 ? nS : nC,
139 [ + + ][ + + ]: 3510 : nVerticalPosition==0 ? nS : nC);
140 [ + - ][ + - ]: 3510 : maBitmap = BitmapEx(rBitmap, aOrigin, aSize);
[ + - ]
141 [ + - ][ + - ]: 3510 : if (maBitmap.IsEmpty())
142 : 3510 : return;
143 : : maOffset = Point(
144 : : nHorizontalPosition<0 ? -nO : nHorizontalPosition>0 ? -nO : 0,
145 [ + + ][ + + ]: 3510 : nVerticalPosition<0 ? -nO : nVerticalPosition>0 ? -nO : 0);
[ + + ][ + + ]
146 : :
147 : : // Enlarge the side bitmaps so that painting the frame requires less
148 : : // paint calls.
149 : 3510 : const sal_Int32 nSideBitmapSize (64);
150 [ + + ][ + + ]: 3510 : if (nHorizontalPosition == 0 && nVerticalPosition == 0)
151 : : {
152 [ + - ]: 390 : maBitmap.Scale(Size(nSideBitmapSize,nSideBitmapSize), BMP_SCALE_FAST);
153 : : }
154 [ + + ]: 3120 : else if (nHorizontalPosition == 0)
155 : : {
156 [ + - ]: 780 : maBitmap.Scale(Size(nSideBitmapSize,aSize.Height()), BMP_SCALE_FAST);
157 : : }
158 [ + + ]: 2340 : else if (nVerticalPosition == 0)
159 : : {
160 [ + - ]: 3510 : maBitmap.Scale(Size(maBitmap.GetSizePixel().Width(), nSideBitmapSize), BMP_SCALE_FAST);
161 : : }
162 : : }
163 : :
164 : :
165 : :
166 : :
167 : 588 : void FramePainter::OffsetBitmap::PaintCorner (
168 : : OutputDevice& rDevice,
169 : : const Point& rAnchor) const
170 : : {
171 [ + - ]: 588 : if ( ! maBitmap.IsEmpty())
172 [ + - ]: 588 : rDevice.DrawBitmapEx(rAnchor+maOffset, maBitmap);
173 : 588 : }
174 : :
175 : :
176 : :
177 : :
178 : 588 : void FramePainter::OffsetBitmap::PaintSide (
179 : : OutputDevice& rDevice,
180 : : const Point& rAnchor1,
181 : : const Point& rAnchor2,
182 : : const OffsetBitmap& rCornerBitmap1,
183 : : const OffsetBitmap& rCornerBitmap2) const
184 : : {
185 [ + - ][ + - ]: 588 : if (maBitmap.IsEmpty())
186 : 588 : return;
187 : :
188 : 588 : const Size aBitmapSize (maBitmap.GetSizePixel());
189 [ + + ]: 588 : if (rAnchor1.Y() == rAnchor2.Y())
190 : : {
191 : : // Side is horizontal.
192 : 294 : const sal_Int32 nY (rAnchor1.Y() + maOffset.Y());
193 : : const sal_Int32 nLeft (
194 : 294 : rAnchor1.X()
195 : 294 : + rCornerBitmap1.maBitmap.GetSizePixel().Width()
196 : 294 : + rCornerBitmap1.maOffset.X());
197 : : const sal_Int32 nRight (
198 : 294 : rAnchor2.X()
199 : 294 : + rCornerBitmap2.maOffset.X()\
200 : 294 : - 1);
201 [ + + ]: 1176 : for (sal_Int32 nX=nLeft; nX<=nRight; nX+=aBitmapSize.Width())
202 : : {
203 : : rDevice.DrawBitmapEx(
204 : : Point(nX,nY),
205 [ + - ]: 882 : Size(std::min(aBitmapSize.Width(),static_cast<long>(nRight-nX+1)),aBitmapSize.Height()),
206 [ + - ]: 1764 : maBitmap);
207 : : }
208 : : }
209 [ + - ]: 294 : else if (rAnchor1.X() == rAnchor2.X())
210 : : {
211 : : // Side is vertical.
212 : 294 : const sal_Int32 nX (rAnchor1.X() + maOffset.X());
213 : : const sal_Int32 nTop (
214 : 294 : rAnchor1.Y()
215 : 294 : + rCornerBitmap1.maBitmap.GetSizePixel().Height()
216 : 294 : + rCornerBitmap1.maOffset.Y());
217 : : const sal_Int32 nBottom (
218 : 294 : rAnchor2.Y()
219 : 294 : + rCornerBitmap2.maOffset.Y()
220 : 294 : - 1);
221 [ + + ]: 1616 : for (sal_Int32 nY=nTop; nY<=nBottom; nY+=aBitmapSize.Height())
222 : : {
223 : : rDevice.DrawBitmapEx(
224 : : Point(nX,nY),
225 [ + - ]: 1028 : Size(aBitmapSize.Width(), std::min(aBitmapSize.Height(), static_cast<long>(nBottom-nY+1))),
226 [ + - ]: 1028 : maBitmap);
227 : : }
228 : : }
229 : : else
230 : : {
231 : : // Diagonal sides indicatee an error.
232 : : OSL_ASSERT(false);
233 : : }
234 : : }
235 : :
236 : :
237 : :
238 : :
239 : 147 : void FramePainter::OffsetBitmap::PaintCenter (
240 : : OutputDevice& rDevice,
241 : : const Rectangle& rBox) const
242 : : {
243 : 147 : const Size aBitmapSize (maBitmap.GetSizePixel());
244 [ + + ]: 679 : for (sal_Int32 nY=rBox.Top(); nY<=rBox.Bottom(); nY+=aBitmapSize.Height())
245 [ + + ]: 2128 : for (sal_Int32 nX=rBox.Left(); nX<=rBox.Right(); nX+=aBitmapSize.Width())
246 : : rDevice.DrawBitmapEx(
247 : : Point(nX,nY),
248 : : Size(
249 [ + - ]: 1596 : ::std::min(aBitmapSize.Width(), rBox.Right()-nX+1),
250 [ + - ]: 1596 : std::min(aBitmapSize.Height(), rBox.Bottom()-nY+1)),
251 [ + - ]: 1596 : maBitmap);
252 : 147 : }
253 : :
254 : :
255 : :
256 : : } } } // end of namespace sd::slidesorter::view
257 : :
258 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|