diff -r f345bda72bc4 -r 43e37759235e Symbian3/Examples/guid-6013a680-57f9-415b-8851-c4fa63356636/_draw_8cpp-source.html --- a/Symbian3/Examples/guid-6013a680-57f9-415b-8851-c4fa63356636/_draw_8cpp-source.html Tue Mar 30 11:56:28 2010 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,467 +0,0 @@ - - -TB10.1 Example Applications: examples/Graphics/GraphicsShell/Draw.cpp Source File - - - - -

examples/Graphics/GraphicsShell/Draw.cpp

00001 // Copyright (c) 2000-2009 Nokia Corporation and/or its subsidiary(-ies).
-00002 // All rights reserved.
-00003 // This component and the accompanying materials are made available
-00004 // under the terms of "Eclipse Public License v1.0"
-00005 // which accompanies this distribution, and is available
-00006 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
-00007 //
-00008 // Initial Contributors:
-00009 // Nokia Corporation - initial contribution.
-00010 //
-00011 // Contributors:
-00012 //
-00013 // Description:
-00014 //
-00015 
-00016 #include "GraphicsControl.h"
-00017 
-00018 #include <coemain.h>
-00019 
-00020 // Text printed to the console in UpdateModeL()
-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 // Text printed to the console in UpdateModeL()
-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& /* aRect */) const
-00152         {
-00153         // put the next line back in to see the individual drawing actions
-00154         // (iCoeEnv->WsSession()).SetAutoFlush(ETrue);
-00155         // draw surrounding rectangle
-00156         CWindowGc& gc=SystemGc(); // graphics context we draw to
-00157         gc.UseFont(iMessageFont); // use the system message font
-00158         gc.Clear();
-00159         SystemGc().DrawRect(Rect()); // surrounding rectangle to draw into
-00160         TRect rect=Rect(); // a centered rectangle of the default size
-00161         TRect ellipseRect=Rect(); // for arcs and ellipse
-00162         ellipseRect.Shrink(10,10); // set size so inside the border rectangle
-00163         TRect box=Rect(); // a smaller centered rectangle, for text in a box
-00164         box.Shrink(10,10); // set size of text box
-00165         TRect tinyBox=Rect(); // a tiny box to clear
-00166         tinyBox.Shrink(220,90); // set size of tiny box to clear
-00167         TInt offset=0; // offset, for text in a box
-00168         TPoint screenCenterPoint=rect.Center(); // the center of the screen 
-00169         // set up a pair of construction points for arc and pie slice drawing
-00170         // set up the size for half a screen (divided vertically)
-00171         TPoint constructionPoint1(15,15); // outside the construction ellipse
-00172         TPoint constructionPoint2(200,150); // inside the construction ellipse
-00173         // set up a pair of points for drawing diagonal lines
-00174         TPoint startPoint(50,50);
-00175         TPoint endPoint(590,190);
-00176         // set up an array of points for drawing a polyline and a polygon etc
-00177         // will be used relative to top left of rectangle
-00178         CArrayFix<TPoint>* mypoints=NULL;
-00179         TRAPD(err,mypoints = CreatePointsArrayL());
-00180         if(err)
-00181                 {
-00182                 return;
-00183                 }
-00184         // set up a black, a dark gray, a lite gray and a white RGB color
-00185         TRgb black(0,0,0);
-00186         TRgb darkGray(85,85,85);
-00187         TRgb liteGray(170,170,170);
-00188         TRgb white(255,255,255); // appears as blank screen gray-green color
-00189         // Set up a "bold" size for the pen tip to (default is 1,1)
-00190         TSize penSizeBold(3,3);
-00191         // Set up a "fat" size for the pen tip
-00192         TSize penSizeFat(30,30);
-00193         // decide what to do, and do it
-00194         switch (Phase())
-00195                 {
-00196                 case 0:
-00197                         // draw a single pixel point in the center of the screen
-00198                         // it is so small that some text is needed to explain the screen...
-00199                         gc.Plot(screenCenterPoint);
-00200                         break;
-00201                 case 1:
-00202                         // draw a "bold" point 3 pixels across
-00203                         gc.SetPenSize(penSizeBold);
-00204                         gc.Plot(screenCenterPoint);
-00205                         break;
-00206                 case 2:
-00207                         // draw a "fat" point (circular blob),
-00208                         // illustrating the effect of a very wide pen
-00209                         gc.SetPenSize(penSizeFat);
-00210                         gc.Plot(screenCenterPoint);
-00211                         break;
-00212                 case 3:
-00213                         // draw a thin line fromtop left to bottom right
-00214                         gc.DrawLine(startPoint,endPoint);
-00215                         break;
-00216                 case 4:
-00217                         // draw a "bold" line fromtop left to bottom right
-00218                         gc.SetPenSize(penSizeBold);
-00219                         gc.DrawLine(startPoint,endPoint);
-00220                         break;
-00221                 case 5:
-00222                         // draw a rather wide line from top left to bottom right,
-00223                         // illustrating rounded ends and their clipping
-00224                         gc.SetPenSize(penSizeFat);
-00225                         gc.DrawLine(startPoint,endPoint);
-00226                         break;
-00227                 case 6:
-00228                         // draw a dotted line from top left to bottom right
-00229                         gc.SetPenStyle(CGraphicsContext::EDottedPen);
-00230                         gc.DrawLine(startPoint,endPoint);
-00231                         break;
-00232                 case 7:
-00233                         // draw a dot-dash line from top left to bottom right
-00234                         gc.SetPenStyle(CGraphicsContext::EDotDashPen);
-00235                         gc.DrawLine(startPoint,endPoint);
-00236                         break;
-00237                 case 8:
-00238                         // draw a triangle by relative drawing
-00239                         gc.MoveTo(TPoint(300,50)); // drawing position (300,50)
-00240                         gc.DrawLineBy(TPoint(205,100)); // drawing position (505,150)
-00241                         gc.DrawLineBy(TPoint(-410,0)); // drawing position (95,150)
-00242                         gc.DrawLineBy(TPoint(205,-100)); // drawing position (300,50)
-00243                         break;
-00244                 case 9:
-00245                         // draw a triangle, by relative drawing
-00246                         // illustrating rounded ends at corners when using very wide lines
-00247                         gc.SetPenSize(penSizeFat);
-00248                         gc.MoveTo(TPoint(300,50)); // drawing position (300,50)
-00249                         gc.DrawLineBy(TPoint(205,100)); // drawing position (505,150)
-00250                         gc.DrawLineBy(TPoint(-410,0)); // drawing position (95,150)
-00251                         gc.DrawLineBy(TPoint(205,-100)); // drawing position (300,50)
-00252                         break;
-00253                 case 10:
-00254                         // draw a triangle by sequential drawing between specified points,
-00255                         // using dot-dash line style, illustrating line pattern continuation 
-00256                         gc.SetPenStyle(CGraphicsContext::EDotDashPen);
-00257                         gc.MoveTo(TPoint(300,50)); // drawing position (300,50)
-00258                         gc.DrawLineTo(TPoint(505,150)); // drawing position (505,150)
-00259                         gc.DrawLineTo(TPoint(95,150)); // drawing position (95,150)
-00260                         gc.DrawLineTo(TPoint(300,50)); // drawing position (300,50)
-00261                         break;
-00262                 case 11:
-00263                         // draw an ellipse centered in the rectangle
-00264                         gc.DrawEllipse(ellipseRect);
-00265                         break;
-00266                 case 12:
-00267                         // draw an arc centered in the rectangle
-00268                         gc.DrawArc(ellipseRect,constructionPoint1,constructionPoint2);
-00269                         // gc.Clear();
-00270                         break;
-00271                 case 13:
-00272                         // draw an arc centered in the rectangle that is the other
-00273                         // portion of the ellipse (arguments reversed)
-00274                         gc.DrawArc(ellipseRect,constructionPoint2,constructionPoint1);
-00275                         // draw construction lines and points
-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                         // draw a pie slice centered in the rectangle
-00287                         gc.SetBrushStyle(CGraphicsContext::ESolidBrush);
-00288                         gc.SetBrushColor(white);
-00289                         gc.DrawPie(ellipseRect,constructionPoint1,constructionPoint2);
-00290                         // draw the other portion of the elliptical disc
-00291                         gc.SetBrushStyle(CGraphicsContext::EVerticalHatchBrush);
-00292                         gc.DrawPie(ellipseRect,constructionPoint2,constructionPoint1);
-00293                         break;
-00294                 case 15:
-00295                         {
-00296                         // draw a rectangle with rounded corners, centered in the rectangle
-00297                         TSize cornerSize(20,20); // size of a rounded corner
-00298                         gc.DrawRoundRect(box,cornerSize); // same rect as text box
-00299                         }
-00300                         break;
-00301                 case 16:
-00302                         {
-00303                         // draw a rectangle with rounded corners,
-00304                         //centered in the rectangle, showing a corner ellipse
-00305                         TSize cornerSize(20,20); // size of a rounded corner
-00306                         // rect for corner ellipse is twice the corner size
-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); // corner construction ellipse
-00312                         }
-00313                         break;
-00314                 case 17:
-00315                         // draw a polyline
-00316                         gc.DrawPolyLine(mypoints);
-00317                         break;
-00318                 case 18:
-00319                         // draw self-crossing polygon using the winding fill rule
-00320                         gc.SetBrushStyle(CGraphicsContext::ESquareCrossHatchBrush);
-00321                         gc.SetBrushColor(black);
-00322                         gc.DrawPolygon(mypoints,CGraphicsContext::EWinding);
-00323                         break;
-00324                 case 19:
-00325                         // draw self-crossing polygon using the alternate fill rule
-00326                         gc.SetBrushStyle(CGraphicsContext::EDiamondCrossHatchBrush);
-00327                         gc.SetBrushColor(black);
-00328                         gc.DrawPolygon(mypoints,CGraphicsContext::EAlternate);
-00329                         break;
-00330                 case 20:
-00331                         {
-00332                         // draw self-crossing polygon using the alternate fill rule,
-00333                         // and copy the lhs to the rhs of the screen
-00334                         gc.SetBrushStyle(CGraphicsContext::EDiamondCrossHatchBrush);
-00335                         gc.SetBrushColor(black);
-00336                         gc.DrawPolygon(mypoints,CGraphicsContext::EAlternate);
-00337                         TPoint screenOrigin(0,0); // top left of the screen
-00338                         TSize halfScreenLR(320,240); // size of vertical half of screen
-00339                         rect.SetRect(screenOrigin,halfScreenLR); // lhs of screen
-00340                         TPoint offset(halfScreenLR.iWidth,0); // half screen width offset
-00341                         gc.CopyRect(offset,rect); //  copy lhs of screen to rhs
-00342                         }
-00343                         break;
-00344                 case 21:
-00345                         // draw some text left justified in a box,
-00346                         // offset so text is just inside top of box
-00347                         {
-00348                         CFont* font=iMessageFont; // get the system message font
-00349                         TInt fontAscent(font->AscentInPixels()); // system message font ascent
-00350                         offset=fontAscent+3; // add a 3 pixel text line spacing
-00351                         TInt margin=2; // left margin is two pixels
-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                         // draw some text centered in a box, (margin is zero)
-00361                         {
-00362                         TInt boxHeight=box.Height(); // get height of text box
-00363                         CFont* font=iMessageFont; // get the system message font
-00364                         TInt textHeight(font->HeightInPixels()); // system message font height
-00365                         offset=(textHeight+boxHeight)/2; // 1/2 font ht below halfway down box
-00366                         TInt margin=0; // margin is zero
-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                         // draw some text right justified in a box,
-00376                         // offset so text is just inside bottom of box
-00377                         {
-00378                         TInt boxHeight=box.Height(); // get height of text box
-00379                         CFont* font=iMessageFont; // get the system message font
-00380                         TInt fontDescent=font->DescentInPixels(); // system message font descent
-00381                         offset=boxHeight-fontDescent-3;// offset, 3 pixel text line spacing 
-00382                         TInt margin=2; // right margin is two pixels
-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                         // draw a cross-hatched box
-00393                         // then clear a small central rectangle
-00394                         gc.SetBrushColor(darkGray);
-00395                         gc.SetBrushStyle(CGraphicsContext::ESquareCrossHatchBrush);
-00396                         gc.DrawRect(rect);
-00397                         // clear a small rectangle
-00398                         gc.SetBrushColor(liteGray); // change the brush color
-00399                         gc.Clear(tinyBox); // clear to brush color
-00400                         }
-00401                         break;
-00402                 case 25:
-00403                         {
-00404                         // draw a cross-hatched box
-00405                         // then clear a small central rectangle
-00406                         // and write some text in it in smallest Swiss font,
-00407                         // (which is actually a tiny "block" print-preview font)
-00408                         // starting bottom left (illustrating flicker, overlap, mess)
-00409                         gc.SetBrushColor(darkGray);
-00410                         gc.SetBrushStyle(CGraphicsContext::ESquareCrossHatchBrush);
-00411                         gc.DrawRect(rect);
-00412                         // clear a small rectangle
-00413                         gc.SetBrushColor(liteGray); // change the brush color
-00414                         gc.Clear(tinyBox); // clear to brush color
-00415                         // get an alternative font
-00416                         CFont* myFont;
-00417                         _LIT(KTxtArial,"Arial");
-00418                         TFontSpec myFontSpec(KTxtArial,1); // to get smallest Arial font
-00419                         CGraphicsDevice* screenDevice=(iCoeEnv->ScreenDevice());
-00420                         screenDevice->GetNearestFontInTwips(myFont,myFontSpec);
-00421                         gc.UseFont(myFont);
-00422                         // set the text drawing position & draw (demonstrating flicker)
-00423                         TInt fontDescent=myFont->DescentInPixels();
-00424                         TPoint pos(0,tinyBox.Height()-fontDescent);
-00425                         pos+=tinyBox.iTl;
-00426                         gc.DrawText(KTxtDrawCase25,pos);
-00427                         // discard and destroy the font
-00428                         gc.DiscardFont();
-00429                         screenDevice->ReleaseFont(myFont);
-00430                         }
-00431                         break;
-00432                 default:
-00433                         break;
-00434                 }
-00435         delete mypoints; // an array must be destroyed after use
-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         }
-

Generated on Thu Jan 21 10:32:58 2010 for TB10.1 Example Applications by  - -doxygen 1.5.3
- -