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