eagle_lander_1.2.0_578532c2/src/timeline.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
 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
-------------------------------------------------------------------------------
--                                                                           --
--                               Eagle Lander                                --
--                                                                           --
--         Copyright (C) 2015 Fabien Chouteau (chouteau@adacore.com)         --
--                                                                           --
--    Eagle Lander is free software: you can redistribute it and/or modify   --
--    it under the terms of the GNU General Public License as published by   --
--    the Free Software Foundation, either version 3 of the License, or      --
--    (at your option) any later version.                                    --
--                                                                           --
--    Eagle Lander is distributed in the hope that it will be useful,        --
--    but WITHOUT ANY WARRANTY; without even the implied warranty of         --
--    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the          --
--    GNU General Public License for more details.                           --
--                                                                           --
--    You should have received a copy of the GNU General Public License      --
--    along with Eagle Lander.  If not, see <http://www.gnu.org/licenses/>.  --
--                                                                           --
-------------------------------------------------------------------------------

with Ada.Containers.Vectors;
with Ada.Containers;
with Glib; use Glib;
with Ada.Numerics;

package body Timeline is

   package Situation_Vecs is new Ada.Containers.Vectors
     (Element_Type => Lander_Situation,
      Index_Type   => Positive);

   Vect : Situation_Vecs.Vector;

   ------------
   -- Lenght --
   ------------

   function Lenght return Simulation_Time is
   begin
      return Simulation_Time (Vect.Length);
   end Lenght;

   -------------
   -- Set_Now --
   -------------

   procedure Set_Now (Index : Simulation_Time) is
   begin
      Vect.Set_Length (Ada.Containers.Count_Type (Index));
   end Set_Now;

   -------------------
   -- Get_Situation --
   -------------------

   function Get_Situation (Index : Simulation_Time) return Lander_Situation is
   begin
      return Vect (Positive (Index));
   end Get_Situation;

   -------------------
   -- Set_Situation --
   -------------------

   procedure Set_Situation (Situ : Lander_Situation) is
   begin
      Vect.Append (Situ);
   end Set_Situation;

   ----------
   -- Init --
   ----------

   procedure Init
     (Self : in out Overview_Panel;
      Pos  :        Vector2D;
      Size :        Vector2D)
   is
   begin
      Self.Pos  := Pos;
      Self.Size := Size;
   end Init;

   ----------
   -- Draw --
   ----------

   procedure Draw (Self : in out Overview_Panel; Cr : Cairo_Context) is
      X           : constant         := -2000.0;
      Y           : constant         := 0.0;
      Height      : constant         := 5000.0;
      Width       : constant         := 12000.0;
      Margin      : constant Gdouble := (Self.Size.X * 0.02) / Self.Scale;
      Screen_Size : Vector2D         := Self.Inner_Frame_Size - Margin * 2.0;
   begin
      Self.Draw_Frame (Cr);

      if Screen_Size.X <= 0.0 then
         Screen_Size.X := 1.0;
      end if;
      if Screen_Size.Y <= 0.0 then
         Screen_Size.Y := 1.0;
      end if;

      Save (Cr);
      Translate (Cr, Self.Inner_Frame_Pos.X, Self.Inner_Frame_Pos.Y);
      Scale (Cr, Self.Scale, Self.Scale);

      Scale (Cr, 1.0, -1.0);
      Translate (Cr, Margin, -Screen_Size.Y - Margin);
      Scale (Cr, Screen_Size.X / Width, Screen_Size.Y / Height);
      Translate (Cr, -X, -Y);

      --  white Screen
      Set_Source_Rgb (Cr, 1.0, 1.0, 1.0);
      Rectangle (Cr, X, Y, Width, Height);
      Fill_Preserve (Cr);

      --  Create A Mask
      Clip (Cr);

      Set_Line_Width (Cr, Height / 50.0);

      Set_Source_Rgb (Cr, 1.0, 0.0, 0.0);
      Arc (Cr, 0.0, 0.0, Height / 20.0, 0.0, 2.0 * Ada.Numerics.Pi);
      Stroke (Cr);
      Arc (Cr, 0.0, 0.0, Height / 40.0, 0.0, 2.0 * Ada.Numerics.Pi);
      Fill (Cr);

      Set_Source_Rgb (Cr, 0.0, 0.0, 1.0);
      Arc
        (Cr,
         Gdouble (Lander.Get_Situation.Pos.X),
         Gdouble (Lander.Get_Situation.Pos.Y),
         Height / 20.0,
         0.0,
         2.0 * Ada.Numerics.Pi);
      Set_Line_Cap (Cr, Cairo_Line_Cap_Round);
      Stroke (Cr);
      Arc
        (Cr,
         Gdouble (Lander.Get_Situation.Pos.X),
         Gdouble (Lander.Get_Situation.Pos.Y),
         Height / 40.0,
         0.0,
         2.0 * Ada.Numerics.Pi);
      Fill (Cr);

      for Situ of Vect loop
         Line_To (Cr, Gdouble (Situ.Pos.X), Gdouble (Situ.Pos.Y));
      end loop;
      Set_Source_Rgb (Cr, 0.0, 1.0, 0.0);
      Stroke (Cr);
      Restore (Cr);
   end Draw;

end Timeline;