1. limited with Game_Views; 
  2.  
  3. private with Ada.Containers.Doubly_Linked_Lists; 
  4.  
  5. package Widgets.Menubars is 
  6.  
  7.     -- A Menubar spans the top of a Window and contains pulldown menus. 
  8.     type Menubar is new Widget and Visibility_Listener with private; 
  9.     type A_Menubar is access all Menubar'Class; 
  10.  
  11.     -- Creates a new Menubar within 'view' with widget id 'id'. Each window has 
  12.     -- at most one menu bar. 
  13.     function Create_Menubar( view : not null access Game_Views.Game_View'Class; 
  14.                              id   : String ) return A_Menubar; 
  15.     pragma Precondition( id'Length > 0 ); 
  16.     pragma Postcondition( Create_Menubar'Result /= null ); 
  17.  
  18.     -- Adds a pulldown menu to the menu bar. 'pulldown' will be consumed. 
  19.     procedure Add( this : access Menubar; pulldown : in out A_Widget ); 
  20.     pragma Precondition( pulldown /= null ); 
  21.     pragma Postcondition( pulldown = null ); 
  22.  
  23.     -- Notifies the menu bar that a pulldown menu has been hidden. This is 
  24.     -- intended to be called by a Pulldown_Menu when it closes. 
  25.     procedure Pulldown_Hidden( this : access Menubar; pulldown : not null A_Widget ); 
  26.  
  27. private 
  28.  
  29.     -- A Menu record encapsulates a pulldown menu. It contains the text and 
  30.     -- location of the clickable area that will open its pulldown menu. It's 
  31.     -- essentially a light-weight radio button that shows and hides its 
  32.     -- pulldown menu. 
  33.     type Menu is 
  34.         record 
  35.             pulldown : A_Widget := null; 
  36.             text     : Unbounded_String; 
  37.             x        : Integer := 0; 
  38.             width    : Integer := 0; 
  39.             hover    : Boolean := False; 
  40.             active   : Boolean := False; 
  41.         end record; 
  42.     type A_Menu is access all Menu; 
  43.  
  44.     -- Deletes the Menu record. 
  45.     procedure Delete( m : in out A_Menu ); 
  46.     pragma Postcondition( m = null ); 
  47.  
  48.     -- provides a list of Menu records. 
  49.     package Menu_Lists is new Ada.Containers.Doubly_Linked_Lists( A_Menu, "=" ); 
  50.     use Menu_Lists; 
  51.  
  52.     ---------------------------------------------------------------------------- 
  53.  
  54.     type Menubar is new Widget and Visibility_Listener with 
  55.         record 
  56.             menus    : Menu_Lists.List;     -- list of menus 
  57.             dragging : Boolean := False;    -- mouse is dragging over the menu bar 
  58.         end record; 
  59.  
  60.     procedure Construct( this : access Menubar; 
  61.                          view : not null access Game_Views.Game_View'Class; 
  62.                          id   : String ); 
  63.     pragma Precondition( id'Length > 0 ); 
  64.  
  65.     procedure Delete( this : in out Menubar ); 
  66.  
  67.     procedure Draw_Content( this : access Menubar; dc : Drawing_Context ); 
  68.  
  69.     -- Updates a pulldown's Menu record when the pulldown becomes invisible. 
  70.     procedure Handle_Action( this   : access Menubar; 
  71.                              action : A_Visibility_Action ); 
  72.  
  73.     procedure Handle_Exit( this : access Menubar ); 
  74.  
  75.     procedure Handle_Mouse_Move( this : access Menubar; 
  76.                                  evt  : not null A_Mouse_Event ); 
  77.  
  78.     procedure Handle_Mouse_Press( this : access Menubar; 
  79.                                   evt  : not null A_Mouse_Button_Event ); 
  80.  
  81.     procedure Handle_Mouse_Release( this : access Menubar; 
  82.                                     evt  : not null A_Mouse_Button_Event ); 
  83.  
  84.     -- Applies the menu bar's special layout before setting its parent. 
  85.     procedure Set_Parent( this : access Menubar; parent : A_Widget ); 
  86.  
  87. end Widgets.Menubars;