Home   |   Guides and Tutorials   |   What's New?   |   Comments   |   About
 

GtkArrow - Arrow Widget

by Brent Fox
Last Modified: Wednesday, 19-May-2004 11:54:17 EDT

Introduction
    The GtkArrow widget draws allows triangular arrows to be drawn on the screen. They can face north, west, south, and east and can be shaded in a variety of ways.
Screenshot



Source Code
Source code for this example is also available in the file arrow.c
/*
 *File name: arrow.c
 */

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

/*-- This function allows the program to exit properly when the window is closed --*/
gint destroyapp (GtkWidget *widget, gpointer gdata)
{
  g_print ("Quitting...\n");
  gtk_main_quit();
  return (FALSE);
}


int main (int argc, char *argv[])
{
  /*-- Declare the GTK Widgets used in the program --*/
  GtkWidget *window;
  GtkWidget *arrow1;
  GtkWidget *arrow2;
  GtkWidget *arrow3;
  GtkWidget *arrow4;
  GtkWidget *hbox;
  
  /*--  Initialize GTK --*/
  gtk_init (&argc, &argv);

  /*-- Create the new window --*/
  window = gtk_window_new(GTK_WINDOW_TOPLEVEL);

  /*-- Create the hbox --*/
  hbox = gtk_hbox_new(FALSE, 0);

  /*-- Create the arrow with a label --*/
  arrow1 = gtk_arrow_new(GTK_ARROW_UP, GTK_SHADOW_OUT);
  arrow2 = gtk_arrow_new(GTK_ARROW_DOWN, GTK_SHADOW_OUT);
  arrow3 = gtk_arrow_new(GTK_ARROW_LEFT, GTK_SHADOW_OUT);    
  arrow4 = gtk_arrow_new(GTK_ARROW_RIGHT, GTK_SHADOW_OUT);

  /*-- Connect the window to the destroyapp function  --*/
  gtk_signal_connect(GTK_OBJECT(window), "delete_event", GTK_SIGNAL_FUNC(destroyapp), NULL);

  /*-- Pack all the radio buttons into the hbox --*/
  gtk_box_pack_start(GTK_BOX(hbox), arrow1, FALSE, FALSE, 15);
  gtk_box_pack_start(GTK_BOX(hbox), arrow2, FALSE, FALSE, 15);
  gtk_box_pack_start(GTK_BOX(hbox), arrow3, FALSE, FALSE, 15);
  gtk_box_pack_start(GTK_BOX(hbox), arrow4, FALSE, FALSE, 15);  

  /*-- Add the hbox to the window --*/
  gtk_container_add(GTK_CONTAINER(window), hbox);

  /*-- Add a border to the window to give the button a little room --*/
  gtk_container_border_width (GTK_CONTAINER (window), 15);

  /*-- Display the widgets --*/
  gtk_widget_show(arrow1);
  gtk_widget_show(arrow2);
  gtk_widget_show(arrow3);
  gtk_widget_show(arrow4);
  gtk_widget_show(hbox);
  gtk_widget_show(window);

  /*-- Start the GTK event loop --*/
  gtk_main();

  /*-- Return 0 if exit is successful --*/
  return 0;
}
Compile the Source Code
gcc -Wall -g arrow.c -o arrow `gtk-config --cflags` `gtk-config --libs`

Execute the Program
./arrow

What's Related


All Rights Reserved Linux Headquarters © 2000-2007
Linux is a registered trademark of Linus Torvalds
All logos are registered trademarks of their respective owners
Last modified: Wednesday, May 19, 2004