00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031 #include <w32std.h>
00032 #include "Base.h"
00033 #include "VectorSprite.h"
00034
00035 CSprite::CSprite(CWsClient *aClient) : iClient(aClient)
00036 {
00037 }
00038
00039 CSprite::~CSprite()
00040 {
00041 for (TInt i=0; i<4; i++)
00042 {
00043 delete iSpriteMember[i].iBitmap;
00044 delete iSpriteMember[i].iMaskBitmap;
00045 }
00046 iSprite.Close();
00047 }
00048
00049 void CSprite::ConstructL(CWindow* aWindow)
00050 {
00051 iSprite = RWsSprite(iClient->iWs);
00052 User::LeaveIfError(iSprite.Construct(aWindow->Window(), TPoint(100,100), 0));
00053 for (TInt spriteNum = 0; spriteNum < 4; spriteNum++)
00054 {
00055 CreateBitmapL(iSpriteMember[spriteNum].iBitmap, spriteNum, EFalse);
00056 CreateBitmapL(iSpriteMember[spriteNum].iMaskBitmap, spriteNum, ETrue);
00057 iSpriteMember[spriteNum].iInvertMask = EFalse;
00058 iSpriteMember[spriteNum].iOffset = TPoint (0,0);
00059 iSpriteMember[spriteNum].iInterval = TTimeIntervalMicroSeconds32 (500000);
00060 iSpriteMember[spriteNum].iDrawMode = CGraphicsContext::EDrawModePEN;
00061 User::LeaveIfError(iSprite.AppendMember(iSpriteMember[spriteNum]));
00062 }
00063 User::LeaveIfError(iSprite.Activate());
00064 iSprite.UpdateMember(3);
00065 }
00066
00067 void CSprite::CreateBitmapL(CFbsBitmap* &aBitmap, TInt aSpriteNum, TBool aDoMask)
00068 {
00069
00070 CFbsBitmapDevice* bitmapDevice;
00071 CGraphicsContext* bitmapContext;
00072
00073
00074
00075
00076
00077
00078 aBitmap = new (ELeave) CFbsBitmap();
00079 aBitmap->Create(TSize(50,50),EGray4);
00080
00081 bitmapDevice = CFbsBitmapDevice::NewL(aBitmap);
00082 bitmapDevice->CreateContext(bitmapContext);
00083
00084 bitmapContext->SetBrushColor(aDoMask? TRgb::Gray4(0) : TRgb::Gray4(2));
00085 bitmapContext->SetBrushStyle(CGraphicsContext::ESolidBrush);
00086 bitmapContext->SetPenStyle(CGraphicsContext::ENullPen);
00087 bitmapContext->DrawRect(TRect(TSize(50,50)));
00088 bitmapContext->SetPenStyle(CGraphicsContext::ESolidPen);
00089 bitmapContext->SetPenSize(TSize(4,4));
00090 bitmapContext->SetPenColor(aDoMask? TRgb::Gray4(3) : TRgb::Gray4(0));
00091
00092 switch (aSpriteNum)
00093 {
00094 case 0:
00095 bitmapContext->DrawLine (TPoint(10,10), TPoint(40,40));
00096 break;
00097 case 1:
00098 bitmapContext->DrawLine (TPoint(25,10), TPoint(25,40));
00099 break;
00100 case 2:
00101 bitmapContext->DrawLine (TPoint(40,10), TPoint(10,40));
00102 break;
00103 case 3:
00104 bitmapContext->DrawLine (TPoint(10,25), TPoint(40,25));
00105 break;
00106 }
00107
00108 delete bitmapContext;
00109 delete bitmapDevice;
00110 }
00111
00112
00113
00114
00115
00116 CMainWindow::CMainWindow (CWsClient* aClient)
00117 : CWindow (aClient)
00118 {
00119 }
00120
00121
00122 CMainWindow::~CMainWindow ()
00123 {
00124 iWindow.Close();
00125 }
00126
00127
00128
00129
00130
00131
00132
00133
00134
00135 void CMainWindow::Draw(const TRect& aRect)
00136 {
00137 CWindowGc* gc=SystemGc();
00138 gc->SetClippingRect(aRect);
00139 gc->Clear(aRect);
00140 gc->SetPenStyle(CGraphicsContext::ESolidPen);
00141 gc->SetPenColor(TRgb::Gray4(2));
00142 TSize size = Window().Size();
00143 TInt width = size.iWidth;
00144 TInt height = size.iHeight;
00145 TInt numHoriz=height/5;
00146 TInt numVert=width/10;
00147 for (TInt i=numHoriz; i>0; i--)
00148 {
00149 gc->DrawLine (TPoint(0,height/numHoriz*i), TPoint(width, height/numHoriz*i));
00150 }
00151 for (TInt j=numVert; j>0; j--)
00152 {
00153 gc->DrawLine (TPoint(width/numVert*j, 0), TPoint(width/numVert*j, height));
00154 }
00155 }
00156
00157
00158
00159
00160
00161
00162
00163
00164
00165 void CMainWindow::HandlePointerEvent (TPointerEvent& aPointerEvent)
00166 {
00167 switch (aPointerEvent.iType)
00168 {
00169 case TPointerEvent::EButton1Down:
00170 break;
00171 case TPointerEvent::EButton1Up:
00172 break;
00173 case TPointerEvent::EButton3Down:
00174 break;
00175 default:
00176 break;
00177 }
00178 }
00179
00180
00182
00184
00185 CExampleWsClient* CExampleWsClient::NewL(const TRect& aRect)
00186 {
00187
00188 CExampleWsClient* client=new (ELeave) CExampleWsClient(aRect);
00189 CleanupStack::PushL(client);
00190 client->ConstructL();
00191 CleanupStack::Pop();
00192 return client;
00193 }
00194
00195
00196
00197
00198
00199
00200
00201 CExampleWsClient::CExampleWsClient(const TRect& aRect)
00202 :iRect(aRect)
00203 {
00204 }
00205
00206 CExampleWsClient::~CExampleWsClient ()
00207 {
00208 delete iMainWindow;
00209 delete iSprite;
00210 }
00211
00212
00213
00214
00215
00216
00217
00218
00219
00220 void CExampleWsClient::ConstructMainWindowL()
00221 {
00222 iMainWindow=new (ELeave) CMainWindow(this);
00223 iMainWindow->ConstructL(iRect, TRgb (255,255,255));
00224 iSprite=new (ELeave) CSprite (this);
00225 iSprite->ConstructL(iMainWindow);
00226 }
00227
00228
00229
00230
00231
00232
00233
00234
00235
00236
00237 void CExampleWsClient::RunL()
00238 {
00239
00240 iWs.GetEvent(iWsEvent);
00241 TInt eventType=iWsEvent.Type();
00242
00243 switch (eventType)
00244 {
00245
00246 case EEventNull:
00247 break;
00248 case EEventKey:
00249 {
00250 TKeyEvent& keyEvent=*iWsEvent.Key();
00251 HandleKeyEventL (keyEvent);
00252 break;
00253 }
00254 case EEventModifiersChanged:
00255 break;
00256 case EEventKeyUp:
00257 case EEventKeyDown:
00258 case EEventFocusLost:
00259 case EEventFocusGained:
00260 case EEventSwitchOn:
00261 case EEventPassword:
00262 case EEventWindowGroupsChanged:
00263 case EEventErrorMessage:
00264 break;
00265
00266 case EEventPointer:
00267 {
00268 CWindow* window=(CWindow*)(iWsEvent.Handle());
00269 TPointerEvent& pointerEvent=*iWsEvent.Pointer();
00270 window->HandlePointerEvent (pointerEvent);
00271 break;
00272 }
00273 case EEventPointerExit:
00274 case EEventPointerEnter:
00275 break;
00276 case EEventPointerBufferReady:
00277 {
00278 break;
00279 }
00280 case EEventDragDrop:
00281 break;
00282 default:
00283 break;
00284 }
00285 IssueRequest();
00286 }
00287
00288
00289
00290
00291
00292 void CExampleWsClient::HandleKeyEventL (TKeyEvent& )
00293 {
00294 }