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

Drawing a line related



Hello all ,

	Can someone help me to draw a simple line.

	Code is being attached.

/* example-start menu itemfactory.c */

#include <gtk/gtk.h>
#include <strings.h>


static GtkItemFactoryEntry menu_items[] = {
  { "/_session",         NULL,         NULL, 0, "<Branch>" },
  { "/session/_pause"},
  { "/session/_restart"},
  { "/session/_exit"},
  { "/_settings",      NULL,         NULL, 0, "<Branch>" },
  { "/settings/advanced",  NULL,         NULL, 0, NULL },
  { "/_help",         NULL,         NULL, 0, "<LastBranch>" },
  { "/_help/About",   NULL,         NULL, 0, NULL },
};


void get_main_menu( GtkWidget  *window,
                    GtkWidget **menubar )
{
  GtkItemFactory *item_factory;
  GtkAccelGroup *accel_group;
  gint nmenu_items = sizeof (menu_items) / sizeof (menu_items[0]);

  accel_group = gtk_accel_group_new ();

  /* This function initializes the item factory.
     Param 1: The type of menu - can be GTK_TYPE_MENU_BAR, GTK_TYPE_MENU,
              or GTK_TYPE_OPTION_MENU.
     Param 2: The path of the menu.
     Param 3: A pointer to a gtk_accel_group.  The item factory sets up
              the accelerator table while generating menus.
  */

  item_factory = gtk_item_factory_new (GTK_TYPE_MENU_BAR, "<main>", 
				       accel_group);

  /* This function generates the menu items. Pass the item factory,
     the number of items in the array, the array itself, and any
     callback data for the the menu items. */
  gtk_item_factory_create_items (item_factory, nmenu_items, menu_items, NULL);

  /* Attach the new accelerator group to the window. */
  gtk_window_add_accel_group (GTK_WINDOW (window), accel_group);

  if (menubar)
    /* Finally, return the actual menu bar created by the item factory. */ 
    *menubar = gtk_item_factory_get_widget (item_factory, "<main>");
}

int main( int argc,
          char *argv[] )
{
  GtkWidget *window;
  GtkWidget *drawing_area;
  GtkWidget *main_vbox;
  GtkWidget *vbox;
  GtkWidget *menubar;
  GdkDrawable *drawable;  
  GdkGC *gc;
    
  gtk_init (&argc, &argv);
  
  window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
  gtk_signal_connect (GTK_OBJECT (window), "destroy", 
		      GTK_SIGNAL_FUNC (gtk_main_quit), 
		      "WM destroy");
  gtk_window_set_title (GTK_WINDOW(window), "VioNotes");
  gtk_widget_set_usize (GTK_WIDGET(window), 500, 500);
  
  main_vbox = gtk_vbox_new (FALSE, 1);
  vbox = gtk_hbox_new(FALSE,0);

  gtk_container_border_width (GTK_CONTAINER (main_vbox), 1);
  gtk_container_add (GTK_CONTAINER (window), main_vbox);
  gtk_container_add (GTK_CONTAINER(window),vbox);

  get_main_menu (window, &menubar);
  gtk_box_pack_start (GTK_BOX (main_vbox), menubar, FALSE, TRUE, 0);
  /*    drawable = drawing_area->window;*/

  drawing_area = gtk_drawing_area_new();
   drawable = drawing_area->window;
  gtk_drawing_area_size(GTK_DRAWING_AREA(drawing_area),100,100);

  gtk_box_pack_start(GTK_BOX(vbox),drawing_area,TRUE,TRUE,0);
  
  gtk_widget_show (vbox);
  gtk_widget_show (drawing_area);
  gdk_draw_line(drawable,gc,10,10,50,50);
  gtk_widget_show_all(window);
  gtk_main ();
  
  return(0);
}
/* example-end */

















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