Example #1
0
/*!
  \brief hte TTM expose event which handles redraw after being unobscured
  \param widget is hte pointer to the TTM drawingarea
  \param event is the pointers to the GdkEventExpose structure
  \param data is unused
  \returns TRUE
  */
G_MODULE_EXPORT gboolean logger_display_expose_event(GtkWidget * widget, GdkEventExpose *event , gpointer data)
{
	cairo_t *cr = NULL;
	GtkAllocation allocation;
	GdkWindow *window = gtk_widget_get_window(widget);
	gtk_widget_get_allocation(widget,&allocation);

	ENTER();
#if GTK_MINOR_VERSION >= 18
	if (gtk_widget_is_sensitive(GTK_WIDGET(widget)))
#else
	if (GTK_WIDGET_IS_SENSITIVE(GTK_WIDGET(widget)))
#endif
	{
		cr = gdk_cairo_create(window);
		gdk_cairo_set_source_pixmap(cr,ttm_data->pixmap,0,0);
		cairo_rectangle(cr,event->area.x,event->area.y,event->area.width, event->area.height);
		cairo_fill(cr);
		cairo_destroy(cr);
	}
	else	/* INSENSITIVE display so grey it */
	{
		cr = gdk_cairo_create(window);
		gdk_cairo_set_source_pixmap(cr,ttm_data->pixmap,0,0);
		cairo_rectangle(cr,event->area.x,event->area.y,event->area.width, event->area.height);
		cairo_fill(cr);
		cairo_set_source_rgba (cr, 0.3,0.3,0.3,0.5);
		cairo_rectangle(cr,0,0,allocation.width, allocation.height);
		cairo_fill(cr);
		cairo_destroy(cr);
	}
	EXIT();
	return TRUE;
}
Example #2
0
/*!
 \brief handles exposure events when the screen is covered and then 
 exposed. Works by copying from a backing pixmap to screen,
 \param widget (GtkWidget *) pointer to the chart object
 \param event (GdkEventExpose *) pointer to GDK event datastructure that
 encodes important info like window dimensions and depth.
 */
gboolean mtx_stripchart_expose (GtkWidget *widget, GdkEventExpose *event)
{
	MtxStripChart * chart = MTX_STRIPCHART(widget);
	MtxStripChartPrivate *priv = MTX_STRIPCHART_GET_PRIVATE(chart);
	cairo_t *cr = NULL;

#if GTK_MINOR_VERSION >= 18
	if (gtk_widget_is_sensitive(GTK_WIDGET(widget)))
#else
		if (GTK_WIDGET_IS_SENSITIVE(GTK_WIDGET(widget)))
#endif
		{
			cr = gdk_cairo_create(widget->window);
			gdk_cairo_set_source_pixmap(cr,priv->bg_pixmap,0,0);
			cairo_rectangle(cr,event->area.x, event->area.y,event->area.width, event->area.height);
			cairo_fill(cr);
			cairo_destroy(cr);
		}
		else
		{
			cr = gdk_cairo_create(widget->window);
			gdk_cairo_set_source_pixmap(cr,priv->bg_pixmap,0,0);
			cairo_rectangle(cr,event->area.x, event->area.y,event->area.width, event->area.height);
			cairo_fill(cr);
			cairo_set_source_rgba (cr, 0.3,0.3,0.3,0.5);
			cairo_paint(cr);
			/*
			   cairo_rectangle (cr,
			   0,0,priv->w,priv->h);
			   cairo_fill(cr);
			 */
			cairo_destroy(cr);
		}
	return FALSE;
}
Example #3
0
/**
 * ppg_ruler_expose_event:
 * @ruler: (in): A #PpgRuler.
 *
 * Handle the "expose-event" for the widget. Blit the background and position
 * arrow to the surface.
 *
 * Returns: None.
 * Side effects: None.
 */
