예제 #1
0
// 绘制按钮
void CDUIButton::DrawButton( Gdiplus::Graphics&  graphics)
{
	// 获取按钮图片信息
	UINT iCount = m_nImageCount;
	int	iButtonIndex = 0;
	if(m_bDisabled && iCount >= 4) iButtonIndex = 3;
	else if(m_bPressed && iCount >= 3)iButtonIndex = 2;
	else if(m_bHovering && iCount >= 2)iButtonIndex = 1;
	else iButtonIndex = 0;

	// 在指定位置绘制按钮
	int iWidth = m_pImage->GetWidth()/iCount;
	int iHeight = m_pImage->GetHeight();
	RectF grect;
	grect.X=(Gdiplus::REAL)m_rcRect.left;
	grect.Y=(Gdiplus::REAL)m_rcRect.top;
	grect.Width = (Gdiplus::REAL)m_rcRect.Width();
	grect.Height = (Gdiplus::REAL)m_rcRect.Height();

	graphics.DrawImage(m_pImage, grect, (Gdiplus::REAL)iWidth*iButtonIndex,0,(Gdiplus::REAL)iWidth,(Gdiplus::REAL)iHeight, UnitPixel);

	StringFormat stringFormat;

	if (m_pIcon)
	{
		PointF ptIcon(m_ptIcon.x,m_ptIcon.y);
		graphics.DrawImage(m_pIcon,ptIcon);

		grect.X=(Gdiplus::REAL)m_ptIcon.x + m_pIcon->GetWidth() + 2;
		grect.Width = (Gdiplus::REAL)m_rcRect.Width() - m_pIcon->GetWidth() - 2;

		stringFormat.SetFormatFlags( StringFormatFlagsDirectionVertical);
		stringFormat.SetAlignment(StringAlignmentCenter);
		stringFormat.SetLineAlignment(StringAlignmentNear);
	}
	else
	{
		//stringFormat.SetFormatFlags( StringFormatFlagsDirectionVertical);
		stringFormat.SetAlignment(StringAlignmentCenter);
		stringFormat.SetLineAlignment(StringAlignmentCenter);
	}

	if (!m_strCaption.IsEmpty())
	{
		//绘制文字
		FontFamily fontFamily(L"宋体");
		Gdiplus::Font font(&fontFamily, 10, FontStyleRegular, UnitPoint);


		CStringW strTitle(m_strCaption);
		SolidBrush brush((ARGB)Color::White);
		if (m_bDisabled)
		{
			brush.SetColor((ARGB)Color::Gray);
		}

		graphics.DrawString(strTitle, strTitle.GetLength(), &font,grect,&stringFormat, &brush);
	}

}
예제 #2
0
void CSkinButton2::DrawImage(Gdiplus::Graphics& gdi,BTN_DRAW_HUE hue)
{
	if(hue == DRAW_NORMAL)
	{
		if( m_pPngImage && m_pPngImage->m_pBitmap )
		{
			RectF grect; grect.X=0, grect.Y=0; grect.Width = m_pPngImage->m_pBitmap->GetWidth(); grect.Height = m_pPngImage->m_pBitmap->GetHeight();
			gdi.DrawImage(*m_pPngImage,grect );
		}
	}
	else if(hue == DRAW_LIGHT)
	{
		if( m_pPngImage && m_pPngImage->m_pBitmap )
		{
			ImageAttributes ia;
			ia.SetColorMatrix(&m_LightMat);
			RectF grect; grect.X=0, grect.Y=0; grect.Width = m_pPngImage->m_pBitmap->GetWidth(); grect.Height = m_pPngImage->m_pBitmap->GetHeight();
			gdi.DrawImage(*m_pPngImage, grect, 0, 0, grect.Width, grect.Height, UnitPixel, &ia);
		}
	}
	else if(hue == DRAW_GRAY )
	{
		if( m_pPngImage && m_pPngImage->m_pBitmap )
		{
			ImageAttributes ia;
			ia.SetColorMatrix(&m_GrayMat);
			RectF grect; grect.X=0, grect.Y=0; grect.Width = m_pPngImage->m_pBitmap->GetWidth(); grect.Height = m_pPngImage->m_pBitmap->GetHeight();
			gdi.DrawImage(*m_pPngImage, grect, 0, 0, grect.Width, grect.Height, UnitPixel, &ia);
		}
	}
}
예제 #3
0
void ProgressBar::onDraw(Gdiplus::Graphics& g, int x, int y)
{
	g.DrawImage(background_, x+x_, y+y_);

	int w = int(foreground_.width() * percent_);
	int h = foreground_.height();
	g.DrawImage(foreground_, x+x_, y+y_, 0, 0, w, h, Gdiplus::UnitPixel);
}
예제 #4
0
void Graphics::DrawImage(Image* image, const Rect& rc, const ImageAttributes* attr) {
    Gdiplus::Graphics* g = reinterpret_cast<Gdiplus::Graphics*>(_private);
    Gdiplus::Image* gdiImage = reinterpret_cast<Gdiplus::Image*>(image->_private);

    if(attr!=0) {
        Gdiplus::ImageAttributes* ia = reinterpret_cast<Gdiplus::ImageAttributes*>(attr->_private);
        g->DrawImage(gdiImage, Gdiplus::Rect(rc.GetLeft(), rc.GetTop(), rc.GetWidth(), rc.GetHeight()), 0, 0, gdiImage->GetWidth(), gdiImage->GetHeight(), Gdiplus::UnitPixel, ia);
    }
    else {
        g->DrawImage(gdiImage, ToGDIRect<Rect, Gdiplus::Rect>(rc));
    }
}
예제 #5
0
파일: XButton.cpp 프로젝트: ohosrry/wtldemo
// 绘制按钮
void CXButton::DrawButton( Gdiplus::Graphics&  graphics)
{
	// 获取按钮图片信息
	Image* pImage = CImageInfo::Instance()->ImageFromResource(m_nImageContorl);
	UINT iCount = m_nImageCount;
	if(m_bCheck && m_nAltImageContorl != 0)
	{
		pImage = CImageInfo::Instance()->ImageFromResource(m_nAltImageContorl);;
		iCount = m_nAltImageCount;
	}

	// 获取按钮状态信息
	int	iButtonIndex = 0;
	if(m_bDisabled && iCount >= 4) iButtonIndex = 3;
	else if(m_bPressed && iCount >= 3)iButtonIndex = 2;
	else if(m_bHovering && iCount >= 2)iButtonIndex = 1;
	else iButtonIndex = 0;

	// 在指定位置绘制按钮
	int iWidth = pImage->GetWidth()/iCount;
	int iHeight = pImage->GetHeight();
	RectF grect;
	grect.X=m_rcRect.left, grect.Y=m_rcRect.top; grect.Width = m_rcRect.Width(); grect.Height = m_rcRect.Height();
	graphics.DrawImage(pImage, grect, iWidth*iButtonIndex,0,iWidth,iHeight, UnitPixel);
}
예제 #6
0
    void CanvasGdiplus::RestoreLayer()
    {
        DCHECK(layers_.size());
        
        CanvasLayer* layer = layers_.top();
        layers_.pop();
        DCHECK(layer);

        Gdiplus::Graphics* current = GetCurrentGraphics();
        Gdiplus::Bitmap* native_bitmap =
            layer->mem_bitmap.GetNativeBitmap();
        Gdiplus::ImageAttributes ia;
        Gdiplus::ColorMatrix cm =
        {
            1.0, 0.0, 0.0, 0.0, 0.0,
            0.0, 1.0, 0.0, 0.0, 0.0,
            0.0, 0.0, 1.0, 0.0, 0.0,
            0.0, 0.0, 0.0, (static_cast<float>(layer->alpha))/255, 0.0,
            0.0, 0.0, 0.0, 0.0, 1.0
        };
        ia.SetColorMatrix(&cm);
        Gdiplus::Rect destRect(layer->bounds.x(), layer->bounds.y(),
            layer->bounds.width(), layer->bounds.height());
        current->DrawImage(native_bitmap, destRect,
            layer->bounds.x(), layer->bounds.y(),
            layer->bounds.width(), layer->bounds.height(),
            Gdiplus::UnitPixel, &ia);

        delete layer;
    }
