| 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 |
#include "markers.h" |
| 21 |
|
| 22 |
#define PADDING 10 |
| 23 |
|
| 24 |
static gboolean |
| 25 |
map_view_button_release_cb (G_GNUC_UNUSED ClutterActor *actor, |
| 26 |
ClutterButtonEvent *event, |
| 27 |
ChamplainView *view) |
| 28 |
{ |
| 29 |
gdouble lat, lon; |
| 30 |
|
| 31 |
if (event->button != 1 || event->click_count > 1) |
| 32 |
return FALSE; |
| 33 |
|
| 34 |
lon = champlain_view_x_to_longitude (view, event->x); |
| 35 |
lat = champlain_view_y_to_latitude (view, event->y); |
| 36 |
|
| 37 |
g_print ("Map clicked at %f, %f \n", lat, lon); |
| 38 |
|
| 39 |
return TRUE; |
| 40 |
} |
| 41 |
|
| 42 |
|
| 43 |
static gboolean |
| 44 |
zoom_in (G_GNUC_UNUSED ClutterActor *actor, |
| 45 |
G_GNUC_UNUSED ClutterButtonEvent *event, |
| 46 |
ChamplainView *view) |
| 47 |
{ |
| 48 |
champlain_view_zoom_in (view); |
| 49 |
return TRUE; |
| 50 |
} |
| 51 |
|
| 52 |
|
| 53 |
static gboolean |
| 54 |
zoom_out (G_GNUC_UNUSED ClutterActor *actor, |
| 55 |
G_GNUC_UNUSED ClutterButtonEvent *event, |
| 56 |
ChamplainView *view) |
| 57 |
{ |
| 58 |
champlain_view_zoom_out (view); |
| 59 |
return TRUE; |
| 60 |
} |
| 61 |
|
| 62 |
|
| 63 |
static ClutterActor * |
| 64 |
make_button (char *text) |
| 65 |
{ |
| 66 |
ClutterActor *button, *button_bg, *button_text; |
| 67 |
ClutterColor white = { 0xff, 0xff, 0xff, 0xff }; |
| 68 |
ClutterColor black = { 0x00, 0x00, 0x00, 0xff }; |
| 69 |
gfloat width, height; |
| 70 |
|
| 71 |
button = clutter_group_new (); |
| 72 |
|
| 73 |
button_bg = clutter_rectangle_new_with_color (&white); |
| 74 |
clutter_container_add_actor (CLUTTER_CONTAINER (button), button_bg); |
| 75 |
clutter_actor_set_opacity (button_bg, 0xcc); |
| 76 |
|
| 77 |
button_text = clutter_text_new_full ("Sans 10", text, &black); |
| 78 |
clutter_container_add_actor (CLUTTER_CONTAINER (button), button_text); |
| 79 |
clutter_actor_get_size (button_text, &width, &height); |
| 80 |
|
| 81 |
clutter_actor_set_size (button_bg, width + PADDING * 2, height + PADDING * 2); |
| 82 |
clutter_actor_set_position (button_bg, 0, 0); |
| 83 |
clutter_actor_set_position (button_text, PADDING, PADDING); |
| 84 |
|
| 85 |
return button; |
| 86 |
} |
| 87 |
|
| 88 |
|
| 89 |
int |
| 90 |
main (int argc, |
| 91 |
char *argv[]) |
| 92 |
{ |
| 93 |
ClutterActor *actor, *stage, *buttons, *button; |
| 94 |
ChamplainMarkerLayer *layer; |
| 95 |
ChamplainPathLayer *path; |
| 96 |
gfloat width, total_width = 0; |
| 97 |
|
| 98 |
if (clutter_init (&argc, &argv) != CLUTTER_INIT_SUCCESS) |
| 99 |
return 1; |
| 100 |
|
| 101 |
stage = clutter_stage_new (); |
| 102 |
clutter_actor_set_size (stage, 800, 600); |
| 103 |
g_signal_connect (stage, "destroy", G_CALLBACK (clutter_main_quit), NULL); |
| 104 |
|
| 105 |
/* Create the map view */ |
| 106 |
actor = champlain_view_new (); |
| 107 |
clutter_actor_set_size (CLUTTER_ACTOR (actor), 800, 600); |
| 108 |
clutter_container_add_actor (CLUTTER_CONTAINER (stage), actor); |
| 109 |
|
| 110 |
/* Create the buttons */ |
| 111 |
buttons = clutter_group_new (); |
| 112 |
clutter_actor_set_position (buttons, PADDING, PADDING); |
| 113 |
|
| 114 |
button = make_button ("Zoom in"); |
| 115 |
clutter_container_add_actor (CLUTTER_CONTAINER (buttons), button); |
| 116 |
clutter_actor_set_reactive (button, TRUE); |
| 117 |
clutter_actor_get_size (button, &width, NULL); |
| 118 |
total_width += width + PADDING; |
| 119 |
g_signal_connect (button, "button-release-event", |
| 120 |
G_CALLBACK (zoom_in), |
| 121 |
actor); |
| 122 |
|
| 123 |
button = make_button ("Zoom out"); |
| 124 |
clutter_container_add_actor (CLUTTER_CONTAINER (buttons), button); |
| 125 |
clutter_actor_set_reactive (button, TRUE); |
| 126 |
clutter_actor_set_position (button, total_width, 0); |
| 127 |
clutter_actor_get_size (button, &width, NULL); |
| 128 |
g_signal_connect (button, "button-release-event", |
| 129 |
G_CALLBACK (zoom_out), |
| 130 |
actor); |
| 131 |
|
| 132 |
clutter_container_add_actor (CLUTTER_CONTAINER (stage), buttons); |
| 133 |
|
| 134 |
/* Create the markers and marker layer */ |
| 135 |
layer = create_marker_layer (CHAMPLAIN_VIEW (actor), &path); |
| 136 |
champlain_view_add_layer (CHAMPLAIN_VIEW (actor), CHAMPLAIN_LAYER (layer)); |
| 137 |
|
| 138 |
/* Connect to the click event */ |
| 139 |
clutter_actor_set_reactive (actor, TRUE); |
| 140 |
g_signal_connect (actor, "button-release-event", |
| 141 |
G_CALLBACK (map_view_button_release_cb), |
| 142 |
actor); |
| 143 |
|
| 144 |
/* Finish initialising the map view */ |
| 145 |
g_object_set (G_OBJECT (actor), "zoom-level", 12, |
| 146 |
"kinetic-mode", TRUE, NULL); |
| 147 |
champlain_view_center_on (CHAMPLAIN_VIEW (actor), 45.466, -73.75); |
| 148 |
|
| 149 |
clutter_actor_show (stage); |
| 150 |
clutter_main (); |
| 151 |
|
| 152 |
return 0; |
| 153 |
} |