Exemplo n.º 1
0
static VALUE
rg_render_pixmap_and_mask(int argc, VALUE *argv, VALUE self)
{
    VALUE colormap_or_alpha, alpha;
    GdkPixmap *pixmap;
    GdkBitmap *mask;

    rb_scan_args(argc, argv, "11", &colormap_or_alpha, &alpha);

    if (rb_obj_is_kind_of(colormap_or_alpha, GTYPE2CLASS(GDK_TYPE_COLORMAP))){
        gdk_pixbuf_render_pixmap_and_mask_for_colormap(_SELF(self),
                                                       RVAL2GOBJ(colormap_or_alpha),
                                                       &pixmap,
                                                       &mask,
                                                       NIL_P(alpha)?0:NUM2INT(alpha));
    } else {
        gdk_pixbuf_render_pixmap_and_mask(_SELF(self),
                                          &pixmap,
                                          &mask,
                                          NIL_P(colormap_or_alpha)?
                                          0:NUM2INT(colormap_or_alpha));
    }

    return rb_ary_new3(2,
                       pixmap ? GOBJ2RVAL(pixmap) : Qnil,
                       mask ? GOBJ2RVAL(mask) : Qnil);
}
Exemplo n.º 2
0
int
setupwindow()
{
  GdkPixmap *background;
  GdkPixbuf *pixbuf;
  GdkPixbuf *scaled;
  GdkScreen *screen;
  GdkColormap *colormap;
  GError *error=NULL;
  GtkStyle *style;

  window=gtk_window_new(GTK_WINDOW_TOPLEVEL);
  g_signal_connect(G_OBJECT(window), "expose_event", G_CALLBACK(expose_window),NULL);
  gtk_window_set_title(GTK_WINDOW(window), "clock");
  gtk_window_stick(GTK_WINDOW(window));
  gtk_window_set_resizable(GTK_WINDOW(window),TRUE);
  gtk_window_set_skip_taskbar_hint(GTK_WINDOW(window),TRUE);
  gtk_window_set_keep_above(GTK_WINDOW(window),TRUE);
  gtk_container_set_border_width(GTK_CONTAINER(window), 3);
  gtk_window_set_decorated(GTK_WINDOW(window),TRUE);
  gtk_window_set_default_size(GTK_WINDOW(window),100,100);
  gtk_widget_set_app_paintable(window,TRUE);

  /* Get the screen to get the colormap */
  screen=gtk_widget_get_screen(window);
  colormap = gdk_screen_get_rgba_colormap(screen);
  if(colormap != NULL){
    alpha_channel_support=TRUE;
  } else {
    alpha_channel_support=FALSE;
    colormap=gdk_screen_get_rgb_colormap(screen);
    g_print("Sorry, no alpha!\n");
  }
  /* Tell the window to use the colormap */
  gtk_widget_set_colormap(window,colormap);

  /* Get a pixbuf from the image file */
  pixbuf=gdk_pixbuf_new_from_file("clockface.png",&error);

  if(pixbuf==NULL){
    g_print("Failed to open background image: %s\n", error->message);
    g_error_free(error);
    error=NULL;
    return 0;
  }
  /* Make it the same size as the window */
  scaled=gdk_pixbuf_scale_simple(pixbuf,100,100, GDK_INTERP_BILINEAR);
  /* Render it using the colormap of the window */
  gdk_pixbuf_render_pixmap_and_mask_for_colormap(scaled,colormap,&background,NULL,0);
  /* Make a new style, stick the background in it, tell window to use it. */
  style = gtk_style_new();
  style->bg_pixmap[0] = background;
  gtk_widget_set_style(GTK_WIDGET(window),GTK_STYLE(style));

  /*gtk_window_set_opacity(GTK_WINDOW(window),0.3);*/
  gtk_window_move(GTK_WINDOW(window), 0, 0);
  gtk_widget_show_all(window);
  return 1;
}
Exemplo n.º 3
0
/**
 * gdk_pixbuf_render_pixmap_and_mask:
 * @pixbuf: A pixbuf.
 * @pixmap_return: Location to store a pointer to the created pixmap,
 *   or %NULL if the pixmap is not needed.
 * @mask_return: Location to store a pointer to the created mask,
 *   or %NULL if the mask is not needed.
 * @alpha_threshold: Threshold value for opacity values.
 *
 * Creates a pixmap and a mask bitmap which are returned in the @pixmap_return
 * and @mask_return arguments, respectively, and renders a pixbuf and its
 * corresponding thresholded alpha mask to them.  This is merely a convenience
 * function; applications that need to render pixbufs with dither offsets or to
 * given drawables should use gdk_draw_pixbuf() and gdk_pixbuf_render_threshold_alpha().
 *
 * The pixmap that is created is created for the colormap returned
 * by gdk_rgb_get_colormap(). You normally will want to instead use
 * the actual colormap for a widget, and use
 * gdk_pixbuf_render_pixmap_and_mask_for_colormap().
 *
 * If the pixbuf does not have an alpha channel, then *@mask_return will be set
 * to %NULL.
 **/
