Package com.anylogic.engine.presentation
- java.lang.Object
- com.anylogic.engine.presentation.Shape
- com.anylogic.engine.presentation.ShapeCanvas
- All Implemented Interfaces:
com.anylogic.engine.internal.Child
,Locatable2D
,AggregatableAnimationElement
,HasLevel
,LevelElement
,SVGElement
,Serializable
,Cloneable
public class ShapeCanvas extends Shape
A raster image whose pixels can be modified dynamically at runtime.
Maps directly to HTML5 canvas element and exposes a part of its API.
In contrast with vector graphics, any shapes drawn on the canvas become
a part of a raster image and cannot be accessed afterwards.
After creation (and after clearing), the canvas is transparent.
- Author:
- AnyLogic North America, LLC https://anylogic.com
- See Also:
- Serialized Form
Constructor | Description |
---|---|
ShapeCanvas |
Constructs a canvas with specific attributes.
|
ShapeCanvas |
Constructs a canvas with given width and height, public visibility,
x and y coordinates and rotation set to 0.
|
Modifier and Type | Method | Description |
---|---|---|
void | clear() |
Clears the whole canvas (makes it fully transparent).
|
void | clearRectangle |
Clears a rectangle on the canvas (makes it fully transparent)
|
boolean | contains |
Tests if the canvas contains the point with the given coordinates
|
void | fillCircle |
Fills a circle with the given color on the canvas, preserving transparency
|
void | fillRectangle |
Fills a rectangle with the given color on the canvas, preserving transparency
|
double | getHeight() |
Returns the height of the canvas.
|
double | getWidth() |
Returns the width of the canvas.
|
void | postSVGShapeSpecificAttributes |
Posts general properties specific to a particular shape class.
|
void | setGlobalCompositeOperation |
Sets the type of composing operation to apply when drawing new shapes,
where type is a string identifying which of the composing or blending mode
operations to use.
|
void | setHeight |
Sets the height of the canvas.
|
void | setSize |
Sets the width and height of the canvas.
|
void | setWidth |
Sets the width of the canvas.
|
canHandleClick, clone, executeUserAction, findSVGElement, getDrawMode, getGroup, getLevel, getName, getPresentable, getRotation, getScaleX, getScaleY, getSVGId, getX, getY, isJava2DSwingPresentation, isPublic_xjal, isSVGPresentation, isVisible, onAggregatorVisibilityChanged, onClick, randomPointInside, randomPointInside, removeSVGFromOwner, removeSVGImage, resetSVGState, restoreOwner, setLevel, setPos, setPos, setPublic_xjal, setRotation, setScale, setScale, setScaleX, setScaleY, setVisible, setX, setY, updateDynamicProperties, updateDynamicPropertiesStructural, updateSVGProperties
public ShapeCanvas(double width, double height)
Constructs a canvas with given width and height, public visibility,
x and y coordinates and rotation set to 0.
- Parameters:
width
- the width of the canvasheight
- the height of the canvas
public ShapeCanvas(boolean ispublic, double x, double y, double rotation, double width, double height)
Constructs a canvas with specific attributes.
- Parameters:
ispublic
- iftrue
, the shape is visible on container's presentationx
- the x coordinate of the canvas upper left cornery
- the y coordinate of the canvas upper left cornerrotation
- the rotation of the canvas around Z-axis from +X to +Y, in radianswidth
- the width of the canvasheight
- the height of the canvas
public double getWidth()
Returns the width of the canvas.
- Returns:
- the width of the canvas
public void setWidth(double width)
Sets the width of the canvas.
- Parameters:
width
- the new width of the canvas
public double getHeight()
Returns the height of the canvas.
- Returns:
- the height of the canvas
public void setHeight(double height)
Sets the height of the canvas.
- Parameters:
height
- the new height of the canvas
public void setSize(double width, double height)
Sets the width and height of the canvas.
- Parameters:
width
- the new width of the canvasheight
- the new height of the canvas
public boolean contains(double px, double py)
Tests if the canvas contains the point with the given coordinates
public void setGlobalCompositeOperation(String type)
Sets the type of composing operation to apply when drawing new shapes,
where type is a string identifying which of the composing or blending mode
operations to use. The valid types are:
- "source-over" - This is the default setting and draws new shapes on top of the existing canvas content.
- "source-in" - The new shape is drawn only where both the new shape and the destination canvas overlap. Everything else is made transparent.
- "source-out" - The new shape is drawn where it doesn't overlap the existing canvas content.
- "source-atop" - The new shape is only drawn where it overlaps the existing canvas content.
- "destination-over" - New shapes are drawn behind the existing canvas content.
- "destination-in" - The existing canvas content is kept where both the new shape and existing canvas content overlap. Everything else is made transparent.
- "destination-out" - The existing content is kept where it doesn't overlap the new shape.
- "destination-atop" - The existing canvas is only kept where it overlaps the new shape. The new shape is drawn behind the canvas content.
- "copy" - Only the new shape is shown.
- "xor" - Shapes are made transparent where both overlap and drawn normal everywhere else.
- "lighter" - Where both shapes overlap the color is determined by adding color values.
- "multiply" - The pixels are of the top layer are multiplied with the corresponding pixel of the bottom layer. A darker picture is the result.
- "screen" - The pixels are inverted, multiplied, and inverted again. A lighter picture is the result (opposite of multiply)
- "overlay" - A combination of multiply and screen. Dark parts on the base layer become darker, and light parts become lighter.
- "darken" - Retains the darkest pixels of both layers.
- "lighten" - Retains the lightest pixels of both layers.
- "color-dodge" - Divides the bottom layer by the inverted top layer.
- "color-burn" - Divides the inverted bottom layer by the top layer, and then inverts the result.
- "hard-light" - A combination of multiply and screen like overlay, but with top and bottom layer swapped.
- "soft-light" - A softer version of hard-light. Pure black or white does not result in pure black or white.
- "difference" - Subtracts the bottom layer from the top layer or the other way round to always get a positive value.
- "exclusion" - Like difference, but with lower contrast.
- "hue" - Preserves the luma and chroma of the bottom layer, while adopting the hue of the top layer.
- "saturation" - Preserves the luma and hue of the bottom layer, while adopting the chroma of the top layer.
- "color" - Preserves the luma of the bottom layer, while adopting the hue and chroma of the top layer.
- "luminosity" - Preserves the hue and chroma of the bottom layer, while adopting the luma of the top layer.
- Parameters:
type
- the type of composing to be applied from now
public void fillRectangle(double x, double y, double width, double height, Paint color)
Fills a rectangle with the given color on the canvas, preserving transparency
- Parameters:
x
- the x coordinate of the top left corner of the rectangley
- the y coordinate of the top left corner of the rectanglewidth
- the width of the rectangleheight
- the height of the rectanglecolor
- the color or texture to use
public void fillCircle(double cx, double cy, double radius, Paint color)
Fills a circle with the given color on the canvas, preserving transparency
- Parameters:
cx
- the x coordinate of the circle centercy
- the y coordinate of the circle centerradius
- the radius of the circlecolor
- the color or texture to use
public void clearRectangle(double x, double y, double width, double height)
Clears a rectangle on the canvas (makes it fully transparent)
- Parameters:
x
- the x coordinate of the top left corner of the rectangley
- the y coordinate of the top left corner of the rectanglewidth
- the width of the rectangleheight
- the height of the rectangle
public void clear()
Clears the whole canvas (makes it fully transparent).
public void postSVGShapeSpecificAttributes(List<String> att, List<String> val, boolean publicOnly)
Description copied from class:
Shape
Posts general properties specific to a particular shape class.
Is triggered by SVG_DIRTY_SHAPE flag.
Made public for occasional posting of additional SVG properties from outside engine
(e.g. from libraries)
- Overrides:
postSVGShapeSpecificAttributes
in classShape
- Parameters:
att
- attribute namesval
- attribute valuespublicOnly
- TODO