xref: /AOO41X/main/sd/source/ui/slidesorter/view/SlsFramePainter.cxx (revision 37ab0f2ded8d56c462c711095097172f45805977)
15b190011SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
35b190011SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
45b190011SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
55b190011SAndrew Rist  * distributed with this work for additional information
65b190011SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
75b190011SAndrew Rist  * to you under the Apache License, Version 2.0 (the
85b190011SAndrew Rist  * "License"); you may not use this file except in compliance
95b190011SAndrew Rist  * with the License.  You may obtain a copy of the License at
10cdf0e10cSrcweir  *
115b190011SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12cdf0e10cSrcweir  *
135b190011SAndrew Rist  * Unless required by applicable law or agreed to in writing,
145b190011SAndrew Rist  * software distributed under the License is distributed on an
155b190011SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
165b190011SAndrew Rist  * KIND, either express or implied.  See the License for the
175b190011SAndrew Rist  * specific language governing permissions and limitations
185b190011SAndrew Rist  * under the License.
19cdf0e10cSrcweir  *
205b190011SAndrew Rist  *************************************************************/
215b190011SAndrew Rist 
225b190011SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir #include "precompiled_sd.hxx"
25cdf0e10cSrcweir 
26cdf0e10cSrcweir #include "SlsFramePainter.hxx"
27cdf0e10cSrcweir #include <vcl/outdev.hxx>
28cdf0e10cSrcweir #include <vcl/bmpacc.hxx>
29cdf0e10cSrcweir 
30cdf0e10cSrcweir 
31cdf0e10cSrcweir namespace sd { namespace slidesorter { namespace view {
32cdf0e10cSrcweir 
FramePainter(const BitmapEx & rShadowBitmap)33cdf0e10cSrcweir FramePainter::FramePainter (const BitmapEx& rShadowBitmap)
34cdf0e10cSrcweir     : maTopLeft(rShadowBitmap,-1,-1),
35cdf0e10cSrcweir       maTop(rShadowBitmap,0,-1),
36cdf0e10cSrcweir       maTopRight(rShadowBitmap,+1,-1),
37cdf0e10cSrcweir       maLeft(rShadowBitmap,-1,0),
38cdf0e10cSrcweir       maRight(rShadowBitmap,+1,0),
39cdf0e10cSrcweir       maBottomLeft(rShadowBitmap,-1,+1),
40cdf0e10cSrcweir       maBottom(rShadowBitmap,0,+1),
41cdf0e10cSrcweir       maBottomRight(rShadowBitmap,+1,+1),
42cdf0e10cSrcweir       maCenter(rShadowBitmap,0,0),
43cdf0e10cSrcweir       mbIsValid(false)
44cdf0e10cSrcweir {
45cdf0e10cSrcweir     if (rShadowBitmap.GetSizePixel().Width() == rShadowBitmap.GetSizePixel().Height()
46cdf0e10cSrcweir         && (rShadowBitmap.GetSizePixel().Width()-1)%2 == 0
47cdf0e10cSrcweir         && ((rShadowBitmap.GetSizePixel().Width()-1)/2)%2 == 1)
48cdf0e10cSrcweir     {
49cdf0e10cSrcweir         mbIsValid = true;
50cdf0e10cSrcweir     }
51cdf0e10cSrcweir     else
52cdf0e10cSrcweir     {
53cdf0e10cSrcweir         OSL_ASSERT(rShadowBitmap.GetSizePixel().Width() == rShadowBitmap.GetSizePixel().Height());
54cdf0e10cSrcweir         OSL_ASSERT((rShadowBitmap.GetSizePixel().Width()-1)%2 == 0);
55cdf0e10cSrcweir         OSL_ASSERT(((rShadowBitmap.GetSizePixel().Width()-1)/2)%2 == 1);
56cdf0e10cSrcweir     }
57cdf0e10cSrcweir }
58cdf0e10cSrcweir 
59cdf0e10cSrcweir 
60cdf0e10cSrcweir 
61cdf0e10cSrcweir 
~FramePainter(void)62cdf0e10cSrcweir FramePainter::~FramePainter (void)
63cdf0e10cSrcweir {
64cdf0e10cSrcweir }
65cdf0e10cSrcweir 
66cdf0e10cSrcweir 
67cdf0e10cSrcweir 
68cdf0e10cSrcweir 
PaintFrame(OutputDevice & rDevice,const Rectangle aBox) const69cdf0e10cSrcweir void FramePainter::PaintFrame (
70cdf0e10cSrcweir     OutputDevice& rDevice,
71cdf0e10cSrcweir     const Rectangle aBox) const
72cdf0e10cSrcweir {
73cdf0e10cSrcweir     if ( ! mbIsValid)
74cdf0e10cSrcweir         return;
75cdf0e10cSrcweir 
76cdf0e10cSrcweir     // Paint the shadow.
77cdf0e10cSrcweir     maTopLeft.PaintCorner(rDevice, aBox.TopLeft());
78cdf0e10cSrcweir     maTopRight.PaintCorner(rDevice, aBox.TopRight());
79cdf0e10cSrcweir     maBottomLeft.PaintCorner(rDevice, aBox.BottomLeft());
80cdf0e10cSrcweir     maBottomRight.PaintCorner(rDevice, aBox.BottomRight());
81cdf0e10cSrcweir     maLeft.PaintSide(rDevice, aBox.TopLeft(), aBox.BottomLeft(), maTopLeft, maBottomLeft);
82cdf0e10cSrcweir     maRight.PaintSide(rDevice, aBox.TopRight(), aBox.BottomRight(), maTopRight, maBottomRight);
83cdf0e10cSrcweir     maTop.PaintSide(rDevice, aBox.TopLeft(), aBox.TopRight(), maTopLeft, maTopRight);
84cdf0e10cSrcweir     maBottom.PaintSide(rDevice, aBox.BottomLeft(), aBox.BottomRight(), maBottomLeft, maBottomRight);
85cdf0e10cSrcweir     maCenter.PaintCenter(rDevice,aBox);
86cdf0e10cSrcweir }
87cdf0e10cSrcweir 
88cdf0e10cSrcweir 
89cdf0e10cSrcweir 
90cdf0e10cSrcweir 
AdaptColor(const Color aNewColor,const bool bEraseCenter)91cdf0e10cSrcweir void FramePainter::AdaptColor (
92cdf0e10cSrcweir     const Color aNewColor,
93cdf0e10cSrcweir     const bool bEraseCenter)
94cdf0e10cSrcweir {
95cdf0e10cSrcweir     // Get the source color.
96cdf0e10cSrcweir     if (maCenter.maBitmap.IsEmpty())
97cdf0e10cSrcweir         return;
98cdf0e10cSrcweir     BitmapReadAccess* pReadAccess = maCenter.maBitmap.GetBitmap().AcquireReadAccess();
99cdf0e10cSrcweir     if (pReadAccess == NULL)
100cdf0e10cSrcweir         return;
101cdf0e10cSrcweir     const Color aSourceColor = pReadAccess->GetColor(0,0);
102cdf0e10cSrcweir     maCenter.maBitmap.GetBitmap().ReleaseAccess(pReadAccess);
103cdf0e10cSrcweir 
104cdf0e10cSrcweir     // Erase the center bitmap.
105cdf0e10cSrcweir     if (bEraseCenter)
106cdf0e10cSrcweir         maCenter.maBitmap.SetEmpty();
107cdf0e10cSrcweir 
108cdf0e10cSrcweir     // Replace the color in all bitmaps.
109cdf0e10cSrcweir     maTopLeft.maBitmap.Replace(aSourceColor, aNewColor, 0);
110cdf0e10cSrcweir     maTop.maBitmap.Replace(aSourceColor, aNewColor, 0);
111cdf0e10cSrcweir     maTopRight.maBitmap.Replace(aSourceColor, aNewColor, 0);
112cdf0e10cSrcweir     maLeft.maBitmap.Replace(aSourceColor, aNewColor, 0);
113cdf0e10cSrcweir     maCenter.maBitmap.Replace(aSourceColor, aNewColor, 0);
114cdf0e10cSrcweir     maRight.maBitmap.Replace(aSourceColor, aNewColor, 0);
115cdf0e10cSrcweir     maBottomLeft.maBitmap.Replace(aSourceColor, aNewColor, 0);
116cdf0e10cSrcweir     maBottom.maBitmap.Replace(aSourceColor, aNewColor, 0);
117cdf0e10cSrcweir     maBottomRight.maBitmap.Replace(aSourceColor, aNewColor, 0);
118cdf0e10cSrcweir }
119cdf0e10cSrcweir 
120cdf0e10cSrcweir 
121cdf0e10cSrcweir 
122cdf0e10cSrcweir 
123cdf0e10cSrcweir //===== FramePainter::OffsetBitmap ============================================
124cdf0e10cSrcweir 
OffsetBitmap(const BitmapEx & rBitmap,const sal_Int32 nHorizontalPosition,const sal_Int32 nVerticalPosition)125cdf0e10cSrcweir FramePainter::OffsetBitmap::OffsetBitmap (
126cdf0e10cSrcweir     const BitmapEx& rBitmap,
127cdf0e10cSrcweir     const sal_Int32 nHorizontalPosition,
128cdf0e10cSrcweir     const sal_Int32 nVerticalPosition)
129cdf0e10cSrcweir     : maBitmap(),
130cdf0e10cSrcweir       maOffset()
131cdf0e10cSrcweir {
132cdf0e10cSrcweir     OSL_ASSERT(nHorizontalPosition>=-1 && nHorizontalPosition<=+1);
133cdf0e10cSrcweir     OSL_ASSERT(nVerticalPosition>=-1 && nVerticalPosition<=+1);
134cdf0e10cSrcweir 
135cdf0e10cSrcweir     const sal_Int32 nS (1);
136cdf0e10cSrcweir     const sal_Int32 nC (::std::max<sal_Int32>(0,(rBitmap.GetSizePixel().Width()-nS)/2));
137cdf0e10cSrcweir     const sal_Int32 nO (nC/2);
138cdf0e10cSrcweir 
139cdf0e10cSrcweir     const Point aOrigin(
140cdf0e10cSrcweir         nHorizontalPosition<0 ? 0 : (nHorizontalPosition == 0 ? nC : nC+nS),
141cdf0e10cSrcweir         nVerticalPosition<0 ? 0 : (nVerticalPosition == 0 ? nC : nC+nS));
142cdf0e10cSrcweir     const Size aSize(
143cdf0e10cSrcweir         nHorizontalPosition==0 ? nS : nC,
144cdf0e10cSrcweir         nVerticalPosition==0 ? nS : nC);
145cdf0e10cSrcweir     maBitmap = BitmapEx(rBitmap, aOrigin, aSize);
146cdf0e10cSrcweir     if (maBitmap.IsEmpty())
147cdf0e10cSrcweir         return;
148cdf0e10cSrcweir     maOffset = Point(
149cdf0e10cSrcweir         nHorizontalPosition<0 ? -nO : nHorizontalPosition>0 ? -nO : 0,
150cdf0e10cSrcweir         nVerticalPosition<0 ? -nO : nVerticalPosition>0 ? -nO : 0);
151cdf0e10cSrcweir 
152cdf0e10cSrcweir     // Enlarge the side bitmaps so that painting the frame requires less
153cdf0e10cSrcweir     // paint calls.
154cdf0e10cSrcweir     const sal_Int32 nSideBitmapSize (64);
155cdf0e10cSrcweir     if (nHorizontalPosition == 0 && nVerticalPosition == 0)
156cdf0e10cSrcweir     {
157*37ab0f2dSArmin Le Grand         maBitmap.Scale(Size(nSideBitmapSize,nSideBitmapSize), BMP_SCALE_FASTESTINTERPOLATE);
158cdf0e10cSrcweir     }
159cdf0e10cSrcweir     else if (nHorizontalPosition == 0)
160cdf0e10cSrcweir     {
161*37ab0f2dSArmin Le Grand         maBitmap.Scale(Size(nSideBitmapSize,aSize.Height()), BMP_SCALE_FASTESTINTERPOLATE);
162cdf0e10cSrcweir     }
163cdf0e10cSrcweir     else if (nVerticalPosition == 0)
164cdf0e10cSrcweir     {
165*37ab0f2dSArmin Le Grand         maBitmap.Scale(Size(maBitmap.GetSizePixel().Width(), nSideBitmapSize), BMP_SCALE_FASTESTINTERPOLATE);
166cdf0e10cSrcweir     }
167cdf0e10cSrcweir }
168cdf0e10cSrcweir 
169cdf0e10cSrcweir 
170cdf0e10cSrcweir 
171cdf0e10cSrcweir 
PaintCorner(OutputDevice & rDevice,const Point & rAnchor) const172cdf0e10cSrcweir void FramePainter::OffsetBitmap::PaintCorner (
173cdf0e10cSrcweir     OutputDevice& rDevice,
174cdf0e10cSrcweir     const Point& rAnchor) const
175cdf0e10cSrcweir {
176cdf0e10cSrcweir     if ( ! maBitmap.IsEmpty())
177cdf0e10cSrcweir         rDevice.DrawBitmapEx(rAnchor+maOffset, maBitmap);
178cdf0e10cSrcweir }
179cdf0e10cSrcweir 
180cdf0e10cSrcweir 
181cdf0e10cSrcweir 
182cdf0e10cSrcweir 
PaintSide(OutputDevice & rDevice,const Point & rAnchor1,const Point & rAnchor2,const OffsetBitmap & rCornerBitmap1,const OffsetBitmap & rCornerBitmap2) const183cdf0e10cSrcweir void FramePainter::OffsetBitmap::PaintSide (
184cdf0e10cSrcweir     OutputDevice& rDevice,
185cdf0e10cSrcweir     const Point& rAnchor1,
186cdf0e10cSrcweir     const Point& rAnchor2,
187cdf0e10cSrcweir     const OffsetBitmap& rCornerBitmap1,
188cdf0e10cSrcweir     const OffsetBitmap& rCornerBitmap2) const
189cdf0e10cSrcweir {
190cdf0e10cSrcweir     if (maBitmap.IsEmpty())
191cdf0e10cSrcweir         return;
192cdf0e10cSrcweir 
193cdf0e10cSrcweir     const Size aBitmapSize (maBitmap.GetSizePixel());
194cdf0e10cSrcweir     if (rAnchor1.Y() == rAnchor2.Y())
195cdf0e10cSrcweir     {
196cdf0e10cSrcweir         // Side is horizontal.
197cdf0e10cSrcweir         const sal_Int32 nY (rAnchor1.Y() + maOffset.Y());
198cdf0e10cSrcweir         const sal_Int32 nLeft (
199cdf0e10cSrcweir             rAnchor1.X()
200cdf0e10cSrcweir             + rCornerBitmap1.maBitmap.GetSizePixel().Width()
201cdf0e10cSrcweir             + rCornerBitmap1.maOffset.X());
202cdf0e10cSrcweir         const sal_Int32 nRight (
203cdf0e10cSrcweir             rAnchor2.X()
204cdf0e10cSrcweir             + rCornerBitmap2.maOffset.X()\
205cdf0e10cSrcweir             - 1);
206cdf0e10cSrcweir         for (sal_Int32 nX=nLeft; nX<=nRight; nX+=aBitmapSize.Width())
207cdf0e10cSrcweir         {
208cdf0e10cSrcweir             rDevice.DrawBitmapEx(
209cdf0e10cSrcweir                 Point(nX,nY),
210cdf0e10cSrcweir                 Size(std::min(aBitmapSize.Width(),static_cast<long>(nRight-nX+1)),aBitmapSize.Height()),
211cdf0e10cSrcweir                 maBitmap);
212cdf0e10cSrcweir         }
213cdf0e10cSrcweir     }
214cdf0e10cSrcweir     else if (rAnchor1.X() == rAnchor2.X())
215cdf0e10cSrcweir     {
216cdf0e10cSrcweir         // Side is vertical.
217cdf0e10cSrcweir         const sal_Int32 nX (rAnchor1.X() + maOffset.X());
218cdf0e10cSrcweir         const sal_Int32 nTop (
219cdf0e10cSrcweir             rAnchor1.Y()
220cdf0e10cSrcweir             + rCornerBitmap1.maBitmap.GetSizePixel().Height()
221cdf0e10cSrcweir             + rCornerBitmap1.maOffset.Y());
222cdf0e10cSrcweir         const sal_Int32 nBottom (
223cdf0e10cSrcweir             rAnchor2.Y()
224cdf0e10cSrcweir             + rCornerBitmap2.maOffset.Y()
225cdf0e10cSrcweir             - 1);
226cdf0e10cSrcweir         for (sal_Int32 nY=nTop; nY<=nBottom; nY+=aBitmapSize.Height())
227cdf0e10cSrcweir         {
228cdf0e10cSrcweir             rDevice.DrawBitmapEx(
229cdf0e10cSrcweir                 Point(nX,nY),
230cdf0e10cSrcweir                 Size(aBitmapSize.Width(), std::min(aBitmapSize.Height(), static_cast<long>(nBottom-nY+1))),
231cdf0e10cSrcweir                 maBitmap);
232cdf0e10cSrcweir         }
233cdf0e10cSrcweir     }
234cdf0e10cSrcweir     else
235cdf0e10cSrcweir     {
236cdf0e10cSrcweir         // Diagonal sides indicatee an error.
237cdf0e10cSrcweir         OSL_ASSERT(false);
238cdf0e10cSrcweir     }
239cdf0e10cSrcweir }
240cdf0e10cSrcweir 
241cdf0e10cSrcweir 
242cdf0e10cSrcweir 
243cdf0e10cSrcweir 
PaintCenter(OutputDevice & rDevice,const Rectangle & rBox) const244cdf0e10cSrcweir void FramePainter::OffsetBitmap::PaintCenter (
245cdf0e10cSrcweir     OutputDevice& rDevice,
246cdf0e10cSrcweir     const Rectangle& rBox) const
247cdf0e10cSrcweir {
248cdf0e10cSrcweir     const Size aBitmapSize (maBitmap.GetSizePixel());
249cdf0e10cSrcweir     for (sal_Int32 nY=rBox.Top(); nY<=rBox.Bottom(); nY+=aBitmapSize.Height())
250cdf0e10cSrcweir         for (sal_Int32 nX=rBox.Left(); nX<=rBox.Right(); nX+=aBitmapSize.Width())
251cdf0e10cSrcweir             rDevice.DrawBitmapEx(
252cdf0e10cSrcweir                 Point(nX,nY),
253cdf0e10cSrcweir                 Size(
254cdf0e10cSrcweir                     ::std::min(aBitmapSize.Width(), rBox.Right()-nX+1),
255cdf0e10cSrcweir                     std::min(aBitmapSize.Height(), rBox.Bottom()-nY+1)),
256cdf0e10cSrcweir                 maBitmap);
257cdf0e10cSrcweir }
258cdf0e10cSrcweir 
259cdf0e10cSrcweir 
260cdf0e10cSrcweir 
261cdf0e10cSrcweir } } } // end of namespace sd::slidesorter::view
262