~ubuntu-branches/ubuntu/maverick/gcompris/maverick

« back to all changes in this revision

Viewing changes to src/goocanvas/src/goocanvasellipse.c

  • Committer: Bazaar Package Importer
  • Author(s): Marc Gariepy, Marc Gariepy, Stephane Graber
  • Date: 2010-01-04 17:42:49 UTC
  • mfrom: (1.1.14 upstream)
  • Revision ID: james.westby@ubuntu.com-20100104174249-7bupatd9dtxyhvs4
Tags: 9.0-0ubuntu1
[Marc Gariepy]
* New upstream release (9.0).
* Remove cache.c from POTFILES to avoid FTBFS
* Remove unneeded rm in debian/rules (file no longer exists upstream)

[Stephane Graber]
* Bump Debian standards to 3.8.3
* Add patch system (dpatch)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * GooCanvas. Copyright (C) 2005 Damon Chaplin.
 
3
 * Released under the GNU LGPL license. See COPYING for details.
 
4
 *
 
5
 * goocanvasellipse.c - ellipse item.
 
6
 */
 
7
 
 
8
/**
 
9
 * SECTION:goocanvasellipse
 
10
 * @Title: GooCanvasEllipse
 
11
 * @Short_Description: an ellipse item.
 
12
 *
 
13
 * GooCanvasEllipse represents an ellipse item.
 
14
 *
 
15
 * It is a subclass of #GooCanvasItemSimple and so inherits all of the style
 
16
 * properties such as "stroke-color", "fill-color" and "line-width".
 
17
 *
 
18
 * It also implements the #GooCanvasItem interface, so you can use the
 
19
 * #GooCanvasItem functions such as goo_canvas_item_raise() and
 
20
 * goo_canvas_item_rotate().
 
21
 *
 
22
 * To create a #GooCanvasEllipse use goo_canvas_ellipse_new().
 
23
 *
 
24
 * To get or set the properties of an existing #GooCanvasEllipse, use
 
25
 * g_object_get() and g_object_set().
 
26
 *
 
27
 * The ellipse can be specified either with the "center-x", "center-y",
 
28
 * "radius-x" and "radius-y" properties, or with the "x", "y", "width" and
 
29
 * "height" properties.
 
30
 */
 
31
#include <config.h>
 
32
#include <math.h>
 
33
#include <glib/gi18n-lib.h>
 
34
#include <gtk/gtk.h>
 
35
#include "goocanvasellipse.h"
 
36
 
 
37
 
 
38
enum {
 
39
  PROP_0,
 
40
 
 
41
  PROP_CENTER_X,
 
42
  PROP_CENTER_Y,
 
43
  PROP_RADIUS_X,
 
44
  PROP_RADIUS_Y,
 
45
 
 
46
  PROP_X,
 
47
  PROP_Y,
 
48
  PROP_WIDTH,
 
49
  PROP_HEIGHT
 
50
};
 
51
 
 
52
 
 
53
static void canvas_item_interface_init      (GooCanvasItemIface  *iface);
 
54
static void goo_canvas_ellipse_finalize     (GObject             *object);
 
55
static void goo_canvas_ellipse_get_property (GObject             *object,
 
56
                                             guint                param_id,
 
57
                                             GValue              *value,
 
58
                                             GParamSpec          *pspec);
 
59
static void goo_canvas_ellipse_set_property (GObject             *object,
 
60
                                             guint                param_id,
 
61
                                             const GValue        *value,
 
62
                                             GParamSpec          *pspec);
 
63
static void goo_canvas_ellipse_create_path  (GooCanvasItemSimple *simple,
 
64
                                             cairo_t             *cr);
 
65
 
 
66
G_DEFINE_TYPE_WITH_CODE (GooCanvasEllipse, goo_canvas_ellipse,
 
67
                         GOO_TYPE_CANVAS_ITEM_SIMPLE,
 
68
                         G_IMPLEMENT_INTERFACE (GOO_TYPE_CANVAS_ITEM,
 
69
                                                canvas_item_interface_init))
 
70
 
 
71
 
 
72
static void
 
73
goo_canvas_ellipse_install_common_properties (GObjectClass *gobject_class)
 
