Window Coordinates

The _setwindow function allows you to use floating-point coordinates instead of integers. More importantly, it scales the screen coordinates to almost any size within the current viewport. Window functions take double-precision arguments and have names that end with the suffixes _w or _wxy. The function _lineto_w is the window-coordinate equivalent of the viewport function _lineto.

To create a window for charting 12 months of average temperatures ranging from –40 to 100, use this line:

_setwindow( TRUE, 1.0, -40.0, 12.0, 100.0 );

The first argument is the invert flag, which puts the lowest y value at the bottom of the screen instead of the top. The minimum and maximum coordinates follow. The new organization of the screen is shown in Figure 9.4.

If you plot a point with _setpixel_w or draw a line with _lineto_w, the values are automatically scaled to the established window.

Window-coordinate graphics provide a lot of flexibility. You can fit an axis into a small range (such as 151.25 to 151.45) or into a large range (–50,000 to 80,000), depending on the type of data to be graphed. In addition, by changing the window coordinates and redrawing a figure, you can create the effects of zooming in or panning across a figure.