1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 #ifndef SD_SLIDESORTER_VIEW_FRAME_PAINTER_HXX
25 #define SD_SLIDESORTER_VIEW_FRAME_PAINTER_HXX
26 
27 #include <vcl/bitmapex.hxx>
28 
29 
30 namespace sd { namespace slidesorter { namespace view {
31 
32 class FramePainter
33 {
34 public:
35 	FramePainter (const BitmapEx& rBitmap);
36 	~FramePainter (void);
37 
38 	/** Paint a border around the given box by using a set of bitmaps for
39 		the corners and sides.
40 	*/
41 	void PaintFrame (OutputDevice&rDevice, const Rectangle aBox) const;
42 
43 	/** Special functionality that takes the color from the center
44 		bitmap and replaces that color in all bitmaps by the given new
45 		color. Alpha values are not modified.
46 		@param bClearCenterBitmap
47 			When <TRUE/> then the center bitmap is erased.
48 	*/
49 	void AdaptColor (const Color aNewColor, const bool bClearCenterBitmap);
50 
51 private:
52 	/** Bitmap with offset that is used when the bitmap is painted. The bitmap
53 	*/
54 	class OffsetBitmap {
55 	public:
56 		BitmapEx maBitmap;
57 		Point maOffset;
58 
59 		/** Create one of the eight shadow bitmaps from one that combines
60 			them all. This larger bitmap is expected to have dimension NxN
61 			with N=1+2*M. Of this larger bitmap there are created four
62 			corner bitmaps of size 2*M x 2*M and four side bitmaps of sizes
63 			1xM (top and bottom) and Mx1 (left and right). The corner
64 			bitmaps have each one quadrant of size MxM that is painted under
65 			the interior of the frame.
66 			@param rBitmap
67 				The larger bitmap of which the eight shadow bitmaps are cut
68 				out from.
69 			@param nHorizontalPosition
70 				Valid values are -1 (left), 0 (center), and +1 (right).
71 			@param nVerticalPosition
72 				Valid values are -1 (top), 0 (center), and +1 (bottom).
73 		*/
74 		OffsetBitmap (
75 			const BitmapEx& rBitmap,
76 			const sal_Int32 nHorizontalPosition,
77 			const sal_Int32 nVerticalPosition);
78 
79 		/** Use the given device to paint the bitmap at the location that is
80 			the sum of the given anchor and the internal offset.
81 		*/
82 		void PaintCorner (OutputDevice& rDevice, const Point& rAnchor) const;
83 
84 		/** Use the given device to paint the bitmap stretched between the
85 			two given locations. Offsets of the adjacent corner bitmaps and
86 			the offset of the side bitmap are used to determine the area
87 			that is to be filled with the side bitmap.
88 		*/
89 		void PaintSide (
90 			OutputDevice& rDevice,
91 			const Point& rAnchor1,
92 			const Point& rAnchor2,
93 			const OffsetBitmap& rCornerBitmap1,
94 			const OffsetBitmap& rCornerBitmap2) const;
95 
96 		/** Fill the given rectangle with the bitmap.
97 		*/
98 		void PaintCenter (
99 			OutputDevice& rDevice,
100 			const Rectangle& rBox) const;
101 	};
102 	OffsetBitmap maTopLeft;
103 	OffsetBitmap maTop;
104 	OffsetBitmap maTopRight;
105 	OffsetBitmap maLeft;
106 	OffsetBitmap maRight;
107 	OffsetBitmap maBottomLeft;
108 	OffsetBitmap maBottom;
109 	OffsetBitmap maBottomRight;
110 	OffsetBitmap maCenter;
111 	bool mbIsValid;
112 };
113 
114 
115 } } } // end of namespace sd::slidesorter::view
116 
117 #endif
118