static cairo_test_status_t
draw (cairo_t *cr, int width, int height)
{
    cairo_set_source_rgb (cr, 0, 0, 0);
    cairo_paint (cr);

    cairo_set_antialias(cr, CAIRO_ANTIALIAS_NONE);
    cairo_move_to(cr, 85, -465);
    cairo_line_to(cr, 3, 4.1);
    cairo_line_to(cr, -145, -25);
    cairo_close_path(cr);
    cairo_clip(cr);

    cairo_set_antialias(cr, CAIRO_ANTIALIAS_DEFAULT);
    cairo_move_to(cr, -139, -524);
    cairo_line_to(cr, 78, 44);
    cairo_line_to(cr, -229, -10);
    cairo_close_path(cr);
    cairo_clip(cr);

    cairo_set_source_rgb (cr, 1, 1, 1);
    cairo_paint (cr);

    return CAIRO_TEST_SUCCESS;
}
static void _draw_round_box(cairo_t* cr, gint width, gint height, double radius)
{
    cairo_set_antialias(cr, CAIRO_ANTIALIAS_BEST);

    double xc = radius, yc = radius;
    double angle1 = 180.0  * (M_PI/180.0);  /* angles are specified */
    double angle2 = 270.0 * (M_PI/180.0);  /* in radians           */

    cairo_arc (cr, xc, yc, radius, angle1, angle2);

    xc = width - radius;
    angle1 = 270.0 * (M_PI/180.0);
    angle2 = 360.0 * (M_PI/180.0);
    cairo_arc (cr, xc, yc, radius, angle1, angle2);

    yc = height - radius;
    angle1 = 0.0 * (M_PI/180.0);
    angle2 = 90.0 * (M_PI/180.0);
    cairo_arc (cr, xc, yc, radius, angle1, angle2);

    xc = radius;
    angle1 = 90.0 * (M_PI/180.0);
    angle2 = 180.0 * (M_PI/180.0);
    cairo_arc (cr, xc, yc, radius, angle1, angle2);

    cairo_set_antialias(cr, CAIRO_ANTIALIAS_DEFAULT);
    cairo_close_path(cr);
}
Exemple #3
0
/**
 * Handle GTK expose-events
 */
static void expose_event(GtkWidget* widget, GdkEventExpose* event, Console* console)
{
  console->width = widget->allocation.width;
  console->height = widget->allocation.height;

  cairo_t* context = gdk_cairo_create(widget->window);

  /* background */
  cairo_set_source_rgba(context, 1, 1, 1, console->transparency);
  cairo_paint(context);

  /* options */
  if (console->transparency < 1.0) {
    cairo_set_operator(context, CAIRO_OPERATOR_SOURCE); 
  }
  if (console->antialias_graphics == true) {
    cairo_set_antialias(context, CAIRO_ANTIALIAS_DEFAULT);
  } else {
    cairo_set_antialias(context, CAIRO_ANTIALIAS_NONE);
  }

  /* draw the console */
  cairo_save(context);
  Console_expose(console, context); 
  cairo_restore(context);
  
  cairo_destroy(context);
}
void
gfxContext::SetAntialiasMode(AntialiasMode mode)
{
    if (mode == MODE_ALIASED) {
        cairo_set_antialias(mCairo, CAIRO_ANTIALIAS_NONE);
    } else if (mode == MODE_COVERAGE) {
        cairo_set_antialias(mCairo, CAIRO_ANTIALIAS_DEFAULT);
    }
}
Exemple #5
0
static void clip_1 (cairo_t *cr)
{
    cairo_set_antialias (cr, CAIRO_ANTIALIAS_NONE);

    cairo_arc (cr, 100, 100, 125, 0, 2*M_PI);
    cairo_clip (cr);

    cairo_set_antialias (cr, CAIRO_ANTIALIAS_DEFAULT);
}
Exemple #6
0
static void clip_3 (cairo_t *cr)
{
    cairo_set_antialias (cr, CAIRO_ANTIALIAS_NONE);

    cairo_rectangle (cr, 40.25, 60.25, 120, 80);
    cairo_rectangle (cr, 60.25, 40.25, 80, 120);
    cairo_clip (cr);

    cairo_set_antialias (cr, CAIRO_ANTIALIAS_DEFAULT);
}
Exemple #7
0
/**
 * uber_heat_map_render_fast:
 * @graph: A #UberGraph.
 *
 * XXX
 *
 * Returns: None.
 * Side effects: None.
 */
