1. ----------------------------------------------------------------------- 
  2. --               GtkAda - Ada95 binding for Gtk+/Gnome               -- 
  3. --                                                                   -- 
  4. --                 Copyright (C) 2011, 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. -- -- -- -- -- -- -- -- -- -- -- --
  22. ----------------------------------------------------------------------- 
  23.  
  24. --  <description> 
  25. --  Utility functions that mimic Gtk.Style drawing methods, but using Cairo 
  26. --  instead of Gdk. This allow smooth transition to Gtk3 that will get rid 
  27. --  of those Gdk drawing methods and only use Cairo. 
  28. --  </description> 
  29. --  <group>Configuration and Themes</group> 
  30.  
  31. with Glib; 
  32.  
  33. with Cairo; 
  34.  
  35. with Pango.Layout; 
  36.  
  37. with Gdk.Color; 
  38. with Gdk.Pixbuf; 
  39.  
  40. with Gtk.Enums; 
  41. with Gtk.Style; 
  42.  
  43. package Gtkada.Style is 
  44.  
  45.    -------------------- 
  46.    -- Color handling -- 
  47.    -------------------- 
  48.  
  49.    subtype Cairo_Color_Val is Glib.Gdouble range 0.0 .. 1.0; 
  50.    --  In cairo, the color components are expressed as percents. 
  51.  
  52.    type Cairo_Color is record 
  53.       R, G, B : Cairo_Color_Val; 
  54.       Alpha   : Cairo_Color_Val := 1.0; 
  55.    end record; 
  56.  
  57.    type HSV_Color is record 
  58.       H, S, V, A : Cairo_Color_Val; 
  59.    end record; 
  60.    --  Used when manipulating Cairo color. The HSV color space is useful when 
  61.    --  wanting to shade a color (change it's value), (de)saturate it, or modify 
  62.    --  its hue. 
  63.  
  64.    function To_HSV (Color   : Cairo_Color) return HSV_Color; 
  65.    function To_Cairo (HSV : HSV_Color) return Cairo_Color; 
  66.    function To_Cairo (Color : Gdk.Color.Gdk_Color) return Cairo_Color; 
  67.    --  Translations between one color definition to another 
  68.  
  69.    function Shade 
  70.      (Color : Gdk.Color.Gdk_Color; 
  71.       Value : Glib.Gdouble) return Cairo_Color; 
  72.    function Shade 
  73.      (Color : Cairo_Color; 
  74.       Value : Glib.Gdouble) return Cairo_Color; 
  75.    --  Modifies the lightning of the color by the specified value 
  76.  
  77.    procedure Set_Source_Color 
  78.      (Cr : Cairo.Cairo_Context; Color : Cairo_Color); 
  79.  
  80.    ----------------------------- 
  81.    -- Extra path manipulation -- 
  82.    ----------------------------- 
  83.  
  84.    procedure Rounded_Rectangle 
  85.      (Cr         : Cairo.Cairo_Context; 
  86.       X, Y, W, H : Glib.Gdouble; 
  87.       Radius     : Glib.Gdouble); 
  88.    --  Draws a rounded rectangle at coordinate X, Y with W and H size. 
  89.    --  If Radius > 0, then the corner will be rounded. 
  90.  
  91.    ------------------------- 
  92.    -- Drawing subprograms -- 
  93.    ------------------------- 
  94.  
  95.    procedure Draw_Shadow 
  96.      (Cr                  : Cairo.Cairo_Context; 
  97.       Style               : Gtk.Style.Gtk_Style; 
  98.       Shadow_Type         : Gtk.Enums.Gtk_Shadow_Type; 
  99.       X, Y, Width, Height : Glib.Gint; 
  100.       Corner_Radius       : Glib.Gdouble := 0.0); 
  101.    --  Draws a Frame of size Width x Height at position (X, Y) and (X2, Y2) 
  102.    --  using the specified color. 
  103.    --  Corner_Radius allows you to draw a rounded frame if set to a value > 0. 
  104.    -- 
  105.    --  Additional drawing styles can be specified by using Cairo.Set_Line_XXXX 
  106.    --  on the Cairo_Context before calling this procedure. 
  107.  
  108.    procedure Draw_Rectangle 
  109.      (Cr                  : Cairo.Cairo_Context; 
  110.       Color               : Cairo_Color; 
  111.       Filled              : Boolean; 
  112.       X, Y, Width, Height : Glib.Gint; 
  113.       Corner_Radius       : Glib.Gdouble := 0.0); 
  114.    procedure Draw_Rectangle 
  115.      (Cr                  : Cairo.Cairo_Context; 
  116.       Color               : Gdk.Color.Gdk_Color; 
  117.       Filled              : Boolean; 
  118.       X, Y, Width, Height : Glib.Gint; 
  119.       Corner_Radius       : Glib.Gdouble := 0.0); 
  120.    --  Draws a rectangle of size Width x Height at position (X, Y) and (X2, Y2) 
  121.    --  using the specified color. 
  122.    --  Corner_Radius allows you to draw a rounded rectangle if set to a 
  123.    --  value > 0.0 
  124.    -- 
  125.    --  Additional drawing styles can be specified by using Cairo.Set_Line_XXXX 
  126.    --  on the Cairo_Context before calling this procedure. 
  127.  
  128.    procedure Draw_Line 
  129.      (Cr             : Cairo.Cairo_Context; 
  130.       Color          : Cairo_Color; 
  131.       X1, Y1, X2, Y2 : Glib.Gint); 
  132.    procedure Draw_Line 
  133.      (Cr             : Cairo.Cairo_Context; 
  134.       Color          : Gdk.Color.Gdk_Color; 
  135.       X1, Y1, X2, Y2 : Glib.Gint); 
  136.    --  Draws a line between (X1, Y1) and (X2, Y2) using the specified color. 
  137.    -- 
  138.    --  Additional drawing styles can be specified by using Cairo.Set_Line_XXXX 
  139.    --  on the Cairo_Context before calling this procedure. 
  140.  
  141.    procedure Draw_Layout 
  142.      (Cr     : Cairo.Cairo_Context; 
  143.       Color  : Cairo_Color; 
  144.       X, Y   : Glib.Gint; 
  145.       Layout : Pango.Layout.Pango_Layout); 
  146.    procedure Draw_Layout 
  147.      (Cr     : Cairo.Cairo_Context; 
  148.       Color  : Gdk.Color.Gdk_Color; 
  149.       X, Y   : Glib.Gint; 
  150.       Layout : Pango.Layout.Pango_Layout); 
  151.    --  Draws the Pango layout at position (X, Y) using Color. 
  152.  
  153.    procedure Draw_Pixbuf 
  154.      (Cr     : Cairo.Cairo_Context; 
  155.       Pixbuf : Gdk.Pixbuf.Gdk_Pixbuf; 
  156.       X, Y   : Glib.Gint); 
  157.    --  Draws a pixbuf at coordinate X, Y 
  158.    -- 
  159.    --  Note that Gdk_Pixmap or Gdk_Bitmap are not supported, as those 
  160.    --  are server-side images, so depend on a surface attached to a screen. 
  161.    --  As a result, those would not be drawn on a non-screen surface (such as 
  162.    --  an internal Image_Surface). 
  163.  
  164. end Gtkada.Style;