Search in sources :

Example 1 with ToggleButton

use of spacegraph.space2d.widget.button.ToggleButton in project narchy by automenta.

the class PhyWall method snake.

protected Snake snake(Wire wire, Runnable onRemove) {
    Surface source = wire.a;
    Surface target = wire.b;
    assert (source != target);
    float sa = source.bounds.area();
    float ta = target.bounds.area();
    float areaDiff = Math.abs(sa - ta) / (sa + ta);
    // heuristic estimate: larger area difference = shorter snake
    int segments = Util.lerp(areaDiff, 8, 6);
    float EXPAND_SCALE_FACTOR = 4;
    PushButton deleteButton = new PushButton("x");
    Surface menu = new TabPane(ButtonSet.Mode.Multi, Map.of("o", () -> new Gridding(new Label(source.toString()), new Label(target.toString()), deleteButton)), (l) -> new CheckBox(l) {

        @Override
        protected String label(String text, boolean on) {
            // override just display the 'o'
            return text;
        }

        @Override
        public ToggleButton set(boolean expanded) {
            super.set(expanded);
            synchronized (wire) {
                PhyWindow w = parent(PhyWindow.class);
                if (w == null)
                    return this;
                float cx = w.cx();
                float cy = w.cy();
                float ww, hh;
                if (expanded) {
                    // grow
                    ww = w.w() * EXPAND_SCALE_FACTOR;
                    hh = w.h() * EXPAND_SCALE_FACTOR;
                } else {
                    // shrink
                    ww = w.w() / EXPAND_SCALE_FACTOR;
                    hh = w.h() / EXPAND_SCALE_FACTOR;
                }
                w.pos(cx - ww / 2, cy - hh / 2, cx + ww / 2, cy + hh / 2);
            }
            return this;
        }
    });
    PhyWindow menuBody = put(menu, RectFloat2D.mid(source.bounds, target.bounds, 0.1f));
    float mw = menuBody.radius();
    Snake s = new Snake(source, target, segments, 1.618f * 2 * mw, mw) {

        @Override
        public void remove() {
            onRemove.run();
            super.remove();
        }
    };
    s.attach(menuBody.body, segments / 2 - 1);
    deleteButton.click(s::remove);
    int jj = 0;
    for (Joint j : s.joints) {
        float p = ((float) jj) / (segments - 1);
        // custom joint renderer: color coded indicate activity and type of data
        j.setData((ObjectLongProcedure<GL2>) (g, now) -> {
            int TIME_DECAY_MS = 250;
            boolean side = p < 0.5f;
            float activity = wire.activity(side, now, TIME_DECAY_MS);
            // Util.lerp(p, wire.activity(false, now, TIME_DECAY_MS), wire.activity(true, now, TIME_DECAY_MS));
            int th = wire.typeHash(side);
            if (th == 0) {
                g.glColor4f(0.5f, 0.5f, 0.5f, 0.5f);
            } else {
                Draw.colorHash(g, th, 0.9f, 0.5f + 0.5f * activity, 0.5f + 0.4f * activity);
            }
            g.glLineWidth(10f + activity * 10f);
        // Draw.line(g, w.a.cx(), w.a.cy(), w.b.cx(), w.b.cy());
        // return;
        });
        jj++;
    }
    return s;
}
Also used : RayCastInput(spacegraph.space2d.phys.collision.RayCastInput) Random(java.util.Random) ParticleColor(spacegraph.space2d.phys.particle.ParticleColor) ButtonSet(spacegraph.space2d.widget.tab.ButtonSet) TabPane(spacegraph.space2d.widget.tab.TabPane) ParticleSystem(spacegraph.space2d.phys.particle.ParticleSystem) spacegraph.space2d.phys.dynamics.joints(spacegraph.space2d.phys.dynamics.joints) ToggleButton(spacegraph.space2d.widget.button.ToggleButton) Map(java.util.Map) Finger(spacegraph.input.finger.Finger) XoRoShiRo128PlusRandom(jcog.math.random.XoRoShiRo128PlusRandom) PolygonShape(spacegraph.space2d.phys.collision.shapes.PolygonShape) NodeGraph(jcog.data.graph.NodeGraph) CircleShape(spacegraph.space2d.phys.collision.shapes.CircleShape) MapNodeGraph(jcog.data.graph.MapNodeGraph) Util(jcog.Util) Animated(spacegraph.util.animate.Animated) List(java.util.List) ImmutableDirectedEdge(jcog.data.graph.ImmutableDirectedEdge) GL2(com.jogamp.opengl.GL2) WizardFrame(spacegraph.space2d.widget.meta.WizardFrame) ObjectLongProcedure(org.eclipse.collections.api.block.procedure.primitive.ObjectLongProcedure) Shape(spacegraph.space2d.phys.collision.shapes.Shape) PolygonFixture(spacegraph.space2d.phys.fracture.PolygonFixture) spacegraph.space2d.phys.dynamics(spacegraph.space2d.phys.dynamics) Surface(spacegraph.space2d.Surface) Draw(spacegraph.video.Draw) Supplier(java.util.function.Supplier) Tuple2f(spacegraph.util.math.Tuple2f) EdgeShape(spacegraph.space2d.phys.collision.shapes.EdgeShape) Tuples.pair(org.eclipse.collections.impl.tuple.Tuples.pair) DoubleClicking(spacegraph.input.finger.DoubleClicking) Gridding(spacegraph.space2d.container.Gridding) On(jcog.event.On) AABB(spacegraph.space2d.phys.collision.AABB) RayCastOutput(spacegraph.space2d.phys.collision.RayCastOutput) Pair(org.eclipse.collections.api.tuple.Pair) Ortho(spacegraph.space2d.hud.Ortho) PushButton(spacegraph.space2d.widget.button.PushButton) FasterList(jcog.list.FasterList) Transform(spacegraph.space2d.phys.common.Transform) spacegraph.util.math.v2(spacegraph.util.math.v2) RectFloat2D(jcog.tree.rtree.rect.RectFloat2D) CheckBox(spacegraph.space2d.widget.button.CheckBox) Consumer(java.util.function.Consumer) ArrayIterator(jcog.util.ArrayIterator) FingerDragging(spacegraph.input.finger.FingerDragging) SurfaceBase(spacegraph.space2d.SurfaceBase) ProtoWidget(spacegraph.space2d.widget.meta.ProtoWidget) Collections(java.util.Collections) Label(spacegraph.space2d.widget.text.Label) TabPane(spacegraph.space2d.widget.tab.TabPane) ToggleButton(spacegraph.space2d.widget.button.ToggleButton) Label(spacegraph.space2d.widget.text.Label) GL2(com.jogamp.opengl.GL2) Surface(spacegraph.space2d.Surface) Gridding(spacegraph.space2d.container.Gridding) spacegraph.space2d.phys.dynamics.joints(spacegraph.space2d.phys.dynamics.joints) spacegraph.space2d.phys.dynamics(spacegraph.space2d.phys.dynamics) Collections(java.util.Collections) CheckBox(spacegraph.space2d.widget.button.CheckBox) PushButton(spacegraph.space2d.widget.button.PushButton)

