示例#1
0
void render_present()
{
	update_bg();
#ifdef WITH_COMPOSITE
	if (theme->use_composite) {
		/* 
		 * Because XRender can't do directly SRCc * SRCa + DSTc * (1 - SRCa) blending,
		 * I must apply SRCa to my SRCc manually. To do this I'm using PictOpSrc with 
		 * alpha channel in mask. So, I need to copy RGB data to one buffer (color) and 
		 * Alpha to another buffer (mask), then use them in XRenderComposite.
		 *
		 * But I think in can be done on theme loading stage. Just apply SRCa to SRCc 
		 * immediately. Optimization?
		 */

		/* copy color part to bbcolor */
		imlib_context_set_image(bbcolor);
		imlib_image_set_has_alpha(1);
		imlib_context_set_color(0,0,0,255);
		imlib_image_fill_rectangle(0,0,bbwidth,bbheight);
		imlib_blend_image_onto_image(bb,0,0,0,bbwidth,bbheight,0,0,bbwidth,bbheight);
		imlib_context_set_drawable(pixcolor);
		imlib_render_image_on_drawable(0,0);

		/* copy alpha part to bbalpha */
		imlib_context_set_image(bbalpha);
		imlib_image_copy_alpha_to_image(bb,0,0);
		imlib_image_set_has_alpha(1);
		imlib_context_set_drawable(pixalpha);
		imlib_render_image_on_drawable(0,0);

		XRenderComposite(bbdpy,
				 PictOpSrc,
				 piccolor,
				 picalpha,
				 rootpic,
				 0, 0, 0, 0, 0, 0, bbwidth, 
				 bbheight);
	} else 
#endif
	if (*rootpmap) {
		imlib_context_set_image(bbcolor);
		imlib_blend_image_onto_image(bg,0,0,0,bbwidth,bbheight,0,0,bbwidth,bbheight);
		imlib_context_set_blend(1);
		imlib_blend_image_onto_image(bb,0,0,0,bbwidth,bbheight,0,0,bbwidth,bbheight);
		imlib_context_set_blend(0);

		imlib_context_set_drawable(bbwin);
		imlib_render_image_on_drawable(0,0);	
	} else {
		imlib_context_set_drawable(bbwin);
		imlib_context_set_image(bb);
		imlib_render_image_on_drawable(0,0);
	}
}
示例#2
0
文件: tag.c 项目: decasm/sxiv
void render_text(char * text, int button_x, int button_y, int * button_w, int * button_h) {
	Imlib_Image buffer;
	int text_w, text_h;

	/* query the size it will be */
	imlib_get_text_size(text, &text_w, &text_h); 
	*button_w = text_w + pad_width;
	*button_h = text_height + pad_height;

	/* create our buffer image for rendering this update */
	buffer = imlib_create_image(*button_w, *button_h);
	if ( buffer == NULL ) {
		fprintf(stderr, "Null buffer First\n");
		return;
	}
	imlib_context_set_image(buffer);

	imlib_context_set_color(tag_color.red,tag_color.green,tag_color.blue,tag_color.alpha);
	imlib_image_fill_rectangle(0,0, *button_w, *button_h);

	imlib_context_set_color(255, 255, 255, 255);
	imlib_text_draw(pad_width/2, pad_height/2, text); 

	imlib_render_image_on_drawable(button_x, button_y);

	imlib_free_image();
}
示例#3
0
文件: extinitwin.c 项目: Limsik/e17
static void
_eiw_render_loop(Window win, EImage * im, EiwData * d)
{
   int                 w, h;
   XRenderPictFormat  *pictfmt;
   Pixmap              pmap;
   Picture             pict;

   EImageGetSize(im, &w, &h);

   pictfmt = XRenderFindStandardFormat(disp, PictStandardARGB32);
   pmap = XCreatePixmap(disp, WinGetXwin(VROOT), w, h, 32);
   imlib_context_set_image(im);
   imlib_context_set_drawable(pmap);
   imlib_render_image_on_drawable(0, 0);
   pict = XRenderCreatePicture(disp, pmap, pictfmt, 0, 0);
   XFreePixmap(disp, pmap);

   if (d->curs != None)
      XFreeCursor(disp, d->curs);
   d->curs = XRenderCreateCursor(disp, pict, w / 2, h / 2);
   XRenderFreePicture(disp, pict);

   XDefineCursor(disp, win, d->curs);
}
示例#4
0
文件: imlib2.c 项目: rdebath/sgt
void image_to_pixmap(image *img, GdkPixmap *pm, int w, int h)
{
    int realw, realh;
    int need_free;

    imlib_context_set_image(img->image);
    realw = imlib_image_get_width();
    realh = imlib_image_get_height();
    if (w != realw || h != realh) {
	Imlib_Image newimg;

	newimg = imlib_create_cropped_scaled_image(0, 0, realw, realh, w, h);
	imlib_context_set_image(newimg);
	need_free = TRUE;
    } else
	need_free = FALSE;

    imlib_context_set_display(GDK_WINDOW_XDISPLAY(pm));
    imlib_context_set_visual(GDK_VISUAL_XVISUAL(gdk_visual_get_system()));
    imlib_context_set_colormap
	(GDK_COLORMAP_XCOLORMAP(gdk_colormap_get_system()));
    imlib_context_set_drawable(GDK_WINDOW_XWINDOW(pm));
    imlib_context_set_blend(1);
    imlib_render_image_on_drawable(0, 0);

    if (need_free)
	imlib_free_image();
}
示例#5
0
void draw_launcher_icon(void *obj, cairo_t *c)
{
	LauncherIcon *launcherIcon = (LauncherIcon*)obj;

	Imlib_Image icon_scaled = launcherIcon->icon_scaled;
	// Render
	imlib_context_set_image (icon_scaled);
	imlib_context_set_blend(1);
	imlib_context_set_drawable(launcherIcon->area.pix);
	imlib_render_image_on_drawable(0, 0);
}
示例#6
0
文件: gib_imlib.c 项目: cbane/giblib
void
gib_imlib_render_image_on_drawable(Drawable d, Imlib_Image im, int x, int y,
                                   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(x, y);
}
示例#7
0
文件: draw.c 项目: lf94/Resurrection
void
Rterm_draw_screen_string_imlib2(struct R_termscreen *screen, int row, int column, int len)
{
    R_text_t *text;
    R_textflags_t *textflags;
    int bufferrow;
    int bgcolor, fgcolor;
    int textw, texth;
    struct imlib2color *color;
    Imlib_Image *textimg;

    if (screen == NULL) {

	return;
    }
    text = screen->textbuf.data[screen->viewrow + row] + column;
    textflags = screen->textbuf.renddata[screen->viewrow + row] + column;
    memcpy(screen->stringbuffer, text, len);
    screen->stringbuffer[len] = '\0';
    fprintf(stderr, "string: %s\n", screen->stringbuffer);
    fgcolor = RTERM_CHAR_FG_COLOR(*textflags);
    if (fgcolor) {
	color = &screen->im2colors[fgcolor];
    } else {
	color = &screen->im2colors[RTERM_SCREEN_FOREGROUND];
    }
#if 0
    fprintf(stderr, "red == %d, green == %d, blue == %d, alpha == %d\n",
	    color->red, color->green, color->blue, color->alpha);
#endif
    imlib_context_set_font(screen->im2font);
    imlib_context_set_color(color->red, color->green, color->blue,
			    color->alpha);
    imlib_context_set_drawable(screen->buf);
    imlib_get_text_size(screen->stringbuffer,
                        &textw, &texth);
    textimg = imlib_create_image(textw, texth);
    imlib_context_set_image(textimg);
    imlib_image_clear();
    imlib_image_set_has_alpha(1);
    imlib_context_set_blend(0);
    imlib_context_set_anti_alias(0);
    imlib_text_draw(0,
                    0,
		    screen->stringbuffer);
    imlib_render_image_on_drawable(Rterm_screen_column_x(screen, column),
                                   Rterm_screen_row_y(screen, column));
    imlib_free_image();

    return;
}
示例#8
0
文件: tag.c 项目: decasm/sxiv
void draw_button_bottom_border(int x, int y, int width) {

	Imlib_Image buffer;
	buffer = imlib_create_image(width, border_height);
	if ( buffer == NULL ) {
		fprintf(stderr, "Null buffer third %d, %d\n", x, width);
		return;
	}
	imlib_context_set_image(buffer);

	imlib_context_set_color(0,0,0,255);
	imlib_image_draw_line (0, 0, width, 0, 0);

	imlib_render_image_on_drawable(x, y);
	imlib_free_image();
}
示例#9
0
文件: tag.c 项目: decasm/sxiv
void draw_button_left_border(int x, int y, int height) {

	Imlib_Image buffer;
	buffer = imlib_create_image(border_width, height);
	if ( buffer == NULL ) {
		fprintf(stderr, "Null buffer second %d, %d\n", x, height);
		return;
	}
	imlib_context_set_image(buffer);

	imlib_context_set_color(0,0,0,255);
	imlib_image_draw_line (0, 0, 0, height, 0);

	imlib_render_image_on_drawable(x, y);
	imlib_free_image();
}
示例#10
0
void XImlib2Caption::draw()
{
        XDesktopContainer * xContainer =
			dynamic_cast<XDesktopContainer *>(AbstractImage::container);
	XIconWithShadow * sIcon = dynamic_cast<XIconWithShadow *>(AbstractImage::iconParent);

        Display * display = xContainer->getDisplay();
    
	int fX, fY;
    
	setXY(fX, fY);
	
	Imlib_Image cropImage = xContainer->bg->createCropImage(fX, fY, width, height, width, height);
	
	imlib_context_set_image(cropImage);
	
	imlib_context_set_drawable(window);
	imlib_render_image_on_drawable(0, 0);
	
	Pixmap shapeMask;
	imlib_render_pixmaps_for_whole_image (&pixmap, &shapeMask);
	XSetWindowBackgroundPixmap (display, window, pixmap);
	imlib_free_image();
	
	imlib_context_set_drawable(xContainer->getRootWindow());

       	imlib_context_set_image(xContainer->bg->spareRoot);
    
    // if the icon shadow is enabled and the shadow is visible underneath the
    // text window
	if (sIcon && //TODO Fix this
		   sIcon->getShadowX() > fX - sIcon->getWidth() &&
		   sIcon->getShadowY() > fY - sIcon->getHeight() &&
		   sIcon->getShadowX() < fX + sIcon->getWidth() &&
		   sIcon->getShadowY() < fY + sIcon->getHeight() )
		sIcon->renderShadowToImage(pixmap, fX, fY);

	updateText();

	XMoveWindow(display, window, fX, fY );
    
        //apply the buffer to the window
	XSetFillStyle(display, gc, FillTiled);
	XSetTile(display, gc, pixmap);
	XFillRectangle(display, window, gc, 0, 0, width, height);
	imlib_free_pixmap_and_mask(pixmap);
}
示例#11
0
文件: gib_imlib.c 项目: cbane/giblib
void
gib_imlib_render_image_on_drawable_with_rotation(Drawable d, Imlib_Image im,
                                                 int x, int y, double angle,
                                                 char dither, char blend,
                                                 char alias)
{
   Imlib_Image new_im;

   imlib_context_set_image(im);
   imlib_context_set_anti_alias(alias);
   imlib_context_set_dither(dither);
   imlib_context_set_blend(blend);
   imlib_context_set_angle(angle);
   imlib_context_set_drawable(d);
   new_im = imlib_create_rotated_image(angle);
   imlib_context_set_image(new_im);
   imlib_render_image_on_drawable(x, y);
   imlib_free_image();
}
示例#12
0
void XImlib2Shadow::renderShadowToImage(Pixmap &buffer, int fX, int fY)
{
    XIconWithShadow * sIcon = dynamic_cast<XIconWithShadow *>(iconParent);
    
    //sIcon->snapShadow();

    x = sIcon->getShadowX();
    y = sIcon->getShadowY();

    int xCord = x - fX;
    int yCord = y - fY;
    
    imlib_context_set_image(image);
    imlib_context_set_anti_alias(1);  //smoother scaling
    imlib_context_set_blend(1);       //automatically blend image and background

    imlib_context_set_drawable(buffer);
    imlib_render_image_on_drawable(xCord, yCord);
}
示例#13
0
文件: render.c 项目: penma/feht2
static void render_checkerboard() {
	/* create the checkerboard texture, if not already done. */

	static Pixmap checks_pmap = None;
	Imlib_Image checks = NULL;

	if (checks_pmap == None) {
		checks = imlib_create_image(16, 16);

		if (!checks) {
			fputs("Unable to create a teeny weeny imlib image. I detect problems\n", stderr);
		}

		imlib_context_set_image(checks);

		imlib_context_set_color(144, 144, 144, 255);
		imlib_image_fill_rectangle(0, 0, 16, 16);

		imlib_context_set_color(100, 100, 100, 255);
		imlib_image_fill_rectangle(0, 0, 8, 8);
		imlib_image_fill_rectangle(8, 8, 8, 8);

		checks_pmap = XCreatePixmap(x11.display, x11_window, 16, 16, x11.depth);

		imlib_context_set_drawable(checks_pmap);
		imlib_render_image_on_drawable(0, 0);
		imlib_free_image_and_decache();
	}

	/* and plot the checkerboards onto the pixmap */

	static GC gc = None;
	XGCValues gcval;

	if (gc == None) {
		gcval.tile = checks_pmap;
		gcval.fill_style = FillTiled;
		gc = XCreateGC(x11.display, x11_window, GCTile | GCFillStyle, &gcval);
	}

	XFillRectangle(x11.display, window_pixmap, gc, 0, 0, s_view.win_width, s_view.win_height);
}
示例#14
0
文件: task.c 项目: chigoncalves/tinto
// TODO icons look too large when the panel is large
void draw_task_icon (Task *tsk, int text_width)
{
	if (tsk->icon[tsk->current_state] == 0) return;

	// Find pos
	int pos_x;
	Panel *panel = (Panel*)tsk->area.panel;
	if (panel->g_task.centered) {
		if (panel->g_task.text)
			pos_x = (tsk->area.bounds.width - text_width - panel->g_task.icon_size1) / 2;
		else
			pos_x = (tsk->area.bounds.width - panel->g_task.icon_size1) / 2;
	}
	else pos_x = panel->g_task.area.paddingxlr + tsk->area.background->border.width;

	// Render
	imlib_context_set_image (tsk->icon[tsk->current_state]);
	imlib_context_set_blend(1);
	imlib_context_set_drawable(tsk->area.pixmap);
	imlib_render_image_on_drawable(pos_x, panel->g_task.icon_posy);
}
示例#15
0
int
main(int argc, char **argv)
{
   int                 w, h, tw, th;
   Imlib_Image         im_bg = NULL;
   XEvent              ev;
   KeySym              keysym;
   static char         kbuf[20];
   Imlib_Font          font;
   Imlib_Color_Range   range;
   const char         *display_name = getenv("DISPLAY");

   /**
    * First tests to determine which rendering task to perform
    */
   if (display_name == NULL)
       display_name = ":0";
   disp = XOpenDisplay(display_name);
   if (disp == NULL)
     {
       fprintf(stderr, "Can't open display %s\n", display_name);
       return 1;
     }
   vis = DefaultVisual(disp, DefaultScreen(disp));
   depth = DefaultDepth(disp, DefaultScreen(disp));
   cm = DefaultColormap(disp, DefaultScreen(disp));
   win =
       XCreateSimpleWindow(disp, DefaultRootWindow(disp), 0, 0, 100, 100, 0, 0,
                           0);
   XSelectInput(disp, win,
                ButtonPressMask | ButtonReleaseMask | ButtonMotionMask |
                PointerMotionMask | ExposureMask | KeyPressMask);
   XMapWindow(disp, win);

   /**
    * Start rendering
    */
   imlib_set_font_cache_size(512 * 1024);
   imlib_add_path_to_font_path(PACKAGE_DATA_DIR"/data/fonts");
   imlib_context_set_display(disp);
   imlib_context_set_visual(vis);
   imlib_context_set_colormap(cm);
   imlib_context_set_drawable(win);
   imlib_context_set_blend(0);
   imlib_context_set_color_modifier(NULL);
   imlib_context_set_blend(0);

   im_bg = imlib_create_image(600, 400);
   imlib_context_set_image(im_bg);
   w = imlib_image_get_width();
   h = imlib_image_get_height();
   imlib_context_set_color(128, 128, 255, 255);
   imlib_image_fill_rectangle(0, 0, w, h);
   XResizeWindow(disp, win, w, h);
   XSync(disp, False);

   while (1)
     {
        do
          {
             XNextEvent(disp, &ev);
             switch (ev.type)
               {
                 case ButtonRelease:
                    exit(0);
                    break;
                 case KeyPress:
                    XLookupString(&ev.xkey, (char *)kbuf, sizeof(kbuf), &keysym,
                                  NULL);
                    switch (*kbuf)
                      {
                        case 'q':
                           exit(0);
                        default:
                           break;
                      }
                    break;
                 default:
                    break;

               }
          }
        while (XPending(disp));

        imlib_context_set_image(im_bg);
        imlib_context_set_color(128, 128, 255, 255);
        imlib_image_fill_rectangle(0, 0, w, h);
        imlib_context_set_color(0, 0, 0, 255);
        imlib_image_draw_rectangle(20, 20, 560, 140);
        imlib_image_draw_rectangle(20, 220, 560, 140);
        font = imlib_load_font("notepad/15");
        if (font)
          {
             char                text[4096];

             imlib_context_set_font(font);
             imlib_context_set_color(0, 0, 0, 255);
             sprintf(text, "RGBA range, 2 points, from red to magenta");
             imlib_get_text_size(text, &tw, &th);
             imlib_text_draw(300 - tw / 2, 180 - th / 2, text);
             sprintf(text, "HSVA range, 2 points, from red to magenta");
             imlib_get_text_size(text, &tw, &th);
             imlib_text_draw(300 - tw / 2, 380 - th / 2, text);
             imlib_free_font();
          }

        /* Draw rectangle w/ RGBA gradient */
        range = imlib_create_color_range();
        imlib_context_set_color_range(range);
        imlib_context_set_color(255, 0, 0, 255);
        imlib_add_color_to_color_range(0);
        imlib_context_set_color(255, 0, 255, 255);
        imlib_add_color_to_color_range(20);
        imlib_image_fill_color_range_rectangle(21, 21, 558, 138, -90.0);
        imlib_free_color_range();

        /* Draw rectangle w/ HSVA gradient */
        range = imlib_create_color_range();
        imlib_context_set_color_range(range);
        imlib_context_set_color_hsva(0, 1, 1, 255);
        imlib_add_color_to_color_range(0);
        imlib_context_set_color_hsva(300, 1, 1, 255);
        imlib_add_color_to_color_range(20);
        imlib_image_fill_hsva_color_range_rectangle(21, 221, 558, 138, -90.0);
        imlib_free_color_range();

        imlib_render_image_on_drawable(0, 0);
     }
   return 0;
}
示例#16
0
int xtwitter_x_popup(void *config, twitter_status_t *status)
{
    twitter_t *twitter = config;
    char image_name[PATH_MAX];
    char image_path[PATH_MAX];
    int pad_y;
    int text_line=0;
    int pos;
    const char *text = status->text;
    int i;

    /* notice: destructive conversion  */
    //xmlunescape((char*)status->text);

    while(*text){
        pos=utf8pos(text, 56);
        text+=pos;
        text_line++;
    }

    twitter_image_name(status, image_name);
    snprintf(image_path, PATH_MAX, "%s/%s", twitter->images_dir, image_name);

/*
    XClearArea(display, window, 0, 0,
               XTWITTER_WINDOW_WIDTH, XTWITTER_WINDOW_HEIGHT, 0);
*/
    XSetForeground(display, gc, color_white);
    XSetBackground(display, gc, color_black);

    XFillRectangle(display, pixmap, gc,
                   0, 0, XTWITTER_WINDOW_WIDTH, XTWITTER_WINDOW_HEIGHT);

    switch(text_line){
    case 1:
        pad_y = 60;
        break;
    case 2:
        pad_y = 56;
        break;
    case 3:
        pad_y = 50;
        break;
    case 4:
        pad_y = 42;
        break;
    case 5:
        pad_y = 34;
        break;
    default:
        pad_y = 34;
    }

    XSetForeground(display, gc, color_black);
    XSetBackground(display, gc, color_white);

    text = status->text;
    i=0;
    while(*text){
        pos=utf8pos(text, 56);
        XmbDrawString(display, pixmap, text_fonts, gc,
                      58, pad_y + 14 * i++, text, pos);
        text+=pos;
    }

    char *name = NULL;
    asprintf(&name, "@%s (%s)", status->user_screen_name, status->user_name);
    XmbDrawString(display, pixmap, user_fonts, gc, 5, 17,
                  name,
                  strlen(name));
    free(name);

    image = imlib_load_image(image_path);
    if(image){
		imlib_context_set_image(image);
		imlib_context_set_drawable(pixmap);
		imlib_render_image_on_drawable(5, 35);
    }

    XCopyArea(display, pixmap, window, gc,
              0, 0, XTWITTER_WINDOW_WIDTH, XTWITTER_WINDOW_HEIGHT, 0, 0);
    //XRaiseWindow(display, window);
    //XFlush(display);
    return 0;
}
示例#17
0
文件: draw.c 项目: lf94/Resurrection
void
menu_draw_string_imlib2(Rwindow_t *window)
{
    int textw, texth;
    unsigned int winw, winh;
    unsigned int dummyui;
    int dummyi;
    size_t len;
    char *str;
    Window dummywin;
    Imlib_Image textimg;
    char blend;

    if (window->im2title) {
        XGetGeometry(window->app->display, window->id, &dummywin,
                     &dummyi, &dummyi, &winw, &winh, &dummyui, &dummyui);
        imlib_context_set_image(window->im2title);
        imlib_context_set_drawable(window->id);
        blend = imlib_context_get_blend();
        imlib_context_set_blend(1);
        imlib_render_image_on_drawable(window->menu->lefttextoffset,
                                       (winh - window->im2titleh) / 2);
        if (window->menuitem) {
            textimg = NULL;
            if (window->menuitem->type == MENUITEM_TOGGLE) {
                if (!window->menuitem->im2true) {
                    imlib_context_set_font(window->im2font);
                    imlib_get_text_size(window->menuitem->truetext,
                                        &textw, &texth);
                    textimg = imlib_create_image(textw, texth);
                    if (textimg) {
                        imlib_context_set_image(textimg);
                        imlib_image_set_has_alpha(1);
                        imlib_image_clear();
                        imlib_context_set_color(204, 181, 59, 255);
                        imlib_text_draw(0, 0, window->menuitem->truetext);
                        window->menuitem->im2true = textimg;
                        window->menuitem->im2truew = textw;
                        window->menuitem->im2trueh = texth;
                    }
                }
                if (!window->menuitem->im2false) {
                    imlib_context_set_font(window->im2font);
                    imlib_get_text_size(window->menuitem->falsetext,
                                        &textw, &texth);
                    textimg = imlib_create_image(textw, texth);
                    if (textimg) {
                        imlib_context_set_image(textimg);
                        imlib_image_set_has_alpha(1);
                        imlib_image_clear();
                        imlib_context_set_color(204, 181, 59, 255);
                        imlib_text_draw(0, 0, window->menuitem->falsetext);
                        window->menuitem->im2false = textimg;
                        window->menuitem->im2falsew = textw;
                        window->menuitem->im2falseh = texth;
                    }
                }
                if (*((unsigned long *)window->menuitem->option.valueptr)
                    & window->menuitem->option.flag) {
                    str = window->menuitem->truetext;
                    textimg = window->menuitem->im2true;
                    textw = window->menuitem->im2truew;
                    texth = window->menuitem->im2trueh;
                } else {
                    str = window->menuitem->falsetext;
                    textimg = window->menuitem->im2false;
                    textw = window->menuitem->im2falsew;
                    texth = window->menuitem->im2falseh;
                }
            } else if (window->menuitem->righttext) {
                if (!window->menuitem->im2right) {
                    imlib_context_set_font(window->im2font);
                    imlib_get_text_size(window->menuitem->righttext,
                                        &textw, &texth);
                    textimg = imlib_create_image(textw, texth);
                    if (textimg) {
                        imlib_context_set_image(textimg);
                        imlib_image_set_has_alpha(1);
                        imlib_image_clear();
                        imlib_context_set_color(204, 181, 59, 255);
                        imlib_text_draw(0, 0, window->menuitem->righttext);
                        window->menuitem->im2right = textimg;
                        window->menuitem->im2rightw = textw;
                        window->menuitem->im2righth = texth;
                    }
                }
                str = window->menuitem->righttext;
                textimg = window->menuitem->im2right;
                textw = window->menuitem->im2rightw;
                texth = window->menuitem->im2righth;
            }
            if (textimg) {
                imlib_context_set_image(textimg);
                imlib_context_set_drawable(window->id);
                imlib_render_image_on_drawable(winw - window->menu->righttextoffset - textw,
                                               (winh - texth) / 2);
            } else {
#if 0
                len = strlen(str);
                if (len) {
                    XDrawString(window->app->display, window->id, window->gc,
                                winw - window->menu->righttextoffset
                                - len * FONT_WIDTH(window->fontinfo),
                                (winh + FONT_HEIGHT(window->fontinfo)) / 2,
                                str, len);
                }
#endif
            }
        }
        imlib_context_set_blend(blend);
    } else {
        menu_draw_string(window);
    }

    return;
}
示例#18
0
void Resources::reloadWallpaper()
{
    if (!_wallpaper)
        delete _wallpaper;

    Window rootWindow = XTools::rootWindow();
    XWindowAttributes attrs;
    XGetWindowAttributes(_dpy, rootWindow, &attrs);
    int width = attrs.width;
    int height = attrs.height;

    _wallpaper = new Image(_dpy, width, height, attrs.depth);

    printf("Loading background from '%s'\n", Settings::instance()->backgroundFilename());
    printf("Background mode: %d\n", Settings::instance()->backgroundMode());

    imlib_context_set_display(_dpy);

    int bgXpos = 0;
    int bgYpos = 0;
    Imlib_Image background = imlib_load_image(Settings::instance()->backgroundFilename());
    if (background == 0)
    {
        printf("Cannot load background\n");
        printf("rgb = (%d, %d, %d)\n",
            _backgroundColor.red   / 256,
            _backgroundColor.green / 256,
            _backgroundColor.blue  / 256
        );
        background = imlib_create_image(width, height);
        imlib_context_set_image(background);
        imlib_context_set_color(
            _backgroundColor.red   / 256,
            _backgroundColor.green / 256,
            _backgroundColor.blue  / 256,
            255
        );
        imlib_image_fill_rectangle(0, 0, width, height);
    }
    else
    {
        Imlib_Image bgToDraw = 0;

        imlib_context_set_image(background);
        switch (Settings::instance()->backgroundMode())
        {
            case Settings::Stretched:
            {
                bgToDraw = imlib_create_cropped_scaled_image(
                    0, 0,
                    imlib_image_get_width(), imlib_image_get_height(),
                    width, height
                );
                break;
            }

            case Settings::Centered:
            {
                // Hildon's logic is not so easy in this case

//                bgToDraw = imlib_create_cropped_image(
//                    (imlib_image_get_width() - width) / 2,
//                    (imlib_image_get_height()- height) / 2,
//                    width, height
//                );

                double scalex = 1.0;
                double scaley = 1.0;

                if (imlib_image_get_width() > width * 2)
                    scalex = (double)imlib_image_get_width() / 2.0 / width;
                if (imlib_image_get_height() > height * 2)
                    scaley = (double)imlib_image_get_height() / 2.0 / height;

                double scale = scalex;
                if (scaley > scale)
                    scale = scaley;

                int newwidth = (int)(scale * width);
                int newheight= (int)(scale * height);

                bgToDraw = imlib_create_cropped_scaled_image(
                    (imlib_image_get_width() - newwidth) / 2,
                    (imlib_image_get_height()- newheight)/ 2,
                    newwidth, newheight,
                    width, height
                );

                break;
            }

            case Settings::Scaled: case Settings::Cropped:
            {
                double scalex = (double)width / imlib_image_get_width();
                double scaley = (double)height / imlib_image_get_height();
                double scale = scalex;

                if (Settings::instance()->backgroundMode() == Settings::Scaled)
                {
                    if (scaley < scale) scale = scaley;
                }
                else
                {
                    if (scaley > scale) scale = scaley;
                }

                int newwidth = (int)(imlib_image_get_width() * scale);
                int newheight= (int)(imlib_image_get_height() * scale);

                bgToDraw = imlib_create_cropped_scaled_image(
                    0, 0,
                    imlib_image_get_width(), imlib_image_get_height(),
                    newwidth, newheight
                );

                bgXpos = (width - newwidth) / 2;
                bgYpos = (height - newheight) / 2;
                break;
            }

            default:
                printf("Unknown background mode: %d\n", Settings::instance()->backgroundMode());
        }

        imlib_free_image();

        imlib_context_set_image(bgToDraw);
    }

    imlib_context_set_drawable(_wallpaper->pixmap());
    imlib_context_set_visual(DefaultVisual(_dpy, DefaultScreen(_dpy)));

    imlib_render_image_on_drawable(bgXpos, bgYpos);

    imlib_free_image();
}
示例#19
0
int xtwitter_xaw_insert(void *ctx, twitter_status_t *status)
{
    twitter_t *twitter = ctx;
    static Widget status_paned = NULL;
    static Widget status_prev_paned = NULL;
    Widget status_lower_paned = NULL;

    int height, width;
    char image_name[PATH_MAX];
    char image_path[PATH_MAX];

    twitter_image_name(status, image_name);
    snprintf(image_path, PATH_MAX, "%s/%s", twitter->images_dir, image_name);
    image = imlib_load_image(image_path);

    pixmap = XCreatePixmap(XtDisplay(widget_shell),
                           XtWindow(widget_shell),
                           48, 48,
                           DefaultDepth(XtDisplay(widget_shell), 0));

    if(image){
		imlib_context_set_image(image);
		imlib_context_set_drawable(pixmap);
		imlib_render_image_on_drawable(0, 0);
    }

    XtVaGetValues(widget_tl_form, XtNwidth, &width, XtNheight, &height, NULL);
    width -= 20; // margine

    //XawFormDoLayout(widget_tl_form, False);

    status_prev_paned = status_paned;
    status_paned = XtVaCreateWidget(
        "status_paned",
        panedWidgetClass,
        widget_tl_form,
        XtNheight, 100,
        XtNwidth, width,
        XtNresizeToPreferred, True,
        XtNallowResize, True,
        XtNtop, (XtArgVal)XawChainTop,
        NULL);

    if(status_prev_paned!=NULL){
        XtVaSetValues(status_prev_paned,
                      XtNfromVert, (XtArgVal)status_paned,
                      NULL);
    }
    XtManageChild(status_paned);

    char *name = NULL;
    twitter_status_t *rt = (twitter_status_t *)status->rt;
    //static int count;
    if(rt){
        asprintf(&name, "@%s Retweeted by @%s (%s)",
                 rt->user_screen_name,
                 status->user_screen_name, status->user_name);
    }else{
        asprintf(&name, "@%s (%s)",
                 status->user_screen_name, status->user_name);
    }

    /* name_label = */
    XtVaCreateManagedWidget(
        "name_label",
        labelWidgetClass,
        status_paned,
        XtNlabel, name,
        XtNshowGrip, False,
        XtNjustify, XtJustifyLeft,
        XtNresizeToPreferred, True,
        //XtNallowResize, True,
        NULL);
    free(name);

    status_lower_paned = XtVaCreateManagedWidget(
        "status_lower_paned",
        panedWidgetClass,
        status_paned,
        XtNorientation, (XtArgVal)XtorientHorizontal,
        NULL);

    /* icon_label = */
    XtVaCreateManagedWidget(
        "icon_label",
        labelWidgetClass,
        status_lower_paned,
        XtNheight, 58,
        XtNwidth, 58,
        XtNmin, 58,
        XtNmax, 58,
        //XtNresizeToPreferred, True,
        XtNbitmap, pixmap,
        XtNshowGrip, False,
        NULL);

    char *text = strbrkdup(status->text, 50);
    /* status_text = */
    XtVaCreateManagedWidget(
        "status_text",
        labelWidgetClass,
        status_lower_paned,
        XtNlabel, text,
        XtNshowGrip, False,
        XtNjustify, XtJustifyLeft,
        XtNresizeToPreferred, True,
        //XtNallowResize, True,
        NULL);

/*
    status_text = XtVaCreateManagedWidget(
        "status_text",
        asciiTextWidgetClass,
        status_lower_paned,
        //status_paned,
        XtNstring, (XtArgVal)status->text,
        XtNeditType, XawtextRead,
        XtNwrap, XawtextWrapWord,
        XtNdisplayCaret, False,
        //XtNfromVert, name_label,
        //XtNwidth, width - 10,
        //XtNheight, 65,
        NULL);
*/

    //XtVaGetValues(status_text, XtNheight, &height, XtNwidth, &width, NULL);
    //printf("width, height: %d, %d\n", width, height);
    //XawFormDoLayout(widget_tl_form, True);
    XFlush(XtDisplay(widget_shell));
    return 0;
}
示例#20
0
int
main(int argc, char **argv)
{
   int                 w, h, x, y;
   Imlib_Image         im = NULL, im_bg = NULL;
   XEvent              ev;
   const char         *display_name = getenv("DISPLAY");

   /**
    * Initialization according to options
    */
   printf("Initialising\n");

   /**
    * First tests to determine which rendering task to perform
    */
   if (display_name == NULL)
       display_name = ":0";
   disp = XOpenDisplay(display_name);
   if (disp == NULL)
     {
       fprintf(stderr, "Can't open display %s\n", display_name);
       return 1;
     }
   vis = DefaultVisual(disp, DefaultScreen(disp));
   depth = DefaultDepth(disp, DefaultScreen(disp));
   cm = DefaultColormap(disp, DefaultScreen(disp));
   win =
       XCreateSimpleWindow(disp, DefaultRootWindow(disp), 0, 0, 100, 100, 0, 0,
                           0);
   XSelectInput(disp, win,
                ButtonPressMask | ButtonReleaseMask | ButtonMotionMask |
                PointerMotionMask | ExposureMask);
   XMapWindow(disp, win);

   /**
    * Start rendering
    */
   printf("Rendering\n");
   imlib_context_set_display(disp);
   imlib_context_set_visual(vis);
   imlib_context_set_colormap(cm);
   imlib_context_set_drawable(win);
   imlib_context_set_dither(1);
   imlib_context_set_blend(0);
   imlib_context_set_color_modifier(NULL);

   im_bg = imlib_load_image(PACKAGE_DATA_DIR"/data/images/imlib2.png");
   im = imlib_load_image(PACKAGE_DATA_DIR"/data/images/imlib2.png");

   imlib_context_set_image(im_bg);
   w = imlib_image_get_width();
   h = imlib_image_get_height();
   printf("Resizing Window to %d by %d\n", w, h);
   XResizeWindow(disp, win, w, h);
   XSync(disp, False);
   x = -9999;
   y = -9999;
   while (1)
     {
        Imlib_Image        *temp, *temp2;

        do
          {
             XNextEvent(disp, &ev);
             switch (ev.type)
               {
                 case Expose:
                    break;
                 case ButtonRelease:
                    exit(0);
                    break;
                 case MotionNotify:
                    x = ev.xmotion.x;
                    y = ev.xmotion.y;
                 default:
                    break;

               }
          }
        while (XPending(disp));

        imlib_context_set_blend(0);
        imlib_context_set_image(im_bg);
        temp = imlib_clone_image();
        imlib_context_set_image(temp);

        /*    imlib_blend_image_onto_image(im_bg, 0,
         * 0, 0, w, h,
         * 0, 0, w, h);
         * first = 0; */

        imlib_apply_filter
            ("bump_map_point(x=[],y=[],map="PACKAGE_DATA_DIR"/data/images/imlib2.png);", &x, &y);

        temp2 = im_bg;
        im_bg = temp;
        imlib_context_set_image(im_bg);
        imlib_render_image_on_drawable(0, 0);
        im_bg = temp2;
        imlib_context_set_image(temp);
        imlib_free_image();
     }

   return 0;
}
示例#21
0
int
main(int argc, char **argv)
{
   int                 w, h;
   Imlib_Image         im_bg = NULL;
   XEvent              ev;
   KeySym              keysym;
   static char         kbuf[20];
   ImlibPolygon        poly, poly1, poly2;
   const char         *display_name = getenv("DISPLAY");

   /**
    * First tests to determine which rendering task to perform
    */
   if (display_name == NULL)
       display_name = ":0";
   disp = XOpenDisplay(display_name);
   if (disp == NULL)
     {
       fprintf(stderr, "Can't open display %s\n", display_name);
       return 1;
     }
   vis = DefaultVisual(disp, DefaultScreen(disp));
   depth = DefaultDepth(disp, DefaultScreen(disp));
   cm = DefaultColormap(disp, DefaultScreen(disp));
   win =
       XCreateSimpleWindow(disp, DefaultRootWindow(disp), 0, 0, 100, 100, 0, 0,
                           0);
   XSelectInput(disp, win,
                ButtonPressMask | ButtonReleaseMask | ButtonMotionMask |
                PointerMotionMask | ExposureMask | KeyPressMask);
   XMapWindow(disp, win);

   /**
    * Start rendering
    */
   imlib_context_set_display(disp);
   imlib_context_set_visual(vis);
   imlib_context_set_colormap(cm);
   imlib_context_set_drawable(win);
   imlib_context_set_blend(0);
   imlib_context_set_color_modifier(NULL);
   imlib_context_set_blend(0);

   im_bg = imlib_create_image(400, 400);
   imlib_context_set_image(im_bg);
   w = imlib_image_get_width();
   h = imlib_image_get_height();
   imlib_context_set_color(0, 0, 0, 255);
   imlib_image_fill_rectangle(0, 0, w, h);
   XResizeWindow(disp, win, w, h);
   XSync(disp, False);

   poly = imlib_polygon_new();
   imlib_polygon_add_point(poly, 20, 20);
   imlib_polygon_add_point(poly, 70, 20);
   imlib_polygon_add_point(poly, 70, 70);
   imlib_polygon_add_point(poly, 20, 70);

   poly1 = imlib_polygon_new();
   imlib_polygon_add_point(poly1, 100, 20);
   imlib_polygon_add_point(poly1, 190, 100);
   imlib_polygon_add_point(poly1, 120, 70);

   poly2 = imlib_polygon_new();
   imlib_polygon_add_point(poly2, 290, 20);
   imlib_polygon_add_point(poly2, 200, 100);
   imlib_polygon_add_point(poly2, 270, 70);

   while (1)
     {
        do
          {
             XNextEvent(disp, &ev);
             switch (ev.type)
               {
                 case ButtonRelease:
                    exit(0);
                    break;
                 case KeyPress:
                    XLookupString(&ev.xkey, (char *)kbuf, sizeof(kbuf), &keysym,
                                  NULL);
                    switch (*kbuf)
                      {
                        case ' ':
                           imlib_context_set_anti_alias
                               (!imlib_context_get_anti_alias());
                           printf("AA is %s\n",
                                  imlib_context_get_anti_alias()? "on" : "off");
                           break;
                        case 'q':
                           exit(0);
                        default:
                           break;
                      }
                    break;
                 default:
                    break;

               }
          }
        while (XPending(disp));

        imlib_context_set_image(im_bg);
        imlib_context_set_color(0, 0, 0, 255);
        imlib_image_fill_rectangle(0, 0, w, h);
        imlib_context_set_color(255, 255, 255, 255);
        imlib_image_fill_polygon(poly);
        imlib_image_fill_polygon(poly1);
        imlib_image_fill_polygon(poly2);
        imlib_render_image_on_drawable(0, 0);
     }
   return 0;
}
示例#22
0
int main (int argc, char **argv)
{
	Visual *vis;
	Colormap cm;
	Display *_display;
	Imlib_Context context;
	Imlib_Image image;
	Pixmap pixmap;
	Imlib_Color_Modifier modifier = NULL;
	_display = XOpenDisplay (NULL);
	int width, height, depth, i, alpha;

	
	char str1[40];
	char str2[40];
	char str3[40];
	char str4[40];
	char str5[40];
		
	int ck0;
	int w, h;
	w = 0;
	h = 0;
			
			
	char strA1[30] = "hwe";
	char strA2[30] = "hwer";
	const char jpg[15] = "jpg"; //1
	const char png[15] = "png"; //2
	
	char *A1; 
	char *A2; 
	
	strcpy(strA1, argv[argc-1]);
	strcpy(strA2, strA1);
	A1 = strstr(strA1, jpg);
	A2 = strstr(strA2, png);
	
		//check to be sure image format is written right or abort
	 	checkForNull(A1, A2);
		
		
			
		
	for (screen = 0; screen < ScreenCount (_display); screen++)
	{
		display = XOpenDisplay (NULL);

		context = imlib_context_new ();
		imlib_context_push (context);

		imlib_context_set_display (display);
		vis = DefaultVisual (display, screen);
		cm = DefaultColormap (display, screen);

		width = DisplayWidth (display, screen);
		height = DisplayHeight (display, screen);

		depth = DefaultDepth (display, screen);

		pixmap =
			XCreatePixmap (display, RootWindow (display, screen),
							width, height, depth);

		imlib_context_set_visual (vis);
		imlib_context_set_colormap (cm);
		imlib_context_set_drawable (pixmap);
		imlib_context_set_color_range (imlib_create_color_range ());
		
		image = imlib_create_image (width, height);
		imlib_context_set_image (image);
				printf("1\n");
		imlib_context_set_color (0, 0, 0, 255);
		imlib_image_fill_rectangle (0, 0, width, height);

		imlib_context_set_dither (1);
		imlib_context_set_blend (1);
		printf("2\n");
		alpha = 255;


	for (i = 1; i < argc; i++)
	{
		if (modifier != NULL)
		{
			imlib_apply_color_modifier ();
			imlib_free_color_modifier ();
		}

	modifier = imlib_create_color_modifier ();
	imlib_context_set_color_modifier (modifier);

		if (strcmp (argv[i], "-alpha") == 0)
		{
			if ((++i) >= argc)
			{
				fprintf (stderr, "Missing alpha\n");
				continue;
			}
				if (sscanf (argv[i], "%i", &alpha) == 0)
				{
					fprintf (stderr, "Bad alpha (%s)\n", argv[i]);
					continue;
				}
		}
	else if (strcmp (argv[i], "-solid") == 0)
	{
		Color c;
		
		if ((++i) >= argc)
		{
			fprintf (stderr, "Missing color\n");
			continue;
		}
			if (parse_color (argv[i], &c, alpha) == 1)
			{
				fprintf (stderr, "Bad color (%s)\n", argv[i]);
				continue;
			}

		imlib_context_set_color (c.r, c.g, c.b, c.a);
		imlib_image_fill_rectangle (0, 0, width, height);
	}
		else if (strcmp (argv[i], "-clear") == 0)
		{
			imlib_free_color_range ();
			imlib_context_set_color_range (imlib_create_color_range ());
		}
	else if (strcmp (argv[i], "-add") == 0)
	{
		Color c;

		if ((++i) >= argc)
		{
			fprintf (stderr, "Missing color\n");
			continue;
		}
			if (parse_color (argv[i], &c, alpha) == 1)
			{
				fprintf (stderr, "Bad color (%s)\n", argv[i - 1]);
				continue;
			}

		imlib_context_set_color (c.r, c.g, c.b, c.a);
		imlib_add_color_to_color_range (1);
	}
	else if (strcmp (argv[i], "-addd") == 0)
	{
		Color c;
		int distance;

		if ((++i) >= argc)
		{
			fprintf (stderr, "Missing color\n");
			continue;
		}
			if ((++i) >= argc)
			{
				fprintf (stderr, "Missing distance\n");
				continue;
			}
				if (parse_color (argv[i - 1], &c, alpha) == 1)
				{
					fprintf (stderr, "Bad color (%s)\n", argv[i - 1]);
					continue;
				}
					if (sscanf (argv[i], "%i", &distance) == 1)
					{
						fprintf (stderr, "Bad distance (%s)\n", argv[i]);
						continue;
					}

				imlib_context_set_color (c.r, c.g, c.b, c.a);
				imlib_add_color_to_color_range (distance);
	}
	else if (strcmp (argv[i], "-gradient") == 0)
	{
		int angle;

		if ((++i) >= argc)
		{
			fprintf (stderr, "Missing angle\n");
			continue;
		}
			if (sscanf (argv[i], "%i", &angle) == 1)
			{
				fprintf (stderr, "Bad angle (%s)\n", argv[i]);
				continue;
			}

		imlib_image_fill_color_range_rectangle (0, 0, width, height,
												angle);
	}

	 else if (strcmp (argv[i], "-fill") == 0)
	 {
		if ((++i) >= argc)
		{
		  fprintf (stderr, "Missing image\n");
		  continue;
		}
		if ( load_Mod_image(Fill, argv[i], width, height, alpha, image, ck0) == 1)
		{
		  fprintf (stderr, "Bad image (%s)\n", argv[i]);
		  continue;
		}
	 }
	else if (strcmp (argv[i], "-dia") == 0)
	{
		if((++i) >= argc)
		{
			fprintf(stderr, "missing Dia, and Image\n");
			continue;
		}
			strcpy (str1, argv[i]);
			strcpy (str2, str1);
				
			if ( findX(str1, &w, &h) == 1 )
			{
				fprintf(stderr, " Bad Format\n");
				continue;
			}
			else if (findX(str2, &w, &h) == 0 && ((++i) >= argc))
			{
				fprintf(stderr, "Missing Image\n");
				continue;
			}
			else
			{
				//if format is correct then assign a number for
				//load_Mod_Image to check
				ck0 = -2;
				w = w;
				h = h;
			}
			if( load_Mod_image(Dia, argv[i], w, h, alpha, image, ck0) == 1 )
			{
			fprintf(stderr, "Bad Image or Bad Image Dimensions \n");
			}
	} 
	else if (strcmp (argv[i], "-tile") == 0)
	{
		if ((++i) >= argc)

			{
			fprintf(stderr, "format 0 missing \n");
			continue;
			}
				strcpy (str1, argv[i]);
				strcpy (str2, str1);
				strcpy (str3, str2);
				strcpy (str4, str3);
				strcpy (str5, str4);


			if ( findX(str1, &w, &h) == 3 &&  ((++i) >= argc))
			{ 
				fprintf(stderr, "missing Image\n");
				continue;
			} //check to see if format is -tile 0 
			else if (findX(str2, &w, &h) == 3)
			{
				ck0 = 3;
				if( load_Mod_image(Tile, argv[i], width, height, alpha, image, ck0) == 1 )
				{
					fprintf(stderr, "Bad Image or Bad Image Dimensions \n");
					continue;
				}
			}

			if (findX(str3, &w, &h) == 1)
			{
				fprintf(stderr, "bad format\n");
				continue;
			}
			 if (findX(str4, &w, &h) == 0 && ((++i) >= argc))
			{
				fprintf(stderr, "missing something again\n");
				continue;
			}
			if (findX (str5, &w, &h) == 0 )
			{
				ck0 = 2;
				w = w;
				h = h;
				
			}
			if( load_Mod_image(Tile, argv[i], w, h, alpha, image, ck0) == 1 )
			{
			fprintf(stderr, "Bad Image or Bad Image Dimension\n");
			}

	}

	else if (strcmp (argv[i], "-center") == 0)
	{
		if ((++i) >= argc)
		{
			fprintf (stderr, "Missing image\n");
			continue;
		}
			if (load_Mod_image (Center, argv[i], width, height, alpha, image, ck0) == 1)
			{
				fprintf (stderr, "Bad image (%s)\n", argv[i]);
				continue;
			}
	}
	else if (strcmp (argv[i], "-tint") == 0)
	{
		Color c;
		DATA8 r[256], g[256], b[256], a[256];
		int j;

		if ((++i) >= argc)
		{
			fprintf (stderr, "Missing color\n");
			continue;
		}
			if (parse_color (argv[i], &c, 255) == 1)
			{
				fprintf (stderr, "Bad color\n");
				continue;
			}

		imlib_get_color_modifier_tables (r, g, b, a);

			for (j = 0; j < 256; j++)
			{
				r[j] = (DATA8) (((double) r[j] / 255.0) * (double) c.r);
				g[j] = (DATA8) (((double) g[j] / 255.0) * (double) c.g);
				b[j] = (DATA8) (((double) b[j] / 255.0) * (double) c.b);
			}

		imlib_set_color_modifier_tables (r, g, b, a);
	}
	else if (strcmp (argv[i], "-blur") == 0)
	{
		int intval;

		if ((++i) >= argc)
		{
			fprintf (stderr, "Missing value\n");
			continue;
		}
			if (sscanf (argv[i], "%i", &intval) == 1)
			{
				fprintf (stderr, "Bad value (%s)\n", argv[i]);
				continue;
			}
		imlib_image_blur (intval);
	}
	else if (strcmp (argv[i], "-sharpen") == 0)
	{
		int intval;

		if ((++i) >= argc)
		{
			fprintf (stderr, "Missing value\n");
			continue;
		}
			if (sscanf (argv[i], "%i", &intval) == 1)
			{
				fprintf (stderr, "Bad value (%s)\n", argv[i]);
				continue;
			}
		imlib_image_sharpen (intval);
	}
	else if (strcmp (argv[i], "-contrast") == 0)
	{
		double dblval;

		if ((++i) >= argc)
		{
			fprintf (stderr, "Missing value\n");
			continue;
		}
			if (sscanf (argv[i], "%lf", &dblval) == 1)
			{
				fprintf (stderr, "Bad value (%s)\n", argv[i]);
				continue;
			}
		imlib_modify_color_modifier_contrast (dblval);
	}
	else if (strcmp (argv[i], "-brightness") == 0)
	{
		double dblval;

		if ((++i) >= argc)
		{
			fprintf (stderr, "Missing value\n");
			continue;
		}
			if (sscanf (argv[i], "%lf", &dblval) == 1)
			{
				fprintf (stderr, "Bad value (%s)\n", argv[i]);
				continue;
			}
		imlib_modify_color_modifier_brightness (dblval);
	}
	else if (strcmp (argv[i], "-gamma") == 0)
	{
		double dblval;

		if ((++i) >= argc)
		{
			fprintf (stderr, "Missing value\n");
			continue;
		}
			if (sscanf (argv[i], "%lf", &dblval) == 1)
			{
				fprintf (stderr, "Bad value (%s)\n", argv[i]);
				continue;
			}
		imlib_modify_color_modifier_gamma (dblval);
	}
	else if (strcmp (argv[i], "-flipv") == 0)
	{
		imlib_image_flip_vertical ();
	}
	else if (strcmp (argv[i], "-fliph") == 0)
	{
		imlib_image_flip_horizontal ();
	}
	else if (strcmp (argv[i], "-flipd") == 0)
	{
		imlib_image_flip_diagonal ();
	}
	else if (strcmp (argv[i], "-write") == 0)
	{
		if ((++i) >= argc)
		{
			fprintf (stderr, "Missing filename\n");
			continue;
		}
      imlib_save_image (argv[i]);
	}
	else
	{
		usage (argv[0]);
		imlib_free_image ();
		imlib_free_color_range ();

			if (modifier != NULL)
			{
				imlib_context_set_color_modifier (modifier);
				imlib_free_color_modifier ();
				modifier = NULL;
			}
				XFreePixmap (display, pixmap);
				exit (1);
	} // end else
} // end loop off of argc

	if (modifier != NULL)
	{
		imlib_context_set_color_modifier (modifier);
        imlib_apply_color_modifier ();
        imlib_free_color_modifier ();
        modifier = NULL;
	}

		imlib_render_image_on_drawable (0, 0);
		imlib_free_image ();
		imlib_free_color_range ();

		if (setRootAtoms (pixmap) == 0)
			fprintf (stderr, "Couldn't create atoms...\n");

		XKillClient (display, AllTemporary);
		XSetCloseDownMode (display, RetainTemporary);

		XSetWindowBackgroundPixmap (display, RootWindow (display, screen),
									pixmap);

		XClearWindow (display, RootWindow (display, screen));

		XFlush (display);
		XSync (display, False);

		imlib_context_pop ();
		imlib_context_free (context);

	} // end for loop off screen
                   //   } //  frist if statment at start of main
  return 0;
}
示例#23
0
文件: tapet.c 项目: haste/Tapet
int main(int argc, char *argv[])
{
	Display *dpy = XOpenDisplay(NULL);
	int screen = DefaultScreen(dpy);
	Window root = RootWindow(dpy, screen);
	Visual *vis = DefaultVisual(dpy, screen);

	int screenDepth = DefaultDepth(dpy, screen);
	int screenWidth = DisplayWidth(dpy, screen);
	int screenHeight = DisplayHeight(dpy, screen);

	unsigned int offsetX = 0;
	unsigned int offsetY = 0;

	unsigned int i;
	for(i = 1; i < argc; i++) {
		int c = argv[i][1];

		switch(c) {
			case 'x':
				if(++i < argc)
					offsetX = -atoi(argv[i]);
				break;

			case 'y':
				if(++i < argc)
					offsetY = -atoi(argv[i]);
				break;
		}
	}

	Imlib_Image image = imlib_load_image(argv[argc - 1]);
	if(image)
	{
		Pixmap bg = XCreatePixmap(dpy, root, screenWidth, screenHeight, screenDepth);

		imlib_context_set_image(image);
		imlib_context_set_display(dpy);
		imlib_context_set_visual(vis);
		imlib_context_set_drawable(bg);

		imlib_render_image_on_drawable(offsetX, offsetY);

		// Ripped out of xsetroot.
		Atom atomRoot = XInternAtom(dpy, "_XROOTPMAP_ID", False);
		XChangeProperty(
			dpy, root, atomRoot,
			XA_PIXMAP, 32, PropModeReplace,
			(unsigned char *) &bg, 1
		);

		XKillClient(dpy, AllTemporary);
		XSetCloseDownMode(dpy, RetainPermanent);

		XSetWindowBackgroundPixmap(dpy, root, bg);
		XClearWindow(dpy, root);

		XFlush(dpy);
		XSync(dpy, False);

		imlib_free_image();
	}

	return 0;
}
示例#24
0
文件: bgs.c 项目: Gottox/bgs
/* draw background to root */
void
drawbg(void) {
	int i, w, h, nx, ny, nh, nw, tmp;
	double factor;
	Pixmap pm;
	Imlib_Image tmpimg, buffer;

	pm = XCreatePixmap(dpy, root, sw, sh,
			   DefaultDepth(dpy, DefaultScreen(dpy)));
	if(!(buffer = imlib_create_image(sw, sh)))
		die("Error: Cannot allocate buffer.\n");
	imlib_context_set_image(buffer);
	imlib_image_fill_rectangle(0, 0, sw, sh);
	imlib_context_set_blend(1);
	for(i = 0; i < nmonitor; i++) {
		imlib_context_set_image(images[i % nimage]);
		w = imlib_image_get_width();
		h = imlib_image_get_height();
		if(!(tmpimg = imlib_clone_image()))
			die("Error: Cannot clone image.\n");
		imlib_context_set_image(tmpimg);
		if(rotate && ((monitors[i].w > monitors[i].h && w < h) ||
		   (monitors[i].w < monitors[i].h && w > h))) {
			imlib_image_orientate(1);
			tmp = w;
			w = h;
			h = tmp;
		}
		imlib_context_set_image(buffer);
		switch(mode) {
		case ModeCenter:
			nw = (monitors[i].w - w) / 2;
			nh = (monitors[i].h - h) / 2;
			nx = monitors[i].x + (monitors[i].w - nw) / 2;
			ny = monitors[i].y + (monitors[i].h - nh) / 2;
			break;
		case ModeZoom:
			nw = monitors[i].w;
			nh = monitors[i].h;
			if(w > h && (w / h > (monitors[i].w / monitors[i].h))) {
				nx = monitors[i].x + (monitors[i].w - nw) / 2;
				ny = monitors[i].y + (int)ceil(h * nx / w) / 2;
			}
			else {
				ny = monitors[i].y + (monitors[i].h - nh) / 2;
				nx = monitors[i].x + (int)ceil(w * ny / h) / 2;
			}
			break;
		default: /* ModeScale */
			factor = MAX((double)w / monitors[i].w,
				     (double)h / monitors[i].h);
			nw = w / factor;
			nh = h / factor;
			nx = monitors[i].x + (monitors[i].w - nw) / 2;
			ny = monitors[i].y + (monitors[i].h - nh) / 2;
		}
		imlib_blend_image_onto_image(tmpimg, 0, 0, 0, w, h,
					     nx, ny, nw, nh);
		imlib_context_set_image(tmpimg);
		imlib_free_image();
	}
	imlib_context_set_blend(0);
	imlib_context_set_image(buffer);
	imlib_context_set_drawable(root);
	imlib_render_image_on_drawable(0, 0);
	imlib_context_set_drawable(pm);
	imlib_render_image_on_drawable(0, 0);
	XSetWindowBackgroundPixmap(dpy, root, pm);
	imlib_context_set_image(buffer);
	imlib_free_image_and_decache();
	XFreePixmap(dpy, pm);
}