static void
uber_heat_map_render_fast (UberGraph    *graph, /* IN */
                           cairo_t      *cr,    /* IN */
                           GdkRectangle *area,  /* IN */
                           guint         epoch, /* IN */
                           gfloat        each)  /* IN */
{
    UberGraphPrivate *priv;
    gfloat height;
    gint i;

    g_return_if_fail(UBER_IS_HEAT_MAP(graph));

    priv = graph->priv;
    /*
     * XXX: Temporarily draw nice little squares.
     */
#define COUNT 10
    height = area->height / (gfloat)COUNT;
    for (i = 0; i < COUNT; i++) {
        cairo_rectangle(cr,
                        area->x + area->width - each,
                        area->y + (i * height),
                        each,
                        height);
        cairo_set_source_rgba(cr, .1, .1, .8,
                              g_random_double_range(0., 1.));
        cairo_set_antialias(cr, CAIRO_ANTIALIAS_NONE);
        cairo_fill(cr);
    }
}
Exemple #8
0
void
gra2cairo_set_antialias(struct gra2cairo_local *local, int antialias)
{
  if (local->cairo == NULL)
    return;

  local->antialias = antialias;

  switch (antialias) {
  case ANTIALIAS_TYPE_NONE:
    antialias = CAIRO_ANTIALIAS_NONE;
    break;
  case ANTIALIAS_TYPE_DEFAULT:
    antialias = CAIRO_ANTIALIAS_DEFAULT;
    break;
  case ANTIALIAS_TYPE_GRAY:
    antialias = CAIRO_ANTIALIAS_GRAY;
    break;
  case ANTIALIAS_TYPE_SUBPIXEL:
    antialias = CAIRO_ANTIALIAS_SUBPIXEL;
    break;
  }

  cairo_set_antialias(local->cairo, antialias);
}
Exemple #9
0
static cairo_test_status_t
draw (cairo_t *cr, int width, int height)
{
    static const struct point {
	double x;
	double y;
    } xy[] = {
	{ 627.016212, 221.749777 },
	{ 756.120787, 221.749777 },
	{ 756.120787, 557.602766 },
	{ 626.952721, 557.602766 },
	{ 626.548456, 493.315729 },
    };
    unsigned int i;

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

    for (i = 0; i < sizeof (xy) / sizeof (xy[0]); i++)
	cairo_line_to (cr, xy[i].x, xy[i].y);

    cairo_set_source_rgb (cr, 1, 0, 0);
    cairo_fill_preserve (cr);

    cairo_set_antialias (cr, CAIRO_ANTIALIAS_NONE);
    cairo_set_source_rgb (cr, 0, 1, 0);
    cairo_fill (cr);

    return CAIRO_TEST_SUCCESS;
}
Exemple #10
0
void on_composited_changed ( GdkScreen *screen,
			   gpointer   user_data)
{
  GromitData *data = (GromitData *) user_data;

  if(data->debug)
    g_printerr("DEBUG: got composited-changed event\n");

  data->composited = gdk_screen_is_composited (data->screen);

  if(data->composited)
    {
      // undo shape
      gtk_widget_shape_combine_region(data->win, NULL);
      // re-apply transparency
      gtk_window_set_opacity(GTK_WINDOW(data->win), 0.75);
    }

  // set anti-aliasing
  GHashTableIter it;
  gpointer value;
  g_hash_table_iter_init (&it, data->tool_config);
  while (g_hash_table_iter_next (&it, NULL, &value)) 
    {
      GromitPaintContext *context = value;
      cairo_set_antialias(context->paint_ctx, data->composited ? CAIRO_ANTIALIAS_DEFAULT : CAIRO_ANTIALIAS_NONE);
    }
      

  GdkRectangle rect = {0, 0, data->width, data->height};
  gdk_window_invalidate_rect(gtk_widget_get_window(data->win), &rect, 0); 
}
Exemple #11
0
static void
toggle_antialias(GtkWidget *menuitem, gpointer data) {
 VGUI.antialias=gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM(menuitem)) ? CAIRO_ANTIALIAS_DEFAULT : CAIRO_ANTIALIAS_NONE;
 cairo_set_antialias(VGUI.cr,VGUI.antialias);
 Keyboard_Buffer_push('');	// queue a redraw command
 notify_input();
}
Exemple #12
0
static Rboolean
BM_Open(pDevDesc dd, pX11Desc xd, int width, int height)
{
    cairo_status_t res;
    if (xd->type == PNG || xd->type == JPEG ||
	xd->type == TIFF || xd->type == BMP) {
	xd->cs = cairo_image_surface_create(CAIRO_FORMAT_ARGB32,
					    xd->windowWidth,
					    xd->windowHeight);
    } else if (xd->type == PNGdirect) {
	xd->cs = cairo_image_surface_create(CAIRO_FORMAT_ARGB32,
					    xd->windowWidth,
					    xd->windowHeight);
    } else if(xd->type == SVG || xd->type == PDF || xd->type == PS) {
	/* leave creation to BM_Newpage */
	return TRUE;
    } else
	error(_("unimplemented cairo-based device"));

    res = cairo_surface_status(xd->cs);
    if (res != CAIRO_STATUS_SUCCESS) {
	warning("cairo error '%s'", cairo_status_to_string(res));
	return FALSE;
    }
    xd->cc = cairo_create(xd->cs);
    res = cairo_status(xd->cc);
    if (res != CAIRO_STATUS_SUCCESS) {
	warning("cairo error '%s'", cairo_status_to_string(res));
	return FALSE;
    }
    cairo_set_operator(xd->cc, CAIRO_OPERATOR_OVER);
    cairo_reset_clip(xd->cc);
    cairo_set_antialias(xd->cc, xd->antialias);
    return TRUE;
}
/**
 * uber_line_graph_stylize_line:
 * @graph: A #UberLineGraph.
 *
 * XXX
 *
 * Returns: None.
 * Side effects: None.
 */
