Mach Modules Documentation
Lua Module API Documentation
Loading...
Searching...
No Matches
DrawingModule.lua File Reference

Go to the source code of this file.

Functions

DrawingModule Shape New ()
 Create a new Shape instance as the base object for all shape subclasses.
DrawingModule Shape GetPoint ()
 Return the point at the specified index from this shape's points array.
DrawingModule Shape AddToList ()
 Add a shape object to the global shape list.
DrawingModule Shape SetOutlineTool ()
 Set the pen used to draw the outline of this shape.
DrawingModule Shape SetFillTool ()
 Set the brush used to fill this shape.
DrawingModule Shape GetOutlineTool ()
 Return the outline pen tool assigned to this shape.
DrawingModule Shape GetFillTool ()
 Return the fill brush tool assigned to this shape.
DrawingModule Circle New (r, outline, fill)
 Create a new Circle instance from a center point and radius.
DrawingModule Circle GetRadius ()
 Return the radius of this circle.
DrawingModule Polygon New (p2, p3, p4, p5,...)
 Create a new Polygon instance from five or more vertices.
DrawingModule Rectangle New (p2, p3, p4, outline, fill)
 Create a new Rectangle instance from four corner points.
DrawingModule Triangle New (p2, p3, outline, fill)
 Create a new Triangle instance from three vertices.
DrawingModule Cut New (p2, outline)
 Create a new Cut instance representing an open two-point line segment.
DrawingModule Dimension_Line New (p2, ori, offset, outline, text_color)
 Create a new Dimension_Line instance measuring the distance between two points.
DrawingModule Dimension_Line GetDistance (p2)
 Calculate the absolute distance between two points along a single axis.
DrawingModule Dimension_Line ApplyOffset ()
 Shift the dimension line endpoints in the configured orientation direction.
DrawingModule Dimension_Line ApplyTextOffset (off)
 Apply an additional offset to the dimension line length label position.
DrawingModule Dimension_Line SetTextColor ()
 Set the color used to render the dimension line length label text.
DrawingModule Dimension_Line GetTextColor ()
 Return the text color used for the dimension line length label.
DrawingModule Point GetX ()
 Return the X coordinate of this point.
DrawingModule Point GetY ()
 Return the Y coordinate of this point.
DrawingModule CreateCircle (r, outline, fill)
 Create a new Circle shape and add it to the shape list.
DrawingModule CreatePolygon (p2, p3, p4, p5,...)
 Create a new Polygon shape and add it to the shape list.
DrawingModule CreateRectangle (p2, p3, p4, outline, fill)
 Create a new Rectangle shape and add it to the shape list.
DrawingModule CreateTriangle (p2, p3, outline, fill)
 Create a new Triangle shape and add it to the shape list.
DrawingModule CreateCut (p2, outline)
 Create a new Cut shape and add it to the shape list.
DrawingModule CreateDimensionLine (p2, ori, offset, outline, text_color)
 Create a new Dimension_Line shape and add it to the shape list.
DrawingModule GetAllShapes ()
 Return the list of all currently created shapes.
DrawingModule ClearShapes ()
 Remove all shapes from the shape list.
DrawingModule SetXScalingFunction ()
 Register an X-axis coordinate scaling function for canvas rendering.
DrawingModule SetYScalingFunction ()
 Register a Y-axis coordinate scaling function for canvas rendering.
DrawingModule SetGenericScalingFunction ()
 Register a generic scaling function for non-axis-specific coordinate scaling.
DrawingModule DrawShapes ()
 Draw all created shapes onto the given canvas.

Function Documentation

◆ AddToList()

DrawingModule Shape AddToList ( )

Add a shape object to the global shape list.

Inserts the provided object into DrawingModule.shape_list using table.insert. This method is called automatically at the end of each shape subclass constructor (Circle, Rectangle, Triangle, Polygon, Cut, Dimension_Line) so that all created shapes are tracked for rendering by DrawShapes.

Parameters
obj(table) The shape object to append to DrawingModule.shape_list
Note
Documentation generated by AI on 2026-03-03

◆ ApplyOffset()

DrawingModule Dimension_Line ApplyOffset ( )

Shift the dimension line endpoints in the configured orientation direction.

Modifies the x_cord or y_cord of start_point and end_point by the stored offset value. The direction of the shift is determined by self.ori: LEFT shifts X negatively, RIGHT shifts X positively, UP shifts Y positively, and DOWN shifts Y negatively. This is called automatically during Dimension_Line:New() to position the line away from the measured geometry.

Note
Documentation generated by AI on 2026-03-03

