Re: GtkDrawingArea size

On 03/08/2012 01:54 AM, Tadej BorovÅak wrote:

2012/3/7 Christopher Howard <christopher howard frigidcode com>:
Hello again. So, I recently started a project to create a certain board
game (in C) using gtk+, and I just started learning gtk+. I was planning
to draw the board graphics, pieces, etc. all into one GtkDrawingArea.
So, how do I fix the size of the drawing area so it doesn't get larger
or smaller than my graphics?

I would add a wrapper GtkAlignment around my drawing area, set it's
xalign and yalign propertes to 0.5, it's xscale and yscale to 0, pack
GtkDrawingArea inside it and fix it's size using

Have a look at this simple app:

#include <gtk/gtk.h>

#define WIDTH  300
#define HEIGHT 400

static gboolean
cb_draw (GtkWidget      *w,
         GdkEventExpose *e)
  cairo_t *cr = gdk_cairo_create (e->window);
  cairo_set_source_rgb (cr, 1.0, 1.0, 0.0);
  cairo_paint (cr);
  cairo_destroy (cr);

  return TRUE;

main (int    argc,
      char **argv)
  GtkWidget *window,

  gtk_init (&argc, &argv);

  window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
  g_signal_connect (window, "destroy", gtk_main_quit, NULL);

  align = gtk_alignment_new (0.5, 0.5, 0, 0);
  gtk_container_add (GTK_CONTAINER (window), align);

  area = gtk_drawing_area_new ();
  gtk_widget_set_size_request (area, WIDTH, HEIGHT);
  g_signal_connect (area, "expose-event", G_CALLBACK (cb_draw), NULL);
  gtk_container_add (GTK_CONTAINER (align), area);

  gtk_widget_show_all (window);

  gtk_main ();

  return 0;


Thanks for the help. Is there a way to turn off the small resizing
graphic that appears at the bottom right of the window? (It looks like
three small diagonal lines.) Even if this did not actually prevent
resizing it would make sense in my case not to have it showing.


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]