void
nautilus_ui_frame_video (GdkPixbuf **pixbuf)
{
	int width, height;
	int holes_width, holes_height;
	int i;

	if (!ensure_filmholes ())
		return;

	width = gdk_pixbuf_get_width (*pixbuf);
	height = gdk_pixbuf_get_height (*pixbuf);
	holes_width = gdk_pixbuf_get_width (filmholes_left);
	holes_height = gdk_pixbuf_get_height (filmholes_left);

	for (i = 0; i < height; i += holes_height) {
		gdk_pixbuf_composite (filmholes_left, *pixbuf, 0, i,
				      MIN (width, holes_width),
				      MIN (height - i, holes_height),
				      0, i, 1, 1, GDK_INTERP_NEAREST, 255);
	}

	for (i = 0; i < height; i += holes_height) {
		gdk_pixbuf_composite (filmholes_right, *pixbuf,
				      width - holes_width, i,
				      MIN (width, holes_width),
				      MIN (height - i, holes_height),
				      width - holes_width, i,
				      1, 1, GDK_INTERP_NEAREST, 255);
	}
}
Пример #2
0
static GdkPixbuf *
add_slideshow_frame (GdkPixbuf *pixbuf)
{
  GdkPixbuf *sheet, *sheet2;
  GdkPixbuf *tmp;
  gint w, h;

  w = gdk_pixbuf_get_width (pixbuf);
  h = gdk_pixbuf_get_height (pixbuf);

  sheet = gdk_pixbuf_new (GDK_COLORSPACE_RGB, FALSE, 8, w, h);
  gdk_pixbuf_fill (sheet, 0x00000000);
  sheet2 = gdk_pixbuf_new_subpixbuf (sheet, 1, 1, w - 2, h - 2);
  gdk_pixbuf_fill (sheet2, 0xffffffff);
  g_object_unref (sheet2);

  tmp = gdk_pixbuf_new (GDK_COLORSPACE_RGB, TRUE, 8, w + 6, h + 6);

  gdk_pixbuf_fill (tmp, 0x00000000);
  gdk_pixbuf_composite (sheet, tmp, 6, 6, w, h, 6.0, 6.0, 1.0, 1.0, GDK_INTERP_NEAREST, 255);
  gdk_pixbuf_composite (sheet, tmp, 3, 3, w, h, 3.0, 3.0, 1.0, 1.0, GDK_INTERP_NEAREST, 255);
  gdk_pixbuf_composite (pixbuf, tmp, 0, 0, w, h, 0.0, 0.0, 1.0, 1.0, GDK_INTERP_NEAREST, 255);

  g_object_unref (sheet);

  return tmp;
}
Пример #3
0
gboolean
xfwmPixmapRenderGdkPixbuf (xfwmPixmap * pm, GdkPixbuf *pixbuf)
{
    GdkPixbuf *src;
    GdkPixmap *destw;
    GdkVisual *gvisual;
    GdkColormap *cmap;
    gint width, height;
    gint dest_x, dest_y;

    g_return_val_if_fail (pm != NULL, FALSE);
    g_return_val_if_fail (pm->pixmap != None, FALSE);
    g_return_val_if_fail (pm->mask != None, FALSE);

    destw = gdk_xid_table_lookup (pm->pixmap);
    if (destw)
    {
        g_object_ref (G_OBJECT (destw));
    }
    else
    {
        destw = gdk_pixmap_foreign_new (pm->pixmap);
    }

    if (!destw)
    {
        g_warning ("Cannot get pixmap");
        return FALSE;
    }

    gvisual = gdk_screen_get_system_visual (pm->screen_info->gscr);
    cmap = gdk_x11_colormap_foreign_new (gvisual, pm->screen_info->cmap);

    if (!cmap)
    {
        g_warning ("Cannot create colormap");
        g_object_unref (destw);
        return FALSE;
    }

    width = MIN (gdk_pixbuf_get_width (pixbuf), pm->width);
    height = MIN (gdk_pixbuf_get_height (pixbuf), pm->height);

    /* Add 1 for rounding */
    dest_x = (pm->width - width + 1) / 2;
    dest_y = (pm->height - height + 1) / 2;

    src = gdk_pixbuf_get_from_drawable(NULL, GDK_DRAWABLE (destw), cmap,
                                       dest_x, dest_y, 0, 0, width, height);
    gdk_pixbuf_composite (pixbuf, src, 0, 0, width, height,
                          0, 0, 1.0, 1.0, GDK_INTERP_NEAREST, 0xFF);
    gdk_draw_pixbuf (GDK_DRAWABLE (destw), NULL, src, 0, 0, dest_x, dest_y,
                     width, height, GDK_RGB_DITHER_NONE, 0, 0);

    g_object_unref (cmap);
    g_object_unref (src);
    g_object_unref (destw);

    return TRUE;
}
static void
mailwatch_set_icon(XfceMailwatchPlugin *mwp, gboolean newmail)
{
    GdkPixbuf       *pb = newmail ?
                            gdk_pixbuf_copy(mwp->pix_newmail) :
                            gdk_pixbuf_copy(mwp->pix_normal);
    GdkPixbuf       *overlay = NULL;
    gint h, ow, oh;

    if ( mwp->log_status && mwp->show_log_status &&
            mwp->log_status < XFCE_MAILWATCH_N_LOG_LEVELS ) {
        overlay = mwp->pix_log[mwp->log_status];
    }
    
    h = gdk_pixbuf_get_height(pb);
    if(overlay) {
        ow = gdk_pixbuf_get_width(overlay);
        oh = gdk_pixbuf_get_height(overlay);
        gdk_pixbuf_composite(overlay, pb, 0, h - oh, ow, oh, 0, h - oh,
                             1.0, 1.0, GDK_INTERP_BILINEAR, 255);
    }
    
    xfce_scaled_image_set_from_pixbuf(XFCE_SCALED_IMAGE(mwp->image ), pb);
    g_object_unref(G_OBJECT(pb));
}
Пример #5
0
static void 
draw_eye (EyesApplet *eyes_applet,
	  gint eye_num, 
          gint pupil_x, 
          gint pupil_y)
{
	GdkPixbuf *pixbuf;
	GdkRectangle rect, r1, r2;

	pixbuf = gdk_pixbuf_copy (eyes_applet->eye_image);
	r1.x = pupil_x - eyes_applet->pupil_width / 2;
	r1.y = pupil_y - eyes_applet->pupil_height / 2;
	r1.width = eyes_applet->pupil_width;
	r1.height = eyes_applet->pupil_height;
	r2.x = 0;
	r2.y = 0;
	r2.width = eyes_applet->eye_width;
	r2.height = eyes_applet->eye_height;
	gdk_rectangle_intersect (&r1, &r2, &rect);
	gdk_pixbuf_composite (eyes_applet->pupil_image, pixbuf, 
					   rect.x,
					   rect.y,
					   rect.width,
				      	   rect.height,
				      	   pupil_x - eyes_applet->pupil_width / 2,
					   pupil_y - eyes_applet->pupil_height / 2, 1.0, 1.0,
				      	   GDK_INTERP_BILINEAR,
				           255);
	gtk_image_set_from_pixbuf (GTK_IMAGE (eyes_applet->eyes[eye_num]),
						  pixbuf);
	g_object_unref (pixbuf);

}
Пример #6
0
static void
x_pixbuf_tmp_draw_tile(int tile, int ofsx, int ofsy)
{
    int i, j, n;
    guint32 pixel;
    int width, height;
    int srcx, srcy;
    int dstx = ofsx, dsty = ofsy;

    width = Tile->unit_width;
    height = Tile->unit_height;
    srcx = (tile % tiles_per_row) * width;
    srcy = (tile / tiles_per_row) * height;

    if (dstx < 0) {
	srcx -= dstx;
	width += dstx;
	dstx = 0;
    }
    if (dsty < 0) {
	srcy -= dsty;
	height += dsty;
	dsty = 0;
    }
    if (dstx > 0)
	width -= dstx;
    if (dsty > 0)
	height -= dsty;

    if (!tmp_pixbuf) {
	tmp_pixbuf = gdk_pixbuf_new(gdk_pixbuf_get_colorspace(tile_pixbuf),
	  gdk_pixbuf_get_has_alpha(tile_pixbuf),
	  gdk_pixbuf_get_bits_per_sample(tile_pixbuf),
	  Tile->unit_width, Tile->unit_height);
	memset(gdk_pixbuf_get_pixels(tmp_pixbuf), 0,
	  Tile->unit_height * gdk_pixbuf_get_rowstride(tmp_pixbuf));
	gdk_pixbuf_copy_area(tile_pixbuf, srcx, srcy, width, height,
	  tmp_pixbuf, dstx, dsty);
	{
	    guchar *pixels;
	    int rowstride;
	    int n_channels;
	    guchar rgba[4];
	    g_return_if_fail(gdk_pixbuf_get_bits_per_sample(tmp_pixbuf) == 8 &&
	      gdk_pixbuf_get_colorspace(tmp_pixbuf) == GDK_COLORSPACE_RGB);
	    pixels = gdk_pixbuf_get_pixels(tmp_pixbuf);
	    rowstride = gdk_pixbuf_get_rowstride(tmp_pixbuf);
	    n_channels = gdk_pixbuf_get_n_channels(tmp_pixbuf);
	    for(j = 0; j < Tile->unit_height; j++)
		for(i = 0; i < Tile->unit_width; i++) {
		    nh_pixbuf_get_pixel(i, j, rgba);
		    rgba[3] = 255;
		    nh_pixbuf_put_pixel(i, j, rgba);
		}
	}
    }
    else
	gdk_pixbuf_composite(tile_pixbuf, tmp_pixbuf, dstx, dsty, width, height,
	  -srcx, -srcy, 1.0, 1.0, GDK_INTERP_NEAREST, 255.0);
}
Пример #7
0
static GdkPixbuf* accessx_status_applet_bouncekeys_image(AccessxStatusApplet* sapplet, XkbAccessXNotifyEvent* event)
{
    GtkStyle* style;
    GdkColor fg, bg;
    GdkPixbuf* icon_base = NULL;
    GdkPixbuf* tmp_pixbuf;
    /* Note to translators: the first letter of the alphabet, not the indefinite article */
    gchar* glyphstring = N_("a");
    gchar* stock_id = ACCESSX_BASE_ICON;

    g_assert(sapplet->applet);
    style = gtk_widget_get_style(GTK_WIDGET(sapplet->applet));
#if GTK_CHECK_VERSION (3, 0, 0)
    fg = style->text[gtk_widget_get_state_flags (GTK_WIDGET (sapplet->applet))];
#else
    fg = style->text[gtk_widget_get_state(GTK_WIDGET(sapplet->applet))];
#endif
    bg = style->base[GTK_STATE_NORMAL];

    if (event != NULL)
    {
        switch (event->detail)
        {
        case XkbAXN_BKReject:
            stock_id = SLOWKEYS_REJECT_ICON;
            _bk_timeout = g_timeout_add_full(G_PRIORITY_HIGH_IDLE, MAX(event->debounce_delay, 150), timer_reset_bouncekeys_image, sapplet->bouncefoo, NULL);
            break;
        default:
            stock_id = ACCESSX_BASE_ICON;
            break;
        }
    }
    tmp_pixbuf = gtk_widget_render_icon(GTK_WIDGET(sapplet->applet), stock_id, icon_size_spec, NULL);

    if (tmp_pixbuf)
    {
        GdkPixbuf* glyph_pixbuf;
        icon_base = gdk_pixbuf_copy(tmp_pixbuf);
        g_object_unref(tmp_pixbuf);
        glyph_pixbuf = accessx_status_applet_get_glyph_pixbuf(sapplet, GTK_WIDGET(sapplet->applet), icon_base, &fg, &bg, glyphstring);
        gdk_pixbuf_composite(glyph_pixbuf, icon_base, 2, 2, gdk_pixbuf_get_width(glyph_pixbuf) - 2, gdk_pixbuf_get_height(glyph_pixbuf) - 2, -2., -2., 1.0, 1.0, GDK_INTERP_NEAREST, 96);
        gdk_pixbuf_composite(glyph_pixbuf, icon_base, 1, 1, gdk_pixbuf_get_width(glyph_pixbuf) - 1, gdk_pixbuf_get_height(glyph_pixbuf) - 1, 1., 1., 1.0, 1.0, GDK_INTERP_NEAREST, 255);

        g_object_unref(glyph_pixbuf);
    }
    return icon_base;
}
Пример #8
0
static GdkPixbuf *
xfwmPixmapCompose (GdkPixbuf *pixbuf, const gchar * dir, const gchar * file)
{
    GdkPixbuf *alpha;
    gchar *filepng;
    gchar *filename;
    gint width, height;
    int i;

    static const char* image_types[] = {
        "svg",
        "png",
        "gif",
        "jpg",
        "bmp",
        NULL
    };

    i = 0;
    alpha = NULL;

    while ((image_types[i]) && (!alpha))
    {
        filepng = g_strdup_printf ("%s.%s", file, image_types[i]);
        filename = g_build_filename (dir, filepng, NULL);
        g_free (filepng);

        if (g_file_test (filename, G_FILE_TEST_IS_REGULAR))
        {
            alpha = gdk_pixbuf_new_from_file (filename, NULL);
        }
        g_free (filename);
        ++i;
    }

    if (!alpha)
    {
        /* We have no suitable image to layer on top of the XPM, stop here... */
        return (pixbuf);
    }

    if (!pixbuf)
    {
        /* We have no XPM canvas and found a suitable image, use it... */
        return (alpha);
    }

    width  = MIN (gdk_pixbuf_get_width (pixbuf),
                  gdk_pixbuf_get_width (alpha));
    height = MIN (gdk_pixbuf_get_height (pixbuf),
                  gdk_pixbuf_get_height (alpha));

    gdk_pixbuf_composite (alpha, pixbuf, 0, 0, width, height,
                          0, 0, 1.0, 1.0, GDK_INTERP_NEAREST, 0xFF);

    g_object_unref (alpha);

    return pixbuf;
}
Пример #9
0
static GdkPixbuf *
add_holes_to_pixbuf_small (GdkPixbuf *pixbuf, int width, int height)
{
	GdkPixbuf *holes, *tmp, *target;
	char *filename;
	int i;

	filename = g_build_filename (DATADIR, "xplayer", "filmholes.png", NULL);
	holes = gdk_pixbuf_new_from_file (filename, NULL);
	g_free (filename);

	if (holes == NULL) {
		g_object_ref (pixbuf);
		return pixbuf;
	}

	g_assert (gdk_pixbuf_get_has_alpha (pixbuf) == FALSE);
	g_assert (gdk_pixbuf_get_has_alpha (holes) != FALSE);
	target = g_object_ref (pixbuf);

	for (i = 0; i < height; i += gdk_pixbuf_get_height (holes))
	{
		gdk_pixbuf_composite (holes, target, 0, i,
				      MIN (width, gdk_pixbuf_get_width (holes)),
				      MIN (height - i, gdk_pixbuf_get_height (holes)),
				      0, i, 1, 1, GDK_INTERP_NEAREST, 255);
	}

	tmp = gdk_pixbuf_flip (holes, FALSE);
	g_object_unref (holes);
	holes = tmp;

	for (i = 0; i < height; i += gdk_pixbuf_get_height (holes))
	{
		gdk_pixbuf_composite (holes, target,
				      width - gdk_pixbuf_get_width (holes), i,
				      MIN (width, gdk_pixbuf_get_width (holes)),
				      MIN (height - i, gdk_pixbuf_get_height (holes)),
				      width - gdk_pixbuf_get_width (holes), i,
				      1, 1, GDK_INTERP_NEAREST, 255);
	}

	g_object_unref (holes);

	return target;
}
Пример #10
0
static GdkPixbuf* accessx_status_applet_mousekeys_image(AccessxStatusApplet* sapplet, XkbStateNotifyEvent* event)
{
    GdkPixbuf* mouse_pixbuf = NULL, *button_pixbuf, *dot_pixbuf, *tmp_pixbuf;
    gchar* which_dot = MOUSEKEYS_DOT_LEFT;
    tmp_pixbuf = gtk_widget_render_icon(GTK_WIDGET(sapplet->applet), MOUSEKEYS_BASE_ICON, icon_size_spec, NULL);
    mouse_pixbuf = gdk_pixbuf_copy(tmp_pixbuf);
    g_object_unref(tmp_pixbuf);
    /* composite in the buttons */
    if (mouse_pixbuf && event && event->ptr_buttons)
    {
        gint i;

        for (i = 0; i < G_N_ELEMENTS(button_icons); ++i)
        {
            if (event->ptr_buttons & button_icons[i].mask)
            {
                button_pixbuf = gtk_widget_render_icon(GTK_WIDGET(sapplet->applet), button_icons[i].stock_id, icon_size_spec, NULL);
                gdk_pixbuf_composite(button_pixbuf, mouse_pixbuf, 0, 0, gdk_pixbuf_get_width(button_pixbuf), gdk_pixbuf_get_height(button_pixbuf), 0.0, 0.0, 1.0, 1.0, GDK_INTERP_NEAREST, 255);
            }
        }
    }

    if (event)
    {
        switch (sapplet->xkb->ctrls->mk_dflt_btn)
        {
        case Button2:
            which_dot = MOUSEKEYS_DOT_MIDDLE;
            break;
        case Button3:
            which_dot = MOUSEKEYS_DOT_RIGHT;
            break;
        case Button1:
        default:
            which_dot = MOUSEKEYS_DOT_LEFT;
            break;
        }
    }
    dot_pixbuf = gtk_widget_render_icon(GTK_WIDGET(sapplet->applet), which_dot, icon_size_spec, NULL);

    gdk_pixbuf_composite(dot_pixbuf, mouse_pixbuf, 0, 0, gdk_pixbuf_get_width(dot_pixbuf), gdk_pixbuf_get_height(dot_pixbuf), 0.0, 0.0, 1.0, 1.0, GDK_INTERP_NEAREST, 255);

    return mouse_pixbuf;
}
Пример #11
0
/**
 * as_screenshot_show_image:
 **/
