Beispiel #1
0
void wTextureDestroy(WScreen * scr, WTexture * texture)
{
	int i;
	int count = 0;
	unsigned long colors[8];

	/*
	 * some stupid servers don't like white or black being freed...
	 */
#define CANFREE(c) (c!=scr->black_pixel && c!=scr->white_pixel && c!=0)
	switch (texture->any.type) {
	case WTEX_SOLID:
		XFreeGC(dpy, texture->solid.light_gc);
		XFreeGC(dpy, texture->solid.dark_gc);
		XFreeGC(dpy, texture->solid.dim_gc);
		if (CANFREE(texture->solid.light.pixel))
			colors[count++] = texture->solid.light.pixel;
		if (CANFREE(texture->solid.dim.pixel))
			colors[count++] = texture->solid.dim.pixel;
		if (CANFREE(texture->solid.dark.pixel))
			colors[count++] = texture->solid.dark.pixel;
		break;

	case WTEX_PIXMAP:
		RReleaseImage(texture->pixmap.pixmap);
		break;

	case WTEX_MHGRADIENT:
	case WTEX_MVGRADIENT:
	case WTEX_MDGRADIENT:
		for (i = 0; texture->mgradient.colors[i] != NULL; i++) {
			wfree(texture->mgradient.colors[i]);
		}
		wfree(texture->mgradient.colors);
		break;

	case WTEX_THGRADIENT:
	case WTEX_TVGRADIENT:
	case WTEX_TDGRADIENT:
		RReleaseImage(texture->tgradient.pixmap);
		break;
	}

	if (CANFREE(texture->any.color.pixel))
		colors[count++] = texture->any.color.pixel;
	if (count > 0) {
		XErrorHandler oldhandler;

		/* ignore error from buggy servers that don't know how
		 * to do reference counting for colors. */
		XSync(dpy, 0);
		oldhandler = XSetErrorHandler(dummyErrorHandler);
		XFreeColors(dpy, scr->w_colormap, colors, count, 0);
		XSync(dpy, 0);
		XSetErrorHandler(oldhandler);
	}
	XFreeGC(dpy, texture->any.gc);
	wfree(texture);
#undef CANFREE
}
Beispiel #2
0
static RImage *renderMDGradient(unsigned width, unsigned height, RColor ** colors, int count)
{
	RImage *image, *tmp;
	float a, offset;
	int j;
	unsigned char *ptr;

	assert(count > 2);

	if (width == 1)
		return renderMVGradient(width, height, colors, count);
	else if (height == 1)
		return renderMHGradient(width, height, colors, count);

	image = RCreateImage(width, height, False);
	if (!image) {
		return NULL;
	}

	if (count > width)
		count = width;
	if (count > height)
		count = height;

	if (count > 2)
		tmp = renderMHGradient(2 * width - 1, 1, colors, count);
	else
		tmp = renderHGradient(2 * width - 1, 1, colors[0]->red << 8,
				      colors[0]->green << 8, colors[0]->blue << 8,
				      colors[1]->red << 8, colors[1]->green << 8, colors[1]->blue << 8);

	if (!tmp) {
		RReleaseImage(image);
		return NULL;
	}
	ptr = tmp->data;

	a = ((float)(width - 1)) / ((float)(height - 1));
	width = width * 3;

	/* copy the first line to the other lines with corresponding offset */
	for (j = 0, offset = 0; j < width * height; j += width) {
		memcpy(&(image->data[j]), &ptr[3 * (int)offset], width);
		offset += a;
	}
	RReleaseImage(tmp);
	return image;
}
Beispiel #3
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);
}
Beispiel #4
0
WMPixmap *WMCreateScaledBlendedPixmapFromFile(WMScreen *scrPtr, const char *fileName, const RColor *color,
                                              unsigned int width, unsigned int height)
{
	WMPixmap *pixPtr;
	RImage *image;

	image = RLoadImage(scrPtr->rcontext, fileName, 0);
	if (!image)
		return NULL;

	/* scale it if needed to fit in the specified box */
	if ((width > 0) && (height > 0) && ((image->width > width) || (image->height > height))) {
		int new_width, new_height;
		RImage *new_image;

		new_width  = image->width;
		new_height = image->height;
		if (new_width > width) {
			new_width  = width;
			new_height = width * image->height / image->width;
		}
		if (new_height > height) {
			new_width  = height * image->width / image->height;
			new_height = height;
		}

		new_image = RScaleImage(image, new_width, new_height);
		RReleaseImage(image);
		image = new_image;
	}

	RCombineImageWithColor(image, color);
	pixPtr = WMCreatePixmapFromRImage(scrPtr, image, 0);
	RReleaseImage(image);

	return pixPtr;
}
Beispiel #5
0
static void hideWorkspaceName(void *data)
{
	WScreen *scr = (WScreen *) data;

	if (!scr->workspace_name_data || scr->workspace_name_data->count == 0
	    || time(NULL) > scr->workspace_name_data->timeout) {
		XUnmapWindow(dpy, scr->workspace_name);

		if (scr->workspace_name_data) {
			RReleaseImage(scr->workspace_name_data->back);
			RReleaseImage(scr->workspace_name_data->text);
			wfree(scr->workspace_name_data);

			scr->workspace_name_data = NULL;
		}
		scr->workspace_name_timer = NULL;
	} else {
		RImage *img = RCloneImage(scr->workspace_name_data->back);
		Pixmap pix;

		scr->workspace_name_timer = WMAddTimerHandler(WORKSPACE_NAME_FADE_DELAY, hideWorkspaceName, scr);

		RCombineImagesWithOpaqueness(img, scr->workspace_name_data->text,
					     scr->workspace_name_data->count * 255 / 10);

		RConvertImage(scr->rcontext, img, &pix);

		RReleaseImage(img);

		XSetWindowBackgroundPixmap(dpy, scr->workspace_name, pix);
		XClearWindow(dpy, scr->workspace_name);
		XFreePixmap(dpy, pix);
		XFlush(dpy);

		scr->workspace_name_data->count--;
	}
}
Beispiel #6
0
static RImage *renderDGradient(unsigned width, unsigned height, int r0, int g0, int b0, int rf, int gf, int bf)
{
	RImage *image, *tmp;
	int j;
	float a, offset;
	unsigned char *ptr;

	if (width == 1)
		return renderVGradient(width, height, r0, g0, b0, rf, gf, bf);
	else if (height == 1)
		return renderHGradient(width, height, r0, g0, b0, rf, gf, bf);

	image = RCreateImage(width, height, False);
	if (!image) {
		return NULL;
	}

	tmp = renderHGradient(2 * width - 1, 1, r0, g0, b0, rf, gf, bf);
	if (!tmp) {
		RReleaseImage(image);
		return NULL;
	}

	ptr = tmp->data;

	a = ((float)(width - 1)) / ((float)(height - 1));
	width = width * 3;

	/* copy the first line to the other lines with corresponding offset */
	for (j = 0, offset = 0.0; j < width * height; j += width) {
		memcpy(&(image->data[j]), &ptr[3 * (int)offset], width);
		offset += a;
	}

	RReleaseImage(tmp);
	return image;
}
Beispiel #7
0
WMPixmap *WMCreatePixmapFromFile(WMScreen * scrPtr, const char *fileName)
{
	WMPixmap *pixPtr;
	RImage *image;

	image = RLoadImage(scrPtr->rcontext, fileName, 0);
	if (!image)
		return NULL;

	pixPtr = WMCreatePixmapFromRImage(scrPtr, image, 127);

	RReleaseImage(image);

	return pixPtr;
}
Beispiel #8
0
WMPixmap *WMCreatePixmapFromXPMData(WMScreen * scrPtr, char **data)
{
	WMPixmap *pixPtr;
	RImage *image;

	image = RGetImageFromXPMData(scrPtr->rcontext, data);
	if (!image)
		return NULL;

	pixPtr = WMCreatePixmapFromRImage(scrPtr, image, 127);

	RReleaseImage(image);

	return pixPtr;
}
Beispiel #9
0
WMPixmap *WMCreateBlendedPixmapFromRImage(WMScreen * scrPtr, RImage * image, const RColor * color)
{
	WMPixmap *pixPtr;
	RImage *copy;

	copy = RCloneImage(image);
	if (!copy)
		return NULL;

	RCombineImageWithColor(copy, color);
	pixPtr = WMCreatePixmapFromRImage(scrPtr, copy, 0);
	RReleaseImage(copy);

	return pixPtr;
}
Beispiel #10
0
static void createPanel(Panel *p)
{
	_Panel *panel = (_Panel *) p;
	WMScreen *scr = WMWidgetScreen(panel->parent);
	char *buf1, *buf2;
	WMPixmap *icon, *altIcon;
	RImage *xis = NULL;
	int i;
	RContext *rc = WMScreenRContext(scr);
	WMFont *font = WMSystemFontOfSize(scr, 10);
	char *path;

	path = LocateImage(ARQUIVO_XIS);
	if (path) {
		xis = RLoadImage(rc, path, 0);
		if (!xis)
			wwarning(_("could not load image file %s"), path);
		wfree(path);
	}

	panel->box = WMCreateBox(panel->parent);
	WMSetViewExpandsToParent(WMWidgetView(panel->box), 2, 2, 2, 2);

    /*********** Icon Slide Speed **********/
	panel->icoF = WMCreateFrame(panel->box);
	WMResizeWidget(panel->icoF, 212, 45);
	WMMoveWidget(panel->icoF, 15, 10);
	WMSetFrameTitle(panel->icoF, _("Icon Slide Speed"));

    /*********** Shade Animation Speed **********/
	panel->shaF = WMCreateFrame(panel->box);
	WMResizeWidget(panel->shaF, 212, 45);
	WMMoveWidget(panel->shaF, 15, 65);
	WMSetFrameTitle(panel->shaF, _("Shade Animation Speed"));

	buf1 = wmalloc(strlen(SPEED_IMAGE) + 1);
	buf2 = wmalloc(strlen(SPEED_IMAGE_S) + 1);

	for (i = 0; i < 5; i++) {
		panel->icoB[i] = WMCreateCustomButton(panel->icoF, WBBStateChangeMask);
		panel->shaB[i] = WMCreateCustomButton(panel->shaF, WBBStateChangeMask);
		WMResizeWidget(panel->icoB[i], 40, 24);
		WMMoveWidget(panel->icoB[i], 2 + (40 * i), 15);
		WMResizeWidget(panel->shaB[i], 40, 24);
		WMMoveWidget(panel->shaB[i], 2 + (40 * i), 15);
		WMSetButtonBordered(panel->icoB[i], False);
		WMSetButtonImagePosition(panel->icoB[i], WIPImageOnly);
		if (i > 0) {
			WMGroupButtons(panel->icoB[0], panel->icoB[i]);
		}
		WMSetButtonBordered(panel->shaB[i], False);
		WMSetButtonImagePosition(panel->shaB[i], WIPImageOnly);
		if (i > 0) {
			WMGroupButtons(panel->shaB[0], panel->shaB[i]);
		}
		sprintf(buf1, SPEED_IMAGE, i);
		sprintf(buf2, SPEED_IMAGE_S, i);
		path = LocateImage(buf1);
		if (path) {
			icon = WMCreatePixmapFromFile(scr, path);
			if (icon) {
				WMSetButtonImage(panel->icoB[i], icon);
				WMSetButtonImage(panel->shaB[i], icon);
				WMReleasePixmap(icon);
			} else {
				wwarning(_("could not load icon file %s"), path);
			}
			wfree(path);
		}
		path = LocateImage(buf2);
		if (path) {
			icon = WMCreatePixmapFromFile(scr, path);
			if (icon) {
				WMSetButtonAltImage(panel->icoB[i], icon);
				WMSetButtonAltImage(panel->shaB[i], icon);
				WMReleasePixmap(icon);
			} else {
				wwarning(_("could not load icon file %s"), path);
			}
			wfree(path);
		}
	}
	wfree(buf1);
	wfree(buf2);

	WMMapSubwidgets(panel->icoF);
	WMMapSubwidgets(panel->shaF);

    /***************** Smoothed Scaling *****************/
	panel->smoF = WMCreateFrame(panel->box);
	WMResizeWidget(panel->smoF, 94, 100);
	WMMoveWidget(panel->smoF, 420, 10);
	WMSetFrameTitle(panel->smoF, _("Smooth Scaling"));

	panel->smoB = WMCreateButton(panel->smoF, WBTToggle);
	WMResizeWidget(panel->smoB, 64, 64);
	WMMoveWidget(panel->smoB, 15, 23);
	WMSetButtonImagePosition(panel->smoB, WIPImageOnly);
	path = LocateImage(SMOOTH_IMAGE);
	if (path) {
		RImage *image, *scaled;

		image = RLoadImage(WMScreenRContext(scr), path, 0);
		wfree(path);

		scaled = RScaleImage(image, 61, 61);
		icon = WMCreatePixmapFromRImage(scr, scaled, 128);
		RReleaseImage(scaled);
		if (icon) {
			WMSetButtonImage(panel->smoB, icon);
			WMReleasePixmap(icon);
		}

		scaled = RSmoothScaleImage(image, 61, 61);
		icon = WMCreatePixmapFromRImage(scr, scaled, 128);
		RReleaseImage(scaled);
		if (icon) {
			WMSetButtonAltImage(panel->smoB, icon);
			WMReleasePixmap(icon);
		}

		RReleaseImage(image);
	}
	WMSetBalloonTextForView(_("Smooth scaled background images, neutralizing\n"
				  "the `pixelization' effect. This will slow\n"
				  "down loading of background images considerably."), WMWidgetView(panel->smoB));

	WMMapSubwidgets(panel->smoF);

    /***************** Titlebar Style Size ****************/
	panel->titlF = WMCreateFrame(panel->box);
	WMResizeWidget(panel->titlF, 212, 97);
	WMMoveWidget(panel->titlF, 15, 120);
	WMSetFrameTitle(panel->titlF, _("Titlebar Style"));

	panel->oldsB = WMCreateButton(panel->titlF, WBTOnOff);
	WMResizeWidget(panel->oldsB, 60, 40);
	WMMoveWidget(panel->oldsB, 16, 32);
	WMSetButtonImagePosition(panel->oldsB, WIPImageOnly);
	path = LocateImage(OLDS_IMAGE);
	if (path) {
		icon = WMCreatePixmapFromFile(scr, path);
		if (icon) {
			WMSetButtonImage(panel->oldsB, icon);
			WMReleasePixmap(icon);
		}
		wfree(path);
	}

	panel->newsB = WMCreateButton(panel->titlF, WBTOnOff);
	WMResizeWidget(panel->newsB, 60, 40);
	WMMoveWidget(panel->newsB, 76, 32);
	WMSetButtonImagePosition(panel->newsB, WIPImageOnly);
	path = LocateImage(NEWS_IMAGE);
	if (path) {
		icon = WMCreatePixmapFromFile(scr, path);
		if (icon) {
			WMSetButtonImage(panel->newsB, icon);
			WMReleasePixmap(icon);
		}
		wfree(path);
	}

	panel->nextB = WMCreateButton(panel->titlF, WBTOnOff);
	WMResizeWidget(panel->nextB, 60, 40);
	WMMoveWidget(panel->nextB, 136, 32);
	WMSetButtonImagePosition(panel->nextB, WIPImageOnly);
	path = LocateImage(NEXT_IMAGE);
	if (path) {
		icon = WMCreatePixmapFromFile(scr, path);
		if (icon) {
			WMSetButtonImage(panel->nextB, icon);
			WMReleasePixmap(icon);
		}
		wfree(path);
	}

	WMGroupButtons(panel->newsB, panel->oldsB);
	WMGroupButtons(panel->newsB, panel->nextB);

	WMMapSubwidgets(panel->titlF);

    /**************** Features ******************/
	panel->animF = WMCreateFrame(panel->box);
	WMResizeWidget(panel->animF, 173, 100);
	WMMoveWidget(panel->animF, 237, 10);
	WMSetFrameTitle(panel->animF, _("Animations"));

	panel->animB = WMCreateButton(panel->animF, WBTToggle);
	WMResizeWidget(panel->animB, 64, 64);
	WMMoveWidget(panel->animB, 15, 23);
	WMSetButtonFont(panel->animB, font);
	WMSetButtonText(panel->animB, _("Animations"));
	WMSetButtonImagePosition(panel->animB, WIPAbove);
	CreateImages(scr, rc, xis, ANIM_IMAGE, &altIcon, &icon);
	if (icon) {
		WMSetButtonImage(panel->animB, icon);
		WMReleasePixmap(icon);
	}
	if (altIcon) {
		WMSetButtonAltImage(panel->animB, altIcon);
		WMReleasePixmap(altIcon);
	}
	WMSetBalloonTextForView(_("Disable/enable animations such as those shown\n"
				  "for window miniaturization, shading etc."), WMWidgetView(panel->animB));

	panel->supB = WMCreateButton(panel->animF, WBTToggle);
	WMResizeWidget(panel->supB, 64, 64);
	WMMoveWidget(panel->supB, 94, 23);
	WMSetButtonFont(panel->supB, font);
	WMSetButtonText(panel->supB, _("Superfluous"));
	WMSetButtonImagePosition(panel->supB, WIPAbove);
	CreateImages(scr, rc, xis, SUPERF_IMAGE, &altIcon, &icon);
	if (icon) {
		WMSetButtonImage(panel->supB, icon);
		WMReleasePixmap(icon);
	}
	if (altIcon) {
		WMSetButtonAltImage(panel->supB, altIcon);
		WMReleasePixmap(altIcon);
	}
	WMSetBalloonTextForView(_("Disable/enable `superfluous' features and\n"
				  "animations. These include the `ghosting' of the\n"
				  "dock when it's being moved to another side and\n"
				  "the explosion animation when undocking icons."), WMWidgetView(panel->supB));

	WMMapSubwidgets(panel->animF);

    /*********** Dithering **********/
	panel->cmapSize = 4;

	panel->dithF = WMCreateFrame(panel->box);
	WMResizeWidget(panel->dithF, 277, 97);
	WMMoveWidget(panel->dithF, 237, 120);
	WMSetFrameTitle(panel->dithF, _("Dithering colormap for 8bpp"));

	WMSetBalloonTextForView(_("Number of colors to reserve for Window Maker\n"
				  "on displays that support only 8bpp (PseudoColor)."),
				WMWidgetView(panel->dithF));

	panel->dithB = WMCreateSwitchButton(panel->dithF);
	WMResizeWidget(panel->dithB, 235, 32);
	WMMoveWidget(panel->dithB, 15, 15);
	WMSetButtonText(panel->dithB, _("Disable dithering in any visual/depth"));

	panel->dithL = WMCreateLabel(panel->dithF);
	WMResizeWidget(panel->dithL, 75, 16);
	WMMoveWidget(panel->dithL, 98, 50);
	WMSetLabelTextAlignment(panel->dithL, WACenter);
	WMSetLabelText(panel->dithL, "64");

	panel->dithS = WMCreateSlider(panel->dithF);
	WMResizeWidget(panel->dithS, 95, 16);
	WMMoveWidget(panel->dithS, 90, 65);
	WMSetSliderMinValue(panel->dithS, 2);
	WMSetSliderMaxValue(panel->dithS, 6);
	WMSetSliderContinuous(panel->dithS, True);
	WMSetSliderAction(panel->dithS, updateLabel, panel);

	panel->dith1L = WMCreateLabel(panel->dithF);
	WMResizeWidget(panel->dith1L, 80, 35);
	WMMoveWidget(panel->dith1L, 5, 50);
	WMSetLabelTextAlignment(panel->dith1L, WACenter);
	WMSetLabelFont(panel->dith1L, font);
	WMSetLabelText(panel->dith1L, _("More colors for\napplications"));

	panel->dith2L = WMCreateLabel(panel->dithF);
	WMResizeWidget(panel->dith2L, 80, 35);
	WMMoveWidget(panel->dith2L, 190, 50);
	WMSetLabelTextAlignment(panel->dith2L, WACenter);
	WMSetLabelFont(panel->dith2L, font);
	WMSetLabelText(panel->dith2L, _("More colors for\nWindow Maker"));

	WMMapSubwidgets(panel->dithF);

	WMRealizeWidget(panel->box);
	WMMapSubwidgets(panel->box);

	if (xis)
		RReleaseImage(xis);
	WMReleaseFont(font);
	showData(panel);
}
Beispiel #11
0
void testGradientButtons(WMScreen * scr)
{
	WMWindow *win;
	WMButton *btn;
	WMPixmap *pix1, *pix2;
	RImage *back;
	RColor light, dark;
	WMColor *color, *altColor;

	windowCount++;

	/* creates the top-level window */
	win = WMCreateWindow(scr, "testGradientButtons");
	WMSetWindowTitle(win, "Gradiented Button Demo");
	WMResizeWidget(win, 300, 200);

	WMSetWindowCloseAction(win, closeAction, NULL);

	light.red = 0x90;
	light.green = 0x85;
	light.blue = 0x90;
	dark.red = 0x35;
	dark.green = 0x30;
	dark.blue = 0x35;

	color = WMCreateRGBColor(scr, 0x5900, 0x5100, 0x5900, True);
	WMSetWidgetBackgroundColor(win, color);
	WMReleaseColor(color);

	back = RRenderGradient(60, 24, &dark, &light, RGRD_DIAGONAL);
	RBevelImage(back, RBEV_RAISED2);
	pix1 = WMCreatePixmapFromRImage(scr, back, 0);
	RReleaseImage(back);

	back = RRenderGradient(60, 24, &dark, &light, RGRD_DIAGONAL);
	RBevelImage(back, RBEV_SUNKEN);
	pix2 = WMCreatePixmapFromRImage(scr, back, 0);
	RReleaseImage(back);

	color = WMWhiteColor(scr);
	altColor = WMCreateNamedColor(scr, "red", True);

	btn = WMCreateButton(win, WBTMomentaryChange);
	WMResizeWidget(btn, 60, 24);
	WMMoveWidget(btn, 20, 100);
	WMSetButtonBordered(btn, False);
	WMSetButtonImagePosition(btn, WIPOverlaps);
	WMSetButtonImage(btn, pix1);
	WMSetButtonAltImage(btn, pix2);
	WMSetButtonText(btn, "Cool");
	WMSetButtonTextColor(btn, color);
	WMSetButtonAltTextColor(btn, altColor);

	WMSetBalloonTextForView("This is a cool button", WMWidgetView(btn));

	btn = WMCreateButton(win, WBTMomentaryChange);
	WMResizeWidget(btn, 60, 24);
	WMMoveWidget(btn, 90, 100);
	WMSetButtonBordered(btn, False);
	WMSetButtonImagePosition(btn, WIPOverlaps);
	WMSetButtonImage(btn, pix1);
	WMSetButtonAltImage(btn, pix2);
	WMSetButtonText(btn, "Button");
	WMSetButtonTextColor(btn, color);

	WMSetBalloonTextForView("Este é outro balão.", WMWidgetView(btn));

	WMReleaseColor(color);
	color = WMCreateNamedColor(scr, "orange", True);

	btn = WMCreateButton(win, WBTMomentaryChange);
	WMResizeWidget(btn, 60, 24);
	WMMoveWidget(btn, 160, 100);
	WMSetButtonBordered(btn, False);
	WMSetButtonImagePosition(btn, WIPOverlaps);
	WMSetButtonImage(btn, pix1);
	WMSetButtonAltImage(btn, pix2);
	WMSetButtonText(btn, "Test");
	WMSetButtonTextColor(btn, color);

	WMSetBalloonTextForView("This is yet another button.\nBut the balloon has 3 lines.\nYay!",
				WMWidgetView(btn));

	WMReleaseColor(color);
	WMReleaseColor(altColor);

	WMRealizeWidget(win);
	WMMapSubwidgets(win);
	WMMapWidget(win);
}
Beispiel #12
0
RImage*
RGetImageFromXPMData(RContext *context, char **xpmData)
{
    Display *dpy = context->dpy;
    Colormap cmap = context->cmap;
    RImage *image;
    XpmImage xpm;
    unsigned char *color_table[4];
    unsigned char *data;
    int *p;
    int i;

    i = XpmCreateXpmImageFromData(xpmData, &xpm, (XpmInfo *)NULL);
    if (i!=XpmSuccess) {
        switch (i) {
        case XpmOpenFailed:
            RErrorCode = RERR_OPEN;
            break;
        case XpmFileInvalid:
            RErrorCode = RERR_BADIMAGEFILE;
            break;
        case XpmNoMemory:
            RErrorCode = RERR_NOMEMORY;
            break;
        default:
            RErrorCode = RERR_BADIMAGEFILE;
            break;
        }
        return NULL;
    }
    if (xpm.height<1 || xpm.width < 1) {
        RErrorCode = RERR_BADIMAGEFILE;
        XpmFreeXpmImage(&xpm);
        return NULL;
    }

    if (xpm.colorTable==NULL) {
        RErrorCode = RERR_BADIMAGEFILE;
        XpmFreeXpmImage(&xpm);
        return NULL;
    }
    image = RCreateImage(xpm.width, xpm.height, True);
    if (!image) {
        XpmFreeXpmImage(&xpm);
        return NULL;
    }

    /* make color table */
    for (i=0; i<4; i++) {
        color_table[i] = malloc(xpm.ncolors*sizeof(char));
        if (!color_table[i]) {
            for (i=i-1;i>=0; i--) {
                if (color_table[i])
                    free(color_table[i]);
            }
            RReleaseImage(image);
            RErrorCode = RERR_NOMEMORY;
            XpmFreeXpmImage(&xpm);
            return NULL;
        }
    }

    for (i=0; i<xpm.ncolors; i++) {
        XColor xcolor;
        char * color = NULL;

        if (xpm.colorTable[i].c_color)
            color = xpm.colorTable[i].c_color;
        else if (xpm.colorTable[i].g_color)
            color = xpm.colorTable[i].g_color;
        else if (xpm.colorTable[i].g4_color)
            color = xpm.colorTable[i].g4_color;
        else if (xpm.colorTable[i].m_color)
            color = xpm.colorTable[i].m_color;
        else if (xpm.colorTable[i].symbolic)
            color = xpm.colorTable[i].symbolic;

        if (!color) {
            color_table[0][i] = 0xbe;
            color_table[1][i] = 0xbe;
            color_table[2][i] = 0xbe;
            color_table[3][i] = 0xff;
            continue;
        }

        if (strncmp(color,"None",4)==0) {
            color_table[0][i]=0;
            color_table[1][i]=0;
            color_table[2][i]=0;
            color_table[3][i]=0;
            continue;
        }
        if (XParseColor(dpy, cmap, color, &xcolor)) {
            color_table[0][i] = xcolor.red>>8;
            color_table[1][i] = xcolor.green>>8;
            color_table[2][i] = xcolor.blue>>8;
            color_table[3][i] = 0xff;
        } else {
Beispiel #13
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
Beispiel #14
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;
	}
}
Beispiel #15
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;
}
Beispiel #16
0
RImage *RLoadPNG(RContext *context, const char *file)
{
	char *tmp;
	RImage *image = NULL;
	FILE *f;
	png_structp png;
	png_infop pinfo, einfo;
	png_color_16p bkcolor;
	int alpha;
	int x, y, i;
	double gamma, sgamma;
	png_uint_32 width, height;
	int depth, junk, color_type;
	png_bytep *png_rows;
	unsigned char *ptr;

	f = fopen(file, "rb");
	if (!f) {
		RErrorCode = RERR_OPEN;
		return NULL;
	}
	png = png_create_read_struct(PNG_LIBPNG_VER_STRING, NULL, (png_error_ptr) NULL, (png_error_ptr) NULL);
	if (!png) {
		RErrorCode = RERR_NOMEMORY;
		fclose(f);
		return NULL;
	}

	pinfo = png_create_info_struct(png);
	if (!pinfo) {
		RErrorCode = RERR_NOMEMORY;
		fclose(f);
		png_destroy_read_struct(&png, NULL, NULL);
		return NULL;
	}

	einfo = png_create_info_struct(png);
	if (!einfo) {
		RErrorCode = RERR_NOMEMORY;
		fclose(f);
		png_destroy_read_struct(&png, &pinfo, NULL);
		return NULL;
	}

	RErrorCode = RERR_INTERNAL;
#if PNG_LIBPNG_VER - 0 < 10400
	if (setjmp(png->jmpbuf)) {
#else
	if (setjmp(png_jmpbuf(png))) {
#endif
		fclose(f);
		png_destroy_read_struct(&png, &pinfo, &einfo);
		if (image)
			RReleaseImage(image);
		return NULL;
	}

	png_init_io(png, f);

	png_read_info(png, pinfo);

	png_get_IHDR(png, pinfo, &width, &height, &depth, &color_type, &junk, &junk, &junk);

	/* sanity check */
	if (width < 1 || height < 1) {
		fclose(f);
		png_destroy_read_struct(&png, &pinfo, &einfo);
		RErrorCode = RERR_BADIMAGEFILE;
		return NULL;
	}

	/* check for an alpha channel */
	if (png_get_valid(png, pinfo, PNG_INFO_tRNS))
		alpha = True;
	else
		alpha = (color_type & PNG_COLOR_MASK_ALPHA);

	/* allocate RImage */
	image = RCreateImage(width, height, alpha);
	if (!image) {
		fclose(f);
		png_destroy_read_struct(&png, &pinfo, &einfo);
		return NULL;
	}

	/* normalize to 8bpp with alpha channel */
	if (color_type == PNG_COLOR_TYPE_PALETTE && depth <= 8)
		png_set_expand(png);

	if (color_type == PNG_COLOR_TYPE_GRAY && depth <= 8)
		png_set_expand(png);

	if (png_get_valid(png, pinfo, PNG_INFO_tRNS))
		png_set_expand(png);

	if (depth == 16)
		png_set_strip_16(png);

	if (color_type == PNG_COLOR_TYPE_GRAY || color_type == PNG_COLOR_TYPE_GRAY_ALPHA)
		png_set_gray_to_rgb(png);

	/* set gamma correction */
	if ((context->attribs->flags & RC_GammaCorrection)
	    && context->depth != 8) {
		sgamma = (context->attribs->rgamma + context->attribs->ggamma + context->attribs->bgamma) / 3;
	} else if ((tmp = getenv("DISPLAY_GAMMA")) != NULL) {
		sgamma = atof(tmp);
		if (sgamma < 1.0E-3)
			sgamma = 1;
	} else {
		/* blah */
		sgamma = 2.2;
	}

	if (png_get_gAMA(png, pinfo, &gamma))
		png_set_gamma(png, sgamma, gamma);
	else
		png_set_gamma(png, sgamma, 0.45);

	/* do the transforms */
	png_read_update_info(png, pinfo);

	/* set background color */
	if (png_get_bKGD(png, pinfo, &bkcolor)) {
		image->background.red = bkcolor->red >> 8;
		image->background.green = bkcolor->green >> 8;
		image->background.blue = bkcolor->blue >> 8;
	}

	png_rows = calloc(height, sizeof(char *));
	if (!png_rows) {
		RErrorCode = RERR_NOMEMORY;
		fclose(f);
		RReleaseImage(image);
		png_destroy_read_struct(&png, &pinfo, &einfo);
		return NULL;
	}
	for (y = 0; y < height; y++) {
		png_rows[y] = malloc(png_get_rowbytes(png, pinfo));
		if (!png_rows[y]) {
			RErrorCode = RERR_NOMEMORY;
			fclose(f);
			RReleaseImage(image);
			png_destroy_read_struct(&png, &pinfo, &einfo);
			while (y-- > 0)
				if (png_rows[y])
					free(png_rows[y]);
			free(png_rows);
			return NULL;
		}
	}
	/* read data */
	png_read_image(png, png_rows);

	png_read_end(png, einfo);

	png_destroy_read_struct(&png, &pinfo, &einfo);

	fclose(f);

	ptr = image->data;

	/* convert to RImage */
	if (alpha) {
		for (y = 0; y < height; y++) {
			for (x = 0, i = width * 4; x < i; x++, ptr++) {
				*ptr = *(png_rows[y] + x);
			}
		}
	} else {
		for (y = 0; y < height; y++) {
			for (x = 0, i = width * 3; x < i; x++, ptr++) {
				*ptr = *(png_rows[y] + x);
			}
		}
	}
	for (y = 0; y < height; y++)
		if (png_rows[y])
			free(png_rows[y]);
	free(png_rows);
	return image;
}
Beispiel #17
0
/*
 * Partially based on code in gif2rgb from giflib, by Gershon Elber.
 */
RImage *RLoadGIF(const char *file, int index)
{
	RImage *image = NULL;
	unsigned char *cptr;
	GifFileType *gif = NULL;
	GifPixelType *buffer = NULL;
	int i, j, k;
	int width, height;
	GifRecordType recType;
	ColorMapObject *colormap;
	unsigned char rmap[256];
	unsigned char gmap[256];
	unsigned char bmap[256];

	if (index < 0)
		index = 0;

	/* default error message */
	RErrorCode = RERR_BADINDEX;

	gif = DGifOpenFileName(file);

	if (!gif) {
		switch (GifLastError()) {
		case D_GIF_ERR_OPEN_FAILED:
			RErrorCode = RERR_OPEN;
			break;
		case D_GIF_ERR_READ_FAILED:
			RErrorCode = RERR_READ;
			break;
		default:
			RErrorCode = RERR_BADIMAGEFILE;
			break;
		}
		return NULL;
	}

	if (gif->SWidth < 1 || gif->SHeight < 1) {
		DGifCloseFile(gif);
		RErrorCode = RERR_BADIMAGEFILE;
		return NULL;
	}

	colormap = gif->SColorMap;

	i = 0;

	do {
		int extCode;
		GifByteType *extension;

		if (DGifGetRecordType(gif, &recType) == GIF_ERROR) {
			goto giferr;
		}
		switch (recType) {
		case IMAGE_DESC_RECORD_TYPE:
			if (i++ != index)
				break;

			if (DGifGetImageDesc(gif) == GIF_ERROR) {
				goto giferr;
			}

			width = gif->Image.Width;
			height = gif->Image.Height;

			if (gif->Image.ColorMap)
				colormap = gif->Image.ColorMap;

			/* the gif specs talk about a default colormap, but it
			 * doesnt say what the heck is this default colormap */
			if (!colormap) {
				/*
				 * Well, since the spec says the colormap can be anything,
				 * lets just render it with whatever garbage the stack
				 * has :)
				 *

				 goto bye;
				 */
			} else {
				for (j = 0; j < colormap->ColorCount; j++) {
					rmap[j] = colormap->Colors[j].Red;
					gmap[j] = colormap->Colors[j].Green;
					bmap[j] = colormap->Colors[j].Blue;
				}
			}

			buffer = malloc(width * sizeof(GifColorType));
			if (!buffer) {
				RErrorCode = RERR_NOMEMORY;
				goto bye;
			}

			image = RCreateImage(width, height, False);
			if (!image) {
				goto bye;
			}

			if (gif->Image.Interlace) {
				int l;
				int pelsPerLine;

				if (RRGBAFormat == image->format)
					pelsPerLine = width * 4;
				else
					pelsPerLine = width * 3;

				for (j = 0; j < 4; j++) {
					for (k = InterlacedOffset[j]; k < height; k += InterlacedJumps[j]) {
						if (DGifGetLine(gif, buffer, width) == GIF_ERROR) {
							goto giferr;
						}
						cptr = image->data + (k * pelsPerLine);
						for (l = 0; l < width; l++) {
							int pixel = buffer[l];
							*cptr++ = rmap[pixel];
							*cptr++ = gmap[pixel];
							*cptr++ = bmap[pixel];
						}
					}
				}
			} else {
				cptr = image->data;
				for (j = 0; j < height; j++) {
					if (DGifGetLine(gif, buffer, width) == GIF_ERROR) {
						goto giferr;
					}
					for (k = 0; k < width; k++) {
						int pixel = buffer[k];
						*cptr++ = rmap[pixel];
						*cptr++ = gmap[pixel];
						*cptr++ = bmap[pixel];
						if (RRGBAFormat == image->format)
							cptr++;
					}
				}
			}
			break;

		case EXTENSION_RECORD_TYPE:
			/* skip all extension blocks */
			if (DGifGetExtension(gif, &extCode, &extension) == GIF_ERROR) {
				goto giferr;
			}
			while (extension) {
				if (DGifGetExtensionNext(gif, &extension) == GIF_ERROR) {
					goto giferr;
				}
			}
			break;

		default:
			break;
		}
	} while (recType != TERMINATE_RECORD_TYPE && i <= index);

	/* yuck! */
	goto did_not_get_any_errors;
 giferr:
	switch (GifLastError()) {
	case D_GIF_ERR_OPEN_FAILED:
		RErrorCode = RERR_OPEN;
		break;
	case D_GIF_ERR_READ_FAILED:
		RErrorCode = RERR_READ;
		break;
	default:
		RErrorCode = RERR_BADIMAGEFILE;
		break;
	}
 bye:
	if (image)
		RReleaseImage(image);
	image = NULL;
 did_not_get_any_errors:

	if (buffer)
		free(buffer);

	if (gif)
		DGifCloseFile(gif);

	return image;
}
Beispiel #18
0
static void showWorkspaceName(WScreen * scr, int workspace)
{
	WorkspaceNameData *data;
	RXImage *ximg;
	Pixmap text, mask;
	int w, h;
	int px, py;
	char *name = w_global.workspace.array[workspace]->name;
	int len = strlen(name);
	int x, y;
#ifdef USE_XINERAMA
	int head;
	WMRect rect;
	int xx, yy;
#endif

	if (wPreferences.workspace_name_display_position == WD_NONE || w_global.workspace.count < 2)
		return;

	if (scr->workspace_name_timer) {
		WMDeleteTimerHandler(scr->workspace_name_timer);
		XUnmapWindow(dpy, scr->workspace_name);
		XFlush(dpy);
	}
	scr->workspace_name_timer = WMAddTimerHandler(WORKSPACE_NAME_DELAY, hideWorkspaceName, scr);

	if (scr->workspace_name_data) {
		RReleaseImage(scr->workspace_name_data->back);
		RReleaseImage(scr->workspace_name_data->text);
		wfree(scr->workspace_name_data);
	}

	data = wmalloc(sizeof(WorkspaceNameData));
	data->back = NULL;

	w = WMWidthOfString(w_global.workspace.font_for_name, name, len);
	h = WMFontHeight(w_global.workspace.font_for_name);

#ifdef USE_XINERAMA
	head = wGetHeadForPointerLocation(scr);
	rect = wGetRectForHead(scr, head);
	if (scr->xine_info.count) {
		xx = rect.pos.x + (scr->xine_info.screens[head].size.width - (w + 4)) / 2;
		yy = rect.pos.y + (scr->xine_info.screens[head].size.height - (h + 4)) / 2;
	}
	else {
		xx = (scr->scr_width - (w + 4)) / 2;
		yy = (scr->scr_height - (h + 4)) / 2;
	}
#endif

	switch (wPreferences.workspace_name_display_position) {
	case WD_TOP:
#ifdef USE_XINERAMA
		px = xx;
#else
		px = (scr->scr_width - (w + 4)) / 2;
#endif
		py = WORKSPACE_NAME_DISPLAY_PADDING;
		break;
	case WD_BOTTOM:
#ifdef USE_XINERAMA
		px = xx;
#else
		px = (scr->scr_width - (w + 4)) / 2;
#endif
		py = scr->scr_height - (h + 4 + WORKSPACE_NAME_DISPLAY_PADDING);
		break;
	case WD_TOPLEFT:
		px = WORKSPACE_NAME_DISPLAY_PADDING;
		py = WORKSPACE_NAME_DISPLAY_PADDING;
		break;
	case WD_TOPRIGHT:
		px = scr->scr_width - (w + 4 + WORKSPACE_NAME_DISPLAY_PADDING);
		py = WORKSPACE_NAME_DISPLAY_PADDING;
		break;
	case WD_BOTTOMLEFT:
		px = WORKSPACE_NAME_DISPLAY_PADDING;
		py = scr->scr_height - (h + 4 + WORKSPACE_NAME_DISPLAY_PADDING);
		break;
	case WD_BOTTOMRIGHT:
		px = scr->scr_width - (w + 4 + WORKSPACE_NAME_DISPLAY_PADDING);
		py = scr->scr_height - (h + 4 + WORKSPACE_NAME_DISPLAY_PADDING);
		break;
	case WD_CENTER:
	default:
#ifdef USE_XINERAMA
		px = xx;
		py = yy;
#else
		px = (scr->scr_width - (w + 4)) / 2;
		py = (scr->scr_height - (h + 4)) / 2;
#endif
		break;
	}
	XResizeWindow(dpy, scr->workspace_name, w + 4, h + 4);
	XMoveWindow(dpy, scr->workspace_name, px, py);

	text = XCreatePixmap(dpy, scr->w_win, w + 4, h + 4, scr->w_depth);
	mask = XCreatePixmap(dpy, scr->w_win, w + 4, h + 4, 1);

	/*XSetForeground(dpy, scr->mono_gc, 0);
	   XFillRectangle(dpy, mask, scr->mono_gc, 0, 0, w+4, h+4); */

	XFillRectangle(dpy, text, WMColorGC(scr->black), 0, 0, w + 4, h + 4);

	for (x = 0; x <= 4; x++)
		for (y = 0; y <= 4; y++)
			WMDrawString(scr->wmscreen, text, scr->white, w_global.workspace.font_for_name, x, y, name, len);

	XSetForeground(dpy, scr->mono_gc, 1);
	XSetBackground(dpy, scr->mono_gc, 0);

	XCopyPlane(dpy, text, mask, scr->mono_gc, 0, 0, w + 4, h + 4, 0, 0, 1 << (scr->w_depth - 1));

	/*XSetForeground(dpy, scr->mono_gc, 1); */
	XSetBackground(dpy, scr->mono_gc, 1);

	XFillRectangle(dpy, text, WMColorGC(scr->black), 0, 0, w + 4, h + 4);

	WMDrawString(scr->wmscreen, text, scr->white, w_global.workspace.font_for_name, 2, 2, name, len);

#ifdef USE_XSHAPE
	if (w_global.xext.shape.supported)
		XShapeCombineMask(dpy, scr->workspace_name, ShapeBounding, 0, 0, mask, ShapeSet);
#endif
	XSetWindowBackgroundPixmap(dpy, scr->workspace_name, text);
	XClearWindow(dpy, scr->workspace_name);

	data->text = RCreateImageFromDrawable(scr->rcontext, text, None);

	XFreePixmap(dpy, text);
	XFreePixmap(dpy, mask);

	if (!data->text) {
		XMapRaised(dpy, scr->workspace_name);
		XFlush(dpy);

		goto erro;
	}

	ximg = RGetXImage(scr->rcontext, scr->root_win, px, py, data->text->width, data->text->height);

	if (!ximg || !ximg->image) {
		goto erro;
	}

	XMapRaised(dpy, scr->workspace_name);
	XFlush(dpy);

	data->back = RCreateImageFromXImage(scr->rcontext, ximg->image, NULL);
	RDestroyXImage(scr->rcontext, ximg);

	if (!data->back) {
		goto erro;
	}

	data->count = 10;

	/* set a timeout for the effect */
	data->timeout = time(NULL) + 2 + (WORKSPACE_NAME_DELAY + WORKSPACE_NAME_FADE_DELAY * data->count) / 1000;

	scr->workspace_name_data = data;

	return;

 erro:
	if (scr->workspace_name_timer)
		WMDeleteTimerHandler(scr->workspace_name_timer);

	if (data->text)
		RReleaseImage(data->text);
	if (data->back)
		RReleaseImage(data->back);
	wfree(data);

	scr->workspace_name_data = NULL;

	scr->workspace_name_timer = WMAddTimerHandler(WORKSPACE_NAME_DELAY +
						      10 * WORKSPACE_NAME_FADE_DELAY, hideWorkspaceName, scr);
}
Beispiel #19
0
static void createPanel(Panel *p)
{
	_Panel *panel = (_Panel *) p;
	WMScreen *scr = WMWidgetScreen(panel->parent);
	WMPixmap *icon1, *icon2;
	RImage *xis = NULL;
	RContext *rc = WMScreenRContext(scr);
	char *path;
	int i, j, k;
	char *buf1, *buf2;

	path = LocateImage(ARQUIVO_XIS);
	if (path) {
		xis = RLoadImage(rc, path, 0);
		if (!xis) {
			wwarning(_("could not load image file %s"), path);
		}
		wfree(path);
	}

	panel->box = WMCreateBox(panel->parent);
	WMSetViewExpandsToParent(WMWidgetView(panel->box), 2, 2, 2, 2);

	/***************** Auto-delays *****************/
	buf1 = wmalloc(strlen(DELAY_ICON) + 1);
	buf2 = wmalloc(strlen(DELAY_ICON_S) + 1);

	for (k = 0; k < 2; k++)
	{
		panel->autoDelayF[k] = WMCreateFrame(panel->box);
		WMResizeWidget(panel->autoDelayF[k], 365, 100);
		WMMoveWidget(panel->autoDelayF[k], 15, 10 + k * 110);
		if (k == 0)
			WMSetFrameTitle(panel->autoDelayF[k], _("Delays in milliseconds for autocollapsing clips"));
		else
			WMSetFrameTitle(panel->autoDelayF[k], _("Delays in milliseconds for autoraising clips"));

		for (i = 0; i < 2; i++)
		{
			panel->autoDelayL[i + k * 2] = WMCreateLabel(panel->autoDelayF[k]);
			WMResizeWidget(panel->autoDelayL[i + k * 2], 165, 20);
			WMMoveWidget(panel->autoDelayL[i + k * 2], 10, 27 + 40 * i);
			WMSetLabelText(panel->autoDelayL[i + k * 2], _(auto_delay[i + k * 2].string));
			WMSetLabelTextAlignment(panel->autoDelayL[i + k * 2], WARight);

			for (j = 0; j < 5; j++)
			{
				panel->autoDelayB[i + k * 2][j] = WMCreateCustomButton(panel->autoDelayF[k], WBBStateChangeMask);
				WMResizeWidget(panel->autoDelayB[i + k * 2][j], 25, 25);
				WMMoveWidget(panel->autoDelayB[i + k * 2][j], 175 + (25 * j), 25 + 40 * i);
				WMSetButtonBordered(panel->autoDelayB[i + k * 2][j], False);
				WMSetButtonImagePosition(panel->autoDelayB[i + k * 2][j], WIPImageOnly);
				WMSetButtonAction(panel->autoDelayB[i + k * 2][j], pushAutoDelayButton, panel);
				if (j > 0)
					WMGroupButtons(panel->autoDelayB[i + k * 2][0], panel->autoDelayB[i + k * 2][j]);
				sprintf(buf1, DELAY_ICON, j);
				CreateImages(scr, rc, NULL, buf1, &icon1, NULL);
				if (icon1) {
					WMSetButtonImage(panel->autoDelayB[i + k * 2][j], icon1);
					WMReleasePixmap(icon1);
				} else {
					wwarning(_("could not load icon file %s"), buf1);
				}
				sprintf(buf2, DELAY_ICON_S, j);
				CreateImages(scr, rc, NULL, buf2, &icon2, NULL);
				if (icon2) {
					WMSetButtonAltImage(panel->autoDelayB[i + k * 2][j], icon2);
					WMReleasePixmap(icon2);
				} else {
					wwarning(_("could not load icon file %s"), buf2);
				}
			}

			panel->autoDelayT[i + k * 2] = WMCreateTextField(panel->autoDelayF[k]);
			WMResizeWidget(panel->autoDelayT[i + k * 2], 36, 20);
			WMMoveWidget(panel->autoDelayT[i + k * 2], 310, 27 + 40 * i);
			WMAddNotificationObserver(autoDelayChanged, panel, WMTextDidChangeNotification, panel->autoDelayT[i + k * 2]);
		}

		WMMapSubwidgets(panel->autoDelayF[k]);
	}
	wfree(buf1);
	wfree(buf2);

	/***************** Enable/disable clip/dock/drawers *****************/
	panel->dockF = WMCreateFrame(panel->box);
	WMResizeWidget(panel->dockF, 115, 210);
	WMMoveWidget(panel->dockF, 390, 10);
	WMSetFrameTitle(panel->dockF, _("Dock/Clip/Drawer"));

	for (i = 0; i < 3; i++)
	{
		panel->docksB[i] = WMCreateButton(panel->dockF, WBTToggle);
		WMResizeWidget(panel->docksB[i], 56, 56);
		WMMoveWidget(panel->docksB[i], 30, 20 + 62 * i);
		WMSetButtonImagePosition(panel->docksB[i], WIPImageOnly);
		CreateImages(scr, rc, xis, dock_config[i].icon_file, &icon1, &icon2);
		if (icon2) {
			WMSetButtonImage(panel->docksB[i], icon2);
			WMReleasePixmap(icon2);
		}
		if (icon1) {
			WMSetButtonAltImage(panel->docksB[i], icon1);
			WMReleasePixmap(icon1);
		}
		switch(i)
		{
		case 0:
			WMSetBalloonTextForView(_("Disable/enable the application Dock (the\n"
						  "vertical icon bar in the side of the screen)."), WMWidgetView(panel->docksB[i]));
			break;
		case 1:
			WMSetBalloonTextForView(_("Disable/enable the Clip (that thing with\n"
						  "a paper clip icon)."), WMWidgetView(panel->docksB[i]));
			break;
		case 2:
			WMSetBalloonTextForView(_("Disable/enable Drawers (a dock that stores\n"
						  "application icons horizontally). The dock is required."), WMWidgetView(panel->docksB[i]));
			break;
		}
		WMSetButtonAction(panel->docksB[i], pushDockButton, panel);
	}
	
	WMMapSubwidgets(panel->dockF);

	if (xis)
		RReleaseImage(xis);

	WMRealizeWidget(panel->box);
	WMMapSubwidgets(panel->box);

	showData(panel);
}
Beispiel #20
0
RImage *RLoadImage(RContext * context, const char *file, int index)
{
	RImage *image = NULL;
	int i;
	struct stat st;

	assert(file != NULL);

	if (RImageCacheSize < 0) {
		init_cache();
	}

	if (RImageCacheSize > 0) {

		for (i = 0; i < RImageCacheSize; i++) {
			if (RImageCache[i].file && strcmp(file, RImageCache[i].file) == 0) {

				if (stat(file, &st) == 0 && st.st_mtime == RImageCache[i].last_modif) {
					RImageCache[i].last_use = time(NULL);

					return RCloneImage(RImageCache[i].image);

				} else {
					free(RImageCache[i].file);
					RImageCache[i].file = NULL;
					RReleaseImage(RImageCache[i].image);
				}
			}
		}
	}

	switch (identFile(file)) {
	case IM_ERROR:
		return NULL;

	case IM_UNKNOWN:
		RErrorCode = RERR_BADFORMAT;
		return NULL;

	case IM_XPM:
		image = RLoadXPM(context, file);
		break;

#ifdef USE_TIFF
	case IM_TIFF:
		image = RLoadTIFF(file, index);
		break;
#endif				/* USE_TIFF */

#ifdef USE_PNG
	case IM_PNG:
		image = RLoadPNG(context, file);
		break;
#endif				/* USE_PNG */

#ifdef USE_JPEG
	case IM_JPEG:
		image = RLoadJPEG(context, file);
		break;
#endif				/* USE_JPEG */

#ifdef USE_GIF
	case IM_GIF:
		image = RLoadGIF(file, index);
		break;
#endif				/* USE_GIF */

	case IM_PPM:
		image = RLoadPPM(file);
		break;

	default:
		RErrorCode = RERR_BADFORMAT;
		return NULL;
	}

	/* store image in cache */
	if (RImageCacheSize > 0 && image &&
	    (RImageCacheMaxImage == 0 || RImageCacheMaxImage >= image->width * image->height)) {
		time_t oldest = time(NULL);
		int oldest_idx = 0;
		int done = 0;

		for (i = 0; i < RImageCacheSize; i++) {
			if (!RImageCache[i].file) {
				RImageCache[i].file = malloc(strlen(file) + 1);
				strcpy(RImageCache[i].file, file);
				RImageCache[i].image = RCloneImage(image);
				RImageCache[i].last_modif = st.st_mtime;
				RImageCache[i].last_use = time(NULL);
				done = 1;
				break;
			} else {
				if (oldest > RImageCache[i].last_use) {
					oldest = RImageCache[i].last_use;
					oldest_idx = i;
				}
			}
		}

		/* if no slot available, dump least recently used one */
		if (!done) {
			free(RImageCache[oldest_idx].file);
			RReleaseImage(RImageCache[oldest_idx].image);
			RImageCache[oldest_idx].file = malloc(strlen(file) + 1);
			strcpy(RImageCache[oldest_idx].file, file);
			RImageCache[oldest_idx].image = RCloneImage(image);
			RImageCache[oldest_idx].last_modif = st.st_mtime;
			RImageCache[oldest_idx].last_use = time(NULL);
		}
	}

	return image;
}