#!/usr/bin/env gjs
/*
 * Copyright 2010 Intel Corporation.
 *
 * This program is free software; you can redistribute it and/or modify it
 * under the terms and conditions of the GNU Lesser General Public License,
 * version 2.1, as published by the Free Software Foundation.
 *
 * This program is distributed in the hope 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 program; if not, write to the Free Software Foundation,
 * Inc., 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
 * Boston, MA 02111-1307, USA.
 *
 */

const Clutter = imports.gi.Clutter;
const Mx = imports.gi.Mx;

Clutter.init (0, null);

let app = new Mx.Application ( {"application-name": "You Can't Touch This"} );

let stage = app.create_window ();
let group = new Clutter.Group ();

let button = new Mx.Button ( {label: "STOP!"} )
group.add_actor (button);

stage.add_actor (group);

group.set_size (400, 400);

button.set_position (100, 50);

group.set_reactive (true);
group.connect ("motion-event",
               function (g, e) {
                 let [x, y] = e.get_coords ();
                 y -= group.y;

                 while ((x >= button.x) &&
                        (x < button.x + button.width) &&
                        (y >= button.y) &&
                        (y < button.y + button.height)) {
                   button.set_position (Math.random() *
                                          (group.width - button.width),
                                        Math.random() *
                                          (group.height - button.height));
                 }
               });

stage.show ();
app.run ();


