1. with Allegro.Bitmaps;                   use Allegro.Bitmaps; 
  2. with Allegro.Truecolor;                 use Allegro.Truecolor; 
  3. with Font_API;                          use Font_API; 
  4.  
  5. package Drawing_Contexts is 
  6.  
  7.     type Layer_Type is (Background, Foreground); 
  8.  
  9.     -- Encapsulates all of the information and operations required to draw 
  10.     -- within a specific context. All drawing operations performed with a 
  11.     -- Drawing_Context will be properly translated onto the context's target 
  12.     -- bitmap. 
  13.     type Drawing_Context is private; 
  14.  
  15.     -- Creates a new drawing context using the given bitmap. All drawing calls 
  16.     -- with this context will be translated to the bitmap by 'offx', 'offy' 
  17.     -- pixels. 
  18.     function Create_Drawing_Context( bmp   : not null A_Bitmap; 
  19.                                      offx, 
  20.                                      offy  : Integer; 
  21.                                      layer : Layer_Type ) return Drawing_Context; 
  22.  
  23.     -- Solidly blits the bitmap, changing every pixel in the dest rectangle 
  24.     -- unless the source pixel contains the standard mask color. 
  25.     procedure Blit( dc       : Drawing_Context; 
  26.                     source   : A_Bitmap; 
  27.                     source_x, 
  28.                     source_y, 
  29.                     dest_x, 
  30.                     dest_y   : Integer; 
  31.                     width, 
  32.                     height   : Natural ); 
  33.  
  34.     -- Clears the entire drawing area to a single color. 
  35.     procedure Clear_To_Color( dc : Drawing_Context; color : Color_Type ); 
  36.  
  37.     -- Draws a sprite using full alpha channel blending. 
  38.     procedure Draw_Alpha_Sprite( dc     : Drawing_Context; 
  39.                                  sprite : A_Bitmap; 
  40.                                  x, y   : Integer ); 
  41.  
  42.     -- Draws a sprite using the standard mask color for transparent pixels. 
  43.     procedure Draw_Sprite( dc     : Drawing_Context; 
  44.                            sprite : A_Bitmap; 
  45.                            x, y   : Integer ); 
  46.  
  47.     -- Returns the height of the drawing area in pixels. 
  48.     function Get_Height( dc : Drawing_Context ) return Natural; 
  49.  
  50.     -- Returns the layer of the drawing context that was specified at creation. 
  51.     function Get_Layer( dc : Drawing_Context ) return Layer_Type; 
  52.  
  53.     -- Returns the width of the drawing area in pixels. 
  54.     function Get_Width( dc : Drawing_Context ) return Natural; 
  55.  
  56.     -- Draws a straight line. 
  57.     procedure Line( dc     : Drawing_Context; 
  58.                     x1, y1, 
  59.                     x2, y2 : Integer; 
  60.                     color  : Color_Type ); 
  61.  
  62.     -- Draws a rectangle. 
  63.     procedure Rect( dc      : Drawing_Context; 
  64.                     x1, y1, 
  65.                     x2, y2  : Integer; 
  66.                     color   : Color_Type; 
  67.                     opacity : Natural := 255 ); 
  68.     pragma Precondition( opacity <= 255 ); 
  69.  
  70.     -- Draws a filled rectangle. 
  71.     procedure Rectfill( dc      : Drawing_Context; 
  72.                         x1, y1, 
  73.                         x2, y2  : Integer; 
  74.                         color   : Color_Type; 
  75.                         opacity : Natural := 255 ); 
  76.     pragma Precondition( opacity <= 255 ); 
  77.  
  78.     -- Solidly blits the bitmap, stretching it to a specified size. 
  79.     procedure Stretch_Blit( dc            : Drawing_Context; 
  80.                             bmp           : A_Bitmap; 
  81.                             source_x, 
  82.                             source_y      : Integer; 
  83.                             source_width, 
  84.                             source_height : Positive; 
  85.                             dest_x, 
  86.                             dest_y        : Integer; 
  87.                             dest_width, 
  88.                             dest_height   : Positive ); 
  89.  
  90.     -- Blits a bitmap using the transparent color as a mask. 'w' and 'h' are the 
  91.     -- destination size to stretch the sprite to. If 'proportional' is to True, 
  92.     -- the sprite will be drawn proportionally within the new width and height, 
  93.     -- instead of being stretched disproportionately to fill it entirely. 
  94.     procedure Stretch_Sprite( dc           : Drawing_Context; 
  95.                               sprite       : A_Bitmap; 
  96.                               x, y         : Integer; 
  97.                               w, h         : Positive; 
  98.                               proportional : Boolean ); 
  99.  
  100.     -- Draws a string string, using the given font. If 'smooth' is set to True, 
  101.     -- the text will be anti-aliased with the context's bitmap. 
  102.     procedure Textout( dc     : Drawing_Context; 
  103.                        f      : Font_Type; 
  104.                        s      : String; 
  105.                        x, y   : Integer; 
  106.                        color  : Color_Type; 
  107.                        smooth : Boolean ); 
  108.  
  109.     -- Draws a triangle. 
  110.     procedure Triangle( dc      : Drawing_Context; 
  111.                         x1, y1  : Integer; 
  112.                         x2, y2  : Integer; 
  113.                         x3, y3  : Integer; 
  114.                         color   : Color_Type; 
  115.                         opacity : Natural := 255 ); 
  116.     pragma Precondition( opacity <= 255 ); 
  117.  
  118. private 
  119.  
  120.     type Drawing_Context is 
  121.         record 
  122.             bmp   : A_Bitmap := null; 
  123.             offx, 
  124.             offy  : Integer := 0; 
  125.             layer : Layer_Type := Background; 
  126.         end record; 
  127.  
  128. end Drawing_Contexts;