📄 draw.cpp
字号:
// illustrating rounded ends and their clipping
gc.SetPenSize(penSizeFat);
gc.DrawLine(startPoint,endPoint);
break;
case 6:
// draw a dotted line from top left to bottom right
gc.SetPenStyle(CGraphicsContext::EDottedPen);
gc.DrawLine(startPoint,endPoint);
break;
case 7:
// draw a dot-dash line from top left to bottom right
gc.SetPenStyle(CGraphicsContext::EDotDashPen);
gc.DrawLine(startPoint,endPoint);
break;
case 8:
// draw a triangle by relative drawing
gc.MoveTo(TPoint(300,50)); // drawing position (300,50)
gc.DrawLineBy(TPoint(205,100)); // drawing position (505,150)
gc.DrawLineBy(TPoint(-410,0)); // drawing position (95,150)
gc.DrawLineBy(TPoint(205,-100)); // drawing position (300,50)
break;
case 9:
// draw a triangle, by relative drawing
// illustrating rounded ends at corners when using very wide lines
gc.SetPenSize(penSizeFat);
gc.MoveTo(TPoint(300,50)); // drawing position (300,50)
gc.DrawLineBy(TPoint(205,100)); // drawing position (505,150)
gc.DrawLineBy(TPoint(-410,0)); // drawing position (95,150)
gc.DrawLineBy(TPoint(205,-100)); // drawing position (300,50)
break;
case 10:
// draw a triangle by sequential drawing between specified points,
// using dot-dash line style, illustrating line pattern continuation
gc.SetPenStyle(CGraphicsContext::EDotDashPen);
gc.MoveTo(TPoint(300,50)); // drawing position (300,50)
gc.DrawLineTo(TPoint(505,150)); // drawing position (505,150)
gc.DrawLineTo(TPoint(95,150)); // drawing position (95,150)
gc.DrawLineTo(TPoint(300,50)); // drawing position (300,50)
break;
case 11:
// draw an ellipse centered in the rectangle
gc.DrawEllipse(ellipseRect);
break;
case 12:
// draw an arc centered in the rectangle
gc.DrawArc(ellipseRect,constructionPoint1,constructionPoint2);
// gc.Clear();
break;
case 13:
// draw an arc centered in the rectangle that is the other
// portion of the ellipse (arguments reversed)
gc.DrawArc(ellipseRect,constructionPoint2,constructionPoint1);
// draw construction lines and points
gc.SetPenStyle(CGraphicsContext::EDottedPen);
gc.MoveTo(constructionPoint1);
gc.DrawLineTo(screenCenterPoint);
gc.DrawLineTo(constructionPoint2);
gc.SetPenSize(penSizeBold);
gc.Plot(constructionPoint1);
gc.Plot(constructionPoint2);
gc.Plot(screenCenterPoint);
break;
case 14:
// draw a pie slice centered in the rectangle
gc.SetBrushStyle(CGraphicsContext::ESolidBrush);
gc.SetBrushColor(white);
gc.DrawPie(ellipseRect,constructionPoint1,constructionPoint2);
// draw the other portion of the elliptical disc
gc.SetBrushStyle(CGraphicsContext::EVerticalHatchBrush);
gc.DrawPie(ellipseRect,constructionPoint2,constructionPoint1);
break;
case 15:
{
// draw a rectangle with rounded corners, centered in the rectangle
TSize cornerSize(20,20); // size of a rounded corner
gc.DrawRoundRect(box,cornerSize); // same rect as text box
}
break;
case 16:
{
// draw a rectangle with rounded corners,
//centered in the rectangle, showing a corner ellipse
TSize cornerSize(20,20); // size of a rounded corner
// rect for corner ellipse is twice the corner size
TSize cornerEllipseSize(cornerSize.iHeight*2,cornerSize.iWidth*2);
TRect cornerRectTl(box.iTl,cornerEllipseSize);
gc.DrawRoundRect(box,cornerSize);
gc.SetPenStyle(CGraphicsContext::EDottedPen);
gc.DrawEllipse(cornerRectTl); // corner construction ellipse
}
break;
case 17:
// draw a polyline
gc.DrawPolyLine(mypoints);
break;
case 18:
// draw self-crossing polygon using the winding fill rule
gc.SetBrushStyle(CGraphicsContext::ESquareCrossHatchBrush);
gc.SetBrushColor(black);
gc.DrawPolygon(mypoints,CGraphicsContext::EWinding);
break;
case 19:
// draw self-crossing polygon using the alternate fill rule
gc.SetBrushStyle(CGraphicsContext::EDiamondCrossHatchBrush);
gc.SetBrushColor(black);
gc.DrawPolygon(mypoints,CGraphicsContext::EAlternate);
break;
case 20:
{
// draw self-crossing polygon using the alternate fill rule,
// and copy the lhs to the rhs of the screen
gc.SetBrushStyle(CGraphicsContext::EDiamondCrossHatchBrush);
gc.SetBrushColor(black);
gc.DrawPolygon(mypoints,CGraphicsContext::EAlternate);
TPoint screenOrigin(0,0); // top left of the screen
TSize halfScreenLR(320,240); // size of vertical half of screen
rect.SetRect(screenOrigin,halfScreenLR); // lhs of screen
TPoint offset(halfScreenLR.iWidth,0); // half screen width offset
gc.CopyRect(offset,rect); // copy lhs of screen to rhs
}
break;
case 21:
// draw some text left justified in a box,
// offset so text is just inside top of box
{
CFont* font=iMessageFont; // get the system message font
TInt fontAscent(font->AscentInPixels()); // system message font ascent
offset=fontAscent+3; // add a 3 pixel text line spacing
TInt margin=2; // left margin is two pixels
gc.SetBrushStyle(CGraphicsContext::ESolidBrush);
gc.SetBrushColor(darkGray);
gc.SetPenColor(white);
gc.UseFont(iMessageFont);
gc.DrawText(KTxtDrawCase21,box,offset,CGraphicsContext::ELeft,margin);
}
break;
case 22:
// draw some text centered in a box, (margin is zero)
{
TInt boxHeight=box.Height(); // get height of text box
CFont* font=iMessageFont; // get the system message font
TInt textHeight(font->HeightInPixels()); // system message font height
offset=(textHeight+boxHeight)/2; // 1/2 font ht below halfway down box
TInt margin=0; // margin is zero
gc.SetBrushStyle(CGraphicsContext::ESolidBrush);
gc.SetBrushColor(black);
gc.SetPenColor(white);
gc.UseFont(iMessageFont);
gc.DrawText(KTxtDrawCase22,box,offset,CGraphicsContext::ECenter,margin);
}
break;
case 23:
// draw some text right justified in a box,
// offset so text is just inside bottom of box
{
TInt boxHeight=box.Height(); // get height of text box
CFont* font=iMessageFont; // get the system message font
TInt fontDescent=font->DescentInPixels(); // system message font descent
offset=boxHeight-fontDescent-3;// offset, 3 pixel text line spacing
TInt margin=2; // right margin is two pixels
gc.SetBrushStyle(CGraphicsContext::ESolidBrush);
gc.SetBrushColor(liteGray);
gc.SetPenColor(darkGray);
gc.UseFont(iMessageFont);
gc.DrawText(KTxtDrawCase23,box,offset,CGraphicsContext::ERight,margin);
}
break;
case 24:
{
// draw a cross-hatched box
// then clear a small central rectangle
gc.SetBrushColor(darkGray);
gc.SetBrushStyle(CGraphicsContext::ESquareCrossHatchBrush);
gc.DrawRect(rect);
// clear a small rectangle
gc.SetBrushColor(liteGray); // change the brush color
gc.Clear(tinyBox); // clear to brush color
}
break;
case 25:
{
// draw a cross-hatched box
// then clear a small central rectangle
// and write some text in it in smallest Swiss font,
// (which is actually a tiny "block" print-preview font)
// starting bottom left (illustrating flicker, overlap, mess)
gc.SetBrushColor(darkGray);
gc.SetBrushStyle(CGraphicsContext::ESquareCrossHatchBrush);
gc.DrawRect(rect);
// clear a small rectangle
gc.SetBrushColor(liteGray); // change the brush color
gc.Clear(tinyBox); // clear to brush color
// get an alternative font
CFont* myFont;
_LIT(KTxtArial,"Arial");
TFontSpec myFontSpec(KTxtArial,1); // to get smallest Arial font
CGraphicsDevice* screenDevice=(iCoeEnv->ScreenDevice());
screenDevice->GetNearestFontInTwips(myFont,myFontSpec);
gc.UseFont(myFont);
// set the text drawing position & draw (demonstrating flicker)
TInt fontDescent=myFont->DescentInPixels();
TPoint pos(0,tinyBox.Height()-fontDescent);
pos+=tinyBox.iTl;
gc.DrawText(KTxtDrawCase25,pos);
// discard and destroy the font
gc.DiscardFont();
screenDevice->ReleaseFont(myFont);
}
break;
default:
break;
}
delete mypoints; // an array must be destroyed after use
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -