]> git.sur5r.net Git - glabels/blob - glabels2/src/label-ellipse.c
Created generic "get" methods for text, fill and line properties for all label object...
[glabels] / glabels2 / src / label-ellipse.c
1 /*
2  *  (GLABELS) Label and Business Card Creation program for GNOME
3  *
4  *  label_ellipse.c:  GLabels label ellipse object
5  *
6  *  Copyright (C) 2001-2002  Jim Evins <evins@snaught.com>.
7  *
8  *  This program is free software; you can redistribute it and/or modify
9  *  it under the terms of the GNU General Public License as published by
10  *  the Free Software Foundation; either version 2 of the License, or
11  *  (at your option) any later version.
12  *
13  *  This program is distributed in the hope that it will be useful,
14  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
15  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16  *  GNU General Public License for more details.
17  *
18  *  You should have received a copy of the GNU General Public License
19  *  along with this program; if not, write to the Free Software
20  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
21  */
22
23 #include <glib.h>
24
25 #include "label-ellipse.h"
26
27 #include "debug.h"
28
29 /*========================================================*/
30 /* Private types.                                         */
31 /*========================================================*/
32
33 struct _glLabelEllipsePrivate {
34         gdouble          line_width;
35         guint            line_color;
36         guint            fill_color;
37 };
38
39 /*========================================================*/
40 /* Private globals.                                       */
41 /*========================================================*/
42
43 static GObjectClass *parent_class = NULL;
44
45 static guint instance = 0;
46
47 /*========================================================*/
48 /* Private function prototypes.                           */
49 /*========================================================*/
50
51 static void    gl_label_ellipse_class_init    (glLabelEllipseClass *klass);
52 static void    gl_label_ellipse_instance_init (glLabelEllipse      *lellipse);
53 static void    gl_label_ellipse_finalize      (GObject             *object);
54
55 static void    copy                           (glLabelObject       *dst_object,
56                                                glLabelObject       *src_object);
57
58 static void    set_fill_color                 (glLabelObject       *object,
59                                                guint                fill_color);
60
61 static void    set_line_color                 (glLabelObject       *object,
62                                                guint                line_color);
63
64 static void    set_line_width                 (glLabelObject       *object,
65                                                gdouble              line_width);
66
67 static guint   get_fill_color                 (glLabelObject       *object);
68
69 static guint   get_line_color                 (glLabelObject       *object);
70
71 static gdouble get_line_width                 (glLabelObject       *object);
72
73
74 \f
75 /*****************************************************************************/
76 /* Boilerplate object stuff.                                                 */
77 /*****************************************************************************/
78 GType
79 gl_label_ellipse_get_type (void)
80 {
81         static GType type = 0;
82
83         if (!type) {
84                 GTypeInfo info = {
85                         sizeof (glLabelEllipseClass),
86                         NULL,
87                         NULL,
88                         (GClassInitFunc) gl_label_ellipse_class_init,
89                         NULL,
90                         NULL,
91                         sizeof (glLabelEllipse),
92                         0,
93                         (GInstanceInitFunc) gl_label_ellipse_instance_init,
94                 };
95
96                 type = g_type_register_static (GL_TYPE_LABEL_OBJECT,
97                                                "glLabelEllipse", &info, 0);
98         }
99
100         return type;
101 }
102
103 static void
104 gl_label_ellipse_class_init (glLabelEllipseClass *klass)
105 {
106         GObjectClass       *object_class       = (GObjectClass *) klass;
107         glLabelObjectClass *label_object_class = (glLabelObjectClass *) klass;
108
109         parent_class = g_type_class_peek_parent (klass);
110
111         label_object_class->copy           = copy;
112         label_object_class->set_fill_color = set_fill_color;
113         label_object_class->set_line_color = set_line_color;
114         label_object_class->set_line_width = set_line_width;
115         label_object_class->get_fill_color = get_fill_color;
116         label_object_class->get_line_color = get_line_color;
117         label_object_class->get_line_width = get_line_width;
118
119         object_class->finalize = gl_label_ellipse_finalize;
120 }
121
122 static void
123 gl_label_ellipse_instance_init (glLabelEllipse *lellipse)
124 {
125         lellipse->private = g_new0 (glLabelEllipsePrivate, 1);
126 }
127
128 static void
129 gl_label_ellipse_finalize (GObject *object)
130 {
131         glLabelEllipse *lellipse;
132
133         g_return_if_fail (object && GL_IS_LABEL_ELLIPSE (object));
134
135         lellipse = GL_LABEL_ELLIPSE (object);
136
137         g_free (lellipse->private);
138
139         G_OBJECT_CLASS (parent_class)->finalize (object);
140 }
141
142 /*****************************************************************************/
143 /* NEW label "ellipse" object.                                               */
144 /*****************************************************************************/
145 GObject *
146 gl_label_ellipse_new (glLabel *label)
147 {
148         glLabelEllipse *lellipse;
149
150         lellipse = g_object_new (gl_label_ellipse_get_type(), NULL);
151
152         gl_label_object_set_parent (GL_LABEL_OBJECT(lellipse), label);
153
154         return G_OBJECT (lellipse);
155 }
156
157 /*****************************************************************************/
158 /* Copy object contents.                                                     */
159 /*****************************************************************************/
160 static void
161 copy (glLabelObject *dst_object,
162       glLabelObject *src_object)
163 {
164         glLabelEllipse *lellipse     = (glLabelEllipse *)src_object;
165         glLabelEllipse *new_lellipse = (glLabelEllipse *)dst_object;
166         gdouble         line_width;
167         guint           line_color, fill_color;
168
169         gl_debug (DEBUG_LABEL, "START");
170
171         g_return_if_fail (lellipse && GL_IS_LABEL_ELLIPSE (lellipse));
172         g_return_if_fail (new_lellipse && GL_IS_LABEL_ELLIPSE (new_lellipse));
173
174         line_width = get_line_width (src_object);
175         line_color = get_line_color (src_object);
176         fill_color = get_fill_color (src_object);
177
178         set_line_width (dst_object, line_width);
179         set_line_color (dst_object, line_color);
180         set_fill_color (dst_object, fill_color);
181
182         gl_debug (DEBUG_LABEL, "END");
183 }
184
185
186 /*---------------------------------------------------------------------------*/
187 /* PRIVATE.  Set fill color method.                                          */
188 /*---------------------------------------------------------------------------*/
189 static void
190 set_fill_color (glLabelObject *object,
191                 guint          fill_color)
192 {
193         glLabelEllipse *lellipse = (glLabelEllipse *)object;
194
195         g_return_if_fail (lellipse && GL_IS_LABEL_ELLIPSE (lellipse));
196
197         if ( lellipse->private->fill_color != fill_color ) {
198                 lellipse->private->fill_color = fill_color;
199                 gl_label_object_emit_changed (GL_LABEL_OBJECT(lellipse));
200         }
201 }
202
203 /*---------------------------------------------------------------------------*/
204 /* PRIVATE.  Set line color method.                                          */
205 /*---------------------------------------------------------------------------*/
206 static void
207 set_line_color (glLabelObject *object,
208                 guint          line_color)
209 {
210         glLabelEllipse *lellipse = (glLabelEllipse *)object;
211
212         g_return_if_fail (lellipse && GL_IS_LABEL_ELLIPSE (lellipse));
213
214         if ( lellipse->private->line_color != line_color ) {
215                 lellipse->private->line_color = line_color;
216                 gl_label_object_emit_changed (GL_LABEL_OBJECT(lellipse));
217         }
218 }
219
220 /*---------------------------------------------------------------------------*/
221 /* PRIVATE.  Set line width method.                                          */
222 /*---------------------------------------------------------------------------*/
223 static void
224 set_line_width (glLabelObject *object,
225                 gdouble        line_width)
226 {
227         glLabelEllipse *lellipse = (glLabelEllipse *)object;
228
229         g_return_if_fail (lellipse && GL_IS_LABEL_ELLIPSE (lellipse));
230
231         if ( lellipse->private->line_width != line_width ) {
232                 lellipse->private->line_width = line_width;
233                 gl_label_object_emit_changed (GL_LABEL_OBJECT(lellipse));
234         }
235 }
236
237
238 /*---------------------------------------------------------------------------*/
239 /* PRIVATE.  Get fill color method.                                          */
240 /*---------------------------------------------------------------------------*/
241 static gdouble
242 get_line_width (glLabelObject *object)
243 {
244         glLabelEllipse *lellipse = (glLabelEllipse *)object;
245
246         g_return_val_if_fail (lellipse && GL_IS_LABEL_ELLIPSE (lellipse), 0.0);
247
248         return lellipse->private->line_width;
249 }
250
251 /*---------------------------------------------------------------------------*/
252 /* PRIVATE.  Get line color method.                                          */
253 /*---------------------------------------------------------------------------*/
254 static guint
255 get_line_color (glLabelObject *object)
256 {
257         glLabelEllipse *lellipse = (glLabelEllipse *)object;
258
259         g_return_val_if_fail (lellipse && GL_IS_LABEL_ELLIPSE (lellipse), 0);
260
261         return lellipse->private->line_color;
262 }
263
264 /*---------------------------------------------------------------------------*/
265 /* PRIVATE.  Get line width method.                                          */
266 /*---------------------------------------------------------------------------*/
267 static guint
268 get_fill_color (glLabelObject *object)
269 {
270         glLabelEllipse *lellipse = (glLabelEllipse *)object;
271
272         g_return_val_if_fail (lellipse && GL_IS_LABEL_ELLIPSE (lellipse), 0);
273
274         return lellipse->private->fill_color;
275 }
276
277