<div dir="ltr"><br clear="all"><div><div dir="ltr"><div dir="ltr"><div>Hello,<br><br></div>I newly started using Cairo. I am facing one problem with the Cairo
function calls. I want to first draw Cartesian grids using hyphens with
gray color and after that I want to plot a normal line in blue color.<br>
<br><div>I referred the program pen dashes at <a href="http://zetcode.com/gfx/cairo/basicdrawing/" target="_blank">Basic drawing in Cairo</a><br></div><br>But I am seeing only the blue color line. but not the Cartesian grids. Can some one help me by telling what mistake I am doing.<br>
<br><br>#include <cairo.h><br>#include <gtk/gtk.h><br>#include <math.h><br>#include <inttypes.h><br><br><br>uint16_t drawing_width = 300, drawing_height = 200;<br><br>uint16_t evaluate_y_coordinate( uint16_t y )<br>
{<br> return drawing_height - y;<br>}<br><br>static void draw_graphlines( cairo_t *cr )<br>{<br> const uint16_t stepx = drawing_width/10, stepy = drawing_height/5;<br> const double dashes[] = { 5, 10 };<br> uint32_t i;<br>
<br> cairo_set_source_rgb( cr, 0.8, 0.8, 0.8 );<br> cairo_set_line_width( cr, 0.5 );<br> cairo_set_dash ( cr, dashes, 2, 0 );<br> for( i=0; i<drawing_width; i+=stepx )<br> {//vertical lines<br> cairo_move_to( cr, i, evaluate_y_coordinate( 0 ) );<br>
cairo_line_to( cr, i, evaluate_y_coordinate( drawing_height ) );<br> }<br> for( i=0; i<drawing_height; i+=stepy )<br> {// horizontal lines<br> cairo_move_to( cr, 0, evaluate_y_coordinate( i ) );<br>
cairo_line_to( cr, drawing_width, evaluate_y_coordinate( i ) );<br> }<br> cairo_stroke(cr);<br> cairo_set_dash ( cr, dashes, 0, 0 );<br>}<br><br><br>static void do_drawing( GtkWidget *widget, cairo_t *cr, char *data )<br>
{<br> GdkRGBA rgba;<br><br> draw_graphlines( cr );<br> cairo_set_source_rgb( cr, 0, 0, 1 );<br> cairo_set_line_width( cr, 2.0 );<br> cairo_move_to( cr, 10, 10 );<br> cairo_line_to( cr, 100, 100 );<br> cairo_stroke(cr);<br>
}<br><br><br>int main (int argc, char *argv[])<br>{<br> GtkWidget *window;<br> GtkWidget *darea;<br> <br> gtk_init(&argc, &argv);<br><br> window = gtk_window_new(GTK_WINDOW_<div>TOPLEVEL);<br><br> darea = gtk_drawing_area_new();<br>
gtk_container_add(GTK_CONTAINER(window), darea);<br><br> g_signal_connect(G_OBJECT(darea), "draw", G_CALLBACK(do_drawing), NULL);<br> g_signal_connect(G_OBJECT(window), "destroy", G_CALLBACK(gtk_main_quit), NULL);<br>
<br> gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER);<br> gtk_window_set_default_size(GTK_WINDOW(window), drawing_width, drawing_height ); <br> gtk_window_set_title(GTK_WINDOW(window), "Fill & stroke");<br>
<br> gtk_widget_show_all(window);<br><br> gtk_main();<br><br> return 0;<br>}<br><br><div><div><br clear="all"><div><div dir="ltr">Thanks & Regards<br>--<br>Lokesh</div></div></div></div></div></div></div></div>
</div>