ID 757211
Date 7/23/2021
Public

## Drawing Lines on the Screen

Writing a Graphics Program Overview next calls the subroutine drawlines, which draws a rectangle around the outer edges of the screen and three horizontal lines that divide the screen into quarters. (See Writing a Graphics Program Overview.)

 !  DRAWLINES - This subroutine draws a box and
!  several lines.
SUBROUTINE drawlines( )   USE IFQWIN   EXTERNAL        newx, newy
INTEGER(2)      status, newx, newy, maxx, maxy
TYPE (xycoord)  xy
COMMON          maxx, maxy
!
!  Draw the box.
status = RECTANGLE( $GBORDER, INT2(0), INT2(0), maxx, maxy ) CALL SETVIEWORG( INT2(0), newy( INT2( 500 ) ), xy ) ! This sets the new origin to 0 for x and 500 for y. ! Draw the lines. CALL MOVETO( INT2(0), INT2(0), xy ) status = LINETO( newx( INT2( 1000 )), INT2(0)) CALL SETLINESTYLE( INT2( #AA3C )) CALL MOVETO( INT2(0), newy( INT2( -250 )), xy ) status = LINETO(newx( INT2( 1000 )),newy( INT2( -250 ))) CALL SETLINESTYLE( INT2( #8888 )) CALL MOVETO(INT2(0), newy( INT2( 250 )), xy ) status = LINETO( newx( INT2( 1000 )),newy( INT2( 250 ) ) ) END SUBROUTINE The first argument to RECTANGLE is the fill flag, which can be either$GBORDER or $GFILLINTERIOR. Choose$GBORDER if you want a rectangle of four lines (a border only, in the current line style), or \$GFILLINTERIOR if you want a solid rectangle (filled in with the current color and fill pattern). Choosing the color and fill pattern is discussed in Adding Color Overview and Adding Shapes.

The second and third RECTANGLE arguments are the x- and y-coordinates of the upper-left corner of the rectangle. The fourth and fifth arguments are the coordinates for the lower-right corner. Because the coordinates for the two corners are ( 0, 0 ) and ( maxx, maxy ), the call to RECTANGLE frames the entire screen.

The program calls SETVIEWORG to change the location of the viewport origin. By resetting the origin to (0, 500) in a 1000x1000 viewport, you effectively make the viewport run from (0, -500) at the top left of the screen to (1000, 500) at the bottom right of the screen:

  CALL SETVIEWORG( INT2(0), newy( INT2( 500 ) ), xy )

Changing the coordinates illustrates the ability to alter the viewport coordinates to whatever dimensions you prefer. (Viewports and the SETVIEWORG routine are explained in more detail in Understanding Coordinate Systems Overview.)

The call to SETLINESTYLE changes the line style from a solid line to a dashed line. A series of 16 bits tells the routine which pattern to follow. Five possible line patterns are available. For more information, see SETLINESTYLE in the Intel Fortran Language Reference.

When drawing lines, first set an appropriate line style. Then, move to where you want the line to begin and call LINETO, passing to it the point where you want the line to end. The drawlines subroutine uses the following code:

  CALL SETLINESTYLE(INT2( #AA3C ) )
CALL MOVETO( INT2(0), newy( INT2( -250 ) ), xy )
dummy = LINETO( newx( INT2( 1000 )), newy( INT2( -250 )))

MOVETO positions an imaginary pixel cursor at a point on the screen (nothing appears on the screen), and LINETO draws a line. When the program called SETVIEWORG, it changed the viewport origin, and the initial y-axis range of 0 to 1000 now corresponds to a range of -500 to +500. Therefore, the negative value -250 is used as the y-coordinate of LINETO to draw a horizontal line across the center of the top half of the screen, and the value of 250 is used as the y-coordinate to draw a horizontal line across the center of the bottom half of the screen.