1. ----------------------------------------------------------------------- 
  2. --               GtkAda - Ada95 binding for Gtk+/Gnome               -- 
  3. --                                                                   -- 
  4. --                    Copyright (C) 2010-2013, AdaCore               -- 
  5. --                                                                   -- 
  6. -- This library is free software; you can redistribute it and/or     -- 
  7. -- modify it under the terms of the GNU General Public               -- 
  8. -- License as published by the Free Software Foundation; either      -- 
  9. -- version 2 of the License, or (at your option) any later version.  -- 
  10. --                                                                   -- 
  11. -- This library is distributed in the hope that it will be useful,   -- 
  12. -- but WITHOUT ANY WARRANTY; without even the implied warranty of    -- 
  13. -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU -- 
  14. -- General Public License for more details.                          -- 
  15. --                                                                   -- 
  16. -- You should have received a copy of the GNU General Public         -- 
  17. -- License along with this library; if not, write to the             -- 
  18. -- Free Software Foundation, Inc., 59 Temple Place - Suite 330,      -- 
  19. -- Boston, MA 02111-1307, USA.                                       -- 
  20. --                                                                   -- 
  21. -- As a special exception, if other files instantiate generics from  -- 
  22. -- this unit, or you link this unit with other files to produce an   -- 
  23. -- executable, this  unit  does not  by itself cause  the resulting  -- 
  24. -- executable to be covered by the GNU General Public License. This  -- 
  25. -- exception does not however invalidate any other reasons why the   -- 
  26. -- executable file  might be covered by the  GNU Public License.     -- 
  27. ----------------------------------------------------------------------- 
  28.  
  29. --  <description> 
  30. --  Generic matrix operations. 
  31. --  </description> 
  32. -- 
  33. --  <c_version>1.8.8</c_version> 
  34. --  <group>Cairo</group> 
  35.  
  36. package Cairo.Matrix is 
  37.  
  38.    procedure Init 
  39.      (Matrix : access Cairo_Matrix; 
  40.       Xx     : Gdouble; 
  41.       Yx     : Gdouble; 
  42.       Xy     : Gdouble; 
  43.       Yy     : Gdouble; 
  44.       X0     : Gdouble; 
  45.       Y0     : Gdouble); 
  46.    --  Matrix: a Cairo_Matrix 
  47.    --  Xx: Xx component of the affine transformation 
  48.    --  Yx: Yx component of the affine transformation 
  49.    --  Xy: Xy component of the affine transformation 
  50.    --  Yy: Yy component of the affine transformation 
  51.    --  X0: X translation component of the affine transformation 
  52.    --  Y0: Y translation component of the affine transformation 
  53.    -- 
  54.    --  Sets matrix to be the affine transformation given by 
  55.    --  Xx, Yx, Xy, Yy, X0, Y0. The transformation is given 
  56.    --  by: 
  57.    -- 
  58.    --    X_new = Xx * X + Xy * Y + X0; 
  59.    --    Y_new = Yx * X + Yy * Y + Y0; 
  60.  
  61.    procedure Init_Identity (Matrix : access Cairo_Matrix); 
  62.    --  Matrix: a Cairo_Matrix 
  63.    -- 
  64.    --  Modifies matrix to be an identity transformation. 
  65.  
  66.    procedure Init_Translate 
  67.      (Matrix : access Cairo_Matrix; 
  68.       Tx     : Gdouble; 
  69.       Ty     : Gdouble); 
  70.    --  Matrix: a Cairo_Matrix 
  71.    --  Tx: amount to translate in the X direction 
  72.    --  Ty: amount to translate in the Y direction 
  73.    -- 
  74.    --  Initializes matrix to a transformation that translates by Tx and 
  75.    --  Ty in the X and Y dimensions, respectively. 
  76.  
  77.    procedure Init_Scale 
  78.      (Matrix : access Cairo_Matrix; 
  79.       Sx     : Gdouble; 
  80.       Sy     : Gdouble); 
  81.    --  Matrix: a Cairo_Matrix 
  82.    --  Sx: scale factor in the X direction 
  83.    --  Sy: scale factor in the Y direction 
  84.    -- 
  85.    --  Initializes matrix to a transformation that scales by Sx and Sy 
  86.    --  in the X and Y dimensions, respectively. 
  87.  
  88.    procedure Init_Rotate (Matrix : access Cairo_Matrix; Radians : Gdouble); 
  89.    --  Matrix: a Cairo_Matrix 
  90.    --  Radians: angle of rotation, in Radians. The direction of rotation 
  91.    --  is defined such that positive angles rotate in the direction from 
  92.    --  the positive X axis toward the positive Y axis. With the default 
  93.    --  axis orientation of cairo, positive angles rotate in a clockwise 
  94.    --  direction. 
  95.    -- 
  96.    --  Initialized matrix to a transformation that rotates by radians. 
  97.  
  98.    procedure Translate 
  99.      (Matrix : access Cairo_Matrix; 
  100.       Tx     : Gdouble; 
  101.       Ty     : Gdouble); 
  102.    --  Matrix: a Cairo_Matrix 
  103.    --  Tx: amount to translate in the X direction 
  104.    --  Ty: amount to translate in the Y direction 
  105.    -- 
  106.    --  Applies a translation by Tx, Ty to the transformation in 
  107.    --  matrix. The effect of the new transformation is to first translate 
  108.    --  the coordinates by Tx and Ty, then apply the original transformation 
  109.    --  to the coordinates. 
  110.  
  111.    procedure Scale 
  112.      (Matrix : access Cairo_Matrix; 
  113.       Sx     : Gdouble; 
  114.       Sy     : Gdouble); 
  115.    --  Matrix: a Cairo_Matrix 
  116.    --  Sx: scale factor in the X direction 
  117.    --  Sy: scale factor in the Y direction 
  118.    -- 
  119.    --  Applies scaling by Sx, Sy to the transformation in matrix. The 
  120.    --  effect of the new transformation is to first scale the coordinates 
  121.    --  by Sx and Sy, then apply the original transformation to the coordinates. 
  122.  
  123.    procedure Rotate (Matrix : access Cairo_Matrix; Radians : Gdouble); 
  124.    --  Matrix: a Cairo_Matrix 
  125.    --  Radians: angle of rotation, in Radians. The direction of rotation 
  126.    --  is defined such that positive angles rotate in the direction from 
  127.    --  the positive X axis toward the positive Y axis. With the default 
  128.    --  axis orientation of cairo, positive angles rotate in a clockwise 
  129.    --  direction. 
  130.    -- 
  131.    --  Applies rotation by radians to the transformation in matrix. The effect 
  132.    --  of the new transformation is to first rotate the coordinates by radians, 
  133.    --  then apply the original transformation to the coordinates. 
  134.  
  135.    function Invert (Matrix : access Cairo_Matrix) return Cairo_Status; 
  136.    --  Matrix: a Cairo_Matrix 
  137.    -- 
  138.    --  Changes matrix to be the inverse of its original value. Not 
  139.    --  all transformation matrices have inverses; if the matrix 
  140.    --  collapses points together (it is "degenerate"), 
  141.    --  then it has no inverse and this function will fail. 
  142.    -- 
  143.    --  Returns: If matrix has an inverse, modifies matrix to 
  144.    --  be the inverse matrix and returns Cairo_Status_Success. Otherwise, 
  145.    --  returns Cairo_Status_Invalid_Matrix. 
  146.  
  147.    procedure Multiply 
  148.      (Result : access Cairo_Matrix; 
  149.       A      : access Cairo_Matrix; 
  150.       B      : access Cairo_Matrix); 
  151.    --  Result: a Cairo_Matrix in which to store the Result 
  152.    --  A: a Cairo_Matrix 
  153.    --  B: a Cairo_Matrix 
  154.    -- 
  155.    --  Multiplies the affine transformations in a and b together 
  156.    --  and stores the result in result. The effect of the resulting 
  157.    --  transformation is to first apply the transformation in a to the 
  158.    --  coordinates and then apply the transformation in b to the 
  159.    --  coordinates. 
  160.    -- 
  161.    --  It is allowable for result to be identical to either a or b. 
  162.  
  163.    procedure Transform_Distance 
  164.      (Matrix : access Cairo_Matrix; 
  165.       Dx     : access Gdouble; 
  166.       Dy     : access Gdouble); 
  167.    --  Matrix: a Cairo_Matrix 
  168.    --  Dx: X component of a distance vector. An in/out parameter 
  169.    --  Dy: Y component of a distance vector. An in/out parameter 
  170.    -- 
  171.    --  Transforms the distance vector (Dx,Dy) by matrix. This is 
  172.    --  similar to Cairo.Matrix.Transform_Point except that the translation 
  173.    --  components of the transformation are ignored. The calculation of 
  174.    --  the returned vector is as follows: 
  175.    -- 
  176.    --  Dx2 = Dx1 * A + Dy1 * C; 
  177.    --  Dy2 = Dx1 * B + Dy1 * D; 
  178.    -- 
  179.    --  Affine transformations are position invariant, so the same vector 
  180.    --  always transforms to the same vector. If (X1,Y1) transforms 
  181.    --  to (X2,Y2) then (X1+Dx1,Y1+Dy1) will transform to 
  182.    --  (X1+Dx2,Y1+Dy2) for all values of X1 and X2. 
  183.  
  184.    procedure Transform_Point 
  185.      (Matrix : access Cairo_Matrix; 
  186.       X      : access Gdouble; 
  187.       Y      : access Gdouble); 
  188.    --  Matrix: a Cairo_Matrix 
  189.    --  X: X position. An in/out parameter 
  190.    --  Y: Y position. An in/out parameter 
  191.    -- 
  192.    --  Transforms the point (X, Y) by matrix. 
  193.  
  194. private 
  195.  
  196.    pragma Import (C, Init, "cairo_matrix_init"); 
  197.    pragma Import (C, Init_Identity, "cairo_matrix_init_identity"); 
  198.    pragma Import (C, Init_Translate, "cairo_matrix_init_translate"); 
  199.    pragma Import (C, Init_Scale, "cairo_matrix_init_scale"); 
  200.    pragma Import (C, Init_Rotate, "cairo_matrix_init_rotate"); 
  201.    pragma Import (C, Translate, "cairo_matrix_translate"); 
  202.    pragma Import (C, Scale, "cairo_matrix_scale"); 
  203.    pragma Import (C, Rotate, "cairo_matrix_rotate"); 
  204.    pragma Import (C, Invert, "cairo_matrix_invert"); 
  205.    pragma Import (C, Multiply, "cairo_matrix_multiply"); 
  206.    pragma Import (C, Transform_Distance, "cairo_matrix_transform_distance"); 
  207.    pragma Import (C, Transform_Point, "cairo_matrix_transform_point"); 
  208.  
  209. end Cairo.Matrix;