⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 colorname.c

📁 Nxlib,一个模拟xlib的程序。使用microwindows的库来运行需要xlib支持的程序。
💻 C
字号:
/* * Parse rgb.txt file and return color by name */#include "nxlib.h"#include <stdlib.h>#include <string.h>#define ISBLANK(c)	((c) == ' ' || (c) == '\t')#define ISDIGIT(c)	((c) >= '0' && (c) <= '9')#define ISEOL(c)	((c) == '\r' || (c) == '\n')/* get next int from buffer, return next buf position*/static char *strInt(int *retint, char *buf){	char *	q;	char	tmp[256];	while (ISBLANK(*buf))		++buf;	q = tmp;	while (ISDIGIT(*buf))		*q++ = *buf++;	*q = 0;	*retint = atoi(tmp);	return buf;}/* return string to end of line from buffer*/static voidstrEol(char *retbuf, char *buf){	while (ISBLANK(*buf))		++buf;	while (!ISEOL(*buf))		*retbuf++ = *buf++;	*retbuf = 0;}GR_COLORGrGetColorByName(char *colorname, int *retr, int *retg, int *retb){	FILE *fp;	unsigned int r = 0, g = 0, b = 0;	char buf[256];	fp = fopen(X11_RGBTXT, "r");	if (!fp)		return 0;	while (fgets(buf, 256, fp) != NULL) {		if (buf[0] != '!') {			char *p;			char name[256];				p = strInt(&r, buf);			p = strInt(&g, p);			p = strInt(&b, p);			strEol(name, p);			if (strcasecmp(name, colorname) == 0) {				if (retr)					*retr = r;				if (retg)					*retg = g;				if (retb)					*retb = b;				return GR_RGB(r, g, b);			}		}	}	fclose(fp);	return 0;}StatusXAllocNamedColor(Display * dpy, Colormap cmap, _Xconst char *colorname,		 XColor * hard_def, XColor * exact_def){	GR_COLOR c;	int r = 0, g = 0, b = 0;	/* first look up color in rgb.txt color database */	c = GrGetColorByName((char *) colorname, &r, &g, &b);//printf("XAllocNamedColor %s = %x\n", colorname, c);	hard_def->red = exact_def->red = r << 8;	hard_def->green = exact_def->green = g << 8;	hard_def->blue = exact_def->blue = b << 8;	/* Do an XAllocColor on the hardware color */	XAllocColor(dpy, cmap, hard_def);	return 1;}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -