CUGL 2.1
Cornell University Game Library
|
#include <CUCanvasNode.h>
Classes | |
class | Paint |
Public Types | |
enum | Winding : int { Winding::NONE = 0, Winding::CCW = 1, Winding::CW = 2 } |
enum | FillRule : int { FillRule::NONZERO = 0, FillRule::EVENODD = 1, FillRule::STENCIL = 2, FillRule::CLIPFILL = 3, FillRule::MASKFILL = 4 } |
Public Member Functions | |
CanvasNode () | |
~CanvasNode () | |
virtual void | dispose () override |
virtual bool | init () override |
virtual bool | initWithBounds (const Size size) override |
virtual bool | initWithBounds (float width, float height) override |
virtual bool | initWithBounds (const Rect rect) override |
virtual bool | initWithBounds (float x, float y, float width, float height) override |
virtual bool | initWithData (const Scene2Loader *loader, const std::shared_ptr< JsonValue > &data) override |
size_t | pages () const |
void | paginate (size_t size) |
size_t | getEditPage () |
void | setEditPage (size_t page) |
size_t | getDrawPage () |
void | setDrawPage (size_t page) |
void | clearPage () |
void | clearAll () |
virtual void | draw (const std::shared_ptr< SpriteBatch > &batch, const Affine2 &transform, Color4 tint) override |
void | saveState () |
void | restoreState () |
void | resetState () |
float | getFringe () const |
void | setFringe (float fringe) |
float | getGlobalAlpha () |
void | setGlobalAlpha (float alpha) |
const Affine2 & | getCommandTransform () |
void | setCommandTransform (const Affine2 &transform) |
void | clearCommandTransform () |
void | translateCommands (const Vec2 p) |
void | translateCommands (float x, float y) |
void | scaleCommands (const Vec2 s) |
void | scaleCommands (float sx, float sy) |
void | rotateCommands (float angle) |
void | skewXCommands (float angle) |
void | skewYCommands (float angle) |
const std::shared_ptr< Scissor > & | getLocalScissor () const |
void | setLocalScissor (const std::shared_ptr< Scissor > &scissor) |
void | applyLocalScissor (const std::shared_ptr< Scissor > &scissor) |
void | clearLocalScissor () |
Winding | getWinding () const |
void | setWinding (Winding winding) |
FillRule | getFillRule () const |
void | setFillRule (FillRule rule) |
Color4 | getFillColor () const |
void | setFillColor (Color4 color) |
const std::shared_ptr< Paint > & | getFillPaint () const |
void | setFillPaint (const std::shared_ptr< Paint > &paint) |
Color4 | getStrokeColor () const |
void | setStrokeColor (Color4 color) |
const std::shared_ptr< Paint > & | getStrokePaint () const |
void | setStrokePaint (const std::shared_ptr< Paint > &paint) |
float | getStrokeWidth () const |
void | setStrokeWidth (float width) |
float | getMitreLimit () const |
void | setMitreLimit (float limit) |
poly2::Joint | getLineJoint () |
void | setLineJoint (poly2::Joint joint) |
poly2::EndCap | getLineCap () |
void | setLineCap (poly2::EndCap cap) |
GLenum | getBlendEquation () const |
void | setBlendEquation (GLenum equation) |
void | setSrcBlendFunc (GLenum func) |
void | setSrcBlendFunc (GLenum srcRGB, GLenum srcAlpha) |
GLenum | getSrcRGBFunc () const |
GLenum | getSrcAlphaFunc () const |
void | setDstBlendFunc (GLenum func) |
void | setDstBlendFunc (GLenum dstRGB, GLenum dstAlpha) |
GLenum | getDstRGBFunc () const |
GLenum | getDstAlphaFunc () const |
void | beginPath () |
void | moveTo (const Vec2 pos) |
void | moveTo (float x, float y) |
void | lineTo (const Vec2 pos) |
void | lineTo (float x, float y) |
void | bezierTo (const Vec2 c1, const Vec2 c2, const Vec2 p) |
void | bezierTo (float c1x, float c1y, float c2x, float c2y, float px, float py) |
void | quadTo (const Vec2 c, const Vec2 p) |
void | quadTo (float cx, float cy, float px, float py) |
void | arcTo (const Vec2 center, float r, float a0, float a1, bool ccw=true) |
void | arcTo (float cx, float cy, float r, float a0, float a1, bool ccw=true) |
void | arcTo (const Vec2 s, const Vec2 e, float radius) |
void | arcTo (float sx, float sy, float ex, float ey, float radius) |
void | closePath () |
void | drawArc (const Vec2 center, float r, float a0, float a1, bool ccw=true) |
void | drawArc (float cx, float cy, float r, float a0, float a1, bool ccw=true) |
void | drawRect (const Rect rect) |
void | drawRect (float x, float y, float w, float h) |
void | drawRoundedRect (const Rect rect, float r) |
void | drawRoundedRect (float x, float y, float w, float h, float r) |
void | drawRoundedRectVarying (const Rect rect, float radBL, float radTL, float radTR, float radBR) |
void | drawRoundedRectVarying (float x, float y, float w, float h, float radBL, float radTL, float radTR, float radBR) |
void | drawEllipse (const Vec2 center, const Size size) |
void | drawEllipse (const Rect bounds) |
void | drawEllipse (float cx, float cy, float rx, float ry) |
void | drawCircle (const Vec2 center, float r) |
void | drawCircle (float cx, float cy, float r) |
void | fillPaths () |
void | strokePaths () |
const std::shared_ptr< Font > & | getFont () const |
void | setFont (const std::shared_ptr< Font > &font) |
float | getFontSize () const |
void | setFontSize (float size) |
float | getFontBlur () const |
void | setFontBlur (float blur) |
float | getTextSpacing () const |
void | setTextSpacing (float spacing) |
HorizontalAlign | getHorizontalTextAlign () const |
void | setHorizontalTextAlign (HorizontalAlign align) |
VerticalAlign | getVerticalTextAlign () const |
void | setVerticalTextAlign (VerticalAlign align) |
void | drawText (const Vec2 p, const std::string text) |
void | drawText (float x, float y, const std::string text) |
void | drawText (const Vec2 p, const char *substr, const char *end) |
void | drawText (float x, float y, const char *substr, const char *end) |
void | drawTextBox (const Vec2 p, float width, const std::string text) |
void | drawTextBox (float x, float y, float width, const std::string text) |
void | drawTextBox (const Vec2 p, float width, const char *substr, const char *end) |
void | drawTextBox (float x, float y, float width, const char *substr, const char *end) |
Public Member Functions inherited from cugl::scene2::SceneNode | |
SceneNode () | |
~SceneNode () | |
virtual bool | initWithPosition (const Vec2 pos) |
bool | initWithPosition (float x, float y) |
virtual std::shared_ptr< SceneNode > | copy (const std::shared_ptr< SceneNode > &dst) const |
unsigned int | getTag () const |
void | setTag (unsigned int tag) |
const std::string | getName () const |
void | setName (const std::string name) |
const std::string | getClassName () const |
virtual std::string | toString (bool verbose=false) const |
operator std::string () const | |
const Vec2 | getPosition () const |
void | setPosition (const Vec2 &position) |
void | setPosition (float x, float y) |
float | getPositionX (void) const |
void | setPositionX (float x) |
float | getPositionY (void) const |
void | setPositionY (float y) |
Vec2 | getWorldPosition () const |
const Size | getContentSize () const |
virtual void | setContentSize (const Size size) |
virtual void | setContentSize (float width, float height) |
float | getContentWidth () const |
void | setContentWidth (float width) |
float | getContentHeight () const |
void | setContentHeight (float height) |
virtual Rect | getLayoutBounds () const |
Size | getSize () const |
float | getWidth () const |
float | getHeight () const |
Rect | getBoundingBox () const |
virtual void | setAnchor (const Vec2 anchor) |
virtual void | setAnchor (float x, float y) |
const Vec2 | getAnchor () const |
Vec2 | getAnchorInPixels () |
Color4 | getColor () const |
virtual void | setColor (Color4 color) |
Color4 | getAbsoluteColor () |
bool | isVisible () const |
void | setVisible (bool visible) |
bool | hasRelativeColor () const |
void | setRelativeColor (bool flag) |
std::shared_ptr< Scissor > | getScissor () const |
void | setScissor (const std::shared_ptr< Scissor > &scissor) |
void | setScissor () |
const Vec2 | getScale () const |
float | getScaleX () const |
float | getScaleY () const |
void | setScale (float scale) |
void | setScale (const Vec2 vec) |
void | setScale (float sx, float sy) |
float | getAngle () |
void | setAngle (float angle) |
const Affine2 & | getTransform () const |
const Affine2 & | getAlternateTransform () const |
void | setAlternateTransform (const Affine2 &transform) |
bool | withAlternateTransform () |
void | chooseAlternateTransform (bool active) |
const Affine2 & | getNodeToParentTransform () const |
Affine2 | getParentToNodeTransform () const |
Affine2 | getNodeToWorldTransform () const |
Affine2 | getWorldToNodeTransform () const |
Vec2 | screenToNodeCoords (const Vec2 screenPoint) const |
Vec2 | worldToNodeCoords (const Vec2 worldPoint) const |
Vec2 | nodeToScreenCoords (const Vec2 nodePoint) const |
Vec2 | nodeToWorldCoords (const Vec2 nodePoint) const |
Vec2 | parentToNodeCoords (const Vec2 parentPoint) const |
Vec2 | nodeToParentCoords (const Vec2 nodePoint) const |
size_t | getChildCount () const |
std::shared_ptr< SceneNode > | getChild (unsigned int pos) |
const std::shared_ptr< SceneNode > & | getChild (unsigned int pos) const |
template<typename T > | |
std::shared_ptr< T > | getChild (unsigned int pos) const |
std::shared_ptr< SceneNode > | getChildByTag (unsigned int tag) const |
template<typename T > | |
std::shared_ptr< T > | getChildByTag (unsigned int tag) const |
std::shared_ptr< SceneNode > | getChildByName (const std::string name) const |
template<typename T > | |
std::shared_ptr< T > | getChildByName (const std::string name) const |
std::vector< std::shared_ptr< SceneNode > > | getChildren () |
const std::vector< std::shared_ptr< SceneNode > > & | getChildren () const |
void | addChild (const std::shared_ptr< SceneNode > &child) |
void | addChildWithTag (const std::shared_ptr< SceneNode > &child, unsigned int tag) |
void | addChildWithName (const std::shared_ptr< SceneNode > &child, const std::string name) |
void | swapChild (const std::shared_ptr< SceneNode > &child1, const std::shared_ptr< SceneNode > &child2, bool inherit=false) |
SceneNode * | getParent () |
const SceneNode * | getParent () const |
Scene2 * | getScene () |
const Scene2 * | getScene () const |
void | removeFromParent () |
virtual void | removeChild (unsigned int pos) |
void | removeChild (const std::shared_ptr< SceneNode > &child) |
void | removeChildByTag (unsigned int tag) |
void | removeChildByName (const std::string name) |
virtual void | removeAllChildren () |
void | setPriority (float priority) |
float | getPriority () |
virtual void | render (const std::shared_ptr< SpriteBatch > &batch, const Affine2 &transform, Color4 tint) |
virtual void | render (const std::shared_ptr< SpriteBatch > &batch) |
const std::shared_ptr< Layout > & | getLayout () const |
void | setLayout (const std::shared_ptr< Layout > &layout) |
virtual void | doLayout () |
Static Public Member Functions | |
static std::shared_ptr< CanvasNode > | alloc () |
static std::shared_ptr< CanvasNode > | allocWithBounds (const Size size) |
static std::shared_ptr< CanvasNode > | allocWithBounds (float width, float height) |
static std::shared_ptr< CanvasNode > | allocWithBounds (const Rect rect) |
static std::shared_ptr< CanvasNode > | allocWithBounds (float x, float y, float width, float height) |
static std::shared_ptr< CanvasNode > | allocWithData (const Scene2Loader *loader, const std::shared_ptr< JsonValue > &data) |
Static Public Member Functions inherited from cugl::scene2::SceneNode | |
static std::shared_ptr< SceneNode > | alloc () |
static std::shared_ptr< SceneNode > | allocWithPosition (const Vec2 pos) |
static std::shared_ptr< SceneNode > | allocWithPosition (float x, float y) |
static std::shared_ptr< SceneNode > | allocWithBounds (const Size size) |
static std::shared_ptr< SceneNode > | allocWithBounds (float width, float height) |
static std::shared_ptr< SceneNode > | allocWithBounds (const Rect rect) |
static std::shared_ptr< SceneNode > | allocWithBounds (float x, float y, float width, float height) |
static std::shared_ptr< SceneNode > | allocWithData (const Scene2Loader *loader, const std::shared_ptr< JsonValue > &data) |
Protected Attributes | |
std::vector< Page * > | _canvas |
size_t | _draw |
size_t | _edit |
Protected Attributes inherited from cugl::scene2::SceneNode | |
Vec2 | _position |
Vec2 | _anchor |
Size | _contentSize |
Color4 | _tintColor |
bool | _hasParentColor |
bool | _isVisible |
std::shared_ptr< Scissor > | _scissor |
Vec2 | _scale |
float | _angle |
Affine2 | _transform |
bool | _useTransform |
Affine2 | _combined |
std::vector< std::shared_ptr< SceneNode > > | _children |
SceneNode * | _parent |
Scene2 * | _graph |
std::shared_ptr< Layout > | _layout |
int | _childOffset |
unsigned int | _tag |
std::string | _name |
size_t | _hashOfName |
std::string | _classname |
float | _priority |
std::shared_ptr< JsonValue > | _json |
This is a scene graph node to support scalable vector graphics
WARNING: This is a highly experimental class. This class is the foundation for SVG support in the future roadmap, but it still needs significant testing. Use this class at your own risk.
A canvas node is a drawing slate, not unlike the classic drawing Turtle found in most programming languages. The programmer issues a sequence of drawing commands, and these commands produce an image on the screen. The commands are stored so that the image is shown every animation frame. However, the programmer can change or erase the drawing commands at any time, thus creating arbitrary animation effects.
There are actually two ways that a programmer can use a canvas node to animate the image. One way is to erase and reissue the drawing commands every animation frame. But the other way to make use of pages. A canvas can have any number of pages. At any given time, getEditPage is the page that receives the drawing commands while getDrawPage is the page whose drawing commands are shown on the screen. This allows the user to save multiple drawings and then switch between them, just as SpriteNode does for sprite sheets.
When drawing to a canvas node, it is often useful to think of units as pixels. Indeed, if the canvas node is the size of the display and anchored in the bottom left corner, this is indeed the case. However, a canvas node can itself be transformed just like any scene graph node, including scaling and rotating.
It is important to stress that this node is designed for complex noninteractive graphics. This node does not remember the format or geometry of any shape or object drawn. This is particularly true for text, which is immediately rendered to a mesh, with all glyph information lost. If the user needs to interact with part of the image, you should use a dedicated-purpose scene graph node for that element, such as PolygonNode or Label.
The API for this node is designed to be similar to the SVG API, allowing this class to render some subset of SVG files. However, there are some important differences. Most notably, the origin of this scene graph node is, as is the case for all scene graph nodes, in the bottom left corner. This is different from an SVG file where the origin is in the top left and the y-axis increases downwards. A conversion between these two formats is currently in development and will be released at a later date.
Much of the code for canvas nodes is heavily inspired by the nanovg framework, developed by Mikko Mononen (memon). However, there are numerous optimizations and changes to make it compatible with the CUGL scene graph architecture. @ins ide.o rg
|
strong |
An enum to specify the winding rule for filled polygons
This rule specifies how to fill a polygon in the case of multiple subpaths and self-intersections. See
https://en.wikipedia.org/wiki/Nonzero-rule
for a discussion of how the default rule works.
In addition, this category includes rules for clipping and masking. That is because, due to the way canvas nodes are designed, any non-trivial use of the stencil buffer mandates an even-odd fill rule.
Enumerator | |
---|---|
NONZERO | Uses the non-zero winding rule (DEFAULT) If a stencil was previously created by the FillRule#STENCIL rule, this fill rule with erase that stencil. |
EVENODD | Uses the even-odd rule If a stencil was previously created by the FillRule#STENCIL rule, this fill rule with erase that stencil. |
STENCIL | Creates a stencil buffer with this shape via an even-odd rule. This fill rule writes to the stencil buffer but it does not draw to the screen. It is used in combination with FillRule#CLIPFILL and FillRule#MASKFILL to provide visual effects. |
CLIPFILL | Uses the even-odd rule to draw a shape clipped to the stencil buffer. This rule must be preceded by a drawing sequence using the fill rule FillRule#STENCIL to have any effect. |
MASKFILL | Uses the even-odd rule to draw a shape masked by the stencil buffer. This rule must be preceded by a drawing sequence using the fill rule FillRule#STENCIL to have any effect. |
|
strong |
An enum to allow the user to specify an explicit winding
This enum allows you to specify the winding order when creating a new path. A rule other than NONE will guarantee your path has a certain orientation even if you generate a path in the wrong order.
Enumerator | |
---|---|
NONE | Use the default, given orientation for each path |
CCW | Use a counter-clockwise orientation for each path |
CW | Use a clockwise orientation for each path |
|
inline |
Creates an uninitialized canvas node.
You must initialize this canvas node before use.
NEVER USE A CONSTRUCTOR WITH NEW. If you want to allocate a Node on the heap, use one of the static constructors instead.
|
inline |
Deletes this canvas node, disposing all resources
|
inlinestatic |
Returns a newly allocated a canvas node the size of the display.
The bounding box of the node is the current screen size. The node is anchored in the center and has position (width/2,height/2) in the parent space. The node origin is the (0,0) at the bottom left corner of the bounding box.
The canvas is initialized with only one drawing buffer. You should call paginate to add more buffers.
|
inlinestatic |
Returns a newly allocated a canvas node with the given bounds.
The rectangle origin is the bottom left corner of the node in parent space, and corresponds to the origin of the Node space. The size defines its content width and height in node space. The node anchor is placed in the bottom left corner.
The canvas is initialized with only one drawing buffer. You should call paginate to add more buffers.
rect | The bounds of the node in parent space |
|
inlinestatic |
Returns a newly allocated a canvas node with the given size.
The size defines the content size. The bounding box of the node is (0,0,width,height) and is anchored in the bottom left corner (0,0). The node is positioned at the origin in parent space.
The canvas is initialized with only one drawing buffer. You should call paginate to add more buffers.
size | The size of the node in parent space |
|
inlinestatic |
Returns a newly allocated a canvas node with the given size.
The size defines the content size. The bounding box of the node is (0,0,width,height) and is anchored in the bottom left corner (0,0). The node is positioned at the origin in parent space.
The canvas is initialized with only one drawing buffer. You should call paginate to add more buffers.
width | The width of the node in parent space |
height | The height of the node in parent space |
|
inlinestatic |
Returns a newly allocated a canvas node with the given bounds.
The rectangle origin is the bottom left corner of the node in parent space, and corresponds to the origin of the Node space. The size defines its content width and height in node space. The node anchor is placed in the bottom left corner.
The canvas is initialized with only one drawing buffer. You should call paginate to add more buffers.
x | The x-coordinate of the node origin in parent space |
y | The y-coordinate of the node origin in parent space |
width | The width of the node in parent space |
height | The height of the node in parent space |
|
inlinestatic |
Returns a newly allocated a canvas node with the given JSON specificaton.
This initializer is designed to receive the "data" object from the JSON passed to Scene2Loader. This JSON format supports the following attribute values:
"pages": A positive integer indicating the number of pages "edit": A positive integer indicating the active edit page "draw": A positive integer indicating the active draw page
All attributes are optional. There are no required attributes. There are currently no options for drawing to a canvas node in in the JSON (the canvas will start out blank). Serialized drawing commands are a feature for a future release.
loader | The scene loader passing this JSON file |
data | The JSON object specifying the node |
void cugl::scene2::CanvasNode::applyLocalScissor | ( | const std::shared_ptr< Scissor > & | scissor | ) |
Applies the given scissor to the stack.
If there is no active local scissor, this method is the same as setLocalScissor. Otherwise, this method will generate a new local scissor by calling Scissor#intersect on the previous local scisor. . The intersection will take place in the coordinate system of this scissor.
scissor | The local scissor to add |
void cugl::scene2::CanvasNode::arcTo | ( | const Vec2 | center, |
float | r, | ||
float | a0, | ||
float | a1, | ||
bool | ccw = true |
||
) |
Adds an arc segment sweeping from angle a0 to a1.
The arc center is at is at c and has radius is r. The method will draw a straight line from the previous point in the path to the point at angle a0. It will then sweep the arc from angle a0 to a1. The value ccw determines whether the arc sweeps counter clockwise or clockwise, as it is not necessarily possible to tell from the angles themselves.
If there is no current path, this method creates a new subpath starting at the point for a0. Note that this differs from other drawing commands that would start a new path at the origin. The command transform is applied to this method when called.
center | The arc center |
r | The arc radius |
a0 | The starting angle of the arc |
a1 | The ending angle of the arc |
ccw | Whether draw the arc counter clockwise |
Adds an arc segment whose corner is defined by the previous point.
The previous point acts as the center for the arc, which is drawn through the two points with the given radius.
If there is no current path, this method creates a new subpath starting at point s. Note that this differs from other drawing commands that would start a new path at the origin. The command transform is applied to this method when called.
s | The start of the arc |
e | The end of the arc |
radius | The arc radius |
|
inline |
Adds an arc segment sweeping from angle a0 to a1.
The arc center is at is at (cx,cy) and has radius is r. The method will draw a straight line from the previous point in the path to the point at angle a0. It will then sweep the arc from angle a0 to a1. The value ccw determines whether the arc sweeps counter clockwise or clockwise, as it is not necessarily possible to tell from the angles themselves.
If there is no current path, this method creates a new subpath starting at the point for a0. Note that this differs from other drawing commands that would start a new path at the origin. The command transform is applied to this method when called.
cx | The x-coordinate of the arc center |
cy | The y-coordinate of the arc center |
r | The arc radius |
a0 | The starting angle of the arc |
a1 | The ending angle of the arc |
ccw | Whether draw the arc counter clockwise |
|
inline |
Adds an arc segment whose corner is defined by the previous point.
The previous point acts as the center for the arc, which is drawn through the two points with the given radius.
If there is no current path, this method creates a new subpath starting at point (sx,sy). Note that this differs from other drawing commands that would start a new path at the origin. The command transform is applied to this method when called.
sx | The x-coordinate of the start of the arc |
sy | The y-coordinate of the start of the arc |
ex | The x-coordinate of the end of the arc |
ey | The y-coordinate of the end of the arc |
radius | The arc radius |
void cugl::scene2::CanvasNode::beginPath | ( | ) |
Clears the current path and sub-paths.
This method should be called before drawing a new path. Otherwise the commands will simply append to the existing paths.
The standard way to draw paths on a canvas is to first call this method and then call moveTo to start the path. To create a subpath (for holes or disjoint polygons) simple call moveTo again.
Adds a cubic bezier segment from the previous point.
The control points specify the tangents as described in Spline2.
If there is no current path, this method creates a new subpath starting at the origin. The command transform is applied to this method when called.
c1 | The first control point |
c2 | The second control point |
p | The end of the bezier segment |
|
inline |
Adds a cubic bezier segment from the previous point.
The control points specify the tangents as described in Spline2.
If there is no current path, this method creates a new subpath starting at the origin. The command transform is applied to this method when called.
c1x | The x-coordinate of the first control point |
c1y | The y-coordinate of the first control point |
c2x | The x-coordinate of the second control point |
c2y | The y-coordinate of the second control point |
px | The x-coordinate of the bezier end |
py | The y-coordinate of the bezier end |
void cugl::scene2::CanvasNode::clearAll | ( | ) |
Clears the drawing commands from all pages.
void cugl::scene2::CanvasNode::clearCommandTransform | ( | ) |
Resets the command transform to an identity matrix.
When this method is called all subsequent calls will be applied in the native coordinate space of the canvas node.
For more information on how this transform is applied to commands, see getCommandTransform.
void cugl::scene2::CanvasNode::clearLocalScissor | ( | ) |
Resets and disables scissoring for this canvas.
Clearing the local scissor will not reveal any commands previously clipped by the local scissor. In addition, this method has no effect on the global scissor SceneNode#getScissor.
void cugl::scene2::CanvasNode::clearPage | ( | ) |
Clears the drawing commands for the active edit page.
Any other page is uneffected. This method should be called before drawing to a page, as otherwise the commands are appended to any existing drawing commands.
void cugl::scene2::CanvasNode::closePath | ( | ) |
Closes the current subpath with a line segment.
While this method closes the subpath, it does not start a new subpath. You will need to call moveTo to do that.
|
overridevirtual |
Disposes all of the resources used by this canvas node.
A disposed node can be safely reinitialized. Any children owned by this node will be released. They will be deleted if no other object owns them.
It is unsafe to call this on a Node that is still currently inside of a scene graph.
Reimplemented from cugl::scene2::SceneNode.
|
overridevirtual |
Draws the drawing page via the given SpriteBatch.
This method only worries about drawing the current node. It does not attempt to render the children.
batch | The SpriteBatch to draw with. |
transform | The global transformation matrix. |
tint | The tint to blend with the Node color. |
Reimplemented from cugl::scene2::SceneNode.
void cugl::scene2::CanvasNode::drawArc | ( | const Vec2 | center, |
float | r, | ||
float | a0, | ||
float | a1, | ||
bool | ccw = true |
||
) |
Creates a new circle arc subpath, sweeping from angle a0 to a1.
The arc center is at is at c and has radius is r. The new subpath will start at the point corresponding to angle a0. The value ccw determines whether the arc sweeps counter clockwise or clockwise, as it is not necessarily possible to tell this from the angles themselves.
The command transform is applied to this method when called.
center | The arc center |
r | The arc radius |
a0 | The starting angle of the arc |
a1 | The ending angle of the arc |
ccw | Whether draw the arc counter clockwise |
|
inline |
Creates a new circle arc subpath, sweeping from angle a0 to a1.
The arc center is at is at (cx,cy) and has radius is r. The new subpath will start at the point corresponding to angle a0. The value ccw determines whether the arc sweeps counter clockwise or clockwise, as it is not necessarily possible to tell this from the angles themselves.
The command transform is applied to this method when called.
cx | The x-coordinate of the arc center |
cy | The y-coordinate of the arc center |
r | The arc radius |
a0 | The starting angle of the arc |
a1 | The ending angle of the arc |
ccw | Whether draw the arc counter clockwise |
|
inline |
Creates a new circle shaped sub-path.
center | The circle center |
r | The circle radius |
void cugl::scene2::CanvasNode::drawCircle | ( | float | cx, |
float | cy, | ||
float | r | ||
) |
Creates a new circle shaped sub-path.
cx | The x-coordinate of the circle center |
cy | The y-coordinate of the circle center |
r | The circle radius |
void cugl::scene2::CanvasNode::drawEllipse | ( | const Rect | bounds | ) |
Creates a new ellipse shaped subpath.
Note that the bounding rectangle defines the bottom left corner of the ellipse and not the center.
The command transform is applied to this method when called.
bounds | The rectangle bounding this ellipse |
Creates a new ellipse shaped subpath.
Note that the ellipse size defines the two diameters of the ellipse, and not the radii.
The command transform is applied to this method when called.
center | The ellipse center |
size | The ellipse size |
void cugl::scene2::CanvasNode::drawEllipse | ( | float | cx, |
float | cy, | ||
float | rx, | ||
float | ry | ||
) |
Creates a new ellipse shaped subpath.
The command transform is applied to this method when called.
cx | The x-coordinate of the ellipse center |
cy | The y-coordinate of the ellipse center |
rx | The radius along the x-axis |
ry | The radius along the y-axis |
void cugl::scene2::CanvasNode::drawRect | ( | const Rect | rect | ) |
Creates a new rectangle shaped subpath
The command transform is applied to this method when called.
rect | The rectangle bounds |
|
inline |
Creates a new rectangle shaped subpath
The command transform is applied to this method when called.
x | The x-coordinate of the rectangle origin |
y | The y-coordinate of the rectangle origin |
w | The rectangle width |
h | The rectangle height |
|
inline |
Creates a new rounded rectangle shaped subpath.
To be well-defined, the corner radius should be no larger than half the width and height (at which point it defines a capsule). Shapes with abnormally large radii are undefined.
The command transform is applied to this method when called.
rect | The rectangle bounds |
r | The corner radius |
void cugl::scene2::CanvasNode::drawRoundedRect | ( | float | x, |
float | y, | ||
float | w, | ||
float | h, | ||
float | r | ||
) |
Creates a new rounded rectangle shaped subpath.
To be well-defined, the corner radius should be no larger than half the width and height (at which point it defines a capsule). Shapes with abnormally large radii are undefined.
The command transform is applied to this method when called.
x | The x-coordinate of the rectangle origin |
y | The y-coordinate of the rectangle origin |
w | The rectangle width |
h | The rectangle height |
r | The corner radius |
|
inline |
Creates a new rounded rectangle shaped subpath with varying radii.
Each corner will have its own radii. But to be well-defined, none of the radii should be larger than half the width and height (at which point it defines a capsule). Shapes with abnormally large radii are undefined.
The command transform is applied to this method when called.
rect | The rectangle bounds |
radBL | The corner radius of the bottom left |
radTL | The corner radius of the top left |
radTR | The corner radius of the top right |
radBR | The corner radius of the bottom right |
void cugl::scene2::CanvasNode::drawRoundedRectVarying | ( | float | x, |
float | y, | ||
float | w, | ||
float | h, | ||
float | radBL, | ||
float | radTL, | ||
float | radTR, | ||
float | radBR | ||
) |
Creates a new rounded rectangle shaped subpath with varying radii.
Each corner will have its own radii. But to be well-defined, none of the radii should be larger than half the width and height (at which point it defines a capsule). Shapes with abnormally large radii are undefined.
The command transform is applied to this method when called.
x | The x-coordinate of the rectangle origin |
y | The y-coordinate of the rectangle origin |
w | The rectangle width |
h | The rectangle height |
radBL | The corner radius of the bottom left |
radTL | The corner radius of the top left |
radTR | The corner radius of the top right |
radBR | The corner radius of the bottom right |
|
inline |
Draws the text string at specified location.
Position p is the location of the text origin, which is defined by both getHorizontalTextAlign and getVerticalTextAlign. This command is subject to the current command transform.
This command will use the current text style, and color the glyphs with the current fill color. If there is a fill Paint then it will also be applied, provided that it is a gradient (text cannot be textured with images).
The C-style string substr need not be null-terminated. Instead, the termination is indicated by the parameter end. This provides efficient substring processing. The string may either be in UTF8 or ASCII; the method will handle conversion automatically.
p | The position of the text origin |
substr | The start of the string |
end | The end of the string |
|
inline |
Draws the text string at specified location.
Position p is the location of the text origin, which is defined by both getHorizontalTextAlign and getVerticalTextAlign. This command is subject to the current command transform.
This command will use the current text style, and color the glyphs with the current fill color. If there is a fill Paint then it will also be applied, provided that it is a gradient (text cannot be textured with images).
The string may either be in UTF8 or ASCII; the method will handle conversion automatically.
p | The position of the text origin |
text | The text to display |
void cugl::scene2::CanvasNode::drawText | ( | float | x, |
float | y, | ||
const char * | substr, | ||
const char * | end | ||
) |
Draws the text string at specified location.
Position (x,y) is the location of the text origin, which is defined by both getHorizontalTextAlign and getVerticalTextAlign. This command is subject to the current command transform.
This command will use the current text style, and color the glyphs with the current fill color. If there is a fill Paint then it will also be applied, provided that it is a gradient (text cannot be textured with images).
The C-style string substr need not be null-terminated. Instead, the termination is indicated by the parameter end. This provides efficient substring processing. The string may either be in UTF8 or ASCII; the method will handle conversion automatically.
x | The x-coordinate of the text origin |
y | The y-coordinate of the text origin |
substr | The start of the string |
end | The end of the string |
|
inline |
Draws the text string at specified location.
Position (x,y) is the location of the text origin, which is defined by both getHorizontalTextAlign and getVerticalTextAlign. This command is subject to the current command transform.
This command will use the current text style, and color the glyphs with the current fill color. If there is a fill Paint then it will also be applied, provided that it is a gradient (text cannot be textured with images).
The string may either be in UTF8 or ASCII; the method will handle conversion automatically.
x | The x-coordinate of the text origin |
y | The y-coordinate of the text origin |
text | The text to display |
|
inline |
Draws a multiline text string at specified location.
Position p is the location of the text origin, which is defined by both getHorizontalTextAlign and getVerticalTextAlign. This command is subject to the current command transform.
When breaking up lines, whitespace at the beginning and end of each line will be "swallowed", causing it to be ignored for purposes of alignment. The exception is at the beginning and end of a paragraph. Whitespace there will be preserved. A paragraph is defined as any piece of text separated by a newline. So the first part of the string before a newline is a paragraph, and each substring after a newline is also a paragraph.
Words longer than the max width are slit at nearest character. There is no support for hyphenation.
This command will use the current text style, and color the glyphs with the current fill color. If there is a fill Paint then it will also be applied, provided that it is a gradient (text cannot be textured with images).
The C-style string substr need not be null-terminated. Instead, the termination is indicated by the parameter end. This provides efficient substring processing. The string may either be in UTF8 or ASCII; the method will handle conversion automatically.
p | The position of the text origin |
width | The text-wrap width |
substr | The start of the string |
end | The end of the string |
|
inline |
Draws a multiline text string at specified location.
Position p is the location of the text origin, which is defined by both getHorizontalTextAlign and getVerticalTextAlign. This command is subject to the current command transform.
When breaking up lines, whitespace at the beginning and end of each line will be "swallowed", causing it to be ignored for purposes of alignment. The exception is at the beginning and end of a paragraph. Whitespace there will be preserved. A paragraph is defined as any piece of text separated by a newline. So the first part of the string before a newline is a paragraph, and each substring after a newline is also a paragraph.
Words longer than the max width are slit at nearest character. There is no support for hyphenation.
This command will use the current text style, and color the glyphs with the current fill color. If there is a fill Paint then it will also be applied, provided that it is a gradient (text cannot be textured with images).
The string may either be in UTF8 or ASCII; the method will handle conversion automatically.
p | The position of the text origin |
width | The text-wrap width |
text | The text to display |
void cugl::scene2::CanvasNode::drawTextBox | ( | float | x, |
float | y, | ||
float | width, | ||
const char * | substr, | ||
const char * | end | ||
) |
Draws a multiline text string at specified location.
Position (x,y) is the location of the text origin, which is defined by both getHorizontalTextAlign and getVerticalTextAlign. This command is subject to the current command transform.
When breaking up lines, whitespace at the beginning and end of each line will be "swallowed", causing it to be ignored for purposes of alignment. The exception is at the beginning and end of a paragraph. Whitespace there will be preserved. A paragraph is defined as any piece of text separated by a newline. So the first part of the string before a newline is a paragraph, and each substring after a newline is also a paragraph.
Words longer than the max width are slit at nearest character. There is no support for hyphenation.
This command will use the current text style, and color the glyphs with the current fill color. If there is a fill Paint then it will also be applied, provided that it is a gradient (text cannot be textured with images).
The C-style string substr need not be null-terminated. Instead, the termination is indicated by the parameter end. This provides efficient substring processing. The string may either be in UTF8 or ASCII; the method will handle conversion automatically.
x | The x-coordinate of the text origin |
y | The y-coordinate of the text origin |
width | The text-wrap width |
substr | The start of the string |
end | The end of the string |
|
inline |
Draws a multiline text string at specified location.
Position (x,y) is the location of the text origin, which is defined by both getHorizontalTextAlign and getVerticalTextAlign. This command is subject to the current command transform.
When breaking up lines, whitespace at the beginning and end of each line will be "swallowed", causing it to be ignored for purposes of alignment. The exception is at the beginning and end of a paragraph. Whitespace there will be preserved. A paragraph is defined as any piece of text separated by a newline. So the first part of the string before a newline is a paragraph, and each substring after a newline is also a paragraph.
Words longer than the max width are slit at nearest character. There is no support for hyphenation.
This command will use the current text style, and color the glyphs with the current fill color. If there is a fill Paint then it will also be applied, provided that it is a gradient (text cannot be textured with images).
The string may either be in UTF8 or ASCII; the method will handle conversion automatically.
x | The x-coordinate of the text origin |
y | The y-coordinate of the text origin |
width | The text-wrap width |
text | The text to display |
void cugl::scene2::CanvasNode::fillPaths | ( | ) |
Fills the current path (and subpaths) with the current fill style.
This method will commit the any outstanding paths, but it will not clear them. You should call beginPath to start a new path sequence.
GLenum cugl::scene2::CanvasNode::getBlendEquation | ( | ) | const |
Returns the blending equation for this canvas node
This setting is applied at the call to either strokePaths or fillPaths.
By default this value is GL_FUNC_ADD. For other options, see
https://www.opengl.org/sdk/docs/man/html/glBlendEquation.xhtml
const Affine2& cugl::scene2::CanvasNode::getCommandTransform | ( | ) |
Returns the current command transform
Transforms are applied to all paths, text, paints, and scissor regions. They are applied at the time that the are passed to the drawing API. So a translation applied after the first point in a path will skip that initial point, but apply to all subsequent points (until the command transform is changed again).
When using Paint objects, it is important to set a transform before applying them. That is because paint objects are specified in the canvas coordinate system, which is affected by the transform. If a paint object is applied to a shape in a different coordinate space then it can have unexpected effects.
The current coordinate system can be saved and restored by using the methods saveState and restoreState.
size_t cugl::scene2::CanvasNode::getDrawPage | ( | ) |
Returns the index of the current drawing page
The drawing page is the page that is shown on the screen. It does not need to be the same page as the one currently receiving drawing commands.
GLenum cugl::scene2::CanvasNode::getDstAlphaFunc | ( | ) | const |
Returns the destination blending function for the alpha component
This setting is applied at the call to either strokePaths or fillPaths.
By default this value is GL_ONE_MINUS_SRC_ALPHA, as sprite batches do not use premultiplied alpha. For other options, see
https://www.opengl.org/sdk/docs/man/html/glBlendFunc.xhtml
GLenum cugl::scene2::CanvasNode::getDstRGBFunc | ( | ) | const |
Returns the destination blending function for the RGB components
This setting is applied at the call to either strokePaths or fillPaths.
By default this value is GL_ONE_MINUS_SRC_ALPHA, as sprite batches do not use premultiplied alpha. For other options, see
https://www.opengl.org/sdk/docs/man/html/glBlendFunc.xhtml
size_t cugl::scene2::CanvasNode::getEditPage | ( | ) |
Returns the index of the current edit page
The edit page is the page that receives drawing commands. It does not need to be the same page as the one currently being drawn.
Color4 cugl::scene2::CanvasNode::getFillColor | ( | ) | const |
Returns the color to use for all filled paths
This setting is applied at a call to fillPaths.
It is possible to combine a color together with a paint. It the attribute getFillPaint is not nullptr, it will tinted by this color.
This color is also the one that will be used to render text. This value is Color4::WHITE by default.
const std::shared_ptr<Paint>& cugl::scene2::CanvasNode::getFillPaint | ( | ) | const |
Returns the paint to use for all filled paths.
This setting is applied at a call to fillPaths.
A Paint object is a user-friend gradient or texture that uses positional coordinates instead of texture coordinates. The paint will be tinted by the value getStrokeColor (which is Color4::WHITE by default).
If there is non-trivial getCommandTransform, it will be applied to the coordinates in this paint object at the time this method is called.
A fill paint will also be applied to text, assuming that it is a gradient paint. Pattern paints cannot be applied to text. If this value is nullptr, then all filled paths will have a solid color.
FillRule cugl::scene2::CanvasNode::getFillRule | ( | ) | const |
Returns the current fill rule
This setting is applied at a call to fillPaths.
By default a canvas node uses a nonzero fill rule, as described here:
https://en.wikipedia.org/wiki/Nonzero-rule
This rule allows you to put holes inside a filled path simply by reversing the winding order.
Alternate fill rules are supported, though they are all the same as the nonzero rule for simple paths. They only differ when either a path has self-intersections, or two subpaths intersect one another.
const std::shared_ptr<Font>& cugl::scene2::CanvasNode::getFont | ( | ) | const |
Returns the font for the current text style
This is the font that will be used as a call to either drawText or drawTextBox. If there is no active font when one of the those methods are called, they will fail.
float cugl::scene2::CanvasNode::getFontBlur | ( | ) | const |
Returns the blur radius of the current text style.
When blurring text, use a font with the same Font#getPadding as the blur size. This will prevent bleeding across characters in the atlas.
float cugl::scene2::CanvasNode::getFontSize | ( | ) | const |
Returns the font size of the current text style.
By default, the text style will use the point size of getFont. However, it is possible to scale the font to get a smaller (or larger) text size. With that said, it is generally better to scale down a font than to scale it up.
If this value is 0, the canvas will use the point size of the active font. This value is 0 by default.
float cugl::scene2::CanvasNode::getFringe | ( | ) | const |
Returns the antialiasing fringe for this canvas node
If this value is non-zero, any fill or stroke will be surrounded by a stroke the width of the fringe. The stroke will fade to transparent on the outside edge. This is a way of providing antialiasing that is significantly better than multisampling. Furthermore, this works on OpenGLES, which does not support multisampling.
A fringe value should be >= 0.5 to have noticeable effects. In practice, values between 1 and 2 work best. Note that this adds to the volume of the fill or stroke. Hence this value should be taken into account when drawing shapes
float cugl::scene2::CanvasNode::getGlobalAlpha | ( | ) |
Returns the transparency to apply to all rendered shapes.
The alpha should be a value 0..1. Already transparent paths will get proportionally more transparent as well.
HorizontalAlign cugl::scene2::CanvasNode::getHorizontalTextAlign | ( | ) | const |
Returns the horizontal alignment of the text.
The horizontal alignment has two meanings. First, it is the relationship of the relative alignment of multiple lines. In addition, it defines the x-coordinate origin of the text. The later is relevant even when the text layout is a single line.
See HorizontalAlign for how alignment affects the text origin.
poly2::EndCap cugl::scene2::CanvasNode::getLineCap | ( | ) |
Returns the end cap value for the stroke.
This setting is applied at a call to strokePaths.
The end cap type determines how the stroke draws the ends of the line segments at the start and end of the path. See poly2::EndCap for the description of the types.
poly2::Joint cugl::scene2::CanvasNode::getLineJoint | ( | ) |
Returns the joint value for the stroke.
The joint type determines how the stroke joins the extruded line segments together. See poly2::Joint for the description of the types.
const std::shared_ptr<Scissor>& cugl::scene2::CanvasNode::getLocalScissor | ( | ) | const |
Returns the current local scissor
The local scissor is applied any subsequent drawing commands, but not to any commands issued before the scissor was applied. This is different from SceneNode#getScissor which is applied globally to the entire scene graph node. The local scissor is transformed by the getCommandTransform at the time it is set.
If there is both a local and a global scissor, their rectangles will be intersected to produce a single scissor, using the method Scissor#intersect. The intersection will take place in the coordinate system of this scissor.
float cugl::scene2::CanvasNode::getMitreLimit | ( | ) | const |
Returns the mitre limit of the extrusion.
This setting is applied at a call to strokePaths.
The mitre limit sets how "pointy" a mitre joint is allowed to be before the algorithm switches it back to a bevel/square joint. Small angles can have very large mitre offsets that go way off-screen.
To determine whether to switch a miter to a bevel, the algorithm will take the two vectors at this joint, normalize them, and then average them. It will multiple the magnitude of that vector by the mitre limit. If that value is less than 1.0, it will switch to a bevel. By default this value is 10.0.
GLenum cugl::scene2::CanvasNode::getSrcAlphaFunc | ( | ) | const |
Returns the source blending function for the alpha component
This setting is applied at the call to either strokePaths or fillPaths.
By default this value is GL_SRC_ALPHA, as scene graphs do not use premultiplied alpha. For other options, see
https://www.opengl.org/sdk/docs/man/html/glBlendFunc.xhtml
GLenum cugl::scene2::CanvasNode::getSrcRGBFunc | ( | ) | const |
Returns the source blending function for the RGB components
This setting is applied at the call to either strokePaths or fillPaths.
By default this value is GL_SRC_ALPHA, as scene graphs do not use premultiplied alpha. For other options, see
https://www.opengl.org/sdk/docs/man/html/glBlendFunc.xhtml
Color4 cugl::scene2::CanvasNode::getStrokeColor | ( | ) | const |
Returns the color to use for all stroked paths
This setting is applied at a call to strokePaths.
It is possible to combine a color together with a paint. It the attribute getStrokePaint is not nullptr, it will tinted by this color.
This value is Color4::WHITE by default.
const std::shared_ptr<Paint>& cugl::scene2::CanvasNode::getStrokePaint | ( | ) | const |
Returns the paint to use for all stroked paths.
This setting is applied at a call to strokePaths.
A Paint object is a user-friend gradient or texture that uses positional coordinates instead of texture coordinates. The paint will be tinted by the value getStrokeColor (which is Color4::WHITE by default).
If there is non-trivial getCommandTransform, it will be applied to the coordinates in this paint object at the time this method is called.
If this value is nullptr, then all strokes will have a solid color.
float cugl::scene2::CanvasNode::getStrokeWidth | ( | ) | const |
Returns the width of the stroke style.
This setting is applied at a call to strokePaths.
If the value of getFringe is not zero, this will be subtracted from the stroke width when extruding the path. The default stroke width is 2.
float cugl::scene2::CanvasNode::getTextSpacing | ( | ) | const |
Returns the line spacing of the current text style.
This value is multiplied by the font size to determine the space between lines. So a value of 1 is single-spaced text, while a value of 2 is double spaced. The value should be positive.
VerticalAlign cugl::scene2::CanvasNode::getVerticalTextAlign | ( | ) | const |
Returns the vertical alignment of the text.
The vertical alignment defines the y-coordinate origin of this text layout. In the case of multiple lines, the alignment is (often) with respect to the entire block of text, not just the first line.
See VerticalAlign for how alignment affects the text origin.
Winding cugl::scene2::CanvasNode::getWinding | ( | ) | const |
Returns the current winding order
As a general rule, solid shapes should have a counter clockwise winding, and holes should have a clockwise winding. This property allows you to specify the winding order to use, even if you generate the path in the wrong order. Hence, if this attribute is CCW, your paths will all be counter clockwise even if the drawing commands generate them clockwise.
By default this value is None, which means that paths use their native winding order.
The winding order is applied to a subpath when it is committed. A subpath is committed at a subsequent call to moveTo or a call to either fillPaths or strokePaths.
|
overridevirtual |
Initializes a canvas node the size of the display.
The bounding box of the node is the current screen size. The node is anchored in the center and has position (width/2,height/2) in the parent space. The node origin is the (0,0) at the bottom left corner of the bounding box.
The canvas is initialized with only one drawing buffer. You should call paginate to add more buffers.
Reimplemented from cugl::scene2::SceneNode.
|
overridevirtual |
Initializes a canvas node with the given bounds.
The rectangle origin is the bottom left corner of the node in parent space, and corresponds to the origin of the Node space. The size defines its content width and height in node space. The node anchor is placed in the bottom left corner.
The canvas is initialized with only one drawing buffer. You should call paginate to add more buffers.
rect | The bounds of the node in parent space |
Reimplemented from cugl::scene2::SceneNode.
|
overridevirtual |
Initializes a canvas node with the given size.
The size defines the content size. The bounding box of the node is (0,0,width,height) and is anchored in the bottom left corner (0,0). The node is positioned at the origin in parent space.
The canvas is initialized with only one drawing buffer. You should call paginate to add more buffers.
size | The size of the node in parent space |
Reimplemented from cugl::scene2::SceneNode.
|
inlineoverridevirtual |
Initializes a canvas node with the given size.
The size defines the content size. The bounding box of the node is (0,0,width,height) and is anchored in the bottom left corner (0,0). The node is positioned at the origin in parent space.
The canvas is initialized with only one drawing buffer. You should call paginate to add more buffers.
width | The width of the node in parent space |
height | The height of the node in parent space |
Reimplemented from cugl::scene2::SceneNode.
|
inlineoverridevirtual |
Initializes a canvas node with the given bounds.
The rectangle origin is the bottom left corner of the node in parent space, and corresponds to the origin of the Node space. The size defines its content width and height in node space. The node anchor is placed in the bottom left corner.
The canvas is initialized with only one drawing buffer. You should call paginate to add more buffers.
x | The x-coordinate of the node origin in parent space |
y | The y-coordinate of the node origin in parent space |
width | The width of the node in parent space |
height | The height of the node in parent space |
Reimplemented from cugl::scene2::SceneNode.
|
overridevirtual |
Initializes a canvas node with the given JSON specificaton.
This initializer is designed to receive the "data" object from the JSON passed to Scene2Loader. This JSON format supports the following attribute values:
"pages": A positive integer indicating the number of pages "edit": A positive integer indicating the active edit page "draw": A positive integer indicating the active draw page
All attributes are optional. There are no required attributes. There are currently no options for drawing to a canvas node in in the JSON (the canvas will start out blank). Serialized drawing commands are a feature for a future release.
loader | The scene loader passing this JSON file |
data | The JSON object specifying the node |
Reimplemented from cugl::scene2::SceneNode.
void cugl::scene2::CanvasNode::lineTo | ( | const Vec2 | pos | ) |
Adds a line segment from the previous point to the given one.
If there is no current path, this method creates a new subpath starting at the origin. The command transform is applied to this method when called.
pos | The next path point |
|
inline |
Adds a line segment from the previous point to the given one.
If there is no current path, this method creates a new subpath starting at the origin. The command transform is applied to this method when called.
x | The x-coordinate of the next path point |
y | The y-coordinate of the next path point |
void cugl::scene2::CanvasNode::moveTo | ( | const Vec2 | pos | ) |
Starts a new sub-path with specified point as first point.
The command transform is applied to this method when called.
pos | The initial path point |
|
inline |
Starts a new sub-path with specified point as first point.
The command transform is applied to this method when called.
x | The x-coordinate of the initial path point |
y | The y-coordinate of the initial path point |
size_t cugl::scene2::CanvasNode::pages | ( | ) | const |
Returns the number of pages in this canvas node.
Each page is capable of storing its own set of drawing commands. Flipping through pages is an efficient way to animate a canvas node.
By default a canvas node has only one page.
void cugl::scene2::CanvasNode::paginate | ( | size_t | size | ) |
Resizes the canvas node to support the given number of pages
Each page is capable of storing its own set of drawing commands. Flipping through pages is an efficient way to animate a canvas node.
When repaginating a canvas, all pages with indices less than size are preserved. Any pages with indices exceeding size are discarded.
size | The number of pages for this canvas node |
Adds a quadratic bezier segment from the previous point.
The control point is as described in Spline2#addQuad.
If there is no current path, this method creates a new subpath starting at the origin. The command transform is applied to this method when called.
c | The control point |
p | The end of the bezier segment |
|
inline |
Adds a quadratic bezier segment from the previous point.
The control point is as described in Spline2#addQuad.
If there is no current path, this method creates a new subpath starting at the origin. The command transform is applied to this method when called.
cx | The x-coordinate of the control point |
cy | The y-coordinate of the control point |
px | The x-coordinate of the bezier end |
py | The y-coordinate of the bezier end |
void cugl::scene2::CanvasNode::resetState | ( | ) |
Resets current render state to default values.
This option does not affect the render state stack. Any states that were previously saved are preserved.
Note that state is local to a canvas page. Changing the current getEditPage will also change the render state to the one for that page. This happens without any loss to the state of the original page.
void cugl::scene2::CanvasNode::restoreState | ( | ) |
Pops and restores current render state.
The state which represents how text and paths will be rendered. It contains local transforms, fill and stroke styles, text and font styles, and scissor clipping regions.
Note that state is local to a canvas page. Changing the current getEditPage will also change the render state to the one for that page. This happens without any loss to the state of the original page.
If the state was not previously saved with a call to saveState, then this method will restore all options to their defaults.
void cugl::scene2::CanvasNode::rotateCommands | ( | float | angle | ) |
Rotates all commands by the given angle.
The angle is specified in radians, and specifies a rotation about the origin. This rotation is cumulative with the existing command transform. It is applied after the existing transform operations.
For more information on how this transform is applied to commands, see getCommandTransform.
angle | The rotation angle in radians |
void cugl::scene2::CanvasNode::saveState | ( | ) |
Pushes and saves the current render state on to a state stack.
The state which represents how text and paths will be rendered. It contains local transforms, fill and stroke styles, text and font styles, and scissor clipping regions.
Note that state is local to a canvas page. Changing the current getEditPage will also change the render state to the one for that page. This happens without any loss to the state of the original page.
After the state is saved, a matching call to restoreState must be used to restore the state.
|
inline |
Scales all commands by the given factor.
This resizing operation is cumulative with the existing command transform. It is applied after the existing transform operations.
For more information on how this transform is applied to commands, see getCommandTransform.
s | The scaling factor |
void cugl::scene2::CanvasNode::scaleCommands | ( | float | sx, |
float | sy | ||
) |
Scales all commands by the given factor.
This resizing operation is cumulative with the existing command transform. It is applied after the existing transform operations.
For more information on how this transform is applied to commands, see getCommandTransform.
sx | The x-axis scaling factor |
sy | The y-axis scaling factor |
void cugl::scene2::CanvasNode::setBlendEquation | ( | GLenum | equation | ) |
Sets the blending equation for this canvas node.
This setting is applied at the call to either strokePaths or fillPaths.
The enum must be a standard ones supported by OpenGL. See
https://www.opengl.org/sdk/docs/man/html/glBlendEquation.xhtml
However, this setter does not do any error checking to verify that the input is valid. By default, the equation is GL_FUNC_ADD.
equation | The blending equation for this canvas node |
void cugl::scene2::CanvasNode::setCommandTransform | ( | const Affine2 & | transform | ) |
Sets the current command transform
Transforms are applied to all paths, text, paints, and scissor regions. They are applied at the time that the are passed to the drawing API. So a translation applied after the first point in a path will skip that initial point, but apply to all subsequent points (until the command transform is changed again).
When using Paint objects, it is important to set a transform before applying them. That is because paint objects are specified in the canvas coordinate system, which is affected by the transform. If a paint object is applied to a shape in a different coordinate space then it can have unexpected effects.
The current coordinate system can be saved and restored by using the methods saveState and restoreState.
transform | The current command transform |
void cugl::scene2::CanvasNode::setDrawPage | ( | size_t | page | ) |
Sets the index of the current drawing page
The drawing page is the page that is shown on the screen. It does not need to be the same page as the one currently receiving drawing commands.
If this index is higher than the number of pages, this canvas will paginate to support the request.
page | The index of the current drawing page |
void cugl::scene2::CanvasNode::setDstBlendFunc | ( | GLenum | dstRGB, |
GLenum | dstAlpha | ||
) |
Sets the blending functions for the destination color
This setting is applied at the call to either strokePaths or fillPaths.
The enums are the standard ones supported by OpenGL. See
https://www.opengl.org/sdk/docs/man/html/glBlendFunc.xhtml
This version of the function allows you to specify different blending fuctions for the RGB and alpha components of the destiniation color. This setter does not do any error checking to verify that the enums are valid.
By default both values are GL_ONE_MINUS_SRC_ALPHA, as scene graphs do not use premultiplied alpha.
dstRGB | The blend function for the destination RGB components |
dstAlpha | The blend function for the destination alpha component |
|
inline |
Sets the blending function for the destination color
This setting is applied at the call to either strokePaths or fillPaths.
The enums are the standard ones supported by OpenGL. See
https://www.opengl.org/sdk/docs/man/html/glBlendFunc.xhtml
However, this setter does not do any error checking to verify that the enums are valid.
By default this value is GL_ONE_MINUS_SRC_ALPHA, as scene graphs do not use premultiplied alpha.
func | Specifies how the source color is blended |
void cugl::scene2::CanvasNode::setEditPage | ( | size_t | page | ) |
Sets the index of the current edit page
The edit page is the page that receives drawing commands. It does not need to be the same page as the one currently being drawn.
If this index is higher than the number of pages, this canvas will paginate to support the request.
page | The index of the current edit page |
void cugl::scene2::CanvasNode::setFillColor | ( | Color4 | color | ) |
Sets the color to use for all filled paths
This setting is applied at a call to fillPaths.
It is possible to combine a color together with a paint. It the attribute getFillPaint is not nullptr, it will tinted by this color.
This color is also the one that will be used to render text. This value is Color4::WHITE by default.
color | The color to use for all filled paths |
void cugl::scene2::CanvasNode::setFillPaint | ( | const std::shared_ptr< Paint > & | paint | ) |
Sets the paint to use for all filled paths.
This setting is applied at a call to fillPaths.
A Paint object is a user-friend gradient or texture that uses positional coordinates instead of texture coordinates. The paint will be tinted by the value getStrokeColor (which is Color4::WHITE by default).
If there is non-trivial getCommandTransform, it will be applied to the coordinates in this paint object at the time this method is called.
A fill paint will also be applied to text, assuming that it is a gradient paint. Pattern paints cannot be applied to text. If this value is nullptr, then all filled paths will have a solid color.
paint | The paint to use for all filled paths |
void cugl::scene2::CanvasNode::setFillRule | ( | FillRule | rule | ) |
Sets the current fill rule
This setting is applied at a call to fillPaths.
By default a canvas node uses a nonzero fill rule, as described here:
https://en.wikipedia.org/wiki/Nonzero-rule
This rule allows you to put holes inside a filled path simply by reversing the winding order.
Alternate fill rules are supported, though they are all the same as the nonzero rule for simple paths. They only differ when either a path has self-intersections, or two subpaths intersect one another.
rule | The current fill rule |
void cugl::scene2::CanvasNode::setFont | ( | const std::shared_ptr< Font > & | font | ) |
Sets the font for the current text style
This is the font that will be used as a call to either drawText or drawTextBox. If there is no active font when one of the those methods are called, they will fail.
font | The font for the current text style |
void cugl::scene2::CanvasNode::setFontBlur | ( | float | blur | ) |
Sets the blur radius of the current text style.
When blurring text, use a font with the same Font#getPadding as the blur size. This will prevent bleeding across characters in the atlas.
blur | The blur radius of the current text style. |
void cugl::scene2::CanvasNode::setFontSize | ( | float | size | ) |
Sets the font size of the current text style.
By default, the text style will use the point size of getFont. However, it is possible to scale the font to get a smaller (or larger) text size. With that said, it is generally better to scale down a font than to scale it up.
If this value is 0, the canvas will use the point size of the active font. This value is 0 by default.
size | The font size of the current text style. |
void cugl::scene2::CanvasNode::setFringe | ( | float | fringe | ) |
Sets the antialiasing fringe for this canvas node
If this value is non-zero, any fill or stroke will be surrounded by a stroke the width of the fringe. The stroke will fade to transparent on the outside edge. This is a way of providing antialiasing that is significantly better than multisampling. Furthermore, this works on OpenGLES, which does not support multisampling.
A fringe value should be >= 0.5 to have noticeable effects. In practice, values between 1 and 2 work best. Note that this adds to the volume of the fill or stroke. Hence this value should be taken into account when drawing shapes
fringe | The antialiasing fringe for this canvas node |
void cugl::scene2::CanvasNode::setGlobalAlpha | ( | float | alpha | ) |
Sets the transparency to apply to all rendered shapes.
The alpha should be a value 0..1. Already transparent paths will get proportionally more transparent as well.
alpha | The transparency to apply to all rendered shapes. |
void cugl::scene2::CanvasNode::setHorizontalTextAlign | ( | HorizontalAlign | align | ) |
Sets the horizontal alignment of the text.
The horizontal alignment has two meanings. First, it is the relationship of the relative alignment of multiple lines. In addition, it defines the x-coordinate origin of the text. The later is relevant even when the text layout is a single line.
See HorizontalAlign for how alignment affects the text origin.
align | The horizontal alignment of the text. |
void cugl::scene2::CanvasNode::setLineCap | ( | poly2::EndCap | cap | ) |
Sets the end cap value for the stroke.
This setting is applied at a call to strokePaths.
The end cap type determines how the stroke draws the ends of the line segments at the start and end of the path. See poly2::EndCap for the description of the types.
cap | The end cap value for the stroke. |
void cugl::scene2::CanvasNode::setLineJoint | ( | poly2::Joint | joint | ) |
Sets the joint value for the stroke.
The joint type determines how the stroke joins the extruded line segments together. See poly2::Joint for the description of the types.
joint | The joint value for the stroke. |
void cugl::scene2::CanvasNode::setLocalScissor | ( | const std::shared_ptr< Scissor > & | scissor | ) |
Sets the current local scissor
The local scissor is applied any subsequent drawing commands, but not to any commands issued before the scissor was applied. This is different from SceneNode#getScissor which is applied globally to the entire scene graph node. The local scissor is transformed by the getCommandTransform at the time it is set.
If there is both a local and a global scissor, their rectangles will be intersected to produce a single scissor, using the method Scissor#intersect. The intersection will take place in the coordinate system of this scissor.
scissor | The current local scissor |
void cugl::scene2::CanvasNode::setMitreLimit | ( | float | limit | ) |
Sets the mitre limit of the extrusion.
This setting is applied at a call to strokePaths.
The mitre limit sets how "pointy" a mitre joint is allowed to be before the algorithm switches it back to a bevel/square joint. Small angles can have very large mitre offsets that go way off-screen.
To determine whether to switch a miter to a bevel, the algorithm will take the two vectors at this joint, normalize them, and then average them. It will multiple the magnitude of that vector by the mitre limit. If that value is less than 1.0, it will switch to a bevel. By default this value is 10.0.
limit | The mitre limit for joint calculations |
|
inline |
Sets the blending function for the source color
This setting is applied at the call to either strokePaths or fillPaths.
The enums are the standard ones supported by OpenGL. See
https://www.opengl.org/sdk/docs/man/html/glBlendFunc.xhtml
However, this setter does not do any error checking to verify that the enums are valid.
By default this value is GL_SRC_ALPHA, as scene graphs do not use premultiplied alpha.
func | Specifies how the source color is blended |
void cugl::scene2::CanvasNode::setSrcBlendFunc | ( | GLenum | srcRGB, |
GLenum | srcAlpha | ||
) |
Sets the blending functions for the source color
This setting is applied at the call to either strokePaths or fillPaths.
The enums are the standard ones supported by OpenGL. See
https://www.opengl.org/sdk/docs/man/html/glBlendFunc.xhtml
This version of the function allows you to specify different blending fuctions for the RGB and alpha components of the source color. This setter does not do any error checking to verify that the enums are valid.
By default both values are GL_SRC_ALPHA, as scene graphs do not use premultiplied alpha.
srcRGB | The blend function for the source RGB components |
srcAlpha | The blend function for the source alpha component |
void cugl::scene2::CanvasNode::setStrokeColor | ( | Color4 | color | ) |
Sets the color to use for all stroked paths
This setting is applied at a call to strokePaths.
It is possible to combine a color together with a paint. It the attribute getStrokePaint is not nullptr, it will tinted by this color.
This value is Color4::WHITE by default.
color | The color to use for all stroked paths |
void cugl::scene2::CanvasNode::setStrokePaint | ( | const std::shared_ptr< Paint > & | paint | ) |
Sets the paint to use for all stroked paths.
This setting is applied at a call to strokePaths.
A Paint object is a user-friend gradient or texture that uses positional coordinates instead of texture coordinates. The paint will be tinted by the value getStrokeColor (which is Color4::WHITE by default).
If there is non-trivial getCommandTransform, it will be applied to the coordinates in this paint object at the time this method is called.
If this value is nullptr, then all strokes will have a solid color.
paint | The paint to use for all stroked paths |
void cugl::scene2::CanvasNode::setStrokeWidth | ( | float | width | ) |
Sets the width of the stroke style.
This setting is applied at a call to strokePaths.
If the value of getFringe is not zero, this will be subtracted from the stroke width when extruding the path. The default stroke width is 2.
width | The width of the stroke style. |
void cugl::scene2::CanvasNode::setTextSpacing | ( | float | spacing | ) |
Sets the line spacing of the current text style.
This value is multiplied by the font size to determine the space between lines. So a value of 1 is single-spaced text, while a value of 2 is double spaced. The value should be positive.
spacing | The line spacing of the current text style. |
void cugl::scene2::CanvasNode::setVerticalTextAlign | ( | VerticalAlign | align | ) |
Sets the vertical alignment of the text.
The vertical alignment defines the y-coordinate origin of this text layout. In the case of multiple lines, the alignment is (often) with respect to the entire block of text, not just the first line.
See VerticalAlign for how alignment affects the text origin.
align | The vertical alignment of the text. |
void cugl::scene2::CanvasNode::setWinding | ( | Winding | winding | ) |
Sets the current winding order
As a general rule, solid shapes should have a counter clockwise winding, and holes should have a clockwise winding. This setting allows you to specify the winding order to use, even if you generate the path in the wrong order. Hence, if this setting is CCW, your paths will all be counter clockwise even if the drawing commands generate them clockwise.
By default this value is None, which means that paths use their native winding order.
The winding order is applied to a subpath when it is committed. A subpath is committed at a subsequent call to moveTo or a call to either fillPaths or strokePaths.
winding | The current winding order |
void cugl::scene2::CanvasNode::skewXCommands | ( | float | angle | ) |
Skews all commands along x-axis.
A skew is a shear with the given angle is specified in radians. This shear is cumulative with the existing command transform. It is applied after the existing transform operations.
For more information on how this transform is applied to commands, see getCommandTransform.
angle | The skew angle in radians |
void cugl::scene2::CanvasNode::skewYCommands | ( | float | angle | ) |
Skews all commands along y-axis.
A skew is a shear with the given angle is specified in radians. This shear is cumulative with the existing command transform. It is applied after the existing transform operations.
For more information on how this transform is applied to commands, see getCommandTransform.
angle | The skew angle in radians |
void cugl::scene2::CanvasNode::strokePaths | ( | ) |
Extrudes the current path (and subpaths) with the current stroke style.
This method will commit the any outstanding paths, but it will not clear them. You should call beginPath to start a new path sequence.
|
inline |
Translates all commands by the given offset.
This translation is cumulative with the existing command transform. It is applied after the existing transform operations.
For more information on how this transform is applied to commands, see getCommandTransform.
p | The translation offset |
void cugl::scene2::CanvasNode::translateCommands | ( | float | x, |
float | y | ||
) |
Translates all commands by the given offset.
This translation is cumulative with the existing command transform. It is applied after the existing transform operations.
For more information on how this transform is applied to commands, see getCommandTransform.
x | The translation x-offset |
y | The translation y-offset |
|
protected |
The individual canvases of this node
|
protected |
The active page for drawing
|
protected |
The active page for editing