GDDM V3R2 Base Application Programming Guide
Previous topic | Next topic | Contents | Index | Contact z/OS | Library | PDF | BOOK


The viewport

GDDM V3R2 Base Application Programming Guide
SC33-0867-01



The viewport is the area of the screen to which the current graphics are to be sent. It is defined as part of the picture space. If it is not explicitly defined, using the GSVIEW call, the viewport covers the whole picture space by default.

The viewport is the lowest physical division of the screen in the hierarchy. Figure 32 shows the positioning of the viewport within the picture space defined with the ratio 1:0.5 in Figure 31.


   PICTURE 22          

Figure 32. Defining a viewport


A viewport must be defined in terms of the picture space that contains it. So if you want to define the viewport you need to know the coordinates of the picture space. Whether you allow the picture space to take the default size or explicitly specify a ratio for it, its coordinates are set by GDDM. You must, therefore, take special action to discover the coordinates of the picture space. GDDM sets the dimensions of the picture space to maximize its size subject to the size of the graphics field and the ratio defined (explicitly or by default). Since the size of the graphics field is dependent on the device, so too is the size of the picture space.

GDDM provides API calls that allow you to query the characteristics of every object in the graphics hierarchy from the device down to the graphics segment. By issuing the GSQPS call, you can first query the coordinates of the picture space at execution time and then define the viewport in terms of the parameters returned by the query. This is a typical combination of calls:


     CALL GSQPS(WIDTH,HEIGHT);          /* Ask GDDM what ratio   */
                                        /* the picture-space has.*/
     CALL GSVIEW(0.0,WIDTH*0.5,0.0,HEIGHT*0.5);
                                        /* Place the viewport    */
                                        /* in the bottom-left    */
                                        /* quarter of the        */
                                        /* picture-space.        */

You do not need to explicitly define a viewport in a graphics program but it can be very useful if you need to include several pictures in one graphics field. Only one viewport can exist (per page) at a given time; but it can be redefined over and over again. Whether you need to present the same picture in several places on the screen or several different pictures, you can define the viewport's size and position on the picture space, call a graphics subroutine for each picture, and redefine the viewport in the position where you want the next picture.

Assume, for example, that SUNSHINE, CLOUD, and RAIN are three subroutines that draw emblems on the weather map of a local T.V station. On a day when the forecast says "Rain in the South West of the region, cloudy skies in the West and North West, and sunshine in all other areas", the weatherman might program his chart in the following way:

Note: The subroutines have to be reexecuted for each new viewport.


     CALL GSQPS(WIDTH,HEIGHT);
                         /* Ask GDDM what ratio the picture space has. */
     CALL GSVIEW(0.0,WIDTH*0.33,0.0,HEIGHT*0.33;
                                              /*Viewport bottom left   */
     CALL CLOUD;                              /* Draw the cloud emblem */
     CALL RAIN;                               /* Draw the rain emblem  */
     CALL GSVIEW(0.0,WIDTH*0.33,HEIGHT*0.33,HEIGHT*0.66);
                                              /* Viewport center left  */
     CALL CLOUD;                              /* Draw the cloud emblem */
     CALL GSVIEW(0.0,WIDTH*0.33,HEIGHT*0.66,HEIGHT);
                                              /* Viewport top left     */
     CALL CLOUD;                              /* Draw the cloud emblem */
     CALL GSVIEW(WIDTH*0.33,WIDTH*0.66,HEIGHT*0.66,HEIGHT);
                                           /* Viewport center top      */
     CALL SUNSHINE;                        /* Draw the sunshine emblem */  A
     CALL GSVIEW(WIDTH*0.33,WIDTH*0.66,HEIGHT*0.33,HEIGHT*0.66);
                                           /* Viewport center center   */
             :
             :
      and so on for other areas
             :
             :
     CALL ASREAD(TYPE,VALUE,COUNT);         /* Send picture to device. */
       /*** Subroutine to draw sunshine emblem ***/
       SUNSHINE: PROC;
       CALL GSSEG(0);        /* Open unnamed segment                   */
       CALL GSCOL(6);        /* Set current color to yellow            */
       CALL GSBMIX(5);       /* Set background mix mode to transparent */
       CALL GSAREA(1);
             :
         and so on
             :
       CALL GSSCLS;                       /* Close the current segment */
       END SUNSHINE;

When the viewport is redefined, it can occupy some or all of the position of a previous definition. If the weatherman forecast both cloud and sunshine for the North central area, he could add some lines such as this to his program at A :


     CALL GSVIEW(WIDTH*0.36,WIDTH*0.69,HEIGHT*0.66,HEIGHT);
                                 /* Viewport slightly right of center top. */
     CALL CLOUD;                 /* Draw the cloud emblem */


   PICTURE 23          

Figure 33. Defining a graphics hierarchy (with default partitioning)


The objects in the hierarchy considered so far are concerned with the physical subdivision of the display device's screen (or the printer page). The remaining objects in the hierarchy are different.

Go to the previous page Go to the next page



Copyright IBM Corporation 1990, 2012