nodesnim/nodes/canvas

Canvas is the root type of all 2D and Control nodes.

Canvas used for drawing primitive geometry.

Types

DrawCommandType {...}{.size: 1.} = enum
  POINT, LINE, RECT, FILL, CIRCLE
DrawCommand = object
  x1*, y1*: GLfloat
  color*: ColorRef
  case kind*: DrawCommandType
  of LINE, RECT:
      x2*, y2*: GLfloat

  of CIRCLE:
      points*: seq[GLfloat]

  else:
      nil

  
CanvasObj = object of NodeObj
  commands*: seq[DrawCommand]
CanvasPtr = ptr CanvasObj

Procs

proc Canvas(name: string; variable: var CanvasObj): CanvasPtr {...}{.raises: [], tags: [].}

Creates a new Canvas pointer.

Arguments:

  • name is a node name.
  • variable is a CanvasObj variable

Examples:

var
  canvas1_obj: CanvasObj
  canvas1 = Canvas("Canvas", canvas1_obj)
proc Canvas(variable: var CanvasObj): CanvasPtr {...}{.inline, raises: [], tags: [].}

Creates a new Canvas pointer with default name "Canvas".

Arguments:

  • variable is a CanvasObj variable

Examples:

var
  canvas1_obj: CanvasObj
  canvas1 = Canvas(canvas1_obj)

Methods

method draw(canvas: CanvasPtr; w, h: GLfloat) {...}{.raises: [GLerror], tags: [].}
This uses in the window.nim.
method duplicate(self: CanvasPtr; obj: var CanvasObj): CanvasPtr {...}{.base, raises: [],
    tags: [].}
Duplicates Canvas object and create a new Canvas pointer.
method circle(canvas: CanvasPtr; x, y, radius: GLfloat; color: ColorRef;
             quality: int = 100) {...}{.base, raises: [], tags: [].}

Draws a circle in the canvas.

Arguments:

  • x - circle center at X axis.
  • y - circle center at Y axis.
  • radius - circle radius.
  • color - Color object.
  • quality - circle quality.
method point(canvas: CanvasPtr; x, y: GLfloat; color: ColorRef) {...}{.base, raises: [],
    tags: [].}

Draws a point in the canvas.

Arguments:

  • x - point position at X axis.
  • y - point position at Y axis.
  • color - point color.
method line(canvas: CanvasPtr; x1, y1, x2, y2: GLfloat; color: ColorRef) {...}{.base,
    raises: [], tags: [].}

Draws a line in the canvas.

Arguments:

  • x1 - first position at X axis.
  • y1 - first position at Y axis.
  • x2 - second position at X axis.
  • y2 - second position at Y axis.
  • color - line color.
method rect(canvas: CanvasPtr; x1, y1, x2, y2: GLfloat; color: ColorRef) {...}{.base,
    raises: [], tags: [].}

Draws a line in the canvas.

Arguments:

  • x1 - first position at X axis.
  • y1 - first position at Y axis.
  • x2 - second position at X axis.
  • y2 - second position at Y axis.
  • color - rectangle color.
method fill(canvas: CanvasPtr; color: ColorRef) {...}{.base, raises: [], tags: [].}
Fills canvas.
method resize(canvas: CanvasPtr; w, h: GLfloat) {...}{.base, raises: [], tags: [].}

Resizes canvas.

Arguments:

  • w is a new width.
  • h is a new height.