00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016 #include "GraphicsControl.h"
00017
00018 #include <coemain.h>
00019
00020
00021 _LIT(KTxtUpdateModelCase0,"point in center of screen");
00022 _LIT(KTxtUpdateModelCase1,"bolder point in center of screen");
00023 _LIT(KTxtUpdateModelCase2,"really bold point in center of screen");
00024 _LIT(KTxtUpdateModelCase3,"a line");
00025 _LIT(KTxtUpdateModelCase4,"a thicker line");
00026 _LIT(KTxtUpdateModelCase5,"really thick - note round ends and clipping");
00027 _LIT(KTxtUpdateModelCase6,"dotted line");
00028 _LIT(KTxtUpdateModelCase7,"dot-dash line");
00029 _LIT(KTxtUpdateModelCase8,"triangle using relative drawing");
00030 _LIT(KTxtUpdateModelCase9,"thick triangle - note rounded corners");
00031 _LIT(KTxtUpdateModelCase10,"dotted triangle - note pattern continuation");
00032 _LIT(KTxtUpdateModelCase11,"centered ellipse");
00033 _LIT(KTxtUpdateModelCase12,"arc - part of ellipse");
00034 _LIT(KTxtUpdateModelCase13,"arc - other part - see also construction elements");
00035 _LIT(KTxtUpdateModelCase14,"pie slices");
00036 _LIT(KTxtUpdateModelCase15,"centered rectangle with rounded corners");
00037 _LIT(KTxtUpdateModelCase16,"rounded rectangle showing corner ellipse");
00038 _LIT(KTxtUpdateModelCase17,"polyline");
00039 _LIT(KTxtUpdateModelCase18,"polygon with winding-fill rule");
00040 _LIT(KTxtUpdateModelCase19,"polygon using alternate-fill rule");
00041 _LIT(KTxtUpdateModelCase20,"copying using CopyRect()");
00042 _LIT(KTxtUpdateModelCase21,"left-justified boxed text");
00043 _LIT(KTxtUpdateModelCase22,"centered boxed text");
00044 _LIT(KTxtUpdateModelCase23,"right-justified offset text");
00045 _LIT(KTxtUpdateModelCase24,"cross-hatched box");
00046 _LIT(KTxtUpdateModelCase25,"teeny preview font!");
00047 _LIT(KTxtUpdateModelDefault,"overran!");
00048
00049 static CArrayFix<TPoint>* CreatePointsArrayL();
00050
00051 void CDrawControl::UpdateModelL()
00052 {
00053 switch (Phase())
00054 {
00055 case 0:
00056 iGraphObserver->NotifyStatus(KTxtUpdateModelCase0);
00057 break;
00058 case 1:
00059 iGraphObserver->NotifyStatus(KTxtUpdateModelCase1);
00060 break;
00061 case 2:
00062 iGraphObserver->NotifyStatus(KTxtUpdateModelCase2);
00063 break;
00064 case 3:
00065 iGraphObserver->NotifyStatus(KTxtUpdateModelCase3);
00066 break;
00067 case 4:
00068 iGraphObserver->NotifyStatus(KTxtUpdateModelCase4);
00069 break;
00070 case 5:
00071 iGraphObserver->NotifyStatus(KTxtUpdateModelCase5);
00072 break;
00073 case 6:
00074 iGraphObserver->NotifyStatus(KTxtUpdateModelCase6);
00075 break;
00076 case 7:
00077 iGraphObserver->NotifyStatus(KTxtUpdateModelCase7);
00078 break;
00079 case 8:
00080 iGraphObserver->NotifyStatus(KTxtUpdateModelCase8);
00081 break;
00082 case 9:
00083 iGraphObserver->NotifyStatus(KTxtUpdateModelCase9);
00084 break;
00085 case 10:
00086 iGraphObserver->NotifyStatus(KTxtUpdateModelCase10);
00087 break;
00088 case 11:
00089 iGraphObserver->NotifyStatus(KTxtUpdateModelCase11);
00090 break;
00091 case 12:
00092 iGraphObserver->NotifyStatus(KTxtUpdateModelCase12);
00093 break;
00094 case 13:
00095 iGraphObserver->NotifyStatus(KTxtUpdateModelCase13);
00096 break;
00097 case 14:
00098 iGraphObserver->NotifyStatus(KTxtUpdateModelCase14);
00099 break;
00100 case 15:
00101 iGraphObserver->NotifyStatus(KTxtUpdateModelCase15);
00102 break;
00103 case 16:
00104 {
00105 iGraphObserver->NotifyStatus(KTxtUpdateModelCase16);
00106 }
00107 break;
00108 case 17:
00109 iGraphObserver->NotifyStatus(KTxtUpdateModelCase17);
00110 break;
00111 case 18:
00112 iGraphObserver->NotifyStatus(KTxtUpdateModelCase18);
00113 break;
00114 case 19:
00115 iGraphObserver->NotifyStatus(KTxtUpdateModelCase19);
00116 break;
00117 case 20:
00118 {
00119 iGraphObserver->NotifyStatus(KTxtUpdateModelCase20);
00120 }
00121 break;
00122 case 21:
00123 iGraphObserver->NotifyStatus(KTxtUpdateModelCase21);
00124 break;
00125 case 22:
00126 iGraphObserver->NotifyStatus(KTxtUpdateModelCase22);
00127 break;
00128 case 23:
00129 iGraphObserver->NotifyStatus(KTxtUpdateModelCase23);
00130 break;
00131 case 24:
00132 iGraphObserver->NotifyStatus(KTxtUpdateModelCase24);
00133 break;
00134 case 25:
00135 iGraphObserver->NotifyStatus(KTxtUpdateModelCase25);
00136 break;
00137 default:
00138 iGraphObserver->NotifyStatus(KTxtUpdateModelDefault);
00139 break;
00140 }
00141 }
00142
00143
00144
00145 _LIT(KTxtDrawCase21,"White text left justified in dark gray box");
00146 _LIT(KTxtDrawCase22,"White text centered in black box");
00147 _LIT(KTxtDrawCase23,"Dark gray text right justified in lite gray box");
00148 _LIT(KTxtDrawCase25,"This text overwrites the cleared area");
00149
00150
00151 void CDrawControl::Draw(const TRect& ) const
00152 {
00153
00154
00155
00156 CWindowGc& gc=SystemGc();
00157 gc.UseFont(iMessageFont);
00158 gc.Clear();
00159 SystemGc().DrawRect(Rect());
00160 TRect rect=Rect();
00161 TRect ellipseRect=Rect();
00162 ellipseRect.Shrink(10,10);
00163 TRect box=Rect();
00164 box.Shrink(10,10);
00165 TRect tinyBox=Rect();
00166 tinyBox.Shrink(220,90);
00167 TInt offset=0;
00168 TPoint screenCenterPoint=rect.Center();
00169
00170
00171 TPoint constructionPoint1(15,15);
00172 TPoint constructionPoint2(200,150);
00173
00174 TPoint startPoint(50,50);
00175 TPoint endPoint(590,190);
00176
00177
00178 CArrayFix<TPoint>* mypoints=NULL;
00179 TRAPD(err,mypoints = CreatePointsArrayL());
00180 if(err)
00181 {
00182 return;
00183 }
00184
00185 TRgb black(0,0,0);
00186 TRgb darkGray(85,85,85);
00187 TRgb liteGray(170,170,170);
00188 TRgb white(255,255,255);
00189
00190 TSize penSizeBold(3,3);
00191
00192 TSize penSizeFat(30,30);
00193
00194 switch (Phase())
00195 {
00196 case 0:
00197
00198
00199 gc.Plot(screenCenterPoint);
00200 break;
00201 case 1:
00202
00203 gc.SetPenSize(penSizeBold);
00204 gc.Plot(screenCenterPoint);
00205 break;
00206 case 2:
00207
00208
00209 gc.SetPenSize(penSizeFat);
00210 gc.Plot(screenCenterPoint);
00211 break;
00212 case 3:
00213
00214 gc.DrawLine(startPoint,endPoint);
00215 break;
00216 case 4:
00217
00218 gc.SetPenSize(penSizeBold);
00219 gc.DrawLine(startPoint,endPoint);
00220 break;
00221 case 5:
00222
00223
00224 gc.SetPenSize(penSizeFat);
00225 gc.DrawLine(startPoint,endPoint);
00226 break;
00227 case 6:
00228
00229 gc.SetPenStyle(CGraphicsContext::EDottedPen);
00230 gc.DrawLine(startPoint,endPoint);
00231 break;
00232 case 7:
00233
00234 gc.SetPenStyle(CGraphicsContext::EDotDashPen);
00235 gc.DrawLine(startPoint,endPoint);
00236 break;
00237 case 8:
00238
00239 gc.MoveTo(TPoint(300,50));
00240 gc.DrawLineBy(TPoint(205,100));
00241 gc.DrawLineBy(TPoint(-410,0));
00242 gc.DrawLineBy(TPoint(205,-100));
00243 break;
00244 case 9:
00245
00246
00247 gc.SetPenSize(penSizeFat);
00248 gc.MoveTo(TPoint(300,50));
00249 gc.DrawLineBy(TPoint(205,100));
00250 gc.DrawLineBy(TPoint(-410,0));
00251 gc.DrawLineBy(TPoint(205,-100));
00252 break;
00253 case 10:
00254
00255
00256 gc.SetPenStyle(CGraphicsContext::EDotDashPen);
00257 gc.MoveTo(TPoint(300,50));
00258 gc.DrawLineTo(TPoint(505,150));
00259 gc.DrawLineTo(TPoint(95,150));
00260 gc.DrawLineTo(TPoint(300,50));
00261 break;
00262 case 11:
00263
00264 gc.DrawEllipse(ellipseRect);
00265 break;
00266 case 12:
00267
00268 gc.DrawArc(ellipseRect,constructionPoint1,constructionPoint2);
00269
00270 break;
00271 case 13:
00272
00273
00274 gc.DrawArc(ellipseRect,constructionPoint2,constructionPoint1);
00275
00276 gc.SetPenStyle(CGraphicsContext::EDottedPen);
00277 gc.MoveTo(constructionPoint1);
00278 gc.DrawLineTo(screenCenterPoint);
00279 gc.DrawLineTo(constructionPoint2);
00280 gc.SetPenSize(penSizeBold);
00281 gc.Plot(constructionPoint1);
00282 gc.Plot(constructionPoint2);
00283 gc.Plot(screenCenterPoint);
00284 break;
00285 case 14:
00286
00287 gc.SetBrushStyle(CGraphicsContext::ESolidBrush);
00288 gc.SetBrushColor(white);
00289 gc.DrawPie(ellipseRect,constructionPoint1,constructionPoint2);
00290
00291 gc.SetBrushStyle(CGraphicsContext::EVerticalHatchBrush);
00292 gc.DrawPie(ellipseRect,constructionPoint2,constructionPoint1);
00293 break;
00294 case 15:
00295 {
00296
00297 TSize cornerSize(20,20);
00298 gc.DrawRoundRect(box,cornerSize);
00299 }
00300 break;
00301 case 16:
00302 {
00303
00304
00305 TSize cornerSize(20,20);
00306
00307 TSize cornerEllipseSize(cornerSize.iHeight*2,cornerSize.iWidth*2);
00308 TRect cornerRectTl(box.iTl,cornerEllipseSize);
00309 gc.DrawRoundRect(box,cornerSize);
00310 gc.SetPenStyle(CGraphicsContext::EDottedPen);
00311 gc.DrawEllipse(cornerRectTl);
00312 }
00313 break;
00314 case 17:
00315
00316 gc.DrawPolyLine(mypoints);
00317 break;
00318 case 18:
00319
00320 gc.SetBrushStyle(CGraphicsContext::ESquareCrossHatchBrush);
00321 gc.SetBrushColor(black);
00322 gc.DrawPolygon(mypoints,CGraphicsContext::EWinding);
00323 break;
00324 case 19:
00325
00326 gc.SetBrushStyle(CGraphicsContext::EDiamondCrossHatchBrush);
00327 gc.SetBrushColor(black);
00328 gc.DrawPolygon(mypoints,CGraphicsContext::EAlternate);
00329 break;
00330 case 20:
00331 {
00332
00333
00334 gc.SetBrushStyle(CGraphicsContext::EDiamondCrossHatchBrush);
00335 gc.SetBrushColor(black);
00336 gc.DrawPolygon(mypoints,CGraphicsContext::EAlternate);
00337 TPoint screenOrigin(0,0);
00338 TSize halfScreenLR(320,240);
00339 rect.SetRect(screenOrigin,halfScreenLR);
00340 TPoint offset(halfScreenLR.iWidth,0);
00341 gc.CopyRect(offset,rect);
00342 }
00343 break;
00344 case 21:
00345
00346
00347 {
00348 CFont* font=iMessageFont;
00349 TInt fontAscent(font->AscentInPixels());
00350 offset=fontAscent+3;
00351 TInt margin=2;
00352 gc.SetBrushStyle(CGraphicsContext::ESolidBrush);
00353 gc.SetBrushColor(darkGray);
00354 gc.SetPenColor(white);
00355 gc.UseFont(iMessageFont);
00356 gc.DrawText(KTxtDrawCase21,box,offset,CGraphicsContext::ELeft,margin);
00357 }
00358 break;
00359 case 22:
00360
00361 {
00362 TInt boxHeight=box.Height();
00363 CFont* font=iMessageFont;
00364 TInt textHeight(font->HeightInPixels());
00365 offset=(textHeight+boxHeight)/2;
00366 TInt margin=0;
00367 gc.SetBrushStyle(CGraphicsContext::ESolidBrush);
00368 gc.SetBrushColor(black);
00369 gc.SetPenColor(white);
00370 gc.UseFont(iMessageFont);
00371 gc.DrawText(KTxtDrawCase22,box,offset,CGraphicsContext::ECenter,margin);
00372 }
00373 break;
00374 case 23:
00375
00376
00377 {
00378 TInt boxHeight=box.Height();
00379 CFont* font=iMessageFont;
00380 TInt fontDescent=font->DescentInPixels();
00381 offset=boxHeight-fontDescent-3;
00382 TInt margin=2;
00383 gc.SetBrushStyle(CGraphicsContext::ESolidBrush);
00384 gc.SetBrushColor(liteGray);
00385 gc.SetPenColor(darkGray);
00386 gc.UseFont(iMessageFont);
00387 gc.DrawText(KTxtDrawCase23,box,offset,CGraphicsContext::ERight,margin);
00388 }
00389 break;
00390 case 24:
00391 {
00392
00393
00394 gc.SetBrushColor(darkGray);
00395 gc.SetBrushStyle(CGraphicsContext::ESquareCrossHatchBrush);
00396 gc.DrawRect(rect);
00397
00398 gc.SetBrushColor(liteGray);
00399 gc.Clear(tinyBox);
00400 }
00401 break;
00402 case 25:
00403 {
00404
00405
00406
00407
00408
00409 gc.SetBrushColor(darkGray);
00410 gc.SetBrushStyle(CGraphicsContext::ESquareCrossHatchBrush);
00411 gc.DrawRect(rect);
00412
00413 gc.SetBrushColor(liteGray);
00414 gc.Clear(tinyBox);
00415
00416 CFont* myFont;
00417 _LIT(KTxtArial,"Arial");
00418 TFontSpec myFontSpec(KTxtArial,1);
00419 CGraphicsDevice* screenDevice=(iCoeEnv->ScreenDevice());
00420 screenDevice->GetNearestFontInTwips(myFont,myFontSpec);
00421 gc.UseFont(myFont);
00422
00423 TInt fontDescent=myFont->DescentInPixels();
00424 TPoint pos(0,tinyBox.Height()-fontDescent);
00425 pos+=tinyBox.iTl;
00426 gc.DrawText(KTxtDrawCase25,pos);
00427
00428 gc.DiscardFont();
00429 screenDevice->ReleaseFont(myFont);
00430 }
00431 break;
00432 default:
00433 break;
00434 }
00435 delete mypoints;
00436 }
00437
00438 static CArrayFix<TPoint>* CreatePointsArrayL()
00439 {
00440 CArrayFixFlat<TPoint>* pointsArray = new CArrayFixFlat<TPoint>(5);
00441
00442 TPoint point1(20,20);
00443 TPoint point2(100,190);
00444 TPoint point3(110,90);
00445 TPoint point4(50,150);
00446 TPoint point5(200,150);
00447
00448 pointsArray->AppendL(point1);
00449 pointsArray->AppendL(point2);
00450 pointsArray->AppendL(point3);
00451 pointsArray->AppendL(point4);
00452 pointsArray->AppendL(point5);
00453
00454 return pointsArray;
00455 }