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