nodesnim/nodes/canvas

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

Canvas used for drawing primitive geometry.

Types

CanvasObj = object of NodeObj
  surface: SurfacePtr
  renderer: RendererPtr
  canvas_texture: GLuint
  position*: Vector2Obj      ## Node position, by default is Vector2(0, 0).
  global_position*: Vector2Obj ## Node global position.
  rect_size*: Vector2Obj     ## Node size.
  rect_min_size*: Vector2Obj
  size_anchor*: Vector2Obj   ## Node size anchor.
  anchor*: AnchorObj         ## Node anchor.
  
CanvasRef = ref CanvasObj

Procs

proc Canvas(name: string = "Canvas"): CanvasRef {...}{.raises: [], tags: [].}

Creates a new Canvas.

Arguments:

  • name is a node name.

Example:

var canvas1 = Canvas("Canvas")
proc bezier(canvas: CanvasRef; x1, y1, x2, y2, x3, y3: GLfloat; color: ColorRef) {...}{.
    raises: [GLerror], tags: [].}

Draws a quadric bezier curve at 3 points.

Arguments:

  • x1 y1 - first point.
  • x2 y2 - second point.
  • x3 y3 - third point.

See also:

proc circle(canvas: CanvasRef; x, y, radius: GLfloat; color: ColorRef;
            quality: int = 100) {...}{.raises: [GLerror], 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.
proc cubicBezier(canvas: CanvasRef; x1, y1, x2, y2, x3, y3, x4, y4: GLfloat;
                 color: ColorRef) {...}{.raises: [GLerror], tags: [].}

Draws a quadric bezier curve at 4 points.

Arguments:

  • x1 y1 - first point.
  • x2 y2 - second point.
  • x3 y3 - third point.
  • x4 y4 - fourth point.

See also:

proc fill(canvas: CanvasRef; color: ColorRef) {...}{.raises: [GLerror], tags: [].}
Fills canvas.
proc line(canvas: CanvasRef; x1, y1, x2, y2: GLfloat; color: ColorRef) {...}{.
    raises: [GLerror], 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.
proc rect(canvas: CanvasRef; x1, y1, x2, y2: GLfloat; color: ColorRef) {...}{.
    raises: [GLerror], 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.
proc fillRect(canvas: CanvasRef; x1, y1, x2, y2: GLfloat; color: ColorRef) {...}{.
    raises: [GLerror], 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.
proc point(canvas: CanvasRef; x, y: GLfloat; color: ColorRef) {...}{.
    raises: [GLerror], tags: [].}

Draws a point in the canvas.

Arguments:

  • x - point position at X axis.
  • y - point position at Y axis.
  • color - point color.
proc text(canvas: CanvasRef; text: StyleText | string; x, y: GLfloat;
          align: Vector2Obj = Vector2())

Draws multiline text.

Arguments:

  • text - multiline colored text.
  • align - horizontal text alignment.
proc saveAs(self: CanvasRef; filename: cstring) {...}{.raises: [], tags: [].}
Saves canvas as image file.

Methods

method calcGlobalPosition(self: CanvasRef) {...}{.base, raises: [], tags: [].}
Returns global node position.
method calcPositionAnchor(self: CanvasRef) {...}{.base, raises: [], tags: [].}
Calculates node position with anchor. This used in the Window object.
method draw(canvas: CanvasRef; w, h: GLfloat) {...}{.raises: [GLerror], tags: [].}
This uses in the window.nim.
method duplicate(self: CanvasRef): CanvasRef {...}{.base, raises: [], tags: [].}
Duplicates Canvas object and create a new Canvas.
method move(self: CanvasRef; vec2: Vector2Obj) {...}{.base, inline, raises: [],
    tags: [].}

Adds vec2 to the node position.

Arguments:

  • vec2: how much to add to the position on the X,Y axes.

See also:

method move(self: CanvasRef; x, y: float) {...}{.base, inline, raises: [], tags: [].}

Adds x and` y` to the node position.

Arguments:

  • x: how much to add to the position on the X axis.
  • y: how much to add to the position on the Y axis.

See also:

method moveTo(self: CanvasRef; x, y: float) {...}{.base, inline, raises: [], tags: [].}

Change node position.

Arguments:

  • x: how much to add to the position on the X axis.
  • y: how much to add to the position on the Y axis.
method moveTo(self: CanvasRef; vec2: Vector2Obj) {...}{.base, inline, raises: [],
    tags: [].}

Change node position.

Arguments:

  • vec2: how much to add to the position on the X,Y axes.
method resize(self: CanvasRef; w, h: GLfloat; save_anchor: bool = false) {...}{.base,
    raises: [GLerror], tags: [].}

Resizes canvas.

Arguments:

  • w is a new width.
  • h is a new height.
method setAnchor(self: CanvasRef; anchor: AnchorObj) {...}{.base, raises: [],
    tags: [].}

Changes node anchor.

Arguments:

  • anchor - AnchorObj object.
method setAnchor(self: CanvasRef; x1, y1, x2, y2: float) {...}{.base, raises: [],
    tags: [].}

Changes node anchor.

Arguments:

  • x1 and y1 - anchor relative to the parent node.
  • x2 and y2 - anchor relative to this node.
method setSizeAnchor(self: CanvasRef; anchor: Vector2Obj) {...}{.base, raises: [],
    tags: [].}
Changes the size anchor to the size of the parent.
method setSizeAnchor(self: CanvasRef; x, y: float) {...}{.base, raises: [], tags: [].}
Changes the size anchor to the size of the parent.