]> Pileus Git - ~andy/gtk/blob - gdk/gdkdraw.c
Revert from "edit-preferences" to "gtk-preferences"
[~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 "config.h"
28 #include <math.h>
29 #include <pango/pangocairo.h>
30 #include <gdk-pixbuf/gdk-pixbuf.h>
31 #include "gdkcairo.h"
32 #include "gdkdrawable.h"
33 #include "gdkinternals.h"
34 #include "gdkwindow.h"
35 #include "gdkscreen.h"
36 #include "gdkpixbuf.h"
37
38
39 static cairo_region_t *  gdk_drawable_real_get_visible_region     (GdkDrawable  *drawable);
40      
41
42 G_DEFINE_ABSTRACT_TYPE (GdkDrawable, gdk_drawable, G_TYPE_OBJECT)
43
44 static void
45 gdk_drawable_class_init (GdkDrawableClass *klass)
46 {
47   /* Default implementation for clip and visible region is the same */
48   klass->get_clip_region = gdk_drawable_real_get_visible_region;
49   klass->get_visible_region = gdk_drawable_real_get_visible_region;
50 }
51
52 static void
53 gdk_drawable_init (GdkDrawable *drawable)
54 {
55 }
56
57 /* Manipulation of drawables
58  */
59
60 /**
61  * gdk_drawable_get_size:
62  * @drawable: a #GdkDrawable
63  * @width: (out) (allow-none): location to store drawable's width, or %NULL
64  * @height: (out) (allow-none): location to store drawable's height, or %NULL
65  *
66  * Fills *@width and *@height with the size of @drawable.
67  * @width or @height can be %NULL if you only want the other one.
68  *
69  * On the X11 platform, if @drawable is a #GdkWindow, the returned
70  * size is the size reported in the most-recently-processed configure
71  * event, rather than the current size on the X server.
72  * 
73  **/
74 void
75 gdk_drawable_get_size (GdkDrawable *drawable,
76                        gint        *width,
77                        gint        *height)
78 {
79   g_return_if_fail (GDK_IS_DRAWABLE (drawable));
80
81   GDK_DRAWABLE_GET_CLASS (drawable)->get_size (drawable, width, height);  
82 }
83
84 /**
85  * gdk_drawable_get_visual:
86  * @drawable: a #GdkDrawable
87  * 
88  * Gets the #GdkVisual describing the pixel format of @drawable.
89  * 
90  * Return value: a #GdkVisual
91  **/
92 GdkVisual*
93 gdk_drawable_get_visual (GdkDrawable *drawable)
94 {
95   g_return_val_if_fail (GDK_IS_DRAWABLE (drawable), NULL);
96   
97   return GDK_DRAWABLE_GET_CLASS (drawable)->get_visual (drawable);
98 }
99
100 /**
101  * gdk_drawable_get_depth:
102  * @drawable: a #GdkDrawable
103  * 
104  * Obtains the bit depth of the drawable, that is, the number of bits
105  * that make up a pixel in the drawable's visual. Examples are 8 bits
106  * per pixel, 24 bits per pixel, etc.
107  * 
108  * Return value: number of bits per pixel
109  **/
110 gint
111 gdk_drawable_get_depth (GdkDrawable *drawable)
112 {
113   g_return_val_if_fail (GDK_IS_DRAWABLE (drawable), 0);
114
115   return GDK_DRAWABLE_GET_CLASS (drawable)->get_depth (drawable);
116 }
117 /**
118  * gdk_drawable_get_screen:
119  * @drawable: a #GdkDrawable
120  * 
121  * Gets the #GdkScreen associated with a #GdkDrawable.
122  * 
123  * Return value: the #GdkScreen associated with @drawable
124  *
125  * Since: 2.2
126  **/
127 GdkScreen*
128 gdk_drawable_get_screen(GdkDrawable *drawable)
129 {
130   g_return_val_if_fail (GDK_IS_DRAWABLE (drawable), NULL);
131
132   return GDK_DRAWABLE_GET_CLASS (drawable)->get_screen (drawable);
133 }
134
135 /**
136  * gdk_drawable_get_display:
137  * @drawable: a #GdkDrawable
138  * 
139  * Gets the #GdkDisplay associated with a #GdkDrawable.
140  * 
141  * Return value: the #GdkDisplay associated with @drawable
142  *
143  * Since: 2.2
144  **/
145 GdkDisplay*
146 gdk_drawable_get_display (GdkDrawable *drawable)
147 {
148   g_return_val_if_fail (GDK_IS_DRAWABLE (drawable), NULL);
149   
150   return gdk_screen_get_display (gdk_drawable_get_screen (drawable));
151 }
152         
153 /**
154  * gdk_drawable_set_colormap:
155  * @drawable: a #GdkDrawable
156  * @colormap: a #GdkColormap
157  *
158  * Sets the colormap associated with @drawable. Normally this will
159  * happen automatically when the drawable is created; you only need to
160  * use this function if the drawable-creating function did not have a
161  * way to determine the colormap, and you then use drawable operations
162  * that require a colormap. The colormap for all drawables and
163  * graphics contexts you intend to use together should match.
164  **/
165 void
166 gdk_drawable_set_colormap (GdkDrawable *drawable,
167                            GdkColormap *cmap)
168 {
169   g_return_if_fail (GDK_IS_DRAWABLE (drawable));
170   g_return_if_fail (cmap == NULL || gdk_drawable_get_depth (drawable)
171                     == cmap->visual->depth);
172
173   GDK_DRAWABLE_GET_CLASS (drawable)->set_colormap (drawable, cmap);
174 }
175
176 /**
177  * gdk_drawable_get_colormap:
178  * @drawable: a #GdkDrawable
179  * 
180  * Gets the colormap for @drawable, if one is set; returns
181  * %NULL otherwise.
182  * 
183  * Return value: the colormap, or %NULL
184  **/
185 GdkColormap*
186 gdk_drawable_get_colormap (GdkDrawable *drawable)
187 {
188   g_return_val_if_fail (GDK_IS_DRAWABLE (drawable), NULL);
189
190   return GDK_DRAWABLE_GET_CLASS (drawable)->get_colormap (drawable);
191 }
192
193 /**
194  * gdk_drawable_get_clip_region:
195  * @drawable: a #GdkDrawable
196  * 
197  * Computes the region of a drawable that potentially can be written
198  * to by drawing primitives. This region will not take into account
199  * the clip region for the GC, and may also not take into account
200  * other factors such as if the window is obscured by other windows,
201  * but no area outside of this region will be affected by drawing
202  * primitives.
203  * 
204  * Returns: a #cairo_region_t. This must be freed with cairo_region_destroy()
205  *          when you are done.
206  **/
207 cairo_region_t *
208 gdk_drawable_get_clip_region (GdkDrawable *drawable)
209 {
210   g_return_val_if_fail (GDK_IS_DRAWABLE (drawable), NULL);
211
212   return GDK_DRAWABLE_GET_CLASS (drawable)->get_clip_region (drawable);
213 }
214
215 /**
216  * gdk_drawable_get_visible_region:
217  * @drawable: a #GdkDrawable
218  * 
219  * Computes the region of a drawable that is potentially visible.
220  * This does not necessarily take into account if the window is
221  * obscured by other windows, but no area outside of this region
222  * is visible.
223  * 
224  * Returns: a #cairo_region_t. This must be freed with cairo_region_destroy()
225  *          when you are done.
226  **/
227 cairo_region_t *
228 gdk_drawable_get_visible_region (GdkDrawable *drawable)
229 {
230   g_return_val_if_fail (GDK_IS_DRAWABLE (drawable), NULL);
231
232   return GDK_DRAWABLE_GET_CLASS (drawable)->get_visible_region (drawable);
233 }
234
235 static cairo_region_t *
236 gdk_drawable_real_get_visible_region (GdkDrawable *drawable)
237 {
238   GdkRectangle rect;
239
240   rect.x = 0;
241   rect.y = 0;
242
243   gdk_drawable_get_size (drawable, &rect.width, &rect.height);
244
245   return cairo_region_create_rectangle (&rect);
246 }
247
248 /**
249  * _gdk_drawable_ref_cairo_surface:
250  * @drawable: a #GdkDrawable
251  * 
252  * Obtains a #cairo_surface_t for the given drawable. If a
253  * #cairo_surface_t for the drawable already exists, it will be
254  * referenced, otherwise a new surface will be created.
255  * 
256  * Return value: a newly referenced #cairo_surface_t that points
257  *  to @drawable. Unref with cairo_surface_destroy()
258  **/
259 cairo_surface_t *
260 _gdk_drawable_ref_cairo_surface (GdkDrawable *drawable)
261 {
262   g_return_val_if_fail (GDK_IS_DRAWABLE (drawable), NULL);
263
264   return GDK_DRAWABLE_GET_CLASS (drawable)->ref_cairo_surface (drawable);
265 }
266
267 /************************************************************************/
268
269 /*
270  * _gdk_drawable_get_source_drawable:
271  * @drawable: a #GdkDrawable
272  *
273  * Returns a drawable for the passed @drawable that is guaranteed to be
274  * usable to create a pixmap (e.g.: not an offscreen window).
275  *
276  * Since: 2.16
277  */
278 GdkDrawable *
279 _gdk_drawable_get_source_drawable (GdkDrawable *drawable)
280 {
281   g_return_val_if_fail (GDK_IS_DRAWABLE (drawable), NULL);
282
283   if (GDK_DRAWABLE_GET_CLASS (drawable)->get_source_drawable)
284     return GDK_DRAWABLE_GET_CLASS (drawable)->get_source_drawable (drawable);
285
286   return drawable;
287 }
288
289 cairo_surface_t *
290 _gdk_drawable_create_cairo_surface (GdkDrawable *drawable,
291                                     int width,
292                                     int height)
293 {
294   return GDK_DRAWABLE_GET_CLASS (drawable)->create_cairo_surface (drawable,
295                                                                   width, height);
296 }