NanoCanvas
Public Types | Public Member Functions | Static Public Member Functions | Protected Attributes | List of all members
NanoCanvas::Canvas Class Reference

#include <Canvas.h>

Public Types

enum  Winding { Winding::CCW = 1, Winding::CW = 2 }
 
enum  LineCap { LineCap::BUTT, LineCap::ROUND, LineCap::SQUARE }
 Line cap style. More...
 
enum  LineJoin { LineJoin::BEVEL, LineJoin::ROUND, LineJoin::MITER }
 Line join style. More...
 

Public Member Functions

 Canvas (NVGcontext *ctx, float width, float height, float scaleRatio=1.0f)
 Construct a canvas with NanoVG Context. More...
 
CanvasmoveTo (float x, float y)
 Moves the path to the specified point in the canvas, without creating a line. More...
 
CanvaslineTo (float x, float y)
 Adds a new point and creates a line from that point to the last specified point in the canvas. More...
 
CanvasarcTo (float x1, float y1, float x2, float y2, float r)
 Creates an arc/curve between two tangents on the canvas. More...
 
CanvasquadraticCurveTo (float cpx, float cpy, float x, float y)
 Creates a quadratic Bézier curve. More...
 
CanvasbezierCurveTo (float cp1x, float cp1y, float cp2x, float cp2y, float x, float y)
 Creates a cubic Bézier curve. More...
 
Canvasarc (float x, float y, float r, float sAngle, float eAngle, bool counterclockwise=false)
 Creates an arc/curve (used to create circles, or parts of circles) The arc() method creates an arc/curve (used to create circles, or parts of circles). More...
 
CanvasclosePath ()
 Close current path with a line segment. More...
 
Canvasrect (float x, float y, float w, float h)
 Creates a rectangle. More...
 
CanvasroundedRect (float x, float y, float w, float h, float r)
 Creates a rounded rectangle. More...
 
Canvascircle (float cx, float cy, float r)
 Creates a circle. More...
 
Canvasellipse (float cx, float cy, float rx, float ry)
 Creates an ellipse. More...
 
Canvasfill ()
 Fills the current drawing (path) More...
 
Canvasstroke ()
 Actually draws the path you have defined. More...
 
CanvasfillRect (float x, float y, float w, float h)
 Draws a "filled" rectangle. More...
 
CanvasstrokeRect (float x, float y, float w, float h)
 Draws a rectangle (no fill) More...
 
CanvasclearColor (const Color &color)
 Clear the canvas with color. More...
 
CanvasfillText (const string &text, float x, float y, float rowWidth=NAN)
 Draws "filled" text on the canvas. More...
 
CanvasdrawImage (Image &image, float x, float y, float width=NAN, float height=NAN, float sx=0, float sy=0, float swidth=NAN, float sheight=NAN)
 Draws an image onto the canvas. More...
 
CanvaslineCap (LineCap cap)
 Set the style of the end caps for a line. More...
 
CanvaslineJoin (LineJoin join)
 Set the type of corner created, when two lines meet. More...
 
CanvaslineWidth (float width)
 Set the current line width. More...
 
CanvasmiterLimit (float limit)
 Sets the maximum miter length. More...
 
CanvasglobalAlpha (float alpha)
 Sets the current alpha or transparency value of the drawing. More...
 
CanvasfillStyle (const Color &color)
 Sets the color to fill the drawing. More...
 
CanvasfillStyle (const Paint &paint)
 Set the gradient or pattern paint used to fill the drawing. More...
 
CanvasstrokeStyle (const Color &color)
 Set the color used for strokes. More...
 
CanvasstrokeStyle (const Paint &paint)
 Set the gradient or pattern paint used for strokes. More...
 
Canvasfont (const Font &font)
 Set current font for text rendering. More...
 
Canvasfont (float size)
 Set font size for current text style. More...
 
CanvastextAlign (HorizontalAlign hAlign, VerticalAlign vAlign)
 Sets the text alignment of current text style. More...
 
CanvasfillStyle (const TextStyle &textStyle)
 Set styles for text rendering. More...
 
float measureText (const string &text, float rowWidth=NAN)
 Check the width of the text, before writing it on the canvas. More...
 
float measureText (const string &text, float x, float y, float *bounds, float rowWidth=NAN)
 Check the boundary of the text, before writing it on the canvas. More...
 
