agpl_1.0.0_b5da3320/src/agpl-gdk/agpl-gdk-palette.ads

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
--  This object is intended to encapsulate all needs for colors and GC in a
--  controlled way.

with Agpl.Types;

with Gdk.Color;    use Gdk.Color;
with Gdk.Drawable; use Gdk.Drawable;
with Gdk.GC;       use Gdk.GC;

with Ada.Containers.Indefinite_Ordered_Maps;
with Ada.Finalization;

package Agpl.Gdk.Palette is

   --  pragma Elaborate_Body;

   type Object is tagged private;

   function Create (Gd : Gdk_Drawable) return Object;
   --  As Set_Drawable, for creation

   procedure Set_Drawable (This : in out Object; X : in Gdk_Drawable);
   --  Replaces the drawable in use. It will cause invalidation of all
   --  allocated resources in the former one.

   function Get_Color (This : access Object; Color : in String)
                       return Gdk_Color;
   pragma Precondition (Color /= "");
   --  Allocates if necessary from default color map.
   --  Color must be a valid gdk parseable string (e.g. "#ffffff" for white).

   function Get_Color (This  : access Object;
                       Color : in String) return Gdk_GC;
   pragma Precondition (Color /= "");
   --  Allocates if necessary from default color map.
   --  Color must be a valid gdk parseable string (e.g. "#ffffff" for white).
   --  It gives an allocated GC instead of a color, ready for drawing.

   function Get_Gc (This       : access Object;
                    Color      : in     String;
                    Line_Width : in     Integer        := 1;
                    Line_Style : in     Gdk_Line_Style := Line_Solid)
                    return              Gdk_GC;
   pragma Precondition (Color /= "");
   --  As previous, but with more options for line effects/fills

   function Get_Color (This : in Object; Color : in String) return Gdk_Color;
   pragma Precondition (Color /= "");

   function Get_Color (This : in Object; Color : in String) return Gdk_GC;
   pragma Precondition (Color /= "");
   --  As the two previous, but using 'Unrestricted_Access on This.
   --  So these two are GNAT specific.

   subtype Rgb_Component is Types.Unsigned_8;

   function Get_Color_Name (R, G, B : Rgb_Component) return String;

   function Get_Gradient (Val_In_Domain                : Float;
                          Min_In_Domain, Max_In_Domain : Float;
                          Min_In_Rgb,    Max_In_Rgb    : Rgb_Component)
                          return Rgb_Component;

   generic
      type Domain_range is digits <>;
      Rgb_Min : Rgb_Component;
      Rgb_Max : Rgb_Component; -- Min can be > Max, to reverse the gradient
   function Gradient (Val : Domain_Range'Base) return Rgb_Component;

private

   use type Gdk_GC;

   package Color_Maps is new Ada.Containers.Indefinite_Ordered_Maps
     (String, Gdk_Color);

   package Gc_Maps is new Ada.Containers.Indefinite_Ordered_Maps
     (String, Gdk_Gc);

   type Object is new Ada.Finalization.Controlled with
      record
         Drawable : Gdk_Drawable;

         Colors   : Color_Maps.Map;
         Gcs      : Gc_Maps.Map;
      end record;

   procedure Initialize (This : in out Object);
   procedure Adjust   (This : in out Object);
   procedure Finalize (This : in out Object);

end Agpl.Gdk.Palette;