rulers.pp 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. {
  2. $Id$
  3. Converted from C to Pascal by Artur Bac with liitle additions by me
  4. <arturbac@@poczta.onet.pl>
  5. Reda Poland
  6. }
  7. {$MODE objfpc}
  8. {$H+}
  9. {$S+}
  10. {$HINTS ON}
  11. {$ifdef win32}
  12. {$define extdecl := stdcall;}
  13. {$APPTYPE GUI}
  14. {$endif}
  15. {$ifdef unix}
  16. {$define extdecl := cdecl;}
  17. {$endif}
  18. Program Rulers;
  19. Uses glib,gdk,gtk;
  20. Const
  21. XSIZE = 600;
  22. YSIZE = 400;
  23. // This routine gets control when the close button is clicked
  24. Function close_application( widget : PGtkWidget ;
  25. event : PGdkEvent;
  26. data : gpointer) : boolean; cdecl;
  27. Begin
  28. gtk_main_quit();
  29. close_application := false; //if something go wrong we will know that gtk didn't quit
  30. End;
  31. // The main routine
  32. Var
  33. window ,table, area, hrule, vrule : PGtkWidget;
  34. Begin
  35. // Initialize GTK and create the main window
  36. gtk_set_locale ();
  37. gtk_init( @argc, @argv );
  38. gtk_rc_init;
  39. window := gtk_window_new( GTK_WINDOW_TOPLEVEL );
  40. gtk_signal_connect (GTK_OBJECT (window), 'delete_event',
  41. GTK_SIGNAL_FUNC( @close_application ), NIL);
  42. gtk_container_set_border_width (GTK_CONTAINER (window), 10);
  43. // Create a table for placing the ruler and the drawing area
  44. table := gtk_table_new( 3, 2, FALSE );
  45. gtk_container_add( GTK_CONTAINER(window), table );
  46. area := gtk_drawing_area_new();
  47. gtk_drawing_area_size( Gtk_Drawing_Area (area), XSIZE, YSIZE );
  48. gtk_table_attach( GTK_TABLE(table), area, 1, 2, 1, 2,
  49. GTK_EXPAND or GTK_FILL, GTK_FILL, 0, 0 );
  50. gtk_widget_set_events( area, GDK_POINTER_MOTION_MASK or
  51. GDK_POINTER_MOTION_HINT_MASK );
  52. { The horizontal ruler goes on top. As the mouse moves across the
  53. * drawing area, a motion_notify_event is passed to the
  54. * appropriate event handler for the ruler. }
  55. hrule := gtk_hruler_new();
  56. gtk_ruler_set_metric( GTK_RULER(hrule), GTK_PIXELS );
  57. gtk_ruler_set_range( GTK_RULER(hrule), 7, 13, 0, 20 );
  58. gtk_signal_connect_object( GTK_OBJECT(area), 'motion_notify_event',
  59. Gtk_Signal_Func (GTK_WIDGET_CLASS(GTK_OBJECT(hrule)^.klass)
  60. ^.motion_notify_event),
  61. GTK_OBJECT(hrule));
  62. gtk_table_attach( GTK_TABLE(table), hrule, 1, 2, 0, 1,
  63. GTK_EXPAND or GTK_SHRINK or GTK_FILL, GTK_FILL, 0, 0 );
  64. {* The vertical ruler goes on the left. As the mouse moves across
  65. * the drawing area, a motion_notify_event is passed to the
  66. * appropriate event handler for the ruler. */}
  67. vrule := gtk_vruler_new();
  68. gtk_ruler_set_metric( GTK_RULER(vrule), GTK_PIXELS );
  69. gtk_ruler_set_range( GTK_RULER(vrule), 0, YSIZE, 10, YSIZE );
  70. gtk_signal_connect_object( GTK_OBJECT(area), 'motion_notify_event',
  71. Gtk_Signal_Func
  72. (GTK_WIDGET_CLASS(GTK_OBJECT(vrule)^.klass)
  73. ^.motion_notify_event),
  74. GTK_OBJECT(vrule) );
  75. gtk_table_attach( GTK_TABLE(table), vrule, 0, 1, 1, 2,
  76. GTK_FILL, GTK_EXPAND or GTK_SHRINK or GTK_FILL, 0, 0 );
  77. // Now show everything changed a little by Me
  78. {gtk_widget_show( area );
  79. gtk_widget_show( hrule );
  80. gtk_widget_show( vrule );
  81. gtk_widget_show( table );}
  82. gtk_widget_show_all( window ); //This will show all childs of window
  83. gtk_main();
  84. End.