static void
as_screenshot_show_image (GsScreenshotImage *ssimg)
{
	GsScreenshotImagePrivate *priv;
	_cleanup_object_unref_ GdkPixbuf *pixbuf_bg = NULL;
	_cleanup_object_unref_ GdkPixbuf *pixbuf = NULL;

	priv = gs_screenshot_image_get_instance_private (ssimg);

	/* no need to composite */
	if (priv->width == G_MAXUINT || priv->height == G_MAXUINT) {
		pixbuf_bg = gdk_pixbuf_new_from_file (priv->filename, NULL);
	} else {
		/* this is always going to have alpha */
		pixbuf = gdk_pixbuf_new_from_file_at_scale (priv->filename,
							    priv->width * priv->scale,
							    priv->height * priv->scale,
							    FALSE, NULL);
		if (pixbuf != NULL) {
			if (gs_screenshot_image_use_desktop_background (ssimg, pixbuf)) {
				pixbuf_bg = gs_screenshot_image_get_desktop_pixbuf (ssimg);
				if (pixbuf_bg == NULL) {
					pixbuf_bg = g_object_ref (pixbuf);
				} else {
					gdk_pixbuf_composite (pixbuf, pixbuf_bg,
							      0, 0,
							      priv->width, priv->height,
							      0, 0, 1.0f, 1.0f,
							      GDK_INTERP_NEAREST, 255);
				}
			} else {
				pixbuf_bg = g_object_ref (pixbuf);
			}
		}
	}

	/* show icon */
	if (g_strcmp0 (priv->current_image, "image1") == 0) {
		if (pixbuf_bg != NULL) {
			gs_image_set_from_pixbuf_with_scale (GTK_IMAGE (priv->image2),
							     pixbuf_bg, priv->scale);
		}
		gtk_stack_set_visible_child_name (GTK_STACK (priv->stack), "image2");
		priv->current_image = "image2";
	} else {
		if (pixbuf_bg != NULL) {
			gs_image_set_from_pixbuf_with_scale (GTK_IMAGE (priv->image1),
							     pixbuf_bg, priv->scale);
		}
		gtk_stack_set_visible_child_name (GTK_STACK (priv->stack), "image1");
		priv->current_image = "image1";
	}

	gtk_widget_show (GTK_WIDGET (ssimg));
}
Пример #12
0
static GdkPixbuf * _mime_icon_emblem(GdkPixbuf * pixbuf, int size,
		char const * emblem)
{
	int esize;
	GdkPixbuf * epixbuf;
	GtkIconTheme * icontheme;
#if GTK_CHECK_VERSION(2, 14, 0)
	const unsigned int flags = GTK_ICON_LOOKUP_USE_BUILTIN
		| GTK_ICON_LOOKUP_FORCE_SIZE;
#else
	const unsigned int flags = GTK_ICON_LOOKUP_USE_BUILTIN;
#endif

	/* work on a copy */
	epixbuf = gdk_pixbuf_copy(pixbuf);
	g_object_unref(pixbuf);
	pixbuf = epixbuf;
	/* determine the size of the emblem */
	if(size >= 96)
		esize = 32;
	else if(size >= 48)
		esize = 24;
	else
		esize = 12;
	/* obtain the emblem's icon */
	icontheme = gtk_icon_theme_get_default();
	if((epixbuf = gtk_icon_theme_load_icon(icontheme, emblem, esize, flags,
					NULL)) == NULL)
		return pixbuf;
	/* blit the emblem */
#if 0 /* XXX does not show anything (bottom right) */
	gdk_pixbuf_composite(epixbuf, pixbuf, size - esize, size - esize,
			esize, esize, 0, 0, 1.0, 1.0, GDK_INTERP_NEAREST,
			255);
#else /* blitting at the top left instead */
	gdk_pixbuf_composite(epixbuf, pixbuf, 0, 0, esize, esize, 0, 0,
			1.0, 1.0, GDK_INTERP_NEAREST, 255);
#endif
	g_object_unref(epixbuf);
	return pixbuf;
}
static void
create_button_images (AppearanceData  *data)
{
  GtkWidget *widget = (GtkWidget*)data->wp_view;
  GtkStyle *style = gtk_widget_get_style (widget);
  GtkIconSet *icon_set;
  GdkPixbuf *pixbuf, *pb, *pb2;
  gint i, w, h;

  icon_set = gtk_style_lookup_icon_set (style, "gtk-media-play");
  pb = gtk_icon_set_render_icon (icon_set,
                                 style,
                                 GTK_TEXT_DIR_RTL,
                                 GTK_STATE_NORMAL,
                                 GTK_ICON_SIZE_MENU,
                                 widget,
                                 NULL);
  pb2 = gtk_icon_set_render_icon (icon_set,
                                  style,
                                  GTK_TEXT_DIR_LTR,
                                  GTK_STATE_NORMAL,
                                  GTK_ICON_SIZE_MENU,
                                  widget,
                                  NULL);
  w = gdk_pixbuf_get_width (pb);
  h = gdk_pixbuf_get_height (pb);

  for (i = 0; i < 3; i++) {
    pixbuf = gdk_pixbuf_new (GDK_COLORSPACE_RGB, TRUE, 8, 2 * w, h);
    gdk_pixbuf_fill (pixbuf, 0);
    if (i > 0)
      gdk_pixbuf_composite (pb, pixbuf, 0, 0, w, h, 0, 0, 1, 1, GDK_INTERP_NEAREST, 255);
    if (i < 2)
      gdk_pixbuf_composite (pb2, pixbuf, w, 0, w, h, w, 0, 1, 1, GDK_INTERP_NEAREST, 255);

    buttons[i] = pixbuf;
  }

  g_object_unref (pb);
  g_object_unref (pb2);
}
Пример #14
0
gint
render_camera(gpointer data)
{
  GdkPixbuf *pixbuf = NULL;
  GdkPixbuf *blobbuf= NULL;
  GdkGC         *gc = NULL;
  GtkWidget *drawing_area = GTK_WIDGET(data);
  uint16_t i;

  gc = GTK_WIDGET(drawing_area)->style->fg_gc[GTK_WIDGET_STATE(GTK_WIDGET(drawing_area))];

  player_update();

  if (g_blob_count > 0)
  {
    // Draw the blobs
    blobbuf = gdk_pixbuf_new(GDK_COLORSPACE_RGB, false, 8, 1, 1);
    for (i=0; i< g_blob_count; ++i)
    {
      // shift the color by 8-bits to account for the alpha channel
      gdk_pixbuf_fill(blobbuf, g_blobs[i].color << 8);

      gdk_pixbuf_composite(blobbuf,
                           g_pixbuf,
                           g_blobs[i].left,
                           g_blobs[i].top,
                           abs(g_blobs[i].right - g_blobs[i].left),
                           abs(g_blobs[i].top   - g_blobs[i].bottom),
                           1, 1, 1, 1, GDK_INTERP_NEAREST, 128);
    }
    gdk_pixbuf_unref(blobbuf);
  }

  // scale everything at the end
  if ((g_width==g_window_width)&&(g_height==g_window_height))
  { // we don't need to worry about scaling
    gdk_draw_pixbuf(GTK_WIDGET(drawing_area)->window, gc,
                    g_pixbuf, 0, 0, 0, 0, g_width, g_height,
                    GDK_RGB_DITHER_NONE, 0, 0);
  }
  else
  {
    pixbuf = gdk_pixbuf_scale_simple(g_pixbuf, g_window_width,
                                     g_window_height, GDK_INTERP_BILINEAR);
    gdk_draw_pixbuf(GTK_WIDGET(drawing_area)->window, gc,
                    pixbuf, 0, 0, 0, 0, g_window_width, g_window_height,
                    GDK_RGB_DITHER_NONE, 0, 0);
    gdk_pixbuf_unref(pixbuf);
  }

  return TRUE;
}
Пример #15
0
/**
 * Update view buffer with new animation frame data.
 *
 * The functino does not update any display related variable (like offset or
 * viewport) since all animation frames have same dimensions and we want
 * animation to play with given zoom.
 *
 * It is called automatically from timeout installed by g_timeout_add()
 *
 * \todo track if somebody changed image by utilizing sequence number
 *
 * \param data pointer to ViewImageDisplay structure cast to gpointer
 * \return FALSE
 */
