The program shown in Figure 94 provides the terminal operator with a menu
from which a shape and a color can be selected. The program draws the
chosen shape in the chosen color. The format of the map it uses is shown
in Figure 96. A typical display is shown in Figure 95.
The program uses several calls, marked A , that refer to the graphics
concepts of segment and picture space. The concepts are described in
"Hierarchy of GDDM concepts" in topic 7.0.
MAPEX11: PROC OPTIONS (MAIN);
DCL 1 DRAW, /* Application Data Structure */
10 MESSAGE_FIELD_SEL CHAR (1),
10 MESSAGE_FIELD CHAR (30),
10 SHAPE_ARRAY(3),
15 SHAPE_SEL CHAR(1),
15 SHAPE CHAR(11),
10 COLOR_ARRAY(7),
15 COLOR_SEL CHAR(1),
15 COLOR CHAR(12);
DRAW_ASLENGTH FIXED BIN(31,0) STATIC
INIT(158);
DCL (ATTYPE,ATVAL,COUNT) FIXED BIN(31); /* ASREAD arguments */
DCL OPERATION FIXED BIN(31); /* Type of output required */
DCL WRITE FIXED BIN(31) INIT(0); /* MSPUT write operation */
DCL REJECT FIXED BIN(31) INIT(2); /* MSPUT reject operation */
DCL SHAPE_CHOSEN FIXED BIN(31); /* Identifies chosen shape */
DCL COLOR_CHOSEN FIXED BIN(31); /* Identifies chosen color */
DCL ERROR FIXED BIN(15) INIT(0); /* Indicates type of error */
DCL 1 MSG(4) CHAR(30) INIT( /* Error messages */
'NO SELECTIONS MADE - RETRY',
'CONFLICTING SELECTIONS - RETRY',
'SHAPE NOT CHOSEN - RETRY',
'COLOR NOT CHOSEN - RETRY');
DCL (I,J) FIXED BIN(15); /* Work variables */
CALL FSINIT; /* Initialize GDDM */
CALL MSPCRT(1, /* Create page using */
-1, /* GDDM-IMD defined page */
-1, /* width and depth */
'DRAWD6'); /* for mapgroup DRAWD6. */
CALL MSDFLD(1, /* Format an area of the */
-1, /* page at GDDM-IMD defined*/
-1, /* row and column */
'DRAW'); /* for map draw. */
DRAW = ''; /* Clear ADS. */
OPERATION = WRITE; /* Initially use write. */
CALL GSPS(1,1); /* Set picture space aspect*/ A
/* Ratio to 1:1 */
CALL GSSEG(1); /* Define graphics segment.*/ A
PUT_MAP:
CALL MSPUT(1, /* Add data to map */
OPERATION, /* with preset operation, */
DRAW_ASLENGTH, /* specifying the ADS */
DRAW); /* length & the data area. */
CALL ASREAD(ATTYPE, /* Send page to terminal & */
ATVAL, /* wait for operator input.*/
COUNT);
IF ATTYPE = 1 /* PF key 3 or 15 pressed, */
& (ATVAL = 3 | ATVAL = 15) /* so terminate. */
THEN GO TO EXIT;
CALL GSCLR; /* Clear the segment. */ A
CALL GSSEG(1); /* Define graphics segment.*/ A
IF COUNT = 0 THEN DO; /* No data input - error. */
ERROR = 1;
GO TO REJECT_MAP;
END;
CALL MSGET(1,0, /* Get data from map. */
DRAW_ASLENGTH, /* Length of data area. */
DRAW); /* Data area. */
MESSAGE_FIELD_SEL = ' '; /* Remove any error message*/
DO I = 1 TO 3; /* Check if shape chosen. */
IF SHAPE_SEL(I) = '1' THEN DO; /* Shape has been chosen. */
DO J = I+1 TO 3; /* Is it unique? */
IF SHAPE_SEL(J) = '1' THEN DO; /* No, so indicate error. */
ERROR = 2;
GO TO REJECT_MAP;
END;
END;
SHAPE_CHOSEN = I; /* Store chosen shape. */
GO TO CHECK_COLOR;
END;
END;
ERROR = 3; /* No shape chosen. */
GO TO REJECT_MAP;
CHECK_COLOR:
DO I = 1 TO 7; /* Check if color chosen. */
IF COLOR_SEL(I) = '1' THEN DO; /* Color has been chosen. */
DO J = I+1 TO 7; /* Is it unique? */
IF COLOR_SEL(J) = '1' THEN DO; /* No, so indicate error. */
ERROR = 2;
GO TO REJECT_MAP;
END;
END;
COLOR_CHOSEN = I; /* Store chosen color. */
GO TO PUT_GRAPHICS;
END;
END;
ERROR = 4; /* No color chosen. */
REJECT_MAP: /* Set up reject of map. */
MESSAGE_FIELD_SEL = '1'; /* Set selector adjunct. */
MESSAGE_FIELD = MSG(ERROR); /* Move in message. */
ERROR = 0; /* Clear indicator. */
OPERATION = REJECT; /* Specify reject operation*/
DO I = 1 TO 3; /* Set the selector */
IF SHAPE_SEL(I) = '1' /* adjuncts to take */
THEN SHAPE_SEL(I) = '2'; /* map-defined values. */
END;
DO I = 1 TO 7; /* Set the selector */
IF COLOR_SEL(I) = '1' /* adjuncts to take */
THEN COLOR_SEL(I) = '2'; /* map-defined values. */
END;
GO TO PUT_MAP;
PUT_GRAPHICS: /* Create chosen shape. */
CALL GSCOL(COLOR_CHOSEN); /* Set color. */
CALL GSAREA(0); /* Start an area. */
IF SHAPE_CHOSEN = 1 THEN DO; /* Circle selected. */
CALL GSMOVE(2,50); /* Move to center. */
CALL GSARC(50,50,360); /* Draw arc. */
END;
ELSE IF SHAPE_CHOSEN = 2 THEN DO; /* Square selected. */
CALL GSMOVE(0,0); /* Move to initial position*/
CALL GSLINE(100,0); /* Draw */
CALL GSLINE(100,100); /* sides */
CALL GSLINE(0,100); /* of */
CALL GSLINE(0,0); /* square. */
END;
ELSE DO; /* Triangle selected. */
CALL GSMOVE(0,0); /* Move to initial position*/
CALL GSLINE(100,0); /* Draw */
CALL GSLINE(50,100); /* three */
CALL GSLINE(0,0); /* lines. */
END;
CALL GSENDA; /* Close the area. */
OPERATION = WRITE; /* Specify write operation.*/
SHAPE_SEL = ' '; /* Clear selector */
COLOR_SEL = ' '; /* adjuncts. */
GO TO PUT_MAP; /* Redisplay the panel. */
EXIT:
CALL FSTERM;
%INCLUDE ADMUPINA; /* GDDM entry declarations.*/
%INCLUDE ADMUPINF;
%INCLUDE ADMUPING;
%INCLUDE ADMUPINM;
END MAPEX11;
Figure 94. Listing of MAPEX11 source code
A screen showing a menu area on the left and a graphics area on the
right.
Figure 95. Typical display by MAPEX11
Figure 96. Field definitions of map used by MAPEX11
|