本文整理汇总了C++中Graphics::DrawString方法的典型用法代码示例。如果您正苦于以下问题:C++ Graphics::DrawString方法的具体用法?C++ Graphics::DrawString怎么用?C++ Graphics::DrawString使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Graphics
的用法示例。
在下文中一共展示了Graphics::DrawString方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: GPDrawShadowTextSimple
void GPDrawShadowTextSimple( Graphics&gc, CString& strTxtIn, CRect& rcIn, Gdiplus::Font& fontIn, ARGB BrushClrIn, ARGB shadowBrushClrIn /*= 0xff000000*/, int nOffXIn /*= 2*/, int nOffYIn /*= 2*/, StringFormat* fmtIn /*= NULL*/ )
{
Gdiplus::Font& gcfont = fontIn;
Rect rcText = CRect2Rect(rcIn);
StringFormat fmt;
fmt.SetAlignment(StringAlignmentCenter);
fmt.SetTrimming(StringTrimmingEllipsisWord);
fmt.SetLineAlignment(StringAlignmentCenter);
StringFormat& fmtUse = fmtIn == NULL? fmt:*fmtIn;
GraphicsContainer gcContainer = gc.BeginContainer();
gc.SetSmoothingMode(SmoothingModeAntiAlias);
CComBSTR btrTxtIn(strTxtIn);
SolidBrush textbrush(ARGB2Color(shadowBrushClrIn));
RectF rfText = Rect2RectF(rcText);
if (shadowBrushClrIn != 0)
{
rfText.Offset(1.0, 1.0);
gc.DrawString(btrTxtIn, -1, &gcfont, rfText, &fmtUse, &textbrush);
}
textbrush.SetColor(ARGB2Color(BrushClrIn));
gc.DrawString(btrTxtIn, -1, &gcfont, rfText, &fmtUse, &textbrush);
gc.EndContainer(gcContainer);
}
示例2: Paint
void TextSegment::Paint(Graphics &g, TextArea *theTextArea, int theStartChar, int theEndChar, int xpos, int ypos, int lineHeight)
{
int aSelStartChar = theTextArea->mSelStartChar - mAbsStartChar;
int aSelEndChar = theTextArea->mSelEndChar - mAbsStartChar;
if(theStartChar > aSelStartChar)
aSelStartChar = theStartChar;
if(theEndChar < aSelEndChar)
aSelEndChar = theEndChar;
g.SetColor(mColor);
g.SetFont(mFont);
bool fullSelection = aSelStartChar==theStartChar && aSelEndChar==theEndChar;
if(!fullSelection)
g.DrawString(mText, theStartChar, theEndChar - theStartChar, xpos, ypos);
if(aSelEndChar > aSelStartChar)
{
int x = xpos + mFont->GetStringWidth(mText,theStartChar,aSelStartChar-theStartChar);
int aWidth = mFont->GetStringWidth(mText,aSelStartChar,aSelEndChar-aSelStartChar);
g.SetColor(theTextArea->mSelColor.GetBackgroundColor(g));
g.FillRect(x,0,aWidth,lineHeight);
g.SetColor(theTextArea->mSelColor.GetForegroundColor(g,mColor));
g.DrawString(mText,aSelStartChar,aSelEndChar-aSelStartChar,x,ypos);
}
}
示例3: DrawMessage
static REAL DrawMessage(Graphics &g, const WCHAR *msg, REAL y, REAL dx, Color color)
{
ScopedMem<WCHAR> s(str::Dup(msg));
Font f(L"Impact", 16, FontStyleRegular);
RectF maxbox(0, y, dx, 0);
RectF bbox;
g.MeasureString(s, -1, &f, maxbox, &bbox);
bbox.X += (dx - bbox.Width) / 2.f;
StringFormat sft;
sft.SetAlignment(StringAlignmentCenter);
if (trans::IsCurrLangRtl())
sft.SetFormatFlags(StringFormatFlagsDirectionRightToLeft);
#if DRAW_MSG_TEXT_SHADOW
{
bbox.X--; bbox.Y++;
SolidBrush b(Color(0xff, 0xff, 0xff));
g.DrawString(s, -1, &f, bbox, &sft, &b);
bbox.X++; bbox.Y--;
}
#endif
SolidBrush b(color);
g.DrawString(s, -1, &f, bbox, &sft, &b);
return bbox.Height;
}
示例4: DrawProperty
void CIGPropertyManager::DrawProperty (const pair<wstring,wstring>& prop, const RectF& rcfNameProp, const RectF& rcfValueProp, Graphics& graphics)
{
static FontFamily fontFamily (L"Times New Roman");
static Font fontRegular (&fontFamily, 12, FontStyleRegular, UnitPixel);
static Font fontItalic (&fontFamily, 12, FontStyleItalic, UnitPixel);
static SolidBrush backgroundBrush (IGPROPERTYMANAGER_COLOR_BACKGROUND);
static SolidBrush solidFontBrush (IGPROPERTYMANAGER_COLOR_FONT);
static StringFormat format (StringFormat::GenericDefault());
graphics.FillRectangle (&backgroundBrush, Rect (Point ((int)rcfNameProp.X, (int)rcfNameProp.Y), Size ((int)(rcfNameProp.Width + rcfValueProp.Width), (int)rcfNameProp.Height)));
graphics.DrawString (prop.first.c_str(), -1, &fontItalic, rcfNameProp, &format, &solidFontBrush);
graphics.DrawString (prop.second.c_str(), -1, &fontRegular, rcfValueProp, &format, &solidFontBrush);
}
示例5: MeasureDisplayString
//*************************************************************************
// Method: MeasureDisplayString
// Description: Gets the size of a string in pixels
//
// Parameters:
// graphics - the graphics object the string will be measured on
// test - the string to measure
// font - the font to measure the string in
//
// Return Value: the size of the string
//*************************************************************************
SizeF StringTools::MeasureDisplayString(Graphics *graphics, String *text, Font *font)
{
const int width = 32;
Bitmap *bitmap = new Bitmap(width, 1, graphics);
SizeF size = graphics->MeasureString(text, font);
Graphics *g = Graphics::FromImage(bitmap);
int measuredWidth = (int)size.Width;
if (g)
{
g->Clear(Color::White);
g->DrawString(String::Concat(text, "|"), font, Brushes::Black, (float)(width - measuredWidth), (float)(0 - (font->Height / 2)));
for (int i = width - 1; i >= 0; i--)
{
measuredWidth--;
if (bitmap->GetPixel(i, 0).R == 0)
{
break;
}
}
}
return SizeF((float)measuredWidth, size.Height);
}
示例6: Paint
void BadUserItem::Paint(Graphics &g, ListArea *theListArea)
{
int aColor = theListArea->GetTextColor();
if(mSelected)
aColor = theListArea->GetSelColor().GetForegroundColor(g,aColor);
int aPaintCol = 0;
bool drawSelection = mSelected;
if(!mIsSimple)
{
aPaintCol = ((MultiListArea*)theListArea)->GetColumnPaintContext();
if(aPaintCol!=-1)
drawSelection = false;
}
if(drawSelection)
{
g.SetColor(theListArea->GetSelColor().GetBackgroundColor(g));
g.FillRect(0,0,theListArea->GetPaintColumnWidth(),mFont->GetHeight());
if(!mIsSimple)
return;
}
if(aPaintCol<0 || aPaintCol>5)
return;
g.SetColor(aColor);
g.SetFont(mFont);
g.DrawString(mColStr[aPaintCol],0,0);
}
示例7: while
void
MFCInstanceView::Draw(Graphics &dc, CRect &clipBox)
{
// !!!??? need to clip properly for short instances with long names
Pen blackPen(AlphaColor(250, rgb_black), 1);
Pen redPen(AlphaColor(250, rgb_red), 1);
SolidBrush blueBrush(AlphaColor(100, rgb_blue));
SolidBrush blackBrush(AlphaColor(100, rgb_black));
CRect clipBounds = bounds;
if (clipBox.left > bounds.left) clipBounds.left = clipBox.left-1;
if (clipBox.right < bounds.right) clipBounds.right = clipBox.right+1;
cerr << "ondraw instance view " << clipBox.left << ", " << clipBox.right << endl;
dc.FillRectangle(&blueBrush,
bounds.left, bounds.top, bounds.right-bounds.left, bounds.bottom-bounds.top);
dc.DrawRectangle(selected?&redPen:&blackPen,
bounds.left, bounds.top, clipBounds.right-bounds.left, bounds.bottom-bounds.top);
Font labelFont(L"Arial", 8.0, FontStyleRegular, UnitPoint, NULL);
wstring nm;
const char *cp = instance->sym->uniqueName();
while (*cp) { nm.push_back(*cp++); }
float lbx = bounds.left+2;
#define LBLSEP 200
if (clipBox.left > lbx) {
int nld = clipBox.left - lbx;
nld = nld/LBLSEP;
// if (nld > 2) lbx += (nld-2)*LBLSEP;
}
PointF p(lbx, clipBounds.top);
do {
dc.DrawString(nm.c_str(), -1, &labelFont, p, &blackBrush);
p.X += LBLSEP;
} while (p.X < clipBounds.right);
}
示例8: Paint
void WrappedText::Paint(Graphics &g, int x, int y)
{
if(mRichText.get()!=NULL)
{
ElementPaintInfo anInfo;
anInfo.mClipX = x;
anInfo.mClipY = y;
anInfo.mClipWidth = GetWidth();
anInfo.mClipHeight = GetHeight();
anInfo.mStartSelSegment = anInfo.mEndSelSegment = -1;
mRichText->Paint(g,x,y,anInfo);
return;
}
if(mFont.get()==NULL)
return;
g.SetFont(mFont);
int aYPos = y;
int aStrPos = 0;
for(BreakList::iterator anItr = mBreakList.begin(); anItr!=mBreakList.end(); ++anItr)
{
if(aStrPos>=mText.length())
break;
int aBreakPos = anItr->mBreakPos;
int anXPos = x;
if(mIsCentered)
anXPos += (mWidth - anItr->mWidth)/2;
g.DrawString(mText, aStrPos, aBreakPos - aStrPos, anXPos, aYPos);
aYPos += mFont->GetHeight();
aStrPos = anItr->mNextStartPos;
}
if(aStrPos<mText.length())
{
if(mIsCentered && !mBreakList.empty())
{
int aWidth = mFont->GetStringWidth(mText,aStrPos,mText.length()-aStrPos);
int anXPos = x + (mWidth - aWidth)/2;
g.DrawString(mText, aStrPos, mText.length()-aStrPos, anXPos, aYPos);
}
else
g.DrawString(mText, aStrPos, mText.length()-aStrPos, x, aYPos);
}
}
示例9: draw
void ParticalEffect::draw(Graphics& graphics) {
for (int x = 0; x < count; x ++) {
if(partsA[x].active) {
graphics.DrawString(800,110,"Drawing Partical");
partsA[x].draw(graphics);
}
}
timeTOLive--;
}
示例10: Draw
void CArcView::Draw(CDC* pDC, const std::vector<CElement*>& selection, CElement* highlight)
{
computeCollisionPoints(FALSE);
computeEnclosingRect(FALSE);
Graphics g = pDC->GetSafeHdc();
g.SetSmoothingMode(SmoothingModeAntiAlias);
Color theColor = ColorToDraw(selection, highlight);
Pen pen(theColor, static_cast<Gdiplus::REAL>(penWidth));
GraphicsPath arc;
Point currentPoint(*pathPoints.begin());
for(auto it=pathPoints.begin() + 1; it != pathPoints.end(); ++it)
{
arc.AddLine(currentPoint, *it);
currentPoint = *it;
}
//Annotation de poids
if(arcModel->getValuation() != 1)
{
//Déterminer le point de mi-chemin
PointF pathAnnotationPoint = annotationPoint((double(valPosition))/100, valDistance);
//Elements de dessin pour chaine de caracteres
CString weight;
weight.Format(_T("%d"), arcModel->getValuation());
FontFamily fontFamily(L"Arial");
Font maxfont(&fontFamily, 16, FontStyleRegular, UnitPixel);
StringFormat stringFormat;
SolidBrush brush(ColorToDraw(selection, highlight));
//Décalage à effectuer
//Peut-être aurait-il suffit de modifier le StringFormat ?
RectF boundingBox;
g.MeasureString(weight,-1,&maxfont,pathAnnotationPoint,&stringFormat,&boundingBox);
pathAnnotationPoint.X -= boundingBox.Width/2;
pathAnnotationPoint.Y += boundingBox.Height/2;
//Translation + Symétrie axiale d'axe des abscisses
g.TranslateTransform(0, pathAnnotationPoint.Y * 2);
Matrix matrix;
matrix.SetElements(1, 0, 0, -1, 0, 0);
g.MultiplyTransform(&matrix);
//Affichage du poids de l'arc
g.DrawString(weight, -1, &maxfont, pathAnnotationPoint, &stringFormat, &brush);
g.ResetTransform();
}
//Dessiner le chemin avec une flèche au bout
pen.SetCustomEndCap(arrowCap);
pen.SetLineJoin(LineJoinRound);
g.DrawPath(&pen, &arc);
}
示例11: onPaintText
void UILabel::onPaintText(Graphics& graphics, Rect rect)
{
StringFormat stringFormat;
stringFormat.SetTrimming(m_font.m_trimming);
stringFormat.SetAlignment(m_font.m_horizen);
stringFormat.SetLineAlignment(m_font.m_vertical);
Font font(m_font.m_family, m_font.m_size, m_font.m_style, m_font.m_unit);
SolidBrush brush(getTrueColor(m_font.m_color));
graphics.DrawString(m_font.m_text, -1, &font, m_font.m_rect, &stringFormat, &brush);
}
示例12: DrawSumatraLetters
static void DrawSumatraLetters(Graphics &g, Font *f, Font *fVer, REAL y)
{
LetterInfo *li;
WCHAR s[2] = { 0 };
for (int i = 0; i < dimof(gLetters); i++) {
li = &gLetters[i];
s[0] = li->c;
if (s[0] == ' ')
return;
g.RotateTransform(li->rotation, MatrixOrderAppend);
#if DRAW_TEXT_SHADOW
// draw shadow first
SolidBrush b2(li->colShadow);
PointF o2(li->x - 3.f, y + 4.f + li->dyOff);
g.DrawString(s, 1, f, o2, &b2);
#endif
SolidBrush b1(li->col);
PointF o1(li->x, y + li->dyOff);
g.DrawString(s, 1, f, o1, &b1);
g.RotateTransform(li->rotation, MatrixOrderAppend);
g.ResetTransform();
}
// draw version number
REAL x = gLetters[dimof(gLetters)-1].x;
g.TranslateTransform(x, y);
g.RotateTransform(45.f);
REAL x2 = 15;
REAL y2 = -34;
WCHAR *ver_s = L"v" CURR_VERSION_STR;
#if DRAW_TEXT_SHADOW
SolidBrush b1(Color(0, 0, 0));
g.DrawString(ver_s, -1, fVer, PointF(x2 - 2, y2 - 1), &b1);
#endif
SolidBrush b2(Color(0xff, 0xff, 0xff));
g.DrawString(ver_s, -1, fVer, PointF(x2, y2), &b2);
g.ResetTransform();
}
示例13: drawTab
void IGTabBar::drawTab (HDC hdc, UINT nSize, bool bSelected, bool bOver, const wchar_t *pcwTitle)
{
Graphics graphics (hdc);
Color colBackground (Color (GetRValue (m_cBackGround), GetGValue (m_cBackGround), GetBValue (m_cBackGround)));
SolidBrush solBrushBackground (colBackground);
graphics.FillRectangle (&solBrushBackground, Rect (0, 0, nSize, BUTTON_HEIGHT - 1));
SolidBrush solBrushTab (bSelected ? IGTAB_COLORBACKGND : IGTAB_COLOR_UNSELECTED);
GraphicsPath pathBorder;
pathBorder.StartFigure();
pathBorder.AddArc (Rect (0, 0, IGTAB_CORNERDIAM, IGTAB_CORNERDIAM), 180.0f, 90.0f);
pathBorder.AddArc (Rect (nSize - IGTAB_CORNERDIAM, 0, IGTAB_CORNERDIAM, IGTAB_CORNERDIAM), -90.0f, 90.0f);
pathBorder.AddLine (Point (nSize, BUTTON_HEIGHT + (bSelected ? 1 : 0)), Point (0, BUTTON_HEIGHT + (bSelected ? 1 : 0)));
graphics.FillPath (&solBrushTab, &pathBorder);
if (bOver)
{
PathGradientBrush pthGrBrush (&pathBorder);
pthGrBrush.SetCenterPoint (PointF (0.7f * (float)nSize,
0.3f * (float)BUTTON_HEIGHT));
pthGrBrush.SetCenterColor (IGTAB_COLOR_FRAMEIN);
Color colors[] = {IGTAB_COLOR_FRAMEOUT};
int count = 1;
pthGrBrush.SetSurroundColors (colors, &count);
graphics.FillPath (&pthGrBrush, &pathBorder);
}
FontFamily fontFamily(L"Times New Roman");
Font font(&fontFamily, 16, FontStyleRegular, UnitPixel);
PointF pointF(20.0f, 5.0f);
SolidBrush solidFontBrush (bSelected ? IGTAB_COLOR_FONTENABLED : IGTAB_COLOR_FONTDISABLED);
StringFormat format(StringFormat::GenericDefault());
format.SetAlignment (StringAlignmentCenter);
graphics.DrawString (pcwTitle, -1, &font, RectF (0.0f, 0.0f, (float)nSize, (float)BUTTON_HEIGHT),
&format, &solidFontBrush);
Pen penBorder (IGTAB_COLORBORDER, 1);
GraphicsPath pathBorderOut;
pathBorderOut.StartFigure();
pathBorderOut.AddArc (Rect (0, 0, IGTAB_CORNERDIAM + 1, IGTAB_CORNERDIAM + 1), 180.0f, 90.0f);
pathBorderOut.AddArc (Rect (nSize - IGTAB_CORNERDIAM - 2, 0, IGTAB_CORNERDIAM + 1, IGTAB_CORNERDIAM + 1), -90.0f, 90.0f);
pathBorderOut.AddLine (Point (nSize - 1, BUTTON_HEIGHT + (bSelected ? 1 : 0)), Point (0, BUTTON_HEIGHT + (bSelected ? 1 : 0)));
pathBorderOut.CloseFigure();
graphics.DrawPath (&penBorder, &pathBorderOut);
}
示例14: Paint
///////////////////////////////////////////////////////////////////////////////
// Paint: Draw the credits.
///////////////////////////////////////////////////////////////////////////////
void ScrollingTextComponent::Paint(Graphics &g)
{
Component::Paint(g);
// Draw the background.
g.SetFont(GetDefaultFont());
g.SetColor(0xFFFFFF);
g.FillRect(2,2,Width()-4,Height()-4);
// Draw the frame.
g.ApplyColorSchemeColor(StandardColor_3DHilight);
g.DrawRect(0,0,Width(),Height());
g.DrawRect(1,1,Width()-1,Height()-1);
g.ApplyColorSchemeColor(StandardColor_3DShadow);
g.DrawRect(0, 0,Width()-1,Height()-1);
// Draw the text.
int nTop = mScrollTop;
CreditsList::iterator Itr = mLines.begin();
while (Itr != mLines.end())
{
CreditLineInfo& LineInfo = *Itr;
int nStrHt = g.GetFont()->GetHeight();
if (nTop < Height() / 3)
g.SetColor(DimColor(LineInfo.GetColor(), nTop * 100 / (Height() / 3)));
else if (Height() - nTop <= nStrHt)
g.SetColor(0xFFFFFF);
else if (nTop > (Height() * 2 / 3) - nStrHt)
g.SetColor(DimColor(LineInfo.GetColor(), ((Height() - (nTop + nStrHt)) * 100 / (Height() / 3))));
else
g.SetColor(LineInfo.GetColor());
if (g.GetColor() != 0xFFFFFF && nTop > 2 && nTop < Height() - nStrHt - 2)
{
int nStrWd = g.GetFont()->GetStringWidth(LineInfo.GetLine());
g.DrawString(LineInfo.GetLine(), (Width() - nStrWd) / 2, nTop);
}
nTop += nStrHt;
++Itr;
}
mTotalTextHeight = nTop - mScrollTop;
}
示例15: DrawRulerMarks
void CToolRegularRuler::DrawRulerMarks(Graphics& graph)
{
int nNumber = 0;
int nbegin = m_rcHot.left + 10;
int nend = m_rcHot.right - 10;
CString strNumber;
Font fontNumber(L"Arial", 10);
SolidBrush brush(Color::Black);
StringFormat format;
format.SetAlignment(StringAlignmentCenter);
Pen penDraw(Color::Black, 1);
PointF ptBegin((float)nbegin, m_rcHot.top + 1.0f);
PointF ptEnd = ptBegin;
graph.SetTextRenderingHint(TextRenderingHintAntiAlias);
for(int i = nbegin; i < nend; i+= 10)
{
ptEnd.X = (float)i;
ptBegin.X = (float)i;
if((i - nbegin) % 100 == 0)
{
ptEnd.Y = ptBegin.Y + 30;
graph.DrawLine(&penDraw, ptBegin, ptEnd);
nNumber = (i - nbegin) / 100;
strNumber.Format(_T("%d"), nNumber);
graph.DrawString(strNumber, strNumber.GetLength(), &fontNumber, ptEnd, &format, &brush);
}
else if((i - nbegin) % 50 == 0)
{
ptEnd.Y = ptBegin.Y + 20;
graph.DrawLine(&penDraw, ptBegin, ptEnd);
}
else
{
ptEnd.Y = ptBegin.Y + 10;
graph.DrawLine(&penDraw, ptBegin, ptEnd);
}
}
}