Canvasscale (float scalewidth, float scaleheight)
 Scales the current drawing, bigger or smaller. More...
 
Canvasrotate (float angle)
 Rotates the current drawing. More...
 
Canvastranslate (float x, float y)
 Remaps the (0,0) position on the canvas. More...
 
Canvastransform (float a, float b, float c, float d, float e, float f)
 Replaces the current transformation matrix for the drawing. More...
 
CanvassetTransform (float a, float b, float c, float d, float e, float f)
 Resets the current transform to the identity matrix. Then runs transform() More...
 
CanvasrestTransform ()
 Resets the current transform to the identity matrix. More...
 
CanvasbegineFrame (int windowWidth, int windowHeight)
 Begin drawing a new frame. More...
 
CanvascancelFrame ()
 Cancels drawing the current frame. More...
 
void endFrame ()
 Ends drawing flushing remaining render state. More...
 
CanvasbeginPath ()
 Begins a path, or resets the current path. More...
 
CanvaspathWinding (Winding dir)
 Sets the current path winding. More...
 
Canvasclip (float x, float y, float w, float h)
 Clip of a rectangular region. More...
 
CanvasresetClip ()
 Reset clip state ,remove all clip region. More...
 
Canvassave ()
 Pushe and save the current render state into a state stack. More...
 
Canvasrestore ()
 Pop and restore current render state. More...
 
Canvasreset ()
 Resets current render state to default values. Does not affect the render state stack. More...
 
bool valid () const
 Check is the context avaliable. More...
 
CanvassetSize (float width, float height)
 Set canvas size. More...
 
CanvassetPosition (float x, float y)
 Set position of the canvas. More...
 
CanvassetScaleRatio (float ratio)
 Set scale ration of the canvas. More...
 
void local2Global (float &x, float &y)
 Convert coordinates in canvas to coordinates in windows. More...
 
void global2Local (float &x, float &y)
 Convert coordinates in windows to coordinates in canvas. More...
 
NVGcontext * nvgContext ()
 Get the NanoVG context for advanced contol. More...
 

Static Public Member Functions

static Paint createLinearGradient (float x0, float y0, float x1, float y1, const Color &scolor, const Color &ecolor)
 Creates a linear gradient (to use on canvas content) More...
 
static Paint createRadialGradient (float cx, float cy, float r1, float r2, const Color &icolor, const Color &ocolor)
 Creates a radial/circular gradient (to use on canvas content) More...
 
static Paint createBoxGradient (float x, float y, float w, float h, float r, float f, Color icol, Color ocol)
 Creates and returns a box gradient. More...
 
static Paint createPattern (const Image &image, float ox, float oy, float w, float h, float angle=0.0f, float alpha=1.0f)
 Creates and returns an image pattern paint. More...
 

Protected Attributes

NVGcontext * m_nvgCtx
 The NanoVG context. More...
 
float m_width
 The width of the canvas. More...
 
float m_height
 The height of the canvas. More...
 
float m_scaleRatio
 Buffer / window size ratio. More...
 
float m_xPos
 The x-coordinate of the canvas in window. More...
 
float m_yPos
 The y-coordinate of the canvas in window. More...
 

Detailed Description

Author
Geequlim

Member Enumeration Documentation

Line cap style.

Enumerator
BUTT 

A flat edge is added to each end of the line.

ROUND 

A rounded end cap is added to each end of the line.

SQUARE 

A square end cap is added to each end of the line.

Line join style.

Enumerator
BEVEL 

Creates a beveled corner.

ROUND 

Creates a rounded corner.

MITER 

Creates a sharp corner.

Enumerator
CCW 

Counter clock wise.

CW 

Clock wise.

Constructor & Destructor Documentation

NanoCanvas::Canvas::Canvas ( NVGcontext *  ctx,
float  width,
float  height,
float  scaleRatio = 1.0f 
)

Construct a canvas with NanoVG Context.

Parameters
ctxThe NanoVG Context used for this canvas
widthThe width of the canvas, in pixels
heightThe height of the canvas, in pixels
scaleRatioThe device pixel ration

Member Function Documentation

Canvas& NanoCanvas::Canvas::arc ( float  x,
float  y,
float  r,
float  sAngle,
float  eAngle,
bool  counterclockwise = false 
)

Creates an arc/curve (used to create circles, or parts of circles) The arc() method creates an arc/curve (used to create circles, or parts of circles).