static gboolean
ppg_ruler_expose_event (GtkWidget      *widget,
                        GdkEventExpose *expose)
{
	PpgRuler *ruler = (PpgRuler *)widget;
	PpgRulerPrivate *priv;
	GtkAllocation alloc;
	cairo_t *cr;
	gint x;
	gint y;

	g_return_val_if_fail(PPG_IS_RULER(ruler), FALSE);

	GTK_WIDGET_CLASS(ppg_ruler_parent_class)->expose_event(widget, expose);

	priv = ruler->priv;

	gtk_widget_get_allocation(widget, &alloc);
	cr = gdk_cairo_create(expose->window);

	/*
	 * Clip to exposure region.
	 */
	gdk_cairo_rectangle(cr, &expose->area);
	cairo_clip(cr);

	/*
	 * Render the contents immediately if needed.
	 */
	if (priv->dirty) {
		ppg_ruler_draw_arrow(ruler);
		ppg_ruler_draw_ruler(ruler);
		priv->dirty = FALSE;
	}

	/*
	 * Blit the background to the surface.
	 */
	cairo_rectangle(cr, 0, 0, alloc.width, alloc.height);
	gdk_cairo_set_source_pixmap(cr, priv->ruler, 0, 0);
	cairo_fill(cr);

	/*
	 * Blit the arrow to the surface.
	 */
	x = (gint)(((priv->pos - priv->lower) /
                (priv->upper - priv->lower) *
                alloc.width) - (ARROW_SIZE / 2.0));
	y = alloc.height - ARROW_SIZE - 1;
	gdk_cairo_set_source_pixmap(cr, priv->arrow, x, y);
	cairo_rectangle(cr, x, y, ARROW_SIZE, ARROW_SIZE);
	cairo_fill(cr);

	/*
	 * Cleanup.
	 */
	cairo_destroy(cr);
	return FALSE;
}
Example #4
0
static void gtk_plot_cairo_draw_pixmap                (GtkPlotPC *pc,
                                                      GdkPixmap *pixmap,
                                                      GdkBitmap *mask,
                                                      gint xsrc, gint ysrc,
                                                      gint xdest, gint ydest,
                                                      gint width, gint height,
                                                      gdouble scale_x, 
                                                      gdouble scale_y)
{
  cairo_surface_t *image_surface = NULL;
  cairo_surface_t *mask_surface = NULL;
  cairo_t *cr;
/* TODO: USE MASK */

  image_surface = cairo_image_surface_create(CAIRO_FORMAT_RGB24, (width-xsrc)*scale_x, (height-ysrc)*scale_y);
  cr = cairo_create(image_surface);
  cairo_scale(cr,scale_x,scale_y);
  gdk_cairo_set_source_pixmap(cr,pixmap,xsrc,ysrc);
  cairo_paint(cr);
  cairo_destroy(cr);

/*
  mask_surface = cairo_image_surface_create(CAIRO_CONTENT_COLOR_ALPHA, (width-xsrc)*scale_x, (height-ysrc)*scale_y);
  cr = cairo_create(image_surface);
  cairo_scale(cr,scale_x,scale_y);
  gdk_cairo_set_source_pixmap(cr,mask,xsrc,ysrc);
  cairo_paint(cr);
  cairo_destroy(cr);
*/
  if(mask){
    mask_surface = cairo_image_surface_create(CAIRO_FORMAT_RGB24, (width-xsrc)*scale_x, (height-ysrc)*scale_y);
    cr = cairo_create(mask_surface);
    cairo_set_source_rgb(cr,0,0,0);
    cairo_scale(cr,scale_x,scale_y);
    gdk_cairo_set_source_pixmap(cr,pixmap,xsrc,ysrc);
    cairo_mask_surface(cr,mask_surface,0,0);
    cairo_fill(cr);
    cairo_destroy(cr);
  }

  cairo_save(GTK_PLOT_CAIRO(pc)->cairo);
/*
  cairo_rectangle(GTK_PLOT_CAIRO(pc)->cairo,xdest,ydest,(width-xsrc)*scale_x,(height-ysrc)*scale_y);
  cairo_clip(GTK_PLOT_CAIRO(pc)->cairo);
*/
/*
  if(mask) cairo_mask_surface(GTK_PLOT_CAIRO(pc)->cairo,mask_surface,xdest,ydest);
*/
  cairo_set_source_surface(GTK_PLOT_CAIRO(pc)->cairo,image_surface,xdest,ydest);
  cairo_paint(GTK_PLOT_CAIRO(pc)->cairo);
  
  cairo_restore(GTK_PLOT_CAIRO(pc)->cairo);
  cairo_surface_destroy(image_surface);
  cairo_surface_destroy(mask_surface);
}
Example #5
0
/* Erase the old cursor, and/or draw a new one, if necessary */
static void
update_cursor (GtkWidget *widget,  gdouble x, gdouble y)
{
  static gint cursor_present = 0;
  gint state = !current_device->has_cursor && cursor_proximity;

  if (pixmap != NULL)
    {
      cairo_t *cr = gdk_cairo_create (widget->window);

      if (cursor_present && (cursor_present != state ||
			     x != cursor_x || y != cursor_y))
	{
          gdk_cairo_set_source_pixmap (cr, pixmap, 0, 0);
          cairo_rectangle (cr, cursor_x - 5, cursor_y - 5, 10, 10);
          cairo_fill (cr);
	}

      cursor_present = state;
      cursor_x = x;
      cursor_y = y;

      if (cursor_present)
	{
          cairo_set_source_rgb (cr, 0, 0, 0);
          cairo_rectangle (cr, 
                           cursor_x - 5, cursor_y -5,
			   10, 10);
          cairo_fill (cr);
	}

      cairo_destroy (cr);
    }
}
static GdkPixmap *
tile_pixmap (GdkPixmap *pixmap,
	     int        width,
	     int        height)
{
	GdkPixmap *copy;
	cairo_t *cr;

	copy = gdk_pixmap_new (pixmap, width, height, pixmap == NULL? 24 : -1);

	cr = gdk_cairo_create (copy);

	if (pixmap != NULL) {
		cairo_pattern_t *pattern;
		gdk_cairo_set_source_pixmap (cr, pixmap, 0.0, 0.0);
		pattern = cairo_get_source (cr);
		cairo_pattern_set_extend (pattern, CAIRO_EXTEND_REPEAT);
	} else {
		GtkStyle *style;
		style = gtk_widget_get_default_style ();
		gdk_cairo_set_source_color (cr, &style->bg[GTK_STATE_NORMAL]);
	}

	cairo_paint (cr);

	if (cairo_status (cr) != CAIRO_STATUS_SUCCESS) {
		g_object_unref (copy);
		copy = NULL;
	}
	cairo_destroy (cr);

	return copy;
}
WidgetRenderingContext::~WidgetRenderingContext()
{
    // We do not need to blit back to the target in the fallback case. See above.
    RenderThemeGtk* theme = static_cast<RenderThemeGtk*>(RenderTheme::defaultTheme().get());
    if (!theme->m_themePartsHaveRGBAColormap && m_graphicsContext->gdkWindow())
        return;

    // Don't paint the results back if there was an error.
    if (m_hadError) {
        scheduleScratchBufferPurge();
        return;
    }

    // FIXME: It's unclear if it is necessary to preserve the current source here.
    cairo_t* cairoContext = m_graphicsContext->platformContext()->cr();
    RefPtr<cairo_pattern_t> previousSource(cairo_get_source(cairoContext));

    // The blit rectangle is the original target rectangle adjusted for any extra space.
    IntRect fullTargetRect(m_targetRect);
    fullTargetRect.inflateX(m_extraSpace.width());
    fullTargetRect.inflateY(m_extraSpace.height());

    gdk_cairo_set_source_pixmap(cairoContext, gScratchBuffer, fullTargetRect.x(), fullTargetRect.y());
    cairo_rectangle(cairoContext, fullTargetRect.x(), fullTargetRect.y(), fullTargetRect.width(), fullTargetRect.height());
    cairo_fill(cairoContext);
    cairo_set_source(cairoContext, previousSource.get());
    scheduleScratchBufferPurge();
}
static void matenu_menu_bar_reset_bg_pixmap (MatenuMenuBar* self) {
	GdkPixmap* pixmap;
	cairo_t* cairo;
	cairo_pattern_t* pattern;
	GtkStyle* style;
	GdkPixmap* _tmp0_;
	g_return_if_fail (self != NULL);
	if (matenu_menu_bar_get_background (self)->type != MATENU_BACKGROUND_TYPE_PIXMAP) {
		return;
	}
	if (!GTK_WIDGET_REALIZED ((GtkWidget*) self)) {
		return;
	}
	g_assert (GDK_IS_DRAWABLE (((GtkWidget*) self)->window));
	g_assert (GDK_IS_DRAWABLE (self->priv->_background->pixmap));
	pixmap = gdk_pixmap_new ((GdkDrawable*) ((GtkWidget*) self)->window, ((GtkWidget*) self)->allocation.width, ((GtkWidget*) self)->allocation.height, -1);
	g_assert (GDK_IS_DRAWABLE (pixmap));
	cairo = gdk_cairo_create ((GdkDrawable*) pixmap);
	g_assert (cairo != NULL);
	gdk_cairo_set_source_pixmap (cairo, self->priv->_background->pixmap, (double) (-self->priv->_background->offset_x), (double) (-self->priv->_background->offset_y));
	pattern = cairo_get_source (cairo);
	cairo_pattern_set_extend (pattern, CAIRO_EXTEND_REPEAT);
	cairo_rectangle (cairo, (double) 0, (double) 0, (double) ((GtkWidget*) self)->allocation.width, (double) ((GtkWidget*) self)->allocation.height);
	cairo_fill (cairo);
	style = _g_object_ref0 (gtk_widget_get_style ((GtkWidget*) self));
	style->bg_pixmap[(gint) GTK_STATE_NORMAL] = (_tmp0_ = _g_object_ref0 (pixmap), _g_object_unref0 (style->bg_pixmap[(gint) GTK_STATE_NORMAL]), _tmp0_);
	gtk_style_set_background (style, ((GtkWidget*) self)->window, GTK_STATE_NORMAL);
	gtk_widget_queue_draw ((GtkWidget*) self);
	_g_object_unref0 (style);
	_cairo_destroy0 (cairo);
	_g_object_unref0 (pixmap);
}
Example #9
0
static gboolean expose_event(GtkWidget *widget, GdkEventExpose *event)
{
    cairo_t *cr = gdk_cairo_create(widget->window);
    gdk_cairo_set_source_pixmap(cr, pixmap, 0, 0);
    cairo_paint(cr);
    cairo_destroy(cr);

    return FALSE;
}
Example #10
0
/*
 * copy_to_front_buffer
 *
 * Description: Helper function to copy the buffer pixmap to a front buffer
 */