74
{
 
75
  g_object_class_install_property (gobject_class, PROP_CENTER_X,
 
76
                                   g_param_spec_double ("center-x",
 
77
                                                        _("Center X"),
 
78
                                                        _("The x coordinate of the center of the ellipse"),
 
79
                                                        -G_MAXDOUBLE,
 
80
                                                        G_MAXDOUBLE, 0.0,
 
81
                                                        G_PARAM_READWRITE));
 
82
 
 
83
  g_object_class_install_property (gobject_class, PROP_CENTER_Y,
 
84
                                   g_param_spec_double ("center-y",
 
85
                                                        _("Center Y"),
 
86
                                                        _("The y coordinate of the center of the ellipse"),
 
87
                                                        -G_MAXDOUBLE,
 
88
                                                        G_MAXDOUBLE, 0.0,
 
89
                                                        G_PARAM_READWRITE));
 
90
 
 
91
  g_object_class_install_property (gobject_class, PROP_RADIUS_X,
 
92
                                   g_param_spec_double ("radius-x",
 
93
                                                        _("Radius X"),
 
94
                                                        _("The horizontal radius of the ellipse"),
 
95
                                                        0.0, G_MAXDOUBLE, 0.0,
 
96
                                                        G_PARAM_READWRITE));
 
97
 
 
98
  g_object_class_install_property (gobject_class, PROP_RADIUS_Y,
 
99
                                   g_param_spec_double ("radius-y",
 
100
                                                        _("Radius Y"),
 
101
                                                        _("The vertical radius of the ellipse"),
 
102
                                                        0.0, G_MAXDOUBLE, 0.0,
 
103
                                                        G_PARAM_READWRITE));
 
104
 
 
105
  g_object_class_install_property (gobject_class, PROP_X,
 
106
                                   g_param_spec_double ("x",
 
107
                                                        "X",
 
108
                                                        _("The x coordinate of the left side of the ellipse"),
 
109
                                                        -G_MAXDOUBLE,
 
110
                                                        G_MAXDOUBLE, 0.0,
 
111
                                                        G_PARAM_READWRITE));
 
112
 
 
113
  g_object_class_install_property (gobject_class, PROP_Y,
 
114
                                   g_param_spec_double ("y",
 
115
                                                        "Y",
 
116
                                                        _("The y coordinate of the top of the ellipse"),
 
117
                                                        -G_MAXDOUBLE,
 
118
                                                        G_MAXDOUBLE, 0.0,
 
119
                                                        G_PARAM_READWRITE));
 
120
 
 
121
  g_object_class_install_property (gobject_class, PROP_WIDTH,
 
122
                                   g_param_spec_double ("width",
 
123
                                                        _("Width"),
 
124
                                                        _("The width of the ellipse"),
 
125
                                                        0.0, G_MAXDOUBLE, 0.0,
 
126
                                                        G_PARAM_READWRITE));
 
127
 
 
128
  g_object_class_install_property (gobject_class, PROP_HEIGHT,
 
129
                                   g_param_spec_double ("height",
 
130
                                                        _("Height"),
 
131
                                                        _("The height of the ellipse"),
 
132
                                                        0.0, G_MAXDOUBLE, 0.0,
 
133
                                                        G_PARAM_READWRITE));
 
134
}
 
135
 
 
136
 
 
137
static void
 
138
goo_canvas_ellipse_class_init (GooCanvasEllipseClass *klass)
 
139
{
 
140
  GObjectClass *gobject_class = (GObjectClass*) klass;
 
141
  GooCanvasItemSimpleClass *simple_class = (GooCanvasItemSimpleClass*) klass;
 
142
 
 
143
  gobject_class->finalize     = goo_canvas_ellipse_finalize;
 
144
 
 
145
  gobject_class->get_property = goo_canvas_ellipse_get_property;
 
146
  gobject_class->set_property = goo_canvas_ellipse_set_property;
 
147
 
 
148
  simple_class->simple_create_path = goo_canvas_ellipse_create_path;
 
149
 
 
150
  goo_canvas_ellipse_install_common_properties (gobject_class);
 
151
}
 
152
 
 
153
 
 
154
static void
 
155
goo_canvas_ellipse_init (GooCanvasEllipse *ellipse)
 
