1. ----------------------------------------------------------------------- 
  2. --               GtkAda - Ada95 binding for Gtk+/Gnome               -- 
  3. --                                                                   -- 
  4. --   Copyright (C) 1998-2000 E. Briot, J. Brobecker and A. Charlet   -- 
  5. --                Copyright (C) 2000-2002 ACT-Europe                 -- 
  6. --                                                                   -- 
  7. -- This library is free software; you can redistribute it and/or     -- 
  8. -- modify it under the terms of the GNU General Public               -- 
  9. -- License as published by the Free Software Foundation; either      -- 
  10. -- version 2 of the License, or (at your option) any later version.  -- 
  11. --                                                                   -- 
  12. -- This library is distributed in the hope that it will be useful,   -- 
  13. -- but WITHOUT ANY WARRANTY; without even the implied warranty of    -- 
  14. -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU -- 
  15. -- General Public License for more details.                          -- 
  16. --                                                                   -- 
  17. -- You should have received a copy of the GNU General Public         -- 
  18. -- License along with this library; if not, write to the             -- 
  19. -- Free Software Foundation, Inc., 59 Temple Place - Suite 330,      -- 
  20. -- Boston, MA 02111-1307, USA.                                       -- 
  21. --                                                                   -- 
  22. -- -- -- -- -- -- -- -- -- -- -- --
  23. ----------------------------------------------------------------------- 
  24.  
  25. --  <description> 
  26. -- 
  27. --  A graphic context is a structure that describes all the attributes 
  28. --  used by the drawing functions in Gdk. 
  29. --  The colors, line styles, Fill styles and so on are defined through 
  30. --  this structure. 
  31. -- 
  32. --  On X11 systems, this structure is stored directly on the XServer, 
  33. --  which speeds up the transfer of the drawing attributes a lot. Instead 
  34. --  of transferring all of them every time you call one of the drawing 
  35. --  functions, you simply specify which GC you want to use. 
  36. -- 
  37. --  Thus, it is recommended to create as many GCs as you need, instead 
  38. --  of creating a single one that is modified every time you need to 
  39. --  modify one of the attributes. 
  40. -- 
  41. --  On Unix machines, you should have a look at the external utility 'xgc' 
  42. --  which demonstrates all the basic settings of the graphic contexts. 
  43. -- 
  44. --  </description> 
  45. --  <c_version>1.3.6</c_version> 
  46. --  <group>Gdk, the low-level API</group> 
  47. --  <testgtk>create_gc.adb</testgtk> 
  48. --  <see>Gtk.GC</see> 
  49.  
  50. with Glib; use Glib; 
  51. with Gdk.Color; 
  52. with Gdk.Font; 
  53. with Gdk.Rectangle; 
  54. with Gdk.Region; 
  55.  
  56. package Gdk.GC is 
  57.  
  58.    subtype Gdk_GC is Gdk.Gdk_GC; 
  59.    --  A graphic context that contain all the information to draw graphics 
  60.    --  on the screen. 
  61.    --  Creating these GC is more efficient than passing a lot of parameters 
  62.    --  to each of the drawing functions, since these GC are stored on the 
  63.    --  server side and do not need to be pass through the network. 
  64.  
  65.    type Gdk_GC_Values is new Gdk.C_Proxy; 
  66.    --  A structure used on the client side to store the same information 
  67.    --  as the GC. Creating a GC from this structure is more efficient than 
  68.    --  calling a lot of functions to modify the GC directly, since there is 
  69.    --  a single call to the server. 
  70.  
  71.    type Gdk_Cap_Style is (Cap_Not_Last, Cap_Butt, Cap_Round, Cap_Projecting); 
  72.    pragma Convention (C, Gdk_Cap_Style); 
  73.  
  74.    type Gdk_Fill is (Solid, Tiled, Stippled, Opaque_Stippled); 
  75.    pragma Convention (C, Gdk_Fill); 
  76.  
  77.    type Gdk_Function is 
  78.      (Copy, 
  79.       Invert, 
  80.       Gdk_Xor, 
  81.       Clear, 
  82.       Gdk_And, 
  83.       And_Reverse, 
  84.       And_Invert, 
  85.       Noop, 
  86.       Gdk_Or, 
  87.       Equiv, 
  88.       Or_Reverse, 
  89.       Copy_Invert, 
  90.       Or_Invert, 
  91.       Nand, 
  92.       Set); 
  93.    pragma Convention (C, Gdk_Function); 
  94.  
  95.    type Gdk_Join_Style is (Join_Miter, Join_Round, Join_Bevel); 
  96.    pragma Convention (C, Gdk_Join_Style); 
  97.  
  98.    type Gdk_Line_Style is (Line_Solid, Line_On_Off_Dash, Line_Double_Dash); 
  99.    pragma Convention (C, Gdk_Line_Style); 
  100.  
  101.    type Gdk_Subwindow_Mode is (Clip_By_Children, Include_Inferiors); 
  102.    pragma Convention (C, Gdk_Subwindow_Mode); 
  103.  
  104.    type Gdk_GC_Values_Mask is mod 2 ** 32; 
  105.    GC_Foreground    : constant Gdk_GC_Values_Mask := 2 ** 0; 
  106.    GC_Background    : constant Gdk_GC_Values_Mask := 2 ** 1; 
  107.    GC_Font          : constant Gdk_GC_Values_Mask := 2 ** 2; 
  108.    GC_Function      : constant Gdk_GC_Values_Mask := 2 ** 3; 
  109.    GC_Fill          : constant Gdk_GC_Values_Mask := 2 ** 4; 
  110.    GC_Tile          : constant Gdk_GC_Values_Mask := 2 ** 5; 
  111.    GC_Stipple       : constant Gdk_GC_Values_Mask := 2 ** 6; 
  112.    GC_Clip_Mask     : constant Gdk_GC_Values_Mask := 2 ** 7; 
  113.    GC_Subwindow     : constant Gdk_GC_Values_Mask := 2 ** 8; 
  114.    GC_Ts_X_Origin   : constant Gdk_GC_Values_Mask := 2 ** 9; 
  115.    GC_Tx_Y_Origin   : constant Gdk_GC_Values_Mask := 2 ** 10; 
  116.    GC_Clip_X_Origin : constant Gdk_GC_Values_Mask := 2 ** 11; 
  117.    GC_Clip_Y_Origin : constant Gdk_GC_Values_Mask := 2 ** 12; 
  118.    GC_Exposures     : constant Gdk_GC_Values_Mask := 2 ** 13; 
  119.    GC_Line_Width    : constant Gdk_GC_Values_Mask := 2 ** 14; 
  120.    GC_Line_Style    : constant Gdk_GC_Values_Mask := 2 ** 15; 
  121.    GC_Cap_Style     : constant Gdk_GC_Values_Mask := 2 ** 16; 
  122.    GC_Join_Style    : constant Gdk_GC_Values_Mask := 2 ** 17; 
  123.  
  124.    Null_GC : constant Gdk_GC := null; 
  125.    Null_GC_Values : constant Gdk_GC_Values := null; 
  126.  
  127.    ------------ 
  128.    -- Gdk_GC -- 
  129.    ------------ 
  130.  
  131.    procedure Gdk_New 
  132.      (GC       : out Gdk_GC; 
  133.       Drawable : Gdk.Gdk_Drawable); 
  134.    --  Create a new graphic context. 
  135.    --  The window must have been realized first (so that it is associated 
  136.    --  with some resources on the Xserver). 
  137.    --  The GC can then be used for any window that has the same root window, 
  138.    --  and same color depth as Window. 
  139.    --  See the manual page for XCreateGC on Unix systems for more information. 
  140.  
  141.    procedure Gdk_New 
  142.      (GC          : out Gdk_GC; 
  143.       Drawable    : Gdk.Gdk_Drawable; 
  144.       Values      : Gdk_GC_Values; 
  145.       Values_Mask : Gdk_GC_Values_Mask); 
  146.    --  Create a new graphic context. 
  147.    --  It is directly created with the values set in Values, and whose 
  148.    --  associated field has been set in Values_Mask. 
  149.    --  This is faster than calling the simple Gdk_New function and each of 
  150.    --  other functions in this package, since each of them requires a call 
  151.    --  to the server. 
  152.  
  153.    function Get_Type return Glib.GType; 
  154.    --  Return the internal value associated with Gdk_GC. 
  155.  
  156.    procedure Destroy (GC : Gdk_GC); 
  157.    --  Free the memory allocated on the server for the graphic context. 
  158.    --  Graphic contexts are never freed automatically by GtkAda, this is 
  159.    --  the user responsibility to do so. 
  160.    --  This procedure is deprecated. Use Unref instead. 
  161.  
  162.    procedure Ref (GC : Gdk_GC); 
  163.    --  Increment the reference counting for the graphic context. 
  164.  
  165.    procedure Unref (GC : Gdk_GC); 
  166.    --  Decrement the reference counting for the graphic context. 
  167.    --  When this reaches 0, the graphic context is destroyed. 
  168.  
  169.    procedure Get_Values (GC : Gdk_GC; Values : Gdk_GC_Values); 
  170.    --  Get the values set in the GC. 
  171.    --  This copies the values from the server to client, allowing faster 
  172.    --  modifications. Values can then be copied back to the server by 
  173.    --  creating a new graphic context with the function Gdk_New above. 
  174.    --  Values should have been allocated first with a call to Gdk_New. 
  175.  
  176.    procedure Set_Values 
  177.      (GC     : Gdk_GC; 
  178.       Values : Gdk_GC_Values; 
  179.       Mask   : Gdk_GC_Values_Mask); 
  180.    --  Set the values in the GC. 
  181.    --  Mask indicates which values should be taken from Values and set in GC. 
  182.  
  183.    procedure Set_Foreground (GC : Gdk_GC; Color : Gdk.Color.Gdk_Color); 
  184.    --  Set the foreground color for the graphic context. 
  185.    --  This color is the one that is used by most drawing functions. 
  186.  
  187.    procedure Set_Background (GC : Gdk_GC; Color : Gdk.Color.Gdk_Color); 
  188.    --  Set the background color for the graphic context. 
  189.  
  190.    procedure Set_Font (GC : Gdk_GC; Font : Gdk.Font.Gdk_Font); 
  191.    --  Set the font used by the graphic context. 
  192.    --  This font is used by the function Gdk.Drawable.Draw_Text. 
  193.  
  194.    procedure Set_Function (GC : Gdk_GC; Func : Gdk_Function); 
  195.    --  Set the function in the graphic context. 
  196.    --  This function specifies how the points are put on the screen, ie 
  197.    --  if GtkAda how GtkAda should mix the point already on the screen 
  198.    --  and the new point being put. 
  199.    --  Note that setting the function to Gdk_Xor is not the right way 
  200.    --  to do animation. You should instead save the background pixmap, 
  201.    --  put the image, and then restore the background. 
  202.    -- 
  203.    --  In general, there are three basic steps to drawing: reading the source 
  204.    --  pixels, reading the destination pixels, and writing the destination 
  205.    --  pixels.  Some functions only perform the third step (Set and Clear), 
  206.    --  some do not need the middle step (Copy), whereas most require the three 
  207.    --  steps, and thus can be much slower. 
  208.  
  209.    procedure Set_Fill (GC : Gdk_GC; Fill : Gdk_Fill); 
  210.    --  Set the pattern used for filling the polygons. 
  211.  
  212.    procedure Set_Tile (GC : Gdk_GC; Tile : Gdk.Gdk_Pixmap); 
  213.  
  214.    procedure Set_Stipple (GC : Gdk_GC; Stipple : Gdk.Gdk_Pixmap); 
  215.  
  216.    procedure Set_Ts_Origin (GC : Gdk_GC; X, Y : Gint); 
  217.    --  Set the Tile and Stipple origin in the graphic context. 
  218.  
  219.    procedure Set_Clip_Origin (GC : Gdk_GC; X, Y : Gint); 
  220.    --  Set the origin of the clip mask. 
  221.    --  See the functions Set_Clip_Rectangle, Set_Clip_Region and 
  222.    --  Gdk.Bitmap.Set_Clip_Mask for more explanation. 
  223.  
  224.    procedure Set_Clip_Mask (GC : Gdk.GC.Gdk_GC; Mask : Gdk.Gdk_Bitmap); 
  225.    --  If Mask is set to Null_Bitmap, then no clip_mask is used for drawing. 
  226.    --  Points will be drawn through this GC only where the bits are set to 1 
  227.    --  in the mask. See also the function Set_Clip_Origin for 
  228.    --  how to move the mask inside the GC. 
  229.  
  230.    procedure Set_Clip_Rectangle 
  231.      (GC : Gdk_GC; Rectangle : Gdk.Rectangle.Gdk_Rectangle); 
  232.    procedure Set_Clip_Rectangle 
  233.      (GC : Gdk_GC; Rectangle : Gdk.Rectangle.Gdk_Rectangle_Access := null); 
  234.    --  Set the clip rectangle. 
  235.    --  Only the points that are drawn inside this rectangle will be displayed 
  236.    --  on the screen. The clip origin is modified automatically. 
  237.    --  See Set_Clip_Mask to delete the current clip mask. 
  238.  
  239.    procedure Set_Clip_Region (GC : Gdk_GC; Region : Gdk.Region.Gdk_Region); 
  240.    --  Define a clip region on the screen. 
  241.    --  This is just like Set_Clip_Rectangle, except that a region is a more 
  242.    --  complex region, that can be the intersection or union of multiple 
  243.    --  rectangles. Note that the Clip_Origin can have an influence on this 
  244.    --  function. 
  245.  
  246.    procedure Set_Subwindow (GC : Gdk_GC; Mode : Gdk_Subwindow_Mode); 
  247.    --  Set the subwindow mode for the graphic context. 
  248.    --  This specifies whether the drawing routines should be clipped to 
  249.    --  the specific window they are drawn into, or if they should extend 
  250.    --  to subwindows as well. 
  251.  
  252.    procedure Set_Exposures (GC : Gdk_GC; Exposures : Boolean); 
  253.    --  Exposures indicates whether you want "expose" and "noexpose" events to 
  254.    --  be reported when calling Copy_Area and Copy_Plane with this GC. 
  255.    --  You should disable this if you don't need the event and want to optimize 
  256.    --  your application. 
  257.    --  If Exposures is True, then any call to Copy_Area or Draw_Pixmap will 
  258.    --  generate an expose event. Otherwise, these will generate a no_expose 
  259.    --  event. 
  260.  
  261.    procedure Set_Line_Attributes 
  262.      (GC         : Gdk_GC; 
  263.       Line_Width : Gint; 
  264.       Line_Style : Gdk_Line_Style; 
  265.       Cap_Style  : Gdk_Cap_Style; 
  266.       Join_Style : Gdk_Join_Style); 
  267.    --  Set the line attributes for this GC. 
  268.    --  Line_Width is the width of the line. If its value is 0, the line is as 
  269.    --  thin as possible, possibly even more so than if the width is 1. It is 
  270.    --  also faster to draw a line with width 0 than any other line width. 
  271.    -- 
  272.    --  Line_Style specifies whether the line should be solid or dashed. 
  273.    --  With Line_On_Off_Dash, the colors are alternatively the foreground 
  274.    --  color, and blank. With Line_Double_Dash, the colors are 
  275.    --  alternatively the foreground and background colors. 
  276.    -- 
  277.    --  Cap_Style specifies how the line should end, either flat or rounded. 
  278.    -- 
  279.    --  Join_Style specifies how two consecutive lines drawn by Draw_Lines are 
  280.    --  connected. 
  281.  
  282.    procedure Set_Dashes 
  283.      (Gc          : Gdk_GC; 
  284.       Dash_Offset : Gint; 
  285.       Dash_List   : Guchar_Array); 
  286.    --  Specify the dash pattern when the line's style is anything but solid. 
  287.    --  The values in the array alternatively give the length (in pixels) of 
  288.    --  the plain dash, the empty dash, the second plain dash, ... None of 
  289.    --  these values can be 0. If there is an odd number of items in Dash_List, 
  290.    --  this is equivalent to giving the array concatenated with itself. 
  291.    --  Dash_Offset specifies the phase of the pattern to start with. 
  292.  
  293.    procedure Copy (Dst_GC : Gdk_GC; Src_GC : Gdk_GC); 
  294.    --  Copy a Src_GC to Dst_GC. 
  295.  
  296.    procedure Set_Colormap (Gc : Gdk_GC; Colormap : Gdk.Gdk_Colormap); 
  297.  
  298.    function Get_Colormap (Gc : Gdk_GC) return Gdk.Gdk_Colormap; 
  299.  
  300.    procedure Set_Rgb_Fg_Color (Gc : Gdk_GC; Color : Gdk.Color.Gdk_Color); 
  301.  
  302.    procedure Set_Rgb_Bg_Color (Gc : Gdk_GC; Color : Gdk.Color.Gdk_Color); 
  303.  
  304.    ---------------------- 
  305.    -- Gdk_Color_Values -- 
  306.    ---------------------- 
  307.  
  308.    function Gdk_New return Gdk_GC_Values; 
  309.    --  Allocate a new Values structure on the client. 
  310.    --  Note that this function allocates a C structure, and thus needs to 
  311.    --  be freed with a call to Free below. 
  312.  
  313.    procedure Free (Values : Gdk_GC_Values); 
  314.    --  Free the C structure associated with Values. 
  315.  
  316.    procedure Set_Foreground 
  317.      (Values : Gdk_GC_Values; Color : Gdk.Color.Gdk_Color); 
  318.    --  Same as Set_Foreground, but on the client side 
  319.  
  320.    procedure Set_Background 
  321.      (Values : Gdk_GC_Values; Color : Gdk.Color.Gdk_Color); 
  322.    --  Same as Set_Background, but on the client side 
  323.  
  324.    procedure Set_Font (Values : Gdk_GC_Values; Font : Gdk.Font.Gdk_Font); 
  325.    --  Same as Set_Font, but on the client side 
  326.  
  327.    procedure Set_Function (Values : Gdk_GC_Values; Func : Gdk_Function); 
  328.    --  Same as Set_Function, but on the client side 
  329.  
  330.    procedure Set_Fill (Values : Gdk_GC_Values; Fill : Gdk_Fill); 
  331.    --  Same as Set_Fill, but on the client side 
  332.  
  333.    procedure Set_Ts_Origin 
  334.      (Values : Gdk_GC_Values; 
  335.       X, Y   : Gint); 
  336.    --  Same as Set_Ts_Origin, but on the client side 
  337.  
  338.    procedure Set_Clip_Origin 
  339.      (Values : Gdk_GC_Values; 
  340.       X, Y   : Gint); 
  341.    --  Same as Set_Clip_Origin, but on the client side 
  342.  
  343.    procedure Set_Subwindow 
  344.      (Values : Gdk_GC_Values; 
  345.       Mode   : Gdk_Subwindow_Mode); 
  346.    --  Same as Set_Subwindow, but on the client side 
  347.  
  348.    procedure Set_Exposures (Values : Gdk_GC_Values; Exposures : Boolean); 
  349.    --  Same as Set_Exposures, but on the client side 
  350.  
  351.    procedure Set_Line_Attributes 
  352.      (Values     : Gdk_GC_Values; 
  353.       Line_Width : Gint; 
  354.       Line_Style : Gdk_Line_Style; 
  355.       Cap_Style  : Gdk_Cap_Style; 
  356.       Join_Style : Gdk_Join_Style); 
  357.    --  Same as Set_Line_Attributes, but on the client side 
  358.  
  359. private 
  360.    pragma Import (C, Get_Type, "gdk_gc_get_type"); 
  361.    pragma Import (C, Copy, "gdk_gc_copy"); 
  362.    pragma Import (C, Destroy, "gdk_gc_unref"); 
  363.    pragma Import (C, Free, "ada_gdk_gc_free_values"); 
  364.    pragma Import (C, Get_Values, "gdk_gc_get_values"); 
  365.    pragma Import (C, Set_Values, "gdk_gc_set_values"); 
  366.    pragma Import (C, Ref, "gdk_gc_ref"); 
  367.    pragma Import (C, Unref, "gdk_gc_unref"); 
  368.    pragma Import (C, Set_Clip_Rectangle, "gdk_gc_set_clip_rectangle"); 
  369.    pragma Import (C, Set_Clip_Region, "gdk_gc_set_clip_region"); 
  370.    pragma Import (C, Set_Stipple, "gdk_gc_set_stipple"); 
  371.    pragma Import (C, Set_Tile, "gdk_gc_set_tile"); 
  372.    pragma Import (C, Set_Clip_Mask, "gdk_gc_set_clip_mask"); 
  373.    pragma Import (C, Set_Colormap, "gdk_gc_set_colormap"); 
  374.    pragma Import (C, Get_Colormap, "gdk_gc_get_colormap"); 
  375.    pragma Import (C, Set_Rgb_Fg_Color, "gdk_gc_set_rgb_fg_color"); 
  376.    pragma Import (C, Set_Rgb_Bg_Color, "gdk_gc_set_rgb_bg_color"); 
  377. end Gdk.GC;