agpl_1.0.0_b5da3320/src/tests/gtk/t028_drawing_area.adb

 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
--  Simple test for the drawing area without and with update

with Ada.Calendar;
with Ada.Numerics;
with Ada.Numerics.Elementary_Functions;
with Ada.Text_IO; use Ada.Text_IO;
with Agpl; use Agpl;
with Agpl.Drawing;
with Agpl.Gdk.Managed.Drawing_Area;
with Agpl.Trace;  use Agpl.Trace;

procedure T028_Drawing_Area is

   type Cross is new Drawing.Drawable with null record;
   overriding
   procedure Draw (This :        Cross;
                   D    : in out Drawing.Drawer'Class);

   procedure Draw (This :        Cross;
                   D    : in out Drawing.Drawer'Class)
   is
      pragma Unreferenced (This);
   begin
      D.Set_Color ((255, 0, 0), 0);
      D.Draw_Line (0.0, 0.0, 1.0, 1.0);
      D.Draw_Line (0.0, 1.0, 1.0, 0.0);
   end Draw;

   type Second is new Drawing.Drawable with null record;
   overriding
   procedure Draw (This :        Second;
                   D    : in out Drawing.Drawer'Class);

   procedure Draw (This :        Second;
                   D    : in out Drawing.Drawer'Class)
   is
      pragma Unreferenced (This);
      use Ada.Calendar;
      use Ada.Numerics;
      use Ada.Numerics.Elementary_Functions;

      Now    : constant Float := Float (Seconds (Clock));
      Offset : constant Float := Now - Float'Floor (Now);

   begin
      D.Set_Color ((0, 255, 0), 0);
      D.Draw_Line (0.0, 0.0, Sin (Offset * 2.0 * Pi), Cos (Offset * 2.0 * Pi));
   end Draw;

   X : Cross;
   Y : Second;
   Z : Second;

   Zh : Gdk.Managed.Drawing_Area.Handle :=
     Gdk.Managed.Drawing_Area.Show (Z, "Z");

begin
--     Set_Level (Debug);
--     Enable_Section (Agpl.Gdk.Managed.Log_Section);
--     Enable_Section (Agpl.Gdk.Managed.Det_Section);

   Gdk.Managed.Drawing_Area.Show (X, "X");
   Gdk.Managed.Drawing_Area.Show (Y, "Y");

   loop
      delay 0.01;
      Zh.Clear;
      Zh.Append (Z);
      Zh.Redraw;
   end loop;
exception
   when E : others =>
      Put_Line ("Main: " & Report (E));
end T028_Drawing_Area;