crystal.Painter

A Wrapper which applies a shader when drawing its child. This element draws in two passes:

  1. Its descendents are rendered to an offscreen canvas.
  2. The resulting canvas is drawn to the screen with the desired shader applied.

If no shader is set on this element, it draws in a single pass (skipping the intermediate canvas).

The child of a Painter has a Basic Joint to adjust positioning preferences (padding, alignment, etc.).

RoundedCorners is an example of a Painter element.

Constructor

crystal.Painter:new(shader)

The optional shader parameter should be a love.Shader.

Methods

Name Description
set_shader Sets or clears the shader used to draw this element.
shader Returns the shader used to draw this element, if any.

Callbacks

Name Description
configure_shader Called right before the element is drawn.

Examples

This example illustrates what implementing your own Painter class looks like:

local MyPainter = Class("MyPainter", crystal.Painter);

MyPainter.init = function(self)
  MyPainter.super.init(self, crystal.assets.get("assets/my_shader.glsl"));
  self.my_param = 0;
end

MyPainter.set_param = function(self, value)
  self.my_param = value;
end

MyPainter.configure_shader = function(self, shader, quad)
  shader:send("my_param", self.my_param);
end

This site uses Just the Docs, a documentation theme for Jekyll.