void
copy_to_front_buffer (decor_t *d)
{
    if (!d->buffer_pixmap)
	return;

    cairo_set_operator (d->cr, CAIRO_OPERATOR_SOURCE);
    gdk_cairo_set_source_pixmap (d->cr, d->buffer_pixmap, 0, 0);
    cairo_paint (d->cr);
}
Example #11
0
/*!
  \brief  renders a marker at the current mouse position
  \param chart is the pointer to the chart object
  */
void render_marker(MtxStripChart *chart)
{
	cairo_t *cr = NULL;
	gint i = 0;
	gint buffer = 0;
	gfloat val = 0.0;
	cairo_text_extents_t extents;
	gchar *message = NULL;
	GtkWidget *widget = GTK_WIDGET(chart);
	MtxStripChartTrace *trace = NULL;
	MtxStripChartPrivate *priv = MTX_STRIPCHART_GET_PRIVATE(chart);
	GtkAllocation allocation;

	gtk_widget_get_allocation(widget,&allocation);
	/* Copy trace+graticule to backing pixmap */

	cr = gdk_cairo_create(priv->bg_pixmap);
	gdk_cairo_set_source_pixmap(cr,priv->grat_pixmap,0,0);
	cairo_rectangle(cr,0,0,allocation.width,allocation.height);
	cairo_fill(cr);

	cairo_set_antialias(cr,CAIRO_ANTIALIAS_DEFAULT);
	cairo_select_font_face (cr, priv->font, CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_NORMAL);
        cairo_set_font_size (cr, 12);

	cairo_set_line_width(cr,2);
	cairo_set_source_rgb (cr, 1.0,1.0,1.0);
	message = g_strdup_printf("123");
	cairo_text_extents(cr,message,&extents);
	g_free(message);
	buffer = extents.height + 3;
	if (priv->mouse_tracking)
	{
		cairo_move_to(cr,priv->mouse_x,0);
		cairo_line_to(cr,priv->mouse_x,priv->h);
		cairo_stroke(cr);
		for (i=0; i<priv->num_traces;i++)
		{
			trace = g_array_index(priv->traces,MtxStripChartTrace *, i);
			if ((priv->w-(gint)priv->mouse_x) > trace->history->len)
				val = trace->min;
			else
				val = g_array_index(trace->history, gfloat, trace->history->len-(priv->w-(gint)priv->mouse_x));

			message = g_strdup_printf("%1$.*2$f", val,trace->precision);
			cairo_set_source_rgb (cr, 
					trace->color.red/65535.0,
					trace->color.green/65535.0,
					trace->color.blue/65535.0);
			cairo_text_extents(cr,message,&extents);
			cairo_move_to(cr,priv->w-20-extents.width, priv->h-(priv->num_traces-i-1)*buffer - extents.height);
			cairo_show_text(cr,message);
			g_free(message);
		}
	}
Example #12
0
gboolean
gimp_overlay_child_expose (GimpOverlayBox   *box,
                           GimpOverlayChild *child,
                           GdkEventExpose   *event)
{
  GtkWidget *widget;

  g_return_val_if_fail (GIMP_IS_OVERLAY_BOX (box), FALSE);
  g_return_val_if_fail (child != NULL, FALSE);
  g_return_val_if_fail (event != NULL, FALSE);

  widget = GTK_WIDGET (box);

  if (event->window == gtk_widget_get_window (widget))
    {
      GtkAllocation child_allocation;
      GdkRectangle  bounds;

      gtk_widget_get_allocation (child->widget, &child_allocation);

      gimp_overlay_child_transform_bounds (child, &child_allocation, &bounds);

      if (gtk_widget_get_visible (child->widget) &&
          gdk_rectangle_intersect (&event->area, &bounds, NULL))
        {
          GdkPixmap *pixmap = gdk_offscreen_window_get_pixmap (child->window);
          cairo_t   *cr     = gdk_cairo_create (gtk_widget_get_window (widget));

          gdk_cairo_region (cr, event->region);
          cairo_clip (cr);

          cairo_transform (cr, &child->matrix);
          gdk_cairo_set_source_pixmap (cr, pixmap, 0, 0);
          cairo_paint_with_alpha (cr, child->opacity);
          cairo_destroy (cr);
        }
    }
  else if (event->window == child->window)
    {
      if (! gtk_widget_get_app_paintable (child->widget))
        gtk_paint_flat_box (gtk_widget_get_style (child->widget),
                            event->window,
                            GTK_STATE_NORMAL, GTK_SHADOW_NONE,
                            &event->area, widget, NULL,
                            0, 0, -1, -1);

      gtk_container_propagate_expose (GTK_CONTAINER (widget),
                                      child->widget,
                                      event);

      return TRUE;
    }

  return FALSE;
}
Example #13
0
static gboolean
ppg_ruler_expose_event (GtkWidget *widget,
                        GdkEventExpose *expose)
{
	PpgRuler *ruler = (PpgRuler *)widget;
	PpgRulerPrivate *priv;
	GtkAllocation alloc;
	cairo_t *cr;
	gint x;
	gint y;

	g_return_val_if_fail(PPG_IS_RULER(ruler), FALSE);

	GTK_WIDGET_CLASS(ppg_ruler_parent_class)->expose_event(widget, expose);

	priv = ruler->priv;

	gtk_widget_get_allocation(widget, &alloc);
	cr = gdk_cairo_create(expose->window);

	if (priv->dirty) {
		ppg_ruler_draw_arrow(ruler);
		ppg_ruler_draw_ruler(ruler);
		priv->dirty = FALSE;
	}

	cairo_rectangle(cr, 0, 0, alloc.width, alloc.height);
	gdk_cairo_set_source_pixmap(cr, priv->ruler, 0, 0);
	cairo_fill(cr);

	x = (gint)(((priv->pos - priv->lower) /
                (priv->upper - priv->lower) *
                alloc.width) - (ARROW_SIZE / 2.0));
	y = alloc.height - ARROW_SIZE - 1;
	gdk_cairo_set_source_pixmap(cr, priv->arrow, x, y);
	cairo_rectangle(cr, x, y, ARROW_SIZE, ARROW_SIZE);
	cairo_fill(cr);

	cairo_destroy(cr);

	return FALSE;
}
static gboolean
on_tick (MateBGCrossfade *fade)
{
	gdouble now, percent_done;
	cairo_t *cr;
	cairo_status_t status;

	g_return_val_if_fail (MATE_IS_BG_CROSSFADE (fade), FALSE);

	now = get_current_time ();

	percent_done = (now - fade->priv->start_time) / fade->priv->total_duration;
	percent_done = CLAMP (percent_done, 0.0, 1.0);

	/* If it's taking a long time to get to the first frame,
	 * then lengthen the duration, so the user will get to see
	 * the effect.
	 */
	if (fade->priv->is_first_frame && percent_done > .33) {
		fade->priv->is_first_frame = FALSE;
		fade->priv->total_duration *= 1.5;
		return on_tick (fade);
	}

	if (fade->priv->fading_pixmap == NULL) {
		return FALSE;
	}

	if (animations_are_disabled (fade)) {
		return FALSE;
	}

	/* We accumulate the results in place for performance reasons.
	 *
	 * This means 1) The fade is exponential, not linear (looks good!)
	 * 2) The rate of fade is not independent of frame rate. Slower machines
	 * will get a slower fade (but never longer than .75 seconds), and
	 * even the fastest machines will get *some* fade because the framerate
	 * is capped.
	 */
	cr = gdk_cairo_create (fade->priv->fading_pixmap);

	gdk_cairo_set_source_pixmap (cr, fade->priv->end_pixmap,
				     0.0, 0.0);
	cairo_paint_with_alpha (cr, percent_done);

	status = cairo_status (cr);
	cairo_destroy (cr);

	if (status == CAIRO_STATUS_SUCCESS) {
		draw_background (fade);
	}
	return percent_done <= .99;
}
Example #15
0
static gboolean
expose_event(GtkWidget *widget, GdkEventExpose *event, GdkPixmap *pixmap)
{
    cairo_t *cr;
    cr = gdk_cairo_create (gtk_widget_get_window (widget));
    gdk_cairo_set_source_pixmap (cr, pixmap, 0, 0);
    gdk_cairo_region (cr, event->region);
    cairo_fill (cr);

    cairo_destroy (cr);

    return FALSE;
}
Example #16
0
/* Refill the screen from the backing pixmap */
static gint
expose_event (GtkWidget *widget, GdkEventExpose *event)
{
  cairo_t *cr = gdk_cairo_create (widget->window);

  gdk_cairo_set_source_pixmap (cr, pixmap, 0, 0);
  gdk_cairo_rectangle (cr, &event->area);
  cairo_fill (cr);

  cairo_destroy (cr);

  return FALSE;
}
Example #17
0
bool Liveplay::window_expose_event(GdkEventExpose *event) {
    Cairo::RefPtr<Cairo::Context> cr = Glib::wrap(event->window, true)->create_cairo_context();
    Gtk::Allocation a = liveplay_canvas->get_allocation();
    Gdk::Region region(a);
    region.intersect(Glib::wrap(event->region, true));
    Gdk::Cairo::add_region_to_path(cr, region);
    cr->clip();
    cr->set_operator(Cairo::OPERATOR_SOURCE);
    cr->set_source_rgb(0,0,0);
    cr->paint();
    //gdk_cairo_set_source_window(cr->cobj(), liveplay_canvas->get_window()->gobj(), a.get_x(), a.get_y()); gtk 2.24
    gdk_cairo_set_source_pixmap(cr->cobj(), liveplay_canvas->get_window()->gobj(), a.get_x(), a.get_y());
    cr->paint_with_alpha(pow(brightness_adj->get_value(),2.2));
    return false;
}
Example #18
0
static gboolean pidgin_whiteboard_expose_event(GtkWidget *widget, GdkEventExpose *event, gpointer data)
{
	PidginWhiteboard *gtkwb = (PidginWhiteboard*)(data);
	GdkPixmap *pixmap = gtkwb->pixmap;
	cairo_t *cr;

	cr = gdk_cairo_create(GDK_DRAWABLE(widget->window));
	gdk_cairo_set_source_pixmap(cr, pixmap, 0, 0);
	cairo_rectangle(cr,
	                event->area.x, event->area.y,
	                event->area.width, event->area.height);
	cairo_fill(cr);
	cairo_destroy(cr);

	return FALSE;
}
static gboolean
awn_image_expose (GtkWidget *widget, GdkEventExpose *event)
{
  AwnImagePrivate *priv = AWN_IMAGE (widget)->priv;
  GtkImage *image = GTK_IMAGE (widget);
  cairo_t *cr;
  GdkPixbuf *pixbuf = NULL;
  GdkPixmap *pixmap = NULL;

  switch (gtk_image_get_storage_type (GTK_IMAGE (widget)))
  {
    case GTK_IMAGE_EMPTY:
      break;
    case GTK_IMAGE_PIXBUF:
      pixbuf = gtk_image_get_pixbuf (image);
      break;
    case GTK_IMAGE_PIXMAP:
      gtk_image_get_pixmap (image, &pixmap, NULL);
      break;
    default:
      g_warning ("AwnImage doesn't support this storage type");
      return FALSE;
  }

  cr = awn_effects_cairo_create_clipped (priv->effects, event);
  g_return_val_if_fail (cr, FALSE);

  if (pixbuf || pixmap)
  {
    if (pixbuf)
    {
      gdk_cairo_set_source_pixbuf (cr, pixbuf, 0.0, 0.0);
    }
    else if (pixmap)
    {
      gdk_cairo_set_source_pixmap (cr, pixmap, 0.0, 0.0);
    }

    cairo_paint (cr);
  }

  awn_effects_cairo_destroy (priv->effects);

  return TRUE;
}
Example #20
0
static void sctp_graph_redraw(struct sctp_udata *u_data)
{
	sctp_graph_t *ios;
	GtkAllocation widget_alloc;
	cairo_t *cr;

	u_data->io->needs_redraw = TRUE;

	sctp_graph_draw(u_data);
	switch (u_data->io->graph_type)
	{
		case 0:
			draw_sack_graph(u_data);
			draw_tsn_graph(u_data);
			break;
		case 1:
			draw_tsn_graph(u_data);
			break;
		case 2:
			draw_sack_graph(u_data);
			break;
	}

	ios=(sctp_graph_t *)g_object_get_data(G_OBJECT(u_data->io->draw_area), "sctp_graph_t");
	g_assert(ios != NULL);

	cr = gdk_cairo_create (gtk_widget_get_window(u_data->io->draw_area));

#if GTK_CHECK_VERSION(2,22,0)
	cairo_set_source_surface (cr, ios->surface, 0, 0);
#else
	gdk_cairo_set_source_pixmap (cr, ios->pixmap, 0, 0);
#endif
	gtk_widget_get_allocation(u_data->io->draw_area, &widget_alloc);
	cairo_rectangle (cr, 0, 0, widget_alloc.width, widget_alloc.height);
	cairo_fill (cr);

	cairo_destroy (cr);
}
PassRefPtr<BitmapContext> createBitmapContextFromWebView(bool, bool, bool, bool drawSelectionRect)
{
    WebKitWebView* view = webkit_web_frame_get_web_view(mainFrame);
    GtkWidget* viewContainer = gtk_widget_get_parent(GTK_WIDGET(view));
    gint width, height;
#ifdef GTK_API_VERSION_2
    GdkPixmap* pixmap = gtk_widget_get_snapshot(viewContainer, 0);
    gdk_pixmap_get_size(pixmap, &width, &height);
#else
    width = gtk_widget_get_allocated_width(viewContainer);
    height = gtk_widget_get_allocated_height(viewContainer);
#endif

    cairo_surface_t* imageSurface = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, width, height);
    cairo_t* context = cairo_create(imageSurface);

#ifdef GTK_API_VERSION_2
    gdk_cairo_set_source_pixmap(context, pixmap, 0, 0);
    cairo_paint(context);
    g_object_unref(pixmap);
#else
    gtk_widget_draw(viewContainer, context);
#endif

    if (drawSelectionRect) {
        cairo_rectangle_int_t rectangle;
        DumpRenderTreeSupportGtk::rectangleForSelection(mainFrame, &rectangle);

        cairo_set_line_width(context, 1.0);
        cairo_rectangle(context, rectangle.x, rectangle.y, rectangle.width, rectangle.height);
        cairo_set_source_rgba(context, 1.0, 0.0, 0.0, 1.0);
        cairo_stroke(context);
    }

    return BitmapContext::createByAdoptingBitmapAndContext(0, context);
}
Example #22
0
 static gboolean expose(GtkWidget *widget, GdkEventExpose *event, void *t)
 {
#if GTK_CHECK_VERSION(2,14,0)
	GdkWindow *window = gtk_widget_get_window(widget);
#else
	GdkWindow *window = widget->window;
#endif
 	cairo_t *cr	= gdk_cairo_create(window);

 	if(!pixmap_terminal)
 	{
 		// Rebuild pixmap
 		gint width;
 		gint height;
		gdk_drawable_get_size(window,&width,&height);
		pixmap_terminal = gdk_pixmap_new(window,width,height,-1);
		g_object_set_data_full(G_OBJECT(pixmap_terminal),"cached_gc",gdk_gc_new(GDK_DRAWABLE(pixmap_terminal)),g_object_unref);
		update_terminal_contents();
 	}

    gdk_cairo_set_source_pixmap(cr, pixmap_terminal, 0, 0);
    gdk_cairo_rectangle(cr, &event->area);
    cairo_fill(cr);

	if((cMode & CURSOR_MODE_ENABLED))
	{
		if(!get_cursor_pixmap())
		{
			pixmap_cursor = gdk_pixmap_new(window,rCursor.width,rCursor.height,-1);
			update_cursor_pixmap();
		}

		if( (cMode & (CURSOR_MODE_BASE|CURSOR_MODE_SHOW)) == (CURSOR_MODE_BASE|CURSOR_MODE_SHOW) )
		{
			gdk_cairo_set_source_pixmap(cr, get_cursor_pixmap(), rCursor.x, rCursor.y);

			if(Toggled(INSERT))
				cairo_rectangle(cr, rCursor.x, rCursor.y, rCursor.width, rCursor.height);
			else
				cairo_rectangle(cr, rCursor.x, rCursor.y+terminal_font_info.ascent, rCursor.width, terminal_font_info.descent);

			cairo_fill(cr);

/*
			GtkStyle	*style	= gtk_widget_get_style(widget);
			gdk_draw_drawable(		widget->window,	style->fg_gc[GTK_STATE_NORMAL],
									GDK_DRAWABLE(get_cursor_pixmap()),
									0,0,
									rCursor.x,rCursor.y,
									rCursor.width,rCursor.height);
*/
		}


		if(cMode & CURSOR_MODE_CROSS)
		{
			// Draw cross-hair cursor
			int			width;
			int			height;

			gdk_drawable_get_size(window,&width,&height);

			gdk_cairo_set_source_color(cr,color+TERMINAL_COLOR_CROSS_HAIR);
			cairo_rectangle(cr, rCursor.x, 0, 1, view.top+2+(terminal_font_info.spacing*view.rows));
			cairo_rectangle(cr, 0, rCursor.y+fontAscent, width,1);
			cairo_fill(cr);
		}
	}

    cairo_destroy(cr);

	return 0;
 }
