示例#1
0
// 根据chess_board不断更新界面的函数。在显示窗口时就被不断调用。
// 输入:控件draw_window。
// 返回值:void
void draw_main(GtkWidget * widget)
{
    cairo_t * cr = gdk_cairo_create(widget->window);
    gdk_cairo_set_source_pixbuf(cr,background,0,0);
    cairo_paint(cr);
    cairo_fill (cr);

    for(int i=0;i<N;i++)
    {
        for(int j=0;j<N;j++)
        {
            if(chess_board[i*N+j]==1)
            {
                gdk_cairo_set_source_pixbuf(cr,A_pic,draw_position[i*N+j][0],draw_position[i*N+j][1]);
                cairo_paint(cr);
                cairo_fill (cr);
            }
            if(chess_board[i*N+j]==-1)
            {
                gdk_cairo_set_source_pixbuf(cr,B_pic,draw_position[i*N+j][0],draw_position[i*N+j][1]);
                cairo_paint(cr);
                cairo_fill (cr);
            }
        }
    }

    cairo_destroy(cr);
}
示例#2
0
void plank_tests_drawing_docksurface_gaussian_blur (void) {
	PlankDrawingColor color = {0};
	PlankDrawingColor color2 = {0};
	PlankDrawingDockSurface* surface = NULL;
	PlankDrawingDockSurface* surface2 = NULL;
	GdkPixbuf* pixbuf = NULL;
	GdkPixbuf* _tmp0_ = NULL;
	PlankDrawingDockSurface* _tmp1_ = NULL;
	PlankDrawingDockSurface* _tmp2_ = NULL;
	cairo_t* cr = NULL;
	cairo_t* _tmp3_ = NULL;
	cairo_t* _tmp4_ = NULL;
	cairo_t* cr2 = NULL;
	cairo_t* _tmp5_ = NULL;
	cairo_t* _tmp6_ = NULL;
	PlankDrawingColor _tmp7_ = {0};
	PlankDrawingColor _tmp8_ = {0};
	PlankDrawingColor _tmp9_ = {0};
	PlankDrawingColor _tmp10_ = {0};
	_tmp0_ = plank_drawing_drawing_service_load_icon (PLANK_TESTS_TEST_ICON, 256, 256);
	_g_object_unref0 (pixbuf);
	pixbuf = _tmp0_;
	_tmp1_ = plank_drawing_dock_surface_new (256, 256);
	_g_object_unref0 (surface);
	surface = _tmp1_;
	_tmp2_ = plank_drawing_dock_surface_new (256, 256);
	_g_object_unref0 (surface2);
	surface2 = _tmp2_;
	_tmp3_ = plank_drawing_dock_surface_get_Context (surface);
	_tmp4_ = _tmp3_;
	cr = _tmp4_;
	gdk_cairo_set_source_pixbuf (cr, pixbuf, (gdouble) 0, (gdouble) 0);
	cairo_paint (cr);
	_tmp5_ = plank_drawing_dock_surface_get_Context (surface2);
	_tmp6_ = _tmp5_;
	cr2 = _tmp6_;
	gdk_cairo_set_source_pixbuf (cr2, pixbuf, (gdouble) 0, (gdouble) 0);
	cairo_paint (cr2);
	plank_drawing_dock_surface_gaussian_blur (surface, 7);
	plank_drawing_dock_surface_gaussian_blur (surface, 15);
	plank_drawing_dock_surface_gaussian_blur (surface, 31);
	plank_drawing_dock_surface_gaussian_blur (surface2, 7);
	plank_drawing_dock_surface_gaussian_blur (surface2, 15);
	plank_drawing_dock_surface_gaussian_blur (surface2, 31);
	plank_drawing_dock_surface_average_color (surface, &_tmp7_);
	color = _tmp7_;
	plank_drawing_dock_surface_average_color (surface2, &_tmp8_);
	color2 = _tmp8_;
	_tmp9_ = color;
	_tmp10_ = color2;
	_vala_assert (_plank_drawing_color_equal (&_tmp9_, &_tmp10_) == TRUE, "color == color2");
	_g_object_unref0 (pixbuf);
	_g_object_unref0 (surface2);
	_g_object_unref0 (surface);
}
static void
update_display_preview (CcBackgroundPanel *panel,
                        GtkWidget         *widget,
                        CcBackgroundItem  *current_background)
{
  CcBackgroundPanelPrivate *priv = panel->priv;
  GtkAllocation allocation;
  const gint preview_width = 309;
  const gint preview_height = 168;
  gint scale_factor;
  GdkPixbuf *pixbuf;
  cairo_t *cr;

  gtk_widget_get_allocation (widget, &allocation);

  if (!current_background)
    return;

  scale_factor = gtk_widget_get_scale_factor (widget);
  pixbuf = cc_background_item_get_frame_thumbnail (current_background,
                                                   priv->thumb_factory,
                                                   preview_width,
                                                   preview_height,
                                                   scale_factor,
                                                   -2, TRUE);

  cr = gdk_cairo_create (gtk_widget_get_window (widget));
  gdk_cairo_set_source_pixbuf (cr,
                               pixbuf,
                               0, 0);
  cairo_paint (cr);
  g_object_unref (pixbuf);

  pixbuf = NULL;
  if (current_background == priv->current_background &&
      panel->priv->display_screenshot != NULL)
    {
      pixbuf = gdk_pixbuf_scale_simple (panel->priv->display_screenshot,
                                        preview_width,
                                        preview_height,
                                        GDK_INTERP_BILINEAR);
    }

  if (pixbuf)
    {
      gdk_cairo_set_source_pixbuf (cr,
                                   pixbuf,
                                   0, 0);
      cairo_paint (cr);
      g_object_unref (pixbuf);
    }

  cairo_destroy (cr);
}
示例#4
0
static gboolean cvImageWidget_expose(GtkWidget* widget, GdkEventExpose* event, gpointer data)
{
#ifdef HAVE_OPENGL
    CvWindow* window = (CvWindow*)data;

    if (window->useGl)
    {
        drawGl(window);
        return TRUE;
    }
#else
    (void)data;
#endif

  CvImageWidget *image_widget = NULL;
  cairo_t *cr = NULL;
  GdkPixbuf *pixbuf = NULL;

  g_return_val_if_fail (widget != NULL, FALSE);
  g_return_val_if_fail (CV_IS_IMAGE_WIDGET (widget), FALSE);
  g_return_val_if_fail (event != NULL, FALSE);

  if (event->count > 0)
    return FALSE;

  cr = gdk_cairo_create(widget->window);
  image_widget = CV_IMAGE_WIDGET (widget);

  if( image_widget->scaled_image ){
      // center image in available region
      int x0 = (widget->allocation.width - image_widget->scaled_image->cols)/2;
      int y0 = (widget->allocation.height - image_widget->scaled_image->rows)/2;

      pixbuf = gdk_pixbuf_new_from_data(image_widget->scaled_image->data.ptr, GDK_COLORSPACE_RGB, false,
          8, MIN(image_widget->scaled_image->cols, widget->allocation.width),
          MIN(image_widget->scaled_image->rows, widget->allocation.height),
          image_widget->scaled_image->step, NULL, NULL);

      gdk_cairo_set_source_pixbuf(cr, pixbuf, x0, y0);
  }
  else if( image_widget->original_image ){
      pixbuf = gdk_pixbuf_new_from_data(image_widget->original_image->data.ptr, GDK_COLORSPACE_RGB, false,
          8, MIN(image_widget->original_image->cols, widget->allocation.width),
          MIN(image_widget->original_image->rows, widget->allocation.height),
          image_widget->original_image->step, NULL, NULL);
      gdk_cairo_set_source_pixbuf(cr, pixbuf, 0, 0);
  }

  cairo_paint(cr);
  g_object_unref(pixbuf);
  cairo_destroy(cr);
  return TRUE;
}
static void
update_display_preview (CcBackgroundPanel *panel)
{
  CcBackgroundPanelPrivate *priv = panel->priv;
  GtkWidget *widget;
  GtkAllocation allocation;
  const gint preview_width = 416;
  const gint preview_height = 248;
  GdkPixbuf *pixbuf;
  GIcon *icon;
  cairo_t *cr;

  widget = WID ("background-desktop-drawingarea");
  gtk_widget_get_allocation (widget, &allocation);

  if (!priv->current_background)
    return;

  icon = cc_background_item_get_frame_thumbnail (priv->current_background,
                                                 priv->thumb_factory,
                                                 preview_width,
                                                 preview_height,
                                                 -2, TRUE);
  pixbuf = GDK_PIXBUF (icon);

  cr = gdk_cairo_create (gtk_widget_get_window (widget));
  gdk_cairo_set_source_pixbuf (cr,
                               pixbuf,
                               0, 0);
  cairo_paint (cr);
  g_object_unref (pixbuf);

  pixbuf = NULL;
  if (panel->priv->display_screenshot != NULL)
    pixbuf = gdk_pixbuf_scale_simple (panel->priv->display_screenshot,
                                      preview_width,
                                      preview_height,
                                      GDK_INTERP_BILINEAR);

  if (pixbuf)
    {
      gdk_cairo_set_source_pixbuf (cr,
                                   pixbuf,
                                   0, 0);
      cairo_paint (cr);
    }

  cairo_destroy (cr);
}
示例#6
0
static cairo_pattern_t *
composite_image_onto_desktop (PanelBackground *background)
{
	int              width, height;
	cairo_t         *cr;
	cairo_surface_t *surface;
	cairo_pattern_t *pattern;

	if (!background->desktop)
		background->desktop = get_desktop_pixbuf (background);

	if (!background->desktop)
		return NULL;

	width  = gdk_pixbuf_get_width  (background->desktop);
	height = gdk_pixbuf_get_height (background->desktop);

	surface = gdk_window_create_similar_surface (background->window,
						     CAIRO_CONTENT_COLOR_ALPHA,
						     width, height);
	if (cairo_surface_status (surface) != CAIRO_STATUS_SUCCESS) {
		cairo_surface_destroy (surface);
		return NULL;
	}

	cr = cairo_create (surface);
	if(!gdk_window_check_composited_wm(background->window)){
		cairo_set_source_rgb (cr, 1, 1, 1);
		cairo_paint (cr);

		gdk_cairo_set_source_pixbuf (cr, background->desktop, 0, 0);
		cairo_rectangle (cr, 0, 0, width, height);
		cairo_fill (cr);
	}

	gdk_cairo_set_source_pixbuf (cr, background->transformed_image, 0, 0);
	pattern = cairo_get_source (cr);
	cairo_pattern_set_extend (pattern, CAIRO_EXTEND_REPEAT);

	cairo_rectangle (cr, 0, 0, width, height);
	cairo_fill (cr);

	cairo_destroy (cr);

	pattern = cairo_pattern_create_for_surface (surface);
	cairo_surface_destroy (surface);
	return pattern;
}
gboolean expose_event(GtkWidget * widget, GdkEventExpose * event, GdkPixbuf * pixbuf)
#endif
{
    gint x, y;

    if (pixbuf != NULL)
    {
        /* Copy the appropriate rectangle of the root window pixmap to the drawing area.
         * All drawing areas are immediate children of the toplevel window, so the allocation yields the source coordinates directly. */
#ifdef USE_GTK3
#elif GTK_CHECK_VERSION(2,14,0)
       cairo_t * cr = gdk_cairo_create (gtk_widget_get_window(widget));
       gdk_window_get_origin(gtk_widget_get_window(widget), &x, &y);
#else
       cairo_t * cr = gdk_cairo_create (widget->window);
       gdk_window_get_origin(widget->window, &x, &y);
#endif
       gdk_cairo_set_source_pixbuf (
           cr,
           pixbuf,
           -x,
           -y);

       cairo_paint (cr);
#ifndef USE_GTK3
       cairo_destroy(cr);
#endif
    }
    return FALSE;
}
示例#8
0
static void
dnd_hints_realized_cb(GtkWidget *window, GtkWidget *pix)
{
	GdkPixbuf *pixbuf;
	cairo_surface_t *surface;
	cairo_region_t *region;
	cairo_t *cr;

	pixbuf = gtk_image_get_pixbuf(GTK_IMAGE(pix));

	surface = cairo_image_surface_create(CAIRO_FORMAT_A1,
	                                     gdk_pixbuf_get_width(pixbuf),
	                                     gdk_pixbuf_get_height(pixbuf));

	cr = cairo_create(surface);
	gdk_cairo_set_source_pixbuf(cr, pixbuf, 0, 0);
	cairo_paint(cr);
	cairo_destroy(cr);

	region = gdk_cairo_region_create_from_surface(surface);
	gtk_widget_shape_combine_region(window, region);
	cairo_region_destroy(region);

	cairo_surface_destroy(surface);
}
static void sample_expose(GtkWidget* darea, GdkEventExpose* expose)
#endif
{
	GtkAllocation allocation;
	GdkPixbuf* pixbuf = g_object_get_data(G_OBJECT(darea), "sample-pixbuf");
	int width = gdk_pixbuf_get_width(pixbuf);
	int height = gdk_pixbuf_get_height(pixbuf);

	gtk_widget_get_allocation (darea, &allocation);
	int x = (allocation.width - width) / 2;
	int y = (allocation.height - height) / 2;

	GdkColor black, white;
	gdk_color_parse ("black", &black);
	gdk_color_parse ("white", &white);

#if !GTK_CHECK_VERSION (3, 0, 0)
	cairo_t *cr = gdk_cairo_create (expose->window);
#endif
	cairo_set_line_width (cr, 1);
	cairo_set_line_cap (cr, CAIRO_LINE_CAP_SQUARE);

	gdk_cairo_set_source_color (cr, &white);
	cairo_rectangle (cr, 0, 0, allocation.width, allocation.height);
	cairo_fill_preserve (cr);
	gdk_cairo_set_source_color (cr, &black);
	cairo_stroke (cr);

	gdk_cairo_set_source_pixbuf(cr, pixbuf, x, y);
	cairo_paint(cr);

#if !GTK_CHECK_VERSION (3, 0, 0)
	cairo_destroy (cr);
#endif
}
示例#10
0
文件: testgradient.c 项目: dnk/marco
static void
render_multi (
              cairo_t     *cr,
              int width, int height,
              MetaGradientType type)
{
  GdkPixbuf *pixbuf;
#define N_COLORS 5

  GdkRGBA colors[N_COLORS];

  gdk_rgba_parse (&colors[0], "red");
  gdk_rgba_parse (&colors[1], "blue");
  gdk_rgba_parse (&colors[2], "orange");
  gdk_rgba_parse (&colors[3], "pink");
  gdk_rgba_parse (&colors[4], "green");

  pixbuf = meta_gradient_create_multi (width, height,
                                       colors, N_COLORS,
                                       type);

  gdk_cairo_set_source_pixbuf (cr, pixbuf, 0, 0);
  cairo_rectangle (cr, 0, 0, width, height);
  cairo_fill (cr);

  g_object_unref (G_OBJECT (pixbuf));
#undef N_COLORS
}
示例#11
0
static gboolean
expose_callback (GtkWidget      *event_box,
                 GdkEventButton *,
                 TSignalData    *sigdata)
{
    cairo_t *cr;
    if (sigdata->event_box != NULL)
        cr = gdk_cairo_create (GDK_DRAWABLE (sigdata->event_box->window));
    else
    {
        cr = gdk_cairo_create (GDK_DRAWABLE (event_box->window));
        sigdata->event_box = event_box;
    }


    if (sigdata->image != NULL)
    {
        GdkPixbuf *pxbf = gtk_image_get_pixbuf(GTK_IMAGE(sigdata->image));

        gdk_cairo_set_source_pixbuf (cr, pxbf, 0,0);

        cairo_paint (cr);

        draw_grid(cr, sigdata->idata);
    }


    return TRUE;
}
示例#12
0
static void draw_album_art (cairo_t * cr)
{
    g_return_if_fail (area);

    if (area->pb != NULL)
    {
        gdk_cairo_set_source_pixbuf (cr, area->pb, SPACING, SPACING);
        cairo_paint_with_alpha (cr, area->alpha);
    }

    if (area->last_pb != NULL)
    {
        gdk_cairo_set_source_pixbuf (cr, area->last_pb, SPACING, SPACING);
        cairo_paint_with_alpha (cr, area->last_alpha);
    }
}
static gboolean
render_custom (GsdMediaKeysWindow *window,
               cairo_t            *cr,
               double              _x0,
               double              _y0,
               double              width,
               double              height)
{
        GdkPixbuf         *pixbuf;
        int                icon_size;

        icon_size = (int)width;

        pixbuf = load_pixbuf (window, window->priv->icon_name, icon_size);

        if (pixbuf == NULL) {
                char *name;
                if (gtk_widget_get_direction (GTK_WIDGET (window)) == GTK_TEXT_DIR_RTL)
                        name = g_strdup_printf ("%s-rtl", window->priv->icon_name);
                else
                        name = g_strdup_printf ("%s-ltr", window->priv->icon_name);
                pixbuf = load_pixbuf (window, name, icon_size);
                g_free (name);
                if (pixbuf == NULL)
                        return FALSE;
        }

        gdk_cairo_set_source_pixbuf (cr, pixbuf, _x0, _y0);
        cairo_paint_with_alpha (cr, GSD_OSD_WINDOW_FG_ALPHA);

        g_object_unref (pixbuf);

        return TRUE;
}
示例#14
0
static void
icon_shape_renderer (cairo_t        *cr,
                     PangoAttrShape *attr,
                     gboolean        do_path,
                     gpointer        user_data)
{
        IconShapeData *data = user_data;
        gdouble x, y;

        cairo_get_current_point (cr, &x, &y);
        if (GPOINTER_TO_UINT (attr->data) == data->placeholder) {
                gdouble ascent;
                gdouble height;
                GdkPixbuf *pixbuf;
                GtkIconInfo *info;

                ascent = pango_units_to_double (attr->ink_rect.y);
                height = pango_units_to_double (attr->ink_rect.height);
                info = gtk_icon_theme_lookup_by_gicon (gtk_icon_theme_get_default (),
                                                       data->icon,
                                                       (gint)height,
                                                       GTK_ICON_LOOKUP_FORCE_SIZE | GTK_ICON_LOOKUP_USE_BUILTIN);
                pixbuf = gtk_icon_info_load_icon (info, NULL);
                g_object_unref (info);

                cairo_set_operator (cr, CAIRO_OPERATOR_OVER);
                cairo_reset_clip (cr);
                gdk_cairo_set_source_pixbuf (cr, pixbuf, x, y + ascent);
                cairo_paint (cr);
                g_object_unref (pixbuf);
        }
}
示例#15
0
static void port_display_expose(GdkEventExpose *ev,
	GtkWidget *widget, GdkRectangle *rect, gdouble sliderstate, GdkPixbuf *image)
{
	cairo_t *cr = gdk_cairo_create(gtk_widget_get_window(widget));
    GxPortDisplay *port_display = GX_PORT_DISPLAY(widget);
    GdkRegion *region;
	region = gdk_region_rectangle (&widget->allocation);
	gdk_region_intersect (region, ev->region);
    gdk_cairo_region (cr, region);
    cairo_clip (cr);
	gdk_cairo_set_source_pixbuf(cr, image, rect->x - (rect->width-(gint)sliderstate), rect->y);
	cairo_rectangle(cr, rect->x, rect->y, rect->width, rect->height);
	cairo_fill(cr);
    if (port_display->cutoff_low + port_display->cutoff_high) {
      cairo_set_source_rgba (cr, 0.8, 0.1, 0.1, 0.4);
      cairo_set_line_width(cr, rect->height);
      gint low = rect->width * port_display->cutoff_low * 0.01;
      gint high = (rect->width* port_display->cutoff_high * 0.01)-2;
      gint lw = rect->height/2;
      cairo_move_to(cr,rect->x, rect->y+lw);
      cairo_line_to(cr,rect->x + low, rect->y+lw);
      cairo_stroke (cr);
      cairo_move_to(cr,rect->width - high, rect->y+lw);
      cairo_line_to(cr,rect->width+2, rect->y+lw);
      cairo_stroke (cr);
      cairo_set_source_rgba (cr, 0.1, 0.6, 0.1, 0.4);
      cairo_move_to(cr,rect->x+ low, rect->y+lw);
      cairo_line_to(cr,rect->width - high, rect->y+lw);
      cairo_stroke (cr);
      
    }
	cairo_destroy(cr);
    gdk_region_destroy (region);
}
static gboolean
render_speaker (GsdMediaKeysWindow *window,
                cairo_t            *cr,
                double              _x0,
                double              _y0,
                double              width,
                double              height)
{
        GdkPixbuf         *pixbuf;
        const char        *icon_name;
        int                icon_size;

	icon_name = get_image_name_for_volume (window->priv->volume_muted,
					       window->priv->volume_level);

        icon_size = (int)width;

        pixbuf = load_pixbuf (window, icon_name, icon_size);

        if (pixbuf == NULL) {
                return FALSE;
        }

        gdk_cairo_set_source_pixbuf (cr, pixbuf, _x0, _y0);
        cairo_paint_with_alpha (cr, GSD_OSD_WINDOW_FG_ALPHA);

        g_object_unref (pixbuf);

        return TRUE;
}
示例#17
0
文件: testgradient.c 项目: dnk/marco
static void
render_interwoven_func (
                        cairo_t     *cr,
                        int width, int height)
{
  GdkPixbuf *pixbuf;
#define N_COLORS 4

  GdkRGBA colors[N_COLORS];

  gdk_rgba_parse (&colors[0], "red");
  gdk_rgba_parse (&colors[1], "blue");
  gdk_rgba_parse (&colors[2], "pink");
  gdk_rgba_parse (&colors[3], "green");

  pixbuf = meta_gradient_create_interwoven (width, height,
                                            colors, height / 10,
                                            colors + 2, height / 14);

  gdk_cairo_set_source_pixbuf (cr, pixbuf, 0, 0);
  cairo_rectangle (cr, 0, 0, width, height);
  cairo_fill (cr);

  g_object_unref (G_OBJECT (pixbuf));
}
示例#18
0
/**
 * draw_tile_pixmap
 * @tileno: Graphics tile number
 * @pno: Number of graphics set
 * @x: x position in grid squares
 * @y: y position in grid squares
 * @cr: context to draw on
 *
 * Description:
 * Draws tile pixmap @tileno from graphics set @pno at (@x, @y) in
 * a widget @area
 **/
