1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
|
/*
* Copyright (C) 2008 Pierre-Luc Beaudoin <pierre-luc@pierlux.com>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "config.h"
#include "champlaindefines.h"
#include "champlainmarker.h"
#include "champlainprivate.h"
#include "champlain.h"
#include "champlain-marshal.h"
#include "map.h"
#include "tile.h"
#include "zoomlevel.h"
#include <clutter/clutter.h>
#include <clutter-cairo/clutter-cairo.h>
#include <glib.h>
#include <glib-object.h>
#include <cairo.h>
#include <math.h>
enum
{
/* normal signals */
LAST_SIGNAL
};
enum
{
PROP_0,
PROP_LONGITUDE,
PROP_LATITUDE,
PROP_ANCHOR_X,
PROP_ANCHOR_Y,
};
//static guint champlain_marker_signals[LAST_SIGNAL] = { 0, };
G_DEFINE_TYPE (ChamplainMarker, champlain_marker, CLUTTER_TYPE_GROUP);
static void
champlain_marker_get_property(GObject *object, guint prop_id, GValue *value, GParamSpec *pspec)
{
ChamplainMarker *marker = CHAMPLAIN_MARKER(object);
ChamplainMarkerPrivate *priv = CHAMPLAIN_MARKER_GET_PRIVATE (marker);
switch(prop_id)
{
case PROP_LONGITUDE:
g_value_set_double(value, priv->lon);
break;
case PROP_LATITUDE:
g_value_set_double(value, priv->lat);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
}
}
static void
champlain_marker_set_property(GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec)
{
ChamplainMarker *marker = CHAMPLAIN_MARKER(object);
ChamplainMarkerPrivate *priv = CHAMPLAIN_MARKER_GET_PRIVATE (marker);
switch(prop_id)
{
case PROP_LONGITUDE:
{
gdouble lon = g_value_get_double(value);
champlain_marker_set_position(marker, lon, priv->lat);
break;
}
case PROP_LATITUDE:
{
gdouble lat = g_value_get_double(value);
champlain_marker_set_position(marker, priv->lon, lat);
break;
}
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
}
}
static void
champlain_marker_finalize (GObject *object)
{
//ChamplainMarker *marker = CHAMPLAIN_MARKER (object);
//ChamplainMarkerPrivate *priv = CHAMPLAIN_MARKER_GET_PRIVATE (marker);
G_OBJECT_CLASS (champlain_marker_parent_class)->finalize (object);
}
static void
champlain_marker_class_init (ChamplainMarkerClass *champlainMarkerClass)
{
g_type_class_add_private (champlainMarkerClass, sizeof (ChamplainMarkerPrivate));
GObjectClass *object_class = G_OBJECT_CLASS (champlainMarkerClass);
object_class->finalize = champlain_marker_finalize;
object_class->get_property = champlain_marker_get_property;
object_class->set_property = champlain_marker_set_property;
/**
* ChamplainMarker:longitude:
*
* The longitude coordonate of the map
*
* Since: 0.2
*/
g_object_class_install_property(object_class, PROP_LONGITUDE,
g_param_spec_double("longitude",
"Longitude",
"The longitude coordonate of the marker",
-180.0f,
180.0f,
0.0f,
CHAMPLAIN_PARAM_READWRITE));
/**
* ChamplainMarker:latitude:
*
* The latitude coordonate of the map
*
* Since: 0.2
*/
g_object_class_install_property(object_class, PROP_LATITUDE,
g_param_spec_double("latitude",
"Latitude",
"The latitude coordonate of the marker",
-90.0f,
90.0f,
0.0f,
CHAMPLAIN_PARAM_READWRITE));
}
static void
champlain_marker_init (ChamplainMarker *champlainMarker)
{
ChamplainMarkerPrivate *priv = CHAMPLAIN_MARKER_GET_PRIVATE (champlainMarker);
}
/**
* champlain_marker_new:
*
* Returns a new #ChamplainMarker ready to be used as a #ClutterActor.
*
* Since: 0.2
*/
ClutterActor *
champlain_marker_new ()
{
ChamplainMarker *marker;
marker = CHAMPLAIN_MARKER (g_object_new (CHAMPLAIN_TYPE_MARKER, NULL));
//ChamplainMarkerPrivate *priv = CHAMPLAIN_MARKER_GET_PRIVATE (marker);
return CLUTTER_ACTOR (marker);
}
/**
* champlain_marker_set_position:
* @marker: a #ChamplainMarker
* @longitude: the longitude to center the map at
* @latitude: the longitude to center the map at
*
* Positions the marker on the map at the coordinates
*
* Since: 0.2
*/
void
champlain_marker_set_position (ChamplainMarker *champlainMarker, gdouble latitude, gdouble longitude)
{
g_return_if_fail(CHAMPLAIN_IS_MARKER(champlainMarker));
ChamplainMarkerPrivate *priv = CHAMPLAIN_MARKER_GET_PRIVATE (champlainMarker);
priv->lon = longitude;
priv->lat = latitude;
g_object_notify(G_OBJECT(champlainMarker), "latitude");
g_object_notify(G_OBJECT(champlainMarker), "longitude");
}
/**
* champlain_marker_new_with_label:
* @label: the text of the label
* @font: the font to use to draw the text, for example "Courrier Bold 11", can be NULL
* @text_color: a #ClutterColor, the color of the text, can be NULL
* @marker_color: a #ClutterColor, the color of the marker, can be NULL
*
* Returns a new #ChamplainMarker with a drawn marker containing the given text.
*
* Since: 0.2
*/
ClutterActor *
champlain_marker_new_with_label (const gchar *label,
const gchar *font,
ClutterColor *text_color,
ClutterColor *marker_color)
{
ChamplainMarker *champlainMarker = CHAMPLAIN_MARKER(champlain_marker_new ());
ClutterColor default_text_color = { 0x22, 022, 0x22, 0xFF },
default_marker_color = { 0x2A, 0xB1, 0x26, 0xEE },
darker_color;
ClutterActor *actor, *bg;
cairo_t *cr;
guint text_width, text_height, point;
const gint padding = 5;
if (!font)
font = "Sans 11";
if (!text_color)
text_color = &default_text_color;
if (!marker_color)
marker_color = &default_marker_color;
actor = clutter_label_new_with_text (font, label);
clutter_actor_set_position (actor, padding, padding / 2.0);
text_width = clutter_actor_get_width (actor) + 2 * padding;
text_height = clutter_actor_get_height (actor)+ padding;
clutter_label_set_color (CLUTTER_LABEL(actor), text_color);
clutter_container_add_actor (CLUTTER_CONTAINER(champlainMarker), actor);
point = (text_height + 2 * padding) / 4.0;
bg = clutter_cairo_new (text_width, text_height + point);
cr = clutter_cairo_create (CLUTTER_CAIRO (bg));
cairo_set_source_rgb (cr, 0, 0, 0);
cairo_move_to (cr, 0, 0);
cairo_line_to (cr, text_width, 0);
cairo_line_to (cr, text_width, text_height);
cairo_line_to (cr, point, text_height);
cairo_line_to (cr, 0, text_height + point);
cairo_close_path (cr);
cairo_set_line_width (cr, 1.0);
cairo_set_source_rgba (cr,
marker_color->red / 255.0,
marker_color->green / 255.0,
marker_color->blue / 255.0,
marker_color->alpha / 255.0);
cairo_fill_preserve (cr);
clutter_color_darken (marker_color, &darker_color);
cairo_set_source_rgba (cr,
darker_color.red / 255.0,
darker_color.green / 255.0,
darker_color.blue / 255.0,
darker_color.alpha / 255.0);
cairo_stroke (cr);
cairo_destroy (cr);
clutter_container_add_actor (CLUTTER_CONTAINER(champlainMarker), bg);
clutter_actor_raise (actor, bg);
clutter_actor_set_anchor_point (CLUTTER_ACTOR(champlainMarker), 0, text_height + point);
return CLUTTER_ACTOR (champlainMarker);
}
/**
* champlain_marker_new_with_image:
* @filename: The filename of the image.
* @error: Return location for an error.
*
* Returns a new #ChamplainMarker with a drawn marker containing the given image.
*
*/
ClutterActor *
champlain_marker_new_with_image(const gchar *filename, GError **error)
{
if (filename == NULL)
return NULL;
ChamplainMarker *champlainMarker = CHAMPLAIN_MARKER(champlain_marker_new ());
ClutterActor *actor = clutter_texture_new_from_file(filename, error);
if (actor == NULL){
g_object_unref(G_OBJECT(champlainMarker));
return NULL;
}
clutter_container_add_actor (CLUTTER_CONTAINER(champlainMarker), actor);
return CLUTTER_ACTOR (champlainMarker);
}
/**
* champlain_marker_new_with_image_full:
* @filename: The name of an image file to load.
* @width: Width of the image in pixel or -1.
* @height: Height of the image in pixel or -1.
* @anchor_x: X coordinate of the anchor point.
* @anchor_y: Y coordinate of the anchor point.
* @error: Return location for an error.
*
* Returns a new #ChamplainMarker with a drawn marker containing the given image.
*
*/
ClutterActor *
champlain_marker_new_with_image_full(const gchar *filename, gint width, gint height, gint anchor_x, gint anchor_y, GError **error)
{
if(filename == NULL)
return NULL;
ChamplainMarker *champlainMarker = CHAMPLAIN_MARKER(champlain_marker_new());
ClutterActor *actor = clutter_texture_new_from_file(filename, error);
if(actor == NULL){
g_object_unref(G_OBJECT(champlainMarker));
return NULL;
}
clutter_actor_set_size(actor, width, height);
clutter_container_add_actor(CLUTTER_CONTAINER(champlainMarker), actor);
clutter_actor_set_anchor_point(CLUTTER_ACTOR(champlainMarker), anchor_x, anchor_y);
return CLUTTER_ACTOR(champlainMarker);
}
|