Example #23
0
static gboolean
gtk_offscreen_box_expose (GtkWidget      *widget,
			  GdkEventExpose *event)
{
  GtkOffscreenBox *offscreen_box = GTK_OFFSCREEN_BOX (widget);

  if (gtk_widget_is_drawable (widget))
    {
      if (event->window == widget->window)
	{
          GdkPixmap *pixmap;
          GtkAllocation child_area;
          cairo_t *cr;
	  int start_y = 0;

	  if (offscreen_box->child1 && gtk_widget_get_visible (offscreen_box->child1))
	    {
	      pixmap = gdk_offscreen_window_get_pixmap (offscreen_box->offscreen_window1);
              child_area = offscreen_box->child1->allocation;

	      cr = gdk_cairo_create (widget->window);

              gdk_cairo_set_source_pixmap (cr, pixmap, 0, 0);
              cairo_paint (cr);

              cairo_destroy (cr);

              start_y += child_area.height;
	    }

	  if (offscreen_box->child2 && gtk_widget_get_visible (offscreen_box->child2))
	    {
	      pixmap = gdk_offscreen_window_get_pixmap (offscreen_box->offscreen_window2);
              child_area = offscreen_box->child2->allocation;

	      cr = gdk_cairo_create (widget->window);

              /* transform */
	      cairo_translate (cr, 0, start_y);
	      cairo_translate (cr, child_area.width / 2, child_area.height / 2);
	      cairo_rotate (cr, offscreen_box->angle);
	      cairo_translate (cr, -child_area.width / 2, -child_area.height / 2);

              /* paint */
	      gdk_cairo_set_source_pixmap (cr, pixmap, 0, 0);
	      cairo_paint (cr);

              cairo_destroy (cr);
	    }
	}
      else if (event->window == offscreen_box->offscreen_window1)
	{
	  gtk_paint_flat_box (widget->style, event->window,
			      GTK_STATE_NORMAL, GTK_SHADOW_NONE,
			      &event->area, widget, "blah",
			      0, 0, -1, -1);

	  if (offscreen_box->child1)
	    gtk_container_propagate_expose (GTK_CONTAINER (widget),
					    offscreen_box->child1,
                                            event);
	}
      else if (event->window == offscreen_box->offscreen_window2)
	{
	  gtk_paint_flat_box (widget->style, event->window,
			      GTK_STATE_NORMAL, GTK_SHADOW_NONE,
			      &event->area, widget, "blah",
			      0, 0, -1, -1);

	  if (offscreen_box->child2)
	    gtk_container_propagate_expose (GTK_CONTAINER (widget),
					    offscreen_box->child2,
                                            event);
	}
    }

  return FALSE;
}
Example #24
0
      /* draw label */
      if (i == 0) {
	int ofst;

	len = g_snprintf(unit_str, sizeof(unit_str), "%d", (int) cur);
	ofst = PANGO_PIXELS(logical_rect.y - ink_rect.y);

	if (ruler->orientation == GTK_ORIENTATION_HORIZONTAL) {
	  pango_layout_set_text(layout, unit_str, -1);
	  cairo_move_to(cr,
			pos + 2,
			ofst + 1);
	  pango_cairo_show_layout(cr, layout);
	} else {
	  for (j = 0; j < len; j++) {
	    pango_layout_set_text(layout, unit_str + j, 1);
	    cairo_move_to(cr,
			  1,
			  pos + digit_height * j + 2 + ofst);
	    pango_cairo_show_layout(cr, layout);
	  }
	}
      }
    }
  }

  cairo_fill(cr);

  ruler->save_l = ruler->lower;
  ruler->save_u = ruler->upper;
 out:
  cairo_destroy(cr);

  g_object_unref(layout);
}

