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 195 : 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 195 : mbIsValid(false)
39 : {
40 390 : if (rShadowBitmap.GetSizePixel().Width() == rShadowBitmap.GetSizePixel().Height()
41 195 : && (rShadowBitmap.GetSizePixel().Width()-1)%2 == 0
42 390 : && ((rShadowBitmap.GetSizePixel().Width()-1)/2)%2 == 1)
43 : {
44 195 : 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 195 : }
53 :
54 :
55 :
56 :
57 195 : FramePainter::~FramePainter (void)
58 : {
59 195 : }
60 :
61 :
62 :
63 :
64 77 : void FramePainter::PaintFrame (
65 : OutputDevice& rDevice,
66 : const Rectangle aBox) const
67 : {
68 77 : if ( ! mbIsValid)
69 77 : return;
70 :
71 : // Paint the shadow.
72 77 : maTopLeft.PaintCorner(rDevice, aBox.TopLeft());
73 77 : maTopRight.PaintCorner(rDevice, aBox.TopRight());
74 77 : maBottomLeft.PaintCorner(rDevice, aBox.BottomLeft());
75 77 : maBottomRight.PaintCorner(rDevice, aBox.BottomRight());
76 77 : maLeft.PaintSide(rDevice, aBox.TopLeft(), aBox.BottomLeft(), maTopLeft, maBottomLeft);
77 77 : maRight.PaintSide(rDevice, aBox.TopRight(), aBox.BottomRight(), maTopRight, maBottomRight);
78 77 : maTop.PaintSide(rDevice, aBox.TopLeft(), aBox.TopRight(), maTopLeft, maTopRight);
79 77 : maBottom.PaintSide(rDevice, aBox.BottomLeft(), aBox.BottomRight(), maBottomLeft, maBottomRight);
80 77 : maCenter.PaintCenter(rDevice,aBox);
81 : }
82 :
83 :
84 :
85 :
86 65 : void FramePainter::AdaptColor (
87 : const Color aNewColor,
88 : const bool bEraseCenter)
89 : {
90 : // Get the source color.
91 65 : if (maCenter.maBitmap.IsEmpty())
92 0 : return;
93 65 : BitmapReadAccess* pReadAccess = maCenter.maBitmap.GetBitmap().AcquireReadAccess();
94 65 : if (pReadAccess == NULL)
95 0 : return;
96 65 : const Color aSourceColor = pReadAccess->GetColor(0,0);
97 65 : maCenter.maBitmap.GetBitmap().ReleaseAccess(pReadAccess);
98 :
99 : // Erase the center bitmap.
100 65 : if (bEraseCenter)
101 65 : maCenter.maBitmap.SetEmpty();
102 :
103 : // Replace the color in all bitmaps.
104 65 : maTopLeft.maBitmap.Replace(aSourceColor, aNewColor, 0);
105 65 : maTop.maBitmap.Replace(aSourceColor, aNewColor, 0);
106 65 : maTopRight.maBitmap.Replace(aSourceColor, aNewColor, 0);
107 65 : maLeft.maBitmap.Replace(aSourceColor, aNewColor, 0);
108 65 : maCenter.maBitmap.Replace(aSourceColor, aNewColor, 0);
109 65 : maRight.maBitmap.Replace(aSourceColor, aNewColor, 0);
110 65 : maBottomLeft.maBitmap.Replace(aSourceColor, aNewColor, 0);
111 65 : maBottom.maBitmap.Replace(aSourceColor, aNewColor, 0);
112 65 : maBottomRight.maBitmap.Replace(aSourceColor, aNewColor, 0);
113 : }
114 :
115 :
116 :
117 :
118 : //===== FramePainter::OffsetBitmap ============================================
119 :
120 1755 : FramePainter::OffsetBitmap::OffsetBitmap (
121 : const BitmapEx& rBitmap,
122 : const sal_Int32 nHorizontalPosition,
123 : const sal_Int32 nVerticalPosition)
124 : : maBitmap(),
125 1755 : maOffset()
126 : {
127 : OSL_ASSERT(nHorizontalPosition>=-1 && nHorizontalPosition<=+1);
128 : OSL_ASSERT(nVerticalPosition>=-1 && nVerticalPosition<=+1);
129 :
130 1755 : const sal_Int32 nS (1);
131 1755 : const sal_Int32 nC (::std::max<sal_Int32>(0,(rBitmap.GetSizePixel().Width()-nS)/2));
132 1755 : const sal_Int32 nO (nC/2);
133 :
134 : const Point aOrigin(
135 : nHorizontalPosition<0 ? 0 : (nHorizontalPosition == 0 ? nC : nC+nS),
136 1755 : nVerticalPosition<0 ? 0 : (nVerticalPosition == 0 ? nC : nC+nS));
137 : const Size aSize(
138 : nHorizontalPosition==0 ? nS : nC,
139 1755 : nVerticalPosition==0 ? nS : nC);
140 1755 : maBitmap = BitmapEx(rBitmap, aOrigin, aSize);
141 1755 : if (maBitmap.IsEmpty())
142 1755 : return;
143 : maOffset = Point(
144 : nHorizontalPosition<0 ? -nO : nHorizontalPosition>0 ? -nO : 0,
145 1755 : nVerticalPosition<0 ? -nO : nVerticalPosition>0 ? -nO : 0);
146 :
147 : // Enlarge the side bitmaps so that painting the frame requires less
148 : // paint calls.
149 1755 : const sal_Int32 nSideBitmapSize (64);
150 1755 : if (nHorizontalPosition == 0 && nVerticalPosition == 0)
151 : {
152 195 : maBitmap.Scale(Size(nSideBitmapSize,nSideBitmapSize));
153 : }
154 1560 : else if (nHorizontalPosition == 0)
155 : {
156 390 : maBitmap.Scale(Size(nSideBitmapSize,aSize.Height()));
157 : }
158 1170 : else if (nVerticalPosition == 0)
159 : {
160 390 : maBitmap.Scale(Size(maBitmap.GetSizePixel().Width(), nSideBitmapSize));
161 : }
162 : }
163 :
164 :
165 :
166 :
167 308 : void FramePainter::OffsetBitmap::PaintCorner (
168 : OutputDevice& rDevice,
169 : const Point& rAnchor) const
170 : {
171 308 : if ( ! maBitmap.IsEmpty())
172 308 : rDevice.DrawBitmapEx(rAnchor+maOffset, maBitmap);
173 308 : }
174 :
175 :
176 :
177 :
178 308 : 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 308 : if (maBitmap.IsEmpty())
186 308 : return;
187 :
188 308 : const Size aBitmapSize (maBitmap.GetSizePixel());
189 308 : if (rAnchor1.Y() == rAnchor2.Y())
190 : {
191 : // Side is horizontal.
192 154 : const sal_Int32 nY (rAnchor1.Y() + maOffset.Y());
193 : const sal_Int32 nLeft (
194 154 : rAnchor1.X()
195 154 : + rCornerBitmap1.maBitmap.GetSizePixel().Width()
196 154 : + rCornerBitmap1.maOffset.X());
197 : const sal_Int32 nRight (
198 154 : rAnchor2.X()
199 154 : + rCornerBitmap2.maOffset.X()\
200 154 : - 1);
201 616 : for (sal_Int32 nX=nLeft; nX<=nRight; nX+=aBitmapSize.Width())
202 : {
203 : rDevice.DrawBitmapEx(
204 : Point(nX,nY),
205 924 : Size(std::min(aBitmapSize.Width(),static_cast<long>(nRight-nX+1)),aBitmapSize.Height()),
206 924 : maBitmap);
207 : }
208 : }
209 154 : else if (rAnchor1.X() == rAnchor2.X())
210 : {
211 : // Side is vertical.
212 154 : const sal_Int32 nX (rAnchor1.X() + maOffset.X());
213 : const sal_Int32 nTop (
214 154 : rAnchor1.Y()
215 154 : + rCornerBitmap1.maBitmap.GetSizePixel().Height()
216 154 : + rCornerBitmap1.maOffset.Y());
217 : const sal_Int32 nBottom (
218 154 : rAnchor2.Y()
219 154 : + rCornerBitmap2.maOffset.Y()
220 154 : - 1);
221 694 : for (sal_Int32 nY=nTop; nY<=nBottom; nY+=aBitmapSize.Height())
222 : {
223 : rDevice.DrawBitmapEx(
224 : Point(nX,nY),
225 1080 : Size(aBitmapSize.Width(), std::min(aBitmapSize.Height(), static_cast<long>(nBottom-nY+1))),
226 1080 : maBitmap);
227 : }
228 : }
229 : else
230 : {
231 : // Diagonal sides indicatee an error.
232 : OSL_ASSERT(false);
233 : }
234 : }
235 :
236 :
237 :
238 :
239 77 : void FramePainter::OffsetBitmap::PaintCenter (
240 : OutputDevice& rDevice,
241 : const Rectangle& rBox) const
242 : {
243 77 : const Size aBitmapSize (maBitmap.GetSizePixel());
244 357 : for (sal_Int32 nY=rBox.Top(); nY<=rBox.Bottom(); nY+=aBitmapSize.Height())
245 1120 : for (sal_Int32 nX=rBox.Left(); nX<=rBox.Right(); nX+=aBitmapSize.Width())
246 : rDevice.DrawBitmapEx(
247 : Point(nX,nY),
248 : Size(
249 1680 : ::std::min(aBitmapSize.Width(), rBox.Right()-nX+1),
250 1680 : std::min(aBitmapSize.Height(), rBox.Bottom()-nY+1)),
251 2520 : maBitmap);
252 77 : }
253 :
254 :
255 :
256 33 : } } } // end of namespace sd::slidesorter::view
257 :
258 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|