]> Pileus Git - ~andy/gtk/blob - gdk/gdkdraw.c
applied patch from Andreas Persenius <ndap@swipnet.se> that updates the
[~andy/gtk] / gdk / gdkdraw.c
1 /* GDK - The GIMP Drawing Kit
2  * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with this library; if not, write to the
16  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17  * Boston, MA 02111-1307, USA.
18  */
19
20 /*
21  * Modified by the GTK+ Team and others 1997-2000.  See the AUTHORS
22  * file for a list of people on the GTK+ Team.  See the ChangeLog
23  * files for a list of changes.  These files are distributed with
24  * GTK+ at ftp://ftp.gtk.org/pub/gtk/. 
25  */
26
27 #include "gdkdrawable.h"
28 #include "gdkinternals.h"
29 #include "gdkwindow.h"
30
31 GType
32 gdk_drawable_get_type (void)
33 {
34   static GType object_type = 0;
35
36   if (!object_type)
37     {
38       static const GTypeInfo object_info =
39       {
40         sizeof (GdkDrawableClass),
41         (GBaseInitFunc) NULL,
42         (GBaseFinalizeFunc) NULL,
43         (GClassInitFunc) NULL,
44         NULL,           /* class_finalize */
45         NULL,           /* class_data */
46         sizeof (GdkDrawable),
47         0,              /* n_preallocs */
48         (GInstanceInitFunc) NULL,
49       };
50       
51       object_type = g_type_register_static (G_TYPE_OBJECT,
52                                             "GdkDrawable",
53                                             &object_info);
54     }  
55
56   return object_type;
57 }
58
59 /* Manipulation of drawables
60  */
61
62 void          
63 gdk_drawable_set_data (GdkDrawable   *drawable,
64                        const gchar   *key,
65                        gpointer       data,
66                        GDestroyNotify destroy_func)
67 {
68   g_return_if_fail (GDK_IS_DRAWABLE (drawable));
69   
70   g_object_set_qdata_full (G_OBJECT (drawable),
71                            g_quark_from_string (key),
72                            data,
73                            destroy_func);
74 }
75
76 gpointer
77 gdk_drawable_get_data (GdkDrawable   *drawable,
78                        const gchar   *key)
79 {
80   g_return_val_if_fail (GDK_IS_DRAWABLE (drawable), NULL);
81   
82   return g_object_get_qdata (G_OBJECT (drawable),
83                              g_quark_try_string (key));
84 }
85
86 void
87 gdk_drawable_get_size (GdkDrawable *drawable,
88                        gint        *width,
89                        gint        *height)
90 {
91   g_return_if_fail (GDK_IS_DRAWABLE (drawable));
92
93   GDK_DRAWABLE_GET_CLASS (drawable)->get_size (drawable, width, height);  
94 }
95
96 GdkVisual*
97 gdk_drawable_get_visual (GdkDrawable *drawable)
98 {
99   g_return_val_if_fail (GDK_IS_DRAWABLE (drawable), NULL);
100   
101   return GDK_DRAWABLE_GET_CLASS (drawable)->get_visual (drawable);
102 }
103
104 gint
105 gdk_drawable_get_depth (GdkDrawable *drawable)
106 {
107   g_return_val_if_fail (GDK_IS_DRAWABLE (drawable), 0);
108
109   return GDK_DRAWABLE_GET_CLASS (drawable)->get_depth (drawable);
110 }
111
112 void
113 gdk_drawable_set_colormap (GdkDrawable *drawable,
114                            GdkColormap *cmap)
115 {
116   g_return_if_fail (GDK_IS_DRAWABLE (drawable));
117
118   GDK_DRAWABLE_GET_CLASS (drawable)->set_colormap (drawable, cmap);
119 }
120
121 GdkColormap*
122 gdk_drawable_get_colormap (GdkDrawable *drawable)
123 {
124   g_return_val_if_fail (GDK_IS_DRAWABLE (drawable), NULL);
125
126   return GDK_DRAWABLE_GET_CLASS (drawable)->get_colormap (drawable);
127 }
128
129 GdkDrawable*
130 gdk_drawable_ref (GdkDrawable *drawable)
131 {
132   return (GdkDrawable *) g_object_ref (G_OBJECT (drawable));
133 }
134
135 void
136 gdk_drawable_unref (GdkDrawable *drawable)
137 {
138   g_return_if_fail (GDK_IS_DRAWABLE (drawable));
139
140   g_object_unref (G_OBJECT (drawable));
141 }
142
143 /* Drawing
144  */
145 void
146 gdk_draw_point (GdkDrawable *drawable,
147                 GdkGC       *gc,
148                 gint         x,
149                 gint         y)
150 {
151   GdkPoint point;
152
153   g_return_if_fail (GDK_IS_DRAWABLE (drawable));
154   g_return_if_fail (GDK_IS_GC (gc));
155
156   point.x = x;
157   point.y = y;
158   
159   GDK_DRAWABLE_GET_CLASS (drawable)->draw_points (drawable, gc, &point, 1);
160 }
161
162 void
163 gdk_draw_line (GdkDrawable *drawable,
164                GdkGC       *gc,
165                gint         x1,
166                gint         y1,
167                gint         x2,
168                gint         y2)
169 {
170   GdkSegment segment;
171
172   g_return_if_fail (drawable != NULL);
173   g_return_if_fail (gc != NULL);
174   g_return_if_fail (GDK_IS_DRAWABLE (drawable));
175   g_return_if_fail (GDK_IS_GC (gc));
176
177   segment.x1 = x1;
178   segment.y1 = y1;
179   segment.x2 = x2;
180   segment.y2 = y2;
181   GDK_DRAWABLE_GET_CLASS (drawable)->draw_segments (drawable, gc, &segment, 1);
182 }
183
184 void
185 gdk_draw_rectangle (GdkDrawable *drawable,
186                     GdkGC       *gc,
187                     gint         filled,
188                     gint         x,
189                     gint         y,
190                     gint         width,
191                     gint         height)
192 {  
193   g_return_if_fail (GDK_IS_DRAWABLE (drawable));
194   g_return_if_fail (GDK_IS_GC (gc));
195
196   if (width < 0 || height < 0)
197     {
198       gint real_width;
199       gint real_height;
200       
201       gdk_drawable_get_size (drawable, &real_width, &real_height);
202
203       if (width < 0)
204         width = real_width;
205       if (height < 0)
206         height = real_height;
207     }
208
209   GDK_DRAWABLE_GET_CLASS (drawable)->draw_rectangle (drawable, gc, filled, x, y,
210                                                      width, height);
211 }
212
213 void
214 gdk_draw_arc (GdkDrawable *drawable,
215               GdkGC       *gc,
216               gint         filled,
217               gint         x,
218               gint         y,
219               gint         width,
220               gint         height,
221               gint         angle1,
222               gint         angle2)
223 {  
224   g_return_if_fail (GDK_IS_DRAWABLE (drawable));
225   g_return_if_fail (GDK_IS_GC (gc));
226
227   if (width < 0 || height < 0)
228     {
229       gint real_width;
230       gint real_height;
231       
232       gdk_drawable_get_size (drawable, &real_width, &real_height);
233
234       if (width < 0)
235         width = real_width;
236       if (height < 0)
237         height = real_height;
238     }
239
240   GDK_DRAWABLE_GET_CLASS (drawable)->draw_arc (drawable, gc, filled,
241                                                x, y, width, height, angle1, angle2);
242 }
243
244 void
245 gdk_draw_polygon (GdkDrawable *drawable,
246                   GdkGC       *gc,
247                   gint         filled,
248                   GdkPoint    *points,
249                   gint         npoints)
250 {
251   g_return_if_fail (GDK_IS_DRAWABLE (drawable));
252   g_return_if_fail (GDK_IS_GC (gc));
253
254   GDK_DRAWABLE_GET_CLASS (drawable)->draw_polygon (drawable, gc, filled,
255                                                    points, npoints);
256 }
257
258 /* gdk_draw_string
259  *
260  * Modified by Li-Da Lho to draw 16 bits and Multibyte strings
261  *
262  * Interface changed: add "GdkFont *font" to specify font or fontset explicitely
263  */
264 void
265 gdk_draw_string (GdkDrawable *drawable,
266                  GdkFont     *font,
267                  GdkGC       *gc,
268                  gint         x,
269                  gint         y,
270                  const gchar *string)
271 {
272   gdk_draw_text (drawable, font, gc, x, y, string, _gdk_font_strlen (font, string));
273 }
274
275 /* gdk_draw_text
276  *
277  * Modified by Li-Da Lho to draw 16 bits and Multibyte strings
278  *
279  * Interface changed: add "GdkFont *font" to specify font or fontset explicitely
280  */
281 void
282 gdk_draw_text (GdkDrawable *drawable,
283                GdkFont     *font,
284                GdkGC       *gc,
285                gint         x,
286                gint         y,
287                const gchar *text,
288                gint         text_length)
289 {
290   g_return_if_fail (GDK_IS_DRAWABLE (drawable));
291   g_return_if_fail (font != NULL);
292   g_return_if_fail (GDK_IS_GC (gc));
293   g_return_if_fail (text != NULL);
294
295   GDK_DRAWABLE_GET_CLASS (drawable)->draw_text (drawable, font, gc, x, y, text, text_length);
296 }
297
298 void
299 gdk_draw_text_wc (GdkDrawable    *drawable,
300                   GdkFont        *font,
301                   GdkGC          *gc,
302                   gint            x,
303                   gint            y,
304                   const GdkWChar *text,
305                   gint            text_length)
306 {
307   g_return_if_fail (GDK_IS_DRAWABLE (drawable));
308   g_return_if_fail (font != NULL);
309   g_return_if_fail (GDK_IS_GC (gc));
310   g_return_if_fail (text != NULL);
311
312   GDK_DRAWABLE_GET_CLASS (drawable)->draw_text_wc (drawable, font, gc, x, y, text, text_length);
313 }
314
315 void
316 gdk_draw_drawable (GdkDrawable *drawable,
317                    GdkGC       *gc,
318                    GdkDrawable *src,
319                    gint         xsrc,
320                    gint         ysrc,
321                    gint         xdest,
322                    gint         ydest,
323                    gint         width,
324                    gint         height)
325 {
326   g_return_if_fail (GDK_IS_DRAWABLE (drawable));
327   g_return_if_fail (src != NULL);
328   g_return_if_fail (GDK_IS_GC (gc));
329
330   if (width < 0 || height < 0)
331     {
332       gint real_width;
333       gint real_height;
334       
335       gdk_drawable_get_size (src, &real_width, &real_height);
336
337       if (width < 0)
338         width = real_width;
339       if (height < 0)
340         height = real_height;
341     }
342
343   GDK_DRAWABLE_GET_CLASS (drawable)->draw_drawable (drawable, gc, src,
344                                                     xsrc, ysrc, xdest, ydest,
345                                                     width, height);
346 }
347
348 void
349 gdk_draw_image (GdkDrawable *drawable,
350                 GdkGC       *gc,
351                 GdkImage    *image,
352                 gint         xsrc,
353                 gint         ysrc,
354                 gint         xdest,
355                 gint         ydest,
356                 gint         width,
357                 gint         height)
358 {
359   g_return_if_fail (GDK_IS_DRAWABLE (drawable));
360   g_return_if_fail (image != NULL);
361   g_return_if_fail (GDK_IS_GC (gc));
362
363   if (width == -1)
364     width = image->width;
365   if (height == -1)
366     height = image->height;
367
368   GDK_DRAWABLE_GET_CLASS (drawable)->draw_image (drawable, gc, image, xsrc, ysrc,
369                                                  xdest, ydest, width, height);
370 }
371
372 void
373 gdk_draw_points (GdkDrawable *drawable,
374                  GdkGC       *gc,
375                  GdkPoint    *points,
376                  gint         npoints)
377 {
378   g_return_if_fail (GDK_IS_DRAWABLE (drawable));
379   g_return_if_fail ((points != NULL) && (npoints > 0));
380   g_return_if_fail (GDK_IS_GC (gc));
381   g_return_if_fail (npoints >= 0);
382
383   if (npoints == 0)
384     return;
385
386   GDK_DRAWABLE_GET_CLASS (drawable)->draw_points (drawable, gc, points, npoints);
387 }
388
389 void
390 gdk_draw_segments (GdkDrawable *drawable,
391                    GdkGC       *gc,
392                    GdkSegment  *segs,
393                    gint         nsegs)
394 {
395   g_return_if_fail (GDK_IS_DRAWABLE (drawable));
396
397   if (nsegs == 0)
398     return;
399
400   g_return_if_fail (segs != NULL);
401   g_return_if_fail (GDK_IS_GC (gc));
402   g_return_if_fail (nsegs >= 0);
403
404   GDK_DRAWABLE_GET_CLASS (drawable)->draw_segments (drawable, gc, segs, nsegs);
405 }
406
407 void
408 gdk_draw_lines (GdkDrawable *drawable,
409                 GdkGC       *gc,
410                 GdkPoint    *points,
411                 gint         npoints)
412 {
413
414   g_return_if_fail (GDK_IS_DRAWABLE (drawable));
415   g_return_if_fail (points != NULL);
416   g_return_if_fail (GDK_IS_GC (gc));
417   g_return_if_fail (npoints >= 0);
418
419   if (npoints == 0)
420     return;
421
422   GDK_DRAWABLE_GET_CLASS (drawable)->draw_lines (drawable, gc, points, npoints);
423 }
424
425 void
426 gdk_draw_glyphs (GdkDrawable      *drawable,
427                  GdkGC            *gc,
428                  PangoFont        *font,
429                  gint              x,
430                  gint              y,
431                  PangoGlyphString *glyphs)
432 {
433
434   g_return_if_fail (GDK_IS_DRAWABLE (drawable));
435   g_return_if_fail (GDK_IS_GC (gc));
436
437
438   GDK_DRAWABLE_GET_CLASS (drawable)->draw_glyphs (drawable, gc, font, x, y, glyphs);
439 }
440
441