File: create_gc.adb

package info (click to toggle)
libgtkada2 2.8.1-6lenny3
  • links: PTS, VCS
  • area: main
  • in suites: lenny
  • size: 13,496 kB
  • ctags: 3,886
  • sloc: ada: 103,189; ansic: 45,411; perl: 5,500; sh: 2,812; makefile: 1,169; xml: 19
file content (200 lines) | stat: -rw-r--r-- 6,422 bytes parent folder | download | duplicates (2)
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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200

with Glib;         use Glib;
with Gdk.GC;       use Gdk.GC;
with Gdk.Color;    use Gdk.Color;
with Gdk.Drawable; use Gdk.Drawable;
with Gdk.Event;    use Gdk.Event;
with Gdk.Font;     use Gdk.Font;
with Gdk.Types;    use Gdk.Types;
with Gtk.Frame;    use Gtk.Frame;
with Gtk.Drawing_Area; use Gtk.Drawing_Area;
with Gtk.Handlers; use Gtk.Handlers;
with Gtk.Widget;   use Gtk.Widget;

package body Create_Gc is

   package Event_Cb is new Gtk.Handlers.Return_Callback
     (Gtk_Drawing_Area_Record, Boolean);

   Gc   : Gdk_GC;
   Font : Gdk_Font;
   Blue : Gdk_Color;
   Red  : Gdk_Color;

   ----------
   -- Help --
   ----------

   function Help return String is
   begin
      return "This demo shows some of the aspects of the graphic contexts"
        & " that you can set before calling the drawing functions in"
        & " @bGdk.Drawable@B."
        & ASCII.LF
        & "In all theses demos, the foreground is set to a blue color, whereas"
        & " the background is set to red.";
   end Help;

   ------------------------
   -- Draw_Text_And_Line --
   ------------------------

   procedure Draw_Text_And_Line
     (Area      : access Gtk_Drawing_Area_Record'Class;
      Y         : Gint;
      Text      : String;
      Num_Lines : Positive := 1) is
   begin
      Draw_Text
        (Drawable => Get_Window (Area),
         Font     => Font,
         Gc       => Gc,
         X        => 3,
         Y        => Y,
         Text     => Text);

      if Num_Lines = 1 then
         Draw_Line
           (Drawable => Get_Window (Area),
            Gc       => Gc,
            X1       => 10,
            Y1       => Y + 7,
            X2       => 200,
            Y2       => Y + 7);

      else
         Draw_Lines
           (Drawable => Get_Window (Area),
            Gc       => Gc,
            Points   => ((10,  Y + 7),
                         (200, Y + 7),
                         (250, Y + 50)));
      end if;
   end Draw_Text_And_Line;

   ------------
   -- Expose --
   ------------

   function Expose
     (Area  : access Gtk_Drawing_Area_Record'Class;
      Event : Gdk_Event)
      return Boolean
   is
      pragma Warnings (Off, Event);
   begin
      Set_Foreground (Gc, Blue);
      Set_Background (Gc, Red);

      Set_Line_Attributes (Gc,
                           Line_Width => 8,
                           Line_Style => Line_Solid,
                           Cap_Style  => Cap_Butt,
                           Join_Style => Join_Miter);
      Draw_Text_And_Line (Area, 15, "Cap_Style = Cap_Butt");

      Set_Line_Attributes (Gc,
                           Line_Width => 8,
                           Line_Style => Line_Solid,
                           Cap_Style  => Cap_Projecting,
                           Join_Style => Join_Miter);
      Draw_Text_And_Line (Area, 45, "Cap_Style = Cap_Projecting");

      Set_Line_Attributes (Gc,
                           Line_Width => 8,
                           Line_Style => Line_Solid,
                           Cap_Style  => Cap_Round,
                           Join_Style => Join_Miter);
      Draw_Text_And_Line (Area, 75, "Cap_Style = Cap_Round");

      Set_Line_Attributes (Gc,
                           Line_Width => 4,
                           Line_Style => Line_On_Off_Dash,
                           Cap_Style  => Cap_Butt,
                           Join_Style => Join_Miter);
      Draw_Text_And_Line (Area, 105, "Line_Style = Line_On_Off_Dash");

      Set_Line_Attributes (Gc,
                           Line_Width => 4,
                           Line_Style => Line_Double_Dash,
                           Cap_Style  => Cap_Butt,
                           Join_Style => Join_Miter);
      Draw_Text_And_Line (Area, 135, "Line_Style = Line_Double_Dash");

      Set_Line_Attributes (Gc,
                           Line_Width => 4,
                           Line_Style => Line_On_Off_Dash,
                           Cap_Style  => Cap_Butt,
                           Join_Style => Join_Miter);
      Set_Dashes (Gc,
                  Dash_Offset => 0,
                  Dash_List   => (2, 2, 4, 4, 6, 6));
      Draw_Text_And_Line (Area, 180, "Dashes set to (2,2,4,4,6,6)");

      Set_Dashes (Gc,
                  Dash_Offset => 0,
                  Dash_List   => (2, 2, 4, 4, 6));
      Draw_Text_And_Line (Area, 210, "Dashes set to (2,2,4,4,6)");

      Set_Line_Attributes (Gc,
                           Line_Width => 8,
                           Line_Style => Line_Solid,
                           Cap_Style  => Cap_Butt,
                           Join_Style => Join_Miter);
      Draw_Text_And_Line (Area, 250, "Join_Style = Join_Miter", 2);

      Set_Line_Attributes (Gc,
                           Line_Width => 8,
                           Line_Style => Line_Solid,
                           Cap_Style  => Cap_Butt,
                           Join_Style => Join_Round);
      Draw_Text_And_Line (Area, 300, "Join_Style = Join_Round", 2);

      Set_Line_Attributes (Gc,
                           Line_Width => 8,
                           Line_Style => Line_Solid,
                           Cap_Style  => Cap_Butt,
                           Join_Style => Join_Bevel);
      Draw_Text_And_Line (Area, 350, "Join_Style = Join_Bevel", 2);

      return False;
   end Expose;

   ---------
   -- Run --
   ---------

   procedure Run (Frame : access Gtk.Frame.Gtk_Frame_Record'Class) is
      Area    : Gtk_Drawing_Area;
      Success : Boolean;

   begin
      Gtk.Frame.Set_Label (Frame, "Graphic contexts");

      Gtk_New (Area);
      Set_USize (Area, 300, 500);
      Add (Frame, Area);
      Event_Cb.Connect (Area, "expose_event",
                        Event_Cb.To_Marshaller (Expose'Access));

      Show_All (Frame);

      Gdk_New (Gc, Get_Window (Area));
      Load (Font, "-*-courier-*-i-*-*-*-130-*-*-*-*-*-*");

      Blue := Gdk.Color.Parse ("Blue");
      Alloc_Color (Colormap   => Gtk.Widget.Get_Default_Colormap,
                   Color      => Blue,
                   Writeable  => False,
                   Best_Match => True,
                   Success    => Success);

      Red := Gdk.Color.Parse ("Red");
      Alloc_Color (Colormap   => Gtk.Widget.Get_Default_Colormap,
                   Color      => Red,
                   Writeable  => False,
                   Best_Match => True,
                   Success    => Success);
   end Run;

end Create_Gc;