#if GTK_CHECK_VERSION(3, 0, 0)
static GtkStyleContext *
nruler_get_color(Nruler *ruler, GdkRGBA *fg)
{
  if (ruler->saved_style == NULL) {
    ruler->saved_style = gtk_widget_get_style_context(TopLevel);
    gtk_style_context_get_color(ruler->saved_style, GTK_STATE_FLAG_NORMAL, &ruler->saved_fg);
  }

  if (fg == NULL) {
    return ruler->saved_style;
  }

  *fg = ruler->saved_fg;
  return ruler->saved_style;
}
#else
static void
nruler_get_color(Nruler *ruler, GdkColor *fg, GdkColor *bg)
{
  GtkStateType state;
  GtkStyle *style;

  state = gtk_widget_get_state(ruler->parent);
  style = gtk_widget_get_style(ruler->parent);
  if (fg) {
    *fg = style->fg[state];
  }

  if (bg) {
    *bg = style->bg[state];
  }
}
#endif	/* GTK_CHECK_VERSION(3, 0, 0) */

static void
#if GTK_CHECK_VERSION(3, 0, 0)
nruler_draw_pos(Nruler *ruler, GtkWidget *widget, cairo_t *cr)
#else	/* GTK_CHECK_VERSION(3, 0, 0) */
nruler_draw_pos(Nruler *ruler, GtkWidget *widget)
#endif	/* GTK_CHECK_VERSION(3, 0, 0) */
{
  gint x, y;
  gint width, height;
  gint bs_width, bs_height;
  gdouble increment;
  GtkAllocation allocation;
#if GTK_CHECK_VERSION(3, 0, 0)
  GdkRGBA fg;
#else	/* GTK_CHECK_VERSION(3, 0, 0) */
  GdkColor fg;
  cairo_t *cr;
#endif	/* GTK_CHECK_VERSION(3, 0, 0) */

  gtk_widget_get_allocation(widget, &allocation);

  if (! gtk_widget_is_drawable(widget)) {
    return;
  }


  if (ruler->orientation == GTK_ORIENTATION_HORIZONTAL) {
    width = ruler->length;
    height = ruler->size;
    bs_width = height / 2 + 2;
    bs_width |= 1;  /* make sure it's odd */
    bs_height = bs_width / 2 + 1;
  } else {
    width = ruler->size;
    height = ruler->length;
    bs_height = width / 2 + 2;
    bs_height |= 1;  /* make sure it's odd */
    bs_width = bs_height / 2 + 1;
  }

  if (bs_width <= 0 || bs_height <= 0) {
    return;
  }

#if ! GTK_CHECK_VERSION(3, 0, 0)
  cr = gdk_cairo_create(gtk_widget_get_window(widget));
#endif	/* ! GTK_CHECK_VERSION(3, 0, 0) */

  /*  If a backing store exists, restore the ruler  */
  if (ruler->backing_store) {
#if GTK_CHECK_VERSION(3, 0, 0)
    cairo_set_source_surface(cr, ruler->backing_store, 0, 0);
#else	/* GTK_CHECK_VERSION(3, 0, 0) */
    gdk_cairo_set_source_pixmap(cr, ruler->backing_store, 0, 0);
#endif	/* GTK_CHECK_VERSION(3, 0, 0) */
    cairo_rectangle(cr, 0, 0, allocation.width, allocation.height);
    cairo_fill(cr);
  }

  if (ruler->orientation == GTK_ORIENTATION_HORIZONTAL) {
    increment = (gdouble) width / (ruler->upper - ruler->lower);

    x = nround((ruler->position - ruler->lower) * increment) - bs_width / 2 - ruler->ofst;
    y = (height + bs_height) / 2 - 1;
  } else {
    increment = (gdouble) height / (ruler->upper - ruler->lower);

    x = (width + bs_width) / 2 - 1;
    y = nround((ruler->position - ruler->lower) * increment) - bs_height / 2 - ruler->ofst;
  }

#if GTK_CHECK_VERSION(3, 0, 0)
  nruler_get_color(ruler, &fg);
  gdk_cairo_set_source_rgba(cr, &fg);
#else	/* GTK_CHECK_VERSION(3, 0, 0) */
  nruler_get_color(ruler, &fg, NULL);
  gdk_cairo_set_source_color(cr, &fg);
#endif	/* GTK_CHECK_VERSION(3, 0, 0) */

  cairo_set_antialias(cr, CAIRO_ANTIALIAS_NONE);
  cairo_move_to(cr, x, y);

  if (ruler->orientation == GTK_ORIENTATION_HORIZONTAL) {
    cairo_line_to(cr, x + bs_width / 2.0, y + bs_height);
    cairo_line_to(cr, x + bs_width, y);
  } else {
    cairo_line_to(cr, x + bs_width, y + bs_height / 2.0);
    cairo_line_to(cr, x, y + bs_height);
  }

  cairo_fill(cr);

#if ! GTK_CHECK_VERSION(3, 0, 0)
  cairo_destroy(cr);
#endif	/* ! GTK_CHECK_VERSION(3, 0, 0) */
}
Example #25
0
/*!
 \brief updates the chart position,  This is the CAIRO implementation
 \param chart is the pointer to the chart object
 */
