Search in sources :

Example 16 with Surface

use of spacegraph.space2d.Surface in project narchy by automenta.

the class Ortho method updateMouse.

/**
 * called each frame regardless of mouse activity
 */
Surface updateMouse(float sx, float sy, short[] buttonsDown) {
    if (!updatingMouse.compareAndSet(false, true)) {
        error(this, 1f, "update collision; skipped");
        // skipped - this is BAD. maybe should be properly queued
        return null;
    }
    try {
        Surface touching = finger.touching;
        Surface touchedNext = finger.on(surface, sx, sy, buttonsDown);
        if (touchedNext != null && touchedNext != touching) {
            debug(this, 1f, () -> "touch(" + touchedNext + ")");
        }
        return touchedNext;
    } finally {
        updatingMouse.set(false);
    }
}
Also used : Surface(spacegraph.space2d.Surface) EmptySurface(spacegraph.space2d.container.EmptySurface)

Example 17 with Surface

use of spacegraph.space2d.Surface in project narchy by automenta.

the class Container method onTouch.

@Override
public Surface onTouch(Finger finger, short[] buttons) {
    if (!visible())
        return null;
    if (childrenCount() > 0) {
        // Draw forward, propagate touch events backwards
        if (finger == null) {
            forEach(c -> c.onTouch(null, null));
            return null;
        } else {
            // HACK
            final Surface[] found = { null };
            float fx = finger.pos.x;
            float fy = finger.pos.y;
            // iterate in reverse, so that the contents drawn last are tested first for interaction (sloppy z-ordering)
            whileEachReverse(c -> {
                if (!clipTouchBounds || (fx >= c.left() && fx <= c.right() && fy >= c.top() && fy <= c.bottom())) {
                    Surface s = c.onTouch(finger, buttons);
                    if (s != null) {
                        if (found[0] == null || found[0].bounds.cost() > s.bounds.cost())
                            // FIFO
                            found[0] = s;
                    }
                }
                // while null
                return found[0] == null;
            });
            if ((found[0]) != null)
                return found[0];
        }
    }
    return tangible() ? this : null;
}
Also used : Surface(spacegraph.space2d.Surface)

Example 18 with Surface

use of spacegraph.space2d.Surface in project narchy by automenta.

the class ExeCharts method metaGoalControls.

public static Surface metaGoalControls(NAR n) {
    CheckBox auto = new CheckBox("Auto");
    auto.set(false);
    float[] want = n.emotion.want;
    Gridding g = grid(// Stream.of(auto),
    IntStream.range(0, want.length).mapToObj(w -> new FloatSlider(want[w], -1f, +1f) {

        @Override
        protected void paintWidget(GL2 gl, RectFloat2D bounds) {
            if (auto.on()) {
                value(want[w]);
            }
        }
    }.text(MetaGoal.values()[w].name()).type(BaseSlider.Knob).on((s, v) -> {
        if (!auto.on())
            want[w] = v;
    })).toArray(Surface[]::new));
    return g;
}
Also used : GL2(com.jogamp.opengl.GL2) IntStream(java.util.stream.IntStream) BaseSlider(spacegraph.space2d.widget.slider.BaseSlider) DurService(nars.control.DurService) Causable(nars.exe.Causable) Surface(spacegraph.space2d.Surface) TreeChart(spacegraph.space2d.widget.meter.TreeChart) StringUtils(org.apache.commons.lang3.StringUtils) Draw(spacegraph.video.Draw) Function(java.util.function.Function) AutoSurface(spacegraph.space2d.widget.meta.AutoSurface) Traffic(nars.control.Traffic) Gridding(spacegraph.space2d.container.Gridding) BitmapMatrixView(spacegraph.space2d.widget.meter.BitmapMatrixView) FloatSlider(spacegraph.space2d.widget.slider.FloatSlider) NAgent(nars.NAgent) FasterList(jcog.list.FasterList) FloatRange(jcog.math.FloatRange) nars.$(nars.$) LoopPanel(spacegraph.space2d.widget.meta.LoopPanel) Collectors(java.util.stream.Collectors) Util(jcog.Util) RectFloat2D(jcog.tree.rtree.rect.RectFloat2D) CheckBox(spacegraph.space2d.widget.button.CheckBox) List(java.util.List) Splitting(spacegraph.space2d.container.Splitting) NAR(nars.NAR) Cause(nars.control.Cause) MetaGoal(nars.control.MetaGoal) FloatFunction(org.eclipse.collections.api.block.function.primitive.FloatFunction) Label(spacegraph.space2d.widget.text.Label) Gridding(spacegraph.space2d.container.Gridding) CheckBox(spacegraph.space2d.widget.button.CheckBox) FloatSlider(spacegraph.space2d.widget.slider.FloatSlider) RectFloat2D(jcog.tree.rtree.rect.RectFloat2D) GL2(com.jogamp.opengl.GL2) Surface(spacegraph.space2d.Surface) AutoSurface(spacegraph.space2d.widget.meta.AutoSurface)

Example 19 with Surface

use of spacegraph.space2d.Surface in project narchy by automenta.

the class ExeCharts method metaGoalChart.