Note
Tip: To create a circle with arc(): Set start angle to 0 and end angle to 2*π.
Parameters
xThe x-coordinate of the center of the circle
yThe y-coordinate of the center of the circle
rThe radius of the circle
sAngleThe starting angle, in radians (0 is at the 3 o'clock position of the arc's circle)
eAngleThe ending angle, in radians
counterclockwiseOptional. Specifies whether the drawing should be counterclockwise or clockwise. False is default, and indicates clockwise, while true indicates counter-clockwise.
Returns
Canvas& NanoCanvas::Canvas::arcTo ( float  x1,
float  y1,
float  x2,
float  y2,
float  r 
)

Creates an arc/curve between two tangents on the canvas.

Parameters
x1The x-coordinate of the first tangent
y1The y-coordinate of the first tangent
x2The x-coordinate of the second tangent
y2The y-coordinate of the second tangent
rThe radius of the arc
Returns
The Canvas to operate with
Canvas& NanoCanvas::Canvas::begineFrame ( int  windowWidth,
int  windowHeight 
)

Begin drawing a new frame.

Calls to Canvas drawing API should be wrapped in begineFrame() & endFrame() begineFrame() defines the size of the window to render to in relation currently set viewport (i.e. glViewport on GL backends).

Parameters
windowWidthWidth of your window
windowHeightHeight of your window
Returns
The canvas to begine frame with
Canvas& NanoCanvas::Canvas::beginPath ( )

Begins a path, or resets the current path.

Returns
The canvas to create path
Canvas& NanoCanvas::Canvas::bezierCurveTo ( float  cp1x,
float  cp1y,
float  cp2x,
float  cp2y,
float  x,
float  y 
)

Creates a cubic Bézier curve.

The bezierCurveTo() method adds a point to the current path by using the specified control points that represent a cubic Bézier curve.
A cubic bezier curve requires three points. The first two points are control points that are used in the cubic Bézier calculation and the last point is the ending point for the curve. The starting point for the curve is the last point in the current path. If a path does not exist, use the beginPath() and moveTo() methods to define a starting point.

Parameters
cp1xThe x-coordinate of the first Bézier control point
cp1yThe y-coordinate of the first Bézier control point
cp2xThe x-coordinate of the second Bézier control point
cp2yThe y-coordinate of the second Bézier control point
xThe x-coordinate of the ending point
yThe y-coordinate of the ending point
Returns
The Canvas to operate with
Canvas& NanoCanvas::Canvas::cancelFrame ( )

Cancels drawing the current frame.

Returns
The canvas to cancle draw
Canvas& NanoCanvas::Canvas::circle ( float  cx,
float  cy,
float  r 
)

Creates a circle.

Parameters
cxThe x-coordinate of center point for the circle
cyThe y-coordinate of center point for the circle
rThe radius of the circle
Returns
The canvas to create path
Canvas& NanoCanvas::Canvas::clearColor ( const Color color)

Clear the canvas with color.

Parameters
colorThe color to fill the hole canvas
Returns
The canvas to operate with
Canvas& NanoCanvas::Canvas::clip ( float  x,
float  y,
float  w,
float  h 
)

Clip of a rectangular region.

Parameters
xThe x-coordinate of the upper-left corner of the clip region
yThe y-coordinate of the upper-left corner of the clip region
wThe width of the clip region, in pixels
hThe width of the clip region, in pixels
Returns
The canvas to clip with
Canvas& NanoCanvas::Canvas::closePath ( )

Close current path with a line segment.

Returns
The canvas to operate with
static Paint NanoCanvas::Canvas::createBoxGradient ( float  x,
float  y,
float  w,
float  h,
float  r,
float  f,
Color  icol,
Color  ocol 
)
static

Creates and returns a box gradient.

Box gradient is a feathered rounded rectangle, it is useful for rendering drop shadows or highlights for boxes.
Parameters
xThe x-coordinate of the upper-left corner of the rectangle
yThe y-coordinate of the upper-left corner of the rectangle
wThe width of the rectangle, in pixels
hThe height of the rectangle, in pixels
rThe radius of the circle formed by 4 corners of the rounded rectangle
fHow blurry the border of the rectangle is
icolThe inner color of the gradient
ocolThe outer color of the gradient
Returns
The created gradient style object.
static Paint NanoCanvas::Canvas::createLinearGradient ( float  x0,
float  y0,
float  x1,
float  y1,
const Color scolor,
const Color ecolor 
)
static

