本文整理汇总了C++中gdiplus::Graphics类的典型用法代码示例。如果您正苦于以下问题:C++ Graphics类的具体用法?C++ Graphics怎么用?C++ Graphics使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Graphics类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: Draw
void Chart::Draw(Gdiplus::Graphics &graph)
{
g = &graph;
graph.FillRectangle(&SolidBrush(Color(0xffaaaaaa)), rect.left, rect.top, rect.right, rect.bottom);
}
示例2: InitTextStyles
void InitTextStyles(Gdiplus::Graphics& gfx, Gdiplus::StringFormat& format, const Style& style)
{
gfx.SetTextRenderingHint(AntialiasingFromStyleString(style.Get(L"antialiasing", L"default")));
format.SetTrimming(StringTrimmingFromStyleString(style.Get(L"trimming", L"default")));
}
示例3: DrawItem
void CBtnRoundImg::DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct)
{
CDC dc;
dc.Attach(lpDrawItemStruct->hDC); //°´Å¥¿Ø¼þDC
COLORREF clrBK = RGB(255,255,255);
switch(m_nCtrlState)
{
case CTRL_NOFOCUS:
clrBK = m_clrBKUnfocus;
break;
case CTRL_FOCUS:
clrBK = m_clrBKFocus;
break;
case CTRL_SELECTED:
clrBK = m_clrBKSelected;
break;
default:
break;
}
if (IsWindowEnabled()==FALSE)
{
clrBK = m_clrBKDisable;
}
//draw background
CRect rect(lpDrawItemStruct->rcItem);
//dc.FillSolidRect(&rect,clrBK);
DrawRoundRect(dc, 5,rect,clrBK);
//draw image
if (m_strPngPath != _T(""))
{
Gdiplus::Image imageBtn(m_strPngPath);
if (imageBtn.GetLastStatus() != Ok)
{
ASSERT(FALSE);
}
;
HRGN hRgnOld = (HRGN)::SelectObject(lpDrawItemStruct->hDC, m_hRgnBtn);
Gdiplus::Graphics * pGrp = Graphics::FromHDC(lpDrawItemStruct->hDC);
pGrp->Clear(Color::White);
CRect rectBtn;
GetClientRect(&rectBtn);
int startX = (rectBtn.Width() - imageBtn.GetWidth())/2;
int startY = (rectBtn.Height() - imageBtn.GetHeight())/2;
startX = 0;
startY = 0;
if (lpDrawItemStruct->itemState & ODS_SELECTED) //Ñ¡ÖÐ״̬£¬Í¼Æ¬Æ«ÒÆÒ»¸öÏñËØ
{
pGrp->DrawImage(&imageBtn, startX+1, startY+1, startX+imageBtn.GetWidth(), startY+imageBtn.GetHeight());
}
else //ĬÈÏ״̬
{
pGrp->DrawImage(&imageBtn, startX, startY, startX+imageBtn.GetWidth(), startY+imageBtn.GetHeight());
}
delete pGrp;
pGrp = NULL;
::SelectObject(lpDrawItemStruct->hDC, hRgnOld);
}
CFont* pOldFont;
if (m_pFont)
{
pOldFont = dc.SelectObject(m_pFont);
}
COLORREF clrOld = dc.SetTextColor(m_clrFont);
CString strText;
GetWindowText(strText);
if (strText != _T(""))
{
int test = 1;
}
int oldMode = dc.SetBkMode(TRANSPARENT);
dc.DrawText(strText, -1, &lpDrawItemStruct->rcItem, DT_CENTER|DT_SINGLELINE|DT_VCENTER);
dc.SetBkMode(oldMode);
dc.SetTextColor(clrOld);
if (m_pFont)
{
dc.SelectObject(pOldFont);
}
dc.Detach();
}
示例4: drawBitmap
//-----------------------------------------------------------------------------
void GdiplusDrawContext::drawBitmap (CBitmap* cbitmap, const CRect& dest, const CPoint& offset, float alpha)
{
alpha *= currentState.globalAlpha;
if (alpha == 0.f || pGraphics == 0)
return;
IPlatformBitmap* platformBitmap = cbitmap ? cbitmap->getPlatformBitmap () : 0;
GdiplusBitmap* gpb = platformBitmap ? dynamic_cast<GdiplusBitmap*> (platformBitmap) : 0;
Gdiplus::Bitmap* bitmap = gpb ? gpb->getBitmap () : 0;
if (bitmap)
{
GdiplusDrawScope drawScope (pGraphics, currentState.clipRect, getCurrentTransform ());
Gdiplus::ImageAttributes imageAtt;
if (alpha != 1.f)
{
// introducing the alpha blend matrix
Gdiplus::ColorMatrix colorMatrix =
{
1.0f, 0.0f, 0.0f, 0.0f, 0.0f,
0.0f, 1.0f, 0.0f, 0.0f, 0.0f,
0.0f, 0.0f, 1.0f, 0.0f, 0.0f,
0.0f, 0.0f, 0.0f, alpha, 0.0f,
0.0f, 0.0f, 0.0f, 0.0f, 0.0f,
};
// create the imageattribute modifier
imageAtt.SetColorMatrix (&colorMatrix, Gdiplus::ColorMatrixFlagsDefault,
Gdiplus::ColorAdjustTypeBitmap);
#if 1
Gdiplus::Rect myDestRect(
(INT)dest.left,
(INT)dest.top,
(INT)dest.getWidth (),
(INT)dest.getHeight ());
pGraphics->DrawImage (
bitmap,
myDestRect,
(INT)offset.x,
(INT)offset.y,
(INT)dest.getWidth (),
(INT)dest.getHeight (),
Gdiplus::UnitPixel,
&imageAtt);
#else
// create a temporary bitmap to prevent OutOfMemory errors
Gdiplus::Bitmap myBitmapBuffer ((INT)dest.getWidth (), (INT)dest.getHeight (),PixelFormat32bppARGB);
// create a graphics context for the temporary bitmap
Gdiplus::Graphics* myGraphicsBuffer = Gdiplus::Graphics::FromImage (&myBitmapBuffer);
// copy the rectangle we want to paint to the temporary bitmap
Gdiplus::Rect myTransRect(
0,
0,
(INT)dest.getWidth (),
(INT)dest.getHeight ());
// transfer the bitmap (without modification by imageattr!)
myGraphicsBuffer->DrawImage (
bitmap,myTransRect,
(INT)offset.x,
(INT)offset.y,
(INT)dest.getWidth (),
(INT)dest.getHeight (),
Gdiplus::UnitPixel,
0);
// now transfer the temporary to the real context at the advised location
Gdiplus::Rect myDestRect (
(INT)dest.left,
(INT)dest.top,
(INT)dest.getWidth (),
(INT)dest.getHeight ());
// transfer from temporary bitmap to real context (with imageattr)
pGraphics->DrawImage (
&myBitmapBuffer,
myDestRect,
(INT)0,
(INT)0,
(INT)dest.getWidth (),
(INT)dest.getHeight (),
Gdiplus::UnitPixel,
&imageAtt);
// delete the temporary context of the temporary bitmap
delete myGraphicsBuffer;
#endif
}
else
{
Gdiplus::Rect myDestRect(
(INT)dest.left,
(INT)dest.top,
(INT)dest.getWidth (),
(INT)dest.getHeight ());
pGraphics->DrawImage (
bitmap,
myDestRect,
(INT)offset.x,
(INT)offset.y,
(INT)dest.getWidth (),
(INT)dest.getHeight (),
Gdiplus::UnitPixel,
0);
}
//.........这里部分代码省略.........
示例5: Draw
void CLine::Draw(Gdiplus::Graphics& graphics)
{
Pen pen(Color::Red);
graphics.DrawLine(&pen, _point1, _point2);
}
示例6: PluginUpdateOverlay
//
// Draw overlay
//
PLUGIN_EXPORT void PluginUpdateOverlay()
{
if (!pRenderHelper)
return;
// lock overlay image
auto pLock = pRenderHelper->BeginFrame();
if (!pLock)
return;
int w = pLock->dwWidth;
int h = pLock->dwHeight;
Gdiplus::Graphics *pGraphics = pRenderHelper->GetGraphics();
//-----------------------------------------
// draw Text Overlay
// set options
pGraphics->SetTextRenderingHint(Gdiplus::TextRenderingHintAntiAlias);
// clear back
pGraphics->Clear(Gdiplus::Color(0, 0, 0, 0));
WCHAR s[128];
_itow_s(PC_GetConfirmedProcessID(), s, 10);
if (PathFileExists(pFileName)) {
string textContents = "";
WIN32_FILE_ATTRIBUTE_DATA attribs;
GetFileAttributesExW(pFileName, GetFileExInfoStandard, &attribs);
FILETIME modifyTime = attribs.ftLastWriteTime;
if (CompareFileTime(&modifyTime, &oldModifyTime) > 0) {
oldModifyTime = modifyTime;
string line;
ifstream myfile;
myfile.open(pFileName);
if (myfile.is_open())
{
while (getline(myfile, line))
{
textContents += line;
}
myfile.close();
}
textLength = textContents.length();
wcTextContents[textLength] = 0;
std::copy(textContents.begin(), textContents.end(), wcTextContents);
}
}
// draw back if required
if (bShowBackground)
{
Gdiplus::RectF bound;
pRenderHelper->GetTextExtent(wcTextContents, pFont, &bound);
pGraphics->FillRectangle(pBackBrush, bound);
}
// draw text
Gdiplus::RectF bound;
pRenderHelper->GetTextExtent(wcTextContents, pFont, &bound);
if (bound.Width > w) {
wchar_t wcNewTextContents[256];
wcNewTextContents[textLength * 2 + 5] = 0;
swprintf_s(wcNewTextContents, L"%s %s", wcTextContents, wcTextContents);
Gdiplus::RectF newbound;
pRenderHelper->GetTextExtent(wcNewTextContents, pFont, &newbound);
pRenderHelper->DrawString(wcNewTextContents, pFont, Gdiplus::Point(0 - scroll, 0), pTextBrush, pBackBrush);
scroll += 2;
if (scroll > newbound.Width - bound.Width)
scroll = 0;
}
else {
pRenderHelper->DrawString(wcTextContents, pFont, Gdiplus::Point(0, 0), pTextBrush, pBackBrush);
}
// fill overlay image
pRenderHelper->EndFrame();
}
示例7: Render
void GameManager::Render(Gdiplus::Graphics& canvas, const CRect& clientRect)
{
////////////////////////////////////////////////////////////////////////////////
// Begin example code
// Save the current transformation of the scene
Gdiplus::Matrix transform;
canvas.GetTransform(&transform);
// Offset by the negative of the player direction
canvas.TranslateTransform(-(Gdiplus::REAL)playerPtr->location.X, -(Gdiplus::REAL)playerPtr->location.Y);
int numRows = clientRect.Height() / CellSize;
int numCols = clientRect.Width() / CellSize;
// draw horizontal lines for grid
for (int row = 0; row < numRows; ++row)
{
Vector2i start = Vector2i(0, row * CellSize);
Vector2i end = Vector2i(clientRect.Width(), row * CellSize);
GameFrameworkInstance.DrawLine(canvas,
start,
end,
Gdiplus::Color::White);
}
// draw vertical lines for grid
for (int col = 0; col < numCols; ++col)
{
Vector2i start = Vector2i(col * CellSize, 0);
Vector2i end = Vector2i(col * CellSize, clientRect.Height());
GameFrameworkInstance.DrawLine(canvas,
start,
end,
Gdiplus::Color::White);
}
// Draw all of the objects
for (GameObject* objectPtr : gameObjects)
{
objectPtr->Render(canvas);
}
// Render method demonstration (You can remove all of this code)
GameFrameworkInstance.DrawLine(canvas, Vector2i(200, 200), Vector2i(400, 200), Gdiplus::Color::White);
GameFrameworkInstance.DrawRectangle(canvas, AABBi(Vector2i(10, 110), Vector2i(100, 200)), false, Gdiplus::Color::White);
GameFrameworkInstance.DrawRectangle(canvas, AABBi(Vector2i(200, 110), Vector2i(300, 200)), true, Gdiplus::Color::White);
//// restore the transform
//canvas.SetTransform(&transform);
GameFrameworkInstance.DrawCircle(canvas, Vector2i(200, 200), 50, false, Gdiplus::Color::White);
GameFrameworkInstance.DrawCircle(canvas, Vector2i(400, 200), 50, true, Gdiplus::Color::White);
GameFrameworkInstance.DrawText(canvas, Vector2i(10, 300), 12, "Arial", "Hello World!", Gdiplus::Color::White);
// Load the image file Untitled.png from the Images folder. Give it the unique name of Image1
ImageWrapper* image1 = GameFrameworkInstance.GetLoadedImage(Image1);
GameFrameworkInstance.DrawImage(canvas, Vector2i(400, 400), image1);
// Restore the transformation of the scene
canvas.SetTransform(&transform);
// End example code
////////////////////////////////////////////////////////////////////////////////
// Build Menu
Vector2i dimensions = GameManagerInstance.GetScreenDimensions();
Vector2i centrePoint = dimensions * 0.1f;
GameFrameworkInstance.DrawRectangle(canvas,
AABBi(Vector2i(0, 0) + centrePoint,
Vector2i(150, 500) + centrePoint),
true, Gdiplus::Color::Gray);
GameFrameworkInstance.DrawText(canvas, Vector2i(10, 10) + centrePoint, 12, "Arial", "[1] Wall", Gdiplus::Color::White);
GameFrameworkInstance.DrawText(canvas, Vector2i(10, 35) + centrePoint, 12, "Arial", "[2] Damage Zone", Gdiplus::Color::White);
GameFrameworkInstance.DrawText(canvas, Vector2i(10, 60) + centrePoint, 12, "Arial", "[3] Healing Zone", Gdiplus::Color::White);
}
示例8: GdiplusGfx
GdiplusGfx(HDC dc) {
g = Gdiplus::Graphics::FromHDC(dc);
InitGraphicsMode(g);
PixelOffsetMode pm = g->GetPixelOffsetMode();
plogf("pm = %d", (int)pm);
}
示例9: OnDrawTop
void CSkyODL::OnDrawTop(Gdiplus::Graphics& gcDrawer, float fScale)
{
CBaseODL::OnDrawTop(gcDrawer, fScale);
Gdiplus::Pen Dot( m_clDotColor, static_cast<Gdiplus::REAL>(1.0 / fScale));
CArray<Gdiplus::Point> st;
CArray<Gdiplus::Point> stMoving;
CArray<BYTE> stBytes;
for (auto& curItem : m_arrTopPoint)
{
Gdiplus::Point pt;
pt.X = static_cast<INT>(curItem.X());
pt.Y = static_cast<INT>(curItem.Z());
st.Add(pt);
}
if (IsTopMoving())
{
for ( auto& curMoving : m_arrMovingTopPoint )
{
Gdiplus::Point pt;
pt.X = static_cast<INT>(curMoving.X());
pt.Y = static_cast<INT>(curMoving.Z());
stMoving.Add(pt);
}
}
if(st.GetSize()<=0)
{
return;
}
for (int i=0; i<st.GetSize(); ++i)
{
st[i].X = static_cast<INT>(st[i].X);
st[i].Y = static_cast<INT>(st[i].Y);
}
for (int i=0; i<stMoving.GetSize(); ++i)
{
stMoving[i].X = static_cast<INT>(stMoving[i].X);
stMoving[i].Y = static_cast<INT>(stMoving[i].Y);
}
Gdiplus::Pen pen( m_clPenColor, static_cast<Gdiplus::REAL>(1.0 / fScale));
pen.SetDashStyle(Gdiplus::DashStyleSolid);
if (!IsTopCreating())
{
Gdiplus::HatchBrush brush( Gdiplus::HatchStyle(Gdiplus::HatchStyle::HatchStyleCross ), m_clPenColor, Gdiplus::Color(0,255,255,255) );
//画皮肤
gcDrawer.FillPolygon(&brush, st.GetData(), st.GetSize(), Gdiplus::FillMode::FillModeAlternate);
}
gcDrawer.DrawLines(&pen, st.GetData(), st.GetSize());
if (IsTopMoving())
{
Gdiplus::Pen penMoving( m_clDotColor, static_cast<Gdiplus::REAL>(1.0 / fScale));
penMoving.SetDashStyle( Gdiplus::DashStyleSolid);
gcDrawer.DrawLines(&penMoving, stMoving.GetData(), stMoving.GetSize());
}
if (IsTopSelected())
{
//每个转角画一个点
for (int x=0; x<st.GetSize(); x++)
{
gcDrawer.DrawRectangle(&Dot, (st[x].X) - 3.0f/fScale, (st[x].Y ) - 3.0f/fScale, 6.0f/fScale, 6.0f/fScale);
}
}
}
示例10: DrawBackground
void CStartupView::DrawBackground(Gdiplus::Graphics &graphics)
{
CSize siTotal = GetTotalSize();
CRect rcClient(0, 0, siTotal.cx, siTotal.cy);
CRect rc;
GetClientRect(&rc);
/* int iLeft = 6;
int iRight = 13;
int iMiddle = rcClient.Width() - iLeft - iRight;*/
Gdiplus::Rect gdipRcClient(rcClient.left, rcClient.top, rcClient.Width(), rcClient.Height());
Gdiplus::SolidBrush bgBrush(Gdiplus::Color(255, 238, 238, 238));
graphics.FillRectangle(&bgBrush, gdipRcClient);
Gdiplus::REAL offsetY = (Gdiplus::REAL)OFFSET_Y;
Gdiplus::REAL y = offsetY;
float fHeight = (Gdiplus::REAL)TOP_HEIGHT;
Gdiplus::RectF gdipRcLeft;
Gdiplus::RectF gdipRcMiddle;
Gdiplus::RectF gdipRcRight;
CalculateBkgRects(gdipRcLeft, gdipRcMiddle, gdipRcRight, y, fHeight);
graphics.DrawImage(m_pBmpTopLeft, gdipRcLeft);
graphics.DrawImage(m_pBmpTopMiddle, gdipRcMiddle, 0.0, 0.0, 1.0, (Gdiplus::REAL)fHeight, Gdiplus::UnitPixel);
graphics.DrawImage(m_pBmpTopRight, gdipRcRight);
fHeight = (Gdiplus::REAL)BLUE_HEIGHT;
CalculateBkgRects(gdipRcLeft, gdipRcMiddle, gdipRcRight, y, fHeight);
graphics.DrawImage(m_pBmpBlueLeft, gdipRcLeft);
graphics.DrawImage(m_pBmpBlueMiddle, gdipRcMiddle, 0.0, 0.0, 1.0, (Gdiplus::REAL)fHeight, Gdiplus::UnitPixel);
graphics.DrawImage(m_pBmpBlueRight, gdipRcRight);
fHeight =(Gdiplus::REAL)( rcClient.Height() - OFFSET_Y - TOP_HEIGHT - BLUE_HEIGHT - LIGHT_BLUE_HEIGHT - FOOT_HEIGHT);
CalculateBkgRects(gdipRcLeft, gdipRcMiddle, gdipRcRight, y, fHeight);
graphics.DrawImage(m_pBmpWhiteLeft, gdipRcLeft/*, 0.0, 0.0, 1.0, (Gdiplus::REAL)296, Gdiplus::UnitPixel*/);
graphics.DrawImage(m_pBmpWhiteMiddle, gdipRcMiddle, 0.0, 0.0, 1.0, (Gdiplus::REAL)296, Gdiplus::UnitPixel);
graphics.DrawImage(m_pBmpWhiteRight, gdipRcRight/*, 0.0, 0.0, 1.0, (Gdiplus::REAL)296, Gdiplus::UnitPixel*/);
fHeight = (Gdiplus::REAL)LIGHT_BLUE_HEIGHT;
y--;
CalculateBkgRects(gdipRcLeft, gdipRcMiddle, gdipRcRight, y , fHeight);
graphics.DrawImage(m_pBmpLightBlueLeft, gdipRcLeft);
graphics.DrawImage(m_pBmpLightBlueMiddle, gdipRcMiddle, 0.0, 0.0, 1.0, (Gdiplus::REAL)fHeight, Gdiplus::UnitPixel);
graphics.DrawImage(m_pBmpLightBlueRight, gdipRcRight);
fHeight = (Gdiplus::REAL)FOOT_HEIGHT;
CalculateBkgRects(gdipRcLeft, gdipRcMiddle, gdipRcRight, y, fHeight);
graphics.DrawImage(m_pBmpFootLeft, gdipRcLeft);
graphics.DrawImage(m_pBmpFootMiddle, gdipRcMiddle, 0.0, 0.0, 1.0, (Gdiplus::REAL)fHeight, Gdiplus::UnitPixel);
graphics.DrawImage(m_pBmpFootRight, gdipRcRight);
Gdiplus::Color colorFrom[] = {Gdiplus::Color(255, 220, 223, 224),
Gdiplus::Color(255, 215, 215, 215),
Gdiplus::Color(255, 216, 216, 216),
Gdiplus::Color(255, 219, 219, 219),
Gdiplus::Color(255, 223, 223, 223),
Gdiplus::Color(255, 226, 226, 226),
Gdiplus::Color(255, 229, 229, 229),
Gdiplus::Color(255, 231, 231, 231),
};
Gdiplus::Color colorTo[] = {Gdiplus::Color(255, 198, 199, 201),
Gdiplus::Color(255, 185, 185, 185),
Gdiplus::Color(255, 190, 190, 190),
Gdiplus::Color(255, 197, 197, 197),
Gdiplus::Color(255, 203, 203, 203),
Gdiplus::Color(255, 213, 213, 213),
Gdiplus::Color(255, 218, 218, 218),
Gdiplus::Color(255, 226, 226, 226),
};
Gdiplus::RectF gdipRcM2;
for(int i = 0; i < 8; i++)
{
gdipRcM2.X = gdipRcMiddle.X + gdipRcMiddle.Width - 30.0;
gdipRcM2.Y = gdipRcMiddle.Y + gdipRcMiddle.Height - 8 + i;
gdipRcM2.Width = 30.0;
gdipRcM2.Height = 1.0;
Gdiplus::LinearGradientBrush gradientBrush(gdipRcM2,
colorFrom[i],
colorTo[i],
Gdiplus::LinearGradientModeHorizontal);
graphics.FillRectangle(&gradientBrush, gdipRcM2);
}
}
示例11: DrawItem
void TrackListCtrl::DrawItem(Gdiplus::Graphics& g, INT nItem, Gdiplus::Rect& itemRC)
{
HDC hdc = g.GetHDC();
if (hdc == 0)
{
TRACE(_T("@1 TrackListCtrl::DrawItem. Cant get HDC\r\n"));
return;
}
CDC* pDC = CDC::FromHandle(hdc);
PrgAPI* pAPI = PRGAPI();
//Calculate Colors
BOOL bSelected = IsItemSelected(nItem);
COLORREF clrText = m_colors[COL_Text];
COLORREF clrBk = m_colors[COL_Bk];
if (bSelected)
{
clrText = m_colors[COL_TextSel];
clrBk = m_colors[COL_TextSelBk];
}
CRect rcSubItem(itemRC.X, itemRC.Y, itemRC.GetRight(), itemRC.GetBottom());
pDC->SetTextColor(clrText);
pDC->FillSolidRect(rcSubItem, clrBk);
const INT cMargin = 2;
FullTrackRecordSP& rec = (*m_pCollection)[nItem];
pDC->SetBkMode(TRANSPARENT);
INT curx = cMargin;
CRect rcFirstLine(rcSubItem);
rcFirstLine.bottom = rcFirstLine.top + 20;
rcFirstLine.left = cMargin;
rcFirstLine.right -= cMargin;
CRect rcSecondLine(rcSubItem);
rcSecondLine.top = rcFirstLine.bottom;
rcSecondLine.left = cMargin;
rcSecondLine.right -= cMargin;
if (m_bDrawPictures)
{
INT imgHeight = 32;//rcSubItem.Height() - 2 * cMargin;
INT cury = rcSubItem.top + cMargin;
LocalPictureManager* pLM = PRGAPI()->GetLocalPictureManager();
Gdiplus::Rect rcImage(curx, cury, imgHeight, imgHeight);
Graphics g2(hdc);
BOOL bRet = pLM->DrawAlbumThumbnail(rec->artist.name.c_str(), rec->album.name.c_str(), g2, rcImage);
if (!bRet)
bRet = pLM->DrawArtistThumbnail(rec->artist.name.c_str(), g2, rcImage);
if (!bRet)
bRet = pLM->DrawDefaultThumbnail(IIT_AlbumPicture, g2, rcImage);
curx += 32 + cMargin ;
}
rcSecondLine.left = curx;
//=== Draw the icon
INT cury = rcFirstLine.top + (rcFirstLine.Height() - 16) / 2;
pDC->SetTextColor(clrText);
DrawIconEx(pDC->m_hDC, curx, cury, pAPI->GetIconForTrackType(rec->track.trackType), 16, 16, 0, 0, DI_NORMAL);
curx += 16 + cMargin;
//=== Draw the title
CRect rcTitle(rcFirstLine);
rcTitle.left = curx;
CFont* pOldFont = pDC->SelectObject(m_pBoldFont);
pDC->DrawText(rec->track.name.c_str(), rec->track.name.size(), &rcTitle, DT_END_ELLIPSIS | DT_LEFT | DT_VCENTER | DT_SINGLELINE | DT_NOPREFIX);
pDC->DrawText(rec->track.name.c_str(), rec->track.name.size(), &rcTitle, DT_END_ELLIPSIS | DT_LEFT | DT_VCENTER | DT_SINGLELINE | DT_NOPREFIX | DT_CALCRECT);
//=== Draw the artist
CRect rcArtist(rcFirstLine);
rcArtist.left = rcTitle.right + cMargin;
pDC->DrawText(rec->artist.name.c_str(), rec->artist.name.size(), &rcArtist, DT_END_ELLIPSIS | DT_RIGHT | DT_VCENTER | DT_SINGLELINE | DT_NOPREFIX);
pDC->SelectObject(m_pNormalFont);
//=== Next line
//=== Draw the rating (if exists)
if (rec->track.rating > 0 && rec->track.rating < 256)
{
FLOAT fStars = Rating2Stars(rec->track.rating);
if (fStars > 0.0f && fStars <=1.0f)
{
DrawIconEx(hdc, rcSecondLine.left, rcSecondLine.top, pAPI->GetIcon(ICO_StarBad16), 16, 16, 0, 0, DI_NORMAL);
rcSecondLine.left += 17;
}
while (fStars > 1.0f)
{
DrawIconEx(hdc, rcSecondLine.left, rcSecondLine.top, pAPI->GetIcon(ICO_StarGold16), 16, 16, 0, 0, DI_NORMAL);
fStars -= 1.0f;
rcSecondLine.left += 17;
}
}
//.........这里部分代码省略.........
示例12: Surface
Surface TextLayout::render( bool useAlpha, bool premultiplied )
{
Surface result;
// determine the extents for all the lines and the result surface
float totalHeight = 0, maxWidth = 0;
for( deque<shared_ptr<Line> >::iterator lineIt = mLines.begin(); lineIt != mLines.end(); ++lineIt ) {
(*lineIt)->calcExtents();
totalHeight = std::max( totalHeight, totalHeight + (*lineIt)->mHeight + (*lineIt)->mLeadingOffset );
if( (*lineIt)->mWidth > maxWidth )
maxWidth = (*lineIt)->mWidth;
}
// for the last line, instead of using the font info, we'll use the true height
/* if( ! mLines.empty() ) {
totalHeight = currentY - (mLines.back()->mAscent - mLines.back()->mDescent - mLines.back()->mLeadingOffset - mLines.back()->mLeading );
totalHeight += mLines.back()->mHeight;
}*/
// round up from the floating point sizes to get the number of pixels we'll need
int pixelWidth = (int)math<float>::ceil( maxWidth ) + mHorizontalBorder * 2;
int pixelHeight = (int)math<float>::ceil( totalHeight ) + mVerticalBorder * 2;
// Odd failure - return a NULL Surface
if( ( pixelWidth < 0 ) || ( pixelHeight < 0 ) )
return Surface();
// allocate the surface based on our collective extents
#if defined( CINDER_MAC )
result = Surface( pixelWidth, pixelHeight, useAlpha, (useAlpha)?SurfaceChannelOrder::RGBA:SurfaceChannelOrder::RGBX );
CGContextRef cgContext = cocoa::createCgBitmapContext( result );
ip::fill( &result, mBackgroundColor.premultiplied() );
float currentY = totalHeight + 1.0f + mVerticalBorder;
for( deque<shared_ptr<Line> >::iterator lineIt = mLines.begin(); lineIt != mLines.end(); ++lineIt ) {
// these are negated from Cinder's normal pixel coordinate system
currentY -= (*lineIt)->mAscent + (*lineIt)->mLeadingOffset;
(*lineIt)->render( cgContext, currentY, (float)mHorizontalBorder, pixelWidth );
currentY -= (*lineIt)->mDescent + (*lineIt)->mLeading;
}
// force all the rendering to finish and release the context
CGContextFlush( cgContext );
CGContextRelease( cgContext );
// since CGContextBitmaps are always premultiplied, if the caller didn't want that we'll have to undo it
if( ! premultiplied )
ip::unpremultiply( &result );
#elif defined( CINDER_MSW )
// I don't have a great explanation for this other than it seems to be necessary
pixelHeight += 1;
// prep our GDI and GDI+ resources
HDC dc = TextManager::instance()->getDc();
result = Surface8u( pixelWidth, pixelHeight, useAlpha, SurfaceConstraintsGdiPlus() );
Gdiplus::Bitmap *offscreenBitmap = msw::createGdiplusBitmap( result, premultiplied );
//Gdiplus::Bitmap *offscreenBitmap = new Gdiplus::Bitmap( pixelWidth, pixelHeight, (premultiplied) ? PixelFormat32bppPARGB : PixelFormat32bppARGB );
Gdiplus::Graphics *offscreenGraphics = Gdiplus::Graphics::FromImage( offscreenBitmap );
// high quality text rendering
offscreenGraphics->SetTextRenderingHint( Gdiplus::TextRenderingHintAntiAlias );
// fill the surface with the background color
offscreenGraphics->Clear( Gdiplus::Color( (BYTE)(mBackgroundColor.a * 255), (BYTE)(mBackgroundColor.r * 255),
(BYTE)(mBackgroundColor.g * 255), (BYTE)(mBackgroundColor.b * 255) ) );
// walk the lines and render them, advancing our Y offset along the way
float currentY = (float)mVerticalBorder;
for( deque<shared_ptr<Line> >::iterator lineIt = mLines.begin(); lineIt != mLines.end(); ++lineIt ) {
//currentY += (*lineIt)->mLeadingOffset + (*lineIt)->mAscent;
currentY += (*lineIt)->mLeadingOffset + (*lineIt)->mLeading;
(*lineIt)->render( offscreenGraphics, currentY, (float)mHorizontalBorder, (float)pixelWidth );
//currentY += (*lineIt)->mDescent + (*lineIt)->mLeading;
currentY += (*lineIt)->mAscent + (*lineIt)->mDescent;
}
GdiFlush();
delete offscreenBitmap;
delete offscreenGraphics;
#endif
return result;
}
示例13: DrawItem
void CTabsControl::DrawItem(CTabControl *item, Gdiplus::Graphics &g)
{
CRect rect = ItemRect(item);
g.ResetTransform();
g.TranslateTransform((REAL)rect.left, (REAL)rect.top);
RectF rf(0.0f, 0.0f, (REAL)rect.Width(), (REAL)rect.Height());
RectF rx;
if(item->selected)
{
#define shadowb 10
CDIB tmp;
tmp.Resize(rect.Width() + shadowb * 2, rect.Height() + shadowb * 2);
if(tmp.Ready())
{
Graphics gt(tmp.bmp);
RectF rx(0, 0, (REAL)tmp.Width(), (REAL)tmp.Height());
GraphicsPath *path = new GraphicsPath();
path->AddLine(rx.X + shadowb, rx.Y + rx.Height - shadowb, rx.X + rx.Width - 2 - shadowb, rx.Y + rx.Height - shadowb);
path->AddLine(rx.X + rx.Width - 2 - shadowb, rx.Y + rx.Height - shadowb, rx.X + rx.Width - 2, rx.Y);
path->AddLine(rx.X + rx.Width - 2, rx.Y, rx.X + rx.Width, rx.Y + rx.Height);
path->AddLine(rx.X + rx.Width, rx.Y + rx.Height, rx.X, rx.Y + rx.Height);
path->AddLine(rx.X, rx.Y, rx.X + shadowb, rx.Y + rx.Height - shadowb);
path->CloseFigure();
SolidBrush brush(0xff000000);
gt.FillPath(&brush, path);
tmp.Blur(tmp.Rect(), CRect(0, 0, 0, 0), shadowb);
g.DrawImage(tmp.bmp, rf, shadowb, shadowb, rf.Width, rf.Height, UnitPixel);
delete path;
}
}
Font font(L"Arial", item->selected ? 8.0f : 8.0f);
StringFormat *stringFormat = new StringFormat();
stringFormat->SetAlignment(StringAlignmentCenter);
stringFormat->SetLineAlignment(StringAlignmentCenter);
stringFormat->SetTrimming(StringTrimmingEllipsisCharacter);
stringFormat->SetFormatFlags(StringFormatFlagsLineLimit);
if(item->icon->Ready())
{
g.SetInterpolationMode(InterpolationModeBicubic);
rx = rf;
rx.Y += 6;
rx.Height -= (20 + rx.Y);
rx.Width = rx.Height;
rx.X += (rf.Width - rx.Width) / 2;
if(item->selected)
{
rx.Y++;
#define shadow 5
CDIB tmp;
tmp.Resize(item->icon->Width(), item->icon->Height());
if(tmp.Ready())
{
tmp.Draw(CRect(shadow, shadow,
item->icon->Width() - shadow,
item->icon->Height() - shadow),
item->icon->Rect(), item->icon);
DIB_ARGB *p = tmp.scan0;
int size = tmp.Width() * tmp.Height();
for(int i = 0; i < size; i++, p++)
{
p->r = 0;
p->g = 0;
p->b = 0;
}
tmp.Blur(tmp.Rect(), CRect(0, 0, 0, 0), shadow);
g.DrawImage(tmp.bmp, RectF(rx.X, rx.Y + shadow, rx.Width, rx.Height));
}
tmp.Assign(item->icon);
/*if(tmp.Ready())
{
DIB_ARGB *p = tmp.scan0;
int size = tmp.Width() * tmp.Height();
for(int i = 0; i < size; i++, p++)
{
p->r = 0x6f;
p->g = 0xa6;
p->b = 0xde;
}
}*/
g.DrawImage(tmp.bmp, rx);
}
else
{
g.DrawImage(item->icon->bmp, rx);
}
}
//.........这里部分代码省略.........
示例14: renderString
Surface renderString( const std::string &str, const Font &font, const ColorA &color, float *baselineOffset )
{
Line line;
line.addRun( Run( str, font, color ) );
line.mJustification = Line::LEFT;
line.mLeadingOffset = 0;
line.calcExtents();
float totalWidth = line.mWidth;
float totalHeight = line.mHeight;
int pixelWidth = (int)math<float>::ceil( totalWidth );
int pixelHeight = (int)math<float>::ceil( totalHeight );
// Odd failure - return a NULL Surface
if( ( pixelWidth < 0 ) || ( pixelHeight < 0 ) )
return Surface();
#if defined( CINDER_MAC )
Surface result( pixelWidth, pixelHeight, true, SurfaceChannelOrder::RGBA );
CGContextRef cgContext = cocoa::createCgBitmapContext( result );
ip::fill( &result, ColorA( 0, 0, 0, 0 ) );
float currentY = totalHeight + 1.0f;
currentY -= line.mAscent + line.mLeadingOffset;
line.render( cgContext, currentY, (float)0, pixelWidth );
// force all the rendering to finish and release the context
::CGContextFlush( cgContext );
::CGContextRelease( cgContext );
ip::unpremultiply( &result );
#elif defined( CINDER_MSW )
// I don't have a great explanation for this other than it seems to be necessary
pixelHeight += 1;
// prep our GDI and GDI+ resources
::HDC dc = TextManager::instance()->getDc();
Surface result( pixelWidth, pixelHeight, true, SurfaceConstraintsGdiPlus() );
Gdiplus::Bitmap *offscreenBitmap = msw::createGdiplusBitmap( result, false );
//Gdiplus::Bitmap *offscreenBitmap = new Gdiplus::Bitmap( pixelWidth, pixelHeight, (premultiplied) ? PixelFormat32bppPARGB : PixelFormat32bppARGB );
Gdiplus::Graphics *offscreenGraphics = Gdiplus::Graphics::FromImage( offscreenBitmap );
// high quality text rendering
offscreenGraphics->SetTextRenderingHint( Gdiplus::TextRenderingHintAntiAlias );
// fill the surface with the background color
offscreenGraphics->Clear( Gdiplus::Color( (BYTE)(0), (BYTE)(0),
(BYTE)(0), (BYTE)(0) ) );
// walk the lines and render them, advancing our Y offset along the way
float currentY = 0;
currentY += line.mLeadingOffset + line.mLeading;
line.render( offscreenGraphics, currentY, (float)0, (float)pixelWidth );
::GdiFlush();
delete offscreenBitmap;
delete offscreenGraphics;
#elif defined( CINDER_LINUX )
Surface result( pixelWidth, pixelHeight, true, SurfaceChannelOrder::RGBA );
#endif
if( baselineOffset )
*baselineOffset = line.mDescent;
return result;
}
示例15: draw_image
void draw_image(ImageData* img, const Rect* r)
{
if(img->get_image() == NULL) return;
graphics->DrawImage((Gdiplus::Image*)img->get_image(), TO_RECT(r));
}