static void
draw_tile_pixmap (gint tileno, gint x, gint y, cairo_t * cr)
{
  if ((x & 1) ^ (y & 1)) {
    gdk_cairo_set_source_rgba (cr, &dark_background);
  } else {
    gdk_cairo_set_source_rgba (cr, &light_background);
  }

  x *= tile_width;
  y *= tile_height;
  
  cairo_rectangle (cr, x, y, tile_width, tile_height);
  cairo_fill (cr);

  if (rerender_needed)
    render_graphics ();

  if ((tileno < 0) || (tileno >= SCENARIO_PIXMAP_WIDTH)) {
    /* nothing */
  } else {
    gdk_cairo_set_source_pixbuf (cr, theme_pixbuf, x - tileno * tile_width, y);
    cairo_rectangle (cr, x, y, tile_width, tile_height);
    cairo_fill (cr);
  }
}
static gboolean
render_eject (GsdMediaKeysWindow *window,
              cairo_t            *cr,
              double              x0,
              double              y0,
              double              width,
              double              height)
{
        GdkPixbuf  *pixbuf;
        int         icon_size;
        const char *icon_name;

        icon_name = "media-eject";

        icon_size = (int)width;

        pixbuf = load_pixbuf (window, icon_name, icon_size);

        if (pixbuf == NULL) {
                return FALSE;
        }

        gdk_cairo_set_source_pixbuf (cr, pixbuf, x0, y0);
        cairo_paint_with_alpha (cr, FG_ALPHA);

        g_object_unref (pixbuf);

        return TRUE;
}
示例#20
0
/***********************************************
 * ge_cairo_pixbuf_pattern -
 *  
 *   Create A Tiled Pixbuf Pattern
 ***********************************************/