예제 #7
0
void DxFont::BuildFontSheetBitmap(Gdiplus::Font & font, Gdiplus::Graphics & charGraphics, Gdiplus::Bitmap & charBitmap, Gdiplus::Graphics & fontSheetGraphics)
{
    WCHAR               charString[ 2 ] = { ' ', 0 };
    Gdiplus::SolidBrush whiteBrush( Gdiplus::Color( 255, 255, 255, 255 ) );
    UINT                fontSheetX = 0;
    UINT                fontSheetY = 0;

    for( UINT i = 0; i < NumChars; ++i )
    {
        charString[ 0 ] = static_cast<WCHAR>(StartChar + i);

        charGraphics.Clear(Gdiplus::Color(0, 0, 0, 0));
        charGraphics.DrawString(charString, 1, &font, Gdiplus::PointF(0.0f, 0.0f), &whiteBrush);

        int minX      = GetCharMinX(charBitmap);
        int maxX      = GetCharMaxX(charBitmap);
        int charWidth = maxX - minX + 1;

        if(fontSheetX + charWidth >= TexWidth)
        {
            fontSheetX = 0;
            fontSheetY += static_cast<int>(CharHeight) + 1;
        }

        CharRects[i] = CD3D11_RECT(fontSheetX, fontSheetY, fontSheetX + charWidth, fontSheetY + CharHeight);

        fontSheetGraphics.DrawImage(&charBitmap, fontSheetX, fontSheetY, minX, 0, charWidth, CharHeight, Gdiplus::UnitPixel);

        fontSheetX += charWidth + 1;
    }
}
예제 #8
0
 void CanvasGdiplus::DrawBitmapInt(const Bitmap& bitmap, int x, int y)
 {
     Gdiplus::Graphics* current = GetCurrentGraphics();
     if(!bitmap.IsNull())
     {
         current->DrawImage(bitmap.GetNativeBitmap(), x, y);
     }
 }
예제 #9
0
void CMonitorWidget::DrawAudioVideo(Gdiplus::Graphics & graphics)
{
   CRect rcVideo;
   pStaticVideo.GetWindowRect(rcVideo);
   ScreenToClient(rcVideo);

   if(m_lpBitsInfo && m_lpBits)
   {
      Gdiplus::Bitmap bitmapVideo(m_lpBitsInfo, m_lpBits);
      graphics.DrawImage(&bitmapVideo, rcVideo.left, rcVideo.top, rcVideo.Width(), rcVideo.Height());
   }
   else
   {
      Gdiplus::Bitmap bitmap(m_hBitmapVideo, NULL);
      graphics.DrawImage(&bitmap, rcVideo.left, rcVideo.top, rcVideo.Width(), rcVideo.Height());
   }

   CAudioWidget::DrawAudioVideo(graphics);
}
예제 #10
0
 void CanvasGdiplus::DrawBitmapInt(const Bitmap& bitmap,
     int src_x, int src_y, int src_w, int src_h,
     int dest_x, int dest_y, int dest_w, int dest_h)
 {
     Gdiplus::Graphics* current = GetCurrentGraphics();
     if(!bitmap.IsNull())
     {
         current->DrawImage(bitmap.GetNativeBitmap(),
             Gdiplus::Rect(dest_x, dest_y, dest_w, dest_h),
             src_x, src_y, src_w, src_h, Gdiplus::UnitPixel);
     }
 }
