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