-- $Date: 2004/03/08 10:42:42 $
-- $Revision: 1.7 $
-- $Author: jcrocholl $
-- $Hash: ef633e932414cfd224a0ffda79d0a992 $

-- This file was automatically created with ado.php.
-- Manual changes will be lost when it is updated.

with Integer_Strings; use Integer_Strings;
with Enum_Strings; use Enum_Strings;
with Messages; use Messages;

package body Boxes.Times is

   -- Constructor for instances.
   function Create
     (Time : in Time_Access-- The initial time.
     return Time_Box_Access  -- The newly created time box.
   is
      Result : Time_Box_Access := new Time_Box;
   begin
      Result.Time := Time;
      return Result;
   end Create;

   -- Accessor to read the time of a time box.
   function Get_Time
     (This : access Time_Box-- The time box to read from.
     return Time_Access is    -- The time of that time box.
   begin
      return This.Time;
   end Get_Time;

   procedure Layout
     (This : access Time_Box;       -- The time box object instance.
      Font : access Font_Loader) is -- Use this font loader.
   begin
      if not Quiet then Debug("preparing time signature layout"); end if;
      This.Upper_Center := (0.0, 0.0);
      This.Lower_Center := (0.0, 0.0);

      case Get_Symbol(This.Time) is
      when Normal =>
         if Get_Beats(This.Time) = 4 then
            This.Upper_Center.X := 30.0;
         end if;
         This.Upper_Center.Y := -100.0;
         This.Upper := Load_Glyph(Font, "times/upper/" & To_String(Get_Beats(This.Time)));

         if Get_Beat_Type(This.Time) = 4 then
            This.Lower_Center.X := 30.0;
         end if;
         This.Lower_Center.Y := 200.0;
         This.Lower := Load_Glyph(Font, "times/lower/" & To_String(Get_Beat_Type(This.Time)));

         This.Bounds := Max(
           Get_Bounds(This.Upper) + This.Upper_Center,
           Get_Bounds(This.Lower) + This.Lower_Center);
      when Common =>
         This.Lower := Load_Glyph(Font, "times/breve/breve");
         This.Bounds := Get_Bounds(This.Lower);
      when Cut =>
         This.Lower := Load_Glyph(Font, "times/breve/breve");
         This.Upper := Load_Glyph(Font, "times/breve/slash");

         This.Bounds := Max(
           Get_Bounds(This.Upper),
           Get_Bounds(This.Lower));
      when others =>
         Error("unsupported time signature symbol: " & To_XML(Get_Symbol(This.Time)'Img));
      end case;

      -- Debug("time bounds: " & To_String(This.Bounds));
   end Layout;

   procedure Print
     (This   : access Time_Box;           -- The time box object instance.
      To     : access Printer'Class-- Render to this printer.
      Center : in Vector) is              -- Center of container.
   begin
      if not Quiet then Debug("printing time signature"); end if;

      case Get_Symbol(This.Time) is
      when Normal =>
         Print(To, This.Upper, Center + This.Center + This.Upper_Center);
         Print(To, This.Lower, Center + This.Center + This.Lower_Center);
      when Common =>
         Print(To, This.Lower, Center + This.Center + This.Lower_Center);
      when Cut =>
         Print(To, This.Upper, Center + This.Center + This.Upper_Center);
         Print(To, This.Lower, Center + This.Center + This.Lower_Center);
      when others =>
         Error("unsupported time signature symbol: " & To_XML(Get_Symbol(This.Time)'Img));
      end case;

      Print_Bounds(This, To, Center);
   end Print;

end Boxes.Times;