CairoPattern*
ge_cairo_pixbuf_pattern(GdkPixbuf *pixbuf)
{
	CairoPattern * result;
        cairo_pattern_t *pattern;

	cairo_t *canvas;
	cairo_surface_t * surface;
	gint width, height;

	width = gdk_pixbuf_get_width(pixbuf);
	height = gdk_pixbuf_get_height(pixbuf);
	
	surface = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, width, height);

	canvas = cairo_create(surface);

	gdk_cairo_set_source_pixbuf (canvas, pixbuf, 0, 0);
	cairo_rectangle (canvas, 0, 0, width, height);
	cairo_fill (canvas);
	cairo_destroy(canvas);

	pattern = cairo_pattern_create_for_surface (surface);
	cairo_surface_destroy(surface);

	cairo_pattern_set_extend (pattern, CAIRO_EXTEND_REPEAT);

        result = ge_cairo_pattern_pattern (pattern);
        cairo_pattern_destroy (pattern);

	return result;
}
示例#21
0
static gboolean
on_draw(XmrButton *button, cairo_t *cr, gpointer data)
{
	XmrButtonPrivate *priv = button->priv;
	cairo_surface_t *image;
	GdkPixbuf *pixbuf = priv->images[priv->state];
	gint image_width, image_height;

	if (priv->type == XMR_BUTTON_NORMAL || pixbuf == NULL)
		return GTK_WIDGET_CLASS(xmr_button_parent_class)->draw(GTK_WIDGET(button), cr);

	image_width = gdk_pixbuf_get_width(pixbuf);
	image_height = gdk_pixbuf_get_height(pixbuf);

	image = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, image_width, image_height);
	if (image == NULL)
		return FALSE;

	cairo_set_source_surface(cr, image, 0, 0);
	gdk_cairo_set_source_pixbuf(cr, pixbuf, 0, 0);
	cairo_paint(cr);
	
	cairo_surface_destroy(image);

	return TRUE;
}
示例#22
0
static gint
on_draw(GtkWidget *widget, cairo_t *cr, gpointer userdata) {
	GdkPixbuf *pixbuf;
	pixbuf = gdk_pixbuf_new_from_file("/usr/share/themes/Ambiance/gtk-2.0/apps/img/panel.png", NULL);
	if (!pixbuf) {
		pixbuf = gdk_pixbuf_new_from_file("/usr/share/lxpanel/images/lubuntu-background.png", NULL);
	}
	if (!pixbuf) {
		pixbuf = gdk_pixbuf_new_from_file("/usr/share/themes/Greybird/ubiquity-panel-bg.png", NULL);
	}
	if (!pixbuf) {
		pixbuf = gdk_pixbuf_new_from_file("/usr/share/budgie-desktop/ubiquity-panel-bg.png", NULL);
	}
	if (!pixbuf) {
		pixbuf = gdk_pixbuf_new_from_file("/usr/share/ubiquity/pixmaps/panel.png", NULL);
	}
	if (pixbuf) {
		gdk_cairo_set_source_pixbuf(cr, pixbuf, 0, 0);
		cairo_pattern_set_extend(cairo_get_source(cr), CAIRO_EXTEND_PAD);
		cairo_paint(cr);
		g_object_unref(pixbuf);
	} else {
		g_warning("Could not find background image.");
	}
	struct {
		GtkWidget *container;
		cairo_t *cr;
	} data;
	data.container = widget;
	data.cr = cr;
	gtk_container_forall (GTK_CONTAINER(widget), draw_child, &data);
	return FALSE;
}
示例#23
0
WG_PRIVATE gboolean
on_expose(GtkWidget *widget, cairo_t *cr, gpointer data)
{
    Gui_display *display = NULL;
    Gui_display_line *line = NULL;
    Iterator itr;

    display = (Gui_display*)data;

    cairo_set_source_rgb(cr, 0.0, 0.0, 0.0);
    cairo_paint(cr);

    if (display->pixbuf != NULL){
        gdk_cairo_set_source_pixbuf(cr,
                display->pixbuf, 
                display->widget_width, display->widget_height);

        cairo_paint(cr);

        iterator_list_init(&itr, &display->lines, 
                GET_OFFSET(Gui_display_line, list));
        while((line = iterator_list_next(&itr)) != NULL){
            paint_line(cr, line);
        }

        cairo_fill(cr);

    }

    return TRUE;
}
示例#24
0
static gboolean
cheese_widget_logo_draw (GtkWidget      *w,
                         cairo_t        *cr,
                         gpointer        user_data)
{
  const char   *icon_name;
  GdkPixbuf    *pixbuf, *logo;
  GError       *error = NULL;
  GtkAllocation allocation;
  guint         s_width, s_height, d_width, d_height;
  float         ratio;

  gtk_widget_get_allocation (w, &allocation);

  cairo_set_source_rgb (cr, 0.0, 0.0, 0.0);

  icon_name = g_object_get_data (G_OBJECT (w), "icon-name");
  if (icon_name == NULL) {
    cairo_paint (cr);
    return FALSE;
  }

  cairo_rectangle (cr, 0, 0, allocation.width, allocation.height);

  d_width  = allocation.width;
  d_height = allocation.height - (allocation.height / 3);

  pixbuf = cheese_widget_load_pixbuf (w, icon_name, d_height, &error);
  if (pixbuf == NULL)
  {
    g_warning ("Could not load icon '%s': %s", icon_name, error->message);
    g_error_free (error);
    return FALSE;
  }

  s_width  = gdk_pixbuf_get_width (pixbuf);
  s_height = gdk_pixbuf_get_height (pixbuf);

  if ((gfloat) d_width / s_width > (gfloat) d_height / s_height)
  {
    ratio = (gfloat) d_height / s_height;
  }
  else
  {
    ratio = (gfloat) d_width / s_width;
  }

  s_width  *= ratio;
  s_height *= ratio;

  logo = gdk_pixbuf_scale_simple (pixbuf, s_width, s_height, GDK_INTERP_BILINEAR);

  gdk_cairo_set_source_pixbuf (cr, logo, (allocation.width - s_width) / 2, (allocation.height - s_height) / 2);
  cairo_paint (cr);

  g_object_unref (logo);
  g_object_unref (pixbuf);

  return FALSE;
}
示例#25
0
文件: GxKnob.cpp 项目: dafx/guitarix
void _gx_knob_expose(GtkWidget *widget, GdkRectangle *image_rect, gdouble knobstate,
                     GdkPixbuf *knob_image, gint framecount, int has_focus)
{
	int findex;
	double angle = scale_zero + knobstate * 2 * (M_PI - scale_zero);
	const double pointer_off = 5;
	double radius = min(image_rect->width-pointer_off, image_rect->height-pointer_off) / 2;
	double lengh_x = (image_rect->x+radius+pointer_off/2) - radius * sin(angle);
	double lengh_y = (image_rect->y+radius+pointer_off/2) + radius * cos(angle);
	double radius1 = min(image_rect->width, image_rect->height) / 2;
	
	if (framecount > 1) {
		framecount--; // zero based index
		findex = (int)(framecount * knobstate);
		cairo_t *cr = gdk_cairo_create(gtk_widget_get_window(widget));
		gdk_cairo_set_source_pixbuf(cr, knob_image, image_rect->x - (image_rect->width * findex), image_rect->y);
		cairo_rectangle(cr, image_rect->x, image_rect->y, image_rect->width, image_rect->height);
		cairo_fill(cr);
		cairo_destroy (cr);
	}
	else {
		cairo_t *cr = gdk_cairo_create(GDK_DRAWABLE(widget->window));
		if (gtk_widget_has_focus(widget)) {
			gtk_paint_focus(widget->style, widget->window, GTK_STATE_NORMAL, NULL, widget, NULL,
					image_rect->x, image_rect->y, image_rect->width, image_rect->height);
		}
		gdk_cairo_set_source_pixbuf(cr, knob_image, image_rect->x-0.5, image_rect->y-0.5);
		cairo_rectangle(cr, image_rect->x, image_rect->y, image_rect->width, image_rect->height);
		cairo_fill(cr);
		_gx_knob_draw_indicator(cr, image_rect, knobstate);
		/** this is to create a pointer rotating on the knob with painting funktions **/
		cairo_set_source_rgb(cr,  0.1, 0.1, 0.1);
		cairo_set_line_width(cr, 5.0);
		cairo_move_to(cr, image_rect->x+radius1, image_rect->y+radius1);
		cairo_line_to(cr,lengh_x,lengh_y);
		cairo_stroke(cr);
		cairo_set_source_rgb(cr,  0.9, 0.9, 0.9);
		cairo_set_line_width(cr, 1.0);
		cairo_move_to(cr, image_rect->x+radius1, image_rect->y+radius1);
		cairo_line_to(cr,lengh_x,lengh_y);
		cairo_stroke(cr);
		_gx_knob_draw_arc(widget, cr, image_rect, knobstate, has_focus);
		cairo_destroy(cr);
	}

	
}
示例#26
0
static gboolean 
pattern_value_parse (GtkCssParser *parser,
                     GFile        *base,
                     GValue       *value)
{
  if (_gtk_css_parser_begins_with (parser, '-'))
    {
      g_value_unset (value);
      g_value_init (value, GTK_TYPE_GRADIENT);
      return gradient_value_parse (parser, base, value);
    }
  else
    {
      GError *error = NULL;
      gchar *path;
      GdkPixbuf *pixbuf;
      GFile *file;
      cairo_surface_t *surface;
      cairo_pattern_t *pattern;
      cairo_t *cr;
      cairo_matrix_t matrix;

      file = _gtk_css_parse_url (parser, base);
      if (file == NULL)
        return FALSE;

      path = g_file_get_path (file);
      g_object_unref (file);

      pixbuf = gdk_pixbuf_new_from_file (path, &error);
      g_free (path);
      if (pixbuf == NULL)
        {
          _gtk_css_parser_take_error (parser, error);
          return FALSE;
        }

      surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32,
                                            gdk_pixbuf_get_width (pixbuf),
                                            gdk_pixbuf_get_height (pixbuf));
      cr = cairo_create (surface);
      gdk_cairo_set_source_pixbuf (cr, pixbuf, 0, 0);
      cairo_paint (cr);
      pattern = cairo_pattern_create_for_surface (surface);

      cairo_matrix_init_scale (&matrix,
                               gdk_pixbuf_get_width (pixbuf),
                               gdk_pixbuf_get_height (pixbuf));
      cairo_pattern_set_matrix (pattern, &matrix);

      cairo_surface_destroy (surface);
      cairo_destroy (cr);
      g_object_unref (pixbuf);

      g_value_take_boxed (value, pattern);
    }
  
  return TRUE;
}
示例#27
0
static cairo_surface_t *
ev_document_misc_render_thumbnail_frame (GtkWidget       *widget,
        int              width,
        int              height,
        gboolean         inverted_colors,
        GdkPixbuf       *source_pixbuf,
        cairo_surface_t *source_surface)
{
    GtkStyleContext *context = gtk_widget_get_style_context (widget);
    GtkStateFlags    state = gtk_widget_get_state_flags (widget);
    int              width_r, height_r;
    int              width_f, height_f;
    cairo_surface_t *surface;
    cairo_t         *cr;
    GtkBorder        border = {0, };

    if (source_surface) {
        width_r = cairo_image_surface_get_width (source_surface);
        height_r = cairo_image_surface_get_height (source_surface);
    } else if (source_pixbuf) {
        g_return_val_if_fail (GDK_IS_PIXBUF (source_pixbuf), NULL);

        width_r = gdk_pixbuf_get_width (source_pixbuf);
        height_r = gdk_pixbuf_get_height (source_pixbuf);
    } else {
        width_r = width;
        height_r = height;
    }

    gtk_style_context_save (context);

    gtk_style_context_add_class (context, "page-thumbnail");
    if (inverted_colors)
        gtk_style_context_add_class (context, "inverted");

    gtk_style_context_get_border (context, state, &border);
    width_f = width_r + border.left + border.right;
    height_f = height_r + border.top + border.bottom;

    surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32,
                                          width_f, height_f);

    cr = cairo_create (surface);
    if (source_surface) {
        cairo_set_source_surface (cr, source_surface, border.left, border.top);
        cairo_paint (cr);
    } else if (source_pixbuf) {
        gdk_cairo_set_source_pixbuf (cr, source_pixbuf, border.left, border.top);
        cairo_paint (cr);
    } else {
        gtk_render_background (context, cr, 0, 0, width_f, height_f);
    }
    gtk_render_frame (context, cr, 0, 0, width_f, height_f);
    cairo_destroy (cr);

    gtk_style_context_restore (context);

    return surface;
}
示例#28
0
/* Expose callback for the drawing area */
static gboolean
draw_cb (GtkWidget *widget, cairo_t *cr, gpointer data)
{
        gdk_cairo_set_source_pixbuf (cr, frame, 0, 0);
        cairo_paint (cr);

	return TRUE;
}
示例#29
0
文件: button.c 项目: yetist/libgtkfw
static gboolean draw (GtkWidget *widget, cairo_t *cr)
{
	GdkPixbuf *pixbuf = gdk_pixbuf_new_from_file("./background.png",NULL);
	gdk_cairo_set_source_pixbuf(cr, pixbuf, 0, 0);
	cairo_set_operator (cr, CAIRO_OPERATOR_SOURCE);
	cairo_paint(cr);
	return FALSE;
}
示例#30
0
static gboolean
gtk_css_image_url_parse (GtkCssImage  *image,
                         GtkCssParser *parser)
{
  GtkCssImageUrl *url = GTK_CSS_IMAGE_URL (image);
  GdkPixbuf *pixbuf;
  GFile *file;
  cairo_t *cr;
  GError *error = NULL;
  GFileInputStream *input;

  file = _gtk_css_parser_read_url (parser);
  if (file == NULL)
    return FALSE;

  /* We special case resources here so we can use
     gdk_pixbuf_new_from_resource, which in turn has some special casing
     for GdkPixdata files to avoid duplicating the memory for the pixbufs */
  if (g_file_has_uri_scheme (file, "resource"))
    {
      char *uri = g_file_get_uri (file);
      char *resource_path = g_uri_unescape_string (uri + strlen ("resource://"), NULL);

      pixbuf = gdk_pixbuf_new_from_resource (resource_path, &error);
      g_free (resource_path);
      g_free (uri);
    }
  else
    {
      input = g_file_read (file, NULL, &error);
      if (input == NULL)
	{
	  _gtk_css_parser_take_error (parser, error);
	  return FALSE;
	}

      pixbuf = gdk_pixbuf_new_from_stream (G_INPUT_STREAM (input), NULL, &error);
      g_object_unref (input);
    }
  g_object_unref (file);

  if (pixbuf == NULL)
    {
      _gtk_css_parser_take_error (parser, error);
      return FALSE;
    }

  url->surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32,
                                             gdk_pixbuf_get_width (pixbuf),
                                             gdk_pixbuf_get_height (pixbuf));
  cr = cairo_create (url->surface);
  gdk_cairo_set_source_pixbuf (cr, pixbuf, 0, 0);
  cairo_paint (cr);
  cairo_destroy (cr);
  g_object_unref (pixbuf);

  return TRUE;
}