Creates a linear gradient (to use on canvas content)

Parameters
x0The x-coordinate of the start point of the gradient
y0The y-coordinate of the start point of the gradient
x1The x-coordinate of the end point of the gradient
y1The y-coordinate of the end point of the gradient
scolorThe start color
outterThe end color
Returns
The created gradient style object.
static Paint NanoCanvas::Canvas::createPattern ( const Image image,
float  ox,
float  oy,
float  w,
float  h,
float  angle = 0.0f,
float  alpha = 1.0f 
)
static

Creates and returns an image pattern paint.

Parameters
imageSpecifies the image of the pattern to use
oxThe x-coordinate of the upper-left corner of the image would be draw
oyThe y-coordinate of the upper-left corner of the image would be draw
wThe width of the pattern
hThe height of the pattern
angleThe rotation around the top-left corner in radians
alphaThe transparent of the image pattern
Returns
The patter paint created
static Paint NanoCanvas::Canvas::createRadialGradient ( float  cx,
float  cy,
float  r1,
float  r2,
const Color icolor,
const Color ocolor 
)
static

Creates a radial/circular gradient (to use on canvas content)

Parameters
cxThe x-coordinate of the circle of the gradient
cyThe y-coordinate of the circle of the gradient
r1The radius of the inner circle
r2The radius of the outter circle
icolorThe color on inner circle
ocolorThe color on outer circle
Returns
The created gradient style object.
Canvas& NanoCanvas::Canvas::drawImage ( Image image,
float  x,
float  y,
float  width = NAN,
float  height = NAN,
float  sx = 0,
float  sy = 0,
float  swidth = NAN,
float  sheight = NAN 
)

Draws an image onto the canvas.

The drawImage() method can also draw parts of an image, and/or increase/reduce the image size.

Parameters
imageSpecifies the image to use
xThe x coordinate where to place the image on the canvas
yThe y coordinate where to place the image on the canvas
widthThe width of the image to use (stretch or reduce the image),NAN as the default be the same as wdith of the clipped area
heightThe height of the image to use (stretch or reduce the image),NAN as the default be the same as wdith of the clipped area
sxThe x coordinate where to start clipping,0 as the default
syThe y coordinate where to start clipping,0 as the default
swidthThe wdith of the clipped image,NAN as defualt to clip to right side of the image
sheightThe height of the clipped image,NAN as defualt to clip to bottom side of the image
Returns
The canvas to draw this image
Canvas& NanoCanvas::Canvas::ellipse ( float  cx,
float  cy,
float  rx,
float  ry 
)

Creates an ellipse.

Parameters
cxThe x-coordinate of center point for the ellipse
cyThe x-coordinate of center point for the ellipse
rxThe radius of the ellipse in horizentoal
ryThe radius of the ellipse in vertical
Returns
The canvas to create path
void NanoCanvas::Canvas::endFrame ( )

Ends drawing flushing remaining render state.

Canvas& NanoCanvas::Canvas::fill ( )

Fills the current drawing (path)

The fill() method fills the current drawing (path). The default color is black.

Note
If the path is not closed, the fill() method will add a line from the last point to the startpoint of the path to close the path (like closePath()), and then fill the path.
Returns
The canvas to fill
Canvas& NanoCanvas::Canvas::fillRect ( float  x,
float  y,
float  w,
float  h 
)

Draws a "filled" rectangle.

The fillRect() method draws a "filled" rectangle. The default color of the fill is black.

Parameters
xThe x-coordinate of the upper-left corner of the rectangle
yThe y-coordinate of the upper-left corner of the rectangle
wThe width of the rectangle, in pixels
hThe height of the rectangle, in pixels
Returns
The canvas to draw
Canvas& NanoCanvas::Canvas::fillStyle ( const Color color)

Sets the color to fill the drawing.

Parameters
colorThe color to fill with
Returns
The canvas to operate with
Canvas& NanoCanvas::Canvas::fillStyle ( const Paint paint)

Set the gradient or pattern paint used to fill the drawing.

Parameters
paintThe paint used to fill the drawing
Returns
The canvas to operate with
Canvas& NanoCanvas::Canvas::fillStyle ( const TextStyle textStyle)

Set styles for text rendering.