void CTranslucentProgressBar::Render(Gdiplus::Graphics& g)
{
    float ratio = (float)m_nPos / (m_nUpper - m_nLower);

    CRect rc;
    GetWindowRect(&rc);
    GetParent()->ScreenToClient(&rc);

    Gdiplus::RectF rect((float)rc.left, (float)rc.top, (float)rc.Width(), (float)rc.Height());
    if (m_imageList[0] != NULL)
        g.DrawImage(m_imageList[0], rect, static_cast<float>(0), static_cast<float>(0), rect.Width, rect.Height, Gdiplus::UnitPixel);

    if (m_imageList[1] != NULL)
    {
        float nWidth = rc.Width() * ratio;
        rect.Width = nWidth;
        (void)g.DrawImage(m_imageList[1], rect, static_cast<float>(0), static_cast<float>(0), nWidth, rect.Height, Gdiplus::UnitPixel);
        rect.Width = (float)rc.Width();
    }

    CString szText;
    GetWindowText(szText);
    if (szText.GetLength() > 0)
    {
        TCHAR wsFile[MAX_PATH] = {0};
        if(!CToolsHelp::Strncpy(wsFile,MAX_PATH,(LPCTSTR)szText,static_cast<IVS_UINT32>(szText.GetLength())))
        {
        	BP_RUN_LOG_ERR(IVS_ALLOC_MEMORY_ERROR,"IVS_OCX::","Failed");
            return;
        }
		WCHAR* wstr = CTranslucentUtility::ttowc(wsFile);

		if (NULL != wstr)
		{
			(void)g.DrawString(wstr, static_cast<int >(wcslen(wstr)), m_pFont, rect, &m_format, &m_brush);
			delete []wstr;
			wstr = NULL;
		}
    }
}
예제 #12
0
void CStartupView::DrawImcLogo(Gdiplus::Graphics &graphics)
{
   if (m_pImcLogo == NULL)
      return;

   Gdiplus::Rect gdipRcLogoRegion;
   Gdiplus::Rect gdipRcButtonRegion;
   Gdiplus::Rect gdipRcBottomRegion;
   CalculateRegions(gdipRcLogoRegion, gdipRcButtonRegion, gdipRcBottomRegion);

   // Calculate correct position
   Gdiplus::REAL dLogoX = (gdipRcBottomRegion.X + gdipRcBottomRegion.Width) - 
      (m_pImcLogo->GetWidth() + LOGO_RIGHT_SPACE);
   Gdiplus::REAL dLogoY = gdipRcBottomRegion.Y + 
      (int)((double)(gdipRcBottomRegion.Height - m_pImcLogo->GetHeight()) / 2.0);

   graphics.DrawImage(m_pImcLogo, dLogoX, dLogoY);
}
예제 #13
0
void FlexDblBuffer::Render(Gdiplus::Graphics& destination, INT X, INT Y)
{
	ASSERT(m_cx > 0 && m_cy > 0);
	ASSERT(m_pB != NULL);
	if (m_cx > 0 && m_cy > 0 && m_pB != NULL)
	{
		//=== DEBUG in order to find out why in VMWare it fails to destination.DrawImage 
		//			(without getting an error)
		//			FillRectangle in contrast always succeeds
		//destination.FillRectangle(&Gdiplus::SolidBrush(Gdiplus::Color::Red), X, Y, m_cx,m_cy);
		//m_pG->FillRectangle(&Gdiplus::SolidBrush(Gdiplus::Color::Blue), X, Y, m_cx,m_cy / 2);
		if (destination.DrawImage(m_pB, X, Y, 0, 0, m_cx, m_cy, Gdiplus::UnitPixel) != Gdiplus::Ok)
		{
			TRACE(_T("@1 FlexDblBuffer::Render x:%d y:%d (FAILED)\r\n"), X, Y);
			TRACE(_T("@1 \tcx:%d cy:%d (FAILED)\r\n"), m_cx, m_cy);
		}
	}
}
예제 #14
0
    void CanvasGdiplus::TileImageInt(const Bitmap& bitmap,
        int src_x, int src_y, int dest_x, int dest_y, int w, int h)
    {
        if(!IntersectsClipRectInt(dest_x, dest_y, w, h))
        {
            return;
        }

        Gdiplus::Graphics* current = GetCurrentGraphics();
        if(!bitmap.IsNull())
        {
            Gdiplus::Bitmap* native_bitmap = bitmap.GetNativeBitmap();
            Gdiplus::ImageAttributes ia;
            ia.SetWrapMode(Gdiplus::WrapModeTile);
            Gdiplus::Rect rc_dest(dest_x, dest_y, w, h);
            current->DrawImage(native_bitmap,
                rc_dest, src_x, src_y,
                native_bitmap->GetWidth()-src_x,
                native_bitmap->GetHeight()-src_y,
                Gdiplus::UnitPixel, &ia);
        }
    }