void update_stripchart_position (MtxStripChart *chart)
{
	GtkWidget * widget = NULL;
	cairo_font_weight_t weight;
	cairo_font_slant_t slant;
	gfloat tmpf = 0.0;
	gfloat needle_pos = 0.0;
	gchar * tmpbuf = NULL;
	gchar * message = NULL;
	gint shift = 0;
	gfloat start_x = 0.0;
	gfloat start_y = 0.0;
	gfloat buffer = 0.0;
	gboolean draw_quarters = TRUE;
	gint i = 0;
	gint j = 0;
	gfloat x = 0.0;
	gfloat y = 0.0;
	gfloat text_offset[NUM_TXTS] = {0.0,0.0,0.0,0.0,0.0};
	GdkPoint tip;
	cairo_t *cr = NULL;
	cairo_t *cr2 = NULL;
	cairo_text_extents_t extents;
	MtxStripChartTrace *trace = NULL;
	MtxStripChartPrivate *priv = MTX_STRIPCHART_GET_PRIVATE(chart);

	widget = GTK_WIDGET(chart);
	shift = priv->newsamples;

	/* Draw new data to trace pixmap */

	/* Scroll trace pixmap */

	cr = gdk_cairo_create(priv->trace_pixmap);
	gdk_cairo_set_source_pixmap(cr,priv->trace_pixmap,-shift,0);
	cairo_rectangle(cr,0,0,priv->w,priv->h);
	cairo_fill(cr);
	cairo_set_source_rgb(cr,0,0,0);
	cairo_rectangle(cr,priv->w-shift,0,shift,priv->h);
	cairo_fill(cr);
	/* Render new data */

	for (i=0;i<priv->num_traces;i++)
	{
		trace = g_array_index(priv->traces,MtxStripChartTrace *,i);

		cairo_set_line_width(cr,trace->lwidth);
		cairo_set_source_rgb (cr, 
				trace->color.red/65535.0,
				trace->color.green/65535.0,
				trace->color.blue/65535.0);
		for(j=shift;j>0;j--)
		{
			if (trace->history->len > 1)
			{
				start_x = priv->w - j;
				start_y = priv->h - (((g_array_index(trace->history,gfloat,trace->history->len-j-1)-trace->min) / (trace->max - trace->min))*priv->h);
				cairo_move_to(cr,start_x,start_y);
				x = priv->w-j+1;
				y = priv->h - (((g_array_index(trace->history,gfloat,trace->history->len-j)-trace->min) / (trace->max - trace->min))*priv->h);
				cairo_line_to(cr,x,y);
				cairo_stroke(cr);
			}
		}
	}
	cairo_destroy(cr);

	/* Copy background trace pixmap to grat for grat rendering */

	cr = gdk_cairo_create(priv->grat_pixmap);
	gdk_cairo_set_source_pixmap(cr,priv->trace_pixmap,0,0);
	cairo_rectangle(cr,0,0,priv->w,priv->h);
	cairo_fill(cr);

	/* Render the graticule lines */

	cairo_set_source_rgba (cr, 
			priv->colors[COL_GRAT].red/65535.0,
			priv->colors[COL_GRAT].green/65535.0,
			priv->colors[COL_GRAT].blue/65535.0,
			0.5);
	cairo_move_to(cr,0,priv->h/4);
	cairo_line_to(cr,priv->w,priv->h/4);
	cairo_stroke(cr);
	cairo_move_to(cr,0,priv->h/2);
	cairo_line_to(cr,priv->w,priv->h/2);
	cairo_stroke(cr);
	cairo_move_to(cr,0,priv->h*3/4);
	cairo_line_to(cr,priv->w,priv->h*3/4);
	cairo_stroke(cr);

	cairo_set_font_options(cr,priv->font_options);
	tmpbuf = g_utf8_strup(priv->font,-1);
	if (g_strrstr(tmpbuf,"BOLD"))
		weight = CAIRO_FONT_WEIGHT_BOLD;
	else
		weight = CAIRO_FONT_WEIGHT_NORMAL;
	if (g_strrstr(tmpbuf,"OBLIQUE"))
		slant = CAIRO_FONT_SLANT_OBLIQUE;
	else if (g_strrstr(tmpbuf,"ITALIC"))
		slant = CAIRO_FONT_SLANT_ITALIC;
	else
		slant = CAIRO_FONT_SLANT_NORMAL;
	g_free(tmpbuf);
	cairo_select_font_face (cr, priv->font,  slant, weight);

	cairo_set_font_size (cr, 12);

	cairo_set_antialias(cr,CAIRO_ANTIALIAS_DEFAULT);
	buffer = 0;
	text_offset[BOTTOM] = 0.0;
	message = g_strdup_printf("123");
	cairo_text_extents(cr,message,&extents);
	if ((extents.height * 4) > (priv->h/4))
		draw_quarters = FALSE;
	else
		draw_quarters = TRUE;
	g_free(message);
	/* render the new data */

	cr2 = gdk_cairo_create(priv->grat_pixmap);
	cairo_set_source_rgba(cr2,0.13,0.13,0.13,0.75);

	for (i=0;i<priv->num_traces;i++)
	{
		trace = g_array_index(priv->traces,MtxStripChartTrace *,i);
		cairo_set_source_rgb (cr, 
				trace->color.red/65535.0,
				trace->color.green/65535.0,
				trace->color.blue/65535.0
				);
		message = g_strdup_printf("%1$.*2$f", trace->min,trace->precision);
		cairo_text_extents (cr, message, &extents);
		cairo_rectangle(cr2,2.0+text_offset[BOTTOM],priv->h-2.0,extents.width,-extents.height);
		cairo_fill(cr2);
		cairo_move_to(cr,2.0+text_offset[BOTTOM],priv->h-2.0);

		cairo_show_text (cr, message);
		g_free(message);
		text_offset[BOTTOM] += extents.width + 7;

		if (draw_quarters)
		{
			message = g_strdup_printf("%1$.*2$f", trace->min+((trace->max-trace->min)/4),trace->precision);
			cairo_text_extents (cr, message, &extents);
			cairo_rectangle(cr2,2.0+text_offset[QUARTER],priv->h*3/4-2.0,extents.width,-extents.height);
			cairo_fill(cr2);
			cairo_move_to(cr,2.0+text_offset[QUARTER],(priv->h*3/4)-2.0);
			cairo_show_text (cr, message);
			g_free(message);
			text_offset[QUARTER] += extents.width + 7;
		}

		message = g_strdup_printf("%1$.*2$f", trace->min+((trace->max-trace->min)/2),trace->precision);
		cairo_text_extents (cr, message, &extents);
		cairo_rectangle(cr2,2.0+text_offset[HALF],(priv->h/2.0)-2.0,extents.width,-extents.height);
		cairo_fill(cr2);
		cairo_move_to(cr,2.0+text_offset[HALF],(priv->h/2.0)-2.0);
		cairo_show_text (cr, message);
		g_free(message);
		text_offset[HALF] += extents.width + 7;

		if (draw_quarters)
		{
			message = g_strdup_printf("%1$.*2$f", trace->min+((trace->max-trace->min)*3/4),trace->precision);
			cairo_text_extents (cr, message, &extents);
			cairo_rectangle(cr2,2.0+text_offset[THREEQUARTER],priv->h/4-2.0,extents.width,-extents.height);
			cairo_fill(cr2);
			cairo_move_to(cr,2.0+text_offset[THREEQUARTER],(priv->h/4)-2.0);
			cairo_show_text (cr, message);
			g_free(message);
			text_offset[THREEQUARTER] += extents.width + 7;
		}

		message = g_strdup_printf("%1$.*2$f", trace->max,trace->precision);
		cairo_text_extents (cr, message, &extents);
		cairo_rectangle(cr2,2.0+text_offset[TOP],2.0,extents.width,extents.height);
		cairo_fill(cr2);
		cairo_move_to(cr,2.0+text_offset[TOP],extents.height+2.0);
		cairo_show_text (cr, message);
		g_free(message);
		text_offset[TOP] += extents.width + 7;

		/* Trace names */

		message = g_strdup_printf("%s", trace->name);
		cairo_text_extents (cr, message, &extents);
		cairo_rectangle(cr2,priv->w-extents.width - 20, 2.0+buffer +extents.height,extents.width,-extents.height);
		cairo_fill(cr2);
		cairo_move_to(cr,priv->w-extents.width - 20, 2.0 + buffer + extents.height);
		cairo_show_text (cr, message);
		g_free(message);
		buffer += (extents.height + 3);

	}
	cairo_destroy(cr);
	cairo_destroy(cr2);
}
Example #26
0
void resource_format_type_image(GtkImage * image, const gint * resources,
				gint max_width)
{
	gint num_res, tot_res, idx, i, pos;

	GdkPixmap *p, *pdest;
	GdkBitmap *b, *bdest;
	gchar *data;
	gint size, step;
	gint width;
	cairo_t *cr;
	GdkRectangle r;

	num_res = tot_res = 0;
	for (idx = 0; idx < NO_RESOURCE; idx++) {
		if (resources[idx]) {
			num_res++;
			tot_res += resources[idx];
		}
	}

	if (tot_res == 0) {
		tot_res = 1;	/* Avoid division by zero */
	}

	size = gui_get_resource_pixmap_res();
	pos = 0;

	if (max_width <= 0 || tot_res == num_res
	    || max_width >= size * tot_res) {
		step = size;
		width = size * num_res + step * (tot_res - num_res);
		if (width < max_width)
			width = max_width;
	} else {
		step = (max_width - num_res * size) / (tot_res - num_res);
		if (step <= 0)
			step = 1;
		width = max_width;
	}

	pdest =
	    gdk_pixmap_new(NULL,
			   width, size, gdk_visual_get_system()->depth);
	data = g_malloc0((((width + 7) >> 3) * size));
	bdest =
	    gdk_bitmap_create_from_data(NULL, data,
					size * num_res + step * (tot_res -
								 num_res),
					size);
	g_free(data);

	r.x = 0;
	r.y = 0;
	r.width = width;
	r.height = width;
	for (idx = 0; idx < NO_RESOURCE; idx++) {
		if (!resources[idx])
			continue;
		gui_get_resource_pixmap(idx, &p, &b);
		for (i = 0; i < resources[idx]; i++) {
			cr = gdk_cairo_create(pdest);
			gdk_cairo_set_source_pixmap(cr, p, pos, 0);
			gdk_cairo_rectangle(cr, &r);
			cairo_fill(cr);
			cairo_destroy(cr);

			cr = gdk_cairo_create(bdest);
			gdk_cairo_set_source_pixmap(cr, b, pos, 0);
			gdk_cairo_rectangle(cr, &r);
			cairo_fill(cr);
			cairo_destroy(cr);

			pos += step;
		}
		pos += size - step;
	}

	gtk_image_set_from_pixmap(image, pdest, bdest);

	g_object_unref(pdest);
	g_object_unref(bdest);
}
Example #27
0
static gboolean
gtk_mirror_bin_expose (GtkWidget      *widget,
                        GdkEventExpose *event)
{
  GtkMirrorBin *bin = GTK_MIRROR_BIN (widget);
  gint width, height;

  if (gtk_widget_is_drawable (widget))
    {
      if (event->window == widget->window)
        {
          GdkPixmap *pixmap;
          cairo_t *cr;
          cairo_matrix_t matrix;
          cairo_pattern_t *mask;

          if (bin->child && gtk_widget_get_visible (bin->child))
            {
              pixmap = gdk_offscreen_window_get_pixmap (bin->offscreen_window);
              gdk_drawable_get_size (pixmap, &width, &height);

              cr = gdk_cairo_create (widget->window);

              cairo_save (cr);

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

              /* paint the offscreen child */
              gdk_cairo_set_source_pixmap (cr, pixmap, 0, 0);
              cairo_paint (cr);

              cairo_restore (cr);

              cairo_matrix_init (&matrix, 1.0, 0.0, 0.3, 1.0, 0.0, 0.0);
              cairo_matrix_scale (&matrix, 1.0, -1.0);
              cairo_matrix_translate (&matrix, -10, - 3 * height - 10);
              cairo_transform (cr, &matrix);

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

              gdk_cairo_set_source_pixmap (cr, pixmap, 0, height);

              /* create linear gradient as mask-pattern to fade out the source */
              mask = cairo_pattern_create_linear (0.0, height, 0.0, 2*height);
              cairo_pattern_add_color_stop_rgba (mask, 0.0,  0.0, 0.0, 0.0, 0.0);
              cairo_pattern_add_color_stop_rgba (mask, 0.25, 0.0, 0.0, 0.0, 0.01);
              cairo_pattern_add_color_stop_rgba (mask, 0.5,  0.0, 0.0, 0.0, 0.25);
              cairo_pattern_add_color_stop_rgba (mask, 0.75, 0.0, 0.0, 0.0, 0.5);
              cairo_pattern_add_color_stop_rgba (mask, 1.0,  0.0, 0.0, 0.0, 1.0);

              /* paint the reflection */
              cairo_mask (cr, mask);

              cairo_pattern_destroy (mask);
              cairo_destroy (cr);
            }
        }
      else if (event->window == bin->offscreen_window)
        {
          gtk_paint_flat_box (widget->style, event->window,
                              GTK_STATE_NORMAL, GTK_SHADOW_NONE,
                              &event->area, widget, "blah",
                              0, 0, -1, -1);

          if (bin->child)
            gtk_container_propagate_expose (GTK_CONTAINER (widget),
                                            bin->child,
                                            event);
        }
    }

  return FALSE;
}
Example #28
0
void gtk_codegraph_save(GtkCodeGraph *box){
    g_return_if_fail (GTK_IS_CODEGRAPH (box));
//Создается диалог выбора места сохранения тренда
    GtkWidget *_dialog = gtk_file_chooser_dialog_new("Сохранить",  NULL, GTK_FILE_CHOOSER_ACTION_SAVE, 
							GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, 
                                    			GTK_STOCK_OK, GTK_RESPONSE_NONE, NULL);							

	GtkWidget *widget = GTK_WIDGET(box);
	gtk_file_chooser_set_current_name (GTK_FILE_CHOOSER (_dialog), "Untitled");
//Добавляем фильты по типу файлов
	GtkFileFilter *ffilter = gtk_file_filter_new();
	ffilter = gtk_file_filter_new();
	gtk_file_filter_set_name( ffilter, "Рисунок PNG");
	gtk_file_filter_add_pattern( ffilter, "*.png");
	gtk_file_chooser_add_filter(GTK_FILE_CHOOSER (_dialog), ffilter);

	ffilter = gtk_file_filter_new();
	gtk_file_filter_set_name( ffilter, "Файл данных MathLab");
	gtk_file_filter_add_pattern( ffilter, "*.dat");
	gtk_file_chooser_add_filter(GTK_FILE_CHOOSER (_dialog), ffilter);
//Отлавливаем конец выбора и работаем
	gint result = gtk_dialog_run (GTK_DIALOG (_dialog) );
	gchar buff[100];
	gchar *fil = NULL; 
	gchar *dir = NULL;
	gchar *filename = NULL;
	if (result == GTK_RESPONSE_NONE){
	    filename = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (_dialog));
	    fil =(char*) gtk_file_filter_get_name( gtk_file_chooser_get_filter(GTK_FILE_CHOOSER (_dialog)) );
	    dir = gtk_file_chooser_get_current_folder (GTK_FILE_CHOOSER (_dialog)); 
	    if (!strcmp(fil, "Рисунок PNG" ) ) 
	        snprintf(buff,sizeof(buff), "%s.png", filename );
	    else if (!strcmp(fil, "Файл данных MathLab" ) ) 
	        snprintf(buff,sizeof(buff), "%s.dat", filename );
	    else	
		snprintf(buff,sizeof(buff), "%s.png", filename );
	}
