1. with Allegro.Bitmaps;                   use Allegro.Bitmaps; 
  2. with Objects;                           use Objects; 
  3. with Processes;                         use Processes; 
  4. with Widgets.Containers.Windows;        use Widgets.Containers.Windows; 
  5.  
  6. private with Ada.Real_Time; 
  7.  
  8. package Renderers is 
  9.  
  10.     -- A Renderer is a member of the Game View system and is responsible for 
  11.     -- drawing a Window widget to the screen. Only one renderer exists per 
  12.     -- application. It implements the Process interface to draw on a tick when 
  13.     -- the specified framerate allows. The renderer uses double-buffering for 
  14.     -- updating frames. 
  15.     type Renderer is new Object and Process with private; 
  16.     type A_Renderer is access all Renderer'Class; 
  17.  
  18.     -- Create a Renderer object that draws 'win' to the screen at a maximum 
  19.     -- frequency of 'fps'. For best performance, do not attach the Renderer to 
  20.     -- a Process_Manager running at a frequency less than 'fps'; it's best if 
  21.     -- the Process is ticked at the same frequency, or a multiple of it. 
  22.     function Create_Renderer( win : not null A_Window; 
  23.                               fps : Positive ) return A_Renderer; 
  24.     pragma Postcondition( Create_Renderer'Result /= null ); 
  25.  
  26.     -- Copies the Renderer. Its window widget is not copied, just re-referenced. 
  27.     function Copy( src : A_Renderer ) return A_Renderer; 
  28.     pragma Postcondition( Copy'Result /= src or else src = null ); 
  29.  
  30.     -- Deletes the Renderer. 
  31.     procedure Delete( this : in out A_Renderer ); 
  32.     pragma Postcondition( this = null ); 
  33.  
  34.     -- Instructs renderers to draw a software mouse. This flag is checked when 
  35.     -- a Renderer is constructed, so it will not affect existing Renderer 
  36.     -- instances. 
  37.     procedure Use_Software_Mouse; 
  38.  
  39. private 
  40.  
  41.     use Ada.Real_Time; 
  42.  
  43.     -- Set by calling Use_Software_Mouse. The application should set this during 
  44.     -- Allegro initialization if it determines the mouse must be drawn in 
  45.     -- software mode. Ideally this flag should be part of the drawing API. 
  46.     using_sw_mouse : Boolean := False; 
  47.  
  48.     -- an array of video bitmaps for double-buffering 
  49.     type Page_Index is mod 2; 
  50.     type Page_Array is array(Page_Index) of A_Bitmap; 
  51.  
  52.     ---------------------------------------------------------------------------- 
  53.  
  54.     type Renderer is new Object and Process with 
  55.         record 
  56.             win        : A_Window := null; 
  57.             videoPages : Page_Array; 
  58.             drawPage   : Page_Index := Page_Array'Last; 
  59.             frameDelta : Time_Span := Time_Span_Zero; 
  60.             lastFrame  : Time := Time_First; 
  61.         end record; 
  62.  
  63.     procedure Adjust( this : access Renderer ); 
  64.  
  65.     procedure Construct( this : access Renderer; 
  66.                          win  : A_Window; 
  67.                          fps  : Positive ); 
  68.  
  69.     procedure Delete( this : in out Renderer ); 
  70.  
  71.     -- Draws a new frame to 'vpage'. 
  72.     procedure Draw_Frame( this  : access Renderer; 
  73.                           vpage : A_Bitmap; 
  74.                           dt    : Time_Span ); 
  75.  
  76.     function Get_Process_Name( this : access Renderer ) return String; 
  77.  
  78.     -- Updates the screen. 
  79.     procedure Tick( this : access Renderer; time : Tick_Time ); 
  80.  
  81. end Renderers;