예제 #15
0
파일: Font.cpp 프로젝트: Anters/LevelEditor
//---------------------------------------------------------------------------
void CreateAndIndexAtlasBitmap(Gdiplus::Font& font, Gdiplus::Graphics& charGraphics, Gdiplus::Bitmap& charBitmap,
            Gdiplus::Graphics& fontSheetGraphics, FontAtlasSizeInfo* pSizeInfo,
            ScreenRect* pCharacterMap )
{
    using namespace Gdiplus;

	WCHAR charString[2] = {' ', 0};
	SolidBrush whiteBrush(Color(255, 255, 255, 255));
	UINT fontSheetX = 0;
	UINT fontSheetY = 0;
	for(UINT i = 0; i < s_NumChars; ++i)
	{
		charString[0] = static_cast<WCHAR>(s_StartChar + i);
		charGraphics.Clear(Color(0, 0, 0, 0));
		charGraphics.DrawString(charString, 1, &font, PointF(0.0f, 0.0f), &whiteBrush);

		// Compute tight char horizontal bounds (ignoring empty space).
		int minX = GetCharMinX(charBitmap);
		int maxX = GetCharMaxX(charBitmap);
		int charWidth = maxX - minX + 1;

		// Move to next row of the font sheet?
		if(fontSheetX + charWidth >= pSizeInfo->atlasTextureWidth)
		{
			fontSheetX = 0;
			fontSheetY += static_cast<int>(pSizeInfo->characterRowHeight) + 1;
		}

		// Save the rectangle of this character on the texture atlas.
		pCharacterMap[i] = ScreenRect(fontSheetX, fontSheetY, fontSheetX + charWidth, fontSheetY + pSizeInfo->characterRowHeight);

		// The rectangle subset of the source image to copy.
		fontSheetGraphics.DrawImage(&charBitmap, fontSheetX, fontSheetY, 
			minX, 0, charWidth, pSizeInfo->characterRowHeight, UnitPixel);

		// next char
		fontSheetX += charWidth + 1;
	}
}
예제 #16
0
bool UnitVideo::onRender(LPVOID world,FLOAT& x,FLOAT& y,FLOAT& z)
{
	if(isRenderFlag() && m_dataPtr && getStat() == MEDIA_PLAY)
	{
		m_critical.lock();
		if(m_initImage)
		{
			INT width = MediaSampler::getImageWidth();
			INT height = MediaSampler::getImageHeight();
			setSize(width,height);
			m_initImage = false;
		}

		INT width = MediaSampler::getImageWidth();
		INT height = MediaSampler::getImageHeight();
		INT pitch = (width * 24/8 + 3)/4*4;
		Gdiplus::Bitmap bitmap(width,height,pitch,PixelFormat24bppRGB,(LPBYTE)m_dataPtr);
		Gdiplus::Graphics* g = getGraphics();
	
		g->DrawImage(&bitmap,0,height-1,width,-height);
		m_critical.unlock();
	}
	return UnitGdip::onRender(world,x,y,z);
}
예제 #17
0
void Graphics::DrawImage(Image* image, int x, int y) {
    Gdiplus::Graphics* g = reinterpret_cast<Gdiplus::Graphics*>(_private);
    Gdiplus::Image* gdiImage = reinterpret_cast<Gdiplus::Image*>(image->_private);
    g->DrawImage(gdiImage, x, y);
}
예제 #18
0
int KWndFrameList::Draw(LPDRAWITEMSTRUCT lpDrawItem)
{
    RECT rc;
    RECT rcTga;
    HDC hDc = NULL;
    TCHAR szId[128] = "";
    szId[0] = _T('\0');
    TCHAR szUitex[128] = "";
    szUitex[0] = _T('\0');
    TCHAR szFrame[128] = "";
    szFrame[0] = _T('\0');
    TCHAR szName[128] = "";
    szName[0] = _T('\0');
    TCHAR szWeith[128] = "";
    szWeith[0] = _T('\0');
    TCHAR szHeight[128] = "";
    szHeight[0] = _T('\0');
    TCHAR szInfo[128] = "";
    szInfo[0] = _T('\0');

    RECT rcDrawWindow;
    Gdiplus::Graphics *pGraphics = NULL;
    Gdiplus::Bitmap *pBitmap = NULL;
    KTgaBlock *pBlock = NULL;
    LPCTSTR pcszFrameName = NULL;
    BITMAPINFO bmpInfo; 

    KG_PROCESS_ERROR(lpDrawItem);
    KG_PROCESS_ERROR(lpDrawItem->CtlType == ODT_LISTVIEW);
    KG_PROCESS_ERROR(lpDrawItem->hwndItem == m_hListWnd);
    hDc = lpDrawItem->hDC;

    ListView_GetItemText(m_hListWnd, lpDrawItem->itemID, 0, szId, sizeof(szId) / sizeof(szId[0]));
    ListView_GetItemText(m_hListWnd, lpDrawItem->itemID, 2, szUitex, sizeof(szUitex) / sizeof(szUitex[0]));
    ListView_GetItemText(m_hListWnd, lpDrawItem->itemID, 3, szFrame, sizeof(szFrame) / sizeof(szFrame[0]));
    ListView_GetItemText(m_hListWnd, lpDrawItem->itemID, 4, szName, sizeof(szName) / sizeof(szName[0]));
    ListView_GetItemText(m_hListWnd, lpDrawItem->itemID, 5, szWeith, sizeof(szWeith) / sizeof(szWeith[0]));
    ListView_GetItemText(m_hListWnd, lpDrawItem->itemID, 6, szHeight, sizeof(szHeight) / sizeof(szHeight[0]));
    ListView_GetItemText(m_hListWnd, lpDrawItem->itemID, 7, szInfo, sizeof(szInfo) / sizeof(szInfo[0]));

    ListView_GetSubItemRect(m_hListWnd, lpDrawItem->itemID, 0, LVIR_BOUNDS, &rc);
    rc.top += TGA_HEIGHT / 3 - 3;
    DrawText(hDc, szId, sizeof(szId) / sizeof(szId[0]) , &rc, NULL);
    ListView_GetSubItemRect(m_hListWnd, lpDrawItem->itemID, 1, LVIR_BOUNDS, &rcTga);
    ListView_GetSubItemRect(m_hListWnd, lpDrawItem->itemID, 2, LVIR_BOUNDS, &rc);
    rc.top += TGA_HEIGHT / 3 - 3;
    DrawText(hDc, szUitex, sizeof(szUitex) / sizeof(szUitex[0]), &rc, NULL);
    ListView_GetSubItemRect(m_hListWnd, lpDrawItem->itemID, 3, LVIR_BOUNDS, &rc);
    rc.top += TGA_HEIGHT / 3 - 3;
    DrawText(hDc, szFrame, sizeof(szFrame) / sizeof(szFrame[0]), &rc, NULL);
    ListView_GetSubItemRect(m_hListWnd, lpDrawItem->itemID, 4, LVIR_BOUNDS, &rc);
    rc.top += TGA_HEIGHT / 3 - 3;
    DrawText(hDc, szName, sizeof(szName) / sizeof(szName[0]), &rc, NULL);
    ListView_GetSubItemRect(m_hListWnd, lpDrawItem->itemID, 5, LVIR_BOUNDS, &rc);
    rc.top += TGA_HEIGHT / 3 - 3;
    DrawText(hDc, szWeith, sizeof(szWeith) / sizeof(szWeith[0]), &rc, NULL);
    ListView_GetSubItemRect(m_hListWnd, lpDrawItem->itemID, 6, LVIR_BOUNDS, &rc);
    rc.top += TGA_HEIGHT / 3 - 3;
    DrawText(hDc, szHeight, sizeof(szHeight) / sizeof(szHeight[0]), &rc, NULL);
    ListView_GetSubItemRect(m_hListWnd, lpDrawItem->itemID, 7, LVIR_BOUNDS, &rc);
    rc.top += TGA_HEIGHT / 3 - 3;
    DrawText(hDc, szInfo, sizeof(szInfo) / sizeof(szInfo[0]), &rc, NULL);

    pBlock = KIconManager::GetSelf().Get(lpDrawItem->itemID)->GetTgaBlock();
    bmpInfo.bmiHeader.biBitCount = 32;
    bmpInfo.bmiHeader.biClrImportant = 0;
    bmpInfo.bmiHeader.biClrUsed = 0;
    bmpInfo.bmiHeader.biCompression = 0;
    bmpInfo.bmiHeader.biHeight = 0 - pBlock->GetHeight();   
    bmpInfo.bmiHeader.biPlanes = 1;
    bmpInfo.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
    bmpInfo.bmiHeader.biSizeImage = pBlock->GetHeight() * pBlock->GetWidth()* sizeof(DWORD);
    bmpInfo.bmiHeader.biWidth = pBlock->GetWidth();
    bmpInfo.bmiHeader.biXPelsPerMeter = 2834;
    bmpInfo.bmiHeader.biYPelsPerMeter = 2834;
    bmpInfo.bmiColors[0].rgbBlue = 255;
    bmpInfo.bmiColors[0].rgbGreen = 255;
    bmpInfo.bmiColors[0].rgbRed = 255;
    bmpInfo.bmiColors[0].rgbReserved = 0;
    pBitmap = Gdiplus::Bitmap::FromBITMAPINFO(&bmpInfo, pBlock->GetBufferPtr());
    KG_PROCESS_ERROR(pBitmap);
    KG_PROCESS_ERROR(m_hListWnd);
    ::GetClientRect(m_hListWnd, &rcDrawWindow); 
    hDc = GetDC(m_hListWnd);
    KG_PROCESS_ERROR(hDc);
    ::ValidateRect(m_hListWnd, NULL);
    pGraphics = new Gdiplus::Graphics(hDc);
    KG_PROCESS_ERROR(pGraphics);
    pGraphics->DrawImage(pBitmap, rcTga.left, rcTga.top);

Exit0:
    KG_DELETE(pBitmap);
    KG_DELETE(pGraphics);
    return true;
}
예제 #19
0
void Graphics::DrawImage(Image* image, int x, int y, int srcX, int srcY, int srcWidth, int srcHeight) {
    Gdiplus::Graphics* g = reinterpret_cast<Gdiplus::Graphics*>(_private);
    Gdiplus::Image* gdiImage = reinterpret_cast<Gdiplus::Image*>(image->_private);
    g->DrawImage(gdiImage, x, y, srcX, srcY, srcWidth, srcHeight, Gdiplus::UnitPixel);
}
예제 #20
0
void Button::onDraw(Gdiplus::Graphics& g, int x, int y)
{
	g.DrawImage(bitmaps_[currState_], x+x_, y+y_);
}
예제 #21
0
		void draw_image(ImageData* img, const Rect* r)
		{
			if(img->get_image() == NULL) return;
			graphics->DrawImage((Gdiplus::Image*)img->get_image(), TO_RECT(r));
		}