Parameters
textStyleThe text style to use
See also
NanoCanvas::TextStyle
Returns
The canvas to operate with
Canvas& NanoCanvas::Canvas::fillText ( const string &  text,
float  x,
float  y,
float  rowWidth = NAN 
)

Draws "filled" text on the canvas.

Parameters
textSpecifies the text that will be written on the canvas
xThe x coordinate where to start painting the text (relative to the canvas)
yThe y coordinate where to start painting the text (relative to the canvas)
rowWidthThe max row width of the text box,NAN is not limited
Returns
The canvas to operate with
Canvas& NanoCanvas::Canvas::font ( const Font font)

Set current font for text rendering.

Note
If the face of the font is invalid ,it doesn't work
See also
NanoCanvas::Font
Parameters
fontThe font to use
Returns
The canvas to operate with
Canvas& NanoCanvas::Canvas::font ( float  size)

Set font size for current text style.

Parameters
sizeThe font size
Returns
The canvas to operate with
void NanoCanvas::Canvas::global2Local ( float &  x,
float &  y 
)
inline

Convert coordinates in windows to coordinates in canvas.

Parameters
x[inout] The x-coordinate to convert
y[inout] The x-coordinate to convert
Canvas& NanoCanvas::Canvas::globalAlpha ( float  alpha)

Sets the current alpha or transparency value of the drawing.

Parameters
alphanew alpha vlaue of canvas
Returns
The canvas to operate with
Canvas& NanoCanvas::Canvas::lineCap ( LineCap  cap)

Set the style of the end caps for a line.

Parameters
capThe line cap style
Returns
The canvas to operate with
Canvas& NanoCanvas::Canvas::lineJoin ( LineJoin  join)

Set the type of corner created, when two lines meet.

Parameters
joinThe line join style
Returns
The canvas to operate with
Canvas& NanoCanvas::Canvas::lineTo ( float  x,
float  y 
)

Adds a new point and creates a line from that point to the last specified point in the canvas.

The lineTo() method adds a new point and creates a line from that point to the last specified point in the canvas (this method does not draw the line).

Parameters
xThe x-coordinate of where to create the line to
yThe y-coordinate of where to create the line to
Returns
The Canvas to operate with
Canvas& NanoCanvas::Canvas::lineWidth ( float  width)

Set the current line width.

Parameters
widthThe current line width, in pixels
Returns
The canvas to operate with
void NanoCanvas::Canvas::local2Global ( float &  x,
float &  y 
)
inline

Convert coordinates in canvas to coordinates in windows.

Parameters
x[inout] The x-coordinate to convert
y[inout] The x-coordinate to convert
float NanoCanvas::Canvas::measureText ( const string &  text,
float  rowWidth = NAN 
)

Check the width of the text, before writing it on the canvas.

Parameters
textThe text to be measured
rowWidthThe max row width of the text box,NAN is not limited
Returns
The width of the specified text
float NanoCanvas::Canvas::measureText ( const string &  text,
float  x,
float  y,
float *  bounds,
float  rowWidth = NAN 
)

Check the boundary of the text, before writing it on the canvas.

Parameters
textThe text to be measured
xThe x-coordinate of the text
yThe y-coordinate of the text
bounds[in] The float array to store boundary values should be a pointer to float[4]
rowWidthThe max row width of the text box,NAN is not limited
Returns
The width of the specified text
Canvas& NanoCanvas::Canvas::miterLimit ( float  limit)

Sets the maximum miter length.

The miter length is the distance between the inner corner and the outer corner where two lines meet.
The miter length grows bigger as the angle of the corner gets smaller.

Note
The miterLimit property works only if the lineJoin attribute is "miter".
Parameters
limitA positive number that specifies the maximum miter length. If the current miter length exceeds the miterLimit, the corner will display as lineJoin "bevel"
Returns
The canvas to operate with
Canvas& NanoCanvas::Canvas::moveTo ( float  x,
float  y 
)

Moves the path to the specified point in the canvas, without creating a line.

The moveTo() method moves the path to the specified point in the canvas, without creating a line.

Parameters
xThe x-coordinate of where to move the path to
yThe y-coordinate of where to move the path to
Returns
The Canvas to operate with
NVGcontext* NanoCanvas::Canvas::nvgContext ( )
inline

Get the NanoVG context for advanced contol.

