1. with Entities;                          use Entities; 
  2.  
  3. limited with Game_Views; 
  4.  
  5. private with Tiles.Libraries; 
  6.  
  7. package Widgets.Sprites is 
  8.  
  9.     -- A Sprite is the visible representation of an Entity. It is a partially 
  10.     -- transparent widget, drawn as a tile from a tile library, that is added to 
  11.     -- a Scene container widget. 
  12.     type Sprite is new Widget with private; 
  13.     type A_Sprite is access all Sprite'Class; 
  14.  
  15.     -- Creates a new Sprite. 'eid' is the id of the entity it represents. Class 
  16.     -- is the class of entity it represents. 'x', 'y' are the location of the 
  17.     -- center of the widget in pixels. 'physical' indicates if the entity obeys 
  18.     -- the laws of physics. 'libName' is the name of the tile library to be used 
  19.     -- for the sprite's images. 'frame' is the id of the current frame in the 
  20.     -- tile library to display. 
  21.     function Create_Sprite( view     : not null access Game_Views.Game_View'Class; 
  22.                             eid      : Entity_Id; 
  23.                             class    : String; 
  24.                             x, y     : Float; 
  25.                             physical : Boolean; 
  26.                             libName  : String; 
  27.                             frame    : Natural ) return A_Sprite; 
  28.     pragma Precondition( class'Length > 0 ); 
  29.     pragma Precondition( libName'Length > 0 ); 
  30.     pragma Postcondition( Create_Sprite'Result /= null ); 
  31.  
  32.     -- Centers the sprite at 'x', 'y' in pixels. The sprite will update its 
  33.     -- known location of its entity. 
  34.     procedure Center_At( this : not null access Sprite'Class; x, y : Float ); 
  35.  
  36.     -- Returns the sprite's entity's class. 
  37.     function Get_Class( this : not null access Sprite'Class ) return String; 
  38.     pragma Postcondition( Get_Class'Result'Length > 0 ); 
  39.  
  40.     -- Returns the Entity_Id of the Sprite's entity. 
  41.     function Get_Entity_Id( this : not null access Sprite'Class ) return Entity_Id; 
  42.  
  43.     -- Returns the x location of the Sprite's entity; located at the center of 
  44.     -- the widget. 
  45.     function Get_X( this : not null access Sprite'Class ) return Float; 
  46.  
  47.     -- Returns the y location of the Sprite's entity; located at the center of 
  48.     -- the widget. 
  49.     function Get_Y( this : not null access Sprite'Class ) return Float; 
  50.  
  51.     -- Sets the tile id of the Sprite's current frame. 
  52.     procedure Set_Frame( this : not null access Sprite'Class; frame : Natural ); 
  53.  
  54.     function Is_Updatable( this : not null access Sprite'Class ) return Boolean; 
  55.  
  56.     -- Resizes the Sprite to 'width', 'height' while keeping the widget centered 
  57.     -- at its entity's location. If 'width' or 'height' is 0, the value will not 
  58.     -- be changed. (ex: width => 10, height => 0 will change only the width.) 
  59.     procedure Resize( this   : not null access Sprite'Class; 
  60.                       width, 
  61.                       height : Natural ); 
  62.  
  63.     -- Notifies the sprite of its selected state. This doesn't actually 
  64.     -- select/unselect the widget; that can only be done by its Window. 
  65.     procedure Set_Selected( this : access Sprite; selected : Boolean ); 
  66.  
  67. private 
  68.  
  69.     use Tiles.Libraries; 
  70.  
  71.     type Sprite is new Widget with 
  72.         record 
  73.             eid         : Entity_Id := INVALID_ID; 
  74.             class       : Unbounded_String; 
  75.             x, y        : Float := 0.0; 
  76.             physical    : Boolean := False; 
  77.             lib         : A_Tile_Library := null; 
  78.             frame       : Natural := 0; 
  79.             updatable   : Integer := 0;       -- accepts updates if = 0 
  80.             interactive : Boolean := False; 
  81.             selected    : Boolean := False; 
  82.         end record; 
  83.  
  84.     procedure Construct( this     : access Sprite; 
  85.                          view     : not null access Game_Views.Game_View'Class; 
  86.                          eid      : Entity_Id; 
  87.                          class    : String; 
  88.                          x, y     : Float; 
  89.                          physical : Boolean; 
  90.                          libName  : String; 
  91.                          frame    : Natural ); 
  92.     pragma Precondition( class'Length > 0 ); 
  93.     pragma Precondition( libName'Length > 0 ); 
  94.  
  95.     procedure Delete( this : in out Sprite ); 
  96.  
  97.     procedure Draw_Content( this : access Sprite; dc : Drawing_Context ); 
  98.  
  99.     function Get_Min_Height( this : access Sprite ) return Natural; 
  100.  
  101.     function Get_Min_Width( this : access Sprite ) return Natural; 
  102.  
  103. end Widgets.Sprites;