op_anim_viewer_scroll()
Abstract
Scrolls a viewer’s window so that the specified diagram coordinate is aligned with the viewer origin.
Syntax
op_anim_viewer_scroll (anvid, x, y)
| Argument | Type | Description |
|---|---|---|
anvid |
Anvid |
viewer ID [This value is a numeric identifier which references the viewer to be scrolled.] |
x |
int |
x coordinate of viewer origin |
y |
int |
y coordinate of viewer origin [The x and y coordinate values are measured in pixels from the origin of the model diagram (upper-left corner).] |
Return Type
void
no return value
Example
/** Message transmission delay line (TDL) chart. **/
/* Calculate the vertical coordinates of TDL. */
simtime = op_sim_time ();
y_src = (simtime / MAX_SIM_TIME) * MAX_Y_LEV;
y_dst = ((simtime + xmit_time) / MAX_SIM_TIME) * MAX_Y_LEV;
/* Draw TDL. */
op_anim_igp_line_draw (vid, lprops, X_SRC, y_src, X_DST, y_dst);
/* Label line at source with simulation time. */
sprintf (tstring, "%g", simtime);
op_anim_igp_text_draw (vid, tprops, X_SRC - TEXT_WIDTH, y_src, tstring);
/* If simulation time passes beyond chart extent, scroll the chart, */
/* leaving some overlap to maintain context. */
if (((int) (simtime / SCROLL_DURATION)) > scrollnum)
op_anim_viewer_scroll (vid, 0, (++scrollnum * SCROLL_DURATION) -
(SCROLL_DURATION * 0.10));
Details
When a viewer is created, its scrollbars are initialized: the horizontal scrollbar is positioned at the far left of its range, and the vertical scrollbar is positioned at the top of its range. This positioning aligns the diagram’s origin (0,0) with the viewer’s origin (the upper-left corner of the window). Manually adjusting the scrollbars of a viewer changes the coordinate of the diagram that is aligned with the viewer origin. This KP has a similar effect: it repositions the diagram within a viewer so that the specified coordinate is aligned with the viewer origin.
Purpose
Provides a mechanism to change the view of animated diagrams which are larger than the associated viewer’s window. Viewer scrolling is useful for custom diagrams which grow over time based on new simulation-generated data. In such cases, the most recent additions to the diagram can be kept in view by dynamically scrolling the viewer to the active area (this technique is illustrated in the Example section).
Errors
- Diagnostic Error: Animation viewer ID (
<anvid>) is out-of-range. (due to an invalid value for theanvidargument) - Diagnostic Error: Kernel procedure argument (
<arg_name>) has out-of-range value (<value>). (due to a value for the argumentsxandythat exceeds the range of a short)
Reference
- Use the KPs
op_anim_viewer_open()orop_anim_viewer_open_std()to create an animation viewer and obtain its ID, or the KPop_anim_lprobe_anvid()to obtain the ID of a viewer opened by a labeled custom animation probe - Use the KP
op_anim_viewer_redraw()to force a redraw of a viewer’s window