author | Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com> |
Wed, 13 Oct 2010 14:09:54 +0300 | |
branch | RCL_3 |
changeset 67 | 756ad29ed18e |
parent 62 | f0c0788c4de2 |
permissions | -rw-r--r-- |
54 | 1 |
/* |
2 |
* Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies). |
|
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: Container for custom camera capture button |
|
15 |
* |
|
16 |
*/ |
|
17 |
||
18 |
#include <AknIconUtils.h> |
|
19 |
#include <touchfeedback.h> |
|
20 |
||
21 |
#include "camcapturebuttoncontainer.h" |
|
22 |
#include "CamPreCaptureViewBase.h" |
|
23 |
#include "camlogging.h" |
|
24 |
#include "cameraapp.mbg" |
|
25 |
#include "CamAppUi.h" |
|
26 |
||
27 |
// CONSTANTS |
|
28 |
_LIT(KCamBitmapFile, "z:\\resource\\apps\\cameraapp.mif"); |
|
29 |
const TInt KCaptureButtonOrdinalPriority( 1 ); |
|
30 |
const TSize KIconMargin( 7, 7 ); |
|
31 |
||
32 |
// ----------------------------------------------------------------------------- |
|
33 |
// CCamCaptureButtonContainer::CCamCaptureButtonContainer |
|
34 |
// ----------------------------------------------------------------------------- |
|
35 |
// |
|
36 |
CCamCaptureButtonContainer::CCamCaptureButtonContainer( CCamAppController& aController, |
|
37 |
CAknView& aView, |
|
38 |
CCamPreCaptureContainerBase& aContainer, |
|
39 |
TCamCameraMode aCameraMode ) |
|
40 |
: iController( aController ), |
|
41 |
iView( aView ), |
|
42 |
iParentContainer( aContainer ), |
|
43 |
iCameraMode( aCameraMode ) |
|
44 |
{ |
|
45 |
} |
|
46 |
||
47 |
// ----------------------------------------------------------------------------- |
|
48 |
// CCamCaptureButtonContainer::ConstructL |
|
49 |
// ----------------------------------------------------------------------------- |
|
50 |
// |
|
51 |
void CCamCaptureButtonContainer::ConstructL( const TRect& aRect ) |
|
52 |
{ |
|
53 |
PRINT( _L("Camera => CCamCaptureButtonContainer::ConstructL") ); |
|
54 |
CreateWindowL(); |
|
55 |
SetRect( aRect ); |
|
56 |
Window().SetBackgroundColor( KRgbTransparent ); |
|
57 |
||
58 |
// Keep hidden until explicitly made visible |
|
59 |
MakeVisible( EFalse ); |
|
60 |
CCamAppUi* appUi = static_cast<CCamAppUi*>( CEikonEnv::Static()->AppUi() ); |
|
61 |
||
62 |
// Load capture icon |
|
63 |
TInt bitmapId = EMbmCameraappQgn_indi_cam4_capture_image; |
|
64 |
TInt maskId = EMbmCameraappQgn_indi_cam4_capture_image_mask; |
|
65 |
TInt bitmapPressedId = EMbmCameraappQgn_indi_cam4_capture_image_pressed; |
|
66 |
TInt maskPressedId = EMbmCameraappQgn_indi_cam4_capture_image_pressed_mask; |
|
67 |
||
68 |
if ( iCameraMode == ECamControllerVideo ) |
|
69 |
{ |
|
70 |
bitmapId = EMbmCameraappQgn_indi_cam4_capture_video; |
|
71 |
maskId = EMbmCameraappQgn_indi_cam4_capture_video_mask; |
|
72 |
bitmapPressedId = EMbmCameraappQgn_indi_cam4_capture_video_pressed; |
|
73 |
maskPressedId = EMbmCameraappQgn_indi_cam4_capture_video_pressed_mask; |
|
74 |
} |
|
75 |
||
76 |
iCaptureRect = aRect; |
|
77 |
iCaptureRect.Move(-iCaptureRect.iTl.iX, -iCaptureRect.iTl.iY ); |
|
78 |
iCaptureRect.Shrink( KIconMargin ); |
|
79 |
||
80 |
AknIconUtils::CreateIconL( |
|
81 |
iCaptureIcon, |
|
82 |
iCaptureIconMask, |
|
83 |
KCamBitmapFile(), |
|
84 |
bitmapId, |
|
85 |
maskId ); |
|
86 |
AknIconUtils::SetSize( iCaptureIcon, iCaptureRect.Size() ); |
|
87 |
AknIconUtils::SetSize( iCaptureIconMask, iCaptureRect.Size() ); |
|
88 |
||
89 |
AknIconUtils::CreateIconL( |
|
90 |
iCaptureIconPressed, |
|
91 |
iCaptureIconPressedMask, |
|
92 |
KCamBitmapFile(), |
|
93 |
bitmapPressedId, |
|
94 |
maskPressedId ); |
|
95 |
AknIconUtils::SetSize( iCaptureIconPressed, iCaptureRect.Size() ); |
|
96 |
AknIconUtils::SetSize( iCaptureIconPressedMask, iCaptureRect.Size() ); |
|
97 |
||
98 |
iFeedback = MTouchFeedback::Instance(); |
|
99 |
PRINT( _L("Camera <= CCamCaptureButtonContainer::ConstructL") ); |
|
100 |
} |
|
101 |
||
102 |
// ----------------------------------------------------------------------------- |
|
103 |
// CCamCaptureButtonContainer::~CCamCaptureButtonContainer |
|
104 |
// ----------------------------------------------------------------------------- |
|
105 |
// |
|
106 |
CCamCaptureButtonContainer::~CCamCaptureButtonContainer() |
|
107 |
{ |
|
108 |
delete iCaptureIcon; |
|
109 |
delete iCaptureIconMask; |
|
110 |
delete iCaptureIconPressed; |
|
111 |
delete iCaptureIconPressedMask; |
|
112 |
} |
|
113 |
||
114 |
// ----------------------------------------------------------------------------- |
|
115 |
// CCamCaptureButtonContainer::NewLC |
|
116 |
// ----------------------------------------------------------------------------- |
|
117 |
// |
|
118 |
CCamCaptureButtonContainer* CCamCaptureButtonContainer::NewLC( CCamAppController& aController, |
|
119 |
CAknView& aView, |
|
120 |
CCamPreCaptureContainerBase& aContainer, |
|
121 |
const TRect& aRect, |
|
122 |
TCamCameraMode aCameraMode ) |
|
123 |
{ |
|
124 |
CCamCaptureButtonContainer* self = new (ELeave) CCamCaptureButtonContainer( aController, |
|
125 |
aView, |
|
126 |
aContainer, |
|
127 |
aCameraMode ); |
|
128 |
CleanupStack::PushL( self ); |
|
129 |
self->ConstructL( aRect ); |
|
130 |
return self; |
|
131 |
} |
|
132 |
||
133 |
// ----------------------------------------------------------------------------- |
|
134 |
// CCamCaptureButtonContainer::NewL |
|
135 |
// ----------------------------------------------------------------------------- |
|
136 |
// |
|
137 |
CCamCaptureButtonContainer* CCamCaptureButtonContainer::NewL( CCamAppController& aController, |
|
138 |
CAknView& aView, |
|
139 |
CCamPreCaptureContainerBase& aContainer, |
|
140 |
const TRect& aRect, |
|
141 |
TCamCameraMode aCameraMode ) |
|
142 |
{ |
|
143 |
CCamCaptureButtonContainer* self = CCamCaptureButtonContainer::NewLC( aController, |
|
144 |
aView, |
|
145 |
aContainer, |
|
146 |
aRect, |
|
147 |
aCameraMode ); |
|
148 |
CleanupStack::Pop(self); |
|
149 |
return self; |
|
150 |
} |
|
151 |
||
152 |
// ------------------------------------------------------------- |
|
153 |
// CCamCaptureButtonContainer::HandlePointerEventL |
|
154 |
// ------------------------------------------------------------- |
|
155 |
// |
|
156 |
void CCamCaptureButtonContainer::HandlePointerEventL( const TPointerEvent& aPointerEvent ) |
|
157 |
{ |
|
158 |
PRINT3( _L("Camera => CCamCaptureButtonContainer::HandlePointerEventL type:%d position:%d,%d"), |
|
159 |
aPointerEvent.iType, aPointerEvent.iPosition.iX, aPointerEvent.iPosition.iY ); |
|
160 |
||
161 |
if( iCaptureButtonShown ) |
|
162 |
{ |
|
163 |
PRINT( _L("Camera <> Capture button shown") ); |
|
164 |
// Button down -> pressed (highlighted) |
|
165 |
if ( aPointerEvent.iType == TPointerEvent::EButton1Down ) |
|
166 |
{ |
|
167 |
SetPointerCapture( ETrue ); |
|
168 |
ClaimPointerGrab( ETrue ); |
|
169 |
iCaptureButtonPressed = ETrue; |
|
170 |
if ( !iFeedback ) |
|
171 |
{ |
|
172 |
iFeedback = MTouchFeedback::Instance(); |
|
173 |
} |
|
174 |
// Feedback on button press |
|
175 |
if ( iFeedback ) |
|
176 |
{ |
|
177 |
iFeedback->InstantFeedback( ETouchFeedbackBasicButton ); |
|
178 |
} |
|
179 |
DrawNow(); |
|
180 |
} |
|
181 |
// Button up after button down (within button area) -> start capture |
|
182 |
else if ( aPointerEvent.iType == TPointerEvent::EButton1Up |
|
183 |
&& iCaptureButtonPressed && Rect().Contains(aPointerEvent.iPosition) ) |
|
184 |
{ |
|
185 |
PRINT( _L("Camera <> starting capture") ); |
|
186 |
ClaimPointerGrab( EFalse ); |
|
187 |
SetPointerCapture( EFalse ); |
|
188 |
iCaptureButtonPressed = EFalse; |
|
189 |
||
190 |
// Give feedback on button release |
|
191 |
if ( iFeedback ) |
|
192 |
{ |
|
193 |
iFeedback->InstantFeedback( ETouchFeedbackBasicButton ); |
|
194 |
} |
|
195 |
||
196 |
iParentContainer.PrepareForCapture(); |
|
197 |
if ( iCameraMode == ECamControllerVideo ) |
|
198 |
{ |
|
199 |
iView.HandleCommandL( ECamCmdRecord ); |
|
200 |
} |
|
201 |
else |
|
202 |
{ |
|
203 |
iController.SetTouchCapture( ETrue ); |
|
204 |
iView.HandleCommandL( ECamCmdCaptureImage ); |
|
205 |
} |
|
206 |
} |
|
207 |
// Drags can potentially start from inside button area |
|
208 |
else if ( iCaptureButtonPressed && aPointerEvent.iType != TPointerEvent::EDrag ) |
|
209 |
{ |
|
210 |
PRINT( _L("Camera <> outside button region - button to not-pressed state") ); |
|
211 |
ClaimPointerGrab( EFalse ); |
|
212 |
SetPointerCapture( EFalse ); |
|
213 |
iCaptureButtonPressed = EFalse; |
|
214 |
DrawNow(); |
|
215 |
} |
|
216 |
else |
|
217 |
{ |
|
218 |
PRINT( _L("Camera <> unhandled case") ); |
|
219 |
// Avoid compiler warning |
|
220 |
} |
|
221 |
} |
|
222 |
||
223 |
PRINT( _L("Camera <= CCamCaptureButtonContainer::HandlePointerEventL") ); |
|
224 |
} |
|
225 |
||
226 |
// ------------------------------------------------------------- |
|
227 |
// CCamCaptureButtonContainer::SetCaptureButtonShown |
|
228 |
// ------------------------------------------------------------- |
|
229 |
// |
|
230 |
void CCamCaptureButtonContainer::SetCaptureButtonShown( TBool aShown ) |
|
231 |
{ |
|
232 |
PRINT1( _L("Camera => CCamCaptureButtonContainer::SetCaptureButtonShown shown:%d"), aShown ); |
|
233 |
iCaptureButtonShown = aShown; |
|
234 |
||
235 |
if ( !aShown ) |
|
236 |
{ |
|
237 |
MakeVisible( EFalse ); |
|
238 |
} |
|
239 |
else if ( !IsVisible() ) |
|
240 |
{ |
|
241 |
// Ensure button is in non-pressed state when making visible |
|
242 |
iCaptureButtonPressed = EFalse; |
|
243 |
||
244 |
PRINT( _L("Camera <> Making the capture button visible") ); |
|
245 |
DrawableWindow()->SetOrdinalPosition( 0, KCaptureButtonOrdinalPriority ); |
|
246 |
MakeVisible( ETrue ); |
|
247 |
DrawDeferred(); |
|
248 |
} |
|
249 |
else |
|
250 |
{ |
|
251 |
PRINT( _L("Camera <> Already visible!") ); |
|
252 |
} |
|
253 |
||
254 |
PRINT( _L("Camera <= CCamCaptureButtonContainer::SetCaptureButtonShown") ); |
|
255 |
} |
|
256 |
||
257 |
// ----------------------------------------------------------------------------- |
|
258 |
// CCamCaptureButtonContainer::Draw |
|
259 |
// ----------------------------------------------------------------------------- |
|
260 |
// |
|
261 |
void CCamCaptureButtonContainer::Draw( const TRect& aRect ) const |
|
262 |
{ |
|
263 |
PRINT( _L("Camera => CCamCaptureButtonContainer::Draw") ); |
|
264 |
||
265 |
CWindowGc& gc = SystemGc(); |
|
266 |
if ( iCaptureButtonShown ) |
|
267 |
{ |
|
268 |
DrawCaptureButton( gc ); |
|
269 |
} |
|
270 |
else |
|
271 |
{ |
|
272 |
PRINT( _L("Camera <> button hidden") ); |
|
273 |
} |
|
274 |
||
275 |
PRINT( _L("Camera <= CCamCaptureButtonContainer::Draw") ); |
|
276 |
} |
|
277 |
||
278 |
// ------------------------------------------------------------- |
|
279 |
// CCamCaptureButtonContainer::DrawCaptureButton |
|
280 |
// ------------------------------------------------------------- |
|
281 |
// |
|
282 |
void CCamCaptureButtonContainer::DrawCaptureButton( CBitmapContext& aGc ) const |
|
283 |
{ |
|
284 |
PRINT( _L("Camera => CCamCaptureButtonContainer::DrawCaptureButton") ); |
|
285 |
TRect boundingRect( iCaptureRect ); |
|
286 |
boundingRect.Move( -boundingRect.iTl.iX, -boundingRect.iTl.iY ); |
|
287 |
||
67
756ad29ed18e
Revision: 201039
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
62
diff
changeset
|
288 |
// Clear the window |
756ad29ed18e
Revision: 201039
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
62
diff
changeset
|
289 |
aGc.SetPenStyle( CGraphicsContext::ENullPen ); |
756ad29ed18e
Revision: 201039
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
62
diff
changeset
|
290 |
aGc.SetBrushStyle( CGraphicsContext::ESolidBrush ); |
756ad29ed18e
Revision: 201039
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
62
diff
changeset
|
291 |
aGc.SetDrawMode( CGraphicsContext::EDrawModeWriteAlpha ); |
756ad29ed18e
Revision: 201039
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
62
diff
changeset
|
292 |
aGc.SetBrushColor( TRgb::Color16MA( 0 ) ); |
756ad29ed18e
Revision: 201039
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
62
diff
changeset
|
293 |
aGc.Clear( boundingRect ); |
756ad29ed18e
Revision: 201039
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
62
diff
changeset
|
294 |
|
54 | 295 |
if ( iCaptureButtonPressed ) |
296 |
{ |
|
297 |
aGc.BitBltMasked( iCaptureRect.iTl, iCaptureIconPressed, boundingRect, iCaptureIconPressedMask, EFalse ); |
|
298 |
} |
|
299 |
else |
|
300 |
{ |
|
301 |
aGc.BitBltMasked( iCaptureRect.iTl, iCaptureIcon, boundingRect, iCaptureIconMask, EFalse ); |
|
302 |
||
303 |
} |
|
304 |
||
305 |
PRINT( _L("Camera <= CCamCaptureButtonContainer::DrawCaptureButton") ); |
|
306 |
} |
|
307 |