1. -- 
  2. -- Copyright (c) 2012 Kevin Wellwood 
  3. -- All rights reserved. 
  4. -- 
  5. -- This source code is distributed under the Modified BSD License. For terms and 
  6. -- conditions, see license.txt. 
  7. -- 
  8.  
  9. package Widgets.Containers.Panels is 
  10.  
  11.     -- A Panel is a simple container for multiple widgets. It can optionally 
  12.     -- have a border, a background color to display when its children don't fill 
  13.     -- its content area, and a title bar on the top, with an icon and/or text. 
  14.     -- The Panel's title bar is displayed automatically if the Panel has either 
  15.     -- an icon or title text. 
  16.     -- 
  17.     -- Panels are useful for visually grouping objects together so that a group 
  18.     -- of them can be moved or shown/hidden simultaneously by performing the 
  19.     -- operation once on their Panel container. 
  20.     -- 
  21.     -- The Panel class is also extended for more specialized uses as a modal 
  22.     -- dialog and a context-sensitive popup. 
  23.     type Panel is new Container with private; 
  24.     type A_Panel is access all Panel'Class; 
  25.  
  26.     -- Creates a new Panel within 'view' with id 'id'. If either 'title' or 
  27.     -- 'icon' are passed a value, the panel will be displayed with a title bar 
  28.     -- at the top, showing its icon and/or title text using left justification. 
  29.     function Create_Panel( view  : not null access Game_Views.Game_View'Class; 
  30.                            id    : String; 
  31.                            title : String := ""; 
  32.                            icon  : String := "" ) return A_Panel; 
  33.     pragma Precondition( id'Length > 0 ); 
  34.     pragma Postcondition( Create_Panel'Result /= null ); 
  35.  
  36.     -- Adds a child widget to the Panel. 'child' will be consumed. 
  37.     procedure Add_Widget( this : access Panel; child : in out A_Widget ); 
  38.     pragma Precondition( child /= null ); 
  39.     pragma Postcondition( child = null ); 
  40.  
  41.     -- Removes and deletes all child widgets within the panel. 
  42.     procedure Clear_Widgets( this : access Panel ); 
  43.  
  44.     -- Returns the panel's title string. 
  45.     function Get_Title( this : access Panel ) return String; 
  46.  
  47.     -- Sets the panel's border style. 
  48.     procedure Set_Border( this : access Panel; border : Border_Type ); 
  49.  
  50.     -- Sets the color to be used for a specific purpose when drawing the panel. 
  51.     procedure Set_Color( this    : access Panel; 
  52.                          purpose : Color_Purpose; 
  53.                          color   : Allegro_Color ); 
  54.  
  55.     -- Sets the icon to display in the Panel's title bar, by filename. If 'icon' 
  56.     -- is an empty string, the icon will be removed. The display state of the 
  57.     -- panel's title bar will be automatically updated as necessary. 
  58.     procedure Set_Icon( this : access Panel; icon : String ); 
  59.  
  60.     -- Sets the title text to display in the Panel's title bar. If 'icon' is an 
  61.     -- empty string, the icon will be removed. The display state of the panel's 
  62.     -- title bar will be automatically updated as necessary. 
  63.     procedure Set_Title( this : access Panel; title : String ); 
  64.  
  65. private 
  66.  
  67.     type Panel is new Container with 
  68.         record 
  69.             -- constant for the life of the widget 
  70.             titlePadding : Natural := 4; 
  71.             -- end constant for the life of the widget 
  72.  
  73.             title        : Unbounded_String;  -- optional title text 
  74.             icon         : Natural := 0;      -- optional icon's tile id 
  75.  
  76.             -- top of the children content area in pixels from the real top 
  77.             contentTop   : Integer := 0; 
  78.         end record; 
  79.  
  80.     procedure Construct( this  : access Panel; 
  81.                          view  : not null access Game_Views.Game_View'Class; 
  82.                          id    : String; 
  83.                          title : String; 
  84.                          icon  : String ); 
  85.     pragma Precondition( id'Length > 0 ); 
  86.  
  87.     -- Draws the Panel's background color, and its border and title bar, if it 
  88.     -- has either. 
  89.     procedure Draw_Content( this : access Panel ); 
  90.  
  91.     -- Returns the set minimum height, or computed minimum height, without 
  92.     -- accounting for child widgets. 
  93.     function Get_Min_Height( this : access Panel ) return Natural; 
  94.  
  95.     -- Returns the set minimum width, or computed minimum width, without 
  96.     -- accounting for child widgets. 
  97.     function Get_Min_Width( this : access Panel ) return Natural; 
  98.  
  99. end Widgets.Containers.Panels;