|
1 // Copyright (c) 2004-2009 Nokia Corporation and/or its subsidiary(-ies). |
|
2 // All rights reserved. |
|
3 // This component and the accompanying materials are made available |
|
4 // under the terms of "Eclipse Public License v1.0" |
|
5 // which accompanies this distribution, and is available |
|
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
7 // |
|
8 // Initial Contributors: |
|
9 // Nokia Corporation - initial contribution. |
|
10 // |
|
11 // Contributors: |
|
12 // |
|
13 // Description: |
|
14 // |
|
15 |
|
16 #include "SpriteAnimationServer.h" |
|
17 #include "AnimationCmd.h" |
|
18 #include "Animator.h" |
|
19 #include "AnimationConfig.h" |
|
20 #include "AnimationTls.h" |
|
21 #include "AnimationTicker.h" |
|
22 |
|
23 // Creates a CSpriteAnimationServer and returns a pointer to the object. |
|
24 CSpriteAnimationServer* CSpriteAnimationServer::NewL() |
|
25 { |
|
26 CSpriteAnimationServer* self = new (ELeave) CSpriteAnimationServer(); |
|
27 return self; |
|
28 } |
|
29 |
|
30 CSpriteAnimationServer::~CSpriteAnimationServer() |
|
31 { |
|
32 iFunctions->GetRawEvents(EFalse); |
|
33 while (iFreezeCount > 0) |
|
34 { |
|
35 --iFreezeCount; |
|
36 iTls->Ticker()->Unfreeze(); |
|
37 } |
|
38 delete iAnimator; |
|
39 delete iSpriteGc; |
|
40 delete iBitmapDevice; |
|
41 delete iMaskDevice; |
|
42 delete iDataType; |
|
43 if (iTls) |
|
44 iTls->Close(); |
|
45 } |
|
46 |
|
47 CSpriteAnimationServer::CSpriteAnimationServer() |
|
48 { |
|
49 } |
|
50 |
|
51 void CSpriteAnimationServer::ConstructL(TAny* aArgs) |
|
52 { |
|
53 iTls = CAnimationTls::NewL(); |
|
54 HBufC8* data = static_cast<HBufC8*>(aArgs); |
|
55 iDataType = HBufC8::NewL(data->Length()); |
|
56 *iDataType = *data; |
|
57 iSpriteGc = CFbsBitGc::NewL(); |
|
58 iAnimator = CAnimator::NewL(this); |
|
59 } |
|
60 |
|
61 // Pure virtual function from CAnim. |
|
62 void CSpriteAnimationServer::Command(TInt aOpcode, TAny* aArgs) |
|
63 { |
|
64 switch (aOpcode) |
|
65 { |
|
66 case EAnimationCmdStart: |
|
67 iAnimator->Start(*(static_cast<TAnimationConfig*>(aArgs))); |
|
68 break; |
|
69 case EAnimationCmdStop: |
|
70 iAnimator->Stop(); |
|
71 break; |
|
72 case EAnimationCmdPause: |
|
73 iAnimator->Pause(); |
|
74 break; |
|
75 case EAnimationCmdResume: |
|
76 iAnimator->Resume(); |
|
77 break; |
|
78 case EAnimationCmdHold: |
|
79 iAnimator->Hold(); |
|
80 break; |
|
81 case EAnimationCmdUnhold: |
|
82 iAnimator->Unhold(); |
|
83 break; |
|
84 case EAnimationCmdFreeze: |
|
85 ++iFreezeCount; |
|
86 iTls->Ticker()->Freeze(); |
|
87 break; |
|
88 case EAnimationCmdUnfreeze: |
|
89 --iFreezeCount; |
|
90 iTls->Ticker()->Unfreeze(); |
|
91 break; |
|
92 case EAnimationCmdHostHandle: |
|
93 iHostHandle = *(static_cast<TInt*>(aArgs)); |
|
94 break; |
|
95 } |
|
96 } |
|
97 |
|
98 // Pure virtual function from CAnim it handles the command received by the related client. |
|
99 // aOpcode determines the action that has to be taken while aArgs contains the information |
|
100 // packed by the client. It returns KErrNone if no problem has occurred. |
|
101 TInt CSpriteAnimationServer::CommandReplyL(TInt aOpcode, TAny* aArgs) |
|
102 { |
|
103 TInt error = KErrNone; |
|
104 switch (aOpcode) |
|
105 { |
|
106 case EAnimationCmdDataEvent: |
|
107 ReceiveEventL(aArgs); |
|
108 break; |
|
109 case EAnimationCmdSize: |
|
110 error = ((iSize.iWidth & ((1 << 15)-1)) << 16) | (iSize.iHeight & ((1 << 15)-1)); |
|
111 break; |
|
112 default: |
|
113 error = KErrNotSupported; |
|
114 } |
|
115 return error; |
|
116 } |
|
117 |
|
118 void CSpriteAnimationServer::ReceiveEventL(TAny* aArgs) |
|
119 { |
|
120 TInt aEvent; |
|
121 TAny* aData; |
|
122 TInt aDataLength; |
|
123 aEvent = *(TInt*)aArgs; |
|
124 aDataLength = *(((TInt*)aArgs) + 1); |
|
125 aData = (((TInt*)aArgs) + 2); |
|
126 iAnimator->DataEventL(aEvent, aData, aDataLength); |
|
127 } |
|
128 |
|
129 void CSpriteAnimationServer::Animate(TDateTime* /*aDateTime*/) |
|
130 { // Empty implementation |
|
131 } |
|
132 |
|
133 TBool CSpriteAnimationServer::OfferRawEvent(const TRawEvent& /*aRawEvent*/) |
|
134 { |
|
135 return EFalse; |
|
136 } |
|
137 |
|
138 void CSpriteAnimationServer::PostHostEvent() |
|
139 { |
|
140 const TInt KUiqDummyKeyCode = 0xBABE; |
|
141 TKeyEvent event; |
|
142 event.iCode = KUiqDummyKeyCode ; |
|
143 event.iScanCode = KUiqDummyKeyCode ; |
|
144 event.iModifiers = 0; |
|
145 event.iRepeats = 0; |
|
146 iFunctions->PostKeyEvent(event); |
|
147 } |
|
148 |
|
149 |
|
150 void CSpriteAnimationServer::AnimatorDraw() |
|
151 { |
|
152 if(iSpriteFunctions->SpriteCanBeSeen()) |
|
153 { |
|
154 if(iFlags & EVirtualHold) |
|
155 { |
|
156 iFlags &= ~EVirtualHold; |
|
157 iAnimator->Hold(); |
|
158 iAnimator->Unhold(); |
|
159 } |
|
160 else |
|
161 { |
|
162 iSpriteGc->Activate(iBitmapDevice); |
|
163 iAnimator->Draw(*iSpriteGc); |
|
164 iSpriteGc->Activate(iMaskDevice); |
|
165 iAnimator->DrawMask(*iSpriteGc); |
|
166 |
|
167 iSpriteFunctions->UpdateMember(0, iSize, ETrue); |
|
168 } |
|
169 } |
|
170 else |
|
171 { |
|
172 // Virtual hold exists because if we actually hold the animator, we would no longer receive |
|
173 // calls to AnimatorDraw, and so we would never unhold it. |
|
174 iFlags |= EVirtualHold; |
|
175 } |
|
176 } |
|
177 |
|
178 void CSpriteAnimationServer::AnimatorInitialisedL(const TSize& aSize) |
|
179 { |
|
180 iSize = aSize; |
|
181 TSpriteMember& spriteMember = *iSpriteFunctions->GetSpriteMember(0); |
|
182 spriteMember.iBitmap->Resize(iSize); |
|
183 spriteMember.iMaskBitmap->Resize(iSize); |
|
184 iSpriteFunctions->SizeChangedL(); |
|
185 |
|
186 delete iBitmapDevice; |
|
187 iBitmapDevice = NULL; |
|
188 delete iMaskDevice; |
|
189 iMaskDevice = NULL; |
|
190 iBitmapDevice = CFbsBitmapDevice::NewL(spriteMember.iBitmap); |
|
191 iMaskDevice = CFbsBitmapDevice::NewL(spriteMember.iMaskBitmap); |
|
192 |
|
193 iSpriteGc->Activate(iMaskDevice); |
|
194 iSpriteGc->SetBrushStyle(CGraphicsContext::ESolidBrush); |
|
195 iSpriteGc->SetBrushColor(KRgbBlack); |
|
196 iSpriteGc->DrawRect(iSize); |
|
197 iSpriteFunctions->UpdateMember(0, iSize, ETrue); |
|
198 |
|
199 iFunctions->GetRawEvents(ETrue); |
|
200 iSpriteFunctions->Activate(ETrue); |
|
201 |
|
202 PostHostEvent(); |
|
203 } |
|
204 |
|
205 void CSpriteAnimationServer::AnimatorResetL() |
|
206 { |
|
207 iSize.iWidth = 0; |
|
208 iSize.iHeight = 0; |
|
209 |
|
210 TSpriteMember& spriteMember = *iSpriteFunctions->GetSpriteMember(0); |
|
211 spriteMember.iBitmap->Resize(iSize); |
|
212 spriteMember.iMaskBitmap->Resize(iSize); |
|
213 iSpriteFunctions->SizeChangedL(); |
|
214 |
|
215 iSpriteFunctions->Activate(EFalse); |
|
216 iFunctions->GetRawEvents(EFalse); |
|
217 delete iBitmapDevice; |
|
218 iBitmapDevice = NULL; |
|
219 delete iMaskDevice; |
|
220 iMaskDevice = NULL; |
|
221 iFlags = 0; |
|
222 } |
|
223 |
|
224 const TPtrC8 CSpriteAnimationServer::AnimatorDataType() const |
|
225 { |
|
226 return *iDataType; |
|
227 } |
|
228 |
|
229 CAnimationTicker& CSpriteAnimationServer::AnimatorTicker() |
|
230 { |
|
231 return *iTls->Ticker(); |
|
232 } |