1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148
| WITH Gtk.Main ; USE Gtk.Main ;
WITH Gtk.Window ; USE Gtk.Window ;
WITH Gtk.Enums ; USE Gtk.Enums ;
WITH Gtk.Widget ; USE Gtk.Widget ;
with Gtk.Handlers;
WITH Gtk.Drawing_Area; USE Gtk.Drawing_Area;
WITH Cairo ; USE Cairo ;
WITH Gdk.Color ; USE Gdk.Color ;
WITH Gdk.Cairo ; USE Gdk.Cairo ;
WITH Gtk.Style ; USE Gtk.Style ;
WITH Glib ; USE Glib ;
WITH Gdk.Event ; USE Gdk.Event ;
WITH Gdk.Rectangle ; USE Gdk.Rectangle ;
WITH Gdk ; USE Gdk ;
PROCEDURE dessine_avec_cairo IS
-----------------------
-- VARIABLES -- |
----------------------------------------------------------
win : Gtk_window ;
zone_dessin : Gtk_Drawing_Area ;
----------------------------------------------------------
--Instanciation package(s) for connexion
----------------------------------------------------------
PACKAGE P_Callback IS NEW Gtk.Handlers.Callback(Gtk_Widget_Record);
USE P_Callback ;
PACKAGE Configured IS NEW Gtk.Handlers.Return_Callback
(Widget_Type => Gtk_Drawing_Area_Record,
Return_Type => Boolean);
----------------------------------------------------------
-- Handlers (or callbacks) |
----------------------------------------------------------
procedure Stop_Program(Emetteur : access Gtk_Widget_Record'class)
is
PRAGMA Unreferenced (Emetteur);
begin
Main_Quit;
end Stop_Program ;
function Expose_Event
(the_Widget : access Gtk_Drawing_Area_Record'Class;
Event : Gdk.Event.Gdk_Event )
return Boolean
is
Area : Gdk_Rectangle := Get_Area (Event);
Region : Gdk_Rectangle;
Context : Cairo_Context ;
Win2 : Gdk_Window ;
drawable : Gdk_Drawable ;
begin
Win2 := Get_Window (Widget => the_Widget) ;
drawable := Gdk_Drawable (Win2) ;-- transtypage
Context := Create ( drawable ) ;
Region.Width := Area.Width / 2;
Region.Height := Area.Height / 2;
Region.X := Region.Width / 2;
Region.Y := Region.Height / 2;
Set_Source_Rgb(Context, 1.0, 0.0, 0.0);
Cairo.Rectangle(Cr => Context, X => GDouble(Region.X), Y => GDouble(Region.Y), Width => GDouble(Region.Width), Height => GDouble(Region.Height));
Cairo.Fill_Preserve(Context);
Set_Line_Width(Context, 1.0);
Set_Source_Rgb(Context, 0.0, 0.0, 1.0);
Cairo.Stroke(Context);
return false ;
end expose_event;
-------------------------------------------------
BEGIN
Init ;
----------------
-- NEW -- |
-------------------------------------------------
Gtk_New(zone_dessin);
Gtk_New(win);
---------------------------------
-- Add |
---------------------------------
win.Add( zone_dessin );
------------------------------------------
-- Connect |
------------------------------------------
Connect(Widget => win ,
Name => "destroy" ,
Cb => Stop_Program'access);
Configured.Connect (Widget => zone_dessin,
Name => "expose_event",
Marsh => Configured.To_Marshaller
(Expose_Event'Access));
------------------------------------------
-- Design Window |
------------------------------------------
Size
(Drawing_Area => zone_dessin ,
Width => 100 ,
Height => 100 );
Size_Allocate
(Widget => zone_dessin ,
Allocation => ( X => 0 , Y => 0 , Width => 10 , Height => 10 ) ) ;
win.Set_Default_Size(600,500) ;
win.set_position(Win_Pos_Center) ;
win.set_opacity(0.7) ;
win.Show_all ;
Main ;
END dessine_avec_cairo ; |
Partager