156
{
 
157
  ellipse->ellipse_data = g_slice_new0 (GooCanvasEllipseData);
 
158
}
 
159
 
 
160
 
 
161
/**
 
162
 * goo_canvas_ellipse_new:
 
163
 * @parent: the parent item, or %NULL. If a parent is specified, it will assume
 
164
 *  ownership of the item, and the item will automatically be freed when it is
 
165
 *  removed from the parent. Otherwise call g_object_unref() to free it.
 
166
 * @center_x: the x coordinate of the center of the ellipse.
 
167
 * @center_y: the y coordinate of the center of the ellipse.
 
168
 * @radius_x: the horizontal radius of the ellipse.
 
169
 * @radius_y: the vertical radius of the ellipse.
 
170
 * @...: optional pairs of property names and values, and a terminating %NULL.
 
171
 * 
 
172
 * Creates a new ellipse item.
 
173
 *
 
174
 * <!--PARAMETERS-->
 
175
 *
 
176
 * Here's an example showing how to create an ellipse centered at (100.0,
 
177
 * 100.0), with a horizontal radius of 50.0 and a vertical radius of 30.0.
 
178
 * It is drawn with a red outline with a width of 5.0 and filled with blue:
 
179
 *
 
180
 * <informalexample><programlisting>
 
181
 *  GooCanvasItem *ellipse = goo_canvas_ellipse_new (mygroup, 100.0, 100.0, 50.0, 30.0,
 
182
 *                                                   "stroke-color", "red",
 
183
 *                                                   "line-width", 5.0,
 
184
 *                                                   "fill-color", "blue",
 
185
 *                                                   NULL);
 
186
 * </programlisting></informalexample>
 
187
 * 
 
188
 * Returns: a new ellipse item.
 
189
 **/
 
190
GooCanvasItem*
 
191
goo_canvas_ellipse_new (GooCanvasItem *parent,
 
192
                        gdouble        center_x,
 
193
                        gdouble        center_y,
 
194
                        gdouble        radius_x,
 
195
                        gdouble        radius_y,
 
196
                        ...)
 
197
{
 
198
  GooCanvasItem *item;
 
199
  GooCanvasEllipse *ellipse;
 
200
  GooCanvasEllipseData *ellipse_data;
 
201
  const char *first_property;
 
202
  va_list var_args;
 
203
 
 
204
  item = g_object_new (GOO_TYPE_CANVAS_ELLIPSE, NULL);
 
205
  ellipse = (GooCanvasEllipse*) item;
 
206
 
 
207
  ellipse_data = ellipse->ellipse_data;
 
208
  ellipse_data->center_x = center_x;
 
209
  ellipse_data->center_y = center_y;
 
210
  ellipse_data->radius_x = radius_x;
 
211
  ellipse_data->radius_y = radius_y;
 
212
 
 
213
  va_start (var_args, radius_y);
 
214
  first_property = va_arg (var_args, char*);
 
215
  if (first_property)
 
216
    g_object_set_valist ((GObject*) item, first_property, var_args);
 
217
  va_end (var_args);
 
218
 
 
219
  if (parent)
 
220
    {
 
221
      goo_canvas_item_add_child (parent, item, -1);
 
222
      g_object_unref (item);
 
223
    }
 
224
 
 
225
  return item;
 
226
}
 
227
 
 
228
 
 
229
static void
 
230
goo_canvas_ellipse_finalize (GObject *object)
 
231
{
 
232
  GooCanvasItemSimple *simple = (GooCanvasItemSimple*) object;
 
233
  GooCanvasEllipse *ellipse = (GooCanvasEllipse*) object;
 
234
 
 
235
  /* Free our data if we didn't have a model. (If we had a model it would
 
236
     have been reset in dispose() and simple_data will be NULL.) */
 
237
  if (simple->simple_data)
 
238
    g_slice_free (GooCanvasEllipseData, ellipse->ellipse_data);
 
239
  ellipse->ellipse_data = NULL;
 
240
 
 
241
  G_OBJECT_CLASS (goo_canvas_ellipse_parent_class)->finalize (object);
 
242
}
 
243
 
 
244
 
 
245
static void
 