gboolean view_idv_update_frame(gpointer data) {
	FrameUpdate *update = (FrameUpdate*) data;
	ViewImageDisplay* idv_data = NULL;
	gint delay = -1;
	GdkPixbuf* image = NULL;

	if ( update->sequence != update->view->last_sequence ) {
		g_free( (gpointer)data );
		return FALSE;
	}

	idv_data = view_idv_get_data_pointer(update->view);
	if ( NULL == idv_data ) {
		g_free( (gpointer)data );
		return FALSE;
	}

	// composite image to the internal view buffer
	image = model_iml_get_image(update->view->model);
	if ( NULL  == image ) {
		ERROR_LOG();
		g_free( (gpointer)data );
		return FALSE;
	}

	gdk_pixbuf_fill( idv_data->view_buffer, 0x000000ff);
	gdk_pixbuf_composite(image, idv_data->view_buffer,
			// destination position
			idv_data->viewport.x, idv_data->viewport.y,
			// destination dimension
			idv_data->viewport.width, idv_data->viewport.height,
			// offsets
			idv_data->viewport.x - idv_data->offset.x,
			idv_data->viewport.y - idv_data->offset.y,
			// zoom in both axes
			idv_data->zoom_factor, idv_data->zoom_factor,
			GDK_INTERP_BILINEAR, 255
		);

	// invalidate the image view region
	gdk_window_invalidate_rect(update->view->window, &(update->view->region), FALSE);

	// check and install new frame update timeout
	delay = model_iml_get_delay(update->view->model);
	if ( -1 != delay ) {
		g_timeout_add(delay, view_idv_update_frame, (gpointer)update);
	} else {
		g_free( (gpointer)data );
	}

	return FALSE;
}
Пример #16
0
static void
simple_gdk_pixbuf_composite(GdkPixbuf *source, GdkPixbuf *dest)
{
    gint height, width, src_height, src_width;

    src_height = gdk_pixbuf_get_height(source);
    src_width = gdk_pixbuf_get_width(source);
    height = gdk_pixbuf_get_height(dest);
    width = gdk_pixbuf_get_width(dest);

    gdk_pixbuf_composite(source, dest, 0, 0, width, height, 0.0, 0.0,
                         (gdouble)width/src_width, (gdouble)height/src_height,
                         GDK_INTERP_TILES, 0xff);
}
Пример #17
0
static void active_sensor_update_icon(ActiveSensor *active_sensor,
                                      GdkPixbuf *base_icon,
                                      SensorType sensor_type) {

    GdkPixbuf *overlay_icon, *new_icon;
    const gchar *overlay_icon_filename = NULL;
    SensorValueRange value_range;

    g_assert(active_sensor);

    /* select overlay icon
     * depending on sensor
     * value */
    value_range = sensor_value_range(active_sensor->sensor_values[0],
                                     active_sensor->sensor_low_value,
                                     active_sensor->sensor_high_value);

    if (sensor_type == TEMP_SENSOR) {
        overlay_icon_filename = temp_overlay_icons[value_range];
    }

    /* load base icon */
    new_icon = gdk_pixbuf_copy(base_icon);

    /* only load overlay if required */
    if (overlay_icon_filename) {
        overlay_icon = gdk_pixbuf_new_from_file_at_size(overlay_icon_filename,
                       DEFAULT_ICON_SIZE,
                       DEFAULT_ICON_SIZE,
                       NULL);
        if (overlay_icon) {
            gdk_pixbuf_composite(overlay_icon, new_icon,
                                 0, 0,
                                 DEFAULT_ICON_SIZE, DEFAULT_ICON_SIZE,
                                 0, 0,
                                 1.0, 1.0,
                                 GDK_INTERP_BILINEAR,
                                 255);

            g_object_unref(overlay_icon);
        }
    }
    gtk_image_set_from_pixbuf(GTK_IMAGE(active_sensor->icon),
                              new_icon);
    g_object_unref(new_icon);

}
Пример #18
0
static void
file_view_render_pixbuf_with_emblem (GtkTreeViewColumn* tree_column,
                                     GtkCellRenderer* cell,
                                     GtkTreeModel* tree_model,
                                     GtkTreeIter* iter,
                                     gpointer data)
{
	GdkPixbuf* file_icon = NULL;
	GdkPixbuf* emblem = NULL;

	AnjutaVcsStatus status;
	
	gtk_tree_model_get (tree_model, iter,
	                    COLUMN_STATUS, &status, 
	                    COLUMN_PIXBUF, &file_icon, -1);
	
	if (file_icon)
	{
		emblem = get_vcs_emblem (status);
		if (emblem)
		{
			GdkPixbuf *new_icon;

			new_icon = gdk_pixbuf_copy (file_icon);
			gdk_pixbuf_composite (emblem,
			                      new_icon,
			                      0, 0,
			                      gdk_pixbuf_get_width (file_icon),
			                      gdk_pixbuf_get_height (file_icon),
			                      0, 0,
			                      1, 1,
			                      GDK_INTERP_BILINEAR,
			                      COMPOSITE_ALPHA);

			g_object_set (cell, "pixbuf", new_icon, NULL);
			
			g_object_unref (new_icon);
			g_object_unref (emblem);
		}
		else
		{
			g_object_set (cell, "pixbuf", file_icon, NULL);
		}
		g_object_unref (file_icon);
	}
}
Пример #19
0
static GdkPixbuf *
transform_pixbuf (GdkPixbuf *orig,
                  gboolean has_tint, guint32 tint_color,
                  double alpha, gint width, gint height)
{
    GdkPixbuf *scaled;
    gint p_width, p_height;

    p_width = gdk_pixbuf_get_width (orig);
    p_height = gdk_pixbuf_get_height (orig);

    if (p_width != width ||
            p_height != height ||
            alpha < 1.0 ||
            has_tint)
    {
        int alpha_i;

        if (alpha >= 1.0)
            alpha_i = 0xff;
        else if (alpha <= 0.0)
            alpha_i = 0;
        else
            alpha_i = (guint) floor (0xff*alpha);
        if (alpha != 0xff)
        {
            scaled = gdk_pixbuf_new (GDK_COLORSPACE_RGB, TRUE, 8, width, height);
            gdk_pixbuf_fill (scaled, 0);
            gdk_pixbuf_composite (orig, scaled, 0, 0, width, height,
                                  0, 0, (double)width/p_width, (double)height/p_height,
                                  GDK_INTERP_BILINEAR, alpha_i);
        }
        else
            scaled = gdk_pixbuf_scale_simple (orig, width, height, GDK_INTERP_BILINEAR);
    }
    else
        scaled = g_object_ref (orig);

    if (has_tint)
        apply_tint (scaled, tint_color);

    return scaled;
}
Пример #20
0
void
nm_network_menu_item_best_strength (NMNetworkMenuItem * item,
                                    guint8 strength,
                                    NMApplet *applet)
{
	GdkPixbuf *icon = NULL, *pixbuf, *top;

	g_return_if_fail (item != NULL);
	g_return_if_fail (NM_IS_NETWORK_MENU_ITEM (item));

	strength = CLAMP (strength, 0, 100);

	/* Just do nothing if the new strength is less */
	if (strength < item->int_strength)
		return;

	item->int_strength = strength;

	if (strength > 80)
		icon = nma_icon_check_and_load ("nm-signal-100", &applet->wireless_100_icon, applet);
	else if (strength > 55)
		icon = nma_icon_check_and_load ("nm-signal-75", &applet->wireless_75_icon, applet);
	else if (strength > 30)
		icon = nma_icon_check_and_load ("nm-signal-50", &applet->wireless_50_icon, applet);
	else if (strength > 5)
		icon = nma_icon_check_and_load ("nm-signal-25", &applet->wireless_25_icon, applet);
	else
		icon = nma_icon_check_and_load ("nm-signal-00", &applet->wireless_00_icon, applet);

	pixbuf = gdk_pixbuf_copy (icon);

	/* If the AP is "secure", composite the lock icon on top of the signal bars */
	if (item->is_encrypted) {
		top = nma_icon_check_and_load ("nm-secure-lock", &applet->secure_lock_icon, applet);
		gdk_pixbuf_composite (top, pixbuf, 0, 0, gdk_pixbuf_get_width (top),
							  gdk_pixbuf_get_height (top),
							  0, 0, 1.0, 1.0,
							  GDK_INTERP_NEAREST, 255);
	}

	gtk_image_set_from_pixbuf (GTK_IMAGE (item->strength), pixbuf);
	g_object_unref (pixbuf);
}
Пример #21
0
gboolean
set_gtk_widget_bg_image (GtkWidget *widget, const gchar *filename, guint bgcolor)
{
	GdkPixbuf *pbuf, *bg;
	GdkPixmap *pixmap;
	gint width, height;

	if (GTK_WIDGET_NO_WINDOW(widget) || !GTK_WIDGET_REALIZED(widget) || !filename)
		goto fail;
   
	pbuf = gdk_pixbuf_new_from_file(filename, NULL);
	if (!pbuf)
		goto fail;

	width = gdk_pixbuf_get_width(pbuf);
	height = gdk_pixbuf_get_height(pbuf);

	bg = gdk_pixbuf_new(GDK_COLORSPACE_RGB, TRUE,
				gdk_pixbuf_get_bits_per_sample(pbuf),
				width, height);
	gdk_pixbuf_fill(bg, bgcolor);
	gdk_pixbuf_composite(pbuf, bg, 0, 0, width, height,
				0, 0, 1, 1, GDK_INTERP_BILINEAR,0xFF);

	pixmap = gdk_pixmap_new(widget->window, width, height, -1);
	gdk_draw_pixbuf(pixmap, NULL, bg, 0, 0, 0, 0,
			-1, -1, GDK_RGB_DITHER_NORMAL, 0, 0);

  	g_object_unref(pbuf);
  	g_object_unref(bg);
   
	gtk_widget_set_app_paintable(widget,TRUE);
	gdk_window_set_back_pixmap(widget->window, pixmap, FALSE);
	g_object_unref(pixmap);
	//gtk_widget_queue_draw(widget);

	return TRUE;
fail:
	return FALSE;
}
Пример #22
0
static GdkPixbuf *add_emblem_to_icon( GdkPixbuf *icon, GdkPixbuf *emblem )
{
	if ( icon == NULL ) {
		g_warning ( "add_emblem_to_icon: icon is NULL." );
		return NULL;
	} else if ( emblem == NULL ) {
		g_warning ( "add_emblem_to_icon: emblem is NULL." );
		return NULL;
	}

	GdkPixbuf *result = gdk_pixbuf_copy( icon );

	if ( result == NULL ) {
		g_warning( "add_emblem_to_icon: failed to copy icon.");
		return NULL;
	}

	gdk_pixbuf_composite(emblem, result, 0, 0,
			MIN(gdk_pixbuf_get_width(emblem), gdk_pixbuf_get_width(result)),
			MIN(gdk_pixbuf_get_height(emblem), gdk_pixbuf_get_height(result)),
			0, 0, 1, 1, GDK_INTERP_NEAREST, 255);

	return result;
}
Пример #23
0
/* shouldn't use this -- slow -- change the alpha channel instead. */
void vik_viewport_draw_pixbuf_with_alpha ( VikViewport *vvp, GdkPixbuf *pixbuf, gint alpha,
                                           gint src_x, gint src_y, gint dest_x, gint dest_y, gint w, gint h )
{
  gint real_dest_x = MAX(dest_x,0);
  gint real_dest_y = MAX(dest_y,0);

  if ( alpha == 0 )
    return; /* don't waste your time */

  if ( w > vvp->alpha_pixbuf_width || h > vvp->alpha_pixbuf_height )
  {
    if ( vvp->alpha_pixbuf )
      g_object_unref ( G_OBJECT ( vvp->alpha_pixbuf ) );
    vvp->alpha_pixbuf_width = MAX(w,vvp->alpha_pixbuf_width);
    vvp->alpha_pixbuf_height = MAX(h,vvp->alpha_pixbuf_height);
    vvp->alpha_pixbuf = gdk_pixbuf_new ( GDK_COLORSPACE_RGB, FALSE, 8, vvp->alpha_pixbuf_width, vvp->alpha_pixbuf_height );
  }

  w = MIN(w,vvp->width - dest_x);
  h = MIN(h,vvp->height - dest_y);

  /* check that we are drawing within boundaries. */
  src_x += (real_dest_x - dest_x);
  src_y += (real_dest_y - dest_y);
  w -= (real_dest_x - dest_x);
  h -= (real_dest_y - dest_y);

  gdk_pixbuf_get_from_drawable ( vvp->alpha_pixbuf, vvp->scr_buffer, NULL,
                                 real_dest_x, real_dest_y, 0, 0, w, h );

  /* do a composite */
  gdk_pixbuf_composite ( pixbuf, vvp->alpha_pixbuf, 0, 0, w, h, -src_x, -src_y, 1, 1, 0, alpha );

  /* draw pixbuf_tmp */
  vik_viewport_draw_pixbuf ( vvp, vvp->alpha_pixbuf, 0, 0, real_dest_x, real_dest_y, w, h );
}
Пример #24
0
static GdkPixbufAnimation*
compose_animation_from_array (animation_param_entry **anim_array, gint array_len, gint pix_size)
{
     GdkPixbufSimpleAnim *result = NULL;
     gint frames = 1, duration = 0,  duration_p, frames_p;
     /* calculate frames count as multiplication of all frames and duration as max */
     gint i;

     GTimeVal start_time = {0, 0};
     for (i = 0; i<array_len; i++){
	  /* initialize iterators for each animation*/
	  animation_param_entry *p_entry = anim_array[i];
	  
	  p_entry->iter = gdk_pixbuf_animation_get_iter (p_entry->anim, &start_time);
	  
	  frames_p = duration_p = 0;
	  pgpug_pixbuf_animation_get_detail (p_entry->anim, &frames_p, &duration_p);

	  duration = duration < duration_p ? duration_p : duration;
	  frames *= frames_p;
     }	  



     float fps = duration > 0 ? frames * 1000 / duration : 1;
     gint frame_change_time = duration / frames; 
     DEBG_MSG ("Fps: %f. frame change time :%dmsec", fps,frame_change_time);

     result = gdk_pixbuf_simple_anim_new (pix_size, pix_size, fps);
 
     gint elapsed_time = 0, frames_counter = 1;
     while (elapsed_time <= duration && frames_counter++ <= frames){

	  animation_param_entry *p_entry = anim_array[0];
	  GdkPixbuf *base_pixbuf = gdk_pixbuf_copy (gdk_pixbuf_animation_iter_get_pixbuf (p_entry->iter));
	  g_time_val_add (&start_time, frame_change_time * 1000);
	  gdk_pixbuf_animation_iter_advance (p_entry->iter, &start_time);

	  for (i = 1; i < array_len; i++) {
	       
	       p_entry = anim_array[i];
	       GdkPixbuf *src_pixbuf = gdk_pixbuf_animation_iter_get_pixbuf (p_entry->iter);
	       gint x_offset, y_offset, src_size;
	       src_size = gdk_pixbuf_get_width (src_pixbuf);

	       
	       pgpug_pixbuf_calculate_composition_offset (pix_size, src_size, p_entry->pos, &x_offset, &y_offset);

	       
	       gdk_pixbuf_composite (src_pixbuf, 
				     base_pixbuf,
				     x_offset, y_offset, 
				     src_size, src_size, 
				     x_offset, y_offset,
				     1.0f, 1.0f,
				     GDK_INTERP_BILINEAR, 255);
	       gboolean res;
	       res = gdk_pixbuf_animation_iter_advance (p_entry->iter, &start_time);
	       
	  }

	  gdk_pixbuf_simple_anim_add_frame (result, base_pixbuf);
	  elapsed_time += frame_change_time;
     }

     gdk_pixbuf_simple_anim_set_loop (result, TRUE);

     for (i=0;i<array_len;i++){
	  g_object_unref (anim_array[i]->iter);
     }

     return GDK_PIXBUF_ANIMATION (result);
}
Пример #25
0
static GdkPixbuf*
compose_splash(const gchar *version)
{
    gint xpos = 224;
    gint ypos = 36;
    GdkPixbufLoader *loader;
    GdkPixbuf *base, *digit;
    GError *err = NULL;
    guint i;
    gchar *p, *filename;

    p = gwy_find_self_dir("pixmaps");
    filename = g_build_filename(p, "splash.png", NULL);
    g_free(p);

    base = gdk_pixbuf_new_from_file(filename, &err);
    if (!base) {
        g_warning("Cannot load base splash image: %s", err->message);
        g_clear_error(&err);
        sanity_check(filename);
        g_free(filename);
        return NULL;
    }
    g_free(filename);

    while (*version) {
        loader = NULL;
        for (i = 0; i < G_N_ELEMENTS(digits); i++) {
            if (*version == digits[i].c)
                break;
        }
        if (i == G_N_ELEMENTS(digits)) {
            g_warning("Cannot find image for %c", *version);
            version++;
            continue;
        }

        loader = gdk_pixbuf_loader_new_with_type("png", &err);
        /* We have already successfully loaded base PNG */
        g_assert(loader);

        if (!gdk_pixbuf_loader_write(loader, digits[i].data, digits[i].len,
                                     &err)) {
            g_critical("Cannot load in-line image for %c as PNG", *version);
            break;
        }
        if (!gdk_pixbuf_loader_close(loader, &err)) {
            g_critical("Cannot load in-line image for %c as PNG", *version);
            break;
        }

        digit = gdk_pixbuf_loader_get_pixbuf(loader);
        g_assert(digit);

        gdk_pixbuf_composite(digit, base,
                             xpos, ypos,
                             gdk_pixbuf_get_width(digit),
                             gdk_pixbuf_get_height(digit),
                             xpos, ypos,
                             1.0, 1.0,
                             GDK_INTERP_NEAREST,
                             255);
        xpos += gdk_pixbuf_get_width(digit);
        g_object_unref(loader);

        version++;
    }
    return base;
}
static GdkPixbuf *
composite_marks (GtkSourceView *view,
                 GSList        *marks,
                 gint           size)
{
	GdkPixbuf *composite;
	gint mark_width;
	gint mark_height;

	/* Draw the mark with higher priority */
	marks = g_slist_sort_with_data (marks, sort_marks_by_priority, view);

	composite = NULL;
	mark_width = 0;
	mark_height = 0;

	/* composite all the pixbufs for the marks present at the line */
	do
	{
		GtkSourceMark *mark;
		GtkSourceMarkAttributes *attrs;
		const GdkPixbuf *pixbuf;

		mark = marks->data;
		attrs = gtk_source_view_get_mark_attributes (view,
		                                             gtk_source_mark_get_category (mark),
		                                             NULL);

		if (attrs == NULL)
		{
			continue;
		}

		pixbuf = gtk_source_mark_attributes_render_icon (attrs,
		                                                 GTK_WIDGET (view),
		                                                 size);

		if (pixbuf != NULL)
		{
			if (composite == NULL)
			{
				composite = gdk_pixbuf_copy (pixbuf);
				mark_width = gdk_pixbuf_get_width (composite);
				mark_height = gdk_pixbuf_get_height (composite);
			}
			else
			{
				gint pixbuf_w;
				gint pixbuf_h;

				pixbuf_w = gdk_pixbuf_get_width (pixbuf);
				pixbuf_h = gdk_pixbuf_get_height (pixbuf);

				gdk_pixbuf_composite (pixbuf,
				                      composite,
				                      0, 0,
				                      mark_width, mark_height,
				                      0, 0,
				                      (gdouble) pixbuf_w / mark_width,
				                      (gdouble) pixbuf_h / mark_height,
				                      GDK_INTERP_BILINEAR,
				                      COMPOSITE_ALPHA);
			}
		}

		marks = g_slist_next (marks);
	}
	while (marks);

	return composite;
}
Пример #27
0
static GtkIconSet* accessx_status_applet_altgraph_icon_set(AccessxStatusApplet* sapplet, GtkWidget* widget)
{
    GtkIconSet* icon_set = gtk_icon_set_new();
    gint i;
    GtkStateType states[3] = {GTK_STATE_NORMAL, GTK_STATE_INSENSITIVE, GTK_STATE_SELECTED};
    GtkStyle* style = gtk_widget_get_style(widget);
    GdkPixbuf* icon_base;

    gtk_widget_set_sensitive(widget, TRUE);

    for (i = 0; i < 3; ++i)
    {
        int alpha;
        GdkColor* fg;
        GdkColor* bg;
        GtkIconSource* source = gtk_icon_source_new();
        GdkPixbuf* pixbuf;
        GdkPixbuf* glyph_pixbuf;
        gboolean wildcarded = FALSE;
        fg = &style->text[states[i]];
        bg = &style->white;
        switch (states[i])
        {
        case GTK_STATE_NORMAL:
            alpha = 255;
            gtk_widget_set_sensitive(widget, TRUE);
#if GTK_CHECK_VERSION (3, 0, 0)
            gtk_widget_set_state_flags (widget, GTK_STATE_FLAG_NORMAL, TRUE);
#else
            gtk_widget_set_state(widget, GTK_STATE_NORMAL);
#endif
            break;
        case GTK_STATE_SELECTED:
            /* FIXME: should use text/base here, for selected ? */
            fg = &style->white;
            bg = &style->black;
            alpha = 255;
            gtk_widget_set_sensitive(widget, TRUE);
#if GTK_CHECK_VERSION (3, 0, 0)
            gtk_widget_set_state_flags (widget, GTK_STATE_FLAG_SELECTED, TRUE);
#else
            gtk_widget_set_state(widget, GTK_STATE_SELECTED);
#endif
            break;
        case GTK_STATE_INSENSITIVE:
        default:
            alpha = 63;
            gtk_widget_set_sensitive(widget, FALSE);
            wildcarded = TRUE;
            break;
        }

        icon_base = gtk_widget_render_icon(widget, ACCESSX_BASE_ICON, icon_size_spec, NULL);
        pixbuf = gdk_pixbuf_copy(icon_base);
        g_object_unref(icon_base);
        /*
        * should be N_("ae"));
        * need en_ locale for this.
        */
        /*
        * Translators: substitute an easily-recognized single glyph
        * from Level 2, i.e. an AltGraph character from a common keyboard
        * in your locale.
        */
        glyph_pixbuf = accessx_status_applet_get_glyph_pixbuf(sapplet, widget, pixbuf, fg, bg, ("æ"));
        gdk_pixbuf_composite(glyph_pixbuf, pixbuf, 0, 0, gdk_pixbuf_get_width(glyph_pixbuf), gdk_pixbuf_get_height(glyph_pixbuf), 0., 0., 1.0, 1.0, GDK_INTERP_NEAREST, alpha);
        g_object_unref(glyph_pixbuf);
        gtk_icon_source_set_pixbuf(source, pixbuf);
        gtk_icon_source_set_state(source, states[i]);
        gtk_icon_source_set_state_wildcarded(source, wildcarded);
        gtk_icon_set_add_source(icon_set, source);
        gtk_icon_source_free(source);
    }
    /* we mucked about with the box's state to create the icons; restore it to normal */
#if GTK_CHECK_VERSION (3, 0, 0)
    gtk_widget_set_state_flags (widget, GTK_STATE_FLAG_NORMAL, TRUE);
#else
    gtk_widget_set_state(widget, GTK_STATE_NORMAL);
#endif
    gtk_widget_set_sensitive(widget, TRUE);

    return icon_set;
}
Пример #28
0
/* Timeout handler to regenerate the frame */
static gint
timeout (gpointer data)
{
  double f;
  int i;
  double xmid, ymid;
  double radius;

  gdk_pixbuf_copy_area (background, 0, 0, back_width, back_height,
                        frame, 0, 0);

  f = (double) (frame_num % CYCLE_LEN) / CYCLE_LEN;

  xmid = back_width / 2.0;
  ymid = back_height / 2.0;

  radius = MIN (xmid, ymid) / 2.0;

  for (i = 0; i < N_IMAGES; i++)
    {
      double ang;
      int xpos, ypos;
      int iw, ih;
      double r;
      GdkRectangle r1, r2, dest;
      double k;

      ang = 2.0 * G_PI * (double) i / N_IMAGES - f * 2.0 * G_PI;

      iw = gdk_pixbuf_get_width (images[i]);
      ih = gdk_pixbuf_get_height (images[i]);

      r = radius + (radius / 3.0) * sin (f * 2.0 * G_PI);

      xpos = floor (xmid + r * cos (ang) - iw / 2.0 + 0.5);
      ypos = floor (ymid + r * sin (ang) - ih / 2.0 + 0.5);

      k = (i & 1) ? sin (f * 2.0 * G_PI) : cos (f * 2.0 * G_PI);
      k = 2.0 * k * k;
      k = MAX (0.25, k);

      r1.x = xpos;
      r1.y = ypos;
      r1.width = iw * k;
      r1.height = ih * k;

      r2.x = 0;
      r2.y = 0;
      r2.width = back_width;
      r2.height = back_height;

      if (gdk_rectangle_intersect (&r1, &r2, &dest))
        gdk_pixbuf_composite (images[i],
                              frame,
                              dest.x, dest.y,
                              dest.width, dest.height,
                              xpos, ypos,
                              k, k,
                              GDK_INTERP_NEAREST,
                              ((i & 1)
                               ? MAX (127, fabs (255 * sin (f * 2.0 * G_PI)))
                               : MAX (127, fabs (255 * cos (f * 2.0 * G_PI)))));
    }

  GDK_THREADS_ENTER ();
  gtk_widget_queue_draw (da);
  GDK_THREADS_LEAVE ();

  frame_num++;
  return TRUE;
}
Пример #29
0
static GdkPixbuf* accessx_status_applet_slowkeys_image(AccessxStatusApplet* sapplet, XkbAccessXNotifyEvent* event)
{
    GdkPixbuf* ret_pixbuf;
    GdkWindow* window;
    gboolean is_idle = TRUE;
    gchar* stock_id = SLOWKEYS_IDLE_ICON;
    GtkStyle* style = gtk_widget_get_style(GTK_WIDGET(sapplet->applet));
    GdkColor bg = style->bg[GTK_STATE_NORMAL];

    if (event != NULL)
    {
        is_idle = FALSE;

        switch (event->detail)
        {
        case XkbAXN_SKPress:
            stock_id = ACCESSX_BASE_ICON;
            if (_sk_timeout)
            {
                g_source_remove(_sk_timeout);
                _sk_timeout = 0;
            }
            break;
        case XkbAXN_SKAccept:
            stock_id = ACCESSX_ACCEPT_BASE;
            gdk_color_parse("#009900", &bg);
            break;
        case XkbAXN_SKReject:
            stock_id = ACCESSX_REJECT_BASE;
            gdk_color_parse("#990000", &bg);
            _sk_timeout = g_timeout_add_full(G_PRIORITY_HIGH_IDLE, MAX(event->sk_delay, 150), timer_reset_slowkeys_image, sapplet->slowfoo, NULL);
            break;
        case XkbAXN_SKRelease:
        default:
            stock_id = SLOWKEYS_IDLE_ICON;
            is_idle = TRUE;
            break;
        }
    }

    ret_pixbuf = gtk_widget_render_icon(GTK_WIDGET(sapplet->applet), stock_id, icon_size_spec, NULL);

    if (!is_idle)
    {
        GdkPixbuf* glyph_pixbuf;
        GdkPixbuf* tmp_pixbuf;
        GdkColor  fg;
        gchar* glyphstring = N_("a");
        tmp_pixbuf = ret_pixbuf;
        ret_pixbuf = gdk_pixbuf_copy(tmp_pixbuf);
        g_object_unref(tmp_pixbuf);

        window = gtk_widget_get_window(GTK_WIDGET(sapplet->applet));

        if (event && window)
        {
            KeySym keysym = XKeycodeToKeysym(GDK_WINDOW_XDISPLAY(window), event->keycode, 0);
            glyphstring = XKeysymToString(keysym);

            if ((!g_utf8_validate(glyphstring, -1, NULL)) || (g_utf8_strlen(glyphstring, -1) > 1))
            {
                glyphstring = "";
            }
        }

#if GTK_CHECK_VERSION (3, 0, 0)
        fg = style->fg[gtk_widget_get_state_flags (GTK_WIDGET (sapplet->applet))];
#else
        fg = style->fg[gtk_widget_get_state(GTK_WIDGET(sapplet->applet))];
#endif
        glyph_pixbuf = accessx_status_applet_get_glyph_pixbuf(sapplet, GTK_WIDGET(sapplet->applet), ret_pixbuf, &fg, &bg, glyphstring);
        gdk_pixbuf_composite(glyph_pixbuf, ret_pixbuf, 0, 0, gdk_pixbuf_get_width(glyph_pixbuf), gdk_pixbuf_get_height(glyph_pixbuf), 0., 0., 1.0, 1.0, GDK_INTERP_NEAREST, 255);
        g_object_unref(glyph_pixbuf);
    }

    return ret_pixbuf;
}
static void
update_icon (DrWright *dr)
{
    GdkPixbuf *pixbuf;
    GdkPixbuf *tmp_pixbuf;
    gint       width, height;
    gfloat     r;
    gint       offset;
    gboolean   set_pixbuf;

    if (!dr->enabled) {
        gtk_status_icon_set_from_pixbuf (dr->icon,
                                         dr->disabled_bar);
        return;
    }

    tmp_pixbuf = gdk_pixbuf_copy (dr->neutral_bar);

    width = gdk_pixbuf_get_width (tmp_pixbuf);
    height = gdk_pixbuf_get_height (tmp_pixbuf);

    set_pixbuf = TRUE;

    switch (dr->state) {
    case STATE_BREAK:
    case STATE_BREAK_SETUP:
        r = 1;
        break;

    case STATE_BREAK_DONE:
    case STATE_BREAK_DONE_SETUP:
    case STATE_START:
        r = 0;
        break;

    default:
        r = (float) (drw_timer_elapsed (dr->timer) + dr->save_last_time) /
            (float) dr->type_time;
        break;
    }

    offset = CLAMP ((height - 0) * (1.0 - r), 1, height - 0);

    switch (dr->state) {
    case STATE_WARN:
        pixbuf = dr->red_bar;
        set_pixbuf = FALSE;
        break;

    case STATE_BREAK_SETUP:
    case STATE_BREAK:
        pixbuf = dr->red_bar;
        break;

    default:
        pixbuf = dr->green_bar;
    }

    gdk_pixbuf_composite (pixbuf,
                          tmp_pixbuf,
                          0,
                          offset,
                          width,
                          height - offset,
                          0,
                          0,
                          1.0,
                          1.0,
                          GDK_INTERP_BILINEAR,
                          255);

    if (set_pixbuf) {
        gtk_status_icon_set_from_pixbuf (dr->icon,
                                         tmp_pixbuf);
    }

    if (dr->composite_bar) {
        g_object_unref (dr->composite_bar);
    }

    dr->composite_bar = tmp_pixbuf;
}