◆ ApplyTextOffset()

DrawingModule Dimension_Line ApplyTextOffset ( off )

Apply an additional offset to the dimension line length label position.

Adjusts the internal text_x_offset or text_y_offset accumulators based on the specified orientation direction. LEFT subtracts from text_x_offset, RIGHT adds to text_x_offset, UP adds to text_y_offset, and DOWN subtracts from text_y_offset. Offsets are cumulative, so multiple calls will continue to shift the text position.

Parameters
ori(number) Direction constant: DrawingModule.LEFT, UP, RIGHT, or DOWN
off(number|nil) The offset magnitude to apply in logical units. Defaults to 0 if nil
Note
Documentation generated by AI on 2026-03-03

◆ ClearShapes()

DrawingModule ClearShapes ( )

Remove all shapes from the shape list.

Resets DrawingModule.shape_list to an empty table, discarding all previously created shapes. This should be called at the beginning of each drawing loop iteration before creating new shapes, to prevent accumulation of stale shapes across redraws.

Note
Documentation generated by AI on 2026-03-03

◆ CreateCircle()

DrawingModule CreateCircle ( r ,
outline ,
fill  )

Create a new Circle shape and add it to the shape list.

Shortcut constructor that delegates to DrawingModule.Circle:New(). The circle is defined by a center point and radius, with configurable outline and fill tools.

Parameters
p(table) Center coordinate array {x, y}
r(number) Radius of the circle in logical units
outline(userdata|nil) wxPen for the outline. Defaults to wx.wxBLACK_PEN if nil
fill(userdata|nil) wxBrush for the fill. Defaults to wx.wxTRANSPARENT_BRUSH if nil
Returns
(table) The newly created Circle object
Note
Documentation generated by AI on 2026-03-03

◆ CreateCut()

DrawingModule CreateCut ( p2 ,
outline  )

Create a new Cut shape and add it to the shape list.

Shortcut constructor that delegates to DrawingModule.Cut:New(). A Cut represents a two-point open line segment (not closed) used to depict material cuts or slots.

Parameters
p1(table) Start coordinate array {x, y}
p2(table) End coordinate array {x, y}
outline(userdata|nil) wxPen for the line color. Defaults to wx.wxBLACK_PEN if nil
Returns
(table) The newly created Cut object
Note
Documentation generated by AI on 2026-03-03

◆ CreateDimensionLine()

DrawingModule CreateDimensionLine ( p2 ,
ori ,
offset ,
outline ,
text_color  )

Create a new Dimension_Line shape and add it to the shape list.

Shortcut constructor that delegates to DrawingModule.Dimension_Line:New(). The dimension line measures the distance between two points and renders the measurement with bracket end-caps and a formatted length label. Orientation determines which direction the line is offset from the measured points.

Parameters
p1(table) Start coordinate array {x, y}
p2(table) End coordinate array {x, y}
ori(number|nil) Orientation constant: DrawingModule.LEFT, UP, RIGHT, or DOWN. Defaults to LEFT if nil
offset(number|nil) Distance to offset the dimension line from the measured points. Defaults to 0.8 if nil
outline(userdata|nil) wxPen for the line color. Defaults to wx.wxBLACK_PEN if nil
text_color(userdata|nil) wxColour for the length label. Defaults to wx.wxBLACK if nil
Returns
(table) The newly created Dimension_Line object
Note
Documentation generated by AI on 2026-03-03

◆ CreatePolygon()

DrawingModule CreatePolygon ( p2 ,
p3 ,
p4 ,
p5 ,
... )

Create a new Polygon shape and add it to the shape list.

Shortcut constructor that delegates to DrawingModule.Polygon:New(). A Polygon requires at least five points and may accept additional points via varargs. The shape is closed automatically during rendering by returning to the first point.

Parameters
p1(table) First vertex coordinate array {x, y}
p2(table) Second vertex coordinate array {x, y}
p3(table) Third vertex coordinate array {x, y}
p4(table) Fourth vertex coordinate array {x, y}
p5(table) Fifth vertex coordinate array {x, y}
...(table) Additional vertex coordinate arrays {x, y} for polygons with more than five sides
Returns
(table) The newly created Polygon object
Note
Documentation generated by AI on 2026-03-03

◆ CreateRectangle()

DrawingModule CreateRectangle ( p2 ,
p3 ,
p4 ,
outline ,
fill  )

Create a new Rectangle shape and add it to the shape list.

Shortcut constructor that delegates to DrawingModule.Rectangle:New(). A Rectangle is a closed four-point shape with configurable outline and fill.

