Going further
The built-in nodes, effects, fonts and formats cover most interfaces, but sooner or later a design asks for something they do not draw. This chapter opens every layer below the nodes: you write your own nodes and effects, draw by hand, run your own shaders, teach JOID other fonts and file types, and give the controls your own look. It also covers the two families of nodes that need more than a line to use: charts and 3D models.
Custom nodes
Section titled “Custom nodes”A custom node extends Node and draws itself; it attaches, nests and reacts like any built-in node.
ContainerNode.create(100, 130, 400, 140).body(container -> { DotNode.create(20, 20, 100).attach(container); DotNode.create(150, 20, 100).attach(container); DotNode.create(280, 20, 100).attach(container);}).attach(this);Read Custom nodes to learn how to write a node, give it properties that follow signals, hold a value that the user changes and fire events of your own.
Drawing shapes and text
Section titled “Drawing shapes and text”DrawUtils draws shapes, lines and text on every frame, from a layer, a custom node or an effect.
ContainerNode.create(80, 80, 400, 200).layer((node, mouseX, mouseY) -> { DrawUtils.SHAPE.drawRoundedRect(0D, 0D, node.getWidth(), node.getHeight(), DrawingUI.SURFACE, 24F); DrawUtils.SHAPE.drawCircle(100D, 100D, DrawingUI.ACCENT, 50D); DrawUtils.SHAPE.drawRect(180D, 85D, 180D, 30D, DrawingUI.ELEMENT);}).attach(this);Read Drawing shapes and text to learn where to draw and how to draw shapes, lines, curves and text.
Drawing resources and transforms
Section titled “Drawing resources and transforms”DrawUtils.RESOURCE draws images, and a Transformation rotates or scales everything drawn inside it.
ContainerNode.create(1160, 80, 600, 240).layer((node, mouseX, mouseY) -> { Transformation .create() .rotate(20D, Rotation.ROLL, Vector.create(150D, 120D)) .apply(() -> DrawUtils.SHAPE.drawRect(80D, 80D, 140D, 80D, TransformsUI.ACCENT));
Transformation .create() .rotate(20D, Rotation.ROLL, Vector.create(380D, 80D)) .apply(() -> DrawUtils.SHAPE.drawRect(380D, 80D, 140D, 80D, TransformsUI.ACCENT));
DrawUtils.SHAPE.drawBorder(80D, 80D, 140D, 80D, TransformsUI.MUTED, 2D); DrawUtils.SHAPE.drawBorder(380D, 80D, 140D, 80D, TransformsUI.MUTED, 2D); DrawUtils.SHAPE.drawCircle(150D, 120D, TransformsUI.TEXT, 7D); DrawUtils.SHAPE.drawCircle(380D, 80D, TransformsUI.TEXT, 7D);}).attach(this);Read Drawing resources and transforms to learn how to draw images, rotate and scale a drawing, and change the render state and the blending.
Framebuffers and models
Section titled “Framebuffers and models”A FrameBuffer keeps a drawing made once, to draw it again on every frame, at any size.
@Overridepublic void draw(final double mouseX, final double mouseY) { if (this.frameBuffer == null) { this.frameBuffer = FrameBuffer.create(128, 128, TextureFilter.LINEAR).fill(() -> { BridgeHandler.RENDER.get().clearColor(0F, 0F, 0F, 0F); DrawUtils.SHAPE.drawCircle(64D, 64D, StampNode.ELEMENT, 64D); DrawUtils.SHAPE.drawCircle(64D, 64D, StampNode.ACCENT, 40D); }); }
this.frameBuffer.draw(super.getX(), super.getY(), super.w(), super.h());}Read Framebuffers and models to learn how to draw once and reuse the result, borrow a temporary target, build your own geometry and draw 3D models by hand.
Shaders
Section titled “Shaders”A shader colors each pixel with a formula, written once in JOID GLSL for every backend, and shader passes post-process a drawing.
final BlurShaderPass blurX = BlurShaderPass.create(12F, true);final BlurShaderPass blurY = BlurShaderPass.create(12F, false);final BorderShaderPass border = BorderShaderPass.create(ShadersUI.MUTED, 4F);
ContainerNode.create(80, 280, 400, 240).layer((node, mouseX, mouseY) -> { final Runnable rect = () -> DrawUtils.SHAPE.drawRect(80D, 60D, 240D, 120D, ShadersUI.ACCENT); ShaderPipeline.render(80D, 60D, 240D, 120D, rect, blurX, blurY, border);}).attach(this);Read Shaders to learn how to write a shader, bind it around a drawing, set its uniforms, and write a pass of your own.
Custom effects
Section titled “Custom effects”A custom effect is a treatment that goes on any node, like the built-in effects.
RectNode.create(100, 100, 200, 120).color(EffectsUI.ELEMENT).effect(HardShadowNodeEffect.create(EffectsUI.ACCENT, 12D)).attach(this);Read Custom effects to learn how to draw around a node, change how it draws, process its pixels, and order it among the other effects.
Custom fonts and MSDF
Section titled “Custom fonts and MSDF”A font of your own can draw pixel-art letters from an atlas, at the exact size you ask for.
final TextInfo title = TextInfo.create(FontsUI.PIXEL, 64F).color(FontsUI.TEXT);final TextInfo line = TextInfo.create(FontsUI.PIXEL, 24F).color(FontsUI.TEXT);
TextNode.create(100, 100).text(Text.create("GAME OVER", title)).attach(this);
TextNode.create(100, 190).text(Text.create("Press any key", line)).attach(this);
TextNode.create(100, 230).text(Text.create("Synthetic bold", line.withWeight(FontWeight.BOLD))).attach(this);Read Custom fonts and MSDF to learn how to write a bitmap or glyph font, and how to generate MSDF atlases ahead of time.
Custom formats
Section titled “Custom formats”A locator, a format and a decoder of yours make any source and any file type load like a PNG.
AssetLocator.register(new FormatsPackAssetLocator());ResourceFormat.register(new FormatsPpmResourceFormat());Read Custom formats to learn how to read resources from your own sources and file types, and build animations from your own frames.
Give your controls a look
Section titled “Give your controls a look”The controls of JOID hold their behavior, and a small subclass, a skin, gives them their parts.
KitCheckboxNode.create(100, 100, 40).checked(true).attach(this);
KitIntegerSliderNode.create(100, 180, 300, 40).range(0, 10).value(4).attach(this);
KitSwitchNode.<String>create(100, 260, 300, 50).values("Low", "Medium", "High").value("Medium").attach(this);
KitPillToggleNode.create(100, 350, 80, 40).toggle(true).attach(this);Read Give your controls a look to learn how to skin each control and gather the skins in a UI kit.
Charts
Section titled “Charts”A chart node holds axes and series of values; a skin of yours draws them.
final ChartsLineChartNode chart = ChartsLineChartNode.create(100, 100, 400, 240).xAxis(ChartAxis.x("day", "Mon", "Tue", "Wed", "Thu", "Fri")).yAxis(ChartAxis.y("visits").suffix(" k")).data("Visits", ChartData.create().add("Mon", 2).add("Tue", 6).add("Wed", 4).add("Thu", 8).add("Fri", 7)).data("Orders", ChartData.create().add("Mon", 1).add("Tue", 2).add("Wed", 3).add("Thu", 3).add("Fri", 5)).attach(this);Read Charts to learn how to feed a chart, update its data and draw it.
3D models
Section titled “3D models”A model node shows a .obj model in its bounds, turned by a yaw and a pitch.
ModelNode.create(100, 100, 200, 200).rotationYaw(yaw).rotationPitch(20D).model(ModelsUI.CUBE).attach(this);Read 3D models to learn how to load a model, turn it, and let the user rotate and zoom it.
