1. with Entities;                          use Entities; 
  2. with Events.Listeners;                  use Events.Listeners; 
  3.  
  4. private with Ada.Containers.Ordered_Maps; 
  5. private with Ada.Containers.Ordered_Sets; 
  6. private with Events; 
  7. private with Events.Entities; 
  8. private with Events.World; 
  9. private with Interfaces; 
  10. private with Maps; 
  11. private with Tiles.Libraries; 
  12. private with Widgets.Sprites; 
  13.  
  14. package Widgets.Containers.Scenes is 
  15.  
  16.     type Scene is abstract new Container and Event_Listener with private; 
  17.     type A_Scene is access all Scene'Class; 
  18.  
  19.     procedure Draw_Layer( this   : access Scene; 
  20.                           dc     : Drawing_Context; 
  21.                           layer  : Positive;      -- layer to draw 
  22.                           startX,                 -- location in world coordinates 
  23.                           startY : Integer;       --     to start drawing 
  24.                           tileX1,                 -- range of the visible layer 
  25.                           tileY1,                 --     in tile coordinates 
  26.                           tileX2,                 -- 
  27.                           tileY2 : Integer        -- 
  28.                         ) is abstract; 
  29.  
  30.     function Get_Height_Tiles( this : not null access Scene'Class ) return Natural; 
  31.  
  32.     function Get_Width_Tiles( this : not null access Scene'Class ) return Natural; 
  33.  
  34.     -- Shifts the focus of the scene by x, y in world coordinates. If the scene 
  35.     -- is following a target entity then scrolling will be constrained to the 
  36.     -- target by slack the distance. 
  37.     procedure Scroll( this : not null access Scene'Class; x, y : Float ); 
  38.  
  39.     -- Passing null in 'child' will clear the selection. 
  40.     procedure Set_Selection( this : access Scene; child : A_Widget ); 
  41.  
  42.     procedure Set_Target( this : access Scene; target : Entity_Id ); 
  43.  
  44.     procedure Unselect( this : access Scene; child : not null A_Widget ); 
  45.  
  46. private 
  47.  
  48.     use Events; 
  49.     use Events.Entities; 
  50.     use Events.World; 
  51.     use Interfaces; 
  52.     use Maps; 
  53.     use Tiles.Libraries; 
  54.     use Widgets.Sprites; 
  55.  
  56.     package Sprite_Maps is new Ada.Containers.Ordered_Maps( Entity_Id, A_Sprite, "<", "=" ); 
  57.     use Sprite_Maps; 
  58.  
  59.     package Widget_Sets is new Ada.Containers.Ordered_Sets( A_Widget, Lt, "=" ); 
  60.     use Widget_Sets; 
  61.  
  62.     type Boolean_Array is array (Natural range <>) of Boolean; 
  63.     type A_Boolean_Array is access all Boolean_Array; 
  64.  
  65.     type Byte_Array is array (Natural range <>) of Unsigned_8; 
  66.     type A_Byte_Array is access all Byte_Array; 
  67.  
  68.     type Cached_Bitmap is 
  69.         record 
  70.             tileId : Natural := 0; 
  71.             bmp    : A_Bitmap := null; 
  72.         end record; 
  73.  
  74.     type Cached_Bitmap_Array is array (Natural range <>) of Cached_Bitmap; 
  75.     type A_Cached_Bitmap_Array is access all Cached_Bitmap_Array; 
  76.  
  77.     type Bitmap_Cache is array (Natural range <>) of A_Cached_Bitmap_Array; 
  78.     type A_Bitmap_Cache is access all Bitmap_Cache; 
  79.  
  80.     ---------------------------------------------------------------------------- 
  81.  
  82.     type Scene is abstract new Container and Event_Listener with 
  83.         record 
  84.             hasData       : Boolean := False; 
  85.             mapWidth, 
  86.             mapHeight     : Natural := 0; 
  87.             mapLayers     : A_Layer_Array := null; 
  88.             bitmapCache   : A_Bitmap_Cache := null; 
  89.             visibleLayers : A_Boolean_Array := null; 
  90.             lightLevels   : A_Byte_Array := null; 
  91.             spriteLayer   : Integer := Integer'Last;   -- sprites draw on top of this layer 
  92.             tileWidth     : Positive := 1; 
  93.             tileLib       : A_Tile_Library := null; 
  94.             target        : Entity_Id := INVALID_ID;   -- target entity to follow 
  95. --            targetX,                          -- location of the target entity in 
  96. --            targetY       : Float := 0.0;     -- world coordinates (if target /= INVALID_ID) 
  97.             wFocusX,                          -- world coords at center of scene 
  98.             wFocusY       : Float := 0.0;     -- 
  99.             wSlackX,                          -- max pixels target can be from center 
  100.             wSlackY       : Float := 0.0;     -- in world units (changes with zoom) 
  101.             spriteMap     : Sprite_Maps.Map; 
  102.             selectedSet   : Widget_Sets.Set; 
  103.             waitForLoad   : Boolean := False;   -- waits for the tile library to 
  104.                                                 -- load completely before 
  105.                                                 -- drawing any tiles. 
  106.         end record; 
  107.  
  108.     procedure Add( this    : access Scene; 
  109.                    child   : in out A_Widget; 
  110.                    consume : Boolean := True ); 
  111.     pragma Postcondition( consume xor child /= null ); 
  112.  
  113.     procedure Clear_Selection( this : access Scene ); 
  114.  
  115.     procedure Construct( this : access Scene; 
  116.                          view : not null access Game_Views.Game_View'Class; 
  117.                          id   : String ); 
  118.     pragma Precondition( id'Length > 0 ); 
  119.  
  120.     procedure Delete( this : in out Scene ); 
  121.  
  122.     procedure Delete_Children( this : access Scene ); 
  123.  
  124.     procedure Draw_Content( this : access Scene; dc : Drawing_Context ); 
  125.  
  126.     procedure Draw_Layer_Overlay( this   : access Scene; 
  127.                                   dc     : Drawing_Context; 
  128.                                   startX, 
  129.                                   startY : Integer; 
  130.                                   tileX1, 
  131.                                   tileY1, 
  132.                                   tileX2, 
  133.                                   tileY2 : Integer ); 
  134.  
  135.     function Find_Sprite( this : not null access Scene'Class; 
  136.                           id   : Entity_Id ) return A_Sprite; 
  137.  
  138.     -- Focus the scene on a point in world coordinates. If the point is already 
  139.     -- within the slack focus area, the viewport will not change. However, if 
  140.     -- centered is set to True then the viewport will ignore slack constraints 
  141.     -- and attempt to center the focal point. 
  142.     procedure Focus_On( this     : not null access Scene'Class; 
  143.                         x, y     : Float; 
  144.                         centered : Boolean := False ); 
  145.  
  146.     function Get_Min_Height( this : access Scene ) return Natural; 
  147.  
  148.     function Get_Min_Width( this : access Scene ) return Natural; 
  149.  
  150.     procedure Handle_Entity_Attribute_Changed( this : access Scene; 
  151.                                                evt  : not null A_Entity_Attribute_Changed_Event ); 
  152.  
  153.     procedure Handle_Entity_Created( this : access Scene; 
  154.                                      evt  : not null A_Entity_Created_Event ); 
  155.  
  156.     procedure Handle_Entity_Deleted( this : access Scene; 
  157.                                      evt  : not null A_Entity_Deleted_Event ); 
  158.  
  159.     procedure Handle_Entity_Moved( this : access Scene; 
  160.                                    evt  : not null A_Entity_Moved_Event ); 
  161.  
  162.     procedure Handle_Entity_Resized( this : access Scene; 
  163.                                      evt  : not null A_Entity_Resized_Event ); 
  164.  
  165.     -- if evt is returned null then the event was consumed 
  166.     procedure Handle_Event( this : access Scene; 
  167.                             evt  : in out A_Event; 
  168.                             resp : out Response_Type ); 
  169.     pragma Precondition( evt /= null ); 
  170.  
  171.     procedure Handle_Frame_Changed( this : access Scene; 
  172.                                     evt  : not null A_Frame_Changed_Event ); 
  173.  
  174.     procedure Handle_New_World( this : access Scene; 
  175.                                 evt  : not null A_New_World_Event ); 
  176.  
  177.     procedure Handle_Resize( this : access Scene ); 
  178.  
  179.     procedure Handle_Tile_Changed( this : access Scene; 
  180.                                    evt  : not null A_Tile_Changed_Event ); 
  181.  
  182.     procedure Handle_World_Property_Changed( this : access Scene; 
  183.                                              evt  : not null A_World_Property_Changed_Event ); 
  184.  
  185.     function Is_Tile_Visible( this  : not null access Scene'Class; 
  186.                               layer : Positive; 
  187.                               x, y  : Integer ) return Boolean; 
  188.  
  189.     procedure Remove( this : access Scene; child : not null A_Widget ); 
  190.  
  191.     ---------------------------------------------------------------------------- 
  192.  
  193.     procedure Delete( ba : in out A_Boolean_Array ); 
  194.  
  195.     procedure Delete( ba : in out A_Byte_Array ); 
  196.  
  197.     procedure Delete( bc : in out A_Bitmap_Cache ); 
  198.  
  199. end Widgets.Containers.Scenes;