📄 ppdrawmanager.cpp
字号:
color_g = (BYTE)(GetGValue(clrColor) * darken);
color_b = (BYTE)(GetBValue(clrColor) * darken);
clrColor = RGB(color_r, color_g, color_b);
} //if
return clrColor;
} //End DarkenColor
COLORREF CPPDrawManager::LightenColor(COLORREF clrColor, double lighten)
{
if (lighten > 0.0 && lighten <= 1.0)
{
BYTE color_r, color_g, color_b;
lighten += 1.0;
color_r = (BYTE)min((DWORD)GetRValue(clrColor) * lighten, 255.0);
color_g = (BYTE)min((DWORD)GetGValue(clrColor) * lighten, 255.0);
color_b = (BYTE)min((DWORD)GetBValue(clrColor) * lighten, 255.0);
clrColor = RGB(color_r, color_g, color_b);
/*
lighten *= 255
color_r = (BYTE)max(0, min(255, (int)((color_r - 128) * 2.0 + 128 + lighten)));
color_g = (BYTE)max(0, min(255, (int)((color_g - 128) * 2.0 + 128 + lighten)));
color_b = (BYTE)max(0, min(255, (int)((color_b - 128) * 2.0 + 128 + lighten)));
clrColor = RGB(color_r, color_g, color_b);
*/
} //if
return clrColor;
} //End LightenColor
COLORREF CPPDrawManager::PixelAlpha(COLORREF clrSrc, double src_darken, COLORREF clrDest, double dest_darken)
{
return RGB (GetRValue (clrSrc) * src_darken + GetRValue (clrDest) * dest_darken,
GetGValue (clrSrc) * src_darken + GetGValue (clrDest) * dest_darken,
GetBValue (clrSrc) * src_darken + GetBValue (clrDest) * dest_darken);
} //End PixelAlpha
HICON CPPDrawManager::StretchIcon(HICON hIcon, DWORD dwWidth, DWORD dwHeight)
{
HICON hStretchedIcon = NULL;
HDC hMainDC = NULL;
HDC hSrcDC = NULL;
HDC hDestDC = NULL;
BITMAP bmp;
HBITMAP hOldSrcBitmap = NULL;
HBITMAP hOldDestBitmap = NULL;
ICONINFO csOriginal, csStretched;
if (!::GetIconInfo(hIcon, &csOriginal))
return FALSE;
hMainDC = ::GetDC(NULL);
hSrcDC = ::CreateCompatibleDC(hMainDC);
hDestDC = ::CreateCompatibleDC(hMainDC);
if ((NULL == hMainDC) || (NULL == hSrcDC) || (NULL == hDestDC))
return NULL;
if (::GetObject(csOriginal.hbmColor, sizeof(BITMAP), &bmp))
{
DWORD dwWidthOrg = csOriginal.xHotspot * 2;
DWORD dwHeightOrg = csOriginal.yHotspot * 2;
csStretched.hbmColor = ::CreateBitmap(dwWidth, dwHeight, bmp.bmPlanes, bmp.bmBitsPixel, NULL);
if (NULL != csStretched.hbmColor)
{
hOldSrcBitmap = (HBITMAP)::SelectObject(hSrcDC, csOriginal.hbmColor);
hOldDestBitmap = (HBITMAP)::SelectObject(hDestDC, csStretched.hbmColor);
::StretchBlt(hDestDC, 0, 0, dwWidth, dwHeight, hSrcDC, 0, 0, dwWidthOrg, dwHeightOrg, SRCCOPY);
if (::GetObject(csOriginal.hbmMask, sizeof(BITMAP), &bmp))
{
csStretched.hbmMask = ::CreateBitmap(dwWidth, dwHeight, bmp.bmPlanes, bmp.bmBitsPixel, NULL);
if (NULL != csStretched.hbmMask)
{
::SelectObject(hSrcDC, csOriginal.hbmMask);
::SelectObject(hDestDC, csStretched.hbmMask);
::StretchBlt(hDestDC, 0, 0, dwWidth, dwHeight, hSrcDC, 0, 0, dwWidthOrg, dwHeightOrg, SRCCOPY);
} //if
} //if
::SelectObject(hSrcDC, hOldSrcBitmap);
::SelectObject(hDestDC, hOldDestBitmap);
csStretched.fIcon = TRUE;
hStretchedIcon = ::CreateIconIndirect(&csStretched);
} //if
::DeleteObject(csStretched.hbmColor);
::DeleteObject(csStretched.hbmMask);
} //if
::DeleteObject(csOriginal.hbmColor);
::DeleteObject(csOriginal.hbmMask);
::DeleteDC(hSrcDC);
::DeleteDC(hDestDC);
::ReleaseDC(NULL, hMainDC);
return hStretchedIcon;
} //End StretchIcon
void CPPDrawManager::FillGradient (HDC hDC, LPCRECT lpRect,
COLORREF colorStart, COLORREF colorFinish,
BOOL bHorz/* = TRUE*/)
{
// this will make 2^6 = 64 fountain steps
int nShift = 6;
int nSteps = 1 << nShift;
RECT r2;
r2.top = lpRect->top;
r2.left = lpRect->left;
r2.right = lpRect->right;
r2.bottom = lpRect->bottom;
int nHeight = lpRect->bottom - lpRect->top;
int nWidth = lpRect->right - lpRect->left;
for (int i = 0; i < nSteps; i++)
{
// do a little alpha blending
BYTE bR = (BYTE) ((GetRValue(colorStart) * (nSteps - i) +
GetRValue(colorFinish) * i) >> nShift);
BYTE bG = (BYTE) ((GetGValue(colorStart) * (nSteps - i) +
GetGValue(colorFinish) * i) >> nShift);
BYTE bB = (BYTE) ((GetBValue(colorStart) * (nSteps - i) +
GetBValue(colorFinish) * i) >> nShift);
HBRUSH hBrush = ::CreateSolidBrush(RGB(bR, bG, bB));
// then paint with the resulting color
if (!bHorz)
{
r2.top = lpRect->top + ((i * nHeight) >> nShift);
r2.bottom = lpRect->top + (((i + 1) * nHeight) >> nShift);
if ((r2.bottom - r2.top) > 0)
::FillRect(hDC, &r2, hBrush);
}
else
{
r2.left = lpRect->left + ((i * nWidth) >> nShift);
r2.right = lpRect->left + (((i + 1) * nWidth) >> nShift);
if ((r2.right - r2.left) > 0)
::FillRect(hDC, &r2, hBrush);
} //if
if (NULL != hBrush)
{
::DeleteObject(hBrush);
hBrush = NULL;
} //if
} //for
} //End FillGradient
#ifdef USE_SHADE
void CPPDrawManager::SetShade(LPCRECT lpRect, UINT shadeID /* = 0 */, BYTE granularity /* = 8 */,
BYTE coloring /* = 0 */, COLORREF hicr /* = 0 */, COLORREF midcr /* = 0 */, COLORREF locr /* = 0 */)
{
long sXSize,sYSize,bytes,j,i,k,h;
BYTE *iDst ,*posDst;
sYSize = lpRect->bottom - lpRect->top;
sXSize = lpRect->right - lpRect->left;
m_dNormal.Create(sXSize,sYSize,8); //create the default bitmap
long r,g,b; //build the shaded palette
for(i = 0; i < 129; i++)
{
r=((128-i)*GetRValue(locr)+i*GetRValue(midcr))/128;
g=((128-i)*GetGValue(locr)+i*GetGValue(midcr))/128;
b=((128-i)*GetBValue(locr)+i*GetBValue(midcr))/128;
m_dNormal.SetPaletteIndex((BYTE)i,(BYTE)r,(BYTE)g,(BYTE)b);
} //for
for(i=1;i<129;i++){
r=((128-i)*GetRValue(midcr)+i*GetRValue(hicr))/128;
g=((128-i)*GetGValue(midcr)+i*GetGValue(hicr))/128;
b=((128-i)*GetBValue(midcr)+i*GetBValue(hicr))/128;
m_dNormal.SetPaletteIndex((BYTE)(i+127),(BYTE)r,(BYTE)g,(BYTE)b);
} //for
m_dNormal.BlendPalette(hicr,coloring); //color the palette
bytes = m_dNormal.GetLineWidth();
iDst = m_dNormal.GetBits();
posDst =iDst;
long a,x,y,d,xs,idxmax,idxmin;
int grainx2 = RAND_MAX/(max(1,2*granularity));
idxmax=255-granularity;
idxmin=granularity;
switch (shadeID)
{
//----------------------------------------------------
case EFFECT_METAL:
m_dNormal.Clear();
// create the strokes
k=40; //stroke granularity
for(a=0;a<200;a++){
x=rand()/(RAND_MAX/sXSize); //stroke postion
y=rand()/(RAND_MAX/sYSize); //stroke position
xs=rand()/(RAND_MAX/min(sXSize,sYSize))/2; //stroke lenght
d=rand()/(RAND_MAX/k); //stroke color
for(i=0;i<xs;i++){
if (((x-i)>0)&&((y+i)<sYSize))
m_dNormal.SetPixelIndex(x-i,y+i,(BYTE)d);
if (((x+i)<sXSize)&&((y-i)>0))
m_dNormal.SetPixelIndex(sXSize-x+i,y-i,(BYTE)d);
} //for
} //for
//blend strokes with SHS_DIAGONAL
posDst =iDst;
a=(idxmax-idxmin-k)/2;
for(i = 0; i < sYSize; i++) {
for(j = 0; j < sXSize; j++) {
d=posDst[j]+((a*i)/sYSize+(a*(sXSize-j))/sXSize);
posDst[j]=(BYTE)d;
posDst[j]+=rand()/grainx2;
} //for
posDst+=bytes;
} //for
break;
//----------------------------------------------------
case EFFECT_HARDBUMP: //
//set horizontal bump
for(i = 0; i < sYSize; i++) {
k=(255*i/sYSize)-127;
k=(k*(k*k)/128)/128;
k=(k*(128-granularity*2))/128+128;
for(j = 0; j < sXSize; j++) {
posDst[j]=(BYTE)k;
posDst[j]+=rand()/grainx2-granularity;
} //for
posDst+=bytes;
} //for
//set vertical bump
d=min(16,sXSize/6); //max edge=16
a=sYSize*sYSize/4;
posDst =iDst;
for(i = 0; i < sYSize; i++) {
y=i-sYSize/2;
for(j = 0; j < sXSize; j++) {
x=j-sXSize/2;
xs=sXSize/2-d+(y*y*d)/a;
if (x>xs) posDst[j]=(BYTE)idxmin+(BYTE)(((sXSize-j)*128)/d);
if ((x+xs)<0) posDst[j]=(BYTE)idxmax-(BYTE)((j*128)/d);
posDst[j]+=rand()/grainx2-granularity;
} //for
posDst+=bytes;
} //for
break;
//----------------------------------------------------
case EFFECT_SOFTBUMP: //
for(i = 0; i < sYSize; i++) {
h=(255*i/sYSize)-127;
for(j = 0; j < sXSize; j++) {
k=(255*(sXSize-j)/sXSize)-127;
k=(h*(h*h)/128)/128+(k*(k*k)/128)/128;
k=k*(128-granularity)/128+128;
if (k<idxmin) k=idxmin;
if (k>idxmax) k=idxmax;
posDst[j]=(BYTE)k;
posDst[j]+=rand()/grainx2-granularity;
} //for
posDst+=bytes;
} //for
break;
//----------------------------------------------------
case EFFECT_VBUMP: //
for(j = 0; j < sXSize; j++) {
k=(255*(sXSize-j)/sXSize)-127;
k=(k*(k*k)/128)/128;
k=(k*(128-granularity))/128+128;
for(i = 0; i < sYSize; i++) {
posDst[j+i*bytes]=(BYTE)k;
posDst[j+i*bytes]+=rand()/grainx2-granularity;
} //for
} //for
break;
//----------------------------------------------------
case EFFECT_HBUMP: //
for(i = 0; i < sYSize; i++) {
k=(255*i/sYSize)-127;
k=(k*(k*k)/128)/128;
k=(k*(128-granularity))/128+128;
for(j = 0; j < sXSize; j++) {
posDst[j]=(BYTE)k;
posDst[j]+=rand()/grainx2-granularity;
} //for
posDst+=bytes;
} //for
break;
//----------------------------------------------------
case EFFECT_DIAGSHADE: //
a=(idxmax-idxmin)/2;
for(i = 0; i < sYSize; i++) {
for(j = 0; j < sXSize; j++) {
posDst[j]=(BYTE)(idxmin+a*i/sYSize+a*(sXSize-j)/sXSize);
posDst[j]+=rand()/grainx2-granularity;
} //for
posDst+=bytes;
} //for
break;
//----------------------------------------------------
case EFFECT_HSHADE: //
a=idxmax-idxmin;
for(i = 0; i < sYSize; i++) {
k=a*i/sYSize+idxmin;
for(j = 0; j < sXSize; j++) {
posDst[j]=(BYTE)k;
posDst[j]+=rand()/grainx2-granularity;
} //for
posDst+=bytes;
} //for
break;
//----------------------------------------------------
case EFFECT_VSHADE: //:
a=idxmax-idxmin;
for(j = 0; j < sXSize; j++) {
k=a*(sXSize-j)/sXSize+idxmin;
for(i = 0; i < sYSize; i++) {
posDst[j+i*bytes]=(BYTE)k;
posDst[j+i*bytes]+=rand()/grainx2-granularity;
} //for
} //for
break;
//----------------------------------------------------
case EFFECT_NOISE:
for(i = 0; i < sYSize; i++) {
for(j = 0; j < sXSize; j++) {
posDst[j]=128+rand()/grainx2-granularity;
} //for
posDst+=bytes;
} //for
} //switch
//----------------------------------------------------
} //End SetShade
#endif
void CPPDrawManager::FillEffect(HDC hDC, DWORD dwEffect, LPCRECT lpRect, COLORREF clrBegin, COLORREF clrMid /* = 0 */, COLORREF clrEnd /* = 0 */, BYTE granularity /* = 0 */, BYTE coloring /* = 0 */)
{
HBRUSH hBrush = NULL;
RECT rect;
rect.left = lpRect->left;
rect.top = lpRect->top;
rect.right = lpRect->right;
rect.bottom = lpRect->bottom;
int nHeight = rect.bottom - rect.top;
int nWidth = rect.right - rect.left;
switch (dwEffect)
{
default:
hBrush = ::CreateSolidBrush(clrBegin);
::FillRect(hDC, lpRect, hBrush);
break;
case EFFECT_HGRADIENT:
FillGradient(hDC, lpRect, clrBegin, clrEnd, TRUE);
break;
case EFFECT_VGRADIENT:
FillGradient(hDC, lpRect, clrBegin, clrEnd, FALSE);
break;
case EFFECT_HCGRADIENT:
rect.right = rect.left + nWidth / 2;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -