Skip to content

Mojo graphics canvas

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.

Fields
RenderAmbient
_iX
_iY
_textureFilter2
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.
Color2
Font The current font for use with DrawText.
GraphicsDevice (read only)
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.
RenderBounds (read only)
RenderMatrix (read only)
RenderTarget The current render target. (read only)
Scissor The current scissor rect.
TextureFiltering
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.
BeginRender
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.
DrawChamferRect
DrawCircle Draws a circle.
DrawColorRect
DrawCross
DrawDiamond
DrawEllipse Draws an ellipse.
DrawFrame Draws a rectangle frame (made from lines).
DrawFrame3d
DrawFrameChamferRect
DrawFrameCircle
DrawFrameDiamond
DrawFrameOval
DrawFrameOvalDepth
DrawFrameRoundedRect
DrawFrameSquare
DrawFrameTriangle
DrawGrid Draws a grid of cells (made from lines).
DrawHFadeRect
DrawImage Draws an image.
DrawImageIcon Draws an image icon frame.
DrawImageIconRotate
DrawImageIconSize
DrawImageQuad
DrawImageQuadPure
DrawImageRect
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.
DrawQuadImage Draws a quad from a source image.
DrawQuadImageIcon Draws a quad from a source image.
DrawQuadImageSlice Draws a quad from a source image slice.
DrawQuadIntersectImage
DrawRect
DrawRoundedRect
DrawSquare
DrawTarget
DrawText Draws text.
DrawTextBold
DrawTextSize
DrawTextSpacing
DrawTextV
DrawTextVSize
DrawTriangle
DrawTriangleXYZ
DrawTriangleXYZNormal
DrawTriangleXYZNormal2
DrawVFadeRect
DrawX
EndLighting Renders lighting and ends lighting mode.
EndRender
Flush Flushes drawing commands.
GetPixel Gets a pixel color.
GetPixelARGB Gets a pixel color.
LineIntersect
PopMatrix Pops the drawing matrix off the internal matrix stack.
PushMatrix Pushes the drawing matrix onto the internal matrix stack.
Resize Resizes a canvas that renders to the backbuffer.
Rotate Rotates the drawing matrix.
Scale Scales the drawing matrix.
SetCol
SetCol2
SetUserUniformCallback
SetViewport
SetXYZ
Translate Translates the drawing matrix.