예제 #22
0
//-----------------------------------------------------------------------------
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);
		}
	}
}
예제 #23
0
파일: emf.c 프로젝트: edalquist/ImageMagick
static Image *ReadEMFImage(const ImageInfo *image_info,
  ExceptionInfo *exception)
{
  Gdiplus::Bitmap
    *bitmap;

  Gdiplus::BitmapData
     bitmap_data;

  Gdiplus::GdiplusStartupInput
    startup_input;

  Gdiplus::Graphics
    *graphics;

  Gdiplus::Image
    *source;

  Gdiplus::Rect
    rect;

  GeometryInfo
    geometry_info;

  Image
    *image;

  MagickStatusType
    flags;

  register Quantum
    *q;

  register ssize_t
    x;

  ssize_t
    y;

  ULONG_PTR
    token;

  unsigned char
    *p;

  wchar_t
    fileName[MagickPathExtent];

  assert(image_info != (const ImageInfo *) NULL);
  assert(image_info->signature == MagickSignature);
  if (image_info->debug != MagickFalse)
    (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
      image_info->filename);
  assert(exception != (ExceptionInfo *) NULL);

  image=AcquireImage(image_info,exception);
  if (Gdiplus::GdiplusStartup(&token,&startup_input,NULL) != 
    Gdiplus::Status::Ok)
    ThrowReaderException(CoderError, "GdiplusStartupFailed");
  MultiByteToWideChar(CP_UTF8,0,image->filename,-1,fileName,MagickPathExtent);
  source=Gdiplus::Image::FromFile(fileName);
  if (source == (Gdiplus::Image *) NULL)
    {
      Gdiplus::GdiplusShutdown(token);
      ThrowReaderException(FileOpenError,"UnableToOpenFile");
    }

  image->resolution.x=source->GetHorizontalResolution();
  image->resolution.y=source->GetVerticalResolution();
  image->columns=(size_t) source->GetWidth();
  image->rows=(size_t) source->GetHeight();
  if (image_info->density != (char *) NULL)
    {
      flags=ParseGeometry(image_info->density,&geometry_info);
      image->resolution.x=geometry_info.rho;
      image->resolution.y=geometry_info.sigma;
      if ((flags & SigmaValue) == 0)
        image->resolution.y=image->resolution.x;
      if ((image->resolution.x > 0.0) && (image->resolution.y > 0.0))
        {
          image->columns=(size_t) floor((Gdiplus::REAL) source->GetWidth() /
            source->GetHorizontalResolution() * image->resolution.x + 0.5);
          image->rows=(size_t)floor((Gdiplus::REAL) source->GetHeight() /
            source->GetVerticalResolution() * image->resolution.y + 0.5);
        }
    }

  bitmap=new Gdiplus::Bitmap((INT) image->columns,(INT) image->rows,
    PixelFormat32bppARGB);
  graphics=Gdiplus::Graphics::FromImage(bitmap);
  graphics->SetInterpolationMode(Gdiplus::InterpolationModeHighQualityBicubic);
  graphics->SetSmoothingMode(Gdiplus::SmoothingModeHighQuality);
  graphics->SetTextRenderingHint(Gdiplus::TextRenderingHintClearTypeGridFit);
  graphics->Clear(Gdiplus::Color((BYTE) ScaleQuantumToChar(
    image->background_color.alpha),(BYTE) ScaleQuantumToChar(
    image->background_color.red),(BYTE) ScaleQuantumToChar(
    image->background_color.green),(BYTE) ScaleQuantumToChar(
    image->background_color.blue)));
  graphics->DrawImage(source,0,0,(INT) image->columns,(INT) image->rows);
  delete graphics;
  delete source;

  rect=Gdiplus::Rect(0,0,(INT) image->columns,(INT) image->rows);
  if (bitmap->LockBits(&rect,Gdiplus::ImageLockModeRead,PixelFormat32bppARGB,
    &bitmap_data) != Gdiplus::Ok)
  {
    delete bitmap;
    Gdiplus::GdiplusShutdown(token);
    ThrowReaderException(FileOpenError,"UnableToReadImageData");
  }

  image->alpha_trait=BlendPixelTrait;
  for (y=0; y < (ssize_t) image->rows; y++)
  {
    p=(unsigned char *) bitmap_data.Scan0+(y*abs(bitmap_data.Stride));
    if (bitmap_data.Stride < 0)
      q=GetAuthenticPixels(image,0,image->rows-y-1,image->columns,1,exception);
    else
      q=GetAuthenticPixels(image,0,y,image->columns,1,exception);
    if (q == (Quantum *) NULL)
      break;

    for (x=0; x < (ssize_t) image->columns; x++)
    {
      SetPixelBlue(image,ScaleCharToQuantum(*p++),q);
      SetPixelGreen(image,ScaleCharToQuantum(*p++),q);
      SetPixelRed(image,ScaleCharToQuantum(*p++),q);
      SetPixelAlpha(image,ScaleCharToQuantum(*p++),q);
      q+=GetPixelChannels(image);
    }

    if (SyncAuthenticPixels(image,exception) == MagickFalse)
      break;
  }

  bitmap->UnlockBits(&bitmap_data);
  delete bitmap;
  Gdiplus::GdiplusShutdown(token);
  return(image);
}
예제 #24
0
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);
   }
}
예제 #25
0
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();
}
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);
		}
	}

	SolidBrush brush(0xff000000);
	rx = rf;
	rx.Height = 20;
	rx.Y = rf.Height - rx.Height;

	rx.Y++;
	g.DrawString(item->text.GetBuffer(), item->text.GetLength(), &font, rx, stringFormat, &brush);

	brush.SetColor(item->selected && false ? 0xff6fa6de : 0xfff0f0f0);
	rx.Y--;
	g.DrawString(item->text.GetBuffer(), item->text.GetLength(), &font, rx, stringFormat, &brush);

	delete stringFormat;

	//POSITION p = items.Find(item);
	//items.GetNext(p);
	//if(p)
	{
		RectF rx = rf;
		rx.X += rx.Width - 1;
		rx.Width = 1;
		LinearGradientBrush brush(rx, Color(140, 0x69, 0x69, 0x69), Color(0x69, 0x69, 0x69), LinearGradientModeVertical);
		g.FillRectangle(&brush, rx);
	}
}
예제 #27
0
void CSimplePanelDlg::DrawArrive(Gdiplus::Graphics& gr, vector<BusArrivalInfo>& vecArrival, CRect& rc, CData* pData)
{
	//每次先刷新背景
	Gdiplus::Color cl = Gdiplus::Color::White;
	Gdiplus::SolidBrush brush(cl);
	gr.FillRectangle(&brush, 0, 0, rc.Width(), rc.Height());

	//显示线路号背景
	Gdiplus::PointF pointLineBK(60, 0);
	gr.DrawImage(m_pImLineBK, pointLineBK);

	int nWidth = m_pImLineBK->GetWidth();
	int nHeight = m_pImLineBK->GetHeight();

	//显示线路号
	CString strLineNum = pData->GetLineNumber();
	Gdiplus::SolidBrush brushLineNum(Gdiplus::Color::White);

	WCHAR wcLineNum[6] = {0};
	MultiByteToWideChar(CP_ACP, 0, (char*)(LPCTSTR)strLineNum, strLineNum.GetLength(), wcLineNum, sizeof(wcLineNum));

	Gdiplus::PointF pointLineNum = pointLineBK;
	Gdiplus::RectF rectLineNum(pointLineNum, Gdiplus::SizeF(nWidth, nHeight));
	Gdiplus::Font fontLineNum(L"helvetica", 42 , Gdiplus::FontStyleBold, Gdiplus::UnitPixel);
	Gdiplus::StringFormat stringFormatLineNum;
	stringFormatLineNum.SetAlignment(Gdiplus::StringAlignmentCenter);
	stringFormatLineNum.SetLineAlignment(Gdiplus::StringAlignmentCenter);

	gr.SetTextRenderingHint(Gdiplus::TextRenderingHintAntiAlias);
	gr.DrawString(wcLineNum, wcslen(wcLineNum), &fontLineNum, rectLineNum, &stringFormatLineNum, &brushLineNum);

	//显示路
	std::wstring str = L"路";
	Gdiplus::SolidBrush brushLu(Gdiplus::Color::White);

	Gdiplus::PointF pointWord = pointLineBK;
	pointWord.X += 0.75 * nWidth;
	Gdiplus::RectF rectWord(pointWord, Gdiplus::SizeF(40, nHeight - 5));
	Gdiplus::Font fontLu(L"方正兰亭黑简体", 24 , Gdiplus::FontStyleRegular, Gdiplus::UnitPixel);
	Gdiplus::StringFormat stringFormatWord;
	stringFormatWord.SetAlignment(Gdiplus::StringAlignmentNear);
	stringFormatWord.SetLineAlignment(Gdiplus::StringAlignmentFar);

	gr.SetTextRenderingHint(Gdiplus::TextRenderingHintAntiAlias);
	gr.DrawString(str.c_str(), str.size(), &fontLu, rectWord, &stringFormatWord, &brushLu);

	if(0 < vecArrival.size())
	{
		//显示第一辆车到站
		BusArrivalInfo& stArrive = vecArrival[0];
		if(stArrive.iNum > 0)
		{
			//距离站
			CString strNum;
			strNum.Format("%d", stArrive.iNum);
			Gdiplus::SolidBrush brushNum(Gdiplus::Color(23,117,231));

			WCHAR wcNum[6] = {0};
			MultiByteToWideChar(CP_ACP, 0, (char*)(LPCTSTR)strNum, strNum.GetLength(), wcNum, sizeof(wcNum));

			Gdiplus::PointF pointNum(60 + nWidth, 0);
			Gdiplus::RectF rectNum(pointNum, Gdiplus::SizeF(145, nHeight));
			Gdiplus::Font fontNum(L"helvetica", 42 , Gdiplus::FontStyleBold, Gdiplus::UnitPixel);
			Gdiplus::StringFormat stringFormatNum;
			stringFormatNum.SetAlignment(Gdiplus::StringAlignmentCenter);
			stringFormatNum.SetLineAlignment(Gdiplus::StringAlignmentCenter);

			gr.SetTextRenderingHint(Gdiplus::TextRenderingHintAntiAlias);
			gr.DrawString(wcNum, wcslen(wcNum), &fontNum, rectNum, &stringFormatNum, &brushNum);

			std::wstring wstr = L"站";
			Gdiplus::SolidBrush brushZhan(Gdiplus::Color(149,158,168));
			Gdiplus::PointF pointZhan(60 + nWidth + 145 - 32, 0);
			Gdiplus::RectF rectZhan(pointZhan, Gdiplus::SizeF(40, nHeight - 5));
			Gdiplus::Font fontZhan(L"方正兰亭黑简体", 24 , Gdiplus::FontStyleRegular, Gdiplus::UnitPixel);
			Gdiplus::StringFormat stringFormatZhan;
			stringFormatZhan.SetAlignment(Gdiplus::StringAlignmentNear);
			stringFormatZhan.SetLineAlignment(Gdiplus::StringAlignmentFar);

			gr.SetTextRenderingHint(Gdiplus::TextRenderingHintAntiAlias);
			gr.DrawString(wstr.c_str(), wstr.size(), &fontZhan, rectZhan, &stringFormatZhan, &brushZhan);

		}
		else if(stArrive.iNum == 0)
		{
			if(stArrive.iDistance <= 50)
			{
				std::wstring wstr = L"已经进站";
				Gdiplus::SolidBrush brushZhan(Gdiplus::Color(23,117,231));
				Gdiplus::PointF pointZhan(60 + nWidth, 0);
				Gdiplus::RectF rectZhan(pointZhan, Gdiplus::SizeF(145, nHeight - 5));
				Gdiplus::Font fontZhan(L"方正兰亭黑简体", 24 , Gdiplus::FontStyleRegular, Gdiplus::UnitPixel);
				Gdiplus::StringFormat stringFormatZhan;
				stringFormatZhan.SetAlignment(Gdiplus::StringAlignmentFar);
				stringFormatZhan.SetLineAlignment(Gdiplus::StringAlignmentFar);

				gr.SetTextRenderingHint(Gdiplus::TextRenderingHintAntiAlias);
				gr.DrawString(wstr.c_str(), wstr.size(), &fontZhan, rectZhan, &stringFormatZhan, &brushZhan);
			}
			else
			{
				std::wstring wstr = L"即将到站";
				Gdiplus::SolidBrush brushZhan(Gdiplus::Color(23,117,231));
				Gdiplus::PointF pointZhan(60 + nWidth, 0);
				Gdiplus::RectF rectZhan(pointZhan, Gdiplus::SizeF(145, nHeight - 5));
				Gdiplus::Font fontZhan(L"方正兰亭黑简体", 24 , Gdiplus::FontStyleRegular, Gdiplus::UnitPixel);
				Gdiplus::StringFormat stringFormatZhan;
				stringFormatZhan.SetAlignment(Gdiplus::StringAlignmentFar);
				stringFormatZhan.SetLineAlignment(Gdiplus::StringAlignmentFar);

				gr.SetTextRenderingHint(Gdiplus::TextRenderingHintAntiAlias);
				gr.DrawString(wstr.c_str(), wstr.size(), &fontZhan, rectZhan, &stringFormatZhan, &brushZhan);

			}
		}

	}
	else
	{
		std::wstring wstr = L"待发";
		Gdiplus::SolidBrush brushZhan(Gdiplus::Color(23,117,231));
		Gdiplus::PointF pointZhan(60 + nWidth, 0);
		Gdiplus::RectF rectZhan(pointZhan, Gdiplus::SizeF(145, nHeight - 5));
		Gdiplus::Font fontZhan(L"方正兰亭黑简体", 24 , Gdiplus::FontStyleRegular, Gdiplus::UnitPixel);
		Gdiplus::StringFormat stringFormatZhan;
		stringFormatZhan.SetAlignment(Gdiplus::StringAlignmentFar);
		stringFormatZhan.SetLineAlignment(Gdiplus::StringAlignmentFar);

		gr.SetTextRenderingHint(Gdiplus::TextRenderingHintAntiAlias);
		gr.DrawString(wstr.c_str(), wstr.size(), &fontZhan, rectZhan, &stringFormatZhan, &brushZhan);

	}

	if(1 < vecArrival.size())
	{
		//显示第二辆车到站
		BusArrivalInfo& stArrive = vecArrival[1];
		if(stArrive.iNum > 0)
		{
			//距离站
			CString strNum;
			strNum.Format("%d", stArrive.iNum);
			Gdiplus::SolidBrush brushNum(Gdiplus::Color(23,117,231));

			WCHAR wcNum[6] = {0};
			MultiByteToWideChar(CP_ACP, 0, (char*)(LPCTSTR)strNum, strNum.GetLength(), wcNum, sizeof(wcNum));

			Gdiplus::PointF pointNum(60 + nWidth + 145, 0);
			Gdiplus::RectF rectNum(pointNum, Gdiplus::SizeF(145, nHeight));
			Gdiplus::Font fontNum(L"helvetica", 42 , Gdiplus::FontStyleBold, Gdiplus::UnitPixel);
			Gdiplus::StringFormat stringFormatNum;
			stringFormatNum.SetAlignment(Gdiplus::StringAlignmentCenter);
			stringFormatNum.SetLineAlignment(Gdiplus::StringAlignmentCenter);

			gr.SetTextRenderingHint(Gdiplus::TextRenderingHintAntiAlias);
			gr.DrawString(wcNum, wcslen(wcNum), &fontNum, rectNum, &stringFormatNum, &brushNum);

			std::wstring wstr = L"站";
			Gdiplus::SolidBrush brushZhan(Gdiplus::Color(149,158,168));
			Gdiplus::PointF pointZhan(60 + nWidth + 145 + 145 - 32, 0);
			Gdiplus::RectF rectZhan(pointZhan, Gdiplus::SizeF(40, nHeight - 5));
			Gdiplus::Font fontZhan(L"方正兰亭黑简体", 24 , Gdiplus::FontStyleRegular, Gdiplus::UnitPixel);
			Gdiplus::StringFormat stringFormatZhan;
			stringFormatZhan.SetAlignment(Gdiplus::StringAlignmentNear);
			stringFormatZhan.SetLineAlignment(Gdiplus::StringAlignmentFar);

			gr.SetTextRenderingHint(Gdiplus::TextRenderingHintAntiAlias);
			gr.DrawString(wstr.c_str(), wstr.size(), &fontZhan, rectZhan, &stringFormatZhan, &brushZhan);

		}
		else if(stArrive.iNum == 0)
		{
			if(stArrive.iDistance <= 50)
			{
				std::wstring wstr = L"已经进站";
				Gdiplus::SolidBrush brushZhan(Gdiplus::Color(23,117,231));
				Gdiplus::PointF pointZhan(60 + nWidth + 145, 0);
				Gdiplus::RectF rectZhan(pointZhan, Gdiplus::SizeF(145, nHeight - 5));
				Gdiplus::Font fontZhan(L"方正兰亭黑简体", 24 , Gdiplus::FontStyleRegular, Gdiplus::UnitPixel);
				Gdiplus::StringFormat stringFormatZhan;
				stringFormatZhan.SetAlignment(Gdiplus::StringAlignmentFar);
				stringFormatZhan.SetLineAlignment(Gdiplus::StringAlignmentFar);

				gr.SetTextRenderingHint(Gdiplus::TextRenderingHintAntiAlias);
				gr.DrawString(wstr.c_str(), wstr.size(), &fontZhan, rectZhan, &stringFormatZhan, &brushZhan);
			}
			else
			{
				std::wstring wstr = L"即将到站";
				Gdiplus::SolidBrush brushZhan(Gdiplus::Color(23,117,231));
				Gdiplus::PointF pointZhan(60 + nWidth + 145, 0);
				Gdiplus::RectF rectZhan(pointZhan, Gdiplus::SizeF(145, nHeight - 5));
				Gdiplus::Font fontZhan(L"方正兰亭黑简体", 24 , Gdiplus::FontStyleRegular, Gdiplus::UnitPixel);
				Gdiplus::StringFormat stringFormatZhan;
				stringFormatZhan.SetAlignment(Gdiplus::StringAlignmentFar);
				stringFormatZhan.SetLineAlignment(Gdiplus::StringAlignmentFar);

				gr.SetTextRenderingHint(Gdiplus::TextRenderingHintAntiAlias);
				gr.DrawString(wstr.c_str(), wstr.size(), &fontZhan, rectZhan, &stringFormatZhan, &brushZhan);

			}
		}

	}
	else
	{
		std::wstring wstr = L"待发";
		Gdiplus::SolidBrush brushZhan(Gdiplus::Color(23,117,231));
		Gdiplus::PointF pointZhan(60 + nWidth + 145, 0);
		Gdiplus::RectF rectZhan(pointZhan, Gdiplus::SizeF(145, nHeight - 5));
		Gdiplus::Font fontZhan(L"方正兰亭黑简体", 24 , Gdiplus::FontStyleRegular, Gdiplus::UnitPixel);
		Gdiplus::StringFormat stringFormatZhan;
		stringFormatZhan.SetAlignment(Gdiplus::StringAlignmentFar);
		stringFormatZhan.SetLineAlignment(Gdiplus::StringAlignmentFar);

		gr.SetTextRenderingHint(Gdiplus::TextRenderingHintAntiAlias);
		gr.DrawString(wstr.c_str(), wstr.size(), &fontZhan, rectZhan, &stringFormatZhan, &brushZhan);

	}

}
예제 #28
0
void CSimplePanelDlg::DrawEmpty(Gdiplus::Graphics& gr, CRect& rc)
{
	//每次先刷新背景
	Gdiplus::Color cl = Gdiplus::Color::White;
	Gdiplus::SolidBrush brush(cl);
	gr.FillRectangle(&brush, 0, 0, rc.Width(), rc.Height());

	//显示线路号背景
	Gdiplus::PointF pointLineBK(60, 0);
	gr.DrawImage(m_pImLineBK, pointLineBK);

	int nWidth = m_pImLineBK->GetWidth();
	int nHeight = m_pImLineBK->GetHeight();

	//显示--
	CString strLineNum = "--";
	Gdiplus::SolidBrush brushLineNum(Gdiplus::Color::White);

	WCHAR wcLineNum[6] = {0};
	MultiByteToWideChar(CP_ACP, 0, (char*)(LPCTSTR)strLineNum, strLineNum.GetLength(), wcLineNum, sizeof(wcLineNum));

	Gdiplus::PointF pointLineNum = pointLineBK;
	Gdiplus::RectF rectLineNum(pointLineNum, Gdiplus::SizeF(nWidth, nHeight));
	Gdiplus::Font fontLineNum(L"helvetica", 42 , Gdiplus::FontStyleBold, Gdiplus::UnitPixel);
	Gdiplus::StringFormat stringFormatLineNum;
	stringFormatLineNum.SetAlignment(Gdiplus::StringAlignmentCenter);
	stringFormatLineNum.SetLineAlignment(Gdiplus::StringAlignmentCenter);

	gr.SetTextRenderingHint(Gdiplus::TextRenderingHintAntiAlias);
	gr.DrawString(wcLineNum, wcslen(wcLineNum), &fontLineNum, rectLineNum, &stringFormatLineNum, &brushLineNum);

	//显示路
	std::wstring str = L"路";
	Gdiplus::SolidBrush brushLu(Gdiplus::Color::White);

	Gdiplus::PointF pointWord = pointLineBK;
	pointWord.X += 0.75 * nWidth;
	Gdiplus::RectF rectWord(pointWord, Gdiplus::SizeF(40, nHeight - 5));
	Gdiplus::Font fontLu(L"方正兰亭黑简体", 24 , Gdiplus::FontStyleRegular, Gdiplus::UnitPixel);
	Gdiplus::StringFormat stringFormatWord;
	stringFormatWord.SetAlignment(Gdiplus::StringAlignmentNear);
	stringFormatWord.SetLineAlignment(Gdiplus::StringAlignmentFar);

	gr.SetTextRenderingHint(Gdiplus::TextRenderingHintAntiAlias);
	gr.DrawString(str.c_str(), str.size(), &fontLu, rectWord, &stringFormatWord, &brushLu);

	//第一辆车距离站
	if(1)
	{
		CString strNum = "- -";
		Gdiplus::SolidBrush brushNum(Gdiplus::Color(149,158,168));

		WCHAR wcNum[6] = {0};
		MultiByteToWideChar(CP_ACP, 0, (char*)(LPCTSTR)strNum, strNum.GetLength(), wcNum, sizeof(wcNum));

		Gdiplus::PointF pointNum(60 + nWidth, 0);
		Gdiplus::RectF rectNum(pointNum, Gdiplus::SizeF(145, nHeight));
		Gdiplus::Font fontNum(L"helvetica", 42 , Gdiplus::FontStyleBold, Gdiplus::UnitPixel);
		Gdiplus::StringFormat stringFormatNum;
		stringFormatNum.SetAlignment(Gdiplus::StringAlignmentCenter);
		stringFormatNum.SetLineAlignment(Gdiplus::StringAlignmentCenter);

		gr.SetTextRenderingHint(Gdiplus::TextRenderingHintAntiAlias);
		gr.DrawString(wcNum, wcslen(wcNum), &fontNum, rectNum, &stringFormatNum, &brushNum);

		std::wstring wstr = L"站";
		Gdiplus::SolidBrush brushZhan(Gdiplus::Color(149,158,168));
		Gdiplus::PointF pointZhan(60 + nWidth + 0.7 * 145, 0);
		Gdiplus::RectF rectZhan(pointZhan, Gdiplus::SizeF(40, nHeight - 5));
		Gdiplus::Font fontZhan(L"方正兰亭黑简体", 24 , Gdiplus::FontStyleRegular, Gdiplus::UnitPixel);
		Gdiplus::StringFormat stringFormatZhan;
		stringFormatZhan.SetAlignment(Gdiplus::StringAlignmentNear);
		stringFormatZhan.SetLineAlignment(Gdiplus::StringAlignmentFar);

		gr.SetTextRenderingHint(Gdiplus::TextRenderingHintAntiAlias);
		gr.DrawString(wstr.c_str(), wstr.size(), &fontZhan, rectZhan, &stringFormatZhan, &brushZhan);	
	}


	if(1)
	{
		//第二辆车距离站
		CString strNum = "- -";
		Gdiplus::SolidBrush brushNum(Gdiplus::Color(149,158,168));

		WCHAR wcNum[6] = {0};
		MultiByteToWideChar(CP_ACP, 0, (char*)(LPCTSTR)strNum, strNum.GetLength(), wcNum, sizeof(wcNum));

		Gdiplus::PointF pointNum(60 + nWidth + 145, 0);
		Gdiplus::RectF rectNum(pointNum, Gdiplus::SizeF(145, nHeight));
		Gdiplus::Font fontNum(L"helvetica", 42 , Gdiplus::FontStyleBold, Gdiplus::UnitPixel);
		Gdiplus::StringFormat stringFormatNum;
		stringFormatNum.SetAlignment(Gdiplus::StringAlignmentCenter);
		stringFormatNum.SetLineAlignment(Gdiplus::StringAlignmentCenter);

		gr.SetTextRenderingHint(Gdiplus::TextRenderingHintAntiAlias);
		gr.DrawString(wcNum, wcslen(wcNum), &fontNum, rectNum, &stringFormatNum, &brushNum);

		std::wstring wstr = L"站";
		Gdiplus::SolidBrush brushZhan(Gdiplus::Color(149,158,168));
		Gdiplus::PointF pointZhan(60 + nWidth + 0.7 * 145 + 145, 0);
		Gdiplus::RectF rectZhan(pointZhan, Gdiplus::SizeF(40, nHeight - 5));
		Gdiplus::Font fontZhan(L"方正兰亭黑简体", 24 , Gdiplus::FontStyleRegular, Gdiplus::UnitPixel);
		Gdiplus::StringFormat stringFormatZhan;
		stringFormatZhan.SetAlignment(Gdiplus::StringAlignmentNear);
		stringFormatZhan.SetLineAlignment(Gdiplus::StringAlignmentFar);

		gr.SetTextRenderingHint(Gdiplus::TextRenderingHintAntiAlias);
		gr.DrawString(wstr.c_str(), wstr.size(), &fontZhan, rectZhan, &stringFormatZhan, &brushZhan);
	}


}