1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 "SlsFramePainter.hxx"
21 #include <vcl/outdev.hxx>
22 #include <vcl/bitmapaccess.hxx>
23 #include <osl/diagnose.h>
25 namespace sd
{ namespace slidesorter
{ namespace view
{
27 FramePainter::FramePainter (const BitmapEx
& rShadowBitmap
)
28 : maTopLeft(rShadowBitmap
,-1,-1),
29 maTop(rShadowBitmap
,0,-1),
30 maTopRight(rShadowBitmap
,+1,-1),
31 maLeft(rShadowBitmap
,-1,0),
32 maRight(rShadowBitmap
,+1,0),
33 maBottomLeft(rShadowBitmap
,-1,+1),
34 maBottom(rShadowBitmap
,0,+1),
35 maBottomRight(rShadowBitmap
,+1,+1),
36 maCenter(rShadowBitmap
,0,0),
39 if (rShadowBitmap
.GetSizePixel().Width() == rShadowBitmap
.GetSizePixel().Height()
40 && (rShadowBitmap
.GetSizePixel().Width()-1)%2 == 0
41 && ((rShadowBitmap
.GetSizePixel().Width()-1)/2)%2 == 1)
47 OSL_ASSERT(rShadowBitmap
.GetSizePixel().Width() == rShadowBitmap
.GetSizePixel().Height());
48 OSL_ASSERT((rShadowBitmap
.GetSizePixel().Width()-1)%2 == 0);
49 OSL_ASSERT(((rShadowBitmap
.GetSizePixel().Width()-1)/2)%2 == 1);
53 FramePainter::~FramePainter()
57 void FramePainter::PaintFrame (
58 OutputDevice
& rDevice
,
59 const ::tools::Rectangle
& rBox
) const
65 maTopLeft
.PaintCorner(rDevice
, rBox
.TopLeft());
66 maTopRight
.PaintCorner(rDevice
, rBox
.TopRight());
67 maBottomLeft
.PaintCorner(rDevice
, rBox
.BottomLeft());
68 maBottomRight
.PaintCorner(rDevice
, rBox
.BottomRight());
69 maLeft
.PaintSide(rDevice
, rBox
.TopLeft(), rBox
.BottomLeft(), maTopLeft
, maBottomLeft
);
70 maRight
.PaintSide(rDevice
, rBox
.TopRight(), rBox
.BottomRight(), maTopRight
, maBottomRight
);
71 maTop
.PaintSide(rDevice
, rBox
.TopLeft(), rBox
.TopRight(), maTopLeft
, maTopRight
);
72 maBottom
.PaintSide(rDevice
, rBox
.BottomLeft(), rBox
.BottomRight(), maBottomLeft
, maBottomRight
);
73 maCenter
.PaintCenter(rDevice
,rBox
);
76 void FramePainter::AdaptColor (
77 const Color aNewColor
)
79 // Get the source color.
80 if (maCenter
.maBitmap
.IsEmpty())
82 const Color aSourceColor
= maCenter
.maBitmap
.GetPixelColor(0,0);
84 // Erase the center bitmap.
85 maCenter
.maBitmap
.SetEmpty();
87 // Replace the color in all bitmaps.
88 maTopLeft
.maBitmap
.Replace(aSourceColor
, aNewColor
);
89 maTop
.maBitmap
.Replace(aSourceColor
, aNewColor
);
90 maTopRight
.maBitmap
.Replace(aSourceColor
, aNewColor
);
91 maLeft
.maBitmap
.Replace(aSourceColor
, aNewColor
);
92 maCenter
.maBitmap
.Replace(aSourceColor
, aNewColor
);
93 maRight
.maBitmap
.Replace(aSourceColor
, aNewColor
);
94 maBottomLeft
.maBitmap
.Replace(aSourceColor
, aNewColor
);
95 maBottom
.maBitmap
.Replace(aSourceColor
, aNewColor
);
96 maBottomRight
.maBitmap
.Replace(aSourceColor
, aNewColor
);
99 //===== FramePainter::OffsetBitmap ============================================
101 FramePainter::OffsetBitmap::OffsetBitmap (
102 const BitmapEx
& rBitmap
,
103 const sal_Int32 nHorizontalPosition
,
104 const sal_Int32 nVerticalPosition
)
108 OSL_ASSERT(nHorizontalPosition
>=-1 && nHorizontalPosition
<=+1);
109 OSL_ASSERT(nVerticalPosition
>=-1 && nVerticalPosition
<=+1);
111 const sal_Int32
nS (1);
112 const sal_Int32
nC (::std::max
<sal_Int32
>(0,(rBitmap
.GetSizePixel().Width()-nS
)/2));
113 const sal_Int32
nO (nC
/2);
116 nHorizontalPosition
<0 ? 0 : (nHorizontalPosition
== 0 ? nC
: nC
+nS
),
117 nVerticalPosition
<0 ? 0 : (nVerticalPosition
== 0 ? nC
: nC
+nS
));
119 nHorizontalPosition
==0 ? nS
: nC
,
120 nVerticalPosition
==0 ? nS
: nC
);
121 maBitmap
= BitmapEx(rBitmap
, aOrigin
, aSize
);
122 if (maBitmap
.IsEmpty())
125 nHorizontalPosition
<0 ? -nO
: nHorizontalPosition
>0 ? -nO
: 0,
126 nVerticalPosition
<0 ? -nO
: nVerticalPosition
>0 ? -nO
: 0);
128 // Enlarge the side bitmaps so that painting the frame requires less
130 const sal_Int32
nSideBitmapSize (64);
131 if (nHorizontalPosition
== 0 && nVerticalPosition
== 0)
133 maBitmap
.Scale(Size(nSideBitmapSize
,nSideBitmapSize
));
135 else if (nHorizontalPosition
== 0)
137 maBitmap
.Scale(Size(nSideBitmapSize
,aSize
.Height()));
139 else if (nVerticalPosition
== 0)
141 maBitmap
.Scale(Size(maBitmap
.GetSizePixel().Width(), nSideBitmapSize
));
145 void FramePainter::OffsetBitmap::PaintCorner (
146 OutputDevice
& rDevice
,
147 const Point
& rAnchor
) const
149 if ( ! maBitmap
.IsEmpty())
150 rDevice
.DrawBitmapEx(rAnchor
+maOffset
, maBitmap
);
153 void FramePainter::OffsetBitmap::PaintSide (
154 OutputDevice
& rDevice
,
155 const Point
& rAnchor1
,
156 const Point
& rAnchor2
,
157 const OffsetBitmap
& rCornerBitmap1
,
158 const OffsetBitmap
& rCornerBitmap2
) const
160 if (maBitmap
.IsEmpty())
163 const Size
aBitmapSize (maBitmap
.GetSizePixel());
164 if (rAnchor1
.Y() == rAnchor2
.Y())
166 // Side is horizontal.
167 const sal_Int32
nY (rAnchor1
.Y() + maOffset
.Y());
168 const sal_Int32
nLeft (
170 + rCornerBitmap1
.maBitmap
.GetSizePixel().Width()
171 + rCornerBitmap1
.maOffset
.X());
172 const sal_Int32
nRight (
174 + rCornerBitmap2
.maOffset
.X()
176 for (sal_Int32 nX
=nLeft
; nX
<=nRight
; nX
+=aBitmapSize
.Width())
178 rDevice
.DrawBitmapEx(
180 Size(std::min(aBitmapSize
.Width(),static_cast<long>(nRight
-nX
+1)),aBitmapSize
.Height()),
184 else if (rAnchor1
.X() == rAnchor2
.X())
187 const sal_Int32
nX (rAnchor1
.X() + maOffset
.X());
188 const sal_Int32
nTop (
190 + rCornerBitmap1
.maBitmap
.GetSizePixel().Height()
191 + rCornerBitmap1
.maOffset
.Y());
192 const sal_Int32
nBottom (
194 + rCornerBitmap2
.maOffset
.Y()
196 for (sal_Int32 nY
=nTop
; nY
<=nBottom
; nY
+=aBitmapSize
.Height())
198 rDevice
.DrawBitmapEx(
200 Size(aBitmapSize
.Width(), std::min(aBitmapSize
.Height(), static_cast<long>(nBottom
-nY
+1))),
206 // Diagonal sides indicates an error.
211 void FramePainter::OffsetBitmap::PaintCenter (
212 OutputDevice
& rDevice
,
213 const ::tools::Rectangle
& rBox
) const
215 const Size
aBitmapSize (maBitmap
.GetSizePixel());
216 for (long nY
=rBox
.Top(); nY
<=rBox
.Bottom(); nY
+=aBitmapSize
.Height())
217 for (long nX
=rBox
.Left(); nX
<=rBox
.Right(); nX
+=aBitmapSize
.Width())
218 rDevice
.DrawBitmapEx(
221 ::std::min(aBitmapSize
.Width(), rBox
.Right()-nX
+1),
222 std::min(aBitmapSize
.Height(), rBox
.Bottom()-nY
+1)),
226 } } } // end of namespace sd::slidesorter::view
228 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */