Esempio n. 1
1
void TVizMapContext::Export(const TStr& FNm, const TStr& EncoderType, const int& Width, 
        const int& Height, const bool& ShowPointNmP, const int& PointFontSize, 
        const int& PointNmFontScale, const double& PointWgtThreshold, const bool& ShowCatNmP,
        const bool& ShowKeyWdP, const int& KeyWdFontSize, const bool& ShowMgGlassP, 
        const int& LegendGridWidth, const int& LegendGridHeight) {

    // create graphics
    Gdiplus::Bitmap* Bmp = new Gdiplus::Bitmap(Width, Height);
    Gdiplus::Graphics* g = Gdiplus::Graphics::FromImage(Bmp);
    PGks BmpGks = TWfGks::New();
    // paint graphics
    HDC HdcHandle = g->GetHDC(); BmpGks->BeginPaint(HdcHandle);
    Paint(BmpGks, ShowPointNmP, PointFontSize, PointNmFontScale,
        PointWgtThreshold, -1, ShowCatNmP, ShowKeyWdP, KeyWdFontSize, ShowMgGlassP, 
        LegendGridWidth, LegendGridHeight);
    BmpGks->EndPaint(); g->ReleaseHDC(HdcHandle);
    // save to disk
    WCHAR* FNmWChar = new WCHAR[FNm.Len() + 1];
    const int Res = MultiByteToWideChar(CP_ACP, 0, 
        FNm.CStr(), FNm.Len() + 1, FNmWChar, FNm.Len() + 1);
    CLSID pngClsid; GetEncoderClsid(EncoderType, &pngClsid);
    Bmp->Save(FNmWChar, &pngClsid, NULL);
    // clean after
    delete FNmWChar; delete Bmp; delete g;
}
Esempio n. 2
0
Gdiplus::RectF GdiplusUtilities::DrawTextMeasure(Gdiplus::Graphics& graphics, LPCTSTR lpchText, int cchText, const LOGFONT& lf)
{
	HDC hdc = graphics.GetHDC();
	Gdiplus::Font font(hdc, &lf);
	graphics.ReleaseHDC(hdc);
	return DrawTextMeasure(graphics, lpchText, cchText, font);
}
Esempio n. 3
0
void TrackListCtrl::DrawBackground(Gdiplus::Graphics& g, const Gdiplus::Rect& r)
{
	CRect rc;
	HDC hdc = g.GetHDC();
	if (hdc == NULL)
	{
		TRACE(_T("@1 TrackListCtrl::DrawBackground. Cant get HDC\r\n"));
		return;
	}
	CDC* pDC = CDC::FromHandle(hdc);
	rc.SetRect(r.X, r.Y, r.GetRight(), r.GetBottom());
	pDC->FillSolidRect(&rc, m_colors[COL_Bk]);//RGB(0,0,0));
	//if (GetItemCount() == 0)
	//{
	//	rc.top += 10;
	//	pDC->SetTextColor(m_colors[COL_Text]);
	//	pDC->SetBkMode(TRANSPARENT);
	//	CFont* oldFont = pDC->SelectObject(m_pBoldFont);
	//	pDC->DrawText(PRGAPI()->GetString(IDS_EMPTY), -1, rc, 
	//		DT_CENTER | DT_WORDBREAK | DT_NOPREFIX | DT_NOCLIP);
	//	pDC->SelectObject(oldFont);
	//}
	g.ReleaseHDC(pDC->m_hDC);

}
void drawTextWithSpacing(GraphicsContext* graphicsContext, const SimpleFontData* font, const wxColour& color, const GlyphBuffer& glyphBuffer, int from, int numGlyphs, const FloatPoint& point)
{
#if USE(WXGC)
    wxGCDC* dc = static_cast<wxGCDC*>(graphicsContext->platformContext());
#else
    wxDC* dc = graphicsContext->platformContext();
#endif

    // get the native HDC handle to draw using native APIs
    HDC hdc = 0;
#if USE(WXGC)
    wxGraphicsContext* gc = dc->GetGraphicsContext();
    Gdiplus::Graphics* g;
    if (gc) {
        g = (Gdiplus::Graphics*)gc->GetNativeContext();
        hdc = g->GetHDC();
    }
#else
    hdc = static_cast<HDC>(dc->GetHDC());
#endif

    // ExtTextOut wants the offsets as an array of ints, so extract them
    // from the glyph buffer
    const GlyphBufferGlyph*   glyphs   = glyphBuffer.glyphs(from);
    const GlyphBufferAdvance* advances = glyphBuffer.advances(from);

    float y = point.y() - font->ascent();
    float x = point.x();

    int* spacing = new int[numGlyphs - from];
    for (unsigned i = 0; i < numGlyphs; ++i)
        spacing[i] = advances[i].width();

    wxFont* wxfont = font->getWxFont();
    if (wxfont && wxfont->IsOk())
        ::SelectObject(hdc, GetHfontOf(*wxfont));

    if (color.Ok())
        ::SetTextColor(hdc, color.GetPixel());

    // do not draw background behind characters
    ::SetBkMode(hdc, TRANSPARENT);

    // draw text with optional character widths array
    wxString string = wxString((wxChar*)(&glyphs[from]), numGlyphs);
    ::ExtTextOut(hdc, x, y, 0, NULL, string.c_str(), string.length(), spacing);

    ::SetBkMode(hdc, TRANSPARENT);

    #if USE(WXGC)
        g->ReleaseHDC(hdc);
    #endif

    delete [] spacing;
}
Esempio n. 5
0
void GuiEngine::SetResolution(Vec2u& size)
{
	DeleteObject(memBitmap);
	DeleteDC(hdc);
	DeleteDC(memHDC);

	Gdiplus::Graphics* graphics = Gdiplus::Graphics::FromHWND((HWND)targetWindow->GetNativeHandle());
	graphics->SetSmoothingMode(Gdiplus::SmoothingModeDefault);

	hdc = graphics->GetHDC();

	memHDC = CreateCompatibleDC(hdc);
	memBitmap = CreateCompatibleBitmap(hdc, size.x, size.y);

	SelectObject(memHDC, memBitmap);

	gdiGraphics = Gdiplus::Graphics::FromHDC(memHDC);
}
Esempio n. 6
0
BOOL GdiplusUtilities::DrawTextOutline(Gdiplus::Graphics& graphics, 
									   LPCTSTR lpchText, int cchText, const RECT* lprc, UINT format, 
									   const LOGFONT& lf, COLORREF fill, COLORREF outline, INT outlineWidth,
									   BOOL bCalcOnly /*= FALSE*/, RECT* rcCalc/* = NULL*/)
{
	HDC hdc = graphics.GetHDC();
	Gdiplus::Font font(hdc, &lf);
	graphics.ReleaseHDC(hdc);
	Gdiplus::StringFormat sFormat;
	if (format & DT_VCENTER)
		sFormat.SetLineAlignment(Gdiplus::StringAlignmentCenter);
	else if (format & DT_BOTTOM)
		sFormat.SetLineAlignment(Gdiplus::StringAlignmentFar);
	else
		sFormat.SetLineAlignment(Gdiplus::StringAlignmentNear);

	if (format & DT_CENTER)
		sFormat.SetAlignment(Gdiplus::StringAlignmentCenter);
	else if (format & DT_RIGHT)
		sFormat.SetAlignment(Gdiplus::StringAlignmentFar);
	else
		sFormat.SetAlignment(Gdiplus::StringAlignmentNear);

	Gdiplus::Rect rcForCalc;
	Gdiplus::Rect* pRCForCalc = &rcForCalc;
	if (rcCalc == NULL)
		pRCForCalc = NULL;
	if (DrawTextOutline(graphics, lpchText, cchText, RECT2GdiplusRect(*lprc), sFormat, font, 
		COLORREF2Color(fill), COLORREF2Color(outline), outlineWidth, bCalcOnly, pRCForCalc))
	{
		if (pRCForCalc != NULL)
			*rcCalc = GdiplusRect2RECT(*pRCForCalc);
		return TRUE;
	}
	return FALSE;

}
Esempio n. 7
0
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;
		}
	}

	TCHAR time[500];
	UINT len = _sntprintf(time, 500, _T("%d:%02d | %s: %s | %s: %s"), 
		INT (rec->track.duration / 60), INT(rec->track.duration) % 60,
		pAPI->GetString(IDS_ALBUM), rec->album.name.c_str(),
		pAPI->GetString(IDS_LOCATION), rec->track.location.c_str()
		);
	pDC->DrawText(time, len, &rcSecondLine, DT_END_ELLIPSIS | DT_LEFT | DT_VCENTER | DT_SINGLELINE | DT_NOPREFIX);

	pDC->SelectObject(pOldFont);

	g.ReleaseHDC(pDC->m_hDC);
}