Example 2 with ToggleButton

use of spacegraph.space2d.widget.button.ToggleButton in project narchy by automenta.

the class AutoSurface method newSwitch.

private ButtonSet newSwitch(EnumParam x) {
    ToggleButton[] b = ((EnumSet<?>) EnumSet.allOf(x.klass)).stream().map(e -> {
        CheckBox tb = new CheckBox(e.name());
        tb.on((c, enabled) -> {
            if (enabled)
                x.set(e);
        });
        return tb;
    }).toArray(ToggleButton[]::new);
    ButtonSet s = new ButtonSet(ButtonSet.Mode.One, b);
    return s;
}
Also used : java.util(java.util) Surface(spacegraph.space2d.Surface) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Widget(spacegraph.space2d.widget.windo.Widget) IntSlider(spacegraph.space2d.widget.slider.IntSlider) ButtonSet(spacegraph.space2d.widget.tab.ButtonSet) Gridding(spacegraph.space2d.container.Gridding) ToggleButton(spacegraph.space2d.widget.button.ToggleButton) LabeledPane(spacegraph.space2d.widget.text.LabeledPane) FloatSlider(spacegraph.space2d.widget.slider.FloatSlider) PushButton(spacegraph.space2d.widget.button.PushButton) Ons(jcog.event.Ons) FasterList(jcog.list.FasterList) EnumParam(jcog.math.EnumParam) FloatRange(jcog.math.FloatRange) Service(jcog.Service) IntRange(jcog.math.IntRange) Field(java.lang.reflect.Field) Sets(com.google.common.collect.Sets) CheckBox(spacegraph.space2d.widget.button.CheckBox) Nullable(org.jetbrains.annotations.Nullable) SurfaceBase(spacegraph.space2d.SurfaceBase) SpaceGraph(spacegraph.SpaceGraph) Modifier(java.lang.reflect.Modifier) Services(jcog.Services) ToggleButton(spacegraph.space2d.widget.button.ToggleButton) ButtonSet(spacegraph.space2d.widget.tab.ButtonSet) CheckBox(spacegraph.space2d.widget.button.CheckBox)

Aggregations

FasterList (jcog.list.FasterList)2 Surface (spacegraph.space2d.Surface)2 SurfaceBase (spacegraph.space2d.SurfaceBase)2 Gridding (spacegraph.space2d.container.Gridding)2 CheckBox (spacegraph.space2d.widget.button.CheckBox)2 PushButton (spacegraph.space2d.widget.button.PushButton)2 ToggleButton (spacegraph.space2d.widget.button.ToggleButton)2 ButtonSet (spacegraph.space2d.widget.tab.ButtonSet)2 Sets (com.google.common.collect.Sets)1 GL2 (com.jogamp.opengl.GL2)1 Field (java.lang.reflect.Field)1 Modifier (java.lang.reflect.Modifier)1 java.util (java.util)1 Collections (java.util.Collections)1 List (java.util.List)1 Map (java.util.Map)1 Random (java.util.Random)1 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1 Consumer (java.util.function.Consumer)1 Supplier (java.util.function.Supplier)1