246
goo_canvas_ellipse_get_common_property (GObject              *object,
 
247
                                        GooCanvasEllipseData *ellipse_data,
 
248
                                        guint                 prop_id,
 
249
                                        GValue               *value,
 
250
                                        GParamSpec           *pspec)
 
251
{
 
252
  switch (prop_id)
 
253
    {
 
254
    case PROP_CENTER_X:
 
255
      g_value_set_double (value, ellipse_data->center_x);
 
256
      break;
 
257
    case PROP_CENTER_Y:
 
258
      g_value_set_double (value, ellipse_data->center_y);
 
259
      break;
 
260
    case PROP_RADIUS_X:
 
261
      g_value_set_double (value, ellipse_data->radius_x);
 
262
      break;
 
263
    case PROP_RADIUS_Y:
 
264
      g_value_set_double (value, ellipse_data->radius_y);
 
265
      break;
 
266
    case PROP_X:
 
267
      g_value_set_double (value, ellipse_data->center_x - ellipse_data->radius_x);
 
268
      break;
 
269
    case PROP_Y:
 
270
      g_value_set_double (value, ellipse_data->center_y - ellipse_data->radius_y);
 
271
      break;
 
272
    case PROP_WIDTH:
 
273
      g_value_set_double (value, 2.0 * ellipse_data->radius_x);
 
274
      break;
 
275
    case PROP_HEIGHT:
 
276
      g_value_set_double (value, 2.0 * ellipse_data->radius_y);
 
277
      break;
 
278
    default:
 
279
      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
 
280
      break;
 
281
    }
 
282
}
 
283
 
 
284
 
 
285
static void
 
286
goo_canvas_ellipse_get_property (GObject              *object,
 
287
                                 guint                 prop_id,
 
288
                                 GValue               *value,
 
289
                                 GParamSpec           *pspec)
 
290
{
 
291
  GooCanvasEllipse *ellipse = (GooCanvasEllipse*) object;
 
292
 
 
293
  goo_canvas_ellipse_get_common_property (object, ellipse->ellipse_data,
 
294
                                          prop_id, value, pspec);
 
295
}
 
296
 
 
297
 
 
298
static void
 
299
goo_canvas_ellipse_set_common_property (GObject              *object,
 
300
                                        GooCanvasEllipseData *ellipse_data,
 
301
                                        guint                 prop_id,
 
302
                                        const GValue         *value,
 
303
                                        GParamSpec           *pspec)
 
304
{
 
305
  gdouble x, y;
 
306
 
 
307
  switch (prop_id)
 
308
    {
 
309
    case PROP_CENTER_X:
 
310
      ellipse_data->center_x = g_value_get_double (value);
 
311
      g_object_notify (object, "x");
 
312
      break;
 
313
    case PROP_CENTER_Y:
 
314
      ellipse_data->center_y = g_value_get_double (value);
 
315
      g_object_notify (object, "y");
 
316
      break;
 
317
    case PROP_RADIUS_X:
 
318
      ellipse_data->radius_x = g_value_get_double (value);
 
319
      g_object_notify (object, "width");
 
320
      break;
 
321
    case PROP_RADIUS_Y:
 
322
      ellipse_data->radius_y = g_value_get_double (value);
 
323
      g_object_notify (object, "height");
 
324
      break;
 
325
    case PROP_X:
 
326
      ellipse_data->center_x = g_value_get_double (value) + ellipse_data->radius_x;
 
327
      g_object_notify (object, "center-x");
 
328
      break;
 
329
    case PROP_Y:
 
330
      ellipse_data->center_y = g_value_get_double (value) + ellipse_data->radius_y;
 
331
      g_object_notify (object, "center-y");
 
332
      break;
 
333
    case PROP_WIDTH:
 
334
      /* Calculate the current x coordinate. */
 
335
      x = ellipse_data->center_x - ellipse_data->radius_x;
 
336
      /* Calculate the new radius_x, which is half the width. */
 
337
      ellipse_data->radius_x = g_value_get_double (value) / 2.0;
 
338
      /* Now calculate the new center_x. */
 
339
      ellipse_data->center_x = x + ellipse_data->radius_x;
 
340
 
 
341
      g_object_notify (object, "center-x");
 
342
      g_object_notify (object, "radius-x");
 
343
      break;
 
344
    case PROP_HEIGHT:
 
345
      /* Calculate the current y coordinate. */
 
346
      y = ellipse_data->center_y - ellipse_data->radius_y;
 
347
      /* Calculate the new radius_y, which is half the height. */
 
348
      ellipse_data->radius_y = g_value_get_double (value) / 2.0;
 
349
      /* Now calculate the new center_y. */
 
350
      ellipse_data->center_y = y + ellipse_data->radius_y;
 
351
 
 
352
      g_object_notify (object, "center-y");
 
353
      g_object_notify (object, "radius-y");
 
354
      break;
 
355
    default:
 
356
      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
 
357
      break;
 
358
    }
 
359
}
 
