Manages the scene graph for a collection of vectors.

The VectorScene class acts as a container and control point for the management of vector definitions. Its main purpose is to draw the scene to a target Bitmap or Surface provided by the client.

Vector scenes are created by initialising multiple Vector objects such as VectorPath and VectorViewport and positioning them within a vector tree. The VectorScene must lie at the root of the tree.

The default mode of operation is for scenes to be manually drawn, for which the client must set the target Bitmap and call the Draw() action as required. Automated drawing can be enabled by setting the target Surface prior to initialisation. In automated mode the PageWidth and PageHeight will reflect the dimensions of the target surface at all times.

Vector definitions can be saved and loaded from permanent storage by using the SVG class.

Structure

The VectorScene class consists of the following fields:

Access
NameTypeComment
  Bitmap*BitmapTarget bitmap for drawing vectors.

The target bitmap to use when drawing the vectors must be specified here.

  FlagsVPFOptional flags.
NameDescription
VPF::BITMAP_SIZEDAutomatically adjust the VectorScene⇒PageWidth and VectorScene⇒PageHeight to match the target Bitmap⇒Width and Bitmap⇒Height.
VPF::OUTLINE_VIEWPORTSDraw a green outline around all viewport paths. Extremely useful for debugging layout issues.
VPF::RENDER_TIMECompute the drawing frame-rate for the RenderTime field.
VPF::RESIZEThe vector will be stretched to fit the VectorScene⇒PageWidth and VectorScene⇒PageHeight values, if defined by the client.
  HostScene*VectorSceneRefers to a top-level VectorScene object, if applicable.

Set HostScene to another VectorScene object if it is intended that this scene is a child of the other. This allows some traits such as vector definitions to be automatically inherited from the host scene.

This feature is useful in circumstances where a hidden group of vectors need to be managed separately, while retaining access to established definitions and vectors in the main.

  PageHeightINTThe height of the page that contains the vector.

This value defines the pixel height of the page that contains the vector scene graph. If the RESIZE Flags option is used then the viewport will be scaled to fit within the page.

  PageWidthINTThe width of the page that contains the vector.

This value defines the pixel width of the page that contains the vector scene graph. If the RESIZE Flags option is used then the viewport will be scaled to fit within the page.

  RenderTimeBIGINTReturns the rendering time of the last scene.

RenderTime returns the rendering time of the last scene that was drawn, measured in microseconds. This value can also be used to compute frames-per-second with 1000000 / RenderTime.

The RENDER_TIME flag should also be set before fetching this value, as it is required to enable the timing feature. If RENDER_TIME is not set, it will be set automatically so that subsequent calls succeed correctly.

  SampleMethodVSMThe sampling method to use when interpolating images and patterns.

The SampleMethod controls the sampling algorithm that is used when images and patterns in the vector definition are affected by rotate, skew and scale transforms. The choice of method will have a significant impact on the speed and quality of the images that are displayed in the rendered scene. The recommended default is BILINEAR, which provides a comparatively average result and execution speed. The most advanced method is BLACKMAN8, which produces an excellent level of quality at the cost of very poor execution speed.

NameDescription
VSM::AUTOThe default option is chosen by the system. This will typically be BILINEAR, but slow machines may switch to nearest neighbour and high speed machines could use more advanced methods.
VSM::BESSEL
VSM::BICUBICProduces a similar result to BILINEAR with a marginally sharper after-effect.
VSM::BILINEARBilinear is a common algorithm that produces a reasonable quality image quickly.
VSM::BLACKMAN3Five times slower than BILINEAR, the final result will lack sharpness when compared to SINC3.
VSM::BLACKMAN815 times slower than BILINEAR, the final result is of excellent quality and sharpness is well balanced.
VSM::GAUSSIAN
VSM::KAISER
VSM::LANCZOS3This well known algorithm may serve as a point of comparison for evaluating the results of other methods. It shares characteristics with SINC and BLACKMAN.
VSM::LANCZOS8
VSM::MITCHELL
VSM::NEIGHBOURNearest neighbour is the fastest sampler at the cost of poor quality.
VSM::QUADRIC
VSM::SINC3Five times slower than BILINEAR, the final result is of very good quality.
VSM::SINC815 times slower than BILINEAR, the final result is of excellent quality but may be marginally over-sharpened.
VSM::SPLINE16About half the speed of BILINEAR, this method produces a considerably better result.
  SurfaceOBJECTIDMay refer to a Surface object for enabling automatic rendering.

