Fwd: GtkDrawingArea size request

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

Fwd: GtkDrawingArea size request

Rúben Rodrigues
Someone received my question?

Thanks


-------- Mensagem reencaminhada --------
Assunto:        GtkDrawingArea size request
Data:   Wed, 21 Jun 2017 10:08:15 +0100
De:     Rúben Rodrigues <[hidden email]><mailto:[hidden email]>
Para:   [hidden email]<mailto:[hidden email]> <[hidden email]><mailto:[hidden email]>



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]<https://www.avast.com/sig-email?utm_medium=email&utm_source=link&utm_campaign=sig-email&utm_content=emailclient>      Sem vírus. www.avast.com<https://www.avast.com/sig-email?utm_medium=email&utm_source=link&utm_campaign=sig-email&utm_content=emailclient>
_______________________________________________
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

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: [hidden email]
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 <[hidden email]><mailto:[hidden email]>
Para:   [hidden email]<mailto:[hidden email]> <[hidden email]><mailto:[hidden email]>



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]<https://www.avast.com/sig-email?utm_medium=email&utm_source=link&utm_campaign=sig-email&utm_content=emailclient>      Sem vírus. www.avast.com<https://www.avast.com/sig-email?utm_medium=email&utm_source=link&utm_campaign=sig-email&utm_content=emailclient>
_______________________________________________
gtk-app-devel-list mailing list
[hidden email]
https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list
_______________________________________________
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: Fwd: GtkDrawingArea size request

Chris Moller-3
In reply to this post by Rúben Rodrigues
There's no reason the drawing area code you're showing shouldn't work.  
The most obvious possibility is that the size of your enclosing widget
(GTK_BOX(gtk_builder_get_object(builder, "box30"))) isn't set right--the
default is that your drawing area will expand to fill its parent.

On 06/21/17 10:11, Rúben Rodrigues wrote:

> Someone received my question?
>
> Thanks
>
>
> -------- Mensagem reencaminhada --------
> Assunto:        GtkDrawingArea size request
> Data:   Wed, 21 Jun 2017 10:08:15 +0100
> De:     Rúben Rodrigues <[hidden email]><mailto:[hidden email]>
> Para:   [hidden email]<mailto:[hidden email]> <[hidden email]><mailto:[hidden email]>
>
>
>
> 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]<https://www.avast.com/sig-email?utm_medium=email&utm_source=link&utm_campaign=sig-email&utm_content=emailclient>      Sem vírus. www.avast.com<https://www.avast.com/sig-email?utm_medium=email&utm_source=link&utm_campaign=sig-email&utm_content=emailclient>
> _______________________________________________
> gtk-app-devel-list mailing list
> [hidden email]
> https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list

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