Parameters
p1(table) First corner coordinate array {x, y}
p2(table) Second corner coordinate array {x, y}
p3(table) Third corner coordinate array {x, y}
p4(table) Fourth corner coordinate array {x, y}
outline(userdata|nil) wxPen for the outline. Defaults to wx.wxBLACK_PEN if nil
fill(userdata|nil) wxBrush for the fill. Defaults to wx.wxTRANSPARENT_BRUSH if nil
Returns
(table) The newly created Rectangle object
Note
Documentation generated by AI on 2026-03-03

◆ CreateTriangle()

DrawingModule CreateTriangle ( p2 ,
p3 ,
outline ,
fill  )

Create a new Triangle shape and add it to the shape list.

Shortcut constructor that delegates to DrawingModule.Triangle:New(). A Triangle is a closed three-point shape with configurable outline and fill.

Parameters
p1(table) First vertex coordinate array {x, y}
p2(table) Second vertex coordinate array {x, y}
p3(table) Third vertex coordinate array {x, y}
outline(userdata|nil) wxPen for the outline. Defaults to wx.wxBLACK_PEN if nil
fill(userdata|nil) wxBrush for the fill. Defaults to wx.wxTRANSPARENT_BRUSH if nil
Returns
(table) The newly created Triangle object
Note
Documentation generated by AI on 2026-03-03

◆ DrawShapes()

DrawingModule DrawShapes ( )

Draw all created shapes onto the given canvas.

Iterates over all shapes in the shape list and renders them to the provided canvas. Shape rendering is dispatched by shape ID: polygons and rectangles are drawn as connected paths, circles are drawn using AddCircle, and dimension lines are drawn with brackets and length text. Dimension line bracket orientation and text placement depend on the orientation (LEFT/RIGHT vs UP/DOWN). This function wraps the internal _DrawShapes method in a protected call via w.pcall() to catch and report any rendering errors without crashing the UI.

Parameters
canvas(userdata) The wxGraphicsContext-compatible canvas object to draw shapes onto
Warning
If any shape rendering fails, w.Error() is called which may raise a Lua error in the screen chunk
Note
Documentation generated by AI on 2026-03-03

◆ GetAllShapes()

DrawingModule GetAllShapes ( )

Return the list of all currently created shapes.

Returns
(table) Array of all shape objects that have been created and added to the shape list
Note
Documentation generated by AI on 2026-03-03

◆ GetDistance()

DrawingModule Dimension_Line GetDistance ( p2 )

Calculate the absolute distance between two points along a single axis.

Computes the distance between p1 and p2 by comparing coordinates. If the X coordinates are equal, the distance is the absolute difference in Y. If the Y coordinates are equal, the distance is the absolute difference in X. Non-axis-aligned segments (diagonal lines) are not supported and will return 0.

Parameters
p1(table) A Point object with GetX() and GetY() methods
p2(table) A Point object with GetX() and GetY() methods
Returns
(number) The absolute axis-aligned distance between the two points
Note
Documentation generated by AI on 2026-03-03

◆ GetFillTool()

DrawingModule Shape GetFillTool ( )

Return the fill brush tool assigned to this shape.

Returns
(userdata) The wxBrush object currently set as the fill tool
Note
Documentation generated by AI on 2026-03-03

◆ GetOutlineTool()

DrawingModule Shape GetOutlineTool ( )

Return the outline pen tool assigned to this shape.

Returns
(userdata) The wxPen object currently set as the outline tool
Note
Documentation generated by AI on 2026-03-03

◆ GetPoint()

DrawingModule Shape GetPoint ( )

Return the point at the specified index from this shape's points array.

Parameters
idx(number) The one-based index into self.points
Returns
(table) The Point object at the given index
Note
Documentation generated by AI on 2026-03-03

◆ GetRadius()

DrawingModule Circle GetRadius ( )

Return the radius of this circle.

Returns
(number) The radius value stored in self.radius
Note
Documentation generated by AI on 2026-03-03

◆ GetTextColor()

DrawingModule Dimension_Line GetTextColor ( )

Return the text color used for the dimension line length label.

Returns
(userdata) The wxColour object currently set as the text color
Note
Documentation generated by AI on 2026-03-03

◆ GetX()

DrawingModule Point GetX ( )

Return the X coordinate of this point.

Returns
(number) The X coordinate value stored in x_cord
Note
Documentation generated by AI on 2026-03-03

◆ GetY()

DrawingModule Point GetY ( )

Return the Y coordinate of this point.

Returns
(number) The Y coordinate value stored in y_cord
Note
Documentation generated by AI on 2026-03-03

