Viewports

Viewports provide an alternate integer-based coordinate system for referencing pixels. Fastgraph includes functions to create a viewport, return the viewport limits, and convert viewport coordinates to their screen space values.

A viewport definition consists of its extremes in "viewport space" and the corresponding limits in screen space. The fg_setview() function defines a 2D viewport. Its first four parameters represent the minimum x, maximum x, minimum y, and maximum y viewport coordinates, and its last four parameters represent the corresponding screen space pixel values defining the viewport's physical size and location. For example, the call

C/C++ and Delphi:

fg_setview(100,739,100,499,0,159,0,99);

Visual Basic:

Call fg_setview(100, 739, 100, 499, 0, 159, 0, 99)

would create a 640x400 viewport in the upper left corner of a 320x200 virtual buffer, as shown here:

The viewport's coordinates would range from 100 to 739 horizontally and 100 to 499 vertically. In other words, the viewport coordinate (100,100) would map to the screen space pixel (0,0). The fg_getview() function returns the current viewport limits and corresponding screen space limits, as defined in the most recent call to fg_setview().

Once you've defined a viewport, the fg_xview() and fg_yview() functions translate viewport coordinates to their screen space equivalents. The translated values can then be passed to any Fastgraph function that expects screen space coordinates. For example, the fg_rect() function draws a filled rectangle in screen space. If you wanted to fill the viewport defined above with color 10 pixels, you could do this as follows:

C/C++ and Delphi:

fg_setcolor(10);
fg_rect(fg_xview(100),fg_xview(739),fg_yview(100),fg_yview(499));

Visual Basic:

Call fg_setcolor(10)
Call fg_rect(fg_xview(100), fg_xview(739), fg_yview(100), fg_yview(499))

To make a viewport a "true" viewport, it is often desirable to establish clipping limits at the viewport's extremes. This way, the Fastgraph functions that support clipping will only draw within the viewport itself. The following call to fg_setclip() will establish the desired clipping limits:

C/C++ and Delphi:

fg_setclip(fg_xview(100),fg_xview(739),fg_yview(100),fg_yview(499));

Visual Basic:

Call fg_setclip(fg_xview(100),fg_xview(739),fg_yview(100),fg_yview(499))

<< Prev

Next >>

Contents
Fastgraph Home Page

 

copyright 2001 Ted Gruber Software, Inc.