Setting the Surface field will enable automatic rendering to a display Surface. The use of features such as input event handling and user focus management will also require an associated surface as a pre-requisite.

  Viewport*VectorViewportReferences the first object in the scene, which must be a VectorViewport object.

The first object in the vector scene is referenced here. It must belong to the VectorViewport class, which will be used to define the size and location of the area rendered by the scene.

The Viewport value cannot be set by the client. It will be automatically defined when the first VectorViewport owned by the VectorScene is initialised.

Actions

The following actions are currently supported:

DrawRenders the scene to a bitmap.
ERR acDraw(*Object, DOUBLE X, DOUBLE Y, DOUBLE Width, DOUBLE Height)
ParameterDescription
XThe X position of the region to be drawn.
YThe Y position of the region to be drawn.
WidthThe width of the region to be drawn.
HeightThe height of the region to be drawn.

The Draw action will render the scene to the target Bitmap immediately. If Bitmap is NULL, an error will be returned.

In addition, the RenderTime field will be updated if the RENDER_TIME flag is defined.

Error Codes
OkayOperation successful.
FieldNotSetThe Bitmap field is NULL.
FlushFlush buffered data from an object.
RedimensionRedefines the size of the page.
ERR acRedimension(*Object, DOUBLE X, DOUBLE Y, DOUBLE Z, DOUBLE Width, DOUBLE Height, DOUBLE Depth)
ParameterDescription
XThe new X position to apply to the target object.
YThe new Y position to apply to the target object.
ZThe new Z position to apply to the target object.
WidthThe new width of the target object.
HeightThe new height of the target object.
DepthThe new depth of the target object.
ResetClears all registered definitions and resets field values. Child vectors are unmodified.
ResizeRedefines the size of the page.
ERR acResize(*Object, DOUBLE Width, DOUBLE Height, DOUBLE Depth)
ParameterDescription
WidthThe new width of the object.
HeightThe new height of the object.
DepthThe new depth of the object.

Methods

The following methods are currently supported:

AddDefRegisters a named definition object within a scene graph.
ERR sc::AddDef(OBJECTPTR Object, CSTRING Name, OBJECTPTR Def)
ParameterDescription
NameThe unique name to associate with the definition.
DefReference to the definition object.

This method will add a new definition object to the root of a vector tree and gives it a name. This feature is provided to support SVG style referencing for features such as gradients, images and patterns. By providing a name with the definition object, the object can then be referenced in URL strings.

For example, if creating a gradient with a name of redGradient it would be possible to reference it with url(#redGradient) in common graphics attributes such as fill and stroke.

At the time of writing, the provided object must belong to one of the following classes to be valid: Vector, VectorScene, VectorGradient, VectorImage, VectorPath, VectorPattern, VectorFilter, VectorTransition, VectorClip.

Error Codes
OkayOperation successful.
UnsupportedOwnerThe definition is not owned by the scene.
ResourceExistsThe given name is already in use as a definition.
NullArgsFunction call missing argument value(s)
InvalidObjectThe definition is not an accepted object class.
DebugInternal functionality for debugging.
ERR sc::Debug(OBJECTPTR Object)

This internal method prints comprehensive information that describes the scene graph to the log.

Error Codes
OkayOperation successful.
FindDefSearch for a vector definition by name.
ERR sc::FindDef(OBJECTPTR Object, CSTRING Name, OBJECTPTR * Def)
ParameterDescription
NameThe name of the definition.
DefA pointer to the definition object is returned here if discovered.

Use the FindDef method to search for a vector definition by name. A reference to the definition will be returned if the search is successful.

Definitions are created with the AddDef() method.

Error Codes
OkayOperation successful.
SearchA definition with the given Name was not found.
NullArgsFunction call missing argument value(s)
SearchByIDSearch for a vector by numeric ID.
ERR sc::SearchByID(OBJECTPTR Object, LONG ID, OBJECTPTR * Result)
ParameterDescription
IDThe ID to search for.
ResultThis parameter will be updated with the discovered vector, or NULL if not found.

This method will search a scene for an object that matches a given ID (vector ID's can be set with the Vector⇒NumericID or Vector⇒ID fields). If multiple vectors are using the same ID, repeated calls can be made to this method to find them all. This is achieved by calling this method on the vector that was last returned as a Result.

Note that searching for string-based ID's is achieved by converting the string to a case-sensitive hash with strhash() and using that as the ID.

Error Codes
OkayOperation successful.
SearchA vector with a matching ID was not found.
NullArgsFunction call missing argument value(s)