360
 
 
361
 
 
362
static void
 
363
goo_canvas_ellipse_set_property (GObject              *object,
 
364
                                 guint                 prop_id,
 
365
                                 const GValue         *value,
 
366
                                 GParamSpec           *pspec)
 
367
{
 
368
  GooCanvasItemSimple *simple = (GooCanvasItemSimple*) object;
 
369
  GooCanvasEllipse *ellipse = (GooCanvasEllipse*) object;
 
370
 
 
371
  if (simple->model)
 
372
    {
 
373
      g_warning ("Can't set property of a canvas item with a model - set the model property instead");
 
374
      return;
 
375
    }
 
376
 
 
377
  goo_canvas_ellipse_set_common_property (object, ellipse->ellipse_data,
 
378
                                          prop_id, value, pspec);
 
379
  goo_canvas_item_simple_changed (simple, TRUE);
 
380
}
 
381
 
 
382
 
 
383
static void
 
384
goo_canvas_ellipse_create_path (GooCanvasItemSimple *simple,
 
385
                                cairo_t             *cr)
 
386
{
 
387
  GooCanvasEllipse *ellipse = (GooCanvasEllipse*) simple;
 
388
  GooCanvasEllipseData *ellipse_data = ellipse->ellipse_data;
 
389
 
 
390
  cairo_new_path (cr);
 
391
  cairo_save (cr);
 
392
  cairo_translate (cr, ellipse_data->center_x, ellipse_data->center_y);
 
393
  cairo_scale (cr, ellipse_data->radius_x, ellipse_data->radius_y);
 
394
  cairo_arc (cr, 0.0, 0.0, 1.0, 0.0, 2.0 * M_PI);
 
395
  cairo_restore (cr);
 
396
}
 
397
 
 
398
 
 
399
 
 
400
static void
 
401
goo_canvas_ellipse_set_model    (GooCanvasItem      *item,
 
402
                                 GooCanvasItemModel *model)
 
403
{
 
404
  GooCanvasItemSimple *simple = (GooCanvasItemSimple*) item;
 
405
  GooCanvasEllipse *ellipse = (GooCanvasEllipse*) item;
 
406
  GooCanvasEllipseModel *emodel = (GooCanvasEllipseModel*) model;
 
407
 
 
408
  /* If our ellipse_data was allocated, free it. */
 
409
  if (!simple->model)
 
410
    g_slice_free (GooCanvasEllipseData, ellipse->ellipse_data);
 
411
 
 
412
  /* Now use the new model's ellipse_data instead. */
 
413
  ellipse->ellipse_data = &emodel->ellipse_data;
 
414
 
 
415
  /* Let the parent GooCanvasItemSimple code do the rest. */
 
416
  goo_canvas_item_simple_set_model (simple, model);
 
417
}
 
418
 
 
419
 
 
420
static void
 
421
canvas_item_interface_init (GooCanvasItemIface *iface)
 
422
{
 
423
  iface->set_model      = goo_canvas_ellipse_set_model;
 
424
}
 
