Пример #1
0
void dtgtk_cairo_paint_lock(cairo_t *cr, gint x, gint y, gint w, gint h, gint flags)
{
  gint s=w<h?w:h;
  cairo_translate(cr, x+(w/2.)-(s/2.), y+(h/2.)-(s/2.));
  cairo_scale(cr, s, s);

  // Adding the lock body
  cairo_rectangle(cr, 0.25, 0.5, .5, .45);
  cairo_fill(cr);

  // Adding the lock shank
  cairo_set_line_width(cr, 0.2);
  cairo_set_line_cap(cr, CAIRO_LINE_CAP_BUTT);
  cairo_translate(cr, .5, .5);
  cairo_scale(cr, .2, .4);
  cairo_arc(cr, 0, 0, 1, M_PI, 0);
  cairo_stroke(cr);

}
Пример #2
0
void XYGraph::plot_point( cairo_t *cairo, double x, double y )
{
    cairo_save( cairo );
    cairo_translate( cairo, x, y );
    cairo_scale( cairo, _point_scale, _point_scale );
    
    if( _pointstyle == XYGRAPH_POINT_CIRCLE ) {
	cairo_move_to( cairo, 1.0, 0.0 );
	cairo_arc( cairo, 0.0, 0.0, 1.0, 0.0, 2.0*M_PI );
    } else if( _pointstyle == XYGRAPH_POINT_BOX ) {
	cairo_rectangle( cairo, -1.0, -1.0, 2.0, 2.0 );
    }

    cairo_restore( cairo );
    if( _point_filled )
	cairo_fill( cairo );
    else
	cairo_stroke( cairo );
}
Пример #3
0
static void drone_render(GpsdViewerOsd *self, OsmGpsMap *map)
{
    GpsdViewerOsdUAV *drone = self->priv->drone;
    cairo_pattern_t *pat=NULL;
    cairo_t *cr = NULL;

    if(!drone->surface || !drone->need_render)
    {
      g_assert(drone->surface);
		cr = cairo_create(drone->surface);
		cairo_set_operator(cr, CAIRO_OPERATOR_SOURCE);
		cairo_set_source_rgba(cr, 1.0, 1.0, 0.0, 0.0);
		cairo_paint(cr);
		cairo_set_operator(cr, CAIRO_OPERATOR_OVER);
		drone->need_render = FALSE;
    }
    else
    {
		// **** fill with transparency
		g_assert(drone->surface);
		cr = cairo_create(drone->surface);
		cairo_set_operator(cr, CAIRO_OPERATOR_SOURCE);
		cairo_set_source_rgba(cr, 1.0, 1.0, 0.0, 0.0);
		cairo_paint(cr);
		cairo_set_operator(cr, CAIRO_OPERATOR_OVER);
    
		cairo_set_line_width (cr, 1);
		cairo_arc (cr, GPSD_VIEWER_OSD_UAV_W/2, GPSD_VIEWER_OSD_COORDINATES_H/2, GPSD_VIEWER_OSD_UAV_RADIUS, 0, 2*M_PI);
		pat = cairo_pattern_create_radial (GPSD_VIEWER_OSD_UAV_W/2-1, GPSD_VIEWER_OSD_COORDINATES_H/2-1, GPSD_VIEWER_OSD_UAV_RADIUS*0.2,
														GPSD_VIEWER_OSD_UAV_W/2, GPSD_VIEWER_OSD_COORDINATES_H/2, GPSD_VIEWER_OSD_UAV_RADIUS);
		cairo_pattern_add_color_stop_rgba (pat,0, 0.8, 0.8, 1.0,0.8);
		cairo_pattern_add_color_stop_rgba (pat,1, 0.0, 0.0, 0.65,0.8);
		cairo_set_source (cr, pat);
		cairo_fill_preserve(cr);
		cairo_set_source_rgba(cr, 0.0, 0.0, 0.0, 1.0);
		cairo_stroke (cr);
		
		cairo_pattern_destroy (pat);    
		drone->need_render = FALSE;
	}
	cairo_destroy(cr);
}
Пример #4
0
void fieldDraw(cairo_t *cairoDrawPlace, field_t *field)
{
    int i, j;
    for (i = 0; i < field->size.y; i++) {
        for (j = 0; j < field->size.x; j++) {
            switch (field->values[i][j]) {
            case SHIP:
                cairo_set_source_rgba(cairoDrawPlace, 1, 0.85, 0, 1);
                cairo_rectangle(cairoDrawPlace, j * pixelConst, i * pixelConst, pixelConst, pixelConst);
                cairo_fill(cairoDrawPlace);
                cairo_stroke(cairoDrawPlace);
                break;
            case BLOCK_LVL1:
                cairo_set_source_rgba(cairoDrawPlace, 1, 1, 1, 1);
                cairo_rectangle(cairoDrawPlace, j * pixelConst, i * pixelConst, pixelConst, pixelConst);
                cairo_fill(cairoDrawPlace);
                cairo_stroke(cairoDrawPlace);
                break;
            case BLOCK_LVL2:
                cairo_set_source_rgba(cairoDrawPlace, 0.5 , 0.5, 0.5, 1);  //127
                cairo_rectangle(cairoDrawPlace, j * pixelConst, i * pixelConst, pixelConst, pixelConst);
                cairo_fill(cairoDrawPlace);
                cairo_stroke(cairoDrawPlace);
                break;
            case BLOCK_LVL3:
                cairo_set_source_rgba(cairoDrawPlace, 0.25, 0.25, 0.25, 1);  //64
                cairo_rectangle(cairoDrawPlace, j * pixelConst, i * pixelConst, pixelConst, pixelConst);
                cairo_fill(cairoDrawPlace);
                cairo_stroke(cairoDrawPlace);
                break;
            case BULLET:
                cairo_set_source_rgba(cairoDrawPlace, 0, 0, 0, 1);
                cairo_arc(cairoDrawPlace, j * pixelConst + (pixelConst / 2), 
                                          i * pixelConst + (pixelConst / 2), 
                                          pixelConst / 4, 0, 2 * 3.14);
                cairo_fill(cairoDrawPlace);
                cairo_stroke(cairoDrawPlace);
                break;
            }
        }
    }
}
Пример #5
0
void crossover_cell_glyph(cairo_t *cr) {
	static cairo_pattern_t *pat = 0;

	cairo_save(cr);
	cairo_scale(cr,0.8,0.8);

	if(pat == 0) {
		pat = cairo_pattern_create_radial (0.27, 0.3, 0.08, 0.2, 0.35, 0.6);
		cairo_pattern_add_color_stop_rgb (pat, 0, 0.9, 0.9, 0.9);
		cairo_pattern_add_color_stop_rgb (pat, 1, 0.8, 0.5, 0.8);
	}

	cairo_new_path(cr);
#ifdef CROSSOVER_DIAMOND
	cairo_move_to(cr,0.5,0.0);
	cairo_line_to(cr,0.0,0.5);
	cairo_line_to(cr,0.5,1.0);
	cairo_line_to(cr,1.0,0.5);
#else
	cairo_arc(cr,0.5,0.5,0.5,0,M_PI*2);
#endif
	cairo_close_path(cr);

	cairo_set_source (cr, pat);

	cairo_fill_preserve (cr);

	cairo_set_source_rgb(cr,0.0,0.0,0.0);
	cairo_set_line_width(cr,0.07);
	cairo_set_line_join(cr,CAIRO_LINE_JOIN_ROUND);
	cairo_stroke(cr);

#ifndef CROSSOVER_DIAMOND
	cairo_move_to(cr,0.5+sqrt(2.0)/4.0,0.5+sqrt(2.0)/4.0);
	cairo_line_to(cr,0.5-sqrt(2.0)/4.0,0.5-sqrt(2.0)/4.0);
	cairo_move_to(cr,0.5-sqrt(2.0)/4.0,0.5+sqrt(2.0)/4.0);
	cairo_line_to(cr,0.5+sqrt(2.0)/4.0,0.5-sqrt(2.0)/4.0);
	cairo_stroke(cr);
#endif
	
	cairo_restore(cr);
}
Пример #6
0
void explosion_step1(cairo_t *cr, int X_Pos,int Y_Pos, int step)
{
  int i = 10 * (step + 1);
  int iarc;


	cairo_set_source_rgba(cr, 0, 0, 0, 0.2126);
	#ifdef GUI_INTERFACE
	cairo_set_source_rgb(SF_rgb_context, 1.0, 0.0, 0.0);
	#endif
//	cairo_set_source_rgba(cr, 0.0, 1, 0);
	for(iarc=i/5;iarc<360+i/5;iarc=iarc+20)
  {
		cairo_new_sub_path(cr);
		cairo_arc(cr, X_Pos,Y_Pos, i, deg2rad(iarc), deg2rad(iarc+2));
	}
	stroke_in_clip(cr);
//	cairo_reset_clip(cr);
//	cairo_stroke(cr);
}
Пример #7
0
static cairo_test_status_t
draw (cairo_t *cr, int width, int height)
{
    /* fill with green so RGB and RGBA tests can share the ref image */
    cairo_set_source_rgb (cr, 0, 1, 0);
    cairo_paint (cr);

    /* red to see eventual bugs immediately */
    cairo_set_source_rgb (cr, 1, 0, 0);

    /* stroke 3/4 of a circle where the last quarter would be this
     * reference image. Keep just a 1 pixel border. Use a huge line
     * width (twice the circle's radius to get it filled completely).
     */
    cairo_set_line_width (cr, 2 * RADIUS);
    cairo_arc (cr, 1, RADIUS - 1, RADIUS, 0, - M_PI / 2.0);
    cairo_stroke (cr);

    return CAIRO_TEST_SUCCESS;
}
Пример #8
0
static void
draw (cairo_t *cr, int width, int height)
{
    int radius;

    if (width < height)
	radius = width/2 - 4;
    else
	radius = height/2 - 4;

    cairo_move_to (cr, width/2 + radius, height/2);
    cairo_arc (cr, width/2, height/2, radius,
	       0.0, 2 * M_PI);

    cairo_set_source_rgb (cr, 0.6, 0.8, 1.0);
    cairo_fill_preserve (cr);

    cairo_set_source_rgb (cr, 0.0, 0.0, 0.0);
    cairo_stroke (cr);
}
Пример #9
0
static void
_cairo_ellipsis (cairo_t *cr,
                 double xc, double yc,
                 double xradius, double yradius,
                 double angle1, double angle2)
{
    cairo_matrix_t save;

    if (xradius <= 0.0 || yradius <= 0.0)
    {
        cairo_line_to (cr, xc, yc);
        return;
    }

    cairo_get_matrix (cr, &save);
    cairo_translate (cr, xc, yc);
    cairo_scale (cr, xradius, yradius);
    cairo_arc (cr, 0, 0, 1.0, angle1, angle2);
    cairo_set_matrix (cr, &save);
}
Пример #10
0
static void
render (GtkCellRenderer *cell,
        GdkDrawable *window,
        GtkWidget *widget,
        GdkRectangle *background_area,
        GdkRectangle *cell_area,
        GdkRectangle *expose_area,
        GtkCellRendererState flags)
{
	GtkCellRendererClass *klass;
	GtkCellRendererBubblePrivate *priv;
	cairo_t *cr;
	GdkColor color;
	gint radius;

	g_return_if_fail(GTK_IS_CELL_RENDERER_BUBBLE (cell));

	priv = GTK_CELL_RENDERER_BUBBLE (cell)->priv;

	if (priv->show_bubble) {
		cr = gdk_cairo_create(GDK_DRAWABLE (window));

		gdk_color_parse("#ccc", &color);
		gdk_cairo_set_source_color(cr, &color);

		radius = MIN(cell_area->width, cell_area->height) / 2;
		cairo_arc(cr,
		          cell_area->x + (cell_area->width / 2),
		          cell_area->y + (cell_area->height / 2),
		          radius,
		          0,
		          2 * G_PI);
		cairo_fill(cr);

		cairo_destroy(cr);
	}

	klass = GTK_CELL_RENDERER_CLASS(gtk_cell_renderer_bubble_parent_class);
	klass->render(cell, window, widget, background_area,
	              cell_area, expose_area, flags);
}
static void
draw_waves (cairo_t *cr,
            double   cx,
            double   cy,
            double   max_radius,
            int      volume_level)
{
        const int n_waves = 3;
        int last_wave;
        int i;

        last_wave = n_waves * volume_level / 100;

        for (i = 0; i < n_waves; i++) {
                double angle1;
                double angle2;
                double radius;
                double alpha;

                angle1 = -M_PI / 4;
                angle2 = M_PI / 4;

                if (i < last_wave)
                        alpha = 1.0;
                else if (i > last_wave)
                        alpha = 0.1;
                else alpha = 0.1 + 0.9 * (n_waves * volume_level % 100) / 100.0;

                radius = (i + 1) * (max_radius / n_waves);
                cairo_arc (cr, cx, cy, radius, angle1, angle2);
                cairo_set_source_rgba (cr, 0.6, 0.6, 0.6, alpha / 2);
                cairo_set_line_width (cr, 14);
                cairo_set_line_cap  (cr, CAIRO_LINE_CAP_ROUND);
                cairo_stroke_preserve (cr);

                cairo_set_source_rgba (cr, 1.0, 1.0, 1.0, alpha);
                cairo_set_line_width (cr, 10);
                cairo_set_line_cap  (cr, CAIRO_LINE_CAP_ROUND);
                cairo_stroke (cr);
        }
}
Пример #12
0
static void 
paints_anime (GtkObject *object, gpointer user_data)
{

   if(!start) return;

	GtkWidget * widget = (GtkWidget *) object;

   cairo_t *cr;
	cairo_t *ci;

	cr = gdk_cairo_create (widget->window);

	// nastavení pozadí kreslící plochy
	cairo_set_source_rgb (cr, 0.0,0.0,0.0);

	cairo_paint (cr);
   
   static int i = 0;
	i++;

	//cairo_set_source_surface(cr, surface, 0, 0);
	//cairo_mask_surface(cr, surface, 0, 0);
	int h,w;
	gdk_window_get_size(widget->window,&w,&h);

  // printf("%d %d \n",w,h);

	for(int k = 0; k < vgames.size(); k++) {

		 cairo_set_source_rgba (cr, 1.,1.,0., 1.);
		 cairo_arc (cr, vgames[k].x*w,vgames[k].y*h,  15, 0, 2 * M_PI);
		 cairo_fill_preserve (cr);
		 cairo_stroke (cr);
   }

	cairo_destroy(cr);


	currently_anime = 0;
}
Пример #13
0
static void
ensure_resources(cairo_surface_t *target)
{
  cairo_t *cr;
  int i, j;

  if (source_surface != NULL)
    return;

  source_surface = cairo_surface_create_similar (target, CAIRO_CONTENT_COLOR_ALPHA,
                                                 16 * DIAMETER, 16 * DIAMETER);
  cr = cairo_create(source_surface);

  cairo_save(cr);
  cairo_set_source_rgba(cr, 0, 0, 0, 0);
  cairo_set_operator(cr, CAIRO_OPERATOR_SOURCE);
  cairo_paint(cr);
  cairo_restore(cr);

  cairo_set_line_width(cr, 1.0);

  for (j = 0; j < 16; j++)
    for (i = 0; i < 16; i++)
      {
        cairo_set_source_rgba(cr,
                              ((i * 41) % 16) / 15.,
                              ((i * 31) % 16) / 15.,
                              ((i * 23) % 16) / 15.,
                              0.25);
        cairo_arc(cr,
                  i * DIAMETER + RADIUS, j * DIAMETER + RADIUS,
                  RADIUS - 0.5, 0, 2 * M_PI);
        cairo_fill_preserve(cr);
        cairo_set_source_rgba(cr,
                              ((i * 41) % 16) / 15.,
                              ((i * 31) % 16) / 15.,
                              ((i * 23) % 16) / 15.,
                              1.0);
        cairo_stroke(cr);
      }
}
Пример #14
0
static cairo_test_status_t
draw (cairo_t *cr, int width, int height)
{
    cairo_rectangle (cr, PAD, PAD, SIZE, SIZE);
    cairo_set_source_rgb (cr, 0, 0, 1);
    cairo_fill_preserve (cr);
    cairo_set_source_rgb (cr, 1, 0, 0);
    cairo_stroke (cr);

    cairo_translate (cr, SIZE + 2 * PAD, 0);

    cairo_arc (cr,
	       PAD + SIZE / 2, PAD + SIZE / 2,
	       SIZE / 2,
	       0, 2 * M_PI);
    cairo_fill_preserve (cr);
    cairo_set_source_rgb (cr, 0, 0, 1);
    cairo_stroke (cr);

    return CAIRO_TEST_SUCCESS;
}
Пример #15
0
static void 
gtk_plot_cairo_draw_ellipse                            (GtkPlotPC *pc,
                                                        gint filled,
                                                        gdouble x, gdouble y,
                                                        gdouble width, gdouble height)
{
  cairo_t *cairo = GTK_PLOT_CAIRO(pc)->cairo;
  if (!cairo)
    return;

  cairo_save(cairo);
  cairo_translate(cairo, x+width/2.0,y+height/2.0);
  cairo_scale (cairo, 1. / (height / 2.), 1. / (width / 2.));
  cairo_arc (cairo, 0., 0., 1., 0., 2 * M_PI);
  cairo_restore(cairo);

  if (filled)
    cairo_fill(cairo);
  else
    cairo_stroke(cairo);
}
static gboolean
abc_color_box_draw (GtkWidget *widget, cairo_t *cr)
{
    AbcColorBox *self = ABC_COLOR_BOX(widget);
    gint width = gtk_widget_get_allocated_width (widget);
    gint height = gtk_widget_get_allocated_height (widget);

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

    if (self->priv->point) {
        guint x,y;
        g_object_get(self->priv->point, "x", &x, "y", &y, NULL);
        cairo_arc(cr, x, y, 5.0, 0.0, 2 * M_PI);
        cairo_set_source_rgb (cr, 0, 1, 0);
        cairo_fill(cr);
    }

    return FALSE;
}
Пример #17
0
void explosion_step2(cairo_t *cr, int X_Pos,int Y_Pos, int step)
{
	int j = step * 10;
  int iarc;

	if (j>0)
	{
		cairo_set_source_rgba(cr, 0, 0, 0, 0.9278);
		#ifdef GUI_INTERFACE
		cairo_set_source_rgb(SF_rgb_context, 1.0, 1.0, 0.0);
		#endif
		for(iarc=j/5;iarc<360+j/5;iarc=iarc+20)
		{
			cairo_new_sub_path(cr);
			cairo_arc(cr,X_Pos,Y_Pos,j,deg2rad(iarc),deg2rad(iarc+2));
		}
		stroke_in_clip(cr);
//		cairo_reset_clip(cr);
//		cairo_stroke(cr);
	}
}
Пример #18
0
void
osd_render_crosshair_shape(cairo_t *cr, int w, int h, int r, int tick) {
    cairo_arc (cr, w/2, h/2,
               r, 0,  2*M_PI);

    cairo_move_to (cr, w/2 - r,
                   h/2);
    cairo_rel_line_to (cr, -tick, 0);
    cairo_move_to (cr, w/2 + r,
                   h/2);
    cairo_rel_line_to (cr,  tick, 0);

    cairo_move_to (cr, w/2,
                   h/2 - r);
    cairo_rel_line_to (cr, 0, -tick);
    cairo_move_to (cr, w/2,
                   h/2 + r);
    cairo_rel_line_to (cr, 0, tick);

    cairo_stroke (cr);
}
Пример #19
0
void dtgtk_cairo_paint_zoom(cairo_t *cr, gint x, gint y, gint w, gint h, gint flags)
{
  gint s = (w<h?w:h);
  cairo_translate(cr, x+(w/2.0)-(s/2.0), y+(h/2.0)-(s/2.0));
  cairo_scale (cr,s,s);

  /* draw magnifying glass */

  cairo_set_line_cap(cr,CAIRO_LINE_CAP_ROUND);

  // handle
  cairo_set_line_width(cr, 0.2);
  cairo_move_to(cr, 0.9, 1.0 - 0.1);
  cairo_line_to(cr, 0.65, 1.0 - 0.35);
  cairo_stroke(cr);

  // lens
  cairo_set_line_width(cr, 0.1);
  cairo_arc(cr, 0.35, 1.0 - 0.65, 0.3, -M_PI, M_PI);
  cairo_stroke(cr);
}
void render_dots(cairo_t *cr, int subdiv) {
  int x, y;

  int a = 1 << subdiv;

  cairo_new_path(cr);

  for (y = -a; y <= a; y = y + 1) {
    for (x = -a; x <= a; x = x + 1) {
      cairo_new_sub_path(cr);
      cairo_arc(cr, (double) x / a, (double) y / a, 1/256.0, 0, 2 * M_PI);
    }
  }

  cairo_set_source_rgb(cr, 0.0, 0.0, 0.0);
  cairo_set_line_width(cr, 1/64.0);
  cairo_stroke_preserve(cr);
  cairo_set_source_rgb(cr, 1.0, 1.0, 1.0);
  cairo_set_line_width(cr, 1/128.0);
  cairo_stroke(cr);
}
Пример #21
0
//  gdouble scale_factor = ((float)MIN(width,height))/(128+SPACING/2);
//  cairo_scale(cr, scale_factor, scale_factor);
//  RsvgHandle* svg = rsvg_handle_new_from_file ("ship.svg", NULL);
//  rsvg_handle_render_cairo(svg, cr);
static void draw_map(cairo_t * cr, guint width, guint height, guint i, guint j) {
  switch (map[i][j]) {
    case BRICK_WALL:
    cairo_set_source_rgba(cr, 0.5, 0.5, 0.5, 1.0);
    break;
    case BRICK_TOP:
    cairo_set_source_rgba(cr, 0.2, 0.2, 0.2, 1.0);
    break;
    default:
    cairo_set_source_rgba(cr, 0.8, 0.8, 0.8, 1.0);
    break;
  }  
  cairo_rectangle(cr, j*width, i*height, (j+1)*width, (i+1)*height);
  cairo_fill(cr);
  if (map[i][j] == GREY_FLOOR) {
    cairo_set_source_rgba (cr, 1.0, 1.0, 1.0, 1.0);
    cairo_arc (cr, j*width + width/2, i*height + height/2 + height/5, MIN(width, height)/5, 0, 2 * M_PI);
    cairo_fill(cr);
  }
  
}
Пример #22
0
void
dv_viewport_draw_focused_mark(dv_viewport_t * VP, cairo_t * cr) {
  (void) VP;
  (void) cr;
  cairo_save(cr);
  cairo_new_path(cr);
#if 0
  double margin = DVG->opts.ruler_width / 2;
  double x = margin;
  double y = margin;
  double r = DVG->opts.vp_mark_radius;
  //cairo_arc(cr, x + r, y + r, r, 0.0, 2 * M_PI);
  cairo_arc(cr, x, y, r, 0.0, 2 * M_PI);
  cairo_close_path(cr);
#else
  dv_draw_path_rectangle(cr, 0.0, 0.0, DVG->opts.ruler_width / 2.0, DVG->opts.ruler_width / 2.0);  
#endif
  cairo_set_source_rgb(cr, 1.0, 0.0, 0.0);
  cairo_fill(cr);
  cairo_restore(cr);
}
Пример #23
0
void draw_rsus(struct ScreenContext *screenContext)
{
	struct Cross *aCross;
	struct Item *anEntry;
	struct Point aPoint, bPoint, cPoint;

	anEntry = screenContext->rsus.head;
	while(anEntry != NULL) {
		aCross = (struct Cross*)anEntry->datap;
		gps_to_canvas(&screenContext->awin, aCross->gPoint.x, aCross->gPoint.y, &aPoint.x, &aPoint.y);
		gps_to_canvas(&screenContext->awin, aCross->box.xmin, aCross->box.ymin, &bPoint.x, &bPoint.y);
		gps_to_canvas(&screenContext->awin, aCross->box.xmax, aCross->box.ymin, &cPoint.x, &cPoint.y);
		cairo_arc(screenContext->cr_on_screen,  (int)aPoint.x-screenContext->scr_x, (int)aPoint.y-screenContext->scr_y, (cPoint.x-bPoint.x)*5, 0, 2*M_PI) ;
		cairo_set_source_rgb(screenContext->cr_on_screen, 0, 0, 0);
		cairo_stroke_preserve(screenContext->cr_on_screen);
		cairo_set_source_rgb(screenContext->cr_on_screen, 0.2, 0.2, 0.8);
		cairo_fill(screenContext->cr_on_screen);
		anEntry = anEntry->next;
	}

}
Пример #24
0
static void
append_arc (cairo_t *cr, double angle1, double angle2, gboolean negative)
{
  static GHashTable *arc_path_cache;
  Arc key;
  cairo_path_t *arc;

  memset (&key, 0, sizeof (Arc));
  key.angle1 = angle1;
  key.angle2 = angle2;
  key.negative = negative;

  if (arc_path_cache == NULL)
    arc_path_cache = g_hash_table_new_full ((GHashFunc)arc_path_hash,
                                            (GEqualFunc)arc_path_equal,
                                            g_free, (GDestroyNotify)cairo_path_destroy);

  arc = g_hash_table_lookup (arc_path_cache, &key);
  if (arc == NULL)
    {
      cairo_surface_t *surface;
      cairo_t *tmp;

      surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32, 1, 1);
      tmp = cairo_create (surface);

      if (negative)
        cairo_arc_negative (tmp, 0.0, 0.0, 1.0, angle1, angle2);
      else
        cairo_arc (tmp, 0.0, 0.0, 1.0, angle1, angle2);

      arc = fixup_path (cairo_copy_path (tmp));
      g_hash_table_insert (arc_path_cache, g_memdup (&key, sizeof (key)), arc);

      cairo_destroy (tmp);
      cairo_surface_destroy (surface);
    }

  cairo_append_path (cr, arc);
}
Пример #25
0
static gboolean sc_shape_draw(GtkWidget*widget, cairo_t*cr)
{

    SCShape*shape=SC_SHAPE(widget);

    int width=gtk_widget_get_allocated_width(widget);
    int height =gtk_widget_get_allocated_height(widget);


    gdk_cairo_set_source_rgba(cr,&shape->color);
    cairo_set_line_width(cr,shape->line_width);

    cairo_save(cr);
    gtk_cairo_transform_to_window(cr, widget,shape->event_window);


    cairo_translate(cr,(double)shape->rectangle.x,(double)shape->rectangle.y);

    if((shape->rectangle.width!=0 && shape->rectangle.height!=0))
        cairo_scale(cr,(shape->rectangle.width),(shape->rectangle.height));

    gdk_cairo_set_source_rgba(cr,&shape->color);

    if(shape->shape_type==SHAPE_RECT){    
        cairo_rectangle(cr,0,0,1,1);

    }else if(shape->shape_type==SHAPE_CIRCLE){
    
    cairo_arc(cr,0.5,0.5,0.5,0,2*M_PI);
    
    }

    cairo_restore(cr);
    cairo_stroke(cr);


    return FALSE;


}
Пример #26
0
static cairo_test_status_t
draw (cairo_t *cr, int width, int height)
{
    cairo_surface_t *mask;
    cairo_pattern_t *pattern;
    cairo_t *cr2;

    cairo_set_source_rgb (cr, 0, 0, 1.0);
    cairo_paint (cr);

    mask = cairo_surface_create_similar (cairo_get_group_target (cr),
				         CAIRO_CONTENT_ALPHA,
					 width, height);
    cr2 = cairo_create (mask);
    cairo_surface_destroy (mask);

    cairo_save (cr2); {
	cairo_set_operator (cr2, CAIRO_OPERATOR_CLEAR);
	cairo_paint (cr2);
    } cairo_restore (cr2);

    pattern = cairo_pattern_create_linear (0, 0, width, height);
    cairo_pattern_add_color_stop_rgba (pattern, 0.00, 0., 0., 0., 0.);
    cairo_pattern_add_color_stop_rgba (pattern, 0.25, 1., 1., 1., 1.);
    cairo_pattern_add_color_stop_rgba (pattern, 0.50, 1., 1., 1., .5);
    cairo_pattern_add_color_stop_rgba (pattern, 0.75, 1., 1., 1., 1.);
    cairo_pattern_add_color_stop_rgba (pattern, 1.00, 0., 0., 0., 0.);
    cairo_set_source (cr2, pattern);
    cairo_pattern_destroy (pattern);

    cairo_arc (cr2, 0.5 * width, 0.5 * height, 0.4 * height, 0, 2 * M_PI);
    cairo_stroke (cr2);

    cairo_set_source_rgb (cr, 1.0, 0, 0);
    cairo_mask_surface (cr, cairo_get_target (cr2), 0, 0);
    cairo_destroy (cr2);

    return CAIRO_TEST_SUCCESS;
}
Пример #27
0
static void
redraw_handler(struct widget *widget, void *data)
{
	static const double r = 10.0;
	struct clickdot *clickdot = data;
	cairo_surface_t *surface;
	cairo_t *cr;
	struct rectangle allocation;

	widget_get_allocation(clickdot->widget, &allocation);

	surface = window_get_surface(clickdot->window);

	cr = cairo_create(surface);
	cairo_set_operator(cr, CAIRO_OPERATOR_SOURCE);
	cairo_rectangle(cr,
			allocation.x,
			allocation.y,
			allocation.width,
			allocation.height);
	cairo_set_source_rgba(cr, 0, 0, 0, 0.8);
	cairo_fill(cr);

	draw_line(clickdot, cr, &allocation);

	cairo_translate(cr, clickdot->dot.x + 0.5, clickdot->dot.y + 0.5);
	cairo_set_line_width(cr, 1.0);
	cairo_set_source_rgb(cr, 0.1, 0.9, 0.9);
	cairo_move_to(cr, 0.0, -r);
	cairo_line_to(cr, 0.0, r);
	cairo_move_to(cr, -r, 0.0);
	cairo_line_to(cr, r, 0.0);
	cairo_arc(cr, 0.0, 0.0, r, 0.0, 2.0 * M_PI);
	cairo_stroke(cr);

	cairo_destroy(cr);

	cairo_surface_destroy(surface);
}
Пример #28
0
static cairo_test_status_t
draw (cairo_t *cr, int width, int height)
{
    /* An overly complex way of drawing a blue circle onto a red
     * background, to trigger the bug. */
    cairo_set_source_rgb (cr, 1, 0, 0); /* red */
    cairo_paint (cr);

    cairo_arc (cr,
	       SIZE / 2, SIZE / 2,
	       SIZE / 2 - PAD,
	       0, 2 * M_PI);
    cairo_clip (cr);

    cairo_push_group (cr);
    cairo_set_source_rgb (cr, 0, 0, 1); /* blue */
    cairo_paint (cr);
    cairo_pop_group_to_source (cr);
    cairo_paint (cr);

    return CAIRO_TEST_SUCCESS;
}
Пример #29
0
static void
draw_symbol (cairo_t *cr)
{
    double dash[] = {6, 3};

    cairo_rectangle (cr, -25, -25, 50, 50);
    cairo_stroke (cr);

    cairo_move_to (cr, 0, -25);
    cairo_curve_to (cr, 12.5, -12.5, 12.5, -12.5, 0, 0);
    cairo_curve_to (cr, -12.5, 12.5, -12.5, 12.5, 0, 25);
    cairo_curve_to (cr, 12.5, 12.5, 12.5, 12.5, 0, 0);
    cairo_stroke (cr);

    cairo_save (cr);
    cairo_set_dash (cr, dash, ARRAY_LENGTH (dash), 0.);
    cairo_move_to (cr, 0, 0);
    cairo_arc (cr, 0, 0, 12.5, 0, 3 * M_PI / 2);
    cairo_close_path (cr);
    cairo_stroke (cr);
    cairo_restore (cr);
}
Пример #30
0
static gboolean on_expose_event(GtkWidget *widget,
		GdkEventExpose *event,
		gpointer data)
{
/*该类型包含当前设备的状态,包括坐标以及形状等*/
  g_print("hi,expose_event\n");
  cairo_t *cr;

  cr = gdk_cairo_create(widget->window);
  //cairo_set_source_surface(cr, image, orig_x, orig_y);
  /*这里的orig_x和orig_y可以控制图片的显示位置*/
  cairo_set_source_surface(cr, image, 50, 50);
  
  /*剪切一个圆形区域仅绘制这个区域*/
cairo_arc (cr, 128.0, 128.0, 76.8, 0, 8);//8应该替换成2*M_PI
cairo_clip (cr);
cairo_new_path (cr); 
  cairo_paint(cr);
  cairo_destroy(cr);

  return FALSE;
}