Re: unable to get the dotted and continuous lines
Lokesh Chakka <[email protected]>
| Newsgroups | gmane.comp.lib.cairo |
|---|---|
| Message-ID | <CACh--sj=-85uTNH27LohgCE9SmzZBDonMnaq9qKBr2qYfYa2oA@mail.gmail.com> |
ravi, thanks for the information. it worked for me. Thanks & Regards -- Lokesh. On Fri, Aug 8, 2014 at 11:53 AM, RAVI NANJUNDAPPA <[email protected]> wrote: > hi Lokesh, > > I tried your sample code in my machine. > I guess the program is fine except that I changed the rgb values in > draw_graphlins() > from > cairo_set_source_rgb( cr, 0.8, 0.8, 0.8 ); > to > cairo_set_source_rgb( cr, 0, 0, 0 ); > After this change, am able to see the grid + blue line. > > So, I feel it was due to rgb values which was making the grid lines not > recognized by eyes. > Please check this out in your environment too. > > Thanks and Best Regards, > N Ravi > > ------- Original Message ------- > Sender : Lokesh Chakka<[email protected]> > Date : Aug 08, 2014 10:15 (GMT+05:30) > Title : [cairo] unable to get the dotted and continuous lines > > > > Hello, > > > 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. > > > I referred the program pen dashes at Basic drawing in Cairo > > > 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. > > > #include <cairo.h> > #include <gtk/gtk.h> > #include <math.h> > #include <inttypes.h> > > > uint16_t drawing_width = 300, drawing_height = 200; > > uint16_t evaluate_y_coordinate( uint16_t y ) > { > return drawing_height - y; > } > > static void draw_graphlines( cairo_t *cr ) > { > const uint16_t stepx = drawing_width/10, stepy = drawing_height/5; > const double dashes[] = { 5, 10 }; > uint32_t i; > > cairo_set_source_rgb( cr, 0.8, 0.8, 0.8 ); > cairo_set_line_width( cr, 0.5 ); > cairo_set_dash ( cr, dashes, 2, 0 ); > for( i=0; i<drawing_width; i+=stepx ) > {//vertical lines > cairo_move_to( cr, i, evaluate_y_coordinate( 0 ) ); > cairo_line_to( cr, i, evaluate_y_coordinate( drawing_height ) ); > } > for( i=0; i<drawing_height; i+=stepy ) > {// horizontal lines > cairo_move_to( cr, 0, evaluate_y_coordinate( i ) ); > cairo_line_to( cr, drawing_width, evaluate_y_coordinate( i ) ); > } > cairo_stroke(cr); > cairo_set_dash ( cr, dashes, 0, 0 ); > } > > > static void do_drawing( GtkWidget *widget, cairo_t *cr, char *data ) > { > GdkRGBA rgba; > > draw_graphlines( cr ); > cairo_set_source_rgb( cr, 0, 0, 1 ); > cairo_set_line_width( cr, 2.0 ); > cairo_move_to( cr, 10, 10 ); > cairo_line_to( cr, 100, 100 ); > cairo_stroke(cr); > } > > > int main (int argc, char *argv[]) > { > GtkWidget *window; > GtkWidget *darea; > > gtk_init(&argc, &argv); > > window = gtk_window_new(GTK_WINDOW_ > TOPLEVEL); > > darea = gtk_drawing_area_new(); > gtk_container_add(GTK_CONTAINER(window), darea); > > g_signal_connect(G_OBJECT(darea), "draw", G_CALLBACK(do_drawing), NULL); > g_signal_connect(G_OBJECT(window), "destroy", G_CALLBACK(gtk_main_quit), > NULL); > > gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER); > gtk_window_set_default_size(GTK_WINDOW(window), drawing_width, > drawing_height ); > gtk_window_set_title(GTK_WINDOW(window), "Fill & stroke"); > > gtk_widget_show_all(window); > > gtk_main(); > > return 0; > } > > > > > Thanks & Regards > -- > Lokesh > -- cairo mailing list [email protected] http://lists.cairographics.org/mailman/listinfo/cairo