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 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214
| WITH Gtk.Main ; USE Gtk.Main ;
WITH Gtk.Window ; USE Gtk.Window ;
WITH Gtk.Enums ; USE Gtk.Enums ;
WITH Gtk.Button ; USE Gtk.Button ;
WITH Gtk.Alignment ; USE Gtk.Alignment ;
WITH Gtk.Box ; USE Gtk.Box ;
WITH Gtk.Gentry; USE Gtk.Gentry;
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 ;
PROCEDURE dessine_avec_cairo IS
-----------------------
-- VARIABLES -- |
----------------------------------------------------------
win : Gtk_window ;
Btn1, Btn2 ,Btn3 : Gtk_Button ;
alignG, alignM ,alignD : Gtk_Alignment ;
Boite : Gtk_VBox ;
Boutons : Gtk_HBox ;
saisie : Gtk_Entry ;
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 P2_Callback IS NEW Gtk.Handlers.User_Callback(Gtk_Widget_Record , Boolean);
USE P2_Callback ;
----------------------------------------------------------
-- Handlers (or callbacks) |
----------------------------------------------------------
procedure Stop_Program(Emetteur : access Gtk_Widget_Record'class)
is
PRAGMA Unreferenced (Emetteur);
begin
Main_Quit;
end Stop_Program ;
function draw_callback (the_Widget : access Gtk_Widget_Record'Class ;
cairo_t : Cairo_Context ) return boolean
is
width : Allocation_Int ;
height : Allocation_Int ;
color : Gdk_Color ;
begin
Queue_Draw (Widget => zone_dessin);
width := Get_Allocation_Width (Widget => the_Widget) ;
height := Get_Allocation_Height (Widget => the_Widget) ;
Arc
(Cr => cairo_t ,
Xc => 2.0 ,
Yc => 2.0 ,
Radius => 2.0 ,
Angle1 => 0.0 ,
Angle2 => 2.0 * 3.14 );
color := Get_Fg
(Style => Get_Style (Widget => the_Widget) ,
State_Type => State_Active) ;
Set_Source_Color
(Cr => cairo_t ,
Color => color);
Set_Fill_Rule
(Cr => cairo_t ,
Fill_Rule => Cairo_Fill_Rule_Winding);
return false ;
end draw_callback ;
-------------------------------------------------
BEGIN
Init ;
----------------
-- NEW -- |
-------------------------------------------------
Gtk_New(zone_dessin);
Gtk_New(win);
Gtk_New(saisie);
Gtk_New(Btn1, "Bouton 1") ;
Gtk_New(Btn2, "Bouton 2") ;
Gtk_New(Btn3, "Bouton 3") ;
Gtk_New(alignG,0.0,1.0,1.0,1.0);
Gtk_New(alignM,0.5,1.0,1.0,1.0);
Gtk_New(alignD,1.0,1.0,1.0,1.0);
Gtk_New_VBox
(Boite, homogeneous => false, Spacing => 0) ;
Gtk_New_HBox
(Boutons, homogeneous => false, Spacing => 0) ;
---------------------------------
-- Add |
---------------------------------
alignG.add(Btn1) ;
alignM.add(Btn2) ;
alignD.add(Btn3) ;
win.Add(Boite);
------------------------------------------
-- Connect |
------------------------------------------
Connect(Widget => win ,
Name => "destroy" ,
Cb => Stop_Program'access);
Connect(Widget => zone_dessin ,
Name => "draw" ,
Cb => draw_callback'access);
------------------------------------------
-- Design Window |
------------------------------------------
Size_Allocate
(Widget => zone_dessin ,
Allocation => ( X => 0 , Y => 0 , Width => 150 , Height => 150 ) ) ;
Pack_Start
(In_Box => Boite ,
Child => zone_dessin ,
Expand => true ,
Fill => true );
Pack_Start
(In_Box => Boite ,
Child => saisie ,
Expand => false );
Pack_Start
(In_Box => Boite ,
Child => Boutons ,
Expand => true ,
Fill => true );
Pack_Start
(In_Box => Boutons ,
Child => alignG ,
Expand => true ,
Fill => true );
Pack_Start
(In_Box => Boutons ,
Child => alignM ,
Expand => true ,
Fill => true );
Pack_Start
(In_Box => Boutons ,
Child => alignD ,
Expand => true ,
Fill => true );
win.Set_Default_Size(600,500) ;
win.set_position(Win_Pos_Mouse) ;
win.set_opacity(0.7) ;
win.Show_all ;
Main ;
END dessine_avec_cairo ; |
Partager