-- $Date: 2004/03/08 10:42:19 $
-- $Revision: 1.9 $
-- $Author: jcrocholl $
-- $Hash: 3303d2f44eb17ec92e4591674b324870 $

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

with Enum_Strings; use Enum_Strings;

package body Boxes.Note_Heads is

   -- Constructor for instances.
   function Create
     (Note_Head : in Note_Head_Enum-- The initial note head.
      Filled    : in Boolean;        -- The initial filled.
      Position  : in Integer)        -- The initial position.
     return Note_Head_Box_Access     -- The newly created note head box.
   is
      Result : Note_Head_Box_Access := new Note_Head_Box;
   begin
      Result.Note_Head := Note_Head;
      Result.Filled := Filled;
      Result.Position := Position;
      return Result;
   end Create;

   -- Accessor to read the note head of a note head box.
   function Get_Note_Head
     (This : access Note_Head_Box-- The note head box to read from.
     return Note_Head_Enum is      -- The note head of that note head box.
   begin
      return This.Note_Head;
   end Get_Note_Head;

   -- Accessor to read the filled of a note head box.
   function Get_Filled
     (This : access Note_Head_Box-- The note head box to read from.
     return Boolean is             -- The filled of that note head box.
   begin
      return This.Filled;
   end Get_Filled;

   -- Accessor to read the position of a note head box.
   function Get_Position
     (This : access Note_Head_Box-- The note head box to read from.
     return Integer is             -- The position of that note head box.
   begin
      return This.Position;
   end Get_Position;

   -- Mutator to update the stem side of a note head box.
   procedure Set_Stem_Side
     (This      : access Note_Head_Box-- The note head box to be updated.
      Stem_Side : in Stem_Side_Enum) is -- The new stem side of that note head box.
   begin
      This.Stem_Side := Stem_Side;
   end Set_Stem_Side;

   -- Accessor to read the stem side of a note head box.
   function Get_Stem_Side
     (This : access Note_Head_Box-- The note head box to read from.
     return Stem_Side_Enum is      -- The stem side of that note head box.
   begin
      return This.Stem_Side;
   end Get_Stem_Side;

   function Get_Name
     (This : access Note_Head_Box-- The note head box object instance.
     return String is              -- The glyph name.
   begin
      if This.Note_Head = Normal and not This.Filled
      then return "hollow";
      else return To_XML(This.Note_Head'Img);
      end if;
   end Get_Name;

   procedure Layout
     (This : access Note_Head_Box;  -- The note head box object instance.
      Font : access Font_Loader) is -- Use this font loader.
   begin
      -- This.Stem_Side := Left;
      This.Glyph := Load_Glyph(Font,
        "noteheads/stem-" & To_XML(This.Stem_Side'Img) & "/" &
        Get_Name(This));
      This.Bounds := Get_Bounds(This.Glyph);
   end Layout;

   procedure Add_Dots
     (This   : access Note_Head_Box-- The note head box object instance.
      Font   : access Font_Loader;   -- Use this font loader.
      Dots   : in Positive;          -- Number of dots.
      Offset : in Vector)            -- Position of first dot.
   is
      Cursor : Vector := Offset;
   begin
      This.Dot_Offset := Offset;
      for Index in 1 .. Dots loop
         This.Dots(Index) := Load_Glyph(Font, "dots/augment");
         This.Bounds := Max(This.Bounds, Get_Bounds(This.Dots(Index)) + Cursor);
         Cursor := Cursor + (50.0, 0.0);
      end loop;
   end Add_Dots;

   procedure Print
     (This   : access Note_Head_Box;      -- The note head box object instance.
      To     : access Printer'Class-- Render to this printer.
      Center : in Vector)                 -- Center of container.
   is
      Cursor : Vector;
   begin
      Print(To, This.Glyph, Center + This.Center);

      Cursor := This.Dot_Offset;
      for Index in Dot_Range loop
         exit when This.Dots(Index) = null;
         Print(To, This.Dots(Index), Center + This.Center + Cursor);
         Cursor := Cursor + (50.0, 0.0);
      end loop;
   end Print;

end Boxes.Note_Heads;