Returns
The NanoVG context of this canvas
Canvas& NanoCanvas::Canvas::pathWinding ( Winding  dir)

Sets the current path winding.

Parameters
dirCVS_CW or CVS_CW
Returns
The canvas to operate with
Canvas& NanoCanvas::Canvas::quadraticCurveTo ( float  cpx,
float  cpy,
float  x,
float  y 
)

Creates a quadratic Bézier curve.

The quadraticCurveTo() method adds a point to the current path by using the specified control points that represent a quadratic Bézier curve.
A quadratic Bézier curve requires two points. The first point is a control point that is used in the quadratic Bézier calculation and the second point is the ending point for the curve. The starting point for the curve is the last point in the current path. If a path does not exist, use the beginPath() and moveTo() methods to define a starting point.

Parameters
cpxThe x-coordinate of the Bézier control point
cpyThe y-coordinate of the Bézier control point
xThe x-coordinate of the ending point
yThe y-coordinate of the ending point
Returns
The Canvas to operate with
Canvas& NanoCanvas::Canvas::rect ( float  x,
float  y,
float  w,
float  h 
)

Creates a rectangle.

The rect() method creates a rectangle.

Parameters
xThe x-coordinate of the upper-left corner of the rectangle
yThe y-coordinate of the upper-left corner of the rectangle
wThe width of the rectangle, in pixels
hThe height of the rectangle, in pixels
Returns
The canvas which the path be added to
Canvas& NanoCanvas::Canvas::reset ( )

Resets current render state to default values. Does not affect the render state stack.

Returns
The canvas to reset state
Canvas& NanoCanvas::Canvas::resetClip ( )

Reset clip state ,remove all clip region.

Returns
The canvas to reset
Canvas& NanoCanvas::Canvas::restore ( )

Pop and restore current render state.

Returns
The canvas to restore state
Canvas& NanoCanvas::Canvas::restTransform ( )

Resets the current transform to the identity matrix.

Returns
The canvas to set transform with
Canvas& NanoCanvas::Canvas::rotate ( float  angle)

Rotates the current drawing.

Note
: The rotation will only affect drawings made AFTER the rotation is done.
To calculate from degrees to radians: degrees*Math.PI/180.

Example: to rotate 5 degrees, specify the following: 5*Math.PI/180
Parameters
angleThe rotation angle, in radians.
Returns
The canvas to rotate with
Canvas& NanoCanvas::Canvas::roundedRect ( float  x,
float  y,
float  w,
float  h,
float  r 
)

Creates a rounded rectangle.

Parameters
xThe x-coordinate of the upper-left corner of the rectangle
yThe y-coordinate of the upper-left corner of the rectangle
wThe width of the rectangle, in pixels
hThe height of the rectangle, in pixels
rThe radius of the circle formed by 4 corners of the rounded rectangle
Returns
The canvas to create path
Canvas& NanoCanvas::Canvas::save ( )

Pushe and save the current render state into a state stack.

Note
A matching restore() must be used to restore the state.
Returns
The canvas to save state
Canvas& NanoCanvas::Canvas::scale ( float  scalewidth,
float  scaleheight 
)

Scales the current drawing, bigger or smaller.

Note
If you scale a drawing, all future drawings will also be scaled. The positioning will also be scaled. If you scale(2,2); drawings will be positioned twice as far from the left and top of the canvas as you specify.
Parameters
scalewidthScales the width of the current drawing (1=100%, 0.5=50%, 2=200%, etc.)
scaleheightScales the height of the current drawing (1=100%, 0.5=50%, 2=200%, etc.)
Returns
The canvas to scale with
Canvas& NanoCanvas::Canvas::setPosition ( float  x,
float  y 
)
inline

Set position of the canvas.

Parameters
xThe x-coordinate of the upper-left corner of the rectangle
yThe y-coordinate of the upper-left corner of the rectangle
Returns
The canvas to change position
Canvas& NanoCanvas::Canvas::setScaleRatio ( float  ratio)
inline

Set scale ration of the canvas.

Device pixel ration allows to control the rendering on Hi-DPI devices. For example, GLFW returns two dimension for an opened window: window size and frame buffer size. In that case you would set windowWidth/Height to the window size devicePixelRatio to: frameBufferWidth / windowWidth.

Parameters
ratioThe device pixel ration
Returns
The canvas to set scale ration with
Canvas& NanoCanvas::Canvas::setSize ( float  width,
float  height 
)
inline