425
 
 
426
 
 
427
/**
 
428
 * SECTION:goocanvasellipsemodel
 
429
 * @Title: GooCanvasEllipseModel
 
430
 * @Short_Description: a model for ellipse items.
 
431
 *
 
432
 * GooCanvasEllipseModel represents a model for ellipse items.
 
433
 *
 
434
 * It is a subclass of #GooCanvasItemModelSimple and so inherits all of the
 
435
 * style properties such as "stroke-color", "fill-color" and "line-width".
 
436
 *
 
437
 * It also implements the #GooCanvasItemModel interface, so you can use the
 
438
 * #GooCanvasItemModel functions such as goo_canvas_item_model_raise() and
 
439
 * goo_canvas_item_model_rotate().
 
440
 *
 
441
 * To create a #GooCanvasEllipseModel use goo_canvas_ellipse_model_new().
 
442
 *
 
443
 * To get or set the properties of an existing #GooCanvasEllipseModel, use
 
444
 * g_object_get() and g_object_set().
 
445
 *
 
446
 * The ellipse can be specified either with the "center-x", "center-y",
 
447
 * "radius-x" and "radius-y" properties, or with the "x", "y", "width" and
 
448
 * "height" properties.
 
449
 *
 
450
 * To respond to events such as mouse clicks on the ellipse you must connect
 
451
 * to the signal handlers of the corresponding #GooCanvasEllipse objects.
 
452
 * (See goo_canvas_get_item() and #GooCanvas::item-created.)
 
453
 */
 
454
 
 
455
static void item_model_interface_init (GooCanvasItemModelIface *iface);
 
456
static void goo_canvas_ellipse_model_finalize     (GObject            *object);
 
457
static void goo_canvas_ellipse_model_get_property (GObject            *object,
 
458
                                                   guint               param_id,
 
459
                                                   GValue             *value,
 
460
                                                   GParamSpec         *pspec);
 
461
static void goo_canvas_ellipse_model_set_property (GObject            *object,
 
462
                                                   guint               param_id,
 
463
                                                   const GValue       *value,
 
464
                                                   GParamSpec         *pspec);
 
465
 
 
466
G_DEFINE_TYPE_WITH_CODE (GooCanvasEllipseModel, goo_canvas_ellipse_model,
 
467
                         GOO_TYPE_CANVAS_ITEM_MODEL_SIMPLE,
 
468
                         G_IMPLEMENT_INTERFACE (GOO_TYPE_CANVAS_ITEM_MODEL,
 
469
                                                item_model_interface_init))
 
470
 
 
471
 
 
472
static void
 
473
goo_canvas_ellipse_model_class_init (GooCanvasEllipseModelClass *klass)
 
474
{
 
475
  GObjectClass *gobject_class = (GObjectClass*) klass;
 
476
 
 
477
  gobject_class->finalize     = goo_canvas_ellipse_model_finalize;
 
478
 
 
479
  gobject_class->get_property = goo_canvas_ellipse_model_get_property;
 
480
  gobject_class->set_property = goo_canvas_ellipse_model_set_property;
 
481
 
 
482
  goo_canvas_ellipse_install_common_properties (gobject_class);
 
483
}
 
484
 
 
485
 
 
486
static void
 
487
goo_canvas_ellipse_model_init (GooCanvasEllipseModel *emodel)
 
488
{
 
489
 
 
490
}
 
491
 
 
492
 
 
493
/**
 
494
 * goo_canvas_ellipse_model_new:
 
495
 * @parent: the parent model, or %NULL. If a parent is specified, it will
 
496
 *  assume ownership of the item, and the item will automatically be freed when
 
497
 *  it is removed from the parent. Otherwise call g_object_unref() to free it.
 
498
 * @center_x: the x coordinate of the center of the ellipse.
 
499
 * @center_y: the y coordinate of the center of the ellipse.
 
500
 * @radius_x: the horizontal radius of the ellipse.
 
501
 * @radius_y: the vertical radius of the ellipse.
 
502
 * @...: optional pairs of property names and values, and a terminating %NULL.
 
503
 * 
 
504
 * Creates a new ellipse model.
 
505
 *
 
506
 * <!--PARAMETERS-->
 
507
 *
 
508
 * Here's an example showing how to create an ellipse centered at (100.0,
 
509
 * 100.0), with a horizontal radius of 50.0 and a vertical radius of 30.0.
 
510
 * It is drawn with a red outline with a width of 5.0 and filled with blue:
 
511
 *
 
512
 * <informalexample><programlisting>
 
513
 *  GooCanvasItemModel *ellipse = goo_canvas_ellipse_model_new (mygroup, 100.0, 100.0, 50.0, 30.0,
 
514
 *                                                              "stroke-color", "red",
 
515
 *                                                              "line-width", 5.0,
 
516
 *                                                              "fill-color", "blue",
 
517
 *                                                              NULL);
 
518
 * </programlisting></informalexample>
 
519
 * 
 
520
 * Returns: a new ellipse model.
 
521
 **/
 