◆ New() [1/7]

DrawingModule Shape New ( )

Create a new Shape instance as the base object for all shape subclasses.

Create a new Point instance from a coordinate array.

Constructs a bare shape table and sets its metatable to the calling class using Lua's prototype-based inheritance pattern. This method serves as the base constructor inherited by Circle, Rectangle, Triangle, Polygon, Cut, and Dimension_Line. Subclasses call this method to obtain a properly chained metatable before populating shape-specific fields.

Returns
(table) A new empty shape object with its metatable set to the calling class
Note
Documentation generated by AI on 2026-03-03

Constructs a Point object by extracting the first and second elements of the provided coordinate array as x_cord and y_cord respectively. Points are used by all shape classes to store vertex and center positions.

Parameters
coord(table) A two-element array where coord[1] is the X coordinate and coord[2] is the Y coordinate
Returns
(table) The newly created Point object with x_cord and y_cord fields
Note
Documentation generated by AI on 2026-03-03

◆ New() [2/7]

DrawingModule Dimension_Line New ( p2 ,
ori ,
offset ,
outline ,
text_color  )

Create a new Dimension_Line instance measuring the distance between two points.

Constructs a Dimension_Line object that records the start and end points, applies an orientation-based offset to position the line away from the measured geometry, computes the axis-aligned distance between the two points, initializes text offset accumulators to zero, and registers the object in DrawingModule.shape_list. If offset is nil, a default of 0.8 is used; otherwise 0.3 is added to the provided value. If ori is nil, DrawingModule.LEFT is used.

Parameters
p1(table) Start coordinate array {x, y}
p2(table) End coordinate array {x, y}
ori(number|nil) Orientation constant: DrawingModule.LEFT, UP, RIGHT, or DOWN. Defaults to DrawingModule.LEFT if nil
offset(number|nil) Distance to offset the dimension line from the measured points. Defaults to 0.8 if nil
outline(userdata|nil) wxPen for the line color. Defaults to wx.wxBLACK_PEN if nil
text_color(userdata|nil) wxColour for the length label. Defaults to wx.wxBLACK if nil
Returns
(table) The newly created Dimension_Line object with start_point, end_point, length, and text offset fields
Note
Documentation generated by AI on 2026-03-03

◆ New() [3/7]

DrawingModule Cut New ( p2 ,
outline  )

Create a new Cut instance representing an open two-point line segment.

Constructs a Cut object with two endpoints and an outline pen. Unlike closed shapes, a Cut is not closed back to the first point during rendering, making it suitable for depicting material cuts, slots, or open line segments. The object is automatically added to DrawingModule.shape_list upon creation.

Parameters
p1(table) Start coordinate array {x, y}
p2(table) End coordinate array {x, y}
outline(userdata|nil) wxPen for the line color. Defaults to wx.wxBLACK_PEN if nil
Returns
(table) The newly created Cut object with ID set to DrawingModule.CUT
Note
Documentation generated by AI on 2026-03-03

◆ New() [4/7]

DrawingModule Triangle New ( p2 ,
p3 ,
outline ,
fill  )

Create a new Triangle instance from three vertices.

Constructs a Triangle object with three Point objects built from the provided coordinate arrays. Sets the outline and fill drawing tools and automatically adds the object to DrawingModule.shape_list. During rendering the shape is closed by returning to the first point.

Parameters
p1(table) First vertex coordinate array {x, y}
p2(table) Second vertex coordinate array {x, y}
p3(table) Third vertex coordinate array {x, y}
outline(userdata|nil) wxPen for the outline. Defaults to wx.wxBLACK_PEN if nil
fill(userdata|nil) wxBrush for the fill. Defaults to wx.wxTRANSPARENT_BRUSH if nil
Returns
(table) The newly created Triangle object with ID set to DrawingModule.TRIANGLE
Note
Documentation generated by AI on 2026-03-03

◆ New() [5/7]

DrawingModule Rectangle New ( p2 ,
p3 ,
p4 ,
outline ,
fill  )

Create a new Rectangle instance from four corner points.

Constructs a Rectangle object with four Point objects built from the provided coordinate arrays. Sets the outline and fill drawing tools and automatically adds the object to DrawingModule.shape_list. During rendering the shape is closed by returning to the first point.

