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