private static Surface metaGoalChart(NAgent a) {
    return new TreeChart<Cause>() {

        final DurService on;

        final FasterList<ItemVis<Cause>> cache = new FasterList();

        final Function<Cause, TreeChart.ItemVis<Cause>> builder = ((i) -> {
            short id = i.id;
            ItemVis<Cause> item;
            if (cache.capacity() - 1 < id)
                cache.ensureCapacity(id + 16);
            else {
                item = cache.get(id);
                if (item != null)
                    return item;
            }
            String str = i.toString();
            if (str.startsWith("class nars."))
                // skip default toString
                str = str.substring("class nars.".length());
            if (str.startsWith("class "))
                // skip default toString
                str = str.substring(5);
            item = new CauseVis(i, str);
            cache.set(id, item);
            return item;
        });

        {
            on = a.onFrame(() -> {
                update(a.nar().causes, (c, i) -> {
                    float v = c.value();
                    float r, g, b;
                    if (v < 0) {
                        r = 0.75f * Math.max(0.1f, Math.min(1f, -v));
                        g = 0;
                    } else {
                        g = 0.75f * Math.max(0.1f, Math.min(1f, +v));
                        r = 0;
                    }
                    float t = Util.sum(((FloatFunction<Traffic>) (p -> Math.abs(p.last))), c.goal);
                    b = Math.max(r, g) / 2f * Util.unitize(t);
                    i.update(v, r, g, b);
                // i.updateMomentum(
                // //0.01f + Util.sqr(Util.tanhFast(v)+1),
                // //Math.signum(v) *(1+Math.abs(v))*(t),
                // //Math.signum(v) * t,
                // v,
                // 0.25f,
                // r, g, b);
                }, builder);
            });
        }

        @Override
        public void stop() {
            super.stop();
            on.off();
        }
    };
}
Also used : GL2(com.jogamp.opengl.GL2) IntStream(java.util.stream.IntStream) BaseSlider(spacegraph.space2d.widget.slider.BaseSlider) DurService(nars.control.DurService) Causable(nars.exe.Causable) Surface(spacegraph.space2d.Surface) TreeChart(spacegraph.space2d.widget.meter.TreeChart) StringUtils(org.apache.commons.lang3.StringUtils) Draw(spacegraph.video.Draw) Function(java.util.function.Function) AutoSurface(spacegraph.space2d.widget.meta.AutoSurface) Traffic(nars.control.Traffic) Gridding(spacegraph.space2d.container.Gridding) BitmapMatrixView(spacegraph.space2d.widget.meter.BitmapMatrixView) FloatSlider(spacegraph.space2d.widget.slider.FloatSlider) NAgent(nars.NAgent) FasterList(jcog.list.FasterList) FloatRange(jcog.math.FloatRange) nars.$(nars.$) LoopPanel(spacegraph.space2d.widget.meta.LoopPanel) Collectors(java.util.stream.Collectors) Util(jcog.Util) RectFloat2D(jcog.tree.rtree.rect.RectFloat2D) CheckBox(spacegraph.space2d.widget.button.CheckBox) List(java.util.List) Splitting(spacegraph.space2d.container.Splitting) NAR(nars.NAR) Cause(nars.control.Cause) MetaGoal(nars.control.MetaGoal) FloatFunction(org.eclipse.collections.api.block.function.primitive.FloatFunction) Label(spacegraph.space2d.widget.text.Label) Function(java.util.function.Function) FloatFunction(org.eclipse.collections.api.block.function.primitive.FloatFunction) FasterList(jcog.list.FasterList) Cause(nars.control.Cause) Traffic(nars.control.Traffic) TreeChart(spacegraph.space2d.widget.meter.TreeChart) DurService(nars.control.DurService)

Example 20 with Surface

use of spacegraph.space2d.Surface in project narchy by automenta.

the class ExeCharts method runPanel.

public static Surface runPanel(NAR n) {
    Label nameLabel;
    LoopPanel control = new LoopPanel(n.loop);
    Surface p = new Gridding(nameLabel = new Label(n.self().toString()), control);
    return DurSurface.get(p, n, () -> {
        control.update();
    });
}
Also used : Gridding(spacegraph.space2d.container.Gridding) Label(spacegraph.space2d.widget.text.Label) LoopPanel(spacegraph.space2d.widget.meta.LoopPanel) Surface(spacegraph.space2d.Surface) AutoSurface(spacegraph.space2d.widget.meta.AutoSurface)

Aggregations

Surface (spacegraph.space2d.Surface)24 Util (jcog.Util)7 GL2 (com.jogamp.opengl.GL2)5 Gridding (spacegraph.space2d.container.Gridding)5 List (java.util.List)4 FasterList (jcog.list.FasterList)4 Label (spacegraph.space2d.widget.text.Label)4 spacegraph.util.math.v2 (spacegraph.util.math.v2)4 Draw (spacegraph.video.Draw)4 Function (java.util.function.Function)3 IntStream (java.util.stream.IntStream)3 RectFloat2D (jcog.tree.rtree.rect.RectFloat2D)3 CheckBox (spacegraph.space2d.widget.button.CheckBox)3 AutoSurface (spacegraph.space2d.widget.meta.AutoSurface)3 LoopPanel (spacegraph.space2d.widget.meta.LoopPanel)3 java.awt (java.awt)2 Collectors (java.util.stream.Collectors)2 TODO (jcog.TODO)2 MapNodeGraph (jcog.data.graph.MapNodeGraph)2 NodeGraph (jcog.data.graph.NodeGraph)2