Parameters
p1(table) First corner coordinate array {x, y}
p2(table) Second corner coordinate array {x, y}
p3(table) Third corner coordinate array {x, y}
p4(table) Fourth corner coordinate array {x, y}
outline(userdata|nil) wxPen for the outline. Defaults to wx.wxBLACK_PEN if nil
fill(userdata|nil) wxBrush for the fill. Defaults to wx.wxTRANSPARENT_BRUSH if nil
Returns
(table) The newly created Rectangle object with ID set to DrawingModule.RECTANGLE
Note
Documentation generated by AI on 2026-03-03

◆ New() [6/7]

DrawingModule Polygon New ( p2 ,
p3 ,
p4 ,
p5 ,
... )

Create a new Polygon instance from five or more vertices.

Constructs a Polygon object with at least five Point objects built from the required coordinate parameters, plus any additional points supplied via varargs. All points are stored in the polygon.points array in the order they are provided. The object is automatically added to DrawingModule.shape_list. During rendering the shape is closed by returning to the first point.

Parameters
p1(table) First vertex coordinate array {x, y}
p2(table) Second vertex coordinate array {x, y}
p3(table) Third vertex coordinate array {x, y}
p4(table) Fourth vertex coordinate array {x, y}
p5(table) Fifth vertex coordinate array {x, y}
...(table) Additional vertex coordinate arrays {x, y} for polygons with more than five sides
Returns
(table) The newly created Polygon object with ID set to DrawingModule.POLYGON
Note
Documentation generated by AI on 2026-03-03

◆ New() [7/7]

DrawingModule Circle New ( r ,
outline ,
fill  )

Create a new Circle instance from a center point and radius.

Constructs a Circle object with a single center Point built from the provided coordinate array and a numeric radius. Sets the outline and fill drawing tools and automatically adds the object to DrawingModule.shape_list. During rendering the circle is drawn using the canvas AddCircle method with the stored radius passed through the Scale function.

Parameters
p(table) Center coordinate array {x, y}
r(number) Radius of the circle in logical units
outline(userdata|nil) wxPen for the outline. Defaults to wx.wxBLACK_PEN if nil
fill(userdata|nil) wxBrush for the fill. Defaults to wx.wxTRANSPARENT_BRUSH if nil
Returns
(table) The newly created Circle object with ID set to DrawingModule.CIRCLE
Note
Documentation generated by AI on 2026-03-03

◆ SetFillTool()

DrawingModule Shape SetFillTool ( )

Set the brush used to fill this shape.

Parameters
fill(userdata|nil) A wxBrush object for the fill. Defaults to wx.wxTRANSPARENT_BRUSH if nil
Note
Documentation generated by AI on 2026-03-03

◆ SetGenericScalingFunction()

DrawingModule SetGenericScalingFunction ( )

Register a generic scaling function for non-axis-specific coordinate scaling.

Assigns a scaling function to DrawingModule.Scale, which is used in _DrawShapes to scale values such as circle radii that are not strictly X or Y coordinates. This function must be set before calling DrawShapes if any circles are present in the shape list.

Parameters
func(function) A function that accepts a numeric value and returns a scaled numeric value
Note
Documentation generated by AI on 2026-03-03

◆ SetOutlineTool()

DrawingModule Shape SetOutlineTool ( )

Set the pen used to draw the outline of this shape.

Parameters
outline(userdata|nil) A wxPen object for the outline. Defaults to wx.wxBLACK_PEN if nil
Note
Documentation generated by AI on 2026-03-03

◆ SetTextColor()

DrawingModule Dimension_Line SetTextColor ( )

Set the color used to render the dimension line length label text.

Parameters
text_color(userdata|nil) A wxColour object for the label color. Defaults to wx.wxBLACK if nil
Note
Documentation generated by AI on 2026-03-03

◆ SetXScalingFunction()

DrawingModule SetXScalingFunction ( )

Register an X-axis coordinate scaling function for canvas rendering.

Assigns a scaling function to DrawingModule.X, which is used in _DrawShapes to convert logical X coordinates to canvas pixel coordinates. This function must be set before calling DrawShapes to ensure correct horizontal positioning of all shapes.

Parameters
func(function) A function that accepts a numeric X coordinate and returns a scaled canvas X coordinate
Note
Documentation generated by AI on 2026-03-03

◆ SetYScalingFunction()

DrawingModule SetYScalingFunction ( )

Register a Y-axis coordinate scaling function for canvas rendering.

Assigns a scaling function to DrawingModule.Y, which is used in _DrawShapes to convert logical Y coordinates to canvas pixel coordinates. This function must be set before calling DrawShapes to ensure correct vertical positioning of all shapes.

Parameters
func(function) A function that accepts a numeric Y coordinate and returns a scaled canvas Y coordinate
Note
Documentation generated by AI on 2026-03-03