static void
uber_line_graph_stylize_line (UberLineGraph *graph, /* IN */
                              LineInfo      *info,  /* IN */
                              cairo_t       *cr)    /* IN */
{
	UberLineGraphPrivate *priv;

	g_return_if_fail(UBER_IS_LINE_GRAPH(graph));
	g_return_if_fail(info != NULL);

	priv = graph->priv;
	if (info->dashes) {
		cairo_set_dash(cr, info->dashes, info->num_dashes, info->dash_offset);
	} else {
		cairo_set_dash(cr, NULL, 0, 0);
	}
	cairo_set_line_cap(cr, CAIRO_LINE_CAP_ROUND);
	cairo_set_line_join(cr, CAIRO_LINE_JOIN_ROUND);
	cairo_set_line_width(cr, info->width);
	cairo_set_antialias(cr, priv->antialias);
	cairo_set_source_rgba(cr,
	                      info->color.red / 65535.,
	                      info->color.green / 65535.,
	                      info->color.blue / 65535.,
	                      info->alpha);
}
Exemple #14
0
static Bool
canvas_configure_event(GtkWidget *widget, GdkEventConfigure *event) {
 GtkAllocation allocation;
 cairo_text_extents_t te;
 //printf("canvas_configure_event\n");

 gtk_widget_get_allocation(widget,&allocation);
 vdevice.sizeX = 1;
 vdevice.sizeY = 1;
 vdevice.minVx = vdevice.minVy = 0;
 vdevice.maxVx = vdevice.sizeSx = allocation.width;
 vdevice.maxVy = vdevice.sizeSy = allocation.height;
 vdevice.depth = 3;
 if (VGUI.cr!=NULL) {
  cairo_destroy (VGUI.cr);
  cairo_surface_destroy (VGUI.surface);
 }
 VGUI.surface= gdk_window_create_similar_surface (gtk_widget_get_window (VGUI.canvas),
  CAIRO_CONTENT_COLOR, vdevice.sizeSx, vdevice.sizeSy);
 VGUI.cr = cairo_create(VGUI.surface);
 cairo_set_antialias(VGUI.cr,VGUI.antialias);
 my_set_font(VGUI.cr);
 cairo_text_extents (VGUI.cr, "A", &te);
 vdevice.hheight = te.height;
 vdevice.hwidth = te.x_advance;
 VGUI.line_width=1;
 //printf("vdevice address=%ld, vdevice.sizeSx=%d, vdevice.sizeSy=%d\n", (long)&vdevice,  vdevice.sizeSx, vdevice.sizeSy);
 Keyboard_Buffer_push('');	// queue a redraw command
 notify_input();
 return TRUE;
}
Exemple #15
0
static gboolean on_badge_draw(ClutterCanvas* canvas, cairo_t* cr,
        gint width, gint height, ClutterActor* badge)
{
    g_debug("%s: %d,%d, ", __func__, width, height);

    cairo_set_antialias(cr, CAIRO_ANTIALIAS_BEST);
    cairo_set_operator(cr, CAIRO_OPERATOR_OVER);
    cairo_set_source_rgba(cr, 0.0, 0.0, 0.0, 1.0);
    cairo_paint_with_alpha(cr, 0.0);

    cairo_arc(cr, width/2, height/2, MIN(width, height)/2.0, 0, 2*M_PI);
    cairo_close_path(cr);

    cairo_set_operator(cr, CAIRO_OPERATOR_OVER);
    cairo_set_source_rgba(cr, 0.6, 0.2, 0.2, 0.8);
    cairo_fill(cr);

    char title[20];
    snprintf(title, 19, "%d", GPOINTER_TO_INT(g_object_get_qdata(G_OBJECT(badge), moses_overview_window_clone_order())));
    cairo_set_source_rgba(cr, 1.0, 1.0, 1.0, 1.0);

    cairo_select_font_face(cr, "fantasy", CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_BOLD);
    cairo_set_font_size(cr, 28.0);

    cairo_text_extents_t te;
    cairo_text_extents(cr, title, &te);
    cairo_move_to(cr, (width - te.width)/2.0 - te.x_bearing, (height - te.height)/2.0 - te.y_bearing);
    cairo_show_text(cr, title);

    return TRUE;
}
Exemple #16
0
static cairo_test_status_t
fill (cairo_t *cr, int width, int height)
{
    int i, j;

    /* Fill background white */
    cairo_set_source_rgb (cr, 1, 1, 1);
    cairo_paint (cr);

    /* Draw in black */
    cairo_set_source_rgb (cr, 0, 0, 0);

    cairo_translate (cr, PAD, PAD);
    cairo_set_antialias (cr, CAIRO_ANTIALIAS_NONE);

    for (i = 0; i < POINTS; i++)
	for (j = 0; j < POINTS; j++) {
	    cairo_save (cr);
	    cairo_rectangle (cr, 2 * i + i * STEP, 2 * j + j * STEP, 1, 1);
	    cairo_clip (cr);
	    cairo_rectangle (cr, 2 * i, 2 * j, 2, 2);
	    cairo_fill (cr);
	    cairo_restore (cr);
	}

    return CAIRO_TEST_SUCCESS;
}
Exemple #17
0
Fichier : cawc.c Projet : Roger/caw
static PyObject * 
_cairo_create(PyObject *self, PyObject *args)
{
    xcb_connection_t *connection;
    xcb_visualtype_t *visual;
    xcb_window_t window;
    cairo_surface_t * surface;
    cairo_t * cairo;
    int width, height;

    if (!PyArg_ParseTuple(args, "lIlii", &connection, &window, &visual, &width, &height))
        return NULL;

    surface = cairo_xcb_surface_create(connection,
            window,
            visual,
            width,
            height);

    cairo = cairo_create(surface);
    cairo_set_antialias(cairo, CAIRO_ANTIALIAS_NONE);
    cairo_surface_destroy(surface);

    return Py_BuildValue("l", cairo);
}
static VALUE
cr_set_antialias(VALUE self, VALUE antialias)
{
  cairo_set_antialias(_SELF, RVAL2CRANTIALIAS (antialias));
  cr_check_status(_SELF);
  return self;
}
Exemple #19
0
static cairo_test_status_t
draw (cairo_t *cr, int width, int height)
{
    int i, j;
    cairo_surface_t *surface;

    surface = cairo_image_surface_create_for_data ((unsigned char *) &black_pixel,
						   CAIRO_FORMAT_ARGB32,
						   1, 1, 4);

    /* Fill background white */
    cairo_set_source_rgb (cr, 1, 1, 1);
    cairo_paint (cr);

    /* Draw in black */
    cairo_set_source_rgb (cr, 0, 0, 0);

    cairo_translate (cr, PAD, PAD);
    cairo_set_antialias (cr, CAIRO_ANTIALIAS_NONE);

    for (i = 0; i < POINTS; i++)
	for (j = 0; j < POINTS; j++) {
	    cairo_set_source_surface (cr, surface,
				      2 * i + i * STEP, 2 * j + j * STEP);
	    cairo_pattern_set_filter (cairo_get_source (cr),
				      CAIRO_FILTER_NEAREST);
	    cairo_paint (cr);
	}

    cairo_surface_destroy (surface);

    return CAIRO_TEST_SUCCESS;
}
void GraphicsContext::drawConvexPolygon(size_t npoints, const FloatPoint* points, bool shouldAntialias)
{
    if (paintingDisabled())
        return;

    if (npoints <= 1)
        return;

    cairo_t* cr = m_data->cr;

    cairo_save(cr);
    cairo_set_antialias(cr, shouldAntialias ? CAIRO_ANTIALIAS_DEFAULT : CAIRO_ANTIALIAS_NONE);
    cairo_move_to(cr, points[0].x(), points[0].y());
    for (size_t i = 1; i < npoints; i++)
        cairo_line_to(cr, points[i].x(), points[i].y());
    cairo_close_path(cr);

    if (fillColor().alpha()) {
        setColor(cr, fillColor());
        cairo_set_fill_rule(cr, CAIRO_FILL_RULE_EVEN_ODD);
        cairo_fill_preserve(cr);
    }

    if (strokeStyle() != NoStroke) {
        setColor(cr, strokeColor());
        cairo_set_line_width(cr, strokeThickness());
        cairo_stroke(cr);
    }

    cairo_new_path(cr);
    cairo_restore(cr);
}
void GraphicsContext::drawConvexPolygon(size_t npoints, const FloatPoint* points, bool shouldAntialias)
{
    if (paintingDisabled())
        return;

    if (npoints <= 1)
        return;

    cairo_t* cr = platformContext()->cr();

    cairo_save(cr);
    cairo_set_antialias(cr, shouldAntialias ? CAIRO_ANTIALIAS_DEFAULT : CAIRO_ANTIALIAS_NONE);
    addConvexPolygonToContext(cr, npoints, points);

    if (fillColor().alpha()) {
        setSourceRGBAFromColor(cr, fillColor());
        cairo_set_fill_rule(cr, CAIRO_FILL_RULE_EVEN_ODD);
        cairo_fill_preserve(cr);
    }

    if (strokeStyle() != NoStroke) {
        setSourceRGBAFromColor(cr, strokeColor());
        cairo_set_line_width(cr, strokeThickness());
        cairo_stroke(cr);
    } else
        cairo_new_path(cr);

    cairo_restore(cr);
}
Exemple #22
0
static int cairo_set_antialias_l( lua_State* L )
{
  lua_cairo_t* lc = lua_cairo_check( L, 1 );

  cairo_set_antialias( lc->cairo, luaL_checkoption( L, 2, "default", cairo_antialias_lst ) );

  return( 0 );
}
Exemple #23
0
static inline void _SetUpHyperLinkUnderlining(const CNFORenderer* r, cairo_t* cr)
{
	if(r->GetHilightHyperLinks() && r->GetUnderlineHyperLinks())
	{
		cairo_set_line_width(cr, 1);
		cairo_set_antialias(cr, CAIRO_ANTIALIAS_NONE); // looks better
	}
}
Exemple #24
0
int
ca_setup_rectangles(caskbench_context_t *ctx)
{
    cairo_t *cr = ctx->cairo_cr;

    cairo_set_antialias (cr, CAIRO_ANTIALIAS_DEFAULT);
    cairo_set_line_width (cr, 1);
    return 1;
}
Exemple #25
0
void
a1_curve (cairo_perf_t *perf, cairo_t *cr, int width, int height)
{
    cairo_set_source_rgb (cr, 1., 1., 1.);
    cairo_set_antialias (cr, CAIRO_ANTIALIAS_NONE);

    cairo_perf_run (perf, "a1-curve-stroked", do_curve_stroke, NULL);
    cairo_perf_run (perf, "a1-curve-filled", do_curve_fill, NULL);
}
Exemple #26
0
static void
gth_image_rotator_draw (GthImageViewerTool *base,
			cairo_t            *cr)
{
	GthImageRotator *self = GTH_IMAGE_ROTATOR (base);
	GtkAllocation    allocation;

	cairo_save (cr);

  	/* background */

	/*
	GtkStyleContext *style_context;
	GdkRGBA          color;
	style_context = gtk_widget_get_style_context (GTK_WIDGET (self->priv->viewer));
	gtk_style_context_get_background_color (style_context,
						gtk_widget_get_state (GTK_WIDGET (self->priv->viewer)),
						&color);
	gdk_cairo_set_source_rgba (cr, &color);
	*/

	gtk_widget_get_allocation (GTK_WIDGET (self->priv->viewer), &allocation);
	cairo_rectangle (cr, 0, 0, allocation.width, allocation.height);

  	cairo_set_source_rgba (cr,
  			       self->priv->background_color.red,
  			       self->priv->background_color.green,
  			       self->priv->background_color.blue,
  			       self->priv->background_color.alpha);
	cairo_fill (cr);
	cairo_restore (cr);

	if (self->priv->preview_image == NULL)
		return;

	paint_image (self, cr);
	paint_darker_background (self, cr);
	paint_grid (self, cr);

	if (self->priv->dragging) {
		GdkPoint center;

		cairo_save (cr);
		cairo_set_antialias (cr, CAIRO_ANTIALIAS_DEFAULT);
		cairo_set_source_rgb (cr, 1.0, 1.0, 1.0);
		cairo_restore (cr);

		center.x = self->priv->center.x * self->priv->preview_zoom + self->priv->preview_image_area.x;
		center.y = self->priv->center.y * self->priv->preview_zoom + self->priv->preview_image_area.y;
		paint_point (self, cr, &center);

		/* used for debugging purposes
		paint_point (self, cr, &self->priv->drag_p1);
		paint_point (self, cr, &self->priv->drag_p2);
		*/
	}
}
void ofCairoRenderer::setup(string _filename, Type _type, bool multiPage_, bool b3D_, ofRectangle _viewport){
	if( _viewport.width == 0 || _viewport.height == 0 ){
		_viewport.set(0, 0, ofGetWidth(), ofGetHeight());
	}
	
	filename = _filename;
	type = _type;
	streamBuffer.clear();

	if(type == FROM_FILE_EXTENSION){
		string ext = ofFilePath::getFileExt(filename);
		if(ofToLower(ext)=="svg"){
			type = SVG;
		}else if(ofToLower(ext)=="pdf"){
			type = PDF;
		}else{ // default to image
			type = IMAGE;
		}
	}

	switch(type){
	case PDF:
		if(filename==""){
			surface = cairo_pdf_surface_create_for_stream(&ofCairoRenderer::stream_function,this,_viewport.width, _viewport.height);
		}else{
			surface = cairo_pdf_surface_create(ofToDataPath(filename).c_str(),_viewport.width, _viewport.height);
		}
		break;
	case SVG:
		if(filename==""){
			surface = cairo_svg_surface_create_for_stream(&ofCairoRenderer::stream_function,this,_viewport.width, _viewport.height);
		}else{
			surface = cairo_svg_surface_create(ofToDataPath(filename).c_str(),_viewport.width, _viewport.height);
		}
		break;
	case IMAGE:
		imageBuffer.allocate(_viewport.width, _viewport.height, 4);
		surface = cairo_image_surface_create_for_data(imageBuffer.getPixels(),CAIRO_FORMAT_ARGB32,_viewport.width, _viewport.height,_viewport.width*4);
		break;
	case FROM_FILE_EXTENSION:
		ofLogFatalError("ofCairoRenderer") << "Type not determined from file extension!";
		break;
	default:
		ofLogError("ofCairoRenderer") << "Unknown type encountered!";
		break;
	}

	cr = cairo_create(surface);
	cairo_set_antialias(cr,CAIRO_ANTIALIAS_SUBPIXEL);
	viewportRect = _viewport;
	viewport(viewportRect);
	page = 0;
	b3D = b3D_;
	multiPage = multiPage_;
	setStyle(ofGetStyle());
}
Exemple #28
0
int 
main(int argc, char** argv) {
   
   cairo_surface_t *sfc;
   cairo_t *ctx;
   
   int x, y;
   struct timespec ts = {0, 500000000};
   
   int running;

   x = y = 0;
   sfc = cairo_create_x11_surface(&x, &y);
   ctx = cairo_create(sfc);
   cairo_set_antialias(ctx, CAIRO_ANTIALIAS_NONE);

   mesh_t* m = mesh_create(x, y);

   for (running = 1; running;) {

      cairo_push_group(ctx);
      
         cairo_set_source_rgb(ctx, 0.1, 0.1, 0.1);
         cairo_paint(ctx);
         
         mesh_draw(ctx, m);

      cairo_pop_group_to_source(ctx);
      cairo_paint(ctx);

      cairo_surface_flush(sfc);

      int event=0;
      switch (event=cairo_check_event(sfc, 0)) {
         case 0xff53:   // right cursor
            break;

         case 0xff51:   // left cursor
            break;

         case 0xff1b:   // Esc
         case -1:       // left mouse button
            running = 0;
            break;
      }

      nanosleep(&ts, NULL);
   }

   mesh_free(m);

   cairo_destroy(ctx);
   cairo_close_x11_surface(sfc);

   return 0;
}
void GraphicsContext::setPlatformShouldAntialias(bool enable)
{
    if (paintingDisabled())
        return;

    // When true, use the default Cairo backend antialias mode (usually this
    // enables standard 'grayscale' antialiasing); false to explicitly disable
    // antialiasing. This is the same strategy as used in drawConvexPolygon().
    cairo_set_antialias(platformContext()->cr(), enable ? CAIRO_ANTIALIAS_DEFAULT : CAIRO_ANTIALIAS_NONE);
}
/*!
  \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);
		}
	}