Skip to content

NodeEffect

abstract class NodeEffect<T extends Node>
Implements: Cloneable
Known subtypes: BlurNodeEffect, BorderNodeEffect, CircleNodeEffect, MaskNodeEffect, RoundedNodeEffect, ShadowNodeEffect, TransformNodeEffect
Package: dev.joid.lib.ui.node.effect · Module: core · Source: NodeEffect.java

Base of every effect, an object added to a node that changes how the node is drawn, never its layout nor the area that receives the mouse.

A NodeEffect changes how its node is drawn: it draws around the node, changes the matrix or the render state for it, or processes its pixels with shader passes. Node.effect adds one to any node, and a node holds one effect per class. Use the built-in effects first: RoundedNodeEffect, CircleNodeEffect, BorderNodeEffect, ShadowNodeEffect, BlurNodeEffect, MaskNodeEffect and TransformNodeEffect. Extend NodeEffect for a treatment that none of them gives: Draw around a node writes one.

Every frame, JOID keeps the effects whose shouldApply returns true and orders them by priority: the lowest priority wraps the others, and its passes run first. The type parameter limits the nodes that take the effect: a NodeEffect<RectNode> goes on a RectNode and its subclasses only.

ReturnsSignatureSummary
NodeEffect() protectedCalled by a subclass for an effect of priority 0.
NodeEffect(int priority) protectedCalled by a subclass for an effect of the given priority.

PropertyTypeDefaultSummary
priority signalintset at creationPlace of the effect among the effects of its node: a lower priority starts earlier and wraps the effects of higher priority, and its shader passes run before theirs.
scope signalNodeEffectScopeNodeEffectScope.SELFWhat the shader passes of the effect process: SELF, the drawing of the node alone, or CHILDREN, the node with its children and its layers.

ReturnsSignatureSummary
voiddraw(T node, Runnable body)Hook that JOID calls on every frame while the effect applies, in the coordinates of the parent: the node sits at getX(), getY().
booleanshouldApply(T node)Hook that JOID calls on every frame before the node draws: false skips draw and the shader passes for this frame.
IShaderPasstoShaderPass(T node)Hook that returns the single IShaderPass that processes the pixels of the node on this frame, or null for an effect without pass.
List<IShaderPass>toShaderPasses(T node)Hook that returns every pass of the effect for this frame, in order.
Ecopy()Returns a shallow copy of the effect: the copy shares the values and the suppliers of the original.
ReturnsSignatureSummary
voidinit(T node, UI ui) hookHook that JOID calls when the node joins a UI, and when the effect is added to a node that is already in one.
voiddetach(T node) hookHook that JOID calls when the node leaves its UI, and when the effect is removed or replaced on a node that is in one.

NodeEffect() protected

Called by a subclass for an effect of priority 0.

NodeEffect(int priority) protected

Called by a subclass for an effect of the given priority.

  • this priority(int priority) fluent
  • this priority(Supplier<Integer> priority) fluent signal
  • int getPriority()

Default: set at creation

Place of the effect among the effects of its node: a lower priority starts earlier and wraps the effects of higher priority, and its shader passes run before theirs. Two effects of the same priority keep the order in which they were added.

  • this scope(NodeEffectScope scope) fluent
  • this scope(Supplier<NodeEffectScope> scope) fluent signal
  • NodeEffectScope getScope()

Default: NodeEffectScope.SELF

What the shader passes of the effect process: SELF, the drawing of the node alone, or CHILDREN, the node with its children and its layers. It has no effect on draw, which always wraps the node and its children.

void draw(T node, Runnable body)

Hook that JOID calls on every frame while the effect applies, in the coordinates of the parent: the node sits at getX(), getY(). An override draws before or after body, or changes the matrix or the render state around it and restores them; it runs body once, or the node disappears. By default, it runs body alone.

boolean shouldApply(T node)

Hook that JOID calls on every frame before the node draws: false skips draw and the shader passes for this frame. The built-in effects return false when they would change nothing, such as a border of width 0.

IShaderPass toShaderPass(T node)

Hook that returns the single IShaderPass that processes the pixels of the node on this frame, or null for an effect without pass. JOID calls it on every frame while the effect applies, so the pass can carry the current values of the effect. An effect with passes draws its node off screen first (Performance).

List<IShaderPass> toShaderPasses(T node)

Hook that returns every pass of the effect for this frame, in order. By default, it returns the pass of toShaderPass, or no pass; override it for an effect that needs several passes, such as a blur in two directions.

<E extends NodeEffect<T>> E copy()

Throws:

  • IllegalStateException: …

Returns a shallow copy of the effect: the copy shares the values and the suppliers of the original. Node.copy copies the effects of a node with it.

void init(T node, UI ui) hook

Hook that JOID calls when the node joins a UI, and when the effect is added to a node that is already in one. Override it to create what the effect needs for this node; it does nothing by default.

void detach(T node) hook

Hook that JOID calls when the node leaves its UI, and when the effect is removed or replaced on a node that is in one. Override it to release what init created; it does nothing by default. An instance added to several nodes receives it once for each node.


fluent returns the instance, typed for chaining · factory creates an instance · signal also accepts a value that follows signals, as a signal, an expression or a lambda (When does JOID compute this value again?) · hook called by JOID, override it · abstract you implement it · default interface method with a body · static called on the class · protected visible to subclasses

Report a problem with this page