[Easyx]一个以图像模式输出圆角矩形的函数

前言:虽然easyx里面有一个这个功能的函数了,但是我还是自制了一种实现方式来练习下。

附加-easyx中的圆角矩形函数:

void roundrect     (int left, int top, int right, int bottom, int ellipsewidth, int ellipseheight);     // 画圆角矩形  
void fillroundrect (int left, int top, int right, int bottom, int ellipsewidth, int ellipseheight);     // 画填充圆角矩形(有边框)  
void solidroundrect(int left, int top, int right, int bottom, int ellipsewidth, int ellipseheight);     // 画填充圆角矩形(无边框)  
void clearroundrect(int left, int top, int right, int bottom, int ellipsewidth, int ellipseheight);     // 清空圆角矩形区域  

好,正式开始介绍:

示例图:
[Easyx]一个以图像模式输出圆角矩形的函数_第1张图片
函数:

void out_long(//制作长方体,圆角长方体
	int left,
	int top,
	int right,
	int bottom,       //上下左右点的坐标
	bool line = false,             //是否启用边框,默认不用
	COLORREF color_full = WHITE,   //填充色(默认为白)
	COLORREF color_line = BLACK,   //边框颜色(默认为黑)
	unsigned int r = 0    //圆半径,0的时候无圆角
)
{
     
	setlinecolor(color_line);  // 设置当前线条颜色 
	setfillcolor(color_full);  // 设置当前填充颜色 
	if (!r) {
     //如果没有半径,就是输出普通长方体
		if (line)//如果有边框
			fillrectangle(left, top, right, bottom);
		else
			solidrectangle(left, top, right, bottom);
	}
	else {
     //输出带圆角长方体
		if (line) {
     //如果有边框
			fillcircle(left + r, top + r, r);
			fillcircle(left + r, bottom - r, r);
			fillcircle(right - r, top + r, r);
			fillcircle(right - r, bottom - r, r);
			solidrectangle(left, top + r, right, bottom - r);
			solidrectangle(left + r, top, right - r, bottom);
			::line(left + r, top, right - r, top);
			::line(left + r, bottom, right - r, bottom);
			::line(left, top + r, left, bottom - r);
			::line(right, top + r, right, bottom - r);
		}
		else {
     
			solidrectangle(left, top + r, right, bottom - r);
			solidrectangle(left + r, top, right - r, bottom);
			solidcircle(left + r, top + r, r);
			solidcircle(left + r, bottom - r, r);
			solidcircle(right - r, top + r, r);
			solidcircle(right - r, bottom - r, r);
		}
	}
}

完整代码:

#include 
#include 
void out_long(//制作长方体,圆角长方体
	int left,
	int top,
	int right,
	int bottom,       //上下左右点的坐标
	bool line = false,             //是否启用边框,默认不用
	COLORREF color_full = WHITE,   //填充色(默认为白)
	COLORREF color_line = BLACK,   //边框颜色(默认为黑)
	unsigned int r = 0    //圆半径,0的时候无圆角
)
{
     
	setlinecolor(color_line);  // 设置当前线条颜色 
	setfillcolor(color_full);  // 设置当前填充颜色 
	if (!r) {
     //如果没有半径,就是输出普通长方体
		if (line)//如果有边框
			fillrectangle(left, top, right, bottom);
		else
			solidrectangle(left, top, right, bottom);
	}
	else {
     //输出带圆角长方体
		if (line) {
     //如果有边框
			fillcircle(left + r, top + r, r);
			fillcircle(left + r, bottom - r, r);
			fillcircle(right - r, top + r, r);
			fillcircle(right - r, bottom - r, r);
			solidrectangle(left, top + r, right, bottom - r);
			solidrectangle(left + r, top, right - r, bottom);
			::line(left + r, top, right - r, top);
			::line(left + r, bottom, right - r, bottom);
			::line(left, top + r, left, bottom - r);
			::line(right, top + r, right, bottom - r);
		}
		else {
     
			solidrectangle(left, top + r, right, bottom - r);
			solidrectangle(left + r, top, right - r, bottom);
			solidcircle(left + r, top + r, r);
			solidcircle(left + r, bottom - r, r);
			solidcircle(right - r, top + r, r);
			solidcircle(right - r, bottom - r, r);
		}
	}
}
int main() {
     
	initgraph(500, 500);
	setbkcolor(0xfffff1);
	cleardevice();//清下屏
	out_long(10, 10, 50, 50);//默认输出
	out_long(10, 60, 50, 100, true);//带边框
	out_long(10, 110, 50, 150, true,0xAAAAAA);//带边框,且填充内部颜色
	out_long(10, 160, 50, 200, true, 0x00Bfff, 0xFF3030);//带边框,且填充内部颜色,还加了边框色
	out_long(10, 210, 50, 250, true, 0xffffff, 0xFF3030,20);//带边框,且填充内部颜色,还加了边框色,设置了边角的半径
	//吐槽:一个像圆的圆角长方体
	out_long(10, 260, 200, 400, true, 0xAAAAAA, 0xADFF2F, 20);//带边框,且填充内部颜色,还加了边框色,设置了边角的半径
	//正常了
	out_long(10, 410, 400, 490, true, 0xf0f0f0, 0x87CEFA, 20);//带边框,且填充内部颜色,还加了边框色,设置了边角的半径
	_getch();//不过不行就换成getch();
	closegraph();
	return 0;
}

你可能感兴趣的:(原创,函数,c++)