Class: LM_Graphics

The LM_Graphics class is used for drawing in an LM_View. It lets you draw basic lines and shapes, and to convert between coordinate systems (the screen pixel space and the 3D coordinate system of Moho layers). You typically would use an LM_Graphics object with a moho tool script to determine what object(s) the user clicks on and to draw extra tool elements like control handles.

Member Functions


int Width()

Returns the width in pixels of the drawing area.

Return value (int): the width in pixels of the drawing area
int Height()

Returns the height in pixels of the drawing area.

Return value (int): the height in pixels of the drawing area
void SetColor(r, g, b, a=255)

Sets the drawing color for subsequent drawing operations.

Return value: none r (int): red g (int): green b (int): blue a (int): alpha (opacity)
void SetPenWidth(w)

Sets the width in pixels for line drawing operations.

Return value: none w (int): line pixel width
void SetSmoothing(value)

Turns on or off smoothing (antialaising) for drawing operations.

Return value: none value (bool): true to draw smooth lines and shapes, false to turn off smoothing
void ScreenToWorld(where, pt)

Converts a screen pixel location to 2D world coordinates. As an example, this can be used to convert between a mouse click to a location in the current Moho layer.

Return value: none where (LM_Point): pixel location pt (LM_Vector2): 2D world position - filled in by this function
void ScreenToWorld(where, pt)

Converts a screen pixel location to 3D world coordinates.

Return value: none where (LM_Point): pixel location pt (LM_Vector3): 3D world position - filled in by this function
bool WorldToScreen(pt, where)

Converts a 2D world position to a screen pixel location. As an example, this can be used to convert between a point in a Moho layer to a screen pixel.

Return value (bool): returns true if the point is visible on screen, false otherwise pt (LM_Vector2): 2D world position where (LM_Point): pixel location - filled in by this function
bool WorldToScreen(pt, where)

Converts a 2D world position to a screen location.

Return value (bool): returns true if the point is visible on screen, false otherwise pt (LM_Vector2): 2D world position where (LM_Vector2): screen location - filled in by this function
void BeginDraw()

Call this function before starting any drawing commands.

Return value: none
void Push()

Push the current matrix stack. This is a way of saving the current transformation.

Return value: none
void Pop()

Pop the current matrix stack. This is a way of restroing a saved transformation.

Return value: none
LM_Matrix CurrentTransform()

Returns the current matrix transformation.

Return value (LM_Matrix): the current matrix transformation
void Translate(dx, dy)

Prepend a 2D translation to the current matrix transform.

Return value: none dx (float): x translation dy (float): y translation
void Scale(sx, sy)

Prepend a 2D scale to the current matrix transform.

Return value: none sx (float): x scale sy (float): y scale
void Rotate(angle)

Prepend a rotation to the current matrix transform.

Return value: none angle (float): angle in radians
void ApplyMatrix(matrix)

Prepend an arbitrary matrix to the current matrix transform.

Return value: none matrix (const LM_Matrix): a matrix with any arbitrary transformation (2D or 3D)
float CurrentScale(ignoreZoom)

Returns the current scale of the drawing. A value of 1 means the drawing is actual size, 0.5 would be half size, 2.0 would be double size, etc.

Return value (float): the drawing's current scale ignoreZoom (bool): true if you wish to ignore zoom effects, false otherwise
void EndDraw()

Call this function when you're finished with all drawing operations.

Return value: none
void BeginPicking(where)

Call this function to begin testing whether the user has clicked on an object.

Return value: none where (LM_Point): the pixel location you want to test (often the location of a mouse click)
bool Pick()

After drawing an object, call this function to see if it was clicked on by the user.

Return value (bool): true if the object was picked, otherwise false
bool IsFullWhite(where)

Test whether a given pixel is 100% white.

Return value (bool): true if the pixel is white, otherwise false where (LM_Point): the pixel you wish to test
void SelectionRect(r)

Draw a selection rectangle.

Return value: none r (LM_Rect): the rectangle to draw
void Clear(r, g, b, a=255)

Clear the drawing area.

Return value: none r (int): red g (int): green b (int): blue a (int): alpha (opacity)
void MoveTo(x, y)

Move the pen location to a given pixel. Nothing is drawn.

Return value: none x (float): x location y (float): y location
void LineTo(x, y)

Draw a line from the current pen position to the given pixel.

Return value: none x (float): x location y (float): y location
void DrawLine(x1, y1, x2, y2)

Draw a line between two pixels.

Return value: none x1 (float): start x location y1 (float): start y location x2 (float): end x location y2 (float): end y location
void BeginShape()

Begin drawing an enclosed shape.

Return value: none
void AddLine(end1, end2)

Add a line segment to the current enclosed shape. All the line segments you add should form the outer boundary of the shape.

Return value: none end1 (LM_Vector2): first endpoint of the line segment end2 (LM_Vector2): second endpoint of the line segment
void EndShape()

End the current enclosed shape and draw it on the screen.

Return value: none
void FrameCircle(center, radius)

Draw a circle outline.

Return value: none center (LM_Vector2): center point radius (float): radius
void FillCircle(center, radius)

Draw a filled circle

Return value: none center (LM_Vector2): center point radius (float): radius
void DrawMarker(xf, yf)

Draw a marker (for example, the control points on Moho curves).

Return value: none xf (float): x location yf (float): y location
void DrawFatMarker(xf, yf, radius)

Draw a fat marker.

Return value: none xf (float): x location yf (float): y location radius (float): radius