mojo.graphics.Canvas - nitrologic/monkey2 GitHub Wiki

mojo::mojo.graphics.Canvas

Class Canvas

The Canvas class.

Canvas objects are used to perform rendering to either a mojo View or an 'off screen' Image.

To draw to a canvas, use one of the 'Draw' methods. Drawing is affected by a number of draw states, including:

  • Color - the current drawing color. This is combined with the current alpha to produce the final rendering color and alpha values.
  • Alpha - the current drawing alpha level.
  • Matrix - the current drawing matrix. All drawing coordinates are multiplied by this matrix before rendering.
  • BlendMode - the blending mode for drawing, eg: opaque, alpha, additive, multiply.
  • Viewport - the current viewport. All drawing coordinates are relative to the top-left of the viewport.
  • Scissor - the current scissor rect. All rendering is clipped to the union of the viewport and the scissor rect.
  • Font - The current font to use when drawing text with DrawText.

Drawing does not occur immediately. Drawing commands are 'buffered' to reduce the overhead of sending lots of draw calls to the lower level graphics API. You can force all drawing commands in the buffer to actually render using Flush.

Constructors
New Creates a canvas that renders to an image
Properties
Alpha The current drawing alpha level.
AmbientLight Ambient light color for lighting mode.
BlendMode The current drawing blend mode.
Color The current drawing color.
Font The current font for use with DrawText.
IsLighting True if canvas is in lighting mode. (read only)
LineSmoothing Smoothing enabled for DrawLine.
LineWidth The current line width for use with DrawLine.
Matrix The current drawing matrix.
OutlineColor The current outline color.
OutlineMode The current outline mode.
OutlineWidth The current outline width.
PointSize The current point size for use with DrawPoint.
RenderTarget The current render target. (read only)
Scissor The current scissor rect.
TextureFilteringEnabled TODO! Texture filtering enabled state.
Viewport The current viewport.
Methods
AddLight Adds a light to the canvas.
AddShadowCaster Adds a shadow caster to the canvas.
BeginLighting Puts the canvas into lighting mode.
Clear Clears the viewport.
ClearMatrix Clears the internal matrix stack and sets the drawing matrix to the identitity matrix.
CopyPixels Copies a rectangular region of pixels to a pixmap.
CopyPixmap Copies a pixmap from the rendertarget.
DrawCircle Draws a circle.
DrawEllipse Draws an ellipse.
DrawImage Draws an image.
DrawLine Draws a line.
DrawOval Draws an oval.
DrawPoint Draws a point.
DrawPoly Draws a polygon.
DrawPolys Draws a sequence of polygons.
DrawPrimitives Draws a sequence of primtives.
DrawQuad Draws a quad.
DrawRect Draws a rectangle.
DrawText Draws text.
DrawTriangle Draws a triangle.
EndLighting Renders lighting and ends lighting mode.
Flush Flushes drawing commands.
GetPixel Gets a pixel color.
GetPixelARGB Gets a pixel color.
PopMatrix Pops the drawing matrix off the internal matrix stack.
PushMatrix Pushes the drawing matrix onto the internal matrix stack.
Rotate Rotates the drawing matrix.
Scale Scales the drawing matrix.
Translate Translates the drawing matrix.