Esempio n. 1
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);
		}
	}
}
Esempio n. 2
0
/*
 * Called by SysStats when the Overlay should render itself
 */
STDMETHODIMP CAnimatorOverlay::Render(LONG _hdc)
{
	// Get state of animation meter
	IMeter *iMeter = 0;
	framecount = 1;
	currentframe = 0;
	get_meter(&iMeter);
	if (iMeter)
	{
		iMeter->GetAsLong(L"framecount", &framecount);
		iMeter->GetAsLong(L"currentframe", &currentframe);
	}

	if (alphaEnd == alpha)
		CompositeOverlayImpl<IAnimatorOverlay>::Render(_hdc);
	else
	{
		// Create a private HDC to draw into so that we can mask it.
		long width = 128;
		long height = 128;
		model->get_Width(&width);
		model->get_Height(&height);
		HDCImage hdc((HDC)_hdc, width, height);

		// Render the composite
		CompositeOverlayImpl<IAnimatorOverlay>::Render(hdc);

		// Copy private HDC into the passed HDC
		Graphics g((HDC)_hdc);
		g.SetInterpolationMode(InterpolationModeHighQuality);
		g.SetSmoothingMode(SmoothingModeAntiAlias);
		float delta = framecount <= 1 ? 0.0 : ((float)currentframe)/(framecount-1.0);
		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, ((float)alpha+(alphaEnd-alpha)*delta)/255.0f, 0.0f,
						0.0f, 0.0f, 0.0f, 0.0f, 1.0f};

 		// Create an ImageAttributes object and set its color matrix.
		ImageAttributes imageAtt;
		imageAtt.SetColorMatrix(&colorMatrix, ColorMatrixFlagsDefault, ColorAdjustTypeBitmap);

		g.DrawImage(
		   &hdc.GetImage(),
		   Rect(0, 0, width, height),	// Destination rectangle
		   0,						// Source rectangle X
		   0,						// Source rectangle Y
		   width,		// Source rectangle width
		   height,		// Source rectangle height
		   UnitPixel,
		   &imageAtt);
	}

	return S_OK;
}
Esempio n. 3
0
BOOL CGif::DrawImage(CDC * pDC, POINT * pPoint, int srcx, int srcy, int srcwidth, int srcheight, float * pfClrAttr)
{
	ASSERT(NULL != m_pImage);
	if (NULL == m_pImage) return 1;

	if (IsNull()) return 2;

	Graphics graph(pDC->GetSafeHdc());

	Gdiplus::Point points[3];

	memset(points, 0, sizeof (points));
	if (NULL == pPoint)
	{
		points[1].X = m_nWidth;
		points[2].Y = m_nHeight;
	}
	else
	{
		for (BYTE i = 0;i < 3;i++)
		{
			points[i].X = pPoint[i].x;
			points[i].Y = pPoint[i].y;
		}
	}
	if ((0 == srcwidth)||(0 == srcheight))
	{
		srcwidth = m_nWidth;
		srcheight = m_nHeight;
	}
	if (NULL == pfClrAttr)
	{
		graph.DrawImage(m_pImage, points, 3, srcx, srcy, srcwidth, srcheight, UnitPixel);
	}
	else
	{
#ifdef _DEBUG
		for (BYTE i = 0;i < 25;i++)
		{
			ASSERT(0 <= pfClrAttr[i]);
		}
#endif
		ColorMatrix colorMatrix;
		memcpy(&colorMatrix, pfClrAttr, sizeof (colorMatrix));

		ImageAttributes imageAttr;
		imageAttr.SetColorMatrix(&colorMatrix);

		graph.DrawImage(m_pImage, points, 3, srcx, srcy, srcwidth, srcheight, UnitPixel, &imageAttr);
	}

	graph.ReleaseHDC(pDC->GetSafeHdc());

	return TRUE;
}
Esempio n. 4
0
//╩Л╨о╩Ф╩╜
bool CPngImageEx::AlphaDrawImage(CDC * pDestDC, INT xDest, INT yDest, INT cxDest, INT cyDest, INT xSrc, INT ySrc, INT cxSrc, INT cySrc, BYTE cbAlphaDepth)
{
	//WIN 7 ж╢пп
	if ( CD2DEngine::GetD2DEngine() )
	{
		CD2DEngine::GetD2DEngine()->DrawImage(m_pWnd, m_strImageName, xDest, yDest, cxDest, cyDest, xSrc, ySrc, cxSrc, cySrc, cbAlphaDepth  );
		return true;
	}

	//╢╢╫╗╩╨ЁЕ
	if ((cxDest!=cxSrc)||(cyDest!=cySrc))
	{
		//╪стьеп╤о
		ASSERT(m_pImage!=NULL);
		if (m_pImage==NULL) return false;

		//╢╢╫╗фад╩
		ASSERT(pDestDC!=NULL);
		Graphics graphics(pDestDC->GetSafeHdc());

		//╧╧тЛн╩жц
		RectF rcDrawRect;
		rcDrawRect.X=(REAL)xDest;
		rcDrawRect.Y=(REAL)yDest;
		rcDrawRect.Width=(REAL)cxDest;
		rcDrawRect.Height=(REAL)cyDest;

		//м╦цВ╬ьуС
		ColorMatrix Matrix=
		{
			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,cbAlphaDepth/255.0f,0.0f, 
				0.0f,0.0f,0.0f,0.0f,1.0f
		};

		//иХжцйТпт
		ImageAttributes Attributes; 
		Attributes.SetColorMatrix(&Matrix,ColorMatrixFlagsDefault,ColorAdjustTypeBitmap); 

		//╩Ф╩╜м╪оЯ
		graphics.DrawImage(m_pImage,rcDrawRect,(REAL)xSrc,(REAL)ySrc,(REAL)cxSrc,(REAL)cySrc,UnitPixel,&Attributes);	
	}
	else
	{
		//фум╗╣Всц
		AlphaDrawImage(pDestDC,xDest,yDest,cxDest,cyDest,xSrc,ySrc,cbAlphaDepth);
	}

	return true;
}
Esempio n. 5
0
/*
** Turns the image greyscale by applying a greyscale color matrix.
** Note that the returned bitmap image must be freed by caller.
**
*/
Bitmap* TintedImage::TurnGreyscale(Bitmap* source)
{
	ImageAttributes ImgAttr;
	ImgAttr.SetColorMatrix(&c_GreyScaleMatrix, ColorMatrixFlagsDefault, ColorAdjustTypeBitmap);

	// We need a blank bitmap to paint our greyscale to in case of alpha
	Rect r(0, 0, source->GetWidth(), source->GetHeight());
	Bitmap* bitmap = new Bitmap(r.Width, r.Height, PixelFormat32bppPARGB);

	Graphics graphics(bitmap);
	graphics.DrawImage(source, r, 0, 0, r.Width, r.Height, UnitPixel, &ImgAttr);

	return bitmap;
}
/*
gamma 参数的典型值在 1.0 到 2.2 之间;但在某些情况下,0.1 到 5.0 范围内的值也很有用。
imageAttr.SetGamma 参数值越大,图像越暗,反之则越亮
*/
Bitmap * HighlightBitmap(Bitmap * pSrc, float fGamma, BOOL bCreate )
{
	if (pSrc == NULL) return NULL;
	if (fGamma <= 0.0f) return NULL;

	RectF rc(0.0f, 0.0f, (float)pSrc->GetWidth(), (float)pSrc->GetHeight());
	if ( rc.IsEmptyArea()) return NULL;

	Bitmap * pResult = !bCreate ? pSrc : new Bitmap( (int)rc.Width, (int)rc.Height, pSrc->GetPixelFormat() );
	if( pResult == NULL ) return NULL;

	Graphics * g = Graphics::FromImage(pResult);
	if ( g == NULL)
	{
		if (bCreate) { delete pResult; pResult = NULL; }
		return NULL;
	}
	
	ImageAttributes imageAttr;

	//////////////////////////////////////////////////////////////////////////
#if TRUE
	imageAttr.SetGamma( 1/fGamma );
#else
	Gdiplus:: ColorMatrix HotMat = 
	{1.05f, 0.00f, 0.00f, 0.00f,0.00f,
	0.00f, 1.05f, 0.00f, 0.00f, 0.00f,
	0.00f, 0.00f, 1.05f, 0.00f, 0.00f,
	0.00f, 0.00f, 0.00f, 1.00f, 0.00f,
	0.05f, 0.05f, 0.05f, 0.00f, 1.00f};
	imageAttr.SetColorMatrix(&HotMat);
#endif
	//////////////////////////////////////////////////////////////////////////

	Status status = g->DrawImage(pSrc, rc, 0, 0, (float)pSrc->GetWidth(), (float)pSrc->GetHeight()
		,Gdiplus:: UnitPixel, &imageAttr);

	delete g; g = NULL;

	if ( Ok != status )
	{
		if (bCreate) { delete pResult; pResult = NULL; }
		return NULL;
	}

	return pResult;
}
Esempio n. 7
0
void CRenderUtility::DrawImage( HDC hDC, Image* pImage, RECT &rctDst, RECT&rctSrc, int nAlpha /*= 255*/ )
{
	if(pImage == NULL || nAlpha == 0) return;

	float fAlpha = (float)nAlpha / 255.0f;
	Graphics	graph(hDC);
	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, fAlpha, 0.0f,
		0.0f, 0.0f, 0.0f, 0.0f, 1.0f};

	ImageAttributes imgAtt;
	imgAtt.SetColorMatrix(&colorMatrix);

	Rect rcDst(rctDst.left, rctDst.top, RECT_WIDTH(rctDst), RECT_HEIGHT(rctDst));
	graph.DrawImage(pImage, rcDst, rctSrc.left, rctSrc.top, RECT_WIDTH(rctSrc), RECT_HEIGHT(rctSrc), UnitPixel, &imgAtt);
}
Esempio n. 8
0
/*
** This will apply the Greyscale matrix and the color tinting.
**
*/
void TintedImage::ApplyTint()
{
	bool useColorMatrix = !CompareColorMatrix(m_ColorMatrix, &c_IdentityMatrix);

	if (m_GreyScale || useColorMatrix)
	{
		Bitmap* original = GetImage();
		Bitmap* tint;

		if (m_GreyScale && !useColorMatrix)
		{
			tint = TurnGreyscale(original);
		}
		else
		{
			ImageAttributes ImgAttr;
			ImgAttr.SetColorMatrix(m_ColorMatrix, ColorMatrixFlagsDefault, ColorAdjustTypeBitmap);

			Rect r(0, 0, original->GetWidth(), original->GetHeight());

			tint = new Bitmap(r.Width, r.Height, PixelFormat32bppPARGB);

			Graphics graphics(tint);

			if (m_GreyScale)
			{
				Bitmap* gray = TurnGreyscale(original);
				graphics.DrawImage(gray, r, 0, 0, r.Width, r.Height, UnitPixel, &ImgAttr);
				delete gray;
			}
			else
			{
				graphics.DrawImage(original, r, 0, 0, r.Width, r.Height, UnitPixel, &ImgAttr);
			}
		}

		delete m_BitmapTint;
		m_BitmapTint = tint;
	}
}
Esempio n. 9
0
//输入原图片指针的指针,及新图片的新宽高
//示例:ResizeBitmap(&m_pOrignImageS,width,height);
BOOL CExampleDemoDlg::ResizeBitmap(Bitmap **ppImg, int m_NewWidth, int m_NewHeight)
{
	if (ppImg == NULL || *ppImg == NULL)
	{
		return FALSE;
	}

	Bitmap *m_NewImage = new Bitmap(m_NewWidth, m_NewHeight);

	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, 1.0f, 0.0f,
		0.0f, 0.0f, 0.0f, 0.0f, 1.0f };

	ImageAttributes imageAtt;
	imageAtt.SetColorMatrix(&colorMatrix);
	imageAtt.SetWrapMode(WrapModeTileFlipXY);

	Graphics gs(m_NewImage);
	gs.SetSmoothingMode(SmoothingModeAntiAlias);
	gs.SetInterpolationMode(InterpolationModeHighQuality);
	gs.DrawImage(
		(*ppImg),
		Rect(0, 0, m_NewWidth, m_NewHeight),  // Destination rectangle
		0,								   // Source rectangle temp->x 
		0,								   // Source rectangle temp->y
		(*ppImg)->GetWidth(),     // Source rectangle width
		(*ppImg)->GetHeight(),    // Source rectangle height
		UnitPixel,
		&imageAtt);

	//交换指针
	delete (*ppImg);
	(*ppImg) = m_NewImage;
	return TRUE;
}
Esempio n. 10
0
BOOL GDIPlus_AlphaBlend(HDC hdcDest, int nXOriginDest, int nYOriginDest, int nWidthDest, int nHeightDest, HDC hdcSrc, int nXOriginSrc, int nYOriginSrc, int nWidthSrc, int nHeightSrc, BLENDFUNCTION * bf)
{
	Graphics g(hdcDest);
	BITMAP bmp;
	HBITMAP hbmp = (HBITMAP)GetCurrentObject(hdcSrc, OBJ_BITMAP);
	GetObject(hbmp, sizeof(BITMAP), &bmp);

	Bitmap *bm;
	if (bmp.bmBitsPixel == 32 && bf->AlphaFormat) {
		bm = new Bitmap(bmp.bmWidth, bmp.bmHeight, bmp.bmWidthBytes, PixelFormat32bppPARGB, (BYTE*)bmp.bmBits);
		bm->RotateFlip(RotateNoneFlipY);
	}
	else bm = new Bitmap(hbmp, nullptr);

	ImageAttributes attr;
	ColorMatrix Matrix =
	{
		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, ((float)bf->SourceConstantAlpha) / 255, 0.0f,
		0.0f, 0.0f, 0.0f, 0.0f, 1.0f
	};
	attr.SetColorMatrix(&Matrix, ColorMatrixFlagsDefault, ColorAdjustTypeBitmap);

	if (bf->BlendFlags & 128 && nWidthDest < nWidthSrc && nHeightDest < nHeightSrc) {
		g.SetInterpolationMode(InterpolationModeHighQualityBicubic);
		g.SetPixelOffsetMode(PixelOffsetModeHalf);
		attr.SetGamma((REAL)0.8, ColorAdjustTypeBitmap);
	}
	else g.SetInterpolationMode(InterpolationModeLowQuality);

	RectF rect((float)nXOriginDest, (float)nYOriginDest, (float)nWidthDest, (float)nHeightDest);
	g.DrawImage(bm, rect, (float)nXOriginSrc, (float)nYOriginSrc, (float)nWidthSrc, (float)nHeightSrc, UnitPixel, &attr, nullptr, nullptr);
	delete bm;
	return TRUE;
}
Esempio n. 11
0
void DrawAvatarImageWithGDIp(HDC hDestDC, int x, int y, DWORD width, DWORD height, HBITMAP hbmp, int x1, int y1, DWORD width1, DWORD height1, DWORD flag, BYTE alpha)
{
	BITMAP bmp;
	Bitmap *bm;
	BYTE * bmbits = nullptr;
	GetObject(hbmp, sizeof(BITMAP), &bmp);
	Graphics g(hDestDC);
	if (bmp.bmBitsPixel == 32 && (flag&AVS_PREMULTIPLIED)) {
		bmbits = (BYTE*)bmp.bmBits;
		if (!bmbits) {
			bmbits = (BYTE*)malloc(bmp.bmHeight*bmp.bmWidthBytes);
			GetBitmapBits(hbmp, bmp.bmHeight*bmp.bmWidthBytes, bmbits);
		}
		bm = new Bitmap(bmp.bmWidth, bmp.bmHeight, bmp.bmWidthBytes, PixelFormat32bppPARGB, bmbits);
		bm->RotateFlip(RotateNoneFlipY);
		if (!bmp.bmBits) {
			bm->RotateFlip(RotateNoneFlipY);
			free(bmbits);
		}
	}
	else bm = new Bitmap(hbmp, nullptr);

	ImageAttributes attr;
	ColorMatrix Matrix =
	{
		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, ((float)alpha) / 255, 0.0f,
		0.0f, 0.0f, 0.0f, 0.0f, 1.0f
	};
	attr.SetColorMatrix(&Matrix, ColorMatrixFlagsDefault, ColorAdjustTypeBitmap);
	g.SetInterpolationMode(InterpolationModeHighQualityBicubic);
	RectF rect((float)x, (float)y, (float)width, (float)height);
	g.DrawImage(bm, rect, (float)x1, (float)y1, (float)width1, (float)height1, UnitPixel, &attr, nullptr, nullptr);
	delete bm;
}
Esempio n. 12
0
// ***************************************************************
//		InitImageAttributes()
// ***************************************************************
void TilesDrawer::InitImageAttributes(TileManager* manager, ImageAttributes& attr)
{
	attr.SetWrapMode(WrapModeTileFlipXY);

	if (!manager->IsBackground())
	{
		Gdiplus::ColorMatrix m = ImageHelper::CreateMatrix(manager->contrast,
			manager->brightness,
			manager->saturation,
			manager->hue,
			0.0f, RGB(255, 255, 255), false, manager->get_Alpha() / 255.0f);

		attr.SetColorMatrix(&m);

		if (manager->useTransparentColor)
		{
			Gdiplus::Color color(GetRValue(manager->transparentColor),
								 GetGValue(manager->transparentColor),
								 GetBValue(manager->transparentColor));

			attr.SetColorKey(color, color);
		}
	}
}
Esempio n. 13
0
void DrawHighlight( Image * pImage, Graphics * pGraphics, RectF rcDraw, float fGamma /*= 2.2f */ )
{
	if (pGraphics == NULL) return;
	if (pImage == NULL) return;

	ImageAttributes imageAttr;
	//////////////////////////////////////////////////////////////////////////
#if FALSE
	imageAttr.SetGamma( 1/fGamma );
#else
	Gdiplus:: ColorMatrix HotMat = 
	{1.05f, 0.00f, 0.00f, 0.00f,0.00f,
	0.00f, 1.05f, 0.00f, 0.00f, 0.00f,
	0.00f, 0.00f, 1.05f, 0.00f, 0.00f,
	0.00f, 0.00f, 0.00f, 1.00f, 0.00f,
	0.05f, 0.05f, 0.05f, 0.00f, 1.00f};
	imageAttr.SetColorMatrix(&HotMat);
#endif
	//////////////////////////////////////////////////////////////////////////

	RectF rc (0.0f, 0.0f, (float)pImage->GetWidth(), (float)pImage->GetHeight());
	pGraphics->DrawImage( pImage, rcDraw, rc.GetLeft(), rc.GetTop(), rc.Width, rc.Height
		, Gdiplus:: UnitPixel, &imageAttr );
}
//
// 윈도우 프로시져 함수 ( 메시지 큐에서 받아온 메시지를 처리한다 )
//
LRESULT CALLBACK WndProc( HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam )
{
	PAINTSTRUCT ps;
	HDC hdc;

	switch (msg)
	{
	case WM_PAINT: // 화면이 갱신될 때 호출된다.
		{
			hdc = BeginPaint(hWnd, &ps);

			Graphics *graph = Graphics::FromImage(g_bmp);

			RECT cr;
			GetClientRect(hWnd, &cr);
			Rect wndSize(cr.left, cr.top, cr.right, cr.bottom);

			graph->DrawImage(g_image, wndSize);

			graph->FillRectangle(g_yellowBrush, g_block);
			graph->FillRectangle(g_yellowBrush, g_block2);


			graph->DrawImage(g_image2, g_bullet, 
				g_bulletSrc.X, g_bulletSrc.Y, g_bulletSrc.Width, g_bulletSrc.Height,
				UnitPixel);


			float fBlend = 1.f; //set the alpha value
			ColorMatrix BitmapMatrix = {
				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, fBlend, 0.0f,
				0.0f, 0.0f, 0.0f, 0.0f, 1.0f
			};

			ImageAttributes ImgAttr;
			ImgAttr.SetColorMatrix(&BitmapMatrix,
				ColorMatrixFlagsDefault,
				ColorAdjustTypeBitmap);

			//graph->SetCompositingMode(CompositingModeSourceCopy);
			if (g_isCollision)
			{
				graph->DrawImage(g_image3, g_bullet, 
					g_explosion.X, g_explosion.Y, g_explosion.Width, g_explosion.Height,
					UnitPixel, &ImgAttr);
			}

//			graph->DrawImage(g_image3, g_bullet, 
//				g_explosion.X, g_explosion.Y, g_explosion.Width, g_explosion.Height,
//				UnitPixel);


			DrawString(graph, 50, 0, frameStr);

			g_graphics->DrawImage(g_bmp, wndSize);


			EndPaint(hWnd, &ps);
		}
		break;

//	case WM_ERASEBKGND:
//		return 0;

	case WM_LBUTTONDOWN:
		{
			g_IsClick = true;
			g_mouseClickPos = Point(LOWORD(lParam), HIWORD(lParam));
		}
		break;

	case WM_LBUTTONUP:
		{
			g_IsClick = false;
		}
		break;

	case WM_MOUSEMOVE:
		{
		}
		break;

	case WM_KEYDOWN:
		switch (wParam)
		{
		case VK_LEFT:
		case VK_UP:
			++g_hatchStyle;
			break;

		case VK_RIGHT:
		case VK_DOWN:
			--g_hatchStyle;
			break;
		}
		break;

	case WM_TIMER:
		{
			if (wParam == 1)
			{
				int a = 0;
			}
			else if (wParam == 2)
			{
				int a = 0;
			}
		}
		break;

	case WM_DESTROY: //윈도우가 파괴된다면..
		PostQuitMessage(0);	//프로그램 종료 요청 ( 메시지 루프를 빠져나가게 된다 )
		break;
	}

	return DefWindowProc( hWnd, msg, wParam, lParam ); // 기본적인 메세지 처리를 담당한다.
}
Esempio n. 15
0
void uie_albumart::paint(HDC hdc)
{
    RECT wndrect_temp;
    if(GetClientRect(m_hWnd,&wndrect_temp))
    {
        Graphics gfx(hdc);
        Rect wndrect(
            wndrect_temp.left,
            wndrect_temp.top,
            wndrect_temp.right-wndrect_temp.left,
            wndrect_temp.bottom-wndrect_temp.top
            );

        Color bg;
        bg.SetFromCOLORREF((m_config.bg_enabled)
                           ?m_config.bgcol
                           :GetSysColor(COLOR_3DFACE));

        bool noimage = m_bufnew.is_empty();
        bool image_changed = !m_image_file_exists || m_bmpnew.is_valid();
        bool size_changed = m_bufnew.is_valid()
            ? (m_bufnew->GetWidth() != wndrect.Width || m_bufnew->GetHeight() != wndrect.Height)
            : true;
        if (noimage || image_changed || size_changed || m_config_changed || m_dragging)
        {
            if (!m_dragging)
            {
                m_pan_dx = m_pan_dy = 0;
            }
            else
            {
                m_bmpnew = m_bmp;
            }

            if (size_changed || noimage)
            {
                // create bitmaps with new size
                m_animating = false;
                m_bufold.release();
                m_bufanim.release();

                m_bufold = new Bitmap(wndrect.Width,wndrect.Height,&gfx);
                m_bufnew = new Bitmap(wndrect.Width,wndrect.Height,&gfx);

                // make sure currently displayed image is redrawn
                // during the resize
                m_bmpnew = m_bmp;
            }
            if (m_config.animtime == 0)
                m_bufanim.release();
            else if (m_bufanim.is_empty())
                m_bufanim=new Bitmap(wndrect.Width,wndrect.Height,&gfx);

            m_config_changed = false;

            Bitmap *temp = m_bufold.detach();
            m_bufold.set(m_bufnew.detach());
            m_bufnew.set(temp);

            Graphics bufgfx(m_bufnew.get_ptr());
            bufgfx.Clear(bg);

            if (m_bmpnew.is_valid())
            {
                // adjust for padding
                if(m_config.padding > 0)
                {
                    wndrect.Height-=2*m_config.padding;
                    wndrect.Width-=2*m_config.padding;
                    wndrect.X+=m_config.padding;
                    wndrect.Y+=m_config.padding;
                }

                Size bmp_dim(m_bmpnew->GetWidth(), m_bmpnew->GetHeight());

                // rectangle that will be drawn on the screen
                RectF rect(wndrect.X, wndrect.Y, bmp_dim.Width, bmp_dim.Height);

                // shrink album art
                if (m_config.shrinkalbum)
                {
                    if (bmp_dim.Width > wndrect.Width)
                        rect.Width = wndrect.Width;

                    if (bmp_dim.Height > wndrect.Height)
                        rect.Height = wndrect.Height;
                }

                // expand album art
                if (m_config.expandalbum)
                {
                    if (bmp_dim.Width < wndrect.Width)
                        rect.Width = wndrect.Width;

                    if (bmp_dim.Height < wndrect.Height)
                        rect.Height = wndrect.Height;
                }

                // correct aspect ratio
                if (m_config.aspectratio)
                {
                    REAL new_width = bmp_dim.Width*(rect.Height/bmp_dim.Height);
                    REAL new_height = bmp_dim.Height*(rect.Width/bmp_dim.Width);

                    if (m_config.expandalbum && !m_config.shrinkalbum)
                    {
                        // try to fill the entire window, even if parts of the
                        // image are cut off (enlarge image)
                        if (new_height >= wndrect.Height)
                        {
                            rect.Height = new_height;
                        }
                        else
                        {
                            if (new_width >= wndrect.Width)
                            {
                                rect.Width = new_width;
                            }
                        }
                    }
                    else
                    {
                        // do not cut off any part of the image while
                        // maintaining aspect ratio (shrink image)
                        if (new_height <= wndrect.Height)
                        {
                            rect.Height = new_height;
                        }
                        else
                        {
                            if (new_width <= wndrect.Width)
                            {
                                rect.Width = new_width;
                            }
                        }
                    }
                }

                // Center album
                // uses integers for the offsets because if the offset
                // is a fraction of a pixel, there's lowered quality
                if (m_config.centeralbum)
                {
                    int center_dx = (wndrect.GetRight() - rect.GetRight()) / 2;
                    int center_dy = (wndrect.GetBottom() - rect.GetBottom()) / 2;
                    rect.Offset((REAL)center_dx,
                                (REAL)center_dy);
                }

                if (m_config.draw_pixel_border)
                {
                    Gdiplus::Color border;
                    border.SetFromCOLORREF(m_config.bordercol);

                    rect.Width--;
                    rect.Height--;
                    bufgfx.DrawRectangle(& Pen(border),rect);
                    rect.X++;
                    rect.Y++;
                    rect.Width--;
                    rect.Height--;
                }

                m_panning_enabled = ((rect.Width > wndrect.Width) ||
                                     (rect.Height > wndrect.Height));

                // panning
                REAL dx = m_pan_dx;
                REAL dy = m_pan_dy;
                if (m_dragging)
                {
                    // Make sure the image doesn't pan out of bounds
                    if (m_panning_enabled)
                    {
                        if (rect.Width > wndrect.Width)
                        {
                            if ((rect.GetLeft()+dx) > wndrect.GetLeft())
                                dx = wndrect.GetLeft() - rect.GetLeft();
                            if ((rect.GetRight()+dx) < wndrect.GetRight())
                                dx = wndrect.GetRight() - rect.GetRight();
                        }

                        if (rect.Height > wndrect.Height)
                        {
                            if ((rect.GetTop()+dy) > wndrect.GetTop())
                                dy = wndrect.GetTop() - rect.GetTop();
                            if ((rect.GetBottom()+dy) < wndrect.GetBottom())
                                dy = wndrect.GetBottom() - rect.GetBottom();
                        }
                    }
                    else
                    {
                        dx = 0;
                        dy = 0;
                    }

                    if (rect.Width <= wndrect.Width) dx = 0;
                    if (rect.Height <= wndrect.Height) dy = 0;

                    m_pan_dx = dx;
                    m_pan_dy = dy;
                }
                rect.Offset(dx,dy);

                bufgfx.SetInterpolationMode(m_config.interpolationmode == RESIZE_HIGH
                    ? InterpolationModeHighQuality
                    : m_config.interpolationmode == RESIZE_MEDIUM
                        ? InterpolationModeDefault
                        : m_config.interpolationmode == RESIZE_LOW
                            ? InterpolationModeLowQuality
                            // m_config.interpolationmode == RESIZE_HIGHEST
                            : InterpolationModeHighQualityBicubic);

                if (m_dragging) bufgfx.SetInterpolationMode(InterpolationModeLowQuality);

                REAL srcWidth = m_bmpnew->GetWidth();
                REAL srcHeight = m_bmpnew->GetHeight();
                REAL srcX = 0;
                REAL srcY = 0;

                /*if (m_config.padding < 0)
                {
                    if(abs(m_config.padding) < m_bmpnew->GetWidth() &&
                       abs(m_config.padding) < m_bmpnew->GetHeight())
                    {
                        srcWidth+=2*m_config.padding;
                        srcHeight+=2*m_config.padding;
                        srcX-=m_config.padding;
                        srcY-=m_config.padding;
                    }
                }*/

                bufgfx.SetClip(wndrect);    // ensures that padding is respected
                bufgfx.DrawImage(
                    &(*m_bmpnew),
                    rect,         // destination rectangle
                    srcX, srcY,   // upper-left corner of source rectangle
                    srcWidth,     // width of source rectangle
                    srcHeight,    // height of source rectangle
                    UnitPixel);
            }

            // m_bufnew updated. time to fade in the changes.
            DWORD now = GetTickCount();
            if (m_config.animtime != 0 && !size_changed && (m_animshouldstart+700) > now)
            {
                m_animating = true;
                m_animstarted=GetTickCount();
                set_anim_timer();
            }
        }



        Rect dest(wndrect_temp.left,
            wndrect_temp.top,
            wndrect_temp.right-wndrect_temp.left,
            wndrect_temp.bottom-wndrect_temp.top);
        if (m_bufnew.is_valid() && !m_animating)
        {
            gfx.DrawImage(m_bufnew.get_ptr(), 0, 0);
        }
        else if (m_animating && m_bufnew.is_valid() && m_bufanim.is_valid())
        {
            float opacityold=0.0f;
            float opacitynew=1.0f;
            int doneness=GetTickCount();
            if (doneness > (m_animstarted+m_config.animtime))
            // animation complete
            {
                m_animating=false;
                opacityold=0.0f;
                opacitynew=1.0f;
            }
            else if (doneness >= m_animstarted && m_config.animtime != 0)
            {
                opacitynew=(float)(doneness-m_animstarted)/(float)m_config.animtime;
                opacityold=1.0f-0.0f;
            }
            {
                Graphics animbuf(m_bufanim.get_ptr());
                animbuf.Clear(bg);
                ColorMatrix cm;
                ZeroMemory(&cm,sizeof(ColorMatrix));
                cm.m[0][0] = 1.0f;
                cm.m[1][1] = 1.0f;
                cm.m[2][2] = 1.0f;
                cm.m[3][3] = opacityold;

                ImageAttributes ia;
                ia.SetColorMatrix(&cm);
                animbuf.DrawImage(m_bufold.get_ptr(),dest,0,0,dest.Width,dest.Height,UnitPixel,&ia);
                cm.m[3][3] = opacitynew;
                ia.SetColorMatrix(&cm);
                animbuf.DrawImage(m_bufnew.get_ptr(),dest,0,0,dest.Width,dest.Height,UnitPixel,&ia);
            }
            gfx.DrawImage(m_bufanim.get_ptr(), 0, 0);
            if (m_animating)
                set_anim_timer();
            else
                m_bufanim.release();
        }
        else gfx.Clear(bg);

        m_bmpnew.release();
    }
}
Esempio n. 16
0
void CUILabel::DoPaint(HDC hDC, const RECT& rcPaint)
{
	if (m_BackColor != INVALID__UICOLOR)
	{
		CUIBlueRenderEngine::DoFillRect(hDC, m_pManager, m_rcItem, m_BackColor);
	}

	if (m_BorderColorOutside != INVALID__UICOLOR)
	{
		RECT rect = {m_rcItem.left + 1, m_rcItem.top + 1, m_rcItem.right - 1, m_rcItem.bottom - 1};
		CUIBlueRenderEngine::DoPaintBorder(hDC, m_pManager, m_rcItem, m_BorderColorOutside);
	}

	if (m_BorderColorInside != INVALID__UICOLOR)
	{
		RECT rect = {m_rcItem.left + 1, m_rcItem.top + 1, m_rcItem.right - 1, m_rcItem.bottom - 1};
		CUIBlueRenderEngine::DoPaintBorder(hDC, m_pManager, rect, m_BorderColorInside);
	}

	if (m_pImageOwner != NULL && m_nIndex >= 0)
	{
		RECT rc = m_rcItem;

		Graphics graph(hDC);

		int nStartX = rc.left;
		int nStartY = rc.top;

		int nImageWidth = m_pImageOwner->GetWidth() / m_nImageCount;
		int nImageHeight = m_pImageOwner->GetHeight();

		double dblScal = (double)nImageWidth / nImageHeight;

		int nRectWidth = nImageWidth;
		int nRectHeight = nImageHeight;

		if (m_sizeAnimate.cx != 0 && m_sizeAnimate.cy != 0)
		{
			nRectWidth = m_sizeAnimate.cx;
			nRectHeight = m_sizeAnimate.cy;
		}


		if ((m_rcItem.bottom - m_rcItem.top) * dblScal < (m_rcItem.right - m_rcItem.left))
		{
			nRectWidth = (int)(nRectHeight * dblScal);
		}
		else
		{
			nRectHeight = (int)(nRectWidth / dblScal);
		}


		nStartX = rc.left + (rc.right - rc.left - nRectWidth) / 2;
		if (nStartX < rc.left)
		{
			nStartX = rc.left;

			nRectWidth = rc.right - rc.left;
		}

		nStartY = rc.top + (rc.bottom - rc.top - nRectHeight) / 2;
		if (nStartY < rc.top)
		{
			nStartY = rc.top;

			nRectHeight = rc.bottom - rc.top;
		}


		RectF rfDest(PointF((REAL)nStartX, (REAL)nStartY), SizeF((REAL)nRectWidth, (REAL)nRectHeight));

		if (m_fAlpha <= 1.0)
		{
			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, m_fAlpha, 0.0f, 
				0.0f, 0.0f, 0.0f, 0.0f, 1.0f
			}; 

			ImageAttributes imageAtt; 
			imageAtt.SetColorMatrix(&colorMatrix, ColorMatrixFlagsDefault, ColorAdjustTypeBitmap); 
			graph.DrawImage(m_pImageOwner, rfDest, (REAL)nImageWidth * m_nIndex, (REAL)0, (REAL)nImageWidth, (REAL)nImageHeight, UnitPixel, &imageAtt);
		}
		else
		{
			graph.DrawImage(m_pImageOwner, rfDest, (REAL)nImageWidth * m_nIndex, (REAL)0, (REAL)nImageWidth, (REAL)nImageHeight, UnitPixel, NULL);
		}


		if (m_bImageAsLinker && m_sText.GetLength() == 0)
		{
			m_nLinks = 1;
			m_rcLinks[0] = CUIRect(nStartX, nStartY, nStartX + nRectWidth, nStartY + nRectHeight);
		}
	}
	
	if (m_sText.GetLength() > 0)
	{
		RECT rcText = m_rcItem;
		m_nLinks = lengthof(m_rcLinks);
		COLORREF color = m_TextColor;
		if (!IsEnabled())
		{
			color = m_TextColor_Disable;
		}

		CUIBlueRenderEngine::DoPaintPrettyText(hDC, m_pManager, rcText, m_sText, color, INVALID__UICOLOR, m_rcLinks, m_nLinks, m_uTextStyle);

		if (m_nLinks == 1 && m_sText.GetLength() > 4)
		{
			if ((m_sText.GetAt(0) == _T('<') && m_sText.GetAt(1) == _T('a')) && 
				(m_sText.GetAt(m_sText.GetLength() - 1) == _T('>') && m_sText.GetAt(m_sText.GetLength() - 2) == _T('a'))
				)
			{
				if (m_rcLinks[0].right - m_rcLinks[0].left < 20)
				{
					m_rcLinks[0].left = m_rcItem.left;
					m_rcLinks[0].right = m_rcItem.right;
				}
			}	
		}
	}
}
Esempio n. 17
0
//控件颜色
HBRUSH CPngButton::CtlColor(CDC* pScreenDC, UINT nCtlColor) 
{
	if (!m_bHaveBitmaps)
	{
		//验证判断
		if(!m_pStdImage.m_pBitmap)	return NULL; 
	
		//变量声明
		CBitmap bmp,	*pOldBitmap;

		//获取区域
		CRect rect;
		GetClientRect(rect);

		//创建内存DC
		CMemDC2 pDC(pScreenDC,rect);

		Gdiplus::Graphics graphics(pDC->m_hDC);

		//背景DC
		if(m_dcBk.m_hDC==NULL)
		{
			CRect rect1;
			CClientDC clDC(GetParent());

			GetWindowRect(rect1);
			GetParent()->ScreenToClient(rect1);

			m_dcBk.CreateCompatibleDC(&clDC);
			bmp.CreateCompatibleBitmap(&clDC,rect.Width(),rect.Height());
			pOldBitmap = m_dcBk.SelectObject(&bmp);
			m_dcBk.BitBlt(0,0,rect.Width(),rect.Height(),&clDC,rect1.left,rect1.top,SRCCOPY);
			bmp.DeleteObject();
		}

		//标准按钮
		if (m_dcStd.m_hDC == NULL)
		{
			PaintBk(pDC);

			float width = (float)m_pStdImage.m_pBitmap->GetWidth()/5;
			float height = (float)m_pStdImage.m_pBitmap->GetHeight();
			RectF grect; grect.X=0, grect.Y=0; grect.Width = width; grect.Height = height;

			graphics.DrawImage(m_pStdImage,grect,0,0,width,height,UnitPixel);

			m_dcStd.CreateCompatibleDC(pDC);
			bmp.CreateCompatibleBitmap(pDC,rect.Width(),rect.Height());
			pOldBitmap=m_dcStd.SelectObject(&bmp);
			m_dcStd.BitBlt(0,0,rect.Width(),rect.Height(),pDC,0,0,SRCCOPY);
			bmp.DeleteObject();

			// 按下状态
			if (m_dcStdP.m_hDC == NULL)
			{
				PaintBk(pDC);

				float width = (float)m_pStdImage.m_pBitmap->GetWidth()/5;
				float height = (float)m_pStdImage.m_pBitmap->GetHeight();

				RectF grect; grect.X=0, grect.Y=0; grect.Width = width; grect.Height = height;

				graphics.DrawImage(m_pStdImage,grect,width*2,0,width,height,UnitPixel);

				m_dcStdP.CreateCompatibleDC(pDC);
				bmp.CreateCompatibleBitmap(pDC,rect.Width(),rect.Height());
				pOldBitmap = m_dcStdP.SelectObject(&bmp);
				m_dcStdP.BitBlt(0,0,rect.Width(),rect.Height(),pDC,0,0,SRCCOPY);
				bmp.DeleteObject();
			}

			// 盘旋状态  
			if(m_dcStdH.m_hDC == NULL)
			{     
				PaintBk(pDC);

				ColorMatrix HotMat = { 1.05f, 0.00f, 0.00f, 0.00f, 0.00f,
					0.00f, 1.05f, 0.00f, 0.00f, 0.00f,
					0.00f, 0.00f, 1.05f, 0.00f, 0.00f,
					0.00f, 0.00f, 0.00f, 1.00f, 0.00f,
					0.05f, 0.05f, 0.05f, 0.00f, 1.00f };

				ImageAttributes ia;
				ia.SetColorMatrix(&HotMat);

				float width = (float)m_pStdImage.m_pBitmap->GetWidth()/5;
				float height = (float)m_pStdImage.m_pBitmap->GetHeight();

				RectF grect; grect.X=0, grect.Y=0; grect.Width = width; grect.Height = height;

				graphics.DrawImage(m_pStdImage, grect, width, 0, width, height, UnitPixel, &ia);

				m_dcStdH.CreateCompatibleDC(pDC);
				bmp.CreateCompatibleBitmap(pDC, rect.Width(), rect.Height());
				pOldBitmap = m_dcStdH.SelectObject(&bmp);
				m_dcStdH.BitBlt(0, 0, rect.Width(), rect.Height(), pDC, 0, 0, SRCCOPY);
				bmp.DeleteObject();
			}

			// 无效状态   
			if(m_dcGS.m_hDC == NULL)
			{     
				PaintBk(pDC);

				ColorMatrix GrayMat = { 0.30f, 0.30f, 0.30f, 0.00f, 0.00f,
					0.59f, 0.59f, 0.59f, 0.00f, 0.00f,
					0.11f, 0.11f, 0.11f, 0.00f, 0.00f,
					0.00f, 0.00f, 0.00f, 1.00f, 0.00f,
					0.00f, 0.00f, 0.00f, 0.00f, 1.00f };

				ImageAttributes ia;
				ia.SetColorMatrix(&GrayMat);

				float width = (float)m_pStdImage.m_pBitmap->GetWidth()/5;
				float height = (float)m_pStdImage.m_pBitmap->GetHeight();

				RectF grect; grect.X=0, grect.Y=0; grect.Width = width; grect.Height = height;

				graphics.DrawImage(m_pStdImage, grect, 0, 0, width, height, UnitPixel, &ia);
				m_dcGS.CreateCompatibleDC(pDC);
				bmp.CreateCompatibleBitmap(pDC, rect.Width(), rect.Height());
				pOldBitmap = m_dcGS.SelectObject(&bmp);
				m_dcGS.BitBlt(0, 0, rect.Width(), rect.Height(), pDC, 0, 0, SRCCOPY);
				bmp.DeleteObject();
			}
		}
		// 交替按钮
		if( (m_dcAlt.m_hDC == NULL) && m_bHaveAltImage )
		{    
			PaintBk(pDC);

			float width = (float)m_pAltImage.m_pBitmap->GetWidth()/5;
			float height = (float)m_pAltImage.m_pBitmap->GetHeight();
			RectF grect; grect.X=0, grect.Y=0; grect.Width = width; grect.Height = height;

			graphics.DrawImage(m_pAltImage,grect,0,0,width,height,UnitPixel);   

			m_dcAlt.CreateCompatibleDC(pDC);    
			bmp.CreateCompatibleBitmap(pDC, rect.Width(), rect.Height());    
			pOldBitmap = m_dcAlt.SelectObject(&bmp);    
			m_dcAlt.BitBlt(0, 0, rect.Width(), rect.Height(), pDC, 0, 0, SRCCOPY);    
			bmp.DeleteObject();

			// 按下状态
			if( (m_dcAltP.m_hDC == NULL) && m_bHaveAltImage )    
			{     
				PaintBk(pDC);

				float width = (float)m_pAltImage.m_pBitmap->GetWidth()/5;
				float height = (float)m_pAltImage.m_pBitmap->GetHeight();

				RectF grect; grect.X=0, grect.Y=0; grect.Width = width; grect.Height = height;
				
				graphics.DrawImage(m_pAltImage,grect,width*2,0,width,height,UnitPixel);

				m_dcAltP.CreateCompatibleDC(pDC);
				bmp.CreateCompatibleBitmap(pDC, rect.Width(), rect.Height());
				pOldBitmap = m_dcAltP.SelectObject(&bmp);
				m_dcAltP.BitBlt(0, 0, rect.Width(), rect.Height(), pDC, 0, 0, SRCCOPY);
				bmp.DeleteObject();
			}

			// 盘旋状态
			if(m_dcAltH.m_hDC == NULL)
			{     
				PaintBk(pDC);

				ColorMatrix HotMat = { 1.05f, 0.00f, 0.00f, 0.00f, 0.00f,           
					0.00f, 1.05f, 0.00f, 0.00f, 0.00f,           
					0.00f, 0.00f, 1.05f, 0.00f, 0.00f,           
					0.00f, 0.00f, 0.00f, 1.00f, 0.00f,           
					0.05f, 0.05f, 0.05f, 0.00f, 1.00f };

				ImageAttributes ia;     
				ia.SetColorMatrix(&HotMat);

				float width = (float)m_pAltImage.m_pBitmap->GetWidth()/5; 
				float height = (float)m_pAltImage.m_pBitmap->GetHeight();

				RectF grect; grect.X=0, grect.Y=0; grect.Width = width; grect.Height = height;

				graphics.DrawImage(m_pAltImage, grect, 0, 0, width, height, UnitPixel, &ia);
				m_dcAltH.CreateCompatibleDC(pDC); 
				bmp.CreateCompatibleBitmap(pDC, rect.Width(), rect.Height());
				pOldBitmap = m_dcAltH.SelectObject(&bmp); 
				m_dcAltH.BitBlt(0, 0, rect.Width(), rect.Height(), pDC, 0, 0, SRCCOPY);
				bmp.DeleteObject();
			}   
		}
		if(m_pCurBtn == NULL)   
		{    
			m_pCurBtn = &m_dcStd;  
		}
		m_bHaveBitmaps = TRUE;
	}
	return NULL;
}
Esempio n. 18
0
//»æ»­Í¼Ïñ
bool CGdiPlusImage::DrawImage(CDC * pDC, INT nXPos, INT nYPos)
{
    //¼ÓÔØÅжÏ
    //ASSERT(m_pImage!=NULL);
    if (m_pImage==NULL) return false;

    //´´½¨ÆÁÄ»
    ASSERT(pDC!=NULL);
    Graphics graphics(pDC->GetSafeHdc());

    GraphicsContainer Containter = graphics.BeginContainer();
    graphics.SetSmoothingMode(SmoothingModeHighQuality);

    //»ñÈ¡ÊôÐÔ
    INT nImageWidth=m_pImage->GetWidth();
    INT nImageHeight=m_pImage->GetHeight();

    //¹¹ÔìλÖÃ
    RectF rcDrawRect;
    rcDrawRect.X=0;//(REAL)nXPos;
    rcDrawRect.Y=0;//(REAL)nYPos;
    rcDrawRect.Width=(REAL)nImageWidth;
    rcDrawRect.Height=(REAL)nImageHeight;

    Matrix matrix;

    CPoint pt((nXPos+nImageWidth/2), (nYPos+nImageHeight/2));
    PointF ptBase((float)pt.x,(float)pt.y);

    //¾ØÕó±ä»»Òª×¢Òâ˳Ðò£¬ÏÈƽÒÆÔÚËõ·ÅºóÐýת
    matrix.Translate((REAL)nXPos,(REAL)nYPos,MatrixOrderAppend);

    //Ëõ·Å
    if ( m_szZoom.cx != 1.0f || m_szZoom.cy != 1.0f )
    {
        ptBase.X += m_szZoom.cx;
        ptBase.Y += m_szZoom.cy;

        matrix.Translate(-ptBase.X,-ptBase.Y,MatrixOrderAppend);
        matrix.Scale(m_szZoom.cx,m_szZoom.cy,MatrixOrderAppend);
        matrix.Translate(ptBase.X,ptBase.Y,MatrixOrderAppend);
    }

    //Ðýת
    if (m_nRotateAngle)
    {
        matrix.RotateAt((REAL)m_nRotateAngle,ptBase,MatrixOrderAppend);
    }

    graphics.SetTransform(&matrix);

    //͸Ã÷¾ØÕó
    ColorMatrix Matrix=
    {
        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,m_cbAlphaDepth/255.0f,0.0f, 
        0.0f,0.0f,0.0f,0.0f,1.0f
    };

    //ÉèÖÃÊôÐÔ
    ImageAttributes Attributes; 
    Attributes.SetColorMatrix(&Matrix,ColorMatrixFlagsDefault,ColorAdjustTypeBitmap); 

    //»æ»­Í¼Ïñ
    graphics.DrawImage(m_pImage,rcDrawRect,0,0,(REAL)nImageWidth,(REAL)nImageHeight,UnitPixel,&Attributes);

    graphics.ResetTransform();

    graphics.EndContainer(Containter);

    return true;
}
Esempio n. 19
0
//=============================================================================
//
//	The framework calls this member function when a child control is about to 
//	be drawn.  All the bitmaps are created here on the first call. Every thing
//	is done with a memory DC except the background, which get's it's information 
//	from the parent. The background is needed for transparent portions of PNG 
//	images. An always on top app (such as Task Manager) that is in the way can 
//	cause it to get an incorrect background.  To avoid this, the parent should 
//	call the SetBkGnd function with a memory DC when it creates the background.
//				
//=============================================================================
HBRUSH CGdipButtonTile::CtlColor(CDC* pScreenDC, UINT nCtlColor) 
{
	if(!m_bHaveBitmaps)
	{
		if(!m_pStdLeftImage || !m_pStdCenterImage || !m_pStdRightImage)
		{
			return NULL; // Load the standard image with LoadStdImage()
		}

		CBitmap bmp, *pOldBitmap;

		CRect rect;
		GetClientRect(rect);

		// do everything with mem dc
		CMemDCEx pDC(pScreenDC, rect);


		Gdiplus::Graphics graphics(pDC->m_hDC);

		// background
		if (m_dcBk.m_hDC == NULL)
		{
			CRect rect1;
			CClientDC clDC(GetParent());
			GetWindowRect(rect1);
			GetParent()->ScreenToClient(rect1);

			m_dcBk.CreateCompatibleDC(&clDC);
			bmp.CreateCompatibleBitmap(&clDC, rect.Width(), rect.Height());
			pOldBitmap = m_dcBk.SelectObject(&bmp);
			m_dcBk.BitBlt(0, 0, rect.Width(), rect.Height(), &clDC, rect1.left, rect1.top, SRCCOPY);
			bmp.DeleteObject();
		}

		// standard image
		if (m_dcStd.m_hDC == NULL)
		{
			PaintBk(pDC);

			InterpolationMode  interMode = graphics.GetInterpolationMode();
			graphics.SetInterpolationMode(InterpolationModeNearestNeighbor);

			int		nCalPos = 0;
			int		nWidthLeft = m_pStdLeftImage->m_pBitmap->GetWidth();
			int		nWidthRight = m_pStdRightImage->m_pBitmap->GetWidth();
			graphics.DrawImage(*m_pStdLeftImage, 0, 0, nWidthLeft, m_pStdLeftImage->m_pBitmap->GetHeight());
			nCalPos += nWidthLeft;
			graphics.DrawImage(*m_pStdCenterImage, nCalPos, 0, (m_nButtonWidth-nWidthLeft-nWidthRight)*2, m_pStdCenterImage->m_pBitmap->GetHeight());
			nCalPos += m_nButtonWidth-nWidthLeft-nWidthRight;
			graphics.DrawImage(*m_pStdRightImage, nCalPos, 0, nWidthRight, m_pStdRightImage->m_pBitmap->GetHeight());
			graphics.SetInterpolationMode(interMode);

			// 글자!
			FontFamily fontFamily(L"나눔고딕");
		    Gdiplus::Font font(&fontFamily, 22, FontStyleBold, UnitPixel);
			SolidBrush brush(Color(255, 72, 72, 72));
			StringFormat stringFormat;
			stringFormat.SetAlignment(StringAlignmentCenter);
			stringFormat.SetLineAlignment(StringAlignmentCenter);
			PointF pointF((float)m_nButtonWidth/2, (float)m_nButtonHeight/2);
			graphics.SetTextRenderingHint(TextRenderingHintAntiAliasGridFit);
			graphics.DrawString(m_strText, (INT)wcslen(m_strText), &font, pointF, &stringFormat, &brush);


			m_dcStd.CreateCompatibleDC(pDC);
			bmp.CreateCompatibleBitmap(pDC, rect.Width(), rect.Height());
			pOldBitmap = m_dcStd.SelectObject(&bmp);
			m_dcStd.BitBlt(0, 0, rect.Width(), rect.Height(), pDC, 0, 0, SRCCOPY);
			//m_dcStd.TransparentBlt(0, 0, rect.Width(), rect.Height(), pDC, 0, 0, rect.Width(), rect.Height(), RGB(255,255,255));
			bmp.DeleteObject();

			// standard image pressed
			if (m_dcStdP.m_hDC == NULL)
			{
				PaintBk(pDC);

				interMode = graphics.GetInterpolationMode();
				graphics.SetInterpolationMode(InterpolationModeNearestNeighbor);

				nCalPos = 1;
				graphics.DrawImage(*m_pStdLeftImage, nCalPos, 1, nWidthLeft, m_pStdLeftImage->m_pBitmap->GetHeight());
				nCalPos += nWidthLeft;
				graphics.DrawImage(*m_pStdCenterImage, nCalPos, 1, 2*(m_nButtonWidth-nWidthLeft-nWidthRight), m_pStdCenterImage->m_pBitmap->GetHeight());
				nCalPos += m_nButtonWidth-nWidthLeft-nWidthRight;
				graphics.DrawImage(*m_pStdRightImage, nCalPos, 1, nWidthRight, m_pStdRightImage->m_pBitmap->GetHeight());
				graphics.SetInterpolationMode(interMode);

				// 글자!
				FontFamily fontFamily(L"나눔고딕");
				Gdiplus::Font font(&fontFamily, 22, FontStyleBold, UnitPixel);
				SolidBrush brush(Color(255, 0, 0, 255));
				StringFormat stringFormat;
				stringFormat.SetAlignment(StringAlignmentCenter);
				stringFormat.SetLineAlignment(StringAlignmentCenter);
				PointF pointF((float)m_nButtonWidth/2, (float)m_nButtonHeight/2);
				graphics.DrawString(m_strText, (INT)wcslen(m_strText), &font, pointF, &stringFormat, &brush);

				m_dcStdP.CreateCompatibleDC(pDC);
				bmp.CreateCompatibleBitmap(pDC, rect.Width(), rect.Height());
				pOldBitmap = m_dcStdP.SelectObject(&bmp);
				m_dcStdP.BitBlt(0, 0, rect.Width(), rect.Height(), pDC, 0, 0, SRCCOPY);
				bmp.DeleteObject();
			}

			// standard image hot
			if(m_dcStdH.m_hDC == NULL)
			{
				PaintBk(pDC);

				ColorMatrix HotMat = {	1.05f, 0.00f, 0.00f, 0.00f, 0.00f,
										0.00f, 1.05f, 0.00f, 0.00f, 0.00f,
										0.00f, 0.00f, 1.05f, 0.00f, 0.00f,
										0.00f, 0.00f, 0.00f, 1.00f, 0.00f,
										0.05f, 0.05f, 0.05f, 0.00f, 1.00f	};

				ImageAttributes ia;
				ia.SetColorMatrix(&HotMat);

				float width = (float)m_nButtonWidth;
				float height = (float)m_nButtonHeight;

				RectF grect; grect.X=0, grect.Y=0; grect.Width = width; grect.Height = height;

				interMode = graphics.GetInterpolationMode();
				graphics.SetInterpolationMode(InterpolationModeNearestNeighbor);

				nCalPos = 0;
				grect.Width = (float)nWidthLeft;
				graphics.DrawImage(*m_pStdLeftImage, grect, 0, 0, (float)nWidthLeft, height, UnitPixel, &ia);
				nCalPos += nWidthLeft;
				grect.X = (float)nCalPos;
				grect.Width = (float)((m_nButtonWidth-nWidthLeft-nWidthRight)*2);
				graphics.DrawImage(*m_pStdCenterImage, grect, 0, 0, 1, height, UnitPixel, &ia);
				nCalPos += m_nButtonWidth-nWidthLeft-nWidthRight;
				grect.X = (float)nCalPos;
				grect.Width = (float)nWidthRight;
				graphics.DrawImage(*m_pStdRightImage, grect, 0, 0, (float)nWidthRight, height, UnitPixel, &ia);
				graphics.SetInterpolationMode(interMode);

				// 글자!
				FontFamily fontFamily(L"나눔고딕");
				Gdiplus::Font font(&fontFamily, 22, FontStyleBold, UnitPixel);
				SolidBrush brush(Color(255, 72, 72, 72));
				StringFormat stringFormat;
				stringFormat.SetAlignment(StringAlignmentCenter);
				stringFormat.SetLineAlignment(StringAlignmentCenter);
				PointF pointF((float)m_nButtonWidth/2, (float)m_nButtonHeight/2);
				graphics.DrawString(m_strText, (INT)wcslen(m_strText), &font, pointF, &stringFormat, &brush);

				m_dcStdH.CreateCompatibleDC(pDC);
				bmp.CreateCompatibleBitmap(pDC, rect.Width(), rect.Height());
				pOldBitmap = m_dcStdH.SelectObject(&bmp);
				m_dcStdH.BitBlt(0, 0, rect.Width(), rect.Height(), pDC, 0, 0, SRCCOPY);
				bmp.DeleteObject();
			}

			// grayscale image
			if(m_dcGS.m_hDC == NULL && m_bHaveAltImage)
			{
				int		nWidthLeft = m_pAltLeftImage->m_pBitmap->GetWidth();
				int		nWidthRight = m_pAltRightImage->m_pBitmap->GetWidth();

				PaintBk(pDC);

				interMode = graphics.GetInterpolationMode();
				graphics.SetInterpolationMode(InterpolationModeNearestNeighbor);

				nCalPos = 1;
				graphics.DrawImage(*m_pAltLeftImage, nCalPos, 1, nWidthLeft, m_pAltLeftImage->m_pBitmap->GetHeight());
				nCalPos += nWidthLeft;
				graphics.DrawImage(*m_pAltCenterImage, nCalPos, 1, 2*(m_nButtonWidth-nWidthLeft-nWidthRight), m_pAltCenterImage->m_pBitmap->GetHeight());
				nCalPos += m_nButtonWidth-nWidthLeft-nWidthRight;
				graphics.DrawImage(*m_pAltRightImage, nCalPos, 1, nWidthRight, m_pAltRightImage->m_pBitmap->GetHeight());
				graphics.SetInterpolationMode(interMode);

				// 글자!
				FontFamily fontFamily(L"나눔고딕");
				Gdiplus::Font font(&fontFamily, 22, FontStyleBold, UnitPixel);
				SolidBrush brush(Color(255, 0, 0, 255));
				StringFormat stringFormat;
				stringFormat.SetAlignment(StringAlignmentCenter);
				stringFormat.SetLineAlignment(StringAlignmentCenter);
				PointF pointF((float)m_nButtonWidth/2, (float)m_nButtonHeight/2);
				graphics.DrawString(m_strText, (INT)wcslen(m_strText), &font, pointF, &stringFormat, &brush);

				m_dcGS.CreateCompatibleDC(pDC);
				bmp.CreateCompatibleBitmap(pDC, rect.Width(), rect.Height());
				pOldBitmap = m_dcGS.SelectObject(&bmp);
				m_dcGS.BitBlt(0, 0, rect.Width(), rect.Height(), pDC, 0, 0, SRCCOPY);
				bmp.DeleteObject();
			}
		}

#if 0
		// alternate image
		if( (m_dcAlt.m_hDC == NULL) && m_bHaveAltImage )
		{
			PaintBk(pDC);

		//	graphics.DrawImage(*m_pAltImage, 0, 0);
			graphics.DrawImage(*m_pAltImage, 0, 0, m_pAltImage->m_pBitmap->GetWidth(), m_pAltImage->m_pBitmap->GetHeight());
		
			m_dcAlt.CreateCompatibleDC(pDC);
			bmp.CreateCompatibleBitmap(pDC, rect.Width(), rect.Height());
			pOldBitmap = m_dcAlt.SelectObject(&bmp);
			m_dcAlt.BitBlt(0, 0, rect.Width(), rect.Height(), pDC, 0, 0, SRCCOPY);
			bmp.DeleteObject();

			// alternate image pressed
			if( (m_dcAltP.m_hDC == NULL) && m_bHaveAltImage )
			{
				PaintBk(pDC);

				// 2012.02.24 frino - Alt 영상이 커지는 문제가 발생하여 수정함
//				graphics.DrawImage(*m_pAltImage, 1, 1);
				graphics.DrawImage(*m_pAltImage, 1, 1, m_pAltImage->m_pBitmap->GetWidth(), m_pAltImage->m_pBitmap->GetHeight());
			
				m_dcAltP.CreateCompatibleDC(pDC);
				bmp.CreateCompatibleBitmap(pDC, rect.Width(), rect.Height());
				pOldBitmap = m_dcAltP.SelectObject(&bmp);
				m_dcAltP.BitBlt(0, 0, rect.Width(), rect.Height(), pDC, 0, 0, SRCCOPY);
				bmp.DeleteObject();
			}

			// alternate image hot
			if(m_dcAltH.m_hDC == NULL)
			{
				PaintBk(pDC);

				ColorMatrix HotMat = {	1.05f, 0.00f, 0.00f, 0.00f, 0.00f,
										0.00f, 1.05f, 0.00f, 0.00f, 0.00f,
										0.00f, 0.00f, 1.05f, 0.00f, 0.00f,
										0.00f, 0.00f, 0.00f, 1.00f, 0.00f,
										0.05f, 0.05f, 0.05f, 0.00f, 1.00f	};

				ImageAttributes ia;
				ia.SetColorMatrix(&HotMat);

				float width = (float)m_pAltImage->m_pBitmap->GetWidth();
				float height = (float)m_pAltImage->m_pBitmap->GetHeight();

				RectF grect; grect.X=0, grect.Y=0; grect.Width = width; grect.Height = height;

				graphics.DrawImage(*m_pAltImage, grect, 0, 0, width, height, UnitPixel, &ia);

				m_dcAltH.CreateCompatibleDC(pDC);
				bmp.CreateCompatibleBitmap(pDC, rect.Width(), rect.Height());
				pOldBitmap = m_dcAltH.SelectObject(&bmp);
				m_dcAltH.BitBlt(0, 0, rect.Width(), rect.Height(), pDC, 0, 0, SRCCOPY);
				bmp.DeleteObject();
			}
		}
#endif

		if (m_pCurBtn == NULL)
		{
			m_pCurBtn = &m_dcStd;
		}

		m_bHaveBitmaps = TRUE;
	}

	return NULL;
}
Esempio n. 20
0
//╩Ф╩╜м╪оЯ
bool CGdiPlusImage::DrawImage(CDC * pDC, INT nXPos, INT nYPos)
{
	//╪стьеп╤о
	ASSERT(m_pImage!=NULL);
	if (m_pImage==NULL) return false;

	//╢╢╫╗фад╩
	ASSERT(pDC!=NULL);
	Graphics graphics(pDC->GetSafeHdc());

	GraphicsContainer Containter = graphics.BeginContainer();
	graphics.SetSmoothingMode(SmoothingModeHighQuality);

	//╩Ях║йТпт
	INT nImageWidth=m_pImage->GetWidth();
	INT nImageHeight=m_pImage->GetHeight();

	//╧╧тЛн╩жц
	RectF rcDrawRect;
	rcDrawRect.X=0;//(REAL)nXPos;
	rcDrawRect.Y=0;//(REAL)nYPos;
	rcDrawRect.Width=(REAL)nImageWidth;
	rcDrawRect.Height=(REAL)nImageHeight;

	Matrix matrix;

	CPoint pt((nXPos+nImageWidth/2), (nYPos+nImageHeight/2));
	PointF ptBase((float)pt.x,(float)pt.y);

	//╬ьуС╠Д╩╩р╙в╒рБкЁпРё╛охф╫рфтзкУ╥е╨СпЩв╙
	matrix.Translate((REAL)nXPos,(REAL)nYPos,MatrixOrderAppend);
	
	//кУ╥е
	if ( m_szZoom.cx != 1.0f || m_szZoom.cy != 1.0f )
	{
		ptBase.X += m_szZoom.cx;
		ptBase.Y += m_szZoom.cy;

		matrix.Translate(-ptBase.X,-ptBase.Y,MatrixOrderAppend);
		matrix.Scale(m_szZoom.cx,m_szZoom.cy,MatrixOrderAppend);
		matrix.Translate(ptBase.X,ptBase.Y,MatrixOrderAppend);
	}

	//пЩв╙
	if (m_nRotateAngle)
	{
		matrix.RotateAt((REAL)m_nRotateAngle,ptBase,MatrixOrderAppend);
	}

	graphics.SetTransform(&matrix);

	//м╦цВ╬ьуС
	ColorMatrix Matrix=
	{
		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,m_cbAlphaDepth/255.0f,0.0f, 
		0.0f,0.0f,0.0f,0.0f,1.0f
	};

	//иХжцйТпт
	ImageAttributes Attributes; 
	Attributes.SetColorMatrix(&Matrix,ColorMatrixFlagsDefault,ColorAdjustTypeBitmap); 

	//╩Ф╩╜м╪оЯ
	graphics.DrawImage(m_pImage,rcDrawRect,0,0,(REAL)nImageWidth,(REAL)nImageHeight,UnitPixel,&Attributes);

	graphics.ResetTransform();

	graphics.EndContainer(Containter);

	return true;
}
Esempio n. 21
0
bool CGdiPlusImage::DrawImage(CDC* pDC)
{
    //´´½¨ÆÁÄ»
    ASSERT(pDC!=NULL); 
    if ( !pDC ) return false; 

    Bitmap bmp(m_rcDest.Width(), m_rcDest.Height()); 
    Graphics* pGraphics = Graphics::FromImage(&bmp); 
    if ( !pGraphics ) return false;

    GraphicsContainer Containter = pGraphics->BeginContainer();
    pGraphics->SetSmoothingMode(SmoothingModeHighQuality); 

    SolidBrush bgbrush(Color(238, 243, 250));
    pGraphics->FillRectangle(&bgbrush, 0, 0, m_rcDest.Width(), m_rcDest.Height());
    
    if ( m_pImage )
    {
        //»ñÈ¡ÊôÐÔ 
        INT nImageWidth  = m_pImage->GetWidth();
        INT nImageHeight = m_pImage->GetHeight(); 


        float fMin = 1.0F; 
        float fZoomRate = 1.0F; 
        bool bZoomOut = false; 
        int nXSrc = 0;
        int nYSrc = 0; 

        if ( nImageWidth >= m_rcDest.Width() || nImageHeight >= m_rcDest.Height() )
        { 
            float fXRate = 1.0F * m_rcDest.Width() / nImageWidth;
            float fYRate = 1.0F * m_rcDest.Height() / nImageHeight;
            fMin = min(fXRate, fYRate);   
            fZoomRate = max(nImageWidth * 1.0F / m_rcDest.Width(), nImageHeight * 1.0F / m_rcDest.Height()); 
            bZoomOut = true;
        } 


        int nDestWidth  = fMin * nImageWidth;
        int nDestHeight = fMin * nImageHeight;


        //¹¹ÔìλÖÃ
        RectF rcDrawRect;  
        rcDrawRect.X = m_rcDest.left + (m_rcDest.Width() - nDestWidth ) / 2;   
        rcDrawRect.Y = m_rcDest.top + (m_rcDest.Height() - nDestHeight ) / 2; 
        rcDrawRect.Width = nDestWidth;
        rcDrawRect.Height = nDestHeight; 

        Matrix matrix;

        CPoint pt(m_rcDest.Width() / 2, m_rcDest.Height() / 2);
        PointF ptBase((float)pt.x, (float)pt.y);  

        //¾ØÕó±ä»»Òª×¢Òâ˳Ðò£¬ÏÈƽÒÆÔÚËõ·ÅºóÐýת
        matrix.Translate((REAL)m_rcDest.left,(REAL)m_rcDest.top,MatrixOrderAppend);

        //Ëõ·Å
        if ( m_szZoom.cx != 1.0f || m_szZoom.cy != 1.0f )
        {
            ptBase.X += m_szZoom.cx;
            ptBase.Y += m_szZoom.cy;

            matrix.Translate(-ptBase.X,-ptBase.Y,MatrixOrderAppend);
            matrix.Scale(m_szZoom.cx,m_szZoom.cy,MatrixOrderAppend);
            matrix.Translate(ptBase.X,ptBase.Y,MatrixOrderAppend);
        }

        //Ðýת
        if (m_nRotateAngle)
        {
            matrix.RotateAt((REAL)m_nRotateAngle,ptBase,MatrixOrderAppend);
        }

        pGraphics->SetTransform(&matrix);

        //͸Ã÷¾ØÕó
        ColorMatrix Matrix=
        {
            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,m_cbAlphaDepth/255.0f,0.0f, 
            0.0f,0.0f,0.0f,0.0f,1.0f
        };

        //ÉèÖÃÊôÐÔ
        ImageAttributes Attributes; 
        Attributes.SetColorMatrix(&Matrix,ColorMatrixFlagsDefault,ColorAdjustTypeBitmap); 

        //»æ»­Í¼Ïñ
        pGraphics->DrawImage(m_pImage, rcDrawRect, nXSrc, nYSrc, (REAL)nImageWidth - nXSrc * 2, (REAL)nImageHeight - nYSrc * 2, UnitPixel,&Attributes);  
        pGraphics->ResetTransform();   
        pGraphics->EndContainer(Containter);

    } // if ( m_pImage )
   
    // ´ÓÄڴ濽±´ÖÁÉ豸
    Graphics graphicsreal(pDC->GetSafeHdc()); 
    graphicsreal.DrawImage(&bmp, 0, 0, m_rcDest.Width(), m_rcDest.Height()); 
    delete pGraphics;
    pGraphics = NULL;

    return true;
}
Esempio n. 22
0
HBITMAP renderer::GetThumbnail()
{
    //Calculate icon size
    int iconsize = height;

    if (m_Settings.AsIcon)
    {
        if (width < iconsize)
            iconsize = width;        
        iconsize = (m_Settings.IconSize * iconsize) / 100;
        iconsize -= 2;
    }

    //Calculate Alpha blend based on Transparency
    float fBlend = (100-m_Settings.BG_Transparency)/100.0;

    ColorMatrix BitmapMatrix =	{     
        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, fBlend, 0.0f,
        0.0f, 0.0f, 0.0f, 0.0f, 1.0f
    };

    bool tempfail = fail;
    int iconposition = m_Settings.IconPosition;

    // Draw background if not valid
    if (!background)
    {      
        if (m_Settings.Shrinkframe)
        {
            if (iconposition == IP_LOWERLEFT)
            {
                iconposition = IP_UPPERLEFT;
            }
            else if (m_Settings.IconPosition == IP_LOWERRIGHT)
            {
                iconposition = IP_UPPERRIGHT;
            }
        }

        no_icon = false;                
        fail = false;
        background = new Bitmap(width, height, PixelFormat32bppPARGB);

        switch (tempfail ? m_Settings.Revertto : m_Settings.Thumbnailbackground)
        {
        case BG_TRANSPARENT:
            no_icon = true;
            break;

        case BG_ALBUMART:
            {
                // get album art
                if (!m_albumart.getAA(m_metadata.getFileName(), background, 
                    width, height, iconsize) &&
                    m_Settings.Revertto != BG_ALBUMART)
                {
                    // fallback
                    fail = true;
                    ClearBackground();                            
                    GetThumbnail();
                }
                else
                {
                    m_iconwidth = iconsize;
                    m_iconheight = iconsize;
                }
            }
            break;

        case BG_CUSTOM:
            if (!m_Settings.BGPath.empty())
            {
                if (custom_img == NULL)
                {
                    custom_img = new Bitmap(width, height, PixelFormat32bppPARGB);                       

                    Image img(m_Settings.BGPath.c_str(), true);

                    if (img.GetType() != 0)
                    {
                        Graphics gfx(custom_img);
                        gfx.SetInterpolationMode(InterpolationModeBicubic);
                        float img_width = img.GetWidth();
                        float img_height = img.GetHeight();

                        if (m_Settings.AsIcon)
                        {
                            float new_height = 0;
                            float new_width = 0;

                            if (img_width > img_height)
                            {
                                new_height = img_height / img_width * (float)iconsize;
                                new_height -= 2;
                                new_width = iconsize;
                            }
                            else
                            {
                                new_width = img_width / img_height * (float)iconsize;
                                new_width -= 2;
                                new_height = iconsize;
                            }

                            int iconleft = 0, icontop = 0;

                            switch (iconposition)
                            {
                            case IP_LOWERLEFT:
                                icontop = height - iconsize - 2;
                                break;
                            case IP_UPPERRIGHT:
                                iconleft = width - iconsize - 2;
                                break;
                            case IP_LOWERRIGHT:
                                iconleft = width - iconsize - 2;
                                icontop = height - iconsize - 2;
                                break;
                            }            

                            if (m_Settings.BG_Transparency == 0)
                            {
                                // Draw icon shadow
                                gfx.SetSmoothingMode(SmoothingModeAntiAlias);
                                gfx.FillRectangle(&SolidBrush(Color::MakeARGB(110, 0, 0, 0)),
                                    static_cast<REAL>(iconleft + 1), static_cast<REAL>(icontop + 1), 
                                    static_cast<REAL>(new_width + 1), static_cast<REAL>(new_height + 1));

                                // Draw icon
                                gfx.SetSmoothingMode(SmoothingModeNone);
                                gfx.DrawImage(&img,
                                    RectF(static_cast<REAL>(iconleft), static_cast<REAL>(icontop), 
                                    static_cast<REAL>(new_width), static_cast<REAL>(new_height)));
                            }
                            else
                            {
                                ImageAttributes ImgAttr;
                                ImgAttr.SetColorMatrix(&BitmapMatrix, 
                                    ColorMatrixFlagsDefault, 
                                    ColorAdjustTypeBitmap);

                                // Draw icon shadow
                                gfx.SetSmoothingMode(SmoothingModeAntiAlias);
                                gfx.FillRectangle(&SolidBrush(Color::MakeARGB(110 - m_Settings.BG_Transparency, 0, 0, 0)),
                                    static_cast<REAL>(iconleft + 1), static_cast<REAL>(icontop + 1), 
                                    static_cast<REAL>(new_width + 1), static_cast<REAL>(new_height + 1));

                                // Draw icon
                                gfx.SetSmoothingMode(SmoothingModeNone);
                                gfx.DrawImage(&img,
                                    RectF(static_cast<REAL>(iconleft), static_cast<REAL>(icontop), 
                                    static_cast<REAL>(new_width), static_cast<REAL>(new_height)),
                                    0, 0, img_width, img_height,
                                    UnitPixel, &ImgAttr);
                            }

                            m_iconwidth = new_width;
                            m_iconheight = new_height;
                        }
                        else
                        {
                            float new_height = 0;
                            float new_width = 0;

                            if (width > height)
                            {
                                new_height = img_height / img_width * (float)width;                            
                                new_width = width;

                                if (new_height > height)
                                {
                                    new_width = img_width / img_height * (float)height;                         
                                    new_height = height;
                                }

                            }
                            else
                            {
                                new_width = img_width / img_height * (float)height;                         
                                new_height = height;

                                if (new_width > width)
                                {
                                    new_height = img_height / img_width * (float)width;                            
                                    new_width = width;
                                }
                            }

                            gfx.SetSmoothingMode(SmoothingModeNone);

                            if (m_Settings.BG_Transparency == 0)
                            {
                                gfx.DrawImage(&img, RectF((width / 2) - (new_width/2), 0, 
                                    static_cast<REAL>(new_width), static_cast<REAL>(new_height)));
                            }
                            else
                            {
                                ImageAttributes ImgAttr;
                                ImgAttr.SetColorMatrix(&BitmapMatrix, 
                                    ColorMatrixFlagsDefault, 
                                    ColorAdjustTypeBitmap);

                                gfx.SetSmoothingMode(SmoothingModeNone);
                                gfx.DrawImage(&img, RectF((width / 2) - (new_width/2), 0, static_cast<REAL>(new_width), static_cast<REAL>(new_height)),
                                    0, 0, img_width, img_height,
                                    UnitPixel, &ImgAttr);
                            }
                        }
                    }
                    else if (m_Settings.Revertto != BG_CUSTOM)
                    {
                        fail = true;
                        ClearBackground();
                        GetThumbnail();
                    }	                   
                }       

                delete background;
                background = (Bitmap*)custom_img->Clone();                
            }
            else if (m_Settings.Revertto != BG_CUSTOM)
            {		
                fail = true;
                ClearBackground();
                GetThumbnail();
            }
            break;	

        default:
            {
                fail = true;
                ClearBackground();
                GetThumbnail();                
            }
            break;
        }
    }

    if (tempfail)
    {
        return NULL;
    }

    REAL textheight = 0;
    Bitmap *canvas = background->Clone(0, 0, background->GetWidth(), background->GetHeight(), PixelFormat32bppPARGB);
    Graphics gfx(canvas);

    if (m_Settings.Text.empty())
    {
        Pen p(Color::MakeARGB(1, 255, 255, 255), 0.1);
        gfx.DrawLine(&p, 0, 0, 1, 1);
        textheight = m_iconheight + 10; 
    }
    else
    {
        // Draw text
        static lines text_parser(m_Settings, m_metadata, m_hwnd);
        text_parser.Parse();

        if (m_textpositions.empty())
        {
            m_textpositions.resize(text_parser.GetNumberOfLines(), 0);
        }
        else
        {
            for (std::vector<int>::size_type i = 0; i != m_textpositions.size(); ++i)
            {
                if (m_textpositions[i] != 0)
                {
                    m_textpositions[i] -= 2;
                }
                else
                {
                    if (scroll_block)
                    {
                        bool unblock = true;

                        for (std::vector<int>::size_type j = 0; j != m_textpositions.size(); ++j)
                        {
                            if (m_textpositions[j] < 0)
                            {
                                unblock = false;
                                break;
                            }                                
                        }

                        scroll_block = !unblock;
                        m_textpause = 60;
                    }

                    if (!scroll_block && m_textpause == 0)
                    {
                        m_textpositions[i] -= 2;
                    }
                }
            }
        }

        // Setup fonts	    
        HDC h_gfx = gfx.GetHDC();	    
        Font font(h_gfx, &m_Settings.font);

        LOGFONT large_font = {};
        large_font = m_Settings.font;	    

        LONG large_size = -((m_Settings.font.lfHeight * 72) / GetDeviceCaps(h_gfx, LOGPIXELSY));
        large_size += 4;
        large_font.lfHeight = -MulDiv(large_size, GetDeviceCaps(h_gfx, LOGPIXELSY), 72);
        Font largefont(h_gfx, &large_font);

        gfx.ReleaseHDC(h_gfx);

        SolidBrush bgcolor(Color(GetRValue(m_Settings.bgcolor), GetGValue(m_Settings.bgcolor), GetBValue(m_Settings.bgcolor)));
        SolidBrush fgcolor(Color(GetRValue(m_Settings.text_color), GetGValue(m_Settings.text_color), GetBValue(m_Settings.text_color)));

        StringFormat sf(StringFormatFlagsNoWrap);
        const int text_space = 28;

        for (std::size_t text_index = 0; text_index != text_parser.GetNumberOfLines(); ++text_index)
        {
            RectF ret_rect;
            std::wstring current_text = text_parser.GetLineText(text_index);
            linesettings current_settings = text_parser.GetLineSettings(text_index);

            // Measure size
            gfx.SetTextRenderingHint(TextRenderingHintAntiAlias);
            if (current_settings.largefont)
                gfx.MeasureString(current_text.c_str(), -1, &largefont, RectF(0, 0, 2000, 1000), &sf, &ret_rect);
            else
                gfx.MeasureString(current_text.c_str(), -1, &font, RectF(0, 0, 2000, 1000), &sf, &ret_rect);

            if (ret_rect.GetBottom() == 0)
            {
                if (current_text.empty())
                {
                    gfx.MeasureString(L"QWEXCyjM", -1, &font, RectF(0, 0, static_cast<REAL>(width), static_cast<REAL>(height)), &sf, &ret_rect);			
                }
                else
                {
                    gfx.MeasureString(L"QWEXCyjM", -1, &Font(L"Segoe UI", 14), RectF(0, 0, static_cast<REAL>(width), static_cast<REAL>(height)), &sf, &ret_rect);			
                }
            }

            Bitmap text_bitmap(ret_rect.GetRight(), ret_rect.GetBottom() - 1, PixelFormat32bppPARGB);
            Graphics text_gfx(&text_bitmap);

            // Graphics setup
            text_gfx.SetSmoothingMode(SmoothingModeNone);
            text_gfx.SetInterpolationMode(InterpolationModeNearestNeighbor);
            text_gfx.SetPixelOffsetMode(PixelOffsetModeNone);
            text_gfx.SetCompositingQuality(CompositingQualityHighSpeed);

            (m_Settings.Antialias) ? text_gfx.SetTextRenderingHint(TextRenderingHintAntiAlias) : 
                text_gfx.SetTextRenderingHint(TextRenderingHintSingleBitPerPixelGridFit);

            // Draw box if needed
            if (current_settings.darkbox && !current_text.empty())
            {
                SolidBrush boxbrush(Color::MakeARGB(120, GetRValue(m_Settings.bgcolor),
                    GetGValue(m_Settings.bgcolor), GetBValue(m_Settings.bgcolor)));

                ret_rect.Height += 2;
                text_gfx.FillRectangle(&boxbrush, ret_rect);
            }

            text_gfx.SetTextContrast(120);

            // Draw text to offscreen surface

            //shadow
            if (current_settings.shadow)
            {
                text_gfx.DrawString(current_text.c_str(), -1, 
                    current_settings.largefont ? &largefont : &font, 
                    PointF(1, -1), &bgcolor);
            }

            //text
            text_gfx.DrawString(current_text.c_str(), -1, 
                current_settings.largefont ? &largefont : &font, 
                PointF(0, -2), &fgcolor);

            // Calculate text position
            int X = 0, CX = width;

            if (m_iconwidth == 0)
            {
                m_iconwidth = iconsize;
            }

            if (m_iconheight == 0)
            {
                m_iconheight = iconsize;
            }

            if (m_Settings.AsIcon && !no_icon && !current_settings.forceleft)
            {
                if ( (iconposition == IP_UPPERLEFT || 
                    iconposition == IP_LOWERLEFT) &&
                    !current_settings.forceleft )
                {
                    X += m_iconwidth + 5;
                    CX = width - X;
                }
                else if ( iconposition == IP_UPPERRIGHT || 
                    iconposition == IP_LOWERRIGHT )
                {
                    CX = width - m_iconwidth - 5;
                }
            }

            gfx.SetClip(RectF(X, 0, CX, width), CombineModeReplace);

            // Draw text bitmap to final bitmap
            if (text_bitmap.GetWidth() > CX + 2 && !current_settings.dontscroll)// && m_textpause[text_index] == 0)
            {
                // Draw scrolling text
                int left = m_textpositions[text_index];
                int bmp_width = (int)text_bitmap.GetWidth();
                int bmp_height = (int)text_bitmap.GetHeight();

                if (left + bmp_width < 0)
                {
                    // reset text
                    m_textpositions[text_index] = text_space;
                    left = text_space;
                    scroll_block = true;
                }

                if (left == 0 && m_textpause == 0)
                {
                    m_textpause = 60; // delay; in steps
                }

                if (left + bmp_width >= CX)
                {
                    gfx.DrawImage(&text_bitmap, X, (int)textheight, -left, 0, CX, bmp_height, UnitPixel);
                }
                else
                {
                    gfx.DrawImage(&text_bitmap, X, (int)textheight, -left, 0, bmp_width + left,
                        bmp_height, UnitPixel);

                    gfx.DrawImage(&text_bitmap, X + text_space + 2 + bmp_width + left, (int)textheight, 0, 0,
                        -left, bmp_height, UnitPixel);
                }
            }
            else
            {
                // Draw non-scrolling text
                if (current_settings.center)
                {
                    // Center text
                    int newleft = X + ((CX / 2) - (text_bitmap.GetWidth() / 2));
                    gfx.DrawImage(&text_bitmap, newleft, (int)textheight, 0, 0, text_bitmap.GetWidth(), text_bitmap.GetHeight(), UnitPixel);          
                }
                else
                {
                    gfx.DrawImage(&text_bitmap, X, (int)textheight, 0, 0, text_bitmap.GetWidth(), text_bitmap.GetHeight(), UnitPixel);          
                }

                m_textpositions[text_index] = 2; // Nr. pixels text jumps on each step when scrolling
            }

            gfx.ResetClip();

            textheight += text_bitmap.GetHeight();
        }

        if (m_textpause > 0)
        {
            --m_textpause;
        }

        if (!m_Settings.Shrinkframe)	
            textheight = height-2;

        if (m_Settings.Thumbnailpb)
            textheight += 25;

        if (textheight > height-2)
            textheight = height-2;
    }

    // Draw progressbar
    if (m_Settings.Thumbnailpb && m_Settings.play_total > 0)// && m_Settings.play_current >0)
    {
        gfx.SetSmoothingMode(SmoothingModeAntiAlias);		
        int Y = canvas->GetHeight()-10;
        if (m_Settings.Shrinkframe)
        {
            Y = textheight - 10;
        }
        Pen p1(Color::White, 1);
        Pen p2(Color::MakeARGB(80, 0, 0, 0), 1);

        SolidBrush b1(Color::MakeARGB(50, 0, 0, 0));	
        SolidBrush b2(Color::MakeARGB(220, 255, 255, 255));

        RectF R1(44, (REAL)Y, 10, 9);
        RectF R2((REAL)width - 56, (REAL)Y, 10, 9);

        gfx.FillRectangle(&b1, 46, Y, width-94, 9);
        gfx.DrawLine(&p2, 46, Y+2, 46, Y+6);
        gfx.DrawLine(&p2, width-48, Y+2, width-48, Y+6);

        gfx.DrawArc(&p1, R1, -90.0f, -180.0f);
        gfx.DrawArc(&p1, R2, 90.0f, -180.0f);

        gfx.DrawLine(&p1, 48, Y, width-49, Y);
        gfx.DrawLine(&p1, 48, Y+9, width-49, Y+9);

        gfx.SetSmoothingMode(SmoothingModeDefault);
        gfx.FillRectangle(&b2, 48, Y+3, (m_Settings.play_current*(width-96))/m_Settings.play_total, 4);
    }

    // finalize / garbage    
    HBITMAP retbmp;

    if (!m_Settings.Shrinkframe)
    {
        canvas->GetHBITMAP(NULL, &retbmp);        
    }
    else
    {
        Bitmap *shrink = canvas->Clone(0, 0, (int)width, 
            textheight > m_iconheight ? (int)textheight : (int)m_iconheight, PixelFormat32bppPARGB);
        shrink->GetHBITMAP(NULL, &retbmp);
        delete shrink;
    }

    delete canvas;
    return retbmp;
}
Esempio n. 23
0
//=============================================================================
//
//	The framework calls this member function when a child control is about to 
//	be drawn.  All the bitmaps are created here on the first call. Every thing
//	is done with a memory DC except the background, which get's it's information 
//	from the parent. The background is needed for transparent portions of PNG 
//	images. An always on top app (such as Task Manager) that is in the way can 
//	cause it to get an incorrect background.  To avoid this, the parent should 
//	call the SetBkGnd function with a memory DC when it creates the background.
//				
//=============================================================================
HBRUSH CGdipButton::CtlColor(CDC* pScreenDC, UINT nCtlColor) 
{
	if(!m_bHaveBitmaps)
	{
		if(!m_pStdImage)
		{
			return NULL; // Load the standard image with LoadStdImage()
		}

		CBitmap bmp, *pOldBitmap;

		CRect rect;
		GetClientRect(rect);

		// do everything with mem dc
		CMemDC pDC(pScreenDC, rect);

		Gdiplus::Graphics graphics(pDC->m_hDC);

		// background
		if (m_dcBk.m_hDC == NULL)
		{

			CRect rect1;
			CClientDC clDC(GetParent());
			GetWindowRect(rect1);
			GetParent()->ScreenToClient(rect1);

			m_dcBk.CreateCompatibleDC(&clDC);
			bmp.CreateCompatibleBitmap(&clDC, rect.Width(), rect.Height());
			pOldBitmap = m_dcBk.SelectObject(&bmp);
			m_dcBk.BitBlt(0, 0, rect.Width(), rect.Height(), &clDC, rect1.left, rect1.top, SRCCOPY);
			bmp.DeleteObject();
		}

		// standard image
		if (m_dcStd.m_hDC == NULL)
		{
			PaintBk(pDC);

			graphics.DrawImage(*m_pStdImage, 0, 0);
		
			m_dcStd.CreateCompatibleDC(pDC);
			bmp.CreateCompatibleBitmap(pDC, rect.Width(), rect.Height());
			pOldBitmap = m_dcStd.SelectObject(&bmp);
			m_dcStd.BitBlt(0, 0, rect.Width(), rect.Height(), pDC, 0, 0, SRCCOPY);
			bmp.DeleteObject();

			// standard image pressed
			if (m_dcStdP.m_hDC == NULL)
			{
				PaintBk(pDC);

				graphics.DrawImage(*m_pStdImage, 1, 1);

				m_dcStdP.CreateCompatibleDC(pDC);
				bmp.CreateCompatibleBitmap(pDC, rect.Width(), rect.Height());
				pOldBitmap = m_dcStdP.SelectObject(&bmp);
				m_dcStdP.BitBlt(0, 0, rect.Width(), rect.Height(), pDC, 0, 0, SRCCOPY);
				bmp.DeleteObject();
			}

			// standard image hot
			if(m_dcStdH.m_hDC == NULL)
			{
				PaintBk(pDC);

				ColorMatrix HotMat = {	1.05f, 0.00f, 0.00f, 0.00f, 0.00f,
										0.00f, 1.05f, 0.00f, 0.00f, 0.00f,
										0.00f, 0.00f, 1.05f, 0.00f, 0.00f,
										0.00f, 0.00f, 0.00f, 1.00f, 0.00f,
										0.05f, 0.05f, 0.05f, 0.00f, 1.00f	};

				ImageAttributes ia;
				ia.SetColorMatrix(&HotMat);

				float width = (float)m_pStdImage->m_pBitmap->GetWidth();
				float height = (float)m_pStdImage->m_pBitmap->GetHeight();

				RectF grect; grect.X=0, grect.Y=0; grect.Width = width; grect.Height = height;

				graphics.DrawImage(*m_pStdImage, grect, 0, 0, width, height, UnitPixel, &ia);

				m_dcStdH.CreateCompatibleDC(pDC);
				bmp.CreateCompatibleBitmap(pDC, rect.Width(), rect.Height());
				pOldBitmap = m_dcStdH.SelectObject(&bmp);
				m_dcStdH.BitBlt(0, 0, rect.Width(), rect.Height(), pDC, 0, 0, SRCCOPY);
				bmp.DeleteObject();
			}

			// grayscale image
			if(m_dcGS.m_hDC == NULL)
			{
				PaintBk(pDC);

				ColorMatrix GrayMat = {	0.30f, 0.30f, 0.30f, 0.00f, 0.00f,
										0.59f, 0.59f, 0.59f, 0.00f, 0.00f,
										0.11f, 0.11f, 0.11f, 0.00f, 0.00f,
										0.00f, 0.00f, 0.00f, 1.00f, 0.00f,
										0.00f, 0.00f, 0.00f, 0.00f, 1.00f	};

				ImageAttributes ia;
				ia.SetColorMatrix(&GrayMat);

				float width = (float)m_pStdImage->m_pBitmap->GetWidth();
				float height = (float)m_pStdImage->m_pBitmap->GetHeight();

				RectF grect; grect.X=0, grect.Y=0; grect.Width = width; grect.Height = height;

				graphics.DrawImage(*m_pStdImage, grect, 0, 0, width, height, UnitPixel, &ia);

				m_dcGS.CreateCompatibleDC(pDC);
				bmp.CreateCompatibleBitmap(pDC, rect.Width(), rect.Height());
				pOldBitmap = m_dcGS.SelectObject(&bmp);
				m_dcGS.BitBlt(0, 0, rect.Width(), rect.Height(), pDC, 0, 0, SRCCOPY);
				bmp.DeleteObject();
			}
		}

		// alternate image
		if( (m_dcAlt.m_hDC == NULL) && m_bHaveAltImage )
		{
			PaintBk(pDC);

			graphics.DrawImage(*m_pAltImage, 0, 0);
		
			m_dcAlt.CreateCompatibleDC(pDC);
			bmp.CreateCompatibleBitmap(pDC, rect.Width(), rect.Height());
			pOldBitmap = m_dcAlt.SelectObject(&bmp);
			m_dcAlt.BitBlt(0, 0, rect.Width(), rect.Height(), pDC, 0, 0, SRCCOPY);
			bmp.DeleteObject();

			// alternate image pressed
			if( (m_dcAltP.m_hDC == NULL) && m_bHaveAltImage )
			{
				PaintBk(pDC);

				graphics.DrawImage(*m_pAltImage, 1, 1);
			
				m_dcAltP.CreateCompatibleDC(pDC);
				bmp.CreateCompatibleBitmap(pDC, rect.Width(), rect.Height());
				pOldBitmap = m_dcAltP.SelectObject(&bmp);
				m_dcAltP.BitBlt(0, 0, rect.Width(), rect.Height(), pDC, 0, 0, SRCCOPY);
				bmp.DeleteObject();
			}

			// alternate image hot
			if(m_dcAltH.m_hDC == NULL)
			{
				PaintBk(pDC);

				ColorMatrix HotMat = {	1.05f, 0.00f, 0.00f, 0.00f, 0.00f,
										0.00f, 1.05f, 0.00f, 0.00f, 0.00f,
										0.00f, 0.00f, 1.05f, 0.00f, 0.00f,
										0.00f, 0.00f, 0.00f, 1.00f, 0.00f,
										0.05f, 0.05f, 0.05f, 0.00f, 1.00f	};

				ImageAttributes ia;
				ia.SetColorMatrix(&HotMat);

				float width = (float)m_pStdImage->m_pBitmap->GetWidth();
				float height = (float)m_pStdImage->m_pBitmap->GetHeight();

				RectF grect; grect.X=0, grect.Y=0; grect.Width = width; grect.Height = height;

				graphics.DrawImage(*m_pAltImage, grect, 0, 0, width, height, UnitPixel, &ia);

				m_dcAltH.CreateCompatibleDC(pDC);
				bmp.CreateCompatibleBitmap(pDC, rect.Width(), rect.Height());
				pOldBitmap = m_dcAltH.SelectObject(&bmp);
				m_dcAltH.BitBlt(0, 0, rect.Width(), rect.Height(), pDC, 0, 0, SRCCOPY);
				bmp.DeleteObject();
			}
		}

		if(m_pCurBtn == NULL)
		{
			m_pCurBtn = &m_dcStd;
		}

		m_bHaveBitmaps = TRUE;
	}

	return NULL;
}
Esempio n. 24
0
void showInfo(HWND hDlg, PLUGIN_DATA *data, int selected)
{
	int size = 128;

	// Load the background image
	CGdiPlusBitmapResource* image = new CGdiPlusBitmapResource();
	image->Load(IDB_BACKGROUND, _T("PNG"), dllInstance);

	if (image->m_pBitmap != NULL) {
		// Get the background color
		Color* background = new Color();
		background->SetFromCOLORREF(GetSysColor(COLOR_BTNFACE));

		// Create the bitmap
		Bitmap bitmap(size+64,size+64);
		Graphics bitmapGraphics(&bitmap);
		SolidBrush solidBrush(*background);
		bitmapGraphics.FillRectangle(&solidBrush, 0, 0, image->m_pBitmap->GetHeight()+64, image->m_pBitmap->GetWidth()+64);

		// Apply color transformation and draw the icon
		RectF rect(0.0f, 0.0f, (REAL)size+64, (REAL)size+64);
		ImageAttributes attributes;
		ColorMatrix colorMatrix = {
				0.45f, 0.33f, 0.33f, 0.0f, 0.0f,
				0.33f, 0.33f, 0.33f, 0.0f, 0.0f,
				0.33f, 0.33f, 0.33f, 0.0f, 0.0f,
				0.0f, 0.0f, 0.0f, 0.1f, 0.0f,
				0.0f, 0.0f, 0.0f, 0.0f, 1.0f};

		attributes.SetColorMatrix(&colorMatrix, ColorMatrixFlagsDefault, ColorAdjustTypeDefault);
		bitmapGraphics.DrawImage(image->m_pBitmap, rect, 0, 0, (REAL)image->m_pBitmap->GetHeight(), (REAL)image->m_pBitmap->GetWidth(), UnitPixel, &attributes, NULL, NULL);

		// Init Brushes & Font
		SolidBrush  blackBrush(Color(255, 0, 0, 0));
		SolidBrush  whiteBrush(Color(128, 160, 160, 160));
		FontFamily  fontFamily(L"Arial");
		Font        font(&fontFamily, 13, FontStyleBold, UnitPixel);

		// Draw the name, author, version and notes
		Docklet::DOCKLET_INFO info = Docklet::GetInformationFromDll((char*)data->docklets[selected].path);

		USES_CONVERSION;

		wchar_t name[200];
		wcscpy_s(name, L"");
		wcscat_s(name, CA2W(info.name));

		wchar_t notes[500];
		wcscpy_s(notes, L"");
		wcscat_s(notes, CA2W(info.notes));

		wchar_t author[200];
		wcscpy_s(author, L"By ");
		wcscat_s(author, CA2W(info.author));

		int major = info.version/100;
		int minor = info.version - 100*major;

		wchar_t version[40];
		wcscpy_s(version, L"");
		if (minor > 9)
			swprintf_s(version, L"Version %d.%d", major, minor);
		else
			swprintf_s(version, L"Version %d.0%d", major, minor);

		////////////////////////////////////////////////////////////////////////////
		bitmapGraphics.DrawString((WCHAR *)&name, -1, &font, PointF(1.0f, 1.0f), &whiteBrush);
		bitmapGraphics.DrawString((WCHAR *)&name, -1, &font, PointF(0.0f, 0.0f), &blackBrush);

		bitmapGraphics.DrawString((WCHAR *)&author, -1, &font, PointF(1.0f, 21.0f), &whiteBrush);
		bitmapGraphics.DrawString((WCHAR *)&author, -1, &font, PointF(0.0f, 20.0f), &blackBrush);

		bitmapGraphics.DrawString((WCHAR *)&version, -1, &font, PointF(1.0f, 41.0f), &whiteBrush);
		bitmapGraphics.DrawString((WCHAR *)&version, -1, &font, PointF(0.0f, 40.0f), &blackBrush);

		RectF rect1(1.0f, 101.0f, 200.0f, 200.0f);
		RectF rect2(0.0f, 100.0f, 200.0f, 200.0f);
		bitmapGraphics.DrawString((WCHAR *)&notes, -1, &font, rect1, StringFormat::GenericDefault(), &whiteBrush);
		bitmapGraphics.DrawString((WCHAR *)&notes, -1, &font, rect2, StringFormat::GenericDefault(), &blackBrush);
		////////////////////////////////////////////////////////////////////////////

		HBITMAP hBitmap;
		bitmap.GetHBITMAP(*background, &hBitmap);

		// Display the image
		SendDlgItemMessage(hDlg, IDC_ICON_PIC, STM_SETIMAGE, (WPARAM)IMAGE_BITMAP, (LPARAM) hBitmap);
		delete(background);
	}
	delete(image);
}