GtkDrawingArea size request

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

GtkDrawingArea size request

Rúben Rodrigues
Hi,

I create a drawing area to draw a circular gauge with cairo.

GtkWidget *drawing_area = gtk_drawing_area_new ();
     gtk_widget_set_size_request (drawing_area, 100, 100);
     gtk_box_pack_start (GTK_BOX(gtk_builder_get_object(builder,
"box30")),drawing_area,FALSE,TRUE,0);

The problem is that the drawing area is not 100x100 but the entire of
screen.

This is the callback function:



gboolean on_circular_gauge_draw(GtkWidget *widget, cairo_t *cr,
     gpointer user_data)
{

       int width, height;
       gint percentage, linewidth;

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


       linewidth = (MIN (width, height) / 2.0 * 30.0) / 100.0;

       cairo_set_source_rgba (cr, 1.0, 1.0, 1.0, 0.6);
       cairo_set_line_width (cr, linewidth);
       cairo_arc(cr, width/2.0, height/2.0,  MIN (width, height) / 2.0 -
linewidth, angle1, angle2);
       cairo_stroke (cr);

       cairo_set_source_rgba (cr, 0.0, 0.9, 0.0, 1.0);
       cairo_set_line_width (cr, linewidth);
       cairo_arc(cr, width/2.0, height/2.0, MIN (width, height) / 2.0  -
linewidth, 180.0  * (M_PI/180.0),315.0  * (M_PI/180.0) );
       cairo_stroke (cr);



   return FALSE;
}


---
Este e-mail foi verificado em termos de vírus pelo software antivírus Avast.
https://www.avast.com/antivirus

_______________________________________________
gtk-app-devel-list mailing list
[hidden email]
https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: GtkDrawingArea size request

Gtk+ - Apps Dev mailing list

 
Hi Ruben,

You might consider allowing the gauge to expand with the window size. This makes the gauge a lot more flexible. When drawing a gauge it is useful to get a general coordinate drawing on screen that you can check your gauge drawing with. Both cartesian coordinates and radial coordinates are useful to check your drawing. There is a general layout drawing in the following.

https://github.com/cecashon/OrderedSetVelociRaptor/blob/master/Misc/cairo_drawings/gears2.c

You can use set sizes if you want to also. To keep your drawing area window size a set size check your vexpand and hexpand properties. Make sure they are false. Try using a GtkGrid instead of a GtkBox. Put the drawing area in a scrolled window and put that in the grid.

I have done some work drawing gauges and have a couple packaged as widgets. There are also some drawings of clocks, gauges, gems and gears in the above github cairo_drawings folder. Some resize as circles and some as ellipses. They might be helpful getting something that you can test a gauge drawing with.

Eric

 


_______________________________________________
gtk-app-devel-list mailing list
[hidden email]
https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list
Loading...