[AdgPositionable] Using origin instead of org in public API
[adg.git] / adg / adg-positionable.c
blob8719fac1925ee060d933af593febb8a52bc8aefc
1 /* ADG - Automatic Drawing Generation
2 * Copyright (C) 2007-2008, Nicola Fontana <ntd at entidi.it>
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.
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.
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., 51 Franklin Street, Fifth Floor,
17 * Boston, MA 02110-1301, USA.
21 /**
22 * SECTION:positionable
23 * @title: AdgPositionable
24 * @short_description: Interface for positionable entities
26 * The #AdgPositionableIface interface gives a common way to manage entities
27 * with an origin point.
28 **/
30 /**
31 * AdgPositionableIface:
32 * @base_iface: the base interface
33 * @get_origin: returns the current origin
34 * @set_origin: sets a new origin
36 * The virtual methods @get_origin and @set_origin must be defined
37 * by all the types which implement this interface.
38 **/
40 #include "adg-positionable.h"
41 #include "adg-intl.h"
44 enum {
45 ORIGIN_MOVED,
46 LAST_SIGNAL
49 static void iface_base (AdgPositionableIface *iface);
50 static void iface_init (AdgPositionableIface *iface);
51 static void get_origin (AdgPositionable *positionable,
52 AdgPoint *dest);
53 static void set_origin (AdgPositionable *positionable,
54 const AdgPoint *origin);
56 static guint signals[LAST_SIGNAL] = { 0 };
59 GType
60 adg_positionable_get_type(void)
62 static GType positionable_type = 0;
64 if (G_UNLIKELY(positionable_type == 0)) {
65 static const GTypeInfo positionable_info = {
66 sizeof(AdgPositionableIface),
67 (GBaseInitFunc) iface_base,
68 NULL,
69 (GClassInitFunc) iface_init,
70 NULL,
73 positionable_type = g_type_register_static(G_TYPE_INTERFACE,
74 "AdgPositionable",
75 &positionable_info, 0);
78 return positionable_type;
81 static void
82 iface_base(AdgPositionableIface *iface)
84 static gboolean initialized = FALSE;
85 GParamSpec *param;
86 GType param_types[1];
88 if (initialized) {
89 return;
91 initialized = TRUE;
93 param = g_param_spec_object("origin",
94 P_("Origin"),
95 P_("Origin point"),
96 ADG_TYPE_POINT,
97 G_PARAM_READWRITE);
98 g_object_interface_install_property(iface, param);
101 * AdgPositionable::origin-moved:
102 * @positionable: an entity implementing #AdgPositionable
104 * Emitted whenever the origin has changed.
106 param_types[0] = ADG_TYPE_POINT;
107 signals[ORIGIN_MOVED] = g_signal_newv("origin-moved",
108 ADG_TYPE_POSITIONABLE,
109 G_SIGNAL_RUN_FIRST,
110 NULL, NULL, NULL,
111 g_cclosure_marshal_VOID__OBJECT,
112 G_TYPE_NONE, 1, param_types);
115 static void
116 iface_init (AdgPositionableIface *iface)
118 iface->get_origin = get_origin;
119 iface->set_origin = set_origin;
123 static void
124 get_origin(AdgPositionable *positionable, AdgPoint *dest)
126 g_warning("AdgPositionable::get_origin not implemented for `%s'",
127 g_type_name(G_TYPE_FROM_INSTANCE(positionable)));
130 static void
131 set_origin(AdgPositionable *positionable, const AdgPoint *point)
133 g_warning("AdgPositionable::set_origin not implemented for `%s'",
134 g_type_name(G_TYPE_FROM_INSTANCE(positionable)));
138 * adg_positionable_get_origin:
139 * @positionable: an entity implementing AdgPositionable
141 * Gets the origin point of @positionable.
143 * Return value: A pointer to the internal origin point
145 void
146 adg_positionable_get_origin(AdgPositionable *positionable, AdgPoint *dest)
148 g_return_if_fail(ADG_IS_POSITIONABLE(positionable));
149 g_return_if_fail(dest != NULL);
151 ADG_POSITIONABLE_GET_IFACE(positionable)->get_origin(positionable, dest);
155 * adg_positionable_set_origin:
156 * @positionable: an entity implementing AdgPositionable
157 * @origin: the new origin
159 * Sets the origin of @positionable to @origin.
160 * An "origin-moved" signal is emitted.
162 void
163 adg_positionable_set_origin(AdgPositionable *positionable,
164 const AdgPoint *origin)
166 AdgPositionableIface *iface;
167 AdgPoint old_origin;
169 g_return_if_fail(ADG_IS_POSITIONABLE(positionable));
170 g_return_if_fail(origin != NULL);
172 iface = ADG_POSITIONABLE_GET_IFACE(positionable);
174 iface->get_origin(positionable, &old_origin);
175 iface->set_origin(positionable, origin);
177 g_signal_emit(positionable, signals[ORIGIN_MOVED], 0, &old_origin);
181 * adg_positionable_set_origin_explicit:
182 * @positionable: an entity implementing AdgPositionable
183 * @model_x: the new x position in model space
184 * @model_y: the new y position in model space
185 * @paper_x: the new x position in paper space
186 * @paper_y: the new y position in paper space
188 * Sets the origin of @positionable to the new coordinates. It calls
189 * adg_positionable_set_origin() internally.
191 void
192 adg_positionable_set_origin_explicit(AdgPositionable *positionable,
193 gdouble model_x, gdouble model_y,
194 gdouble paper_x, gdouble paper_y)
196 AdgPoint origin;
198 origin.model.x = model_x;
199 origin.model.y = model_y;
200 origin.paper.x = paper_x;
201 origin.paper.y = paper_y;
203 adg_positionable_set_origin(positionable, &origin);