Draw - page of item PmiCanvas
) for onDraw
drawing event that allows to draw into the CanvasCtx
| onDraw||This drawing event is called if the item graphics needs to be redrawn. |
|pEvent||(Object) A referrence to object describing detailed information about the specific event.|
| pEvent.GetCtx(state)||(Object) Returns reference to the CanvasCtx object, that represents the drawing area. The meaning of the state parameter:|
0 - An empty drawing area is obtained, any existing content is discarded. All visible content is drawn again from the start.
- The drawing area in current state is obtained, so the existing content is preserved. This way, the new drawings can be added, for example the value progression where the new points are added. The pEvent.CtxExt.isReset()
method can be used to detect whether the drawing are is non-initialized (empty) or contains drawings from previous sessions.
| pEvent.GetVar()||(Object) Returns reference to the variable of graphic item on the Variables page with defined name. See PmiItem.Vars.|
| pEvent.GetParentVar()||(Object) Returns reference to the variable of parent graphic item on the Variables page with defined name. The In onDraw the pEvent.GetParentVar() method will be used configurator must me enabled, in order to access the parent item variables. See PmiItem.Vars.|
| pEvent.CtxDx||(Long) The width of drawing area (in pixels). The drawing area has the same dimensions as the PmiCanvas item.|
| pEvent.CtxDy||(Long) The height of the drawing area (in pixels).|
| pEvent.CtxExt||(Object) Reference to extending object CanvasCtxExt|
| pEvent.Methods||(Object) Designer's methods for drawing.|
| pEvent.ViewerType||(Long) Flag showing whether the panel is in local PROMOTIC application or in Web browser. |
The value is the same as in the PmiRoot.ClientType property. In the onDraw event script, the PmiRoot object is not accessible.
| Auxiliary methods||Beause some drawings can be very complex it may be handy to divide the whole drawing into assistant user drawing methods that can be created on the same level as the onDraw event. |
Assistant drawing methods have the same parameters as the onDraw event and can also have its own extra parameters. It is recommended that the methods have at least one extra parameter ctx, so it does not to be obtained individually - see example:
One method draws the scale (named for example DrawScale) and another method draws the value curve (named for example DrawCurve). In the onDraw event, there is just a simple script that calls these methods.
, regardless on the PmPanel
setting of "Scripting language settings
PmiCanvas graphic item allows automated calling of onDraw drawing event for redrawing the draw area CanvasCtx if needed:
1) If the drawing area is not initialised (empty) after opening the panel
or after changing the dimensions
of the PmiCanvas
graphic item, or after calling the CtxReset
method. In this case the drawing area is always empty (transparent).
2) If the input variables
) of the PmiCanvas
graphic item were changed. The drawing method may request an existing drawing area, see pEvent.GetCtx
(1), or more commonly non-initialized (empty) drawing area, see pEvent.GetCtx
3) If the variables
) of the parent
grafiphic item (background) PmiCanvas
were changed (valid for embedded item - foreground).
The drawing area is redrawn by the onDraw event only if changed. If no change occurs, then it is not necessary to use the script for redrawing the area and the remembered appearance is used. The onDraw event can access only the values of local variables (Variables) of the PmiCanvas item, that are currently used as data interface of the drawing function. It can also use the Pm object and the drawing area object CanvasCtx. The scripting interface of the CanvasCtx object enables most of the methods and properties for 2D drawing used in HTML5 in the <canvas> tag.