const Lang = imports.lang;
const Clutter = imports.gi.Clutter;

Clutter.init(null, null);

let stage = new Clutter.Stage();
stage.set_size(800, 600);
stage.connect('destroy',
              Lang.bind(this, function() { Clutter.main_quit(); }));


let group = new Clutter.Actor();
group.add_effect(new Clutter.BlurEffect());
stage.add_child(group);

for (let i = 0; i < 20; i++) {
    let rect = new Clutter.Actor({ background_color: Clutter.Color.new(255 * Math.random(),
                                                                       255 * Math.random(),
                                                                       255 * Math.random(),
                                                                       0xff),
                                   width: 100,
                                   height: 100,
                                   x: (stage.width - 100) * Math.random(),
                                   y: (stage.height - 100) * Math.random(),
                                 });

    group.add_child(rect);
}

stage.connect('scroll-event', Lang.bind(this, function(actor, event) {
    let [ex, ey] = event.get_coords();
    let [success, tx, ty] = group.transform_stage_point(ex, ey);

    group.set_pivot_point(tx / group.width, ty / group.height);
    switch (event.get_scroll_direction()) {
    case Clutter.ScrollDirection.UP:
        group.scale_x = group.scale_x + 0.1;
        group.scale_y = group.scale_y + 0.1;
        break;
    case Clutter.ScrollDirection.DOWN:
        group.scale_x = Math.max(0.1, group.scale_x - 0.1);
        group.scale_y = Math.max(0.1, group.scale_y - 0.1);
        break;
    }
}));

stage.show();
Clutter.main();
