1
/*
2
 * Copyright (C) 2010 Simon Wenner <simon@wenner.ch>
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
using GLib;
20
using Clutter;
21
using Champlain;
22
23
public class Launcher : GLib.Object
24
{
25
  private const int PADDING = 10;
26
  private Champlain.View view;
27
  private Clutter.Stage stage;
28
29
  public Launcher ()
30
  {
31
    float width, total_width = 0;
32
33
    stage = Clutter.Stage.get_default ();
34
    stage.title = "Champlain Vala Example";
35
    stage.set_size (800, 600);
36
37
    /* Create the map view */
38
    view = new Champlain.View ();
39
    view.set_size (800, 600);
40
    stage.add_actor (view);
41
42
    /* Create the buttons */
43
    var buttons = new Clutter.Group ();
44
    buttons.set_position (PADDING, PADDING);
45
46
    var button = make_button ("Zoom in");
47
    buttons.add_actor (button);
48
    button.reactive = true;
49
    button.get_size (out width, null);
50
    total_width += width + PADDING;
51
    button.button_release_event.connect ((event) => {
52
        view.zoom_in ();
53
        return true;
54
      });
55
56
    button = make_button ("Zoom out");
57
    buttons.add_actor (button);
58
    button.reactive = true;
59
    button.set_position (total_width, 0);
60
    button.get_size (out width, null);
61
    total_width += width + PADDING;
62
    button.button_release_event.connect ((event) => {
63
        view.zoom_out ();
64
        return true;
65
      });
66
67
    stage.add_actor (buttons);
68
69
    /* Create the markers and marker layer */
70
    var layer = new  DemoLayer ();
71
    view.add_layer (layer);
72
73
    /* Connect to the click event */
74
    view.reactive = true;
75
    view.button_release_event.connect (button_release_cb);
76
77
    /* Finish initialising the map view */
78
    view.zoom_level = 7;
79
    view.kinetic_mode = true;
80
    view.center_on (45.466, -73.75);
81
  }
82
83
  public void show ()
84
  {
85
    stage.show ();
86
  }
87
88
  private bool button_release_cb (Clutter.ButtonEvent event)
89
  {
90
    double lat, lon;
91
92
    if (event.button != 1 || event.click_count > 1)
93
      return false;
94
      
95
    lat = view.y_to_latitude (event.y);
96
    lon = view.x_to_longitude (event.x);
97
98
    GLib.print ("Map clicked at %f, %f \n", lat, lon);
99
100
    return true;
101
  }
102
103
  public Clutter.Actor make_button (string text)
104
  {
105
    Clutter.Color white = { 0xff, 0xff, 0xff, 0xff };
106
    Clutter.Color black = { 0x00, 0x00, 0x00, 0xff };
107
    float width, height;
108
109
    var button = new Clutter.Group ();
110
111
    var button_bg = new Clutter.Rectangle.with_color (white);
112
    button.add_actor (button_bg);
113
    button_bg.opacity = 0xcc;
114
115
    var button_text = new Clutter.Text.full ("Sans 10", text, black);
116
    button.add_actor (button_text);
117
    button_text.get_size (out width, out height);
118
119
    button_bg.set_size (width + PADDING * 2, height + PADDING * 2);
120
    button_bg.set_position (0, 0);
121
    button_text.set_position (PADDING, PADDING);
122
123
    return button;
124
  }
125
126
  public static int main (string[] args)
127
  {
128
    if (Clutter.init (ref args) != InitError.SUCCESS)
129
      return 1;
130
131
    var launcher = new Launcher ();
132
    launcher.show ();
133
    Clutter.main ();
134
    return 0;
135
  }
136
}