Re.: GtkDrawingArea size request

2017-06-22 Thread Rúben Rodrigues
Solved.

Someone have a example of how to create a custom widget with cairo in C?
Thanks

 Mensagem original 
Assunto: Fwd: GtkDrawingArea size request
De: Rúben Rodrigues
Para: gtk-app-devel-list@gnome.org
CC:

Someone received my question?

Thanks


 Mensagem reencaminhada 
Assunto:GtkDrawingArea size request
Data:   Wed, 21 Jun 2017 10:08:15 +0100
De: Rúben Rodrigues 
Para:   gtk-app-devel-list@gnome.org 




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;
}



[https://ipmcdn.avast.com/images/icons/icon-envelope-tick-round-orange-animated-no-repeat-v1.gif]
  Sem vírus. 
www.avast.com
___
gtk-app-devel-list mailing list
gtk-app-devel-list@gnome.org
https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list
___
gtk-app-devel-list mailing list
gtk-app-devel-list@gnome.org
https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list


Re: GtkDrawingArea size request

2017-06-22 Thread Eric Cashon via gtk-app-devel-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
gtk-app-devel-list@gnome.org
https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list