void
gdk_pixbuf_render_pixmap_and_mask (GdkPixbuf  *pixbuf,
				   GdkPixmap **pixmap_return,
				   GdkBitmap **mask_return,
				   int         alpha_threshold)
{
  gdk_pixbuf_render_pixmap_and_mask_for_colormap (pixbuf,
						  gdk_rgb_get_colormap (),
						  pixmap_return, mask_return,
						  alpha_threshold);
}
Exemplo n.º 4
0
/**
 * @brief Add an icon to the #guiIcon icon structure.
 *
 * @param theme theme to load the icon from
 * @param size size of the icon to load
 * @param gdkIcon memory location to store a pointer to the created pixmap
 * @param gdkIconMask memory location to store a pointer to the created mask
 *
 * @return #True (ok) or #False (error)
 */
static int gtkLoadIcon(GtkIconTheme *theme, gint size, GdkPixmap **gdkIcon, GdkBitmap **gdkIconMask)
{
    GdkPixbuf *pixbuf;
    guchar *data;
    int csize, i;

    pixbuf = gtk_icon_theme_load_icon(theme, guiIconName, size, 0, NULL);

    if (pixbuf)
        gdk_pixbuf_render_pixmap_and_mask_for_colormap(pixbuf, gdk_colormap_get_system(), gdkIcon, gdkIconMask, THRESHOLD);

    if (pixbuf &&
        gdk_pixbuf_get_colorspace(pixbuf) == GDK_COLORSPACE_RGB &&
        gdk_pixbuf_get_n_channels(pixbuf) == 4 &&
        gdk_pixbuf_get_bits_per_sample(pixbuf) == 8) {
        csize = guiIcon.collection_size;
        guiIcon.collection_size += 2 + gdk_pixbuf_get_width(pixbuf) * gdk_pixbuf_get_height(pixbuf);

        guiIcon.collection = realloc(guiIcon.collection, guiIcon.collection_size * sizeof(*guiIcon.collection));

        if (guiIcon.collection) {
            guiIcon.collection[csize++] = gdk_pixbuf_get_width(pixbuf);
            guiIcon.collection[csize++] = gdk_pixbuf_get_height(pixbuf);

            data = gdk_pixbuf_get_pixels(pixbuf);

            for (i = csize; i < guiIcon.collection_size; data += 4, i++)
                guiIcon.collection[i] = (uint32_t)(data[3] << 24) | AV_RB24(data); // RGBA -> ARGB
        }

        g_object_unref(pixbuf);
    } else
        mp_msg(MSGT_GPLAYER, MSGL_WARN, MSGTR_GUI_MSG_IconError, guiIconName, size);

    /* start up GTK which realizes the pixmaps */
    gtk_main_iteration_do(FALSE);

    return (pixbuf != NULL);
}