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. with Allegro.Displays;                  use Allegro.Displays; 
  10.  
  11. private with Ada.Containers.Doubly_Linked_Lists; 
  12.  
  13. limited private with Tiles.Atlases.Bins; 
  14.  
  15. private package Tiles.Atlases is 
  16.  
  17.     type Atlas is new Limited_Object with private; 
  18.     type A_Atlas is access all Atlas'Class; 
  19.  
  20.     -- Creates a new Atlas with pages of the specified size but no larger than 
  21.     -- the largest texture size supported by the display. 
  22.     function Create_Atlas( display    : not null A_Allegro_Display; 
  23.                            pageWidth, 
  24.                            pageHeight : Positive ) return A_Atlas; 
  25.     pragma Postcondition( Create_Atlas'Result /= null ); 
  26.  
  27.     -- Adds a bitmap 'bmp' to the Atlas. It will be consumed and returned as a 
  28.     -- sub-bitmap of a page in the atlas. Be sure to destroy the bitmap before 
  29.     -- this atlas, or the bitmap will become invalid. 
  30.     procedure Add_Bitmap( this : not null access Atlas'Class; 
  31.                           bmp  : in out A_Allegro_Bitmap ); 
  32.  
  33.     -- Saves each page of the atlas as a bitmap in the current directory, using 
  34.     -- 'name' as the filename prefix and appending the page number. The bitmaps 
  35.     -- will be saved in .png format. 
  36.     procedure Save_Bitmaps( this : not null access Atlas'Class; 
  37.                             name : String ); 
  38.  
  39.     -- Deletes the Atlas. Make sure all sub-bitmap references previously 
  40.     -- returned from the atlas have been destroyed first or they will become 
  41.     -- invalid. 
  42.     procedure Delete( this : in out A_Atlas ); 
  43.  
  44. private 
  45.  
  46.     type Page is 
  47.         record 
  48.             bmp  : A_Allegro_Bitmap; 
  49.             bin  : access Tiles.Atlases.Bins.Bin'Class; 
  50.             full : Boolean := False; 
  51.         end record; 
  52.     type A_Page is access all Page; 
  53.  
  54.     package Page_Lists is new Ada.Containers.Doubly_Linked_Lists( A_Page, "=" ); 
  55.  
  56.     type Atlas is new Limited_Object with 
  57.         record 
  58.             display    : A_Allegro_Display := null; 
  59.             pageWidth, 
  60.             pageHeight : Natural := 0; 
  61.             pages      : Page_Lists.List; 
  62.         end record; 
  63.  
  64.     -- Constructs the Atlas with pages of 'pageWidth' x 'pageHeight' but no 
  65.     -- larger than the largest texture size supported by the display. 
  66.     procedure Construct( this       : in out Atlas; 
  67.                          display    : not null A_Allegro_Display; 
  68.                          pageWidth, 
  69.                          pageHeight : Positive ); 
  70.  
  71.     procedure Delete( this : in out Atlas ); 
  72.  
  73.     -- Adds a new Page to the Atlas. 
  74.     procedure Add_Page( this : not null access Atlas'Class ); 
  75.  
  76. end Tiles.Atlases;