rulers.pp 3.4 KB

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