Exemplo n.º 1
0
/** Draw an image in a drawable
  * \param dr Drawable
  * \param x X position
  * \param y Y position
  * \param name Path of the image
*/
static void draw_image(Drawable dr, int x, int y, int w, int h, char *name)
{
     Imlib_Image image;

     if(!name)
          return;

     imlib_set_cache_size(2048 * 1024);
     imlib_context_set_display(dpy);
     imlib_context_set_visual(DefaultVisual(dpy, DefaultScreen(dpy)));
     imlib_context_set_colormap(DefaultColormap(dpy, DefaultScreen(dpy)));
     imlib_context_set_drawable(dr);

     image = imlib_load_image(patht(name));
     imlib_context_set_image(image);

     if(w <= 0)
          w = imlib_image_get_width();

     if(h <= 0)
          h = imlib_image_get_height();

     if(image)
     {
          imlib_render_image_on_drawable_at_size(x, y, w, h);
          imlib_free_image();
     }
     else
          warnx("Can't draw image: '%s'", name);

     return;
}
Exemplo n.º 2
0
void XImlib2Image::repaint()
{
    XDesktopContainer * xContainer =
	dynamic_cast<XDesktopContainer *>(container);
    
    Imlib_Image cropImage = xContainer->bg->createCropImage(x, y, width, height, width, height);
    
    imlib_context_set_dither(1);

    imlib_context_set_blend(1);       //automatically blend image and background
    imlib_context_set_dither_mask(0);
    imlib_context_set_image(cropImage);
    imlib_blend_image_onto_image(image, 1, 0, 0, width, height, 0, 0, width, height);
    
    imlib_image_set_has_alpha(1);
    
    imlib_context_set_anti_alias(1);  //smoother scaling
    imlib_context_set_blend(0);    
    
    imlib_context_set_drawable(window);
    imlib_render_image_on_drawable_at_size(0, 0, width, height);
    
    imlib_free_image();
    imlib_context_set_drawable(xContainer->getRootWindow());
}
Exemplo n.º 3
0
void
gib_imlib_render_image_on_drawable_at_size(Drawable d, Imlib_Image im, int x,
                                           int y, int w, int h, char dither,
                                           char blend, char alias)
{
   imlib_context_set_image(im);
   imlib_context_set_drawable(d);
   imlib_context_set_anti_alias(alias);
   imlib_context_set_dither(dither);
   imlib_context_set_blend(blend);
   imlib_context_set_angle(0);
   imlib_render_image_on_drawable_at_size(x, y, w, h);
}
Exemplo n.º 4
0
int command_line(int argc, const char **argv) {
	if ( !(dpy=XOpenDisplay(0x0)) ) exit(1);
	scr = DefaultScreen(dpy); root = DefaultRootWindow(dpy);
	sw = DisplayWidth(dpy,scr); sh = DisplayHeight(dpy,scr);
	int i; const char *c;
	for (i = 1; i < argc; i++) {
		if (argv[i][0] != '-') break;
		if ( *(c=argv[i]+1) == '-' ) c++;
		if (*c == '\0') continue;
		if (*c == 'b') win = root;
	}
	if ( !(img=imlib_load_image(argv[i])) ) exit(2);;
	imlib_context_set_image(img);
	imlib_context_set_display(dpy);
	imlib_context_set_visual(DefaultVisual(dpy,scr));
	imlib_context_set_colormap(DefaultColormap(dpy,scr));
	iw = imlib_image_get_width();
	ih = imlib_image_get_height();
	imlib_context_set_anti_alias(0);
	imlib_context_set_dither(0);
	imlib_context_set_blend(0);
	XSetWindowAttributes wa;
	if (win == root) {
		Pixmap buf = XCreatePixmap(dpy,root,sw,sh,DefaultDepth(dpy,scr));
		imlib_context_set_drawable(buf);
		imlib_render_image_on_drawable_at_size(0, 0, sw, sh);
		wa.background_pixmap = buf;
		XSetWindowBackgroundPixmap(dpy,root,buf);
		XFlush(dpy);
		XFreePixmap(dpy,buf);
		XCloseDisplay(dpy);
		exit(0);
	}
	if (iw > mw) scale = mw / (float) iw;
	if (ih * scale > mh) scale = mh / (float) ih;
	ww = iw * scale + 0.5; wh = ih * scale + 0.5;
	wa.background_pixel = BlackPixel(dpy,scr);
	wa.event_mask = KeyPressMask | ExposureMask | StructureNotifyMask;
	win = XCreateWindow(dpy,root,0,0,ww,wh,0,DefaultDepth(dpy,scr),
			InputOutput, DefaultVisual(dpy,scr),CWEventMask|CWBackPixel,&wa);
	const char *name;
	if ( (name=strrchr(argv[i],'/')) ) name++;
	else name = argv[i];
	XStoreName(dpy,win,name);
	class.res_name = (char *) argv[0];
	class.res_class = "float";
	XSetClassHint(dpy,win,&class);
	XMapWindow(dpy,win); XFlush(dpy);
	imlib_context_set_drawable(win);
	return 0;
}
Exemplo n.º 5
0
void
gib_imlib_render_image_on_drawable_at_size_with_rotation(Drawable d,
                                                         Imlib_Image im,
                                                         int x, int y, int w,
                                                         int h, double angle,
                                                         char dither,
                                                         char blend,
                                                         char alias)
{
   Imlib_Image new_im;

   imlib_context_set_image(im);
   imlib_context_set_drawable(d);
   imlib_context_set_anti_alias(alias);
   imlib_context_set_dither(dither);
   imlib_context_set_blend(blend);
   imlib_context_set_angle(angle);
   new_im = imlib_create_rotated_image(angle);
   imlib_context_set_image(new_im);
   imlib_render_image_on_drawable_at_size(x, y, w, h);
   imlib_free_image_and_decache();
}
Exemplo n.º 6
0
void LFSTK_imageClass::LFSTK_clearWindow(void)
{
	if(this->wc->useTile==true) 
		{
			XSetTSOrigin(this->display,this->gc,0-this->gadgetGeom.x,0-this->gadgetGeom.y);
			XSetFillStyle(this->display,this->gc,FillTiled);
			XSetTile(this->display,this->gc,this->wc->tile[0]);
			XFillRectangle(this->display,this->window,this->gc,0,0,this->gadgetGeom.w,this->gadgetGeom.h);
			XSetFillStyle(this->display,this->gc,FillSolid);
		}
	else
		{
			XSetFillStyle(this->display,this->gc,FillSolid);
			XSetForeground(this->display,this->gc,this->wc->windowColourNames[NORMALCOLOUR].pixel);
			XFillRectangle(this->display,this->window,this->gc,0,0,this->gadgetGeom.w,this->gadgetGeom.h);
		}

	if(this->gotIcon==true)
		{
			XSetClipMask(this->display,this->gc,this->icon[1]);
			XSetClipOrigin(this->display,this->gc,0,0);
			XCopyArea(this->display,this->icon[0],this->window,this->gc,0,0,this->iconSize,this->iconSize,0,0);
			XSetClipMask(this->display,this->gc,None);
		}
	else if(this->useImage==true)
		{
			imlib_context_set_display(this->display);
			imlib_context_set_visual(this->visual);
			imlib_context_set_colormap(this->cm);

			imlib_context_set_drawable(this->window);
			imlib_context_set_image(this->image);
			imlib_context_set_blend(1);
			imlib_render_image_on_drawable_at_size(4,(this->gadgetGeom.h/2)-(this->imageHeight/2),this->imageWidth,this->imageHeight); 
		}
}
Exemplo n.º 7
0
int draw() {
	XClearWindow(dpy,win);
	if (fullscreen) imlib_render_image_on_drawable_at_size(wx, wy, ww, wh);
	else imlib_render_image_on_drawable_at_size(0, 0, ww, wh);
	XSync(dpy,True);
}
Exemplo n.º 8
0
int main(int argc, char *argv[])
{
    int b;

    extern int d_depth;
    extern Window iconwin, win;
    Visual *visual;
    XEvent event;
    Pixmap xpm;
    Time lastTime=0;

    Imlib_Image image;

    ParseCMDLine(argc, argv);
    openXwindow(argc, argv, xpm_master, xpm_mask_bits, xpm_mask_width, xpm_mask_height);

    xpm = XCreatePixmap(display, win, 64, 64, d_depth);
    XFillRectangle(display, xpm, NormalGC, 0, 0, 64, 64);

    if (fname) {
	visual = DefaultVisual(display, DefaultScreen(display));

	imlib_context_set_dither(1);
	imlib_context_set_display(display);
	imlib_context_set_visual(visual);

	image = imlib_load_image(fname);
	imlib_context_set_image(image);
	imlib_context_set_drawable(xpm);
	imlib_render_image_on_drawable_at_size(0, 0, isize, isize);
    }
    b = (64-isize)/2;
    /* Loop Forever */
    while (1) {
	/* Process any pending X events. */
	while (XPending(display)) {
	    XNextEvent(display, &event);
	    switch (event.type) {
		case Expose:
		    RedrawWindow();
		    XCopyArea(display, xpm, iconwin, NormalGC, 0, 0, isize, isize, b, b);
		    break;
		case MotionNotify:
		    break;
		case ButtonPress:
		    /*printf("ButtonPress\n");*/
		    break;
		case ButtonRelease:
		    if (event.xbutton.button == Button1) {
			if (event.xbutton.time - lastTime < 250) {
			    if (system(cmd) == -1) {
				fprintf(stdout, "Failed to run command:%s\n", cmd);
				exit(0);
			    }
			} else {
			    lastTime = event.xbutton.time;
			}
		    } else if (event.xbutton.button == Button3) {
			exit(0);
		    }
		    /*printf("ButtonRelease\n");*/
		    break;
	    }
	}
	usleep(10000);
    }
    /* we should never get here */
    return (0);
}
Exemplo n.º 9
0
static int
x11_load_image(w3mimg_op * self, W3MImage * img, char *fname, int w, int h)
{
    struct x11_info *xi;
#if defined(USE_IMLIB)
    ImlibImage *im;
#elif defined(USE_IMLIB2)
    Imlib_Image im;
#elif defined(USE_GDKPIXBUF)
    GdkPixbufAnimation *animation;
    GList *frames;
    int i, j, iw, ih, n, frame_num, delay, max_anim;
    double ratio_w, ratio_h;
    struct x11_image *ximg;
    Pixmap tmp_pixmap;
#endif

    if (self == NULL)
	return 0;
    xi = (struct x11_info *)self->priv;
    if (xi == NULL)
	return 0;

#if defined(USE_IMLIB)
    im = Imlib_load_image(xi->id, fname);
    if (!im)
	return 0;
    if (w <= 0)
	w = im->rgb_width;
    if (h <= 0)
	h = im->rgb_height;
    img->pixmap = (void *)XCreatePixmap(xi->display, xi->parent, w, h,
					DefaultDepth(xi->display, 0));
    if (!img->pixmap)
	return 0;
    XSetForeground(xi->display, xi->imageGC, xi->background_pixel);
    XFillRectangle(xi->display, (Pixmap) img->pixmap, xi->imageGC, 0, 0, w, h);
    Imlib_paste_image(xi->id, im, (Pixmap) img->pixmap, 0, 0, w, h);
    Imlib_kill_image(xi->id, im);
#elif defined(USE_IMLIB2)
    im = imlib_load_image(fname);
    if (!im)
	return 0;
    imlib_context_set_image(im);
    if (w <= 0)
	w = imlib_image_get_width();
    if (h <= 0)
	h = imlib_image_get_height();
    img->pixmap = (void *)XCreatePixmap(xi->display, xi->parent, w, h,
					DefaultDepth(xi->display, 0));
    if (!img->pixmap)
	return 0;
    XSetForeground(xi->display, xi->imageGC, xi->background_pixel);
    XFillRectangle(xi->display, (Pixmap) img->pixmap, xi->imageGC, 0, 0, w, h);
    imlib_context_set_display(xi->display);
    imlib_context_set_visual(DefaultVisual(xi->display, 0));
    imlib_context_set_colormap(DefaultColormap(xi->display, 0));
    imlib_context_set_drawable((Drawable) img->pixmap);
    imlib_render_image_on_drawable_at_size(0, 0, w, h);
    imlib_free_image();
#elif defined(USE_GDKPIXBUF)
    max_anim = self->max_anim;
    animation = gdk_pixbuf_animation_new_from_file(fname);
    if (!animation)
	return 0;
    frames = gdk_pixbuf_animation_get_frames(animation);
    frame_num = n = gdk_pixbuf_animation_get_num_frames(animation);

    get_animation_size(animation, &iw, &ih, &delay);
    if (delay <= 0)
	max_anim = -1;

    if (max_anim < 0) {
	frame_num = (-max_anim > n) ? n : -max_anim;
    }
    else if (max_anim > 0) {
	frame_num = n = (max_anim > n) ? n : max_anim;
    }

    if (w < 1 || h < 1) {
	w = iw;
	h = ih;
	ratio_w = ratio_h = 1;
    }
    else {
	ratio_w = 1.0 * w / iw;
	ratio_h = 1.0 * h / ih;
    }
    tmp_pixmap = XCreatePixmap(xi->display, xi->parent, w, h,
			       DefaultDepth(xi->display, 0));
    XFillRectangle(xi->display, (Pixmap) tmp_pixmap, xi->imageGC, 0, 0, w, h);
    if (!tmp_pixmap) {
	gdk_pixbuf_animation_unref(animation);
	return 0;
    }
    ximg = x11_img_new(xi, w, h, frame_num);
    if (!ximg) {
	XFreePixmap(xi->display, tmp_pixmap);
	gdk_pixbuf_animation_unref(animation);
	return 0;
    }
    for (j = 0; j < n; j++) {
	GdkPixbufFrame *frame;
	GdkPixbuf *org_pixbuf, *pixbuf;
	int width, height, ofstx, ofsty;

	if (max_anim < 0) {
	    i = (j - n + frame_num > 0) ? (j - n + frame_num) : 0;
	}
	else {
	    i = j;
	}
	frame = (GdkPixbufFrame *) g_list_nth_data(frames, j);
	org_pixbuf = gdk_pixbuf_frame_get_pixbuf(frame);
	ofstx = gdk_pixbuf_frame_get_x_offset(frame);
	ofsty = gdk_pixbuf_frame_get_y_offset(frame);
	delay = gdk_pixbuf_frame_get_delay_time(frame);
	width = gdk_pixbuf_get_width(org_pixbuf);
	height = gdk_pixbuf_get_height(org_pixbuf);

	if (ofstx == 0 && ofsty == 0 && width == w && height == h) {
	    pixbuf = resize_image(org_pixbuf, w, h);
	}
	else {
	    pixbuf =
		resize_image(org_pixbuf, width * ratio_w, height * ratio_h);
	    ofstx *= ratio_w;
	    ofsty *= ratio_h;
	}
	width = gdk_pixbuf_get_width(pixbuf);
	height = gdk_pixbuf_get_height(pixbuf);

	if (delay > ximg->delay)
	    ximg->delay = delay;

	XCopyArea(xi->display, tmp_pixmap, ximg->pixmap[i],
		  xi->imageGC, 0, 0, w, h, 0, 0);
	gdk_pixbuf_xlib_render_to_drawable_alpha(pixbuf,
						 (Drawable) ximg->pixmap[i], 0,
						 0, ofstx, ofsty, width,
						 height,
						 GDK_PIXBUF_ALPHA_BILEVEL, 1,
						 XLIB_RGB_DITHER_NORMAL, 0, 0);

	switch (gdk_pixbuf_frame_get_action(frame)) {
	case GDK_PIXBUF_FRAME_RETAIN:
	    XCopyArea(xi->display, ximg->pixmap[i], tmp_pixmap,
		      xi->imageGC, 0, 0, w, h, 0, 0);
	    break;
	case GDK_PIXBUF_FRAME_DISPOSE:
	    break;
	case GDK_PIXBUF_FRAME_REVERT:
	    XCopyArea(xi->display, ximg->pixmap[0], tmp_pixmap,
		      xi->imageGC, 0, 0, w, h, 0, 0);
	    break;
	default:
	    XCopyArea(xi->display, ximg->pixmap[0], tmp_pixmap,
		      xi->imageGC, 0, 0, w, h, 0, 0);
	    break;
	}


	if (org_pixbuf != pixbuf)
	    gdk_pixbuf_finalize(pixbuf);

    }
    XFreePixmap(xi->display, tmp_pixmap);
    gdk_pixbuf_animation_unref(animation);
    img->pixmap = ximg;
#endif

    img->width = w;
    img->height = h;
    return 1;
}