硬汉嵌入式论坛

 找回密码
 立即注册
查看: 5521|回复: 0
收起左侧

[emWin] 绘制一个支持梯度色的圆角矩形源码

[复制链接]

1万

主题

6万

回帖

10万

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
106934
QQ
发表于 2014-6-10 10:40:24 | 显示全部楼层 |阅读模式
/*********************************************************************
*
*       _DrawGradientRoundBar
*
* Function description
*   Draws a vertical gradient in form of a rounded bar
*/
static void _DrawGradientRoundBar(int xPos0, int yPos0, int xPos1, int yPos1, GUI_COLOR Color0, GUI_COLOR Color1)
{
    GUI_COLOR Color;
    unsigned  r;
    unsigned  g;
    U32       b;
    double    rd;
    double    rr;
    double    x;
    double    y;
    int       Add;
    int       r0;
    int       g0;
    int       b0;
    int       r1;
    int       g1;
    int       b1;
    int       d;
    int       i;

    r0  = (Color0 >>  0) & 0x000000ff;
    g0  = (Color0 >>  8) & 0x000000ff;
    b0  = (Color0 >> 16) & 0x000000ff;
    r1  = (Color1 >>  0) & 0x000000ff;
    g1  = (Color1 >>  8) & 0x000000ff;
    b1  = (Color1 >> 16) & 0x000000ff;
    Add = -1;
    d   = yPos1 - yPos0 + 1;
    rd  = (yPos1 - yPos0) / 2.0;
    rr  = rd * rd;
    y   = rd;
   
    for (i = yPos0; i <= yPos1; i++)
    {
        x = sqrt(rr - y * y);
        r = r0 + (r1 - r0) * (i - yPos0) / d;
        g = g0 + (g1 - g0) * (i - yPos0) / d;
        b = b0 + (b1 - b0) * (i - yPos0) / d;
        Color = r | (g << 8) | (b << 16);
        GUI_SetColor(Color);
        
        GUI_DrawHLine(i, (int)(xPos0 + rd - x), (int)(xPos0 + rd));
        GUI_DrawHLine(i, (int)(xPos0 + rd),     (int)(xPos1 - rd));
        GUI_DrawHLine(i, (int)(xPos1 - rd),     (int)(xPos1 - rd + x));
        
        y += Add;
        if (y < 0)
        {
            Add = -Add;
            y = -y;
        }
    }
}
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|小黑屋|Archiver|手机版|硬汉嵌入式论坛

GMT+8, 2024-5-10 22:47 , Processed in 0.147300 second(s), 25 queries .

Powered by Discuz! X3.4 Licensed

Copyright © 2001-2023, Tencent Cloud.

快速回复 返回顶部 返回列表