1
/*
2
 * Copyright (C) 2008 Pierre-Luc Beaudoin <pierre-luc@pierlux.com>
3
 *
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.1 of the License, or (at your option) any later version.
8
 *
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.
13
 *
14
 * You should have received a copy of the GNU Lesser General Public
15
 * License along with this library; if not, write to the Free Software
16
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
17
 */
18
19
#include <champlain/champlain.h>
20
21
#define PADDING 10
22
23
static gboolean
24
zoom_in (G_GNUC_UNUSED ClutterActor *actor,
25
    G_GNUC_UNUSED ClutterButtonEvent *event,
26
    ChamplainView *view)
27
{
28
  champlain_view_zoom_in (view);
29
  return TRUE;
30
}
31
32
33
static gboolean
34
zoom_out (G_GNUC_UNUSED ClutterActor *actor,
35
    G_GNUC_UNUSED ClutterButtonEvent *event,
36
    ChamplainView *view)
37
{
38
  champlain_view_zoom_out (view);
39
  return TRUE;
40
}
41
42
43
static ClutterActor *
44
make_button (char *text)
45
{
46
  ClutterActor *button, *button_bg, *button_text;
47
  ClutterColor white = { 0xff, 0xff, 0xff, 0xff };
48
  ClutterColor black = { 0x00, 0x00, 0x00, 0xff };
49
  gfloat width, height;
50
51
  button = clutter_group_new ();
52
53
  button_bg = clutter_rectangle_new_with_color (&white);
54
  clutter_container_add_actor (CLUTTER_CONTAINER (button), button_bg);
55
  clutter_actor_set_opacity (button_bg, 0xcc);
56
57
  button_text = clutter_text_new_full ("Sans 10", text, &black);
58
  clutter_container_add_actor (CLUTTER_CONTAINER (button), button_text);
59
  clutter_actor_get_size (button_text, &width, &height);
60
61
  clutter_actor_set_size (button_bg, width + PADDING * 2, height + PADDING * 2);
62
  clutter_actor_set_position (button_bg, 0, 0);
63
  clutter_actor_set_position (button_text, PADDING, PADDING);
64
65
  return button;
66
}
67
68
69
static void
70
append_point (ChamplainPathLayer *layer, gdouble lon, gdouble lat)
71
{
72
  ChamplainCoordinate *coord;  
73
  
74
  coord = champlain_coordinate_new_full (lon, lat);
75
  champlain_path_layer_add_node (layer, CHAMPLAIN_LOCATION (coord));
76
}
77
78
79
int
80
main (int argc,
81
    char *argv[])
82
{
83
  ClutterActor *actor, *stage, *buttons, *button;
84
  ChamplainPathLayer *layer;
85
  gfloat width, total_width = 0;;
86
  GList *dash = NULL;
87
88
  if (clutter_init (&argc, &argv) != CLUTTER_INIT_SUCCESS)
89
    return 1;
90
91
  stage = clutter_stage_new ();
92
  clutter_actor_set_size (stage, 800, 600);
93
  g_signal_connect (stage, "destroy", G_CALLBACK (clutter_main_quit), NULL);
94
95
  /* Create the map view */
96
  actor = champlain_view_new ();
97
  clutter_actor_set_size (CLUTTER_ACTOR (actor), 800, 600);
98
  clutter_container_add_actor (CLUTTER_CONTAINER (stage), actor);
99
100
  /* Create the buttons */
101
  buttons = clutter_group_new ();
102
  clutter_actor_set_position (buttons, PADDING, PADDING);
103
104
  button = make_button ("Zoom in");
105
  clutter_container_add_actor (CLUTTER_CONTAINER (buttons), button);
106
  clutter_actor_set_reactive (button, TRUE);
107
  clutter_actor_get_size (button, &width, NULL);
108
  total_width += width + PADDING;
109
  g_signal_connect (button, "button-release-event",
110
      G_CALLBACK (zoom_in),
111
      actor);
112
113
  button = make_button ("Zoom out");
114
  clutter_container_add_actor (CLUTTER_CONTAINER (buttons), button);
115
  clutter_actor_set_reactive (button, TRUE);
116
  clutter_actor_set_position (button, total_width, 0);
117
  clutter_actor_get_size (button, &width, NULL);
118
  g_signal_connect (button, "button-release-event",
119
      G_CALLBACK (zoom_out),
120
      actor);
121
122
  clutter_container_add_actor (CLUTTER_CONTAINER (stage), buttons);
123
124
  /* draw a line */
125
  layer = champlain_path_layer_new ();
126
  /* Cheap approx of Highway 10 */
127
  append_point (layer, 45.4104, -73.2846);
128
  append_point (layer, 45.4178, -73.2239);
129
  append_point (layer, 45.4176, -73.2181);
130
  append_point (layer, 45.4151, -73.2126);
131
  append_point (layer, 45.4016, -73.1926);
132
  append_point (layer, 45.3994, -73.1877);
133
  append_point (layer, 45.4000, -73.1815);
134
  append_point (layer, 45.4151, -73.1218);
135
  champlain_path_layer_set_stroke_width (layer, 4.0);
136
  champlain_view_add_layer (CHAMPLAIN_VIEW (actor), CHAMPLAIN_LAYER (layer));
137
138
  dash = g_list_append(dash, GUINT_TO_POINTER(6));
139
  dash = g_list_append(dash, GUINT_TO_POINTER(2));
140
  champlain_path_layer_set_dash (layer, dash);
141
  
142
  /* draw a path */
143
  layer = champlain_path_layer_new ();
144
  append_point (layer, 45.1386, -73.9196);
145
  append_point (layer, 45.1229, -73.8991);
146
  append_point (layer, 45.0946, -73.9531);
147
  append_point (layer, 45.1085, -73.9714);
148
  append_point (layer, 45.1104, -73.9761);
149
  g_object_set (layer, "closed", TRUE, NULL);
150
  g_object_set (layer, "fill", TRUE, NULL);
151
  champlain_path_layer_set_visible (layer, TRUE);
152
  champlain_view_add_layer (CHAMPLAIN_VIEW (actor), CHAMPLAIN_LAYER (layer));
153
154
  /* Finish initialising the map view */
155
  g_object_set (G_OBJECT (actor), "zoom-level", 8,
156
      "kinetic-mode", TRUE, NULL);
157
  champlain_view_center_on (CHAMPLAIN_VIEW (actor), 45.466, -73.75);
158
159
  clutter_actor_show (stage);
160
  clutter_main ();
161
162
  return 0;
163
}