Set canvas size.

Parameters
widthThe width of the canvas, in pixels
heightThe height of the canvas, in pixels
Returns
The canvas to resize
Canvas& NanoCanvas::Canvas::setTransform ( float  a,
float  b,
float  c,
float  d,
float  e,
float  f 
)

Resets the current transform to the identity matrix. Then runs transform()

Parameters
aScales the drawing horizontally
bSkew the the drawing horizontally
cSkew the the drawing vertically
dScales the drawing vertically
eMoves the the drawing horizontally
fMoves the the drawing vertically
See also
Canvas::transform()
Canvas::restTransform()
Returns
The canvas to set transform with
Canvas& NanoCanvas::Canvas::stroke ( )

Actually draws the path you have defined.

The stroke() method actually draws the path you have defined with all those moveTo() and lineTo() methods. The default color is black.

Returns
The canvas to stroke
Canvas& NanoCanvas::Canvas::strokeRect ( float  x,
float  y,
float  w,
float  h 
)

Draws a rectangle (no fill)

The strokeRect() method draws a rectangle (no fill). The default color of the stroke is black.

Parameters
xThe x-coordinate of the upper-left corner of the rectangle
yThe y-coordinate of the upper-left corner of the rectangle
wThe width of the rectangle, in pixels
hThe height of the rectangle, in pixels
Returns
The canvas to draw
Canvas& NanoCanvas::Canvas::strokeStyle ( const Color color)

Set the color used for strokes.

Parameters
colorStroke color
Returns
The canvas to operate with
Canvas& NanoCanvas::Canvas::strokeStyle ( const Paint paint)

Set the gradient or pattern paint used for strokes.

Parameters
paintThe paint used to fill the drawing
Returns
The canvas to operate with
Canvas& NanoCanvas::Canvas::textAlign ( HorizontalAlign  hAlign,
VerticalAlign  vAlign 
)

Sets the text alignment of current text style.

Parameters
hAlignThe horizontak alignment
vAlignThe verical alignment
See also
TextAlign::HorizontalAlign
TextAlign::VerticalAlign
Returns
The canvas to operate with
Canvas& NanoCanvas::Canvas::transform ( float  a,
float  b,
float  c,
float  d,
float  e,
float  f 
)

Replaces the current transformation matrix for the drawing.

Each object on the canvas has a current transformation matrix.
The transform() method replaces the current transformation matrix. It multiplies the current transformation matrix with the matrix described by:
  • a c e
  • b d f
  • 0 0 1
In other words, the transform() method lets you scale, rotate, move, and skew the current context.
Note
The transformation will only affect drawings made after the transform() method is called.
The transform() method behaves relatively to other transformations made by rotate(), scale(), translate(), or transform(). Example: If you already have set your drawing to scale by two, and the transform() method scales your drawings by two, your drawings will now scale by four.
Tip: Check out the setTransform() method, which does not behave relatively to other transformations.
Parameters
aScales the drawing horizontally
bSkew the the drawing horizontally
cSkew the the drawing vertically
dScales the drawing vertically
eMoves the the drawing horizontally
fMoves the the drawing vertically
Returns
The canvas to transform with
Canvas& NanoCanvas::Canvas::translate ( float  x,
float  y 
)

Remaps the (0,0) position on the canvas.

Note
When you call a method such as fillRect() after translate(), the value is added to the x- and y-coordinate values.
Parameters
xThe value to add to horizontal (x) coordinates
yThe value to add to vertical (y) coordinates
Returns
The canvas to translate with
bool NanoCanvas::Canvas::valid ( ) const
inline

Check is the context avaliable.

Returns
Is the context avaliable

Member Data Documentation

float NanoCanvas::Canvas::m_height
protected

The height of the canvas.

NVGcontext* NanoCanvas::Canvas::m_nvgCtx
protected

The NanoVG context.

float NanoCanvas::Canvas::m_scaleRatio
protected

Buffer / window size ratio.

float NanoCanvas::Canvas::m_width
protected

The width of the canvas.

float NanoCanvas::Canvas::m_xPos
protected

The x-coordinate of the canvas in window.

float NanoCanvas::Canvas::m_yPos
protected

The y-coordinate of the canvas in window.


The documentation for this class was generated from the following file:

The documentation was generated by Doxygen

Copyright © 2015 Geequlim. All rights reserved.