~ubuntu-branches/ubuntu/maverick/libchamplain/maverick

« back to all changes in this revision

Viewing changes to demos/polygons.c

  • Committer: Bazaar Package Importer
  • Author(s): Laurent Bigonville
  • Date: 2009-06-16 16:23:34 UTC
  • mfrom: (1.1.2 upstream) (2.1.1 squeeze)
  • Revision ID: james.westby@ubuntu.com-20090616162334-ne6px8h90fzem5gf
Tags: 0.3.3-1
* New upstream release
  - Bump soname and adjust .symbols files of booth libraries
* debian/control:
  - Add ${misc:Depends} to libchamplain-gtk-doc to please lintian
  - Build depend against libsoup-gnome2.4-dev instead of libsoup-2.4-dev
  - Add myself as an Uploaders
  - Remove duplicate section field for libchamplain-0.3-1
    and libchamplain-gtk-0.3-1 to please lintian
  - Versionize libclutter-0.8-dev build-dep
* debian/watch: Fix URL
* debian/copyright: Cleanup copyright file

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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 (ClutterActor *actor,
 
25
    ClutterButtonEvent *event,
 
26
    ChamplainView * view)
 
27
{
 
28
  champlain_view_zoom_in (view);
 
29
  return TRUE;
 
30
}
 
31
 
 
32
static gboolean
 
33
zoom_out (ClutterActor *actor,
 
34
    ClutterButtonEvent *event,
 
35
    ChamplainView * view)
 
36
{
 
37
  champlain_view_zoom_out (view);
 
38
  return TRUE;
 
39
}
 
40
 
 
41
static ClutterActor *
 
42
make_button (char *text)
 
43
{
 
44
  ClutterActor *button, *button_bg, *button_text;
 
45
  ClutterColor white = { 0xff, 0xff, 0xff, 0xff };
 
46
  ClutterColor black = { 0x00, 0x00, 0x00, 0xff };
 
47
  guint width, height;
 
48
 
 
49
  button = clutter_group_new ();
 
50
 
 
51
  button_bg = clutter_rectangle_new_with_color (&white);
 
52
  clutter_container_add_actor (CLUTTER_CONTAINER (button), button_bg);
 
53
  clutter_actor_set_opacity (button_bg, 0xcc);
 
54
 
 
55
  button_text = clutter_label_new_full ("Sans 10", text, &black);
 
56
  clutter_container_add_actor (CLUTTER_CONTAINER (button), button_text);
 
57
  clutter_actor_get_size (button_text, &width, &height);
 
58
 
 
59
  clutter_actor_set_size (button_bg, width + PADDING * 2, height + PADDING * 2);
 
60
  clutter_actor_set_position (button_bg, 0, 0);
 
61
  clutter_actor_set_position (button_text, PADDING, PADDING);
 
62
 
 
63
  return button;
 
64
}
 
65
 
 
66
int
 
67
main (int argc,
 
68
    char *argv[])
 
69
{
 
70
  ClutterActor* actor, *stage, *buttons, *button;
 
71
  ChamplainPolygon *polygon;
 
72
  guint width, total_width = 0;;
 
73
 
 
74
  g_thread_init (NULL);
 
75
  clutter_init (&argc, &argv);
 
76
 
 
77
  stage = clutter_stage_get_default ();
 
78
  clutter_actor_set_size (stage, 800, 600);
 
79
 
 
80
  /* Create the map view */
 
81
  actor = champlain_view_new ();
 
82
  champlain_view_set_size (CHAMPLAIN_VIEW (actor), 800, 600);
 
83
  clutter_container_add_actor (CLUTTER_CONTAINER (stage), actor);
 
84
 
 
85
  /* Create the buttons */
 
86
  buttons = clutter_group_new ();
 
87
  clutter_actor_set_position (buttons, PADDING, PADDING);
 
88
 
 
89
  button = make_button ("Zoom in");
 
90
  clutter_container_add_actor (CLUTTER_CONTAINER (buttons), button);
 
91
  clutter_actor_set_reactive (button, TRUE);
 
92
  clutter_actor_get_size (button, &width, NULL);
 
93
  total_width += width + PADDING;
 
94
  g_signal_connect (button, "button-release-event",
 
95
      G_CALLBACK (zoom_in),
 
96
      actor);
 
97
 
 
98
  button = make_button ("Zoom out");
 
99
  clutter_container_add_actor (CLUTTER_CONTAINER (buttons), button);
 
100
  clutter_actor_set_reactive (button, TRUE);
 
101
  clutter_actor_set_position (button, total_width, 0);
 
102
  clutter_actor_get_size (button, &width, NULL);
 
103
  total_width += width + PADDING;
 
104
  g_signal_connect (button, "button-release-event",
 
105
      G_CALLBACK (zoom_out),
 
106
      actor);
 
107
 
 
108
  clutter_container_add_actor (CLUTTER_CONTAINER (stage), buttons);
 
109
 
 
110
  /* draw a line */
 
111
  polygon = champlain_polygon_new ();
 
112
  /* Cheap approx of Highway 10 */
 
113
  champlain_polygon_append_point (polygon, 45.4095, -73.3197);
 
114
  champlain_polygon_append_point (polygon, 45.4104, -73.2846);
 
115
  champlain_polygon_append_point (polygon, 45.4178, -73.2239);
 
116
  champlain_polygon_append_point (polygon, 45.4176, -73.2181);
 
117
  champlain_polygon_append_point (polygon, 45.4151, -73.2126);
 
118
  champlain_polygon_append_point (polygon, 45.4016, -73.1926);
 
119
  champlain_polygon_append_point (polygon, 45.3994, -73.1877);
 
120
  champlain_polygon_append_point (polygon, 45.4000, -73.1815);
 
121
  champlain_polygon_append_point (polygon, 45.4151, -73.1218);
 
122
  champlain_polygon_set_stroke_width (polygon, 5.0);
 
123
  champlain_view_add_polygon (CHAMPLAIN_VIEW (actor), polygon);
 
124
 
 
125
  /* draw a polygon */
 
126
  polygon = champlain_polygon_new ();
 
127
  champlain_polygon_append_point (polygon, 45.1386, -73.9196);
 
128
  champlain_polygon_append_point (polygon, 45.1229, -73.8991);
 
129
  champlain_polygon_append_point (polygon, 45.0946, -73.9531);
 
130
  champlain_polygon_append_point (polygon, 45.1085, -73.9714);
 
131
  champlain_polygon_append_point (polygon, 45.1104, -73.9761);
 
132
  champlain_view_add_polygon (CHAMPLAIN_VIEW (actor), polygon);
 
133
  g_object_set (polygon, "closed-path", TRUE, NULL);
 
134
  g_object_set (polygon, "fill", TRUE, NULL);
 
135
 
 
136
  /* Finish initialising the map view */
 
137
  g_object_set (G_OBJECT (actor), "zoom-level", 9,
 
138
      "scroll-mode", CHAMPLAIN_SCROLL_MODE_KINETIC, NULL);
 
139
  champlain_view_center_on (CHAMPLAIN_VIEW (actor), 45.466, -73.75);
 
140
 
 
141
  clutter_actor_show (stage);
 
142
  clutter_main ();
 
143
 
 
144
  return 0;
 
145
}