//
// Triple Play - utilities for use in PlayN-based games
// Copyright (c) 2011, Three Rings Design, Inc. - All rights reserved.
// http://github.com/threerings/tripleplay/blob/master/LICENSE

package tripleplay.ui;

import playn.core.PlayN;

import pythagoras.f.IDimension;

/**
 * The root of a display hierarchy. An application can have one or more roots, but they should not
 * overlap and will behave as if oblivious to one another's existence.
 */
public class Root extends Elements<Root>
{
    /**
     * Sizes this root element to its preferred size.
     */
    public Root pack () {
        IDimension psize = preferredSize(0, 0);
        setSize(psize.width(), psize.height());
        return this;
    }

    /**
     * Sizes this root element to the specified width and its preferred height.
     */
    public Root packToWidth (float width) {
        IDimension psize = preferredSize(width, 0);
        setSize(width, psize.height());
        return this;
    }

    /**
     * Sizes this root element to the specified height and its preferred width.
     */
    public Root packToHeight (float height) {
        IDimension psize = preferredSize(0, height);
        setSize(psize.width(), height);
        return this;
    }

    /**
     * Sets the size of this root element.
     */
    public Root setSize (float width, float height) {
        _size.setSize(width, height);
        invalidate();
        return this;
    }

    /**
     * Sets the size of this root element and its translation from its parent.
     */
    public Root setBounds (float x, float y, float width, float height) {
        setSize(width, height);
        setLocation(x, y);
        return this;
    }

    protected Root (Interface iface, Layout layout, Stylesheet sheet) {
        super(layout);
        setStylesheet(sheet);
        _iface = iface;
    }

    @Override protected Root root () {
        return this;
    }

    protected final Interface _iface;
    protected boolean _valid;
    protected Element<?> _active;
}

@@ -223,56 +223,108 @@
 rt p
-layn.core.PlayN;%0A%0Aimport pythagoras.f.IDimension
+ythagoras.f.IDimension;%0Aimport pythagoras.f.Point;%0A%0Aimport playn.core.Layer;%0Aimport playn.core.PlayN
 ;%0A%0A/
@@ -1896,73 +1896,1003 @@
 ce;%0A
-    %7D%0A%0A    @Override protected Root root () %7B%0A        return this
+%0A        if (absorbsClicks()) %7B%0A            layer.setHitTester(new Layer.HitTester() %7B%0A                public Layer hitTest (Layer layer, Point p) %7B%0A                    if (!isVisible() %7C%7C !contains(p.x, p.y)) return null;%0A                    // if this click doesn't hit anything else, it hits us%0A                    Layer hit = layer.hitTestDefault(p);%0A                    return (hit != null) ? hit : Root.this.layer;%0A                %7D%0A            %7D);%0A        %7D%0A    %7D%0A%0A    @Override protected Root root () %7B%0A        return this;%0A    %7D%0A%0A    /**%0A     * By default, all clicks that fall within a root's bounds are dispatched to the root's layer%0A     * if they do not land on an interactive child element. This prevents clicks from %22falling%0A     * through%22 to lower roots, which are visually obscured by this root. Override this method and%0A     * return false if you want this root not to absorb clicks (if it's %22transparent%22).%0A     */%0A    protected boolean absorbsClicks () %7B%0A        return true
 ;%0A  

Make roots absorb clicks (in their bounds) by default.