1 /* GDK - The GIMP Drawing Kit
2 * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Library 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.
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 * Library General Public License for more details.
14 * You should have received a copy of the GNU Library 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.
21 * Modified by the GTK+ Team and others 1997-1999. 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/.
30 #include "gdkprivate.h"
35 GdkGCPrivate *private;
37 private = g_new (GdkGCPrivate, 1);
38 private->ref_count = 1;
39 private->klass = NULL;
40 private->klass_data = NULL;
41 private->clip_x_origin = 0;
42 private->clip_y_origin = 0;
43 private->ts_x_origin = 0;
44 private->ts_y_origin = 0;
46 return (GdkGC *)private;
50 gdk_gc_new (GdkDrawable *drawable)
52 g_return_val_if_fail (drawable != NULL, NULL);
54 if (GDK_DRAWABLE_DESTROYED (drawable))
57 return gdk_gc_new_with_values (drawable, NULL, 0);
61 gdk_gc_new_with_values (GdkDrawable *drawable,
63 GdkGCValuesMask values_mask)
66 GdkGCPrivate *private;
68 g_return_val_if_fail (drawable != NULL, NULL);
70 if (GDK_DRAWABLE_DESTROYED (drawable))
73 gc = ((GdkDrawablePrivate *)drawable)->klass->create_gc (drawable,
76 private = (GdkGCPrivate *)gc;
78 if (values_mask & GDK_GC_CLIP_X_ORIGIN)
79 private->clip_x_origin = values->clip_x_origin;
80 if (values_mask & GDK_GC_CLIP_Y_ORIGIN)
81 private->clip_y_origin = values->clip_y_origin;
82 if (values_mask & GDK_GC_TS_X_ORIGIN)
83 private->ts_x_origin = values->ts_x_origin;
84 if (values_mask & GDK_GC_TS_Y_ORIGIN)
85 private->ts_y_origin = values->ts_y_origin;
91 gdk_gc_ref (GdkGC *gc)
93 GdkGCPrivate *private = (GdkGCPrivate*) gc;
95 g_return_val_if_fail (gc != NULL, NULL);
96 private->ref_count += 1;
102 gdk_gc_unref (GdkGC *gc)
104 GdkGCPrivate *private = (GdkGCPrivate*) gc;
106 g_return_if_fail (gc != NULL);
107 g_return_if_fail (private->ref_count > 0);
109 private->ref_count--;
111 if (private->ref_count == 0)
113 private->klass->destroy (gc);
119 gdk_gc_get_values (GdkGC *gc,
122 g_return_if_fail (gc != NULL);
123 g_return_if_fail (values != NULL);
125 ((GdkGCPrivate *)gc)->klass->get_values (gc, values);
129 gdk_gc_set_values (GdkGC *gc,
131 GdkGCValuesMask values_mask)
133 GdkGCPrivate *private = (GdkGCPrivate *)gc;
135 g_return_if_fail (gc != NULL);
136 g_return_if_fail (values != NULL);
138 if (values_mask & GDK_GC_CLIP_X_ORIGIN)
139 private->clip_x_origin = values->clip_x_origin;
140 if (values_mask & GDK_GC_CLIP_Y_ORIGIN)
141 private->clip_y_origin = values->clip_y_origin;
142 if (values_mask & GDK_GC_TS_X_ORIGIN)
143 private->ts_x_origin = values->ts_x_origin;
144 if (values_mask & GDK_GC_TS_Y_ORIGIN)
145 private->ts_y_origin = values->ts_y_origin;
147 private->klass->set_values (gc, values, values_mask);
151 gdk_gc_set_foreground (GdkGC *gc,
156 g_return_if_fail (gc != NULL);
157 g_return_if_fail (color != NULL);
159 values.foreground = *color;
160 gdk_gc_set_values (gc, &values, GDK_GC_FOREGROUND);
164 gdk_gc_set_background (GdkGC *gc,
169 g_return_if_fail (gc != NULL);
170 g_return_if_fail (color != NULL);
172 values.background = *color;
173 gdk_gc_set_values (gc, &values, GDK_GC_BACKGROUND);
177 gdk_gc_set_font (GdkGC *gc,
182 g_return_if_fail (gc != NULL);
183 g_return_if_fail (font != NULL);
186 gdk_gc_set_values (gc, &values, GDK_GC_FONT);
190 gdk_gc_set_function (GdkGC *gc,
191 GdkFunction function)
195 g_return_if_fail (gc != NULL);
197 values.function = function;
198 gdk_gc_set_values (gc, &values, GDK_GC_FUNCTION);
202 gdk_gc_set_fill (GdkGC *gc,
207 g_return_if_fail (gc != NULL);
210 gdk_gc_set_values (gc, &values, GDK_GC_FILL);
214 gdk_gc_set_tile (GdkGC *gc,
219 g_return_if_fail (gc != NULL);
222 gdk_gc_set_values (gc, &values, GDK_GC_TILE);
226 gdk_gc_set_stipple (GdkGC *gc,
231 g_return_if_fail (gc != NULL);
233 values.stipple = stipple;
234 gdk_gc_set_values (gc, &values, GDK_GC_STIPPLE);
238 gdk_gc_set_ts_origin (GdkGC *gc,
244 g_return_if_fail (gc != NULL);
246 values.ts_x_origin = x;
247 values.ts_y_origin = y;
249 gdk_gc_set_values (gc, &values,
250 GDK_GC_TS_X_ORIGIN | GDK_GC_TS_Y_ORIGIN);
254 gdk_gc_set_clip_origin (GdkGC *gc,
260 g_return_if_fail (gc != NULL);
262 values.clip_x_origin = x;
263 values.clip_y_origin = y;
265 gdk_gc_set_values (gc, &values,
266 GDK_GC_CLIP_X_ORIGIN | GDK_GC_CLIP_Y_ORIGIN);
270 gdk_gc_set_clip_mask (GdkGC *gc,
275 g_return_if_fail (gc != NULL);
277 values.clip_mask = mask;
278 gdk_gc_set_values (gc, &values, GDK_GC_CLIP_MASK);
283 gdk_gc_set_subwindow (GdkGC *gc,
284 GdkSubwindowMode mode)
288 g_return_if_fail (gc != NULL);
290 values.subwindow_mode = mode;
291 gdk_gc_set_values (gc, &values, GDK_GC_SUBWINDOW);
295 gdk_gc_set_exposures (GdkGC *gc,
300 g_return_if_fail (gc != NULL);
302 values.graphics_exposures = exposures;
303 gdk_gc_set_values (gc, &values, GDK_GC_EXPOSURES);
307 gdk_gc_set_line_attributes (GdkGC *gc,
309 GdkLineStyle line_style,
310 GdkCapStyle cap_style,
311 GdkJoinStyle join_style)
315 values.line_width = line_width;
316 values.line_style = line_style;
317 values.cap_style = cap_style;
318 values.join_style = join_style;
320 gdk_gc_set_values (gc, &values,
328 gdk_gc_set_dashes (GdkGC *gc,
333 g_return_if_fail (gc != NULL);
334 g_return_if_fail (dash_list != NULL);
336 ((GdkGCPrivate *)gc)->klass->set_dashes (gc, dash_offset, dash_list, n);