Пример #1
0
int main(int argc, char **argv)
{
	RContextAttributes attr;
	float a;

	dpy = XOpenDisplay("");
	if (!dpy) {
		puts("cant open display");
		exit(1);
	}

	attr.flags = RC_RenderMode | RC_ColorsPerChannel;
	attr.render_mode = RDitheredRendering;
	attr.colors_per_channel = 4;
	ctx = RCreateContext(dpy, DefaultScreen(dpy), &attr);

	if (argc < 2)
		img = RGetImageFromXPMData(ctx, image_name);
	else
		img = RLoadImage(ctx, argv[1], 0);

	if (!img) {
		puts(RMessageForError(RErrorCode));
		exit(1);
	}
	win = XCreateSimpleWindow(dpy, DefaultRootWindow(dpy), 10, 10,
				  MAX(img->width, img->height), MAX(img->height, img->width), 0, 0, 0);
	XMapRaised(dpy, win);
	XFlush(dpy);

	a = 0;
	while (1) {
		RImage *tmp;

		a = a + 1.0;

		tmp = RRotateImage(img, a);
		if (!RConvertImage(ctx, tmp, &pix)) {
			puts(RMessageForError(RErrorCode));
			exit(1);
		}
		RReleaseImage(tmp);

		XSetWindowBackgroundPixmap(dpy, win, pix);
		XFreePixmap(dpy, pix);
		XClearWindow(dpy, win);
		XSync(dpy, 0);
		usleep(50000);
	}
	exit(0);
}
Пример #2
0
static RImage * get_texture_image(WScreen *scr, const char *pixmap_file)
{
	char *file;
	RImage *image;

	file = FindImage(wPreferences.pixmap_path, pixmap_file);
	if (!file) {
		wwarning(_("image file \"%s\" used as texture could not be found."), pixmap_file);
		return NULL;
	}
	image = RLoadImage(scr->rcontext, file, 0);
	if (!image) {
		wwarning(_("could not load texture pixmap \"%s\":%s"), file, RMessageForError(RErrorCode));
		wfree(file);
		return NULL;
	}
	wfree(file);

	return image;
}
Пример #3
0
static RImage *loadImage(RContext * rc, const char *file)
{
	char *path;
	RImage *image;

	if (access(file, F_OK) != 0) {
		path = wfindfile(PixmapPath, file);
		if (!path) {
			wwarning("%s:could not find image file used in texture", file);
			return NULL;
		}
	} else {
		path = wstrdup(file);
	}

	image = RLoadImage(rc, path, 0);
	if (!image) {
		wwarning("%s:could not load image file used in texture:%s", path, RMessageForError(RErrorCode));
	}
	wfree(path);

	return image;
}
Пример #4
0
static BackgroundTexture *parseTexture(RContext * rc, char *text)
{
	BackgroundTexture *texture = NULL;
	WMPropList *texarray;
	WMPropList *val;
	int count;
	char *tmp;
	char *type;

#define GETSTRORGOTO(val, str, i, label) \
    val = WMGetFromPLArray(texarray, i);\
    if (!WMIsPLString(val)) {\
    wwarning("could not parse texture %s", text);\
    goto label;\
    }\
    str = WMGetFromPLString(val)

	texarray = WMCreatePropListFromDescription(text);
	if (!texarray || !WMIsPLArray(texarray)
	    || (count = WMGetPropListItemCount(texarray)) < 2) {

		wwarning("could not parse texture %s", text);
		if (texarray)
			WMReleasePropList(texarray);
		return NULL;
	}

	texture = wmalloc(sizeof(BackgroundTexture));

	GETSTRORGOTO(val, type, 0, error);

	if (strcasecmp(type, "solid") == 0) {
		XColor color;
		Pixmap pixmap;

		texture->solid = 1;

		GETSTRORGOTO(val, tmp, 1, error);

		if (!XParseColor(dpy, DefaultColormap(dpy, scr), tmp, &color)) {
			wwarning("could not parse color %s in texture %s", tmp, text);
			goto error;
		}
		XAllocColor(dpy, DefaultColormap(dpy, scr), &color);

		pixmap = XCreatePixmap(dpy, root, 8, 8, DefaultDepth(dpy, scr));
		XSetForeground(dpy, DefaultGC(dpy, scr), color.pixel);
		XFillRectangle(dpy, pixmap, DefaultGC(dpy, scr), 0, 0, 8, 8);

		texture->pixmap = pixmap;
		texture->color = color;
		texture->width = 8;
		texture->height = 8;
	} else if (strcasecmp(type, "vgradient") == 0
		   || strcasecmp(type, "dgradient") == 0 || strcasecmp(type, "hgradient") == 0) {
		XColor color;
		RColor color1, color2;
		RImage *image;
		Pixmap pixmap;
		RGradientStyle gtype;
		int iwidth, iheight;

		GETSTRORGOTO(val, tmp, 1, error);

		if (!XParseColor(dpy, DefaultColormap(dpy, scr), tmp, &color)) {
			wwarning("could not parse color %s in texture %s", tmp, text);
			goto error;
		}

		color1.red = color.red >> 8;
		color1.green = color.green >> 8;
		color1.blue = color.blue >> 8;

		GETSTRORGOTO(val, tmp, 2, error);

		if (!XParseColor(dpy, DefaultColormap(dpy, scr), tmp, &color)) {
			wwarning("could not parse color %s in texture %s", tmp, text);
			goto error;
		}

		color2.red = color.red >> 8;
		color2.green = color.green >> 8;
		color2.blue = color.blue >> 8;

		switch (type[0]) {
		case 'h':
		case 'H':
			gtype = RHorizontalGradient;
			iwidth = scrWidth;
			iheight = 32;
			break;
		case 'V':
		case 'v':
			gtype = RVerticalGradient;
			iwidth = 32;
			iheight = scrHeight;
			break;
		default:
			gtype = RDiagonalGradient;
			iwidth = scrWidth;
			iheight = scrHeight;
			break;
		}

		image = RRenderGradient(iwidth, iheight, &color1, &color2, gtype);

		if (!image) {
			wwarning("could not render gradient texture:%s", RMessageForError(RErrorCode));
			goto error;
		}

		if (!RConvertImage(rc, image, &pixmap)) {
			wwarning("could not convert texture:%s", RMessageForError(RErrorCode));
			RReleaseImage(image);
			goto error;
		}

		texture->width = image->width;
		texture->height = image->height;
		RReleaseImage(image);

		texture->pixmap = pixmap;
	} else if (strcasecmp(type, "mvgradient") == 0
Пример #5
0
static void
applyImage(RContext * rc, BackgroundTexture * texture, RImage * image, char type,
	   int x, int y, int width, int height)
{
	int w, h;
	Bool fimage = False;

	switch (toupper(type)) {
	case 'S':
	case 'M':
	case 'F':
		if (toupper(type) == 'S') {
			w = width;
			h = height;
		} else if(toupper(type) == 'F') {
			if (image->width * height > image->height * width) {
				w = (height * image->width) / image->height;
				h = height;
			} else {
				w = width;
				h = (width * image->height) / image->width;
			}
		} else {
			if (image->width * height > image->height * width) {
				w = width;
				h = (width * image->height) / image->width;
			} else {
				w = (height * image->width) / image->height;
				h = height;
			}
		}

		if (w != image->width || h != image->height) {
			RImage *simage;

			if (smooth) {
				simage = RSmoothScaleImage(image, w, h);
			} else {
				simage = RScaleImage(image, w, h);
			}

			if (!simage) {
				wwarning("could not scale image:%s", RMessageForError(RErrorCode));
				return;
			}
			fimage = True;
			image = simage;
		}

		/* fall through */
	case 'C':
		{
			Pixmap pixmap;

			if (!RConvertImage(rc, image, &pixmap)) {
				wwarning("could not convert texture:%s", RMessageForError(RErrorCode));
				if (fimage)
					RReleaseImage(image);
				return;
			}

			if (image->width != width || image->height != height) {
				int sx, sy, w, h;

				if (image->height < height) {
					h = image->height;
					y += (height - h) / 2;
					sy = 0;
				} else {
					sy = (image->height - height) / 2;
					h = height;
				}
				if (image->width < width) {
					w = image->width;
					x += (width - w) / 2;
					sx = 0;
				} else {
					sx = (image->width - width) / 2;
					w = width;
				}

				XCopyArea(dpy, pixmap, texture->pixmap, DefaultGC(dpy, scr), sx, sy, w, h, x, y);
			} else
				XCopyArea(dpy, pixmap, texture->pixmap, DefaultGC(dpy, scr), 0, 0, width, height,
					  x, y);

			XFreePixmap(dpy, pixmap);
			if (fimage) {
				RReleaseImage(image);
			}
		}
		break;
	}
}
Пример #6
0
static Bool loadPixmaps(WMScreen * scr)
{
	RImage *image, *tmp;
	RColor gray;
	RColor white;

	gray.red = 0xae;
	gray.green = 0xaa;
	gray.blue = 0xae;

	white.red = 0xff;
	white.green = 0xff;
	white.blue = 0xff;

	image = RLoadImage(scr->rcontext, T_WINGS_IMAGES_FILE, 0);
	if (!image)
		image = RLoadImage(scr->rcontext, X_WINGS_IMAGES_FILE, 0);
	if (!image) {
		wwarning(_("WINGs: could not load widget images file: %s"), RMessageForError(RErrorCode));
		return False;
	}
	/* home icon */
	/* make it have a gray background */
	tmp = RGetSubImage(image, 0, 0, 24, 24);
	RCombineImageWithColor(tmp, &gray);
	scr->homeIcon = WMCreatePixmapFromRImage(scr, tmp, 128);
	RReleaseImage(tmp);
	/* make it have a white background */
	tmp = RGetSubImage(image, 0, 0, 24, 24);
	RCombineImageWithColor(tmp, &white);
	scr->altHomeIcon = WMCreatePixmapFromRImage(scr, tmp, 128);
	RReleaseImage(tmp);

	/* trash can */
	tmp = RGetSubImage(image, 104, 0, 24, 24);
	RCombineImageWithColor(tmp, &white);
	scr->trashcanIcon = WMCreatePixmapFromRImage(scr, tmp, 128);
	RReleaseImage(tmp);
	tmp = RGetSubImage(image, 104, 0, 24, 24);
	RCombineImageWithColor(tmp, &white);
	scr->altTrashcanIcon = WMCreatePixmapFromRImage(scr, tmp, 128);
	RReleaseImage(tmp);
	/* create dir */
	tmp = RGetSubImage(image, 104, 24, 24, 24);
	RCombineImageWithColor(tmp, &white);
	scr->createDirIcon = WMCreatePixmapFromRImage(scr, tmp, 128);
	RReleaseImage(tmp);
	tmp = RGetSubImage(image, 104, 24, 24, 24);
	RCombineImageWithColor(tmp, &white);
	scr->altCreateDirIcon = WMCreatePixmapFromRImage(scr, tmp, 128);
	RReleaseImage(tmp);
	/* diskettes */
	tmp = RGetSubImage(image, 24, 80, 24, 24);
	RCombineImageWithColor(tmp, &white);
	scr->disketteIcon = WMCreatePixmapFromRImage(scr, tmp, 128);
	RReleaseImage(tmp);
	tmp = RGetSubImage(image, 24, 80, 24, 24);
	RCombineImageWithColor(tmp, &white);
	scr->altDisketteIcon = WMCreatePixmapFromRImage(scr, tmp, 128);
	RReleaseImage(tmp);
	/* unmount */
	tmp = RGetSubImage(image, 0, 80, 24, 24);
	RCombineImageWithColor(tmp, &white);
	scr->unmountIcon = WMCreatePixmapFromRImage(scr, tmp, 128);
	RReleaseImage(tmp);
	tmp = RGetSubImage(image, 0, 80, 24, 24);
	RCombineImageWithColor(tmp, &white);
	scr->altUnmountIcon = WMCreatePixmapFromRImage(scr, tmp, 128);
	RReleaseImage(tmp);

	/* Magnifying Glass Icon for ColorPanel */
	tmp = RGetSubImage(image, 24, 0, 40, 32);
	RCombineImageWithColor(tmp, &gray);
	scr->magnifyIcon = WMCreatePixmapFromRImage(scr, tmp, 128);
	RReleaseImage(tmp);
	/* ColorWheel Icon for ColorPanel */
	tmp = RGetSubImage(image, 0, 25, 24, 24);
	scr->wheelIcon = WMCreatePixmapFromRImage(scr, tmp, 128);
	RReleaseImage(tmp);
	/* GrayScale Icon for ColorPanel */
	tmp = RGetSubImage(image, 65, 0, 40, 24);
	scr->grayIcon = WMCreatePixmapFromRImage(scr, tmp, 128);
	RReleaseImage(tmp);
	/* RGB Icon for ColorPanel */
	tmp = RGetSubImage(image, 25, 33, 40, 24);
	scr->rgbIcon = WMCreatePixmapFromRImage(scr, tmp, 128);
	RReleaseImage(tmp);
	/* CMYK Icon for ColorPanel */
	tmp = RGetSubImage(image, 65, 25, 40, 24);
	scr->cmykIcon = WMCreatePixmapFromRImage(scr, tmp, 128);
	RReleaseImage(tmp);
	/* HSB Icon for ColorPanel */
	tmp = RGetSubImage(image, 0, 57, 40, 24);
	scr->hsbIcon = WMCreatePixmapFromRImage(scr, tmp, 128);
	RReleaseImage(tmp);
	/* CustomColorPalette Icon for ColorPanel */
	tmp = RGetSubImage(image, 81, 57, 40, 24);
	scr->customPaletteIcon = WMCreatePixmapFromRImage(scr, tmp, 128);
	RReleaseImage(tmp);
	/* ColorList Icon for ColorPanel */
	tmp = RGetSubImage(image, 41, 57, 40, 24);
	scr->colorListIcon = WMCreatePixmapFromRImage(scr, tmp, 128);
	RReleaseImage(tmp);

	RReleaseImage(image);

	return True;
}
Пример #7
0
static int showIconFor(WMScreen *scrPtr, InspectorPanel *panel, const char *wm_instance, const char *wm_class, int flags)
{
	WMPixmap *pixmap = (WMPixmap *) NULL;
	char *file = NULL, *path = NULL;

	if ((flags & USE_TEXT_FIELD) != 0) {
		file = WMGetTextFieldText(panel->fileText);
		if (file && file[0] == 0) {
			wfree(file);
			file = NULL;
		}
	} else if (flags & REVERT_TO_DEFAULT) {
		const char *db_icon;

		/* Get the application icon, default NOT included */
		db_icon = wDefaultGetIconFile(wm_instance, wm_class, False);
		if (db_icon != NULL) {
			file = wstrdup(db_icon);
			flags |= UPDATE_TEXT_FIELD;
		}
	}

	if ((flags & UPDATE_TEXT_FIELD) != 0)
		WMSetTextFieldText(panel->fileText, file);

	if (file) {
		path = FindImage(wPreferences.icon_path, file);

		if (!path) {
			char *buf;
			int len = strlen(file) + 80;

			buf = wmalloc(len);
			snprintf(buf, len, _("Could not find icon \"%s\" specified for this window"), file);
			wMessageDialog(panel->frame->screen_ptr, _("Error"), buf, _("OK"), NULL, NULL);
			wfree(buf);
			wfree(file);
			return -1;
		}

		pixmap = WMCreatePixmapFromFile(scrPtr, path);
		wfree(path);

		if (!pixmap) {
			char *buf;
			int len = strlen(file) + 80;

			buf = wmalloc(len);
			snprintf(buf, len, _("Could not open specified icon \"%s\":%s"),
				 file, RMessageForError(RErrorCode));
			wMessageDialog(panel->frame->screen_ptr, _("Error"), buf, _("OK"), NULL, NULL);
			wfree(buf);
			wfree(file);
			return -1;
		}
		wfree(file);
	}

	WMSetLabelImage(panel->iconLbl, pixmap);
	if (pixmap)
		WMReleasePixmap(pixmap);

	return 0;
}