/*Если юзер передумал сохраняться*/
	else{
	    gtk_widget_destroy (_dialog);
	    return;
	}
/*Ошибка при открытии файла	*/
	FILE *fp;
	if ((fp=fopen(buff, "w")) == NULL ){
	    gchar buff[300];
	    gchar *homedir = (gchar*)getenv("HOME");
	    snprintf(buff, sizeof(buff), "Отказано в доступе.\nСохранить файл в %s  не удалось. \nВыберите, другой каталог, \nнапример: %s",filename, homedir );
	    GtkWidget* dialog = gtk_message_dialog_new (GTK_WINDOW (NULL),
				      (GtkDialogFlags)(GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT), GTK_MESSAGE_INFO, GTK_BUTTONS_OK,
				        buff );
	    gtk_dialog_run (GTK_DIALOG (dialog));
	    gtk_widget_destroy (dialog);
	}
	else{
/*Сохраняем картинку*/
	    cairo_surface_t *surface;
	    if (!strcmp(fil, "Рисунок PNG" ) ){
		fclose(fp);
		cairo_surface_t * surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32, widget->allocation.width , widget->allocation.height );
		cairo_t *cr_save = cairo_create (surface);
		gdk_cairo_set_source_pixmap(cr_save, box->priv->backing_pixmap, 0.0, 0.0);
		cairo_paint(cr_save);
		cairo_destroy (cr_save);
		cairo_surface_write_to_png (surface, buff);
		cairo_surface_destroy (surface);
	    }
/*Сохраняем данные*/	    
	    if ( !strcmp(fil, "Файл данных MathLab" )  ){
		int i; int im=0;
		gchar buff[40];
		for (i=0; i<box->priv->numPointsText; i+=2 ){
		    ++im;
		    g_snprintf(buff, sizeof(buff), "%d импульс: %1.3f сек;\n",im ,box->priv->dta[i]  );
		    fwrite(buff, strlen(buff), 1, fp);
		    g_snprintf(buff, sizeof(buff), "%d интервал: %1.3f сек;\n",im ,box->priv->dta[i+1]  );
		    fwrite(buff, strlen(buff), 1, fp);
		}
		fclose(fp);
	    }
	}
	gtk_widget_destroy (_dialog);

}