LibreOffice Module sd (master) 1
SlsFramePainter.cxx
Go to the documentation of this file.
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#include "SlsFramePainter.hxx"
21#include <vcl/outdev.hxx>
22#include <osl/diagnose.h>
23
24namespace sd::slidesorter::view {
25
27 : maTopLeft(rShadowBitmap,-1,-1),
28 maTop(rShadowBitmap,0,-1),
29 maTopRight(rShadowBitmap,+1,-1),
30 maLeft(rShadowBitmap,-1,0),
31 maRight(rShadowBitmap,+1,0),
32 maBottomLeft(rShadowBitmap,-1,+1),
33 maBottom(rShadowBitmap,0,+1),
34 maBottomRight(rShadowBitmap,+1,+1),
35 maCenter(rShadowBitmap,0,0),
36 mbIsValid(false)
37{
38 if (rShadowBitmap.GetSizePixel().Width() == rShadowBitmap.GetSizePixel().Height()
39 && (rShadowBitmap.GetSizePixel().Width()-1)%2 == 0
40 && ((rShadowBitmap.GetSizePixel().Width()-1)/2)%2 == 1)
41 {
42 mbIsValid = true;
43 }
44 else
45 {
46 OSL_ASSERT(rShadowBitmap.GetSizePixel().Width() == rShadowBitmap.GetSizePixel().Height());
47 OSL_ASSERT((rShadowBitmap.GetSizePixel().Width()-1)%2 == 0);
48 OSL_ASSERT(((rShadowBitmap.GetSizePixel().Width()-1)/2)%2 == 1);
49 }
50}
51
53{
54}
55
57 OutputDevice& rDevice,
58 const ::tools::Rectangle& rBox) const
59{
60 if ( ! mbIsValid)
61 return;
62
63 // Paint the shadow.
64 maTopLeft.PaintCorner(rDevice, rBox.TopLeft());
65 maTopRight.PaintCorner(rDevice, rBox.TopRight());
66 maBottomLeft.PaintCorner(rDevice, rBox.BottomLeft());
67 maBottomRight.PaintCorner(rDevice, rBox.BottomRight());
68 maLeft.PaintSide(rDevice, rBox.TopLeft(), rBox.BottomLeft(), maTopLeft, maBottomLeft);
69 maRight.PaintSide(rDevice, rBox.TopRight(), rBox.BottomRight(), maTopRight, maBottomRight);
70 maTop.PaintSide(rDevice, rBox.TopLeft(), rBox.TopRight(), maTopLeft, maTopRight);
71 maBottom.PaintSide(rDevice, rBox.BottomLeft(), rBox.BottomRight(), maBottomLeft, maBottomRight);
72 maCenter.PaintCenter(rDevice,rBox);
73}
74
76 const Color aNewColor)
77{
78 // Get the source color.
80 return;
81 const Color aSourceColor = maCenter.maBitmap.GetPixelColor(0,0);
82
83 // Erase the center bitmap.
85
86 // Replace the color in all bitmaps.
87 maTopLeft.maBitmap.Replace(aSourceColor, aNewColor);
88 maTop.maBitmap.Replace(aSourceColor, aNewColor);
89 maTopRight.maBitmap.Replace(aSourceColor, aNewColor);
90 maLeft.maBitmap.Replace(aSourceColor, aNewColor);
91 maCenter.maBitmap.Replace(aSourceColor, aNewColor);
92 maRight.maBitmap.Replace(aSourceColor, aNewColor);
93 maBottomLeft.maBitmap.Replace(aSourceColor, aNewColor);
94 maBottom.maBitmap.Replace(aSourceColor, aNewColor);
95 maBottomRight.maBitmap.Replace(aSourceColor, aNewColor);
96}
97
98//===== FramePainter::OffsetBitmap ============================================
99
101 const BitmapEx& rBitmap,
102 const sal_Int32 nHorizontalPosition,
103 const sal_Int32 nVerticalPosition)
104{
105 OSL_ASSERT(nHorizontalPosition>=-1 && nHorizontalPosition<=+1);
106 OSL_ASSERT(nVerticalPosition>=-1 && nVerticalPosition<=+1);
107
108 const sal_Int32 nS (1);
109 const sal_Int32 nC (::std::max<sal_Int32>(0,(rBitmap.GetSizePixel().Width()-nS)/2));
110 const sal_Int32 nO (nC/2);
111
112 const Point aOrigin(
113 nHorizontalPosition<0 ? 0 : (nHorizontalPosition == 0 ? nC : nC+nS),
114 nVerticalPosition<0 ? 0 : (nVerticalPosition == 0 ? nC : nC+nS));
115 const Size aSize(
116 nHorizontalPosition==0 ? nS : nC,
117 nVerticalPosition==0 ? nS : nC);
118 maBitmap = BitmapEx(rBitmap, aOrigin, aSize);
119 if (maBitmap.IsEmpty())
120 return;
121 maOffset = Point(
122 nHorizontalPosition<0 ? -nO : nHorizontalPosition>0 ? -nO : 0,
123 nVerticalPosition<0 ? -nO : nVerticalPosition>0 ? -nO : 0);
124
125 // Enlarge the side bitmaps so that painting the frame requires less
126 // paint calls.
127 const sal_Int32 nSideBitmapSize (64);
128 if (nHorizontalPosition == 0 && nVerticalPosition == 0)
129 {
130 maBitmap.Scale(Size(nSideBitmapSize,nSideBitmapSize));
131 }
132 else if (nHorizontalPosition == 0)
133 {
134 maBitmap.Scale(Size(nSideBitmapSize,aSize.Height()));
135 }
136 else if (nVerticalPosition == 0)
137 {
138 maBitmap.Scale(Size(maBitmap.GetSizePixel().Width(), nSideBitmapSize));
139 }
140}
141
143 OutputDevice& rDevice,
144 const Point& rAnchor) const
145{
146 if ( ! maBitmap.IsEmpty())
147 rDevice.DrawBitmapEx(rAnchor+maOffset, maBitmap);
148}
149
151 OutputDevice& rDevice,
152 const Point& rAnchor1,
153 const Point& rAnchor2,
154 const OffsetBitmap& rCornerBitmap1,
155 const OffsetBitmap& rCornerBitmap2) const
156{
157 if (maBitmap.IsEmpty())
158 return;
159
160 const Size aBitmapSize (maBitmap.GetSizePixel());
161 if (rAnchor1.Y() == rAnchor2.Y())
162 {
163 // Side is horizontal.
164 const sal_Int32 nY (rAnchor1.Y() + maOffset.Y());
165 const sal_Int32 nLeft (
166 rAnchor1.X()
167 + rCornerBitmap1.maBitmap.GetSizePixel().Width()
168 + rCornerBitmap1.maOffset.X());
169 const sal_Int32 nRight (
170 rAnchor2.X()
171 + rCornerBitmap2.maOffset.X()
172 - 1);
173 for (sal_Int32 nX=nLeft; nX<=nRight; nX+=aBitmapSize.Width())
174 {
175 rDevice.DrawBitmapEx(
176 Point(nX,nY),
177 Size(std::min(aBitmapSize.Width(),static_cast<::tools::Long>(nRight-nX+1)),aBitmapSize.Height()),
178 maBitmap);
179 }
180 }
181 else if (rAnchor1.X() == rAnchor2.X())
182 {
183 // Side is vertical.
184 const sal_Int32 nX (rAnchor1.X() + maOffset.X());
185 const sal_Int32 nTop (
186 rAnchor1.Y()
187 + rCornerBitmap1.maBitmap.GetSizePixel().Height()
188 + rCornerBitmap1.maOffset.Y());
189 const sal_Int32 nBottom (
190 rAnchor2.Y()
191 + rCornerBitmap2.maOffset.Y()
192 - 1);
193 for (sal_Int32 nY=nTop; nY<=nBottom; nY+=aBitmapSize.Height())
194 {
195 rDevice.DrawBitmapEx(
196 Point(nX,nY),
197 Size(aBitmapSize.Width(), std::min(aBitmapSize.Height(), static_cast<::tools::Long>(nBottom-nY+1))),
198 maBitmap);
199 }
200 }
201 else
202 {
203 // Diagonal sides indicates an error.
204 OSL_ASSERT(false);
205 }
206}
207
209 OutputDevice& rDevice,
210 const ::tools::Rectangle& rBox) const
211{
212 const Size aBitmapSize (maBitmap.GetSizePixel());
213 for (::tools::Long nY=rBox.Top(); nY<=rBox.Bottom(); nY+=aBitmapSize.Height())
214 for (::tools::Long nX=rBox.Left(); nX<=rBox.Right(); nX+=aBitmapSize.Width())
215 rDevice.DrawBitmapEx(
216 Point(nX,nY),
217 Size(
218 ::std::min(aBitmapSize.Width(), rBox.Right()-nX+1),
219 std::min(aBitmapSize.Height(), rBox.Bottom()-nY+1)),
220 maBitmap);
221}
222
223} // end of namespace sd::slidesorter::view
224
225/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
LineDescriptorList maRight
LineDescriptorList maLeft
bool Scale(const Size &rNewSize, BmpScaleFlag nScaleFlag=BmpScaleFlag::Default)
::Color GetPixelColor(sal_Int32 nX, sal_Int32 nY) const
bool IsEmpty() const
void Replace(const Color &rSearchColor, const Color &rReplaceColor)
const Size & GetSizePixel() const
void SetEmpty()
void DrawBitmapEx(const Point &rDestPt, const BitmapEx &rBitmapEx)
constexpr tools::Long Y() const
constexpr tools::Long X() const
constexpr tools::Long Height() const
constexpr tools::Long Width() const
Bitmap with offset that is used when the bitmap is painted.
OffsetBitmap(const BitmapEx &rBitmap, const sal_Int32 nHorizontalPosition, const sal_Int32 nVerticalPosition)
Create one of the eight shadow bitmaps from one that combines them all.
void PaintSide(OutputDevice &rDevice, const Point &rAnchor1, const Point &rAnchor2, const OffsetBitmap &rCornerBitmap1, const OffsetBitmap &rCornerBitmap2) const
Use the given device to paint the bitmap stretched between the two given locations.
void PaintCenter(OutputDevice &rDevice, const ::tools::Rectangle &rBox) const
Fill the given rectangle with the bitmap.
void PaintCorner(OutputDevice &rDevice, const Point &rAnchor) const
Use the given device to paint the bitmap at the location that is the sum of the given anchor and the ...
void AdaptColor(const Color aNewColor)
Special functionality that takes the color from the center bitmap and replaces that color in all bitm...
void PaintFrame(OutputDevice &rDevice, const ::tools::Rectangle &rBox) const
Paint a border around the given box by using a set of bitmaps for the corners and sides.
FramePainter(const BitmapEx &rBitmap)
Style maTop
Style maBottom
long Long