Update contrib.
2 * Copyright (c) 1996-2009 Nokia Corporation and/or its subsidiary(-ies).
4 * This component and the accompanying materials are made available
5 * under the terms of "Eclipse Public License v1.0"
6 * which accompanies this distribution, and is available
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
9 * Initial Contributors:
10 * Nokia Corporation - initial contribution.
21 const TInt KBorderThicknessInPixels=2;
23 /** This constructs a TFrameOverlay, clearing all flags and initializing both
24 blob widths to zero. */
25 EXPORT_C TFrameOverlay::TFrameOverlay()
26 :iFlags(0),iVisibleBlobWidth(0),iActiveBlobWidth(0)
30 /** Sets the visible and active blob widths to the same value in pixels.
31 @param aWidth The visible and active blob width in pixels. */
32 EXPORT_C void TFrameOverlay::SetBlobWidthInPixels(const TInt aWidth)
34 SetVisibleBlobWidthInPixels(aWidth);
35 SetActiveBlobWidthInPixels(aWidth);
38 /** Sets the visible blob width in pixels.
39 @param aWidth The visible blob width in pixels. */
40 EXPORT_C void TFrameOverlay::SetVisibleBlobWidthInPixels(const TInt aWidth)
42 iVisibleBlobWidth=aWidth;
45 /** Sets the active blob width in pixels. The active blob width should normally
46 be at least as large as the visible blob width.
47 @param aWidth The active blob width in pixels. */
48 EXPORT_C void TFrameOverlay::SetActiveBlobWidthInPixels(const TInt aWidth)
50 iActiveBlobWidth=aWidth;
53 /** Sets the flags which control how the frame is drawn. Adds the flags
54 specified to the existing flag settings, which are preserved. For a description
55 of the available flags, see the TFrameOverlayFlags enum.
56 @param aFlag Flags to add to the existing settings. */
57 EXPORT_C void TFrameOverlay::SetFlags(TInt aFlag)
62 /** Clears the flags specified from the frame's flag settings. For a description
63 of the available flags, see the TFrameOverlayFlags enum.
64 @param aFlag Flags to clear from the existing flag settings. */
65 EXPORT_C void TFrameOverlay::ClearFlags(TInt aFlag)
72 EXPORT_C void TFrameOverlay::SetRect(const TRect& aRect)
73 /** Sets the picture frame rectangle.
75 @param aRect The picture frame rectangle. */
80 /** Draws the picture frame and blobs to a graphics context using the frame's
81 flag settings. If drawn, the frame is represented by a dotted line. The
82 operation uses a draw mode of CGraphicsContext::EDrawModeNOTSCREEN so that the
83 colour of each pixel which is drawn over is inverted. The frame's coordinates
84 are set using SetRect().
85 @param aGc The graphics context to draw to. */
86 EXPORT_C void TFrameOverlay::XorDraw(CGraphicsContext& aGc) const
89 TInt blobWidth=VisibleBlobWidth();
90 if (iFlags&EFrameOverlayFlagBlobsInternal)
91 rect.Shrink(blobWidth,blobWidth);
94 aGc.SetDrawMode(CGraphicsContext::EDrawModeNOTSCREEN);
95 aGc.SetBrushStyle(CGraphicsContext::ENullBrush);
97 if (iFlags&EFrameOverlayFlagShowBorder)
99 rect.Grow(blobWidth,blobWidth);
100 DrawDottedRectangle(aGc, rect);
105 TInt width=br.iX-tl.iX;
106 TInt height=br.iY-tl.iY;
108 aGc.SetPenStyle(CGraphicsContext::ESolidPen);
109 if (!(iFlags&EFrameOverlayFlagTopBlobsDimmed) && !(iFlags&EFrameOverlayFlagLeftBlobsDimmed))
110 aGc.SetBrushStyle(CGraphicsContext::ESolidBrush);
111 aGc.DrawRect(TRect(tl-TPoint(blobWidth,blobWidth),tl));
112 aGc.SetBrushStyle(CGraphicsContext::ENullBrush);
114 if (DrawTopAndBottom())
116 if (!(iFlags&EFrameOverlayFlagTopBlobsDimmed))
117 aGc.SetBrushStyle(CGraphicsContext::ESolidBrush);
118 aGc.DrawRect(TRect(tl+TPoint((width-blobWidth)/2,-blobWidth),tl+TPoint((width+blobWidth)/2,0)));
119 aGc.SetBrushStyle(CGraphicsContext::ENullBrush);
122 if (!(iFlags&EFrameOverlayFlagTopBlobsDimmed) && !(iFlags&EFrameOverlayFlagRightBlobsDimmed))
123 aGc.SetBrushStyle(CGraphicsContext::ESolidBrush);
125 aGc.DrawRect(TRect(TPoint(br.iX,tl.iY-blobWidth),TPoint(br.iX+blobWidth,tl.iY)));
126 aGc.SetBrushStyle(CGraphicsContext::ENullBrush);
128 if (DrawLeftAndRight())
130 if (!(iFlags&EFrameOverlayFlagRightBlobsDimmed))
131 aGc.SetBrushStyle(CGraphicsContext::ESolidBrush);
132 aGc.DrawRect(TRect(br-TPoint(0,(height+blobWidth)/2),br+TPoint(blobWidth,-(height-blobWidth)/2)));
133 aGc.SetBrushStyle(CGraphicsContext::ENullBrush);
136 if (!(iFlags&EFrameOverlayFlagRightBlobsDimmed) && !(iFlags&EFrameOverlayFlagBottomBlobsDimmed))
137 aGc.SetBrushStyle(CGraphicsContext::ESolidBrush);
138 aGc.DrawRect(TRect(br,br+TPoint(blobWidth,blobWidth)));
139 aGc.SetBrushStyle(CGraphicsContext::ENullBrush);
141 if (DrawTopAndBottom())
143 if (!(iFlags&EFrameOverlayFlagBottomBlobsDimmed))
144 aGc.SetBrushStyle(CGraphicsContext::ESolidBrush);
145 aGc.DrawRect(TRect(br-TPoint((width+blobWidth)/2,0),br-TPoint((width-blobWidth)/2,-blobWidth)));
146 aGc.SetBrushStyle(CGraphicsContext::ENullBrush);
149 if (!(iFlags&EFrameOverlayFlagBottomBlobsDimmed) && !(iFlags&EFrameOverlayFlagLeftBlobsDimmed))
150 aGc.SetBrushStyle(CGraphicsContext::ESolidBrush);
151 aGc.DrawRect(TRect(TPoint(tl.iX-blobWidth,br.iY),TPoint(tl.iX,br.iY+blobWidth)));
152 aGc.SetBrushStyle(CGraphicsContext::ENullBrush);
154 if (DrawLeftAndRight())
156 if (!(iFlags&EFrameOverlayFlagLeftBlobsDimmed))
157 aGc.SetBrushStyle(CGraphicsContext::ESolidBrush);
158 aGc.DrawRect(TRect(tl+TPoint(-blobWidth,(height-blobWidth)/2),tl+TPoint(0,(height+blobWidth)/2)));
159 aGc.SetBrushStyle(CGraphicsContext::ENullBrush);
163 aGc.SetDrawMode(CGraphicsContext::EDrawModePEN);
166 /** Gets the active region in which a pixel position is located.
168 Note: Adjacent active regions overlap at the corners of the picture frame, so
169 that a pixel position may be located within more than one active region.
171 @param aPos A pixel position.
172 @return The active area(s) within which the position specified is located. Zero
173 if not located within any active area. For details, see the TEdges enumeration,
175 EXPORT_C TInt TFrameOverlay::XyPosToEdges(const TPoint& aPos) const
177 TInt visibleBlobWidth=VisibleBlobWidth();
178 TInt marginWidth=ActiveMarginWidth();
179 TInt edgesTouched=ENoEdges;
180 TRect frameOuterRect=iRect;
181 TRect frameInnerRect=iRect;
182 frameOuterRect.Grow(marginWidth,marginWidth);
183 frameInnerRect.Shrink(marginWidth,marginWidth);
184 if (iFlags&EFrameOverlayFlagBlobsInternal)
185 frameInnerRect.Shrink(visibleBlobWidth,visibleBlobWidth);
187 frameOuterRect.Grow(visibleBlobWidth,visibleBlobWidth);
188 TRect rightRect(TPoint(frameInnerRect.iBr.iX,frameOuterRect.iTl.iY),frameOuterRect.iBr);
189 TRect leftRect(frameOuterRect.iTl,TPoint(frameInnerRect.iTl.iX,frameOuterRect.iBr.iY));
190 if (rightRect.Contains(aPos))
191 edgesTouched|=EEdgeRight;
192 else if (leftRect.Contains(aPos))
193 edgesTouched|=EEdgeLeft;
194 TRect topRect(frameOuterRect.iTl,TPoint(frameOuterRect.iBr.iX,frameInnerRect.iTl.iY));
195 TRect bottomRect(TPoint(frameOuterRect.iTl.iX,frameInnerRect.iBr.iY),frameOuterRect.iBr);
196 if (topRect.Contains(aPos))
197 edgesTouched|=EEdgeTop;
198 else if (bottomRect.Contains(aPos))
199 edgesTouched|=EEdgeBottom;
200 return(edgesTouched);
204 TInt TFrameOverlay::VisibleBlobWidth() const
206 if (iFlags&EFrameOverlayFlagBlobsInternal)
207 return Min(Min(iRect.Width(),iRect.Height())/3,(TInt) iVisibleBlobWidth);
209 return iVisibleBlobWidth;
212 TInt TFrameOverlay::ActiveMarginWidth() const
214 TInt margin=(iActiveBlobWidth-VisibleBlobWidth())/2;
215 if (iFlags&EFrameOverlayFlagBlobsInternal)
216 return Min(Min(iRect.Width(),iRect.Height())/3-VisibleBlobWidth(),margin);
218 return Min(Min(iRect.Width(),iRect.Height())/3,margin);
222 TBool TFrameOverlay::DrawLeftAndRight() const
224 if (iFlags&EFrameOverlayFlagBlobsInternal)
225 return (iRect.Height()>3*iVisibleBlobWidth);
227 return (iRect.Height()>iVisibleBlobWidth);
230 TBool TFrameOverlay::DrawTopAndBottom() const
232 if (iFlags&EFrameOverlayFlagBlobsInternal)
233 return (iRect.Width()>3*iVisibleBlobWidth);
235 return (iRect.Width()>iVisibleBlobWidth);
238 void TFrameOverlay::DrawDottedRectangle(CGraphicsContext& aGc,const TRect& aRect) const
240 TInt dashWidth=KBorderThicknessInPixels;
241 TInt dashLength=KBorderThicknessInPixels;
242 TInt horizontalDashes=(aRect.Width()+dashLength-dashWidth)/(2*dashLength);
243 TInt verticalDashes=(aRect.Height()+dashLength-dashWidth)/(2*dashLength);
244 aGc.SetPenStyle(CGraphicsContext::ENullPen);
245 aGc.SetBrushStyle(CGraphicsContext::ESolidBrush);
246 TPoint move(2*dashLength,0);
247 TRect drawRect(aRect.iTl,TSize(dashLength,dashWidth));
249 {for (TInt ii=0;ii<horizontalDashes;ii++)
251 aGc.DrawRect(drawRect);
256 move.SetXY(0,2*dashLength);
257 drawRect.SetRect(TPoint(aRect.iBr.iX-dashWidth,aRect.iTl.iY),TSize(dashWidth,dashLength));
259 {for (TInt ii=0;ii<verticalDashes;ii++)
261 aGc.DrawRect(drawRect);
266 move.SetXY(-2*dashLength,0);
267 drawRect.SetRect(TPoint(aRect.iBr.iX-dashLength,aRect.iBr.iY-dashWidth),TSize(dashLength,dashWidth));
269 {for (TInt ii=0;ii<horizontalDashes;ii++)
271 aGc.DrawRect(drawRect);
276 move.SetXY(0,-2*dashLength);
277 drawRect.SetRect(TPoint(aRect.iTl.iX,aRect.iBr.iY-dashLength),TSize(dashWidth,dashLength));
279 {for (TInt ii=0;ii<verticalDashes;ii++)
281 aGc.DrawRect(drawRect);