]> git.sur5r.net Git - glabels/blob - glabels2/src/label-ellipse.c
Initial revision
[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 \f
56 /*****************************************************************************/
57 /* Boilerplate object stuff.                                                 */
58 /*****************************************************************************/
59 GType
60 gl_label_ellipse_get_type (void)
61 {
62         static GType type = 0;
63
64         if (!type) {
65                 GTypeInfo info = {
66                         sizeof (glLabelEllipseClass),
67                         NULL,
68                         NULL,
69                         (GClassInitFunc) gl_label_ellipse_class_init,
70                         NULL,
71                         NULL,
72                         sizeof (glLabelEllipse),
73                         0,
74                         (GInstanceInitFunc) gl_label_ellipse_instance_init,
75                 };
76
77                 type = g_type_register_static (GL_TYPE_LABEL_OBJECT,
78                                                "glLabelEllipse", &info, 0);
79         }
80
81         return type;
82 }
83
84 static void
85 gl_label_ellipse_class_init (glLabelEllipseClass *klass)
86 {
87         GObjectClass *object_class = (GObjectClass *) klass;
88
89         parent_class = g_type_class_peek_parent (klass);
90
91         object_class->finalize = gl_label_ellipse_finalize;
92 }
93
94 static void
95 gl_label_ellipse_instance_init (glLabelEllipse *lellipse)
96 {
97         lellipse->private = g_new0 (glLabelEllipsePrivate, 1);
98 }
99
100 static void
101 gl_label_ellipse_finalize (GObject *object)
102 {
103         glLabelEllipse *lellipse;
104
105         g_return_if_fail (object && GL_IS_LABEL_ELLIPSE (object));
106
107         lellipse = GL_LABEL_ELLIPSE (object);
108
109         g_free (lellipse->private);
110
111         G_OBJECT_CLASS (parent_class)->finalize (object);
112 }
113
114 /*****************************************************************************/
115 /* NEW label "ellipse" object.                                               */
116 /*****************************************************************************/
117 GObject *
118 gl_label_ellipse_new (glLabel *label)
119 {
120         glLabelEllipse *lellipse;
121
122         lellipse = g_object_new (gl_label_ellipse_get_type(), NULL);
123
124         gl_label_object_set_parent (GL_LABEL_OBJECT(lellipse), label);
125
126         return G_OBJECT (lellipse);
127 }
128
129 /*****************************************************************************/
130 /* Duplicate object.                                                         */
131 /*****************************************************************************/
132 glLabelEllipse *
133 gl_label_ellipse_dup (glLabelEllipse *lellipse,
134                       glLabel *label)
135 {
136         glLabelEllipse *new_lellipse;
137         gdouble        x, y, w, h, line_width;
138         guint          line_color, fill_color;
139
140         gl_debug (DEBUG_LABEL, "START");
141
142         g_return_if_fail (lellipse && GL_IS_LABEL_ELLIPSE (lellipse));
143         g_return_if_fail (label && GL_IS_LABEL (label));
144
145         new_lellipse = GL_LABEL_ELLIPSE(gl_label_ellipse_new (label));
146
147         gl_label_object_get_position (GL_LABEL_OBJECT(lellipse), &x, &y);
148         gl_label_object_get_size     (GL_LABEL_OBJECT(lellipse), &w, &h);
149
150         gl_label_object_set_position (GL_LABEL_OBJECT(new_lellipse),  x,  y);
151         gl_label_object_set_size     (GL_LABEL_OBJECT(new_lellipse),  w,  h);
152
153         line_width = gl_label_ellipse_get_line_width (lellipse);
154         line_color = gl_label_ellipse_get_line_color (lellipse);
155         fill_color = gl_label_ellipse_get_fill_color (lellipse);
156
157         gl_label_ellipse_set_line_width (new_lellipse, line_width);
158         gl_label_ellipse_set_line_color (new_lellipse, line_color);
159         gl_label_ellipse_set_fill_color (new_lellipse, fill_color);
160
161         gl_debug (DEBUG_LABEL, "END");
162
163         return new_lellipse;
164 }
165
166
167 /*****************************************************************************/
168 /* Set object params.                                                        */
169 /*****************************************************************************/
170 void
171 gl_label_ellipse_set_line_width (glLabelEllipse *lellipse,
172                                  gdouble        line_width)
173 {
174         g_return_if_fail (lellipse && GL_IS_LABEL_ELLIPSE (lellipse));
175
176         if ( lellipse->private->line_width != line_width ) {
177                 lellipse->private->line_width = line_width;
178                 gl_label_object_emit_changed (GL_LABEL_OBJECT(lellipse));
179         }
180 }
181
182 void
183 gl_label_ellipse_set_line_color (glLabelEllipse *lellipse,
184                                  guint          line_color)
185 {
186         g_return_if_fail (lellipse && GL_IS_LABEL_ELLIPSE (lellipse));
187
188         if ( lellipse->private->line_color != line_color ) {
189                 lellipse->private->line_color = line_color;
190                 gl_label_object_emit_changed (GL_LABEL_OBJECT(lellipse));
191         }
192 }
193
194 void
195 gl_label_ellipse_set_fill_color (glLabelEllipse *lellipse,
196                                  guint          fill_color)
197 {
198         g_return_if_fail (lellipse && GL_IS_LABEL_ELLIPSE (lellipse));
199
200         if ( lellipse->private->fill_color != fill_color ) {
201                 lellipse->private->fill_color = fill_color;
202                 gl_label_object_emit_changed (GL_LABEL_OBJECT(lellipse));
203         }
204 }
205
206 /*****************************************************************************/
207 /* Get object params.                                                        */
208 /*****************************************************************************/
209 gdouble
210 gl_label_ellipse_get_line_width (glLabelEllipse *lellipse)
211 {
212         g_return_val_if_fail (lellipse && GL_IS_LABEL_ELLIPSE (lellipse), 0.0);
213
214         return lellipse->private->line_width;
215 }
216
217 guint
218 gl_label_ellipse_get_line_color (glLabelEllipse *lellipse)
219 {
220         g_return_val_if_fail (lellipse && GL_IS_LABEL_ELLIPSE (lellipse), 0);
221
222         return lellipse->private->line_color;
223 }
224
225 guint
226 gl_label_ellipse_get_fill_color (glLabelEllipse *lellipse)
227 {
228         g_return_val_if_fail (lellipse && GL_IS_LABEL_ELLIPSE (lellipse), 0);
229
230         return lellipse->private->fill_color;
231 }
232