use of org.graphstream.ui.graphicGraph.GraphicElement in project gs-ui-javafx by graphstream.
the class FunctionInVoid method render.
/**
* Main rendering method.
*
* This works in three phases:
* - draw all "bulk" elements using renderElement()
* - draw all "dynamic" elements using renderElement().
* - draw all "event" elements using renderElement().
*
* Before drawing, the setupRenderingPass() and pushStyle() methods are called. The phase 1 is
* run. Then for each dynamic element in phase 2, before calling renderElement, for each element
* the pushDynStyle() method is called.
* Then for each element modified by an event, in phase 3, the before drawing the element, the
* event is enabled, then pushStyle() is called, then the element is drawn, and finally the
* event is disabled.
*
* This rendering pass is made both for shadows and for regular drawing. The shadow and render
* arguments allow to specify that we are rendering for shadow, and what element rendering
* method to use (renderElement() or renderShadow()).
*/
public void render(Backend bck, DefaultCamera2D camera, boolean shadow, FunctionInVoid<Backend, DefaultCamera2D, GraphicElement> render) {
setupRenderingPass(bck, camera, shadow);
pushStyle(bck, camera, shadow);
// var T1 = System.currentTimeMillis
group.bulkElements().forEach(e -> {
GraphicElement ge = (GraphicElement) e;
if (camera.isVisible(ge))
render.apply(bck, camera, ge);
else
elementInvisible(bck, camera, ge);
});
if (group.hasDynamicElements()) {
group.dynamicElements().forEach(e -> {
GraphicElement ge = (GraphicElement) e;
if (camera.isVisible(ge)) {
if (!group.elementHasEvents(ge)) {
pushDynStyle(bck, camera, ge);
render.apply(bck, camera, ge);
}
} else {
elementInvisible(bck, camera, ge);
}
});
}
if (group.hasEventElements()) {
group.elementsEvents().forEach(event -> {
GraphicElement ge = (GraphicElement) event.getElement();
if (camera.isVisible(ge)) {
event.activate();
pushStyle(bck, camera, shadow);
render.apply(bck, camera, ge);
event.deactivate();
} else {
elementInvisible(bck, camera, ge);
}
});
hadEvents = true;
} else {
hadEvents = false;
}
endRenderingPass(bck, camera, shadow);
}
use of org.graphstream.ui.graphicGraph.GraphicElement in project gs-ui-javafx by graphstream.
the class DefaultCamera method allGraphicElementsIn.
@Override
public Collection<GraphicElement> allGraphicElementsIn(GraphicGraph graph, EnumSet<InteractiveElement> types, double x1, double y1, double x2, double y2) {
List<GraphicElement> elts = new ArrayList<GraphicElement>();
Stream nodeStream = null;
Stream edgeStream = null;
Stream spriteStream = null;
if (types.contains(InteractiveElement.NODE)) {
nodeStream = graph.nodes().filter(n -> isNodeIn((GraphicNode) n, x1, y1, x2, y2));
} else {
nodeStream = Stream.empty();
}
if (types.contains(InteractiveElement.EDGE)) {
edgeStream = graph.edges().filter(e -> isEdgeIn((GraphicEdge) e, x1, y1, x2, y2));
} else {
edgeStream = Stream.empty();
}
if (types.contains(InteractiveElement.SPRITE)) {
spriteStream = graph.sprites().filter(e -> isSpriteIn((GraphicSprite) e, x1, y1, x2, y2));
} else {
spriteStream = Stream.empty();
}
Stream<GraphicElement> s = Stream.concat(nodeStream, Stream.concat(edgeStream, spriteStream));
return s.collect(Collectors.toList());
}
Aggregations