绘制颜色渐变矩形函数
2017-07-25 12:16
459 查看
填充效果如下:
其中falg指定渐变形式:
0:左右渐变。
1:上下渐变
3:中心到左右两边渐变
4:中心到上下渐变
5:中心到四周实现渐变
void_DrawRect(CDC *pDC,CRect rect,COLORREF
nShadowBeginColor,COLORREF
nShadowEndColor,int falg )
{
TRIVERTEX rcVertex[2];
rcVertex[0].x=rect.left;
rcVertex[0].y=rect.top;
rcVertex[0].Red=GetRValue(nShadowBeginColor)<<8;
rcVertex[0].Green=GetGValue(nShadowBeginColor)<<8;
rcVertex[0].Blue=GetBValue(nShadowBeginColor)<<8;
rcVertex[0].Alpha=0x0000;
rcVertex[1].x=rect.right;
rcVertex[1].y=rect.bottom;
rcVertex[1].Red=GetRValue(nShadowEndColor)<<8;
rcVertex[1].Green=GetGValue(nShadowEndColor)<<8;
rcVertex[1].Blue=GetBValue(nShadowEndColor)<<8;
rcVertex[1].Alpha=0;
GRADIENT_RECT rect1;
rect1.UpperLeft=0;
rect1.LowerRight=1;
if (falg==0)
handle_GradientFill( pDC->GetSafeHdc
(),rcVertex,2,&rect1,1,
GRADIENT_FILL_RECT_H);
if (falg==1)
handle_GradientFill( pDC->GetSafeHdc
(),rcVertex,2,&rect1,1,
GRADIENT_FILL_RECT_V );
if (falg==3)
{
///////
Email: visualsan@yahoo.cn
rcVertex[0].x=rect.left;
rcVertex[0].y=rect.top;
rcVertex[0].Red=GetRValue(nShadowBeginColor)<<8;
rcVertex[0].Green=GetGValue(nShadowBeginColor)<<8;
rcVertex[0].Blue=GetBValue(nShadowBeginColor)<<8;
rcVertex[0].Alpha=0x0000;
rcVertex[1].x=rect.right-rect.Width()/2;
rcVertex[1].y=rect.bottom;
rcVertex[1].Red=GetRValue(nShadowEndColor)<<8;
rcVertex[1].Green=GetGValue(nShadowEndColor)<<8;
rcVertex[1].Blue=GetBValue(nShadowEndColor)<<8;
rcVertex[1].Alpha=0;
handle_GradientFill(pDC->GetSafeHdc
(),rcVertex,2,&rect1,1,
GRADIENT_FILL_RECT_H);
rcVertex[0].x=rect.left+rect.Width()/2-1;
rcVertex[0].y=rect.top;
rcVertex[0].Red=GetRValue(nShadowEndColor)<<8;
rcVertex[0].Green=GetGValue(nShadowEndColor)<<8;
rcVertex[0].Blue=GetBValue(nShadowEndColor)<<8;
rcVertex[0].Alpha=0x0000;
rcVertex[1].x=rect.right;
rcVertex[1].y=rect.bottom;
rcVertex[1].Red=GetRValue(nShadowBeginColor)<<8;
rcVertex[1].Green=GetGValue(nShadowBeginColor)<<8;
rcVertex[1].Blue=GetBValue(nShadowBeginColor)<<8;
rcVertex[1].Alpha=0;
handle_GradientFill( pDC->GetSafeHdc
(),rcVertex,2,&rect1,1,
GRADIENT_FILL_RECT_H);
}
if (falg==4)
{ ///////
Email: visualsan@yahoo.cn
rcVertex[0].x=rect.left;
rcVertex[0].y=rect.top;
rcVertex[0].Red=GetRValue(nShadowBeginColor)
<< 8;
rcVertex[0].Green=GetGValue(nShadowBeginColor)<<8;
rcVertex[0].Blue=GetBValue(nShadowBeginColor)<<8;
rcVertex[0].Alpha=0x0000;
rcVertex[1].x=rect.right;
rcVertex[1].y=rect.bottom-rect.Height()/2;
rcVertex[1].Red=GetRValue(nShadowEndColor)<<8;
rcVertex[1].Green=GetGValue(nShadowEndColor)<<8;
rcVertex[1].Blue=GetBValue(nShadowEndColor)<<8;
rcVertex[1].Alpha=0;
handle_GradientFill(pDC->GetSafeHdc
(),rcVertex,2,&rect1,1,
GRADIENT_FILL_RECT_V);
rcVertex[0].x=rect.left;
rcVertex[0].y=rect.top-1+rect.Height()/2;
rcVertex[0].Red=GetRValue(nShadowEndColor)<<8;
rcVertex[0].Green=GetGValue(nShadowEndColor)<<8;
rcVertex[0].Blue=GetBValue(nShadowEndColor)<<8;
rcVertex[0].Alpha=0x0000;
rcVertex[1].x=rect.right;
rcVertex[1].y=rect.bottom;
rcVertex[1].Red=GetRValue(nShadowBeginColor)<<8;
rcVertex[1].Green=GetGValue(nShadowBeginColor)<<8;
rcVertex[1].Blue=GetBValue(nShadowBeginColor)<<8;
rcVertex[1].Alpha=0;
handle_GradientFill( pDC->GetSafeHdc
(),rcVertex,2,&rect1,1,
GRADIENT_FILL_RECT_V);
}
if (falg==MIDDLE_TO_SIDE)
{
POINT p1,p2,p3,p4,p;
p1.x=rect.left;p1.y=rect.bottom;
p2.x=rect.right;p2.y=rect.bottom;
p3.x=rect.right;p3.y=rect.top;
p4.x=rect.left;p4.y=rect.top;
p=rect.CenterPoint();
_DrawTriangle (pDC,p1,p2,p,nShadowEndColor,nShadowEndColor,nShadowBeginColor);
DrawTriangle(pDC,p2,p3,p,nShadowEndColor,nShadowEndColor,nShadowBeginColor);
DrawTriangle(pDC,p3,p4,p,nShadowEndColor,nShadowEndColor,nShadowBeginColor);
DrawTriangle(pDC,p4,p1,p,nShadowEndColor,nShadowEndColor,nShadowBeginColor);
}
}
其中falg指定渐变形式:
0:左右渐变。
1:上下渐变
3:中心到左右两边渐变
4:中心到上下渐变
5:中心到四周实现渐变
void_DrawRect(CDC *pDC,CRect rect,COLORREF
nShadowBeginColor,COLORREF
nShadowEndColor,int falg )
{
TRIVERTEX rcVertex[2];
rcVertex[0].x=rect.left;
rcVertex[0].y=rect.top;
rcVertex[0].Red=GetRValue(nShadowBeginColor)<<8;
rcVertex[0].Green=GetGValue(nShadowBeginColor)<<8;
rcVertex[0].Blue=GetBValue(nShadowBeginColor)<<8;
rcVertex[0].Alpha=0x0000;
rcVertex[1].x=rect.right;
rcVertex[1].y=rect.bottom;
rcVertex[1].Red=GetRValue(nShadowEndColor)<<8;
rcVertex[1].Green=GetGValue(nShadowEndColor)<<8;
rcVertex[1].Blue=GetBValue(nShadowEndColor)<<8;
rcVertex[1].Alpha=0;
GRADIENT_RECT rect1;
rect1.UpperLeft=0;
rect1.LowerRight=1;
if (falg==0)
handle_GradientFill( pDC->GetSafeHdc
(),rcVertex,2,&rect1,1,
GRADIENT_FILL_RECT_H);
if (falg==1)
handle_GradientFill( pDC->GetSafeHdc
(),rcVertex,2,&rect1,1,
GRADIENT_FILL_RECT_V );
if (falg==3)
{
///////
Email: visualsan@yahoo.cn
rcVertex[0].x=rect.left;
rcVertex[0].y=rect.top;
rcVertex[0].Red=GetRValue(nShadowBeginColor)<<8;
rcVertex[0].Green=GetGValue(nShadowBeginColor)<<8;
rcVertex[0].Blue=GetBValue(nShadowBeginColor)<<8;
rcVertex[0].Alpha=0x0000;
rcVertex[1].x=rect.right-rect.Width()/2;
rcVertex[1].y=rect.bottom;
rcVertex[1].Red=GetRValue(nShadowEndColor)<<8;
rcVertex[1].Green=GetGValue(nShadowEndColor)<<8;
rcVertex[1].Blue=GetBValue(nShadowEndColor)<<8;
rcVertex[1].Alpha=0;
handle_GradientFill(pDC->GetSafeHdc
(),rcVertex,2,&rect1,1,
GRADIENT_FILL_RECT_H);
rcVertex[0].x=rect.left+rect.Width()/2-1;
rcVertex[0].y=rect.top;
rcVertex[0].Red=GetRValue(nShadowEndColor)<<8;
rcVertex[0].Green=GetGValue(nShadowEndColor)<<8;
rcVertex[0].Blue=GetBValue(nShadowEndColor)<<8;
rcVertex[0].Alpha=0x0000;
rcVertex[1].x=rect.right;
rcVertex[1].y=rect.bottom;
rcVertex[1].Red=GetRValue(nShadowBeginColor)<<8;
rcVertex[1].Green=GetGValue(nShadowBeginColor)<<8;
rcVertex[1].Blue=GetBValue(nShadowBeginColor)<<8;
rcVertex[1].Alpha=0;
handle_GradientFill( pDC->GetSafeHdc
(),rcVertex,2,&rect1,1,
GRADIENT_FILL_RECT_H);
}
if (falg==4)
{ ///////
Email: visualsan@yahoo.cn
rcVertex[0].x=rect.left;
rcVertex[0].y=rect.top;
rcVertex[0].Red=GetRValue(nShadowBeginColor)
<< 8;
rcVertex[0].Green=GetGValue(nShadowBeginColor)<<8;
rcVertex[0].Blue=GetBValue(nShadowBeginColor)<<8;
rcVertex[0].Alpha=0x0000;
rcVertex[1].x=rect.right;
rcVertex[1].y=rect.bottom-rect.Height()/2;
rcVertex[1].Red=GetRValue(nShadowEndColor)<<8;
rcVertex[1].Green=GetGValue(nShadowEndColor)<<8;
rcVertex[1].Blue=GetBValue(nShadowEndColor)<<8;
rcVertex[1].Alpha=0;
handle_GradientFill(pDC->GetSafeHdc
(),rcVertex,2,&rect1,1,
GRADIENT_FILL_RECT_V);
rcVertex[0].x=rect.left;
rcVertex[0].y=rect.top-1+rect.Height()/2;
rcVertex[0].Red=GetRValue(nShadowEndColor)<<8;
rcVertex[0].Green=GetGValue(nShadowEndColor)<<8;
rcVertex[0].Blue=GetBValue(nShadowEndColor)<<8;
rcVertex[0].Alpha=0x0000;
rcVertex[1].x=rect.right;
rcVertex[1].y=rect.bottom;
rcVertex[1].Red=GetRValue(nShadowBeginColor)<<8;
rcVertex[1].Green=GetGValue(nShadowBeginColor)<<8;
rcVertex[1].Blue=GetBValue(nShadowBeginColor)<<8;
rcVertex[1].Alpha=0;
handle_GradientFill( pDC->GetSafeHdc
(),rcVertex,2,&rect1,1,
GRADIENT_FILL_RECT_V);
}
if (falg==MIDDLE_TO_SIDE)
{
POINT p1,p2,p3,p4,p;
p1.x=rect.left;p1.y=rect.bottom;
p2.x=rect.right;p2.y=rect.bottom;
p3.x=rect.right;p3.y=rect.top;
p4.x=rect.left;p4.y=rect.top;
p=rect.CenterPoint();
_DrawTriangle (pDC,p1,p2,p,nShadowEndColor,nShadowEndColor,nShadowBeginColor);
DrawTriangle(pDC,p2,p3,p,nShadowEndColor,nShadowEndColor,nShadowBeginColor);
DrawTriangle(pDC,p3,p4,p,nShadowEndColor,nShadowEndColor,nShadowBeginColor);
DrawTriangle(pDC,p4,p1,p,nShadowEndColor,nShadowEndColor,nShadowBeginColor);
}
}
相关文章推荐
- IOS 绘制背景色渐变的矩形
- iOS 动画绘制线条颜色渐变的折线图
- 椭圆拟合的函数式子以及绘制外接矩形
- IOS 绘制背景色渐变的矩形
- Graphics类提供基本的几何图形绘制方法,主要有:画线段、画矩形、画圆、画带颜色的图形、画椭圆、画圆弧、画多边形等。
- HTML5 canvas 绘制矩形 改变矩形颜色
- vtk等值面体绘制|纹理映射体绘制 附:不透明传输函数,颜色传输函数、光照与阴影
- javascript实现通过表格绘制颜色填充矩形的方法
- VTK修炼之道69:体绘制讨论_颜色传输函数
- 带颜色渐变效果的的矩形进度条
- 在VC中用GDI+绘制角度可变的颜色渐变效果
- IOS绘制动画颜色渐变折线条
- 在VC中用GDI+绘制角度可变的颜色渐变效果
- 【js学习笔记-114】----<canvas>矩形、颜色、透明度、渐变及图案
- 聊天气泡的绘制(圆角矩形+三角形+黑色边框,关键学会QPainter的draw函数就行了),注意每个QLabel都有自己的独立坐标
- 用Qt绘制颜色渐变
- HTML5绘制颜色渐变
- 颜色渐变矩形的画法
- android 使用java编程实现圆角渐变矩形的绘制
- 利用GradientFill函数实现颜色渐变效果