author | Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com> |
Tue, 14 Sep 2010 20:46:07 +0300 | |
branch | RCL_3 |
changeset 57 | 2c87b2808fd7 |
parent 54 | bac7acad7cb3 |
child 67 | 756ad29ed18e |
permissions | -rw-r--r-- |
54 | 1 |
/* |
57
2c87b2808fd7
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
54
diff
changeset
|
2 |
* Copyright (c) 2007-2010 Nokia Corporation and/or its subsidiary(-ies). |
54 | 3 |
* All rights reserved. |
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". |
|
8 |
* |
|
9 |
* Initial Contributors: |
|
10 |
* Nokia Corporation - initial contribution. |
|
11 |
* |
|
12 |
* Contributors: |
|
13 |
* |
|
14 |
* Description: Implemantation for CCamLineVfGridDrawer class. |
|
15 |
* |
|
16 |
*/ |
|
17 |
||
18 |
||
19 |
#include <gdi.h> |
|
20 |
#include "camlinevfgriddrawer.h" |
|
21 |
#include "camlogging.h" |
|
22 |
||
23 |
// ======== LOCAL CONSTANTS ======== |
|
24 |
||
25 |
namespace |
|
26 |
{ |
|
27 |
const TInt KArrayGranularity = 8; |
|
28 |
const TInt KMaxLineCount = 64; |
|
29 |
||
30 |
const TInt KPenColorRed = 255; |
|
31 |
const TInt KPenColorGreen = 0;//255; |
|
32 |
const TInt KPenColorBlue = 0;//255; |
|
33 |
const TInt KPenColorAlpha = 255;//128; |
|
34 |
const TInt KPenWidth = 2; |
|
35 |
const TInt KPenHeight = 2; |
|
36 |
const CGraphicsContext::TPenStyle KPenStyle = CGraphicsContext::ESolidPen; |
|
37 |
} |
|
38 |
||
39 |
// ======== LOCAL FUNCTIONS ======== |
|
40 |
||
41 |
// ======== MEMBER FUNCTIONS ======== |
|
42 |
||
43 |
// =========================================================================== |
|
44 |
// Public part |
|
45 |
||
46 |
// --------------------------------------------------------------------------- |
|
47 |
// static NewL |
|
48 |
// |
|
49 |
// 2-phased constructor |
|
50 |
// --------------------------------------------------------------------------- |
|
51 |
// |
|
52 |
CCamLineVfGridDrawer* |
|
53 |
CCamLineVfGridDrawer::NewL() |
|
54 |
{ |
|
55 |
CCamLineVfGridDrawer* self = new (ELeave) CCamLineVfGridDrawer; |
|
56 |
CleanupStack::PushL( self ); |
|
57 |
self->ConstructL(); |
|
58 |
CleanupStack::Pop( self ); |
|
59 |
return self; |
|
60 |
} |
|
61 |
||
62 |
// --------------------------------------------------------------------------- |
|
63 |
// Destructor |
|
64 |
// --------------------------------------------------------------------------- |
|
65 |
// |
|
66 |
CCamLineVfGridDrawer::~CCamLineVfGridDrawer() |
|
67 |
{ |
|
68 |
PRINT( _L("Camera => ~CCamLineVfGridDrawer") ); |
|
69 |
iLineArray.Reset(); |
|
70 |
iLineArray.Close(); |
|
71 |
PRINT( _L("Camera <= ~CCamLineVfGridDrawer") ); |
|
72 |
} |
|
73 |
||
74 |
||
75 |
||
76 |
// --------------------------------------------------------------------------- |
|
77 |
// virtual InitL |
|
78 |
// * from MCamVfGridDrawer |
|
79 |
// |
|
80 |
// Initialize the drawer. |
|
81 |
// --------------------------------------------------------------------------- |
|
82 |
// |
|
83 |
void |
|
84 |
CCamLineVfGridDrawer::InitL( TAny* /*aParam*/ ) |
|
85 |
{ |
|
86 |
} |
|
87 |
||
88 |
// --------------------------------------------------------------------------- |
|
89 |
// virtual Draw( CBitmapContext& ) |
|
90 |
// * from MCamVfGridDrawer |
|
91 |
// |
|
92 |
// Draw the grid. If not set visible nothing is drawn. |
|
93 |
// --------------------------------------------------------------------------- |
|
94 |
// |
|
95 |
void |
|
96 |
CCamLineVfGridDrawer::Draw( CBitmapContext& aGc ) const |
|
97 |
{ |
|
98 |
if( iVisible && |
|
99 |
iLineArray.Count() > 0 ) |
|
100 |
{ |
|
101 |
// Set drawing properties. |
|
102 |
aGc.SetPenStyle( iPenStyle ); |
|
103 |
aGc.SetPenSize ( iPenSize ); |
|
104 |
aGc.SetPenColor( iPenColor ); |
|
105 |
||
106 |
// Draw the lines |
|
107 |
for( TInt i = 0; i < iLineArray.Count(); i++ ) |
|
108 |
{ |
|
109 |
// Top-left and bottom-right corners of the rect |
|
110 |
// represent the line ends. |
|
111 |
aGc.DrawLine( iLineArray[i].iTl, iLineArray[i].iBr ); |
|
112 |
} |
|
113 |
||
114 |
// Clear any settings made to gc |
|
115 |
aGc.Reset(); |
|
116 |
} |
|
117 |
else |
|
118 |
{ |
|
119 |
// Not visible => draw nothing. |
|
120 |
} |
|
121 |
} |
|
122 |
||
123 |
||
124 |
// --------------------------------------------------------------------------- |
|
125 |
// virtual Draw( const TRect&, CBitmapContext& ) |
|
126 |
// * from MCamVfGridDrawer |
|
127 |
// |
|
128 |
// Draw part of the grid. If not set visible nothing is drawn. |
|
129 |
// Note: |
|
130 |
// Only pure vertical and pure horizontal lines |
|
131 |
// get drawn to right place if lines expand outside |
|
132 |
// the aRect rectangle given here as parameter. |
|
133 |
// --------------------------------------------------------------------------- |
|
134 |
// |
|
135 |
void |
|
136 |
CCamLineVfGridDrawer::Draw( const TRect& aRect, |
|
137 |
CBitmapContext& aGc ) const |
|
138 |
{ |
|
139 |
if( iVisible && |
|
140 |
iLineArray.Count() > 0 ) |
|
141 |
{ |
|
142 |
// Limit the drawing to given rectangle. |
|
143 |
// Drawing outside this rectangle has no visible effect. |
|
144 |
aGc.SetClippingRect( aRect ); |
|
145 |
// Make the same drawing operations as in full screen draw. |
|
146 |
// The drawing is so simple that any optimization is |
|
147 |
// probably more time consuming than the drawing itself. |
|
148 |
// Draw resets the gc in the end, so clipping rect is cleared. |
|
149 |
Draw( aGc ); |
|
150 |
} |
|
151 |
else |
|
152 |
{ |
|
153 |
// Not visible => draw nothing. |
|
154 |
} |
|
155 |
} |
|
156 |
||
157 |
// --------------------------------------------------------------------------- |
|
158 |
// virtual SetVisible |
|
159 |
// * from MCamVfGridDrawer |
|
160 |
// |
|
161 |
// Set visibility of the grid. |
|
162 |
// |
|
163 |
// --------------------------------------------------------------------------- |
|
164 |
// |
|
165 |
void |
|
166 |
CCamLineVfGridDrawer::SetVisible( TBool aVisible ) |
|
167 |
{ |
|
168 |
iVisible = aVisible; |
|
169 |
} |
|
170 |
||
171 |
||
172 |
||
173 |
// --------------------------------------------------------------------------- |
|
174 |
// virtual IsVisible |
|
175 |
// * from MCamVfGridDrawer |
|
176 |
// |
|
177 |
// Get visibility of the grid. |
|
178 |
// |
|
179 |
// --------------------------------------------------------------------------- |
|
180 |
// |
|
181 |
TBool |
|
182 |
CCamLineVfGridDrawer::IsVisible() const |
|
183 |
{ |
|
184 |
return iVisible; |
|
185 |
} |
|
186 |
||
187 |
||
188 |
// --------------------------------------------------------------------------- |
|
189 |
// SetLinesL |
|
190 |
// * from MCamVfGridDrawer |
|
191 |
// |
|
192 |
// Set the line end pair array. |
|
193 |
// --------------------------------------------------------------------------- |
|
194 |
// |
|
195 |
void |
|
196 |
CCamLineVfGridDrawer::SetLinesL( const RLineArray& aLineArray ) |
|
197 |
{ |
|
198 |
TInt newLineCount = aLineArray.Count(); |
|
199 |
if( newLineCount > KMaxLineCount ) |
|
200 |
{ |
|
201 |
User::Leave( KErrArgument ); |
|
202 |
} |
|
203 |
||
204 |
iLineArray.Reset(); |
|
205 |
for( TInt i = 0; i < newLineCount; i++ ) |
|
206 |
{ |
|
207 |
iLineArray.Append( aLineArray[i] ); |
|
208 |
} |
|
209 |
} |
|
210 |
||
211 |
||
212 |
// --------------------------------------------------------------------------- |
|
213 |
// SetLinesL |
|
214 |
// |
|
215 |
// Set the line end pair array by defining the count and bordered property |
|
216 |
// of lines per horizontal and vertical axis. |
|
217 |
// --------------------------------------------------------------------------- |
|
218 |
// |
|
219 |
void |
|
220 |
CCamLineVfGridDrawer::SetLinesL( const TRect& aDrawingRect, |
|
221 |
TInt aHorizontalLines, |
|
222 |
TInt aVerticalLines, |
|
223 |
TBool aBorderedGrid /* = EFalse */) |
|
224 |
{ |
|
225 |
// ------------------------------------------------------- |
|
226 |
// Check the max limit for lines does not exceed. |
|
227 |
if( aHorizontalLines < 0 |
|
228 |
|| aVerticalLines < 0 |
|
229 |
|| aHorizontalLines + aVerticalLines > KMaxLineCount |
|
230 |
) |
|
231 |
{ |
|
232 |
User::Leave( KErrArgument ); |
|
233 |
} |
|
234 |
||
235 |
// ------------------------------------------------------- |
|
236 |
// Fill the line end array |
|
237 |
// |
|
238 |
// The lines are evenly spaced over the draw area axis in question. |
|
239 |
// The aBorderedGrid parameter determines whether the grid |
|
240 |
// draws lines to the borders of draw area: |
|
241 |
// E.g. 3 vertical lines: '[' and ']' are the draw area borders. |
|
242 |
// aBorderedGrid: [| | |] |
|
243 |
// !aBorderedGrid: [ | | | ] |
|
244 |
// |
|
245 |
// The formula for the location of i:th line when N lines |
|
246 |
// are used along dimension D: |
|
247 |
// - aBorderedGrid: ( i * D) / (N - 1) |
|
248 |
// - !aBorderedGrid: ((i+1) * D) / (N + 1) |
|
249 |
// * Divide by (N-1) needs special handling with N=1. |
|
250 |
// * Half of pen width is subtracted from the above formula result |
|
251 |
// to center the line to the calculated location. |
|
252 |
// * odd area or pen width/height may cause error of 1 pixel. |
|
253 |
TInt indexOffset = (aBorderedGrid ? 0 : 1); |
|
254 |
TInt countOffset = (aBorderedGrid ? -1 : 1); |
|
255 |
||
256 |
// ----------------------------------- |
|
257 |
// First horizontal lines |
|
258 |
TInt height = aDrawingRect.Height(); |
|
259 |
TInt leftX = aDrawingRect.iTl.iX; |
|
260 |
TInt rightX = aDrawingRect.iBr.iX; |
|
261 |
||
262 |
TInt i = 0; |
|
263 |
while( i < aHorizontalLines ) |
|
264 |
{ |
|
265 |
// Max used to make sure no div-by-zero |
|
266 |
TInt currentY = ((i+indexOffset)*height) / Max(1,aHorizontalLines+countOffset) - KPenHeight/2; |
|
57
2c87b2808fd7
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
54
diff
changeset
|
267 |
currentY += aDrawingRect.iTl.iY; //Offset, due to NHD viewfinder on VGA display |
54 | 268 |
iLineArray.Append( TRect( leftX, currentY, rightX, currentY ) ); |
269 |
i++; |
|
270 |
} |
|
271 |
||
272 |
// ----------------------------------- |
|
273 |
// Then vertical lines |
|
274 |
TInt width = aDrawingRect.Width(); |
|
275 |
TInt topY = aDrawingRect.iTl.iY; |
|
276 |
TInt bottomY = aDrawingRect.iBr.iY; |
|
277 |
||
278 |
TInt j = 0; |
|
279 |
while( j < aVerticalLines ) |
|
280 |
{ |
|
281 |
// Max used to make sure no div-by-zero |
|
282 |
TInt currentX = leftX + ((j+indexOffset)*width) / Max(1,aVerticalLines+countOffset) - KPenWidth/2; |
|
283 |
iLineArray.Append( TRect( currentX, topY, currentX, bottomY ) ); |
|
284 |
j++; |
|
285 |
} |
|
286 |
// ------------------------------------------------------- |
|
287 |
} |
|
288 |
||
289 |
||
290 |
// --------------------------------------------------------------------------- |
|
291 |
// SetPenStyle |
|
292 |
// |
|
293 |
// Set the style of drawing pen. |
|
294 |
// See CGraphicsContext. |
|
295 |
// --------------------------------------------------------------------------- |
|
296 |
// |
|
297 |
void |
|
298 |
CCamLineVfGridDrawer::SetPenStyle( const CGraphicsContext::TPenStyle& aPenStyle ) |
|
299 |
{ |
|
300 |
iPenStyle = aPenStyle; |
|
301 |
} |
|
302 |
||
303 |
||
304 |
// --------------------------------------------------------------------------- |
|
305 |
// SetPenSize |
|
306 |
// |
|
307 |
// Set the size of drawing pen. |
|
308 |
// See CGraphicsContext. |
|
309 |
// --------------------------------------------------------------------------- |
|
310 |
// |
|
311 |
void |
|
312 |
CCamLineVfGridDrawer::SetPenSize( const TSize& aPenSize ) |
|
313 |
{ |
|
314 |
iPenSize = aPenSize; |
|
315 |
} |
|
316 |
||
317 |
// --------------------------------------------------------------------------- |
|
318 |
// SetPenColor |
|
319 |
// |
|
320 |
// Set the color of drawing pen. |
|
321 |
// See CGraphicsContext. |
|
322 |
// --------------------------------------------------------------------------- |
|
323 |
// |
|
324 |
void |
|
325 |
CCamLineVfGridDrawer::SetPenColor( const TRgb aPenColor ) |
|
326 |
{ |
|
327 |
iPenColor = aPenColor; |
|
328 |
} |
|
329 |
||
330 |
||
331 |
// =========================================================================== |
|
332 |
// Protected part |
|
333 |
||
334 |
// --------------------------------------------------------------------------- |
|
335 |
// ConstructL |
|
336 |
// |
|
337 |
// 2nd phase constructor. |
|
338 |
// --------------------------------------------------------------------------- |
|
339 |
// |
|
340 |
void |
|
341 |
CCamLineVfGridDrawer::ConstructL() |
|
342 |
{ |
|
343 |
// empty |
|
344 |
} |
|
345 |
||
346 |
||
347 |
||
348 |
// =========================================================================== |
|
349 |
// Private part |
|
350 |
||
351 |
// --------------------------------------------------------------------------- |
|
352 |
// C++ constructor. |
|
353 |
// Called in 1st phase of construction. |
|
354 |
// --------------------------------------------------------------------------- |
|
355 |
// |
|
356 |
CCamLineVfGridDrawer::CCamLineVfGridDrawer() |
|
357 |
: iLineArray( KArrayGranularity ), |
|
358 |
iVisible( EFalse ), |
|
359 |
iPenStyle( KPenStyle ), |
|
360 |
iPenSize( KPenWidth, KPenHeight ), |
|
361 |
iPenColor( KPenColorRed, KPenColorGreen, KPenColorBlue, KPenColorAlpha ) |
|
362 |
{ |
|
363 |
// empty |
|
364 |
} |
|
365 |
||
366 |
||
367 |
// ============================== end of file ================================ |