522
GooCanvasItemModel*
 
523
goo_canvas_ellipse_model_new (GooCanvasItemModel *parent,
 
524
                              gdouble             center_x,
 
525
                              gdouble             center_y,
 
526
                              gdouble             radius_x,
 
527
                              gdouble             radius_y,
 
528
                              ...)
 
529
{
 
530
  GooCanvasItemModel *model;
 
531
  GooCanvasEllipseModel *emodel;
 
532
  GooCanvasEllipseData *ellipse_data;
 
533
  const char *first_property;
 
534
  va_list var_args;
 
535
 
 
536
  model = g_object_new (GOO_TYPE_CANVAS_ELLIPSE_MODEL, NULL);
 
537
  emodel = (GooCanvasEllipseModel*) model;
 
538
 
 
539
  ellipse_data = &emodel->ellipse_data;
 
540
  ellipse_data->center_x = center_x;
 
541
  ellipse_data->center_y = center_y;
 
542
  ellipse_data->radius_x = radius_x;
 
543
  ellipse_data->radius_y = radius_y;
 
544
 
 
545
  va_start (var_args, radius_y);
 
546
  first_property = va_arg (var_args, char*);
 
547
  if (first_property)
 
548
    g_object_set_valist ((GObject*) model, first_property, var_args);
 
549
  va_end (var_args);
 
550
 
 
551
  if (parent)
 
552
    {
 
553
      goo_canvas_item_model_add_child (parent, model, -1);
 
554
      g_object_unref (model);
 
555
    }
 
556
 
 
557
  return model;
 
558
}
 
559
 
 
560
 
 
561
static void
 
562
goo_canvas_ellipse_model_finalize (GObject *object)
 
563
{
 
564
  /*GooCanvasEllipseModel *emodel = (GooCanvasEllipseModel*) object;*/
 
565
 
 
566
  G_OBJECT_CLASS (goo_canvas_ellipse_model_parent_class)->finalize (object);
 
567
}
 
568
 
 
569
 
 
570
static void
 
571
goo_canvas_ellipse_model_get_property (GObject              *object,
 
572
                                       guint                 prop_id,
 
573
                                       GValue               *value,
 
574
                                       GParamSpec           *pspec)
 
575
{
 
576
  GooCanvasEllipseModel *emodel = (GooCanvasEllipseModel*) object;
 
577
 
 
578
  goo_canvas_ellipse_get_common_property (object, &emodel->ellipse_data,
 
579
                                          prop_id, value, pspec);
 
580
}
 
581
 
 
582
 
 
583
static void
 
584
goo_canvas_ellipse_model_set_property (GObject              *object,
 
585
                                       guint                 prop_id,
 
586
                                       const GValue         *value,
 
587
                                       GParamSpec           *pspec)
 
588
{
 
589
  GooCanvasEllipseModel *emodel = (GooCanvasEllipseModel*) object;
 
590
 
 
591
  goo_canvas_ellipse_set_common_property (object, &emodel->ellipse_data,
 
592
                                          prop_id, value, pspec);
 
593
  g_signal_emit_by_name (emodel, "changed", TRUE);
 
594
}
 
595
 
 
596
 
 
597
static GooCanvasItem*
 
598
goo_canvas_ellipse_model_create_item (GooCanvasItemModel *model,
 
599
                                      GooCanvas          *canvas)
 
600
{
 
601
  GooCanvasItem *item;
 
602
 
 
603
  item = g_object_new (GOO_TYPE_CANVAS_ELLIPSE, NULL);
 
604
  goo_canvas_item_set_model (item, model);
 
605
 
 
606
  return item;
 
607
}
 
608
 
 
609
 
 
610
static void
 
611
item_model_interface_init (GooCanvasItemModelIface *iface)
 
612
{
 
613
  iface->create_item    = goo_canvas_ellipse_model_create_item;
 
614
}