Within the physical screen, the upper-left corner is called the “origin.” The x and y coordinates for the origin are always (0, 0). The x axis extends in the positive direction left to right, while the y axis extends in the positive direction top to bottom.
For example, the video mode _VRES16COLOR has a resolution of 640-by-480, which means the x axis contains the values 0–639 (left to right), and the y axis contains 0–479 (top to bottom). (See Figure 9.1.)
Only five functions use physical coordinates: _setcliprgn, _setvieworg, _setviewport, _getviewcoord, and _getphyscoord.
The _setcliprgn function establishes a “clipping region.” Attempts to draw inside the region succeed, while attempts to draw outside the region are clipped (ignored). When you first enter a graphics mode, the clipping region defaults to the entire screen.
The _setvieworg function changes the current location of the origin. When a program first enters a graphics mode, the physical origin and the viewport origin are in the upper-left corner. The following code moves the viewport origin to the physical screen location (50, 100):
_setvieworg( 50, 100 );
The effect on the screen is illustrated in Figure 9.2. Note that the number of pixels remains constant, but the range of legal x values changes from a range of 0 to 639 (physical screen) to –50 to 589. The legal y values change as well.
All graphics functions are affected by the new origin, including _arc, _ellipse, _lineto, _moveto, _outgtext, _pie, and _rectangle.
The third function that uses physical coordinates is _setviewport, described below, which establishes the boundaries of the current viewport.