home *** CD-ROM | disk | FTP | other *** search
/ ProfitPress Mega CDROM2 …eeware (MSDOS)(1992)(Eng) / ProfitPress-MegaCDROM2.B6I / PROG / PASCAL / TOTDOC.ZIP / CHAPT5.TXT < prev    next >
Encoding:
Text File  |  1991-02-10  |  46.6 KB  |  1,188 lines

  1.                                                                          Writing
  2.                                                                           to the
  3.                                                                           Screen
  4.  
  5.  
  6.  
  7.  
  8.  
  9.          "Some of the newer computer-related equipment is of considerable
  10.          help... Among the most useful tools is the cathode-ray-tube console, a
  11.          computer-connected instrument resembling a television set, which can
  12.          display on its screen textual information from the computer's memory in
  13.          easily readable form."
  14.  
  15.                                           The American Heritage Dictionary, 1981
  16.  
  17.  
  18.  
  19.          Most programs need to write output to the display, and usually this
  20.          needs to be done very quickly! The totFAST unit includes a variety of
  21.          objects for writing to the screen.
  22.  
  23.          The main object ScreenOBJ is capable of writing to the physical screen
  24.          as well as virtual screens. A virtual screen is a screen that is not
  25.          visible but provides all the facilities of the physical screen. A vir-
  26.          tual screen can be used to keep a snapshot copy of the physical screen
  27.          so that it may be restored at some later date. Virtual screens can also
  28.          be used to prepare full screen displays "off line", which, when
  29.          required, can be pushed onto the visible screen using a variety of
  30.          effects.
  31.  
  32.          The ScreenOBJ object provides methods for writing to the screen using
  33.          varied justification, as well as methods to draw lines and boxes, read
  34.          information from the screen, move blocks of text around the screen, and
  35.          control cursor location and appearance.
  36.  
  37.          The totFAST unit also includes objects for controlling the appearance
  38.          of scroll bars and window shadows. Note: remember that the display
  39.          colors are always specified as the composite foreground and background
  40.          attribute (refer to page 3.11 for more information).
  41.  
  42.  
  43.  
  44. The Writing Engine
  45.  
  46.          Before plunging into the totFAST unit, you ought to be aware of an
  47.          important Toolkit feature.
  48.  
  49.          At the heart of the ScreenOBJ object is another object called WriteOBJ
  50.          (yes, an object within an object). This object is the screen writing
  51.          engine, and performs all of the primary screen manipulation tasks.
  52.          There are methods for writing text, controlling the cursor, and for
  53.          making direct video memory moves.
  54.  
  55.          You should never need to access the WriteOBJ methods; when you make
  56.          calls to the ScreenOBJ methods, the Toolkit makes calls to the WriteOBJ
  57.          engine. Ordinarily, therefore, you don't even need to be aware that
  58.          WriteOBJ exists. However, if you want to use some different routines
  59.          for accessing the display (e.g. you want to run programs on non-
  60.  
  61. 5-2                                                                 User's Guide
  62.  
  63. --------------------------------------------------------------------------------
  64.  
  65.          standard hardware, or you want to run in graphics mode), then all you
  66.          have to do is create your own WriteOBJ-type object, and instruct the
  67.          Toolkit to use it. This "back door" gives you complete control of the
  68.          Toolkit's engine. This feature allows you to modify the Toolkit display
  69.          engine without making a single change to the Toolkit source code.
  70.  
  71.          This whole subject is discussed in detail in Part 2: Extending the
  72.          Toolkit.
  73.  
  74.  
  75.  
  76. Managing the Visible Screen
  77.  
  78.          One of the few parts of the Toolkit written in Assembler is the screen
  79.          writing code. The reason? Speed. The totFAST unit provides very high
  80.          performance screen writing, especially in CGA systems, which are noto-
  81.          rious for "snow" and slow speeds.
  82.  
  83.          The Toolkit can write to all PC monitor types ranging from monochrome
  84.          to VGA. For performance reasons, totFAST bypasses DOS screen writing
  85.          services (BIOS) and writes directly to the video area of memory.
  86.  
  87.          The Toolkit automatically switches off the mouse cursor during screen
  88.          writes.
  89.  
  90.  
  91.  
  92. Using SCREEN
  93.  
  94.          totFAST includes a global object SCREEN of type ScreenOBJ. SCREEN is
  95.          automatically initialized when you use the totFAST unit. All direct
  96.          screen writing should be performed using the SCREEN instance. For exam-
  97.          ple, to write "Hello World" at the current cursor position, you would
  98.          call the method Write as follows:
  99.  
  100.                   Screen.Write("Hello World");
  101.  
  102.  
  103.          Most of the other screen writing methods must be passed the X and Y
  104.          coordinates where the string is to be written. Like Turbo Pascal, the
  105.          Toolkit uses a one-based system where the top left of the screen is at
  106.          coordinates (1,1) and the bottom right of the screen is normally
  107.          (80,25). Some routines, like the box drawing methods, need to be passed
  108.          a pair of coordinates. Pass the upper-left and lower-right coordinates,
  109.          respectively.
  110.  
  111.  
  112.  
  113.  
  114.  
  115. Basic Screen Writing
  116.  
  117.          This section explains how to use the methods for writing strings using
  118.          varied justification methods, how to clear all or part of the screen,
  119.          how to change the display attributes and how to draw lines and boxes.
  120.  
  121.  
  122. Writing to the Screen                                                        5-3
  123.  
  124. --------------------------------------------------------------------------------
  125.  
  126.             Note: unfortunately, Turbo Pascal provides no facility for writing
  127.             procedures or functions which can be passed different parameter
  128.             types or varying numbers of parameters. For this reason, the Tool-
  129.             kit is incapable of providing the ultra-flexible facilities similar
  130.             to Turbo Pascal's own Write and WriteLn procedures.
  131.  
  132.             The Toolkit therefore expects a single string to be passed to its
  133.             main screen writing methods. If you need to write a non-string
  134.             item, you can use one of the string conversion functions in the
  135.             totSTR unit. For example, to display the value of a real variable
  136.             REALVAL, use the following statement:
  137.  
  138.                      SCREEN.Write(RealToStr(REALVAL));
  139.  
  140.             For plain screen writing, feel free to use Turbo Pascal's proce-
  141.             dures Write and WriteLn, e.g. Write(REALVAL);, but remember to hide
  142.             the mouse first.
  143.  
  144.  
  145.  
  146.  
  147. Writing Strings
  148.  
  149.          The following eleven methods simplify the tasks of writing strings to
  150.          the screen:
  151.  
  152.  
  153.          Write(Str:string);
  154.  
  155.          Writes a string at the current cursor position using the default dis-
  156.          play attributes. The display attributes are set with Turbo Pascal's CRT
  157.          procedures TextColor and TextBackground. The cursor is automatically
  158.          moved to the position following the last character of the string.
  159.  
  160.  
  161.          WriteLn(Str:string);
  162.  
  163.          This method is the same as Write, except that the cursor is moved to
  164.          the beginning of the next line. If the string is written to the last
  165.          line of the display (or the last line of a window - discussed later),
  166.          the display scrolls up one line.
  167.  
  168.  
  169.          WriteAT(X,Y,Attr:byte; Str:string);
  170.  
  171.          Writes a string at the specified X and Y coordinates using the display
  172.          attribute Attr. The cursor is not moved.
  173.  
  174.  
  175.          WriteHi(X,Y,AttrHi,Attr:byte; Str:string);
  176.  
  177.  
  178.  
  179. 5-4                                                                 User's Guide
  180.  
  181. --------------------------------------------------------------------------------
  182.  
  183.          This method is used to write a string with a combination of color
  184.          attributes. Some parts of the string may be written in attribute
  185.          AttrHi, and other parts in Attr. A special character must be embedded
  186.          into the string to indicate when to change attributes. By default, this
  187.          character is '~'. Any text written up to the first occurrence of '~' is
  188.          written using Attr, the next set of text is written in AttrHi. If
  189.          another '~' is encountered, the attribute is switched back to Attr, and
  190.          so on.
  191.  
  192.          For example, the following statement would write the string 'F1 Help'
  193.          so that the 'F1' is highlighted:
  194.  
  195.                   Screen.WriteHi(1,1,yellow,white,'~F1~ Help');
  196.  
  197.          Similarly, the following statement would write the text so that the
  198.          letter H is highlighted:
  199.  
  200.                   Screen.WriteHi(1,1,yellow,white,'F1 ~H~elp');
  201.  
  202.          The method SetHiMarker can be used to instruct the Toolkit to recognize
  203.          a different special character. For example, the following statement
  204.          would change the special character to an asterisk:
  205.  
  206.                   Screen.SetHiMarker('*');
  207.                   Screen.WriteHi(1,1,yellow,white,'F1 *H*elp');
  208.  
  209.  
  210.          WriteCap(X,Y,AttrCap,Attr:byte; Str:string);
  211.  
  212.          WriteCap is similar to WriteHi. The only difference is that there are
  213.          no embedded markers in the string; WriteCap automatically highlights
  214.          the first capital letter.
  215.  
  216.  
  217.          WriteClick(X,Y,Attr:byte; Str:string);
  218.  
  219.          This method is the functional equivalent of WriteAT. WriteClick, how-
  220.          ever, causes the PC speaker to emit a "click" after each character is
  221.          written, and the text expands onto the screen from left to right.
  222.  
  223.  
  224.          WriteCenter(Y,Attr:byte; Str:string);
  225.  
  226.          WriteCenter is ideal for titles and headings. The string is automati-
  227.          cally displayed at the center of the specified line. There is no need
  228.          to compute the X coordinate based on the length of the string, as this
  229.          is all done automatically.
  230.  
  231.  
  232.          WriteBetween(X1,X2,Y1,Attr:byte; Str:string);
  233.  
  234.          This method writes the string centered between two X coordinates. If
  235.          the text is too long to fit between the coordinates, the full string is
  236.          written starting at X1.
  237.  
  238.  
  239.  
  240. Writing to the Screen                                                        5-5
  241.  
  242. --------------------------------------------------------------------------------
  243.  
  244.          WriteRight(X,Y,Attr:byte; Str:string);
  245.  
  246.          WriteAT writes the text left-justified at the X coordinate. This
  247.          method, WriteRight, writes the text right-justified at the X coordi-
  248.          nate. The last character of the string will be positioned at (X,Y).
  249.  
  250.  
  251.          WriteVert(X,Y,Attr:byte; Str:string);
  252.  
  253.          This method writes the string in a vertical column starting at (X,Y),
  254.          i.e. the second character will be drawn at coordinates (X,Y+1), and so
  255.          on.
  256.  
  257.  
  258.          WritePlain(X,Y:byte; Str:string);
  259.  
  260.          Whereas Write and Writeln use the default attributes, and all the other
  261.          methods are passed the display attribute(s), WritePlain uses the exis-
  262.          ting color attributes at the location where the string is written.
  263.          Because the display attributes are not modified, this is the fastest
  264.          screen writing routine in the Toolkit.
  265.  
  266.          Listed below is the demo program DEMWR1.PAS and a screen shot of the
  267.          resultant output.
  268.  
  269.  
  270.  
  271. Figure 5.1                                                              [SCREEN]
  272. The Screen Writing
  273. Methods
  274.  
  275.  
  276.  
  277.          Program DemoWriteOne;
  278.          {DEMWR1}
  279.  
  280.          USES DOS,CRT, totFAST;
  281.  
  282.          begin
  283.             ClrScr;
  284.             with Screen do
  285.             begin
  286.                WriteCenter(1,attr(white,red),'TechnoJock''s Object Toolkit');
  287.                WriteCenter(2,79,'Write Demo One');
  288.                WriteAT(5,5,lightgreen,'Written using WriteAT');
  289.                WriteHi(5,7,white,cyan,'Written with the Write~Hi~ method');
  290.                WriteRight(80,9,yellow,'Written with WriteRight');
  291.                WriteCap(5,11,white,cyan,'Written with WriteCap');
  292.                WriteCap(5,13,white,cyan,'also written with WriteCap');
  293.                WriteVert(40,5,12,'Writevert');
  294.                WriteBetween(1,40,15,lightgreen,'Left Half');
  295.                WriteBetween(41,80,15,lightgreen,'Right Half');
  296.                WritePlain(5,17,'This is written with WritePlain');
  297.                GotoXY(5,19);
  298.  
  299.  
  300.  
  301. 5-6                                                                 User's Guide
  302.  
  303. --------------------------------------------------------------------------------
  304.  
  305.                Write('Good Old Write! ');
  306.                Writeln('And ...');
  307.                Writeln('Good old Writeln');
  308.                Writeln('');
  309.                System.Writeln('This ','is',' Turbo''s Writeln');
  310.                WriteClick(33,24,white,'That''s all Folks!');
  311.                GotoXY(1,25);
  312.             end;
  313.          end.
  314.  
  315.  
  316.  
  317.  
  318. Clearing the Screen
  319.  
  320.          In addition to Turbo's ClrScr function, the Toolkit provides the fol-
  321.          lowing screen clearing methods in ScreenOBJ:
  322.  
  323.  
  324.  
  325.  
  326.          Clear(Attr:byte; Ch:char);
  327.  
  328.          This method erases the entire screen and fills the screen with the
  329.          character Ch, using the specified attribute.
  330.  
  331.  
  332.          PartClear(X1,Y1,X2,Y2,Attr:byte; Ch:char);
  333.  
  334.          This method is similar to Clear, except that only the rectangular area
  335.          between (X1,Y1) and (X2,Y2) is cleared.
  336.  
  337.  
  338.          ClearText(X1,Y1,X2,Y2:byte);
  339.  
  340.          The method ClearText erases all the characters in the specified region,
  341.          but does not change the display attribute.
  342.  
  343.  
  344.  
  345. Changing Display Attributes
  346.  
  347.          The ScreenOBJ object includes the following method, Attrib, for chang-
  348.          ing the display attribute of a rectangular area of the screen:
  349.  
  350.  
  351.          Attrib(X1,Y1,X2,Y2,Attr:byte);
  352.  
  353.          Changes the display in the region between coordinates (X1,Y1) to
  354.          (X2,Y2) to the specified attribute. The displayed characters in this
  355.          region are unscathed except for their color being changed.
  356.  
  357.  
  358.  
  359. Writing to the Screen                                                        5-7
  360.  
  361. --------------------------------------------------------------------------------
  362.  
  363. Drawing Lines and Boxes
  364.  
  365.          ScreenOBJ includes a host of methods for drawing lines and boxes. The
  366.          boxes may optionally have left, center or right justified title posi-
  367.          tion at the top, bottom, or in a drop box.
  368.  
  369.          Using the standard (upper ASCII) characters, lines may be drawn using
  370.          either a single or double line. Each line drawing method requires a
  371.          style parameter, of type byte. A style of 1 indicates a single line,
  372.          and 2 a double line. When drawing boxes, the following styles should be
  373.          used:
  374.  
  375.               0     no box border
  376.               1     single line box
  377.               2     double line box
  378.               3     double sides, single top and bottom
  379.               4     single sides, double top and bottom
  380.               5     single left and upper, double lower and right
  381.               6     menu box style
  382.  
  383.          If a style value of 7 or greater is specified, the lines are drawn
  384.          using the ASCII character represented by the style value. Figure 5.2
  385.          graphically illustrates the impact of the style parameter, and was
  386.          generated from the file DEMBX1.PAS.
  387.  
  388.  
  389.  
  390. Drawing Boxes
  391.  
  392.          The following three methods are included in the ScreenOBJ:
  393.  
  394.  
  395.          Box(X1,Y1,X2,Y2,attr,style:byte);
  396.  
  397.          This method draws a rectangular box from (X1,Y1) to (X2,Y2) in the
  398.          specified attribute and style. Only the box border is drawn -- the area
  399.          within the box perimeter is not affected.
  400.  
  401.  
  402.  
  403. Figure 5.2                                                              [SCREEN]
  404. Line Drawing Styles
  405.  
  406.  
  407.          FillBox(X1,Y1,X2,Y2,attr,style:byte);
  408.  
  409.          This method is the same as Box, except that the interior of the box is
  410.          erased (or filled).
  411.  
  412.  
  413.          ShadFillBox(X1,Y1,X2,Y2,attr,style:byte);
  414.  
  415.          This method is the same as FillBox, except that a shadow is also drawn.
  416.          The shadow characteristics are defined with the global instance Shadow-
  417.          TOT^ (see page 3-12).
  418.  
  419.  
  420. 5-8                                                                 User's Guide
  421.  
  422. --------------------------------------------------------------------------------
  423.  
  424. Boxes with Titles
  425.  
  426.          Often times, you will want to add a title to the box. The method Title-
  427.          Box will draw a filled box with a title. The syntax of the method is as
  428.          follows:
  429.  
  430.  
  431.          TitledBox(X1,Y1,X2,Y2,Battr,Tattr,Mattr,style: byte;
  432.                    Title:string);
  433.  
  434.          This method will draw a box from (X1,Y1) to (X2,Y2) using the style
  435.          specified. The box border will be drawn with attribute Battr, the inte-
  436.          rior of the box will be filled using the attribute Mattr, and the title
  437.          string will be drawn in the attribute Tattr.
  438.  
  439.          By default, the title will be displayed in the center of the top box
  440.          border. However, by embedding some special characters at the beginning
  441.          of the string, you can control precisely where the title is positioned.
  442.          The title can be prefixed with two special character codes to control
  443.          the justification and position of the title.
  444.  
  445.          The justification special characters are as follows:
  446.  
  447.               '<'   Left Justify
  448.               '>'   Right Justify
  449.               '+'   Center (default)
  450.  
  451.          The position special characters are as follows:
  452.  
  453.               '^'   Top of box
  454.               '|'   In a drop box
  455.               '_'   Bottom of box
  456.  
  457.          These special characters should be inserted at the beginning of the
  458.          title string. It does not matter in which order the justification and
  459.          position characters are specified. For example, either '<_Hello' or
  460.          '_<Hello' will result in the title 'Hello' being drawn left-justified
  461.          on the bottom box border.
  462.  
  463.          Listed below is the demo file DEMBX2.PAS, followed by figure 5.3 show-
  464.          ing the resultant output.
  465.  
  466.          Program DemoBoxTwo;
  467.          {DEMBX2}
  468.  
  469.          USES DOS,CRT, totFAST;
  470.  
  471.          begin
  472.             with Screen do
  473.             begin
  474.                Clear(white,chr(178));
  475.                TitledBox(1,1,19,10,27,31,30,1,'Default');
  476.                TitledBox(21,1,39,10,27,31,30,1,'_Bottom');
  477.                TitledBox(41,1,59,10,27,31,30,1,'|Drop Box');
  478.                TitledBox(61,1,80,10,27,31,30,1,'<Left');
  479.  
  480.  
  481. Writing to the Screen                                                        5-9
  482.  
  483. --------------------------------------------------------------------------------
  484.  
  485.                TitledBox(1,12,19,22,27,31,30,1,'>Right');
  486.                TitledBox(21,12,39,22,27,31,30,1,'_<Bottom Left');
  487.                TitledBox(41,12,59,22,27,31,30,1,'>|Drop Right');
  488.                TitledBox(61,12,80,22,27,31,30,1,'< Spaced Left ');
  489.                WriteCenter(24,white,'You get the idea!');
  490.                GotoXY(1,25);
  491.             end;
  492.          end.
  493.  
  494.  
  495.  
  496.  
  497. Figure 5.3                                                              [SCREEN]
  498. Box Title Positions
  499.  
  500.  
  501.  
  502. Drawing Lines
  503.  
  504.          ScreenOBJ includes the two following methods for drawing simple
  505.          straight lines:
  506.  
  507.  
  508.          HorizLine(X1,X2,Y,Attr,Style:byte);
  509.  
  510.          This procedure draws a horizontal straight line from (X1,Y) to (X2,Y)
  511.          in the specified attribute. If a style of 1 or 3 is used, a single line
  512.          is drawn. Styles 2 and 4 result in a double line. Any other style
  513.          results in a line being drawn using the ASCII character represented by
  514.          the style number.
  515.  
  516.  
  517.          VertLine(X,Y1,Y2,Attr,Style:byte);
  518.  
  519.          This method is similar to HorizLine, except that the line is drawn
  520.          vertically from (X,Y1) to (X,Y2).
  521.  
  522.  
  523.  
  524. Intelligent Lines!
  525.  
  526.          There are two line drawing methods designed to help you draw irregular
  527.          shapes from individual lines. The methods SmartHorizLine and SmartVert-
  528.          Line are similar to HorizLine and VertLine, but smarter! These smart
  529.          methods automatically add joints and corners if the line crosses or
  530.          butts up against another line.
  531.  
  532.          The syntax of the smart line drawing methods is as follows:
  533.  
  534.  
  535.          SmartHorizLine(X1,X2,Y,Attr,Style:byte);
  536.  
  537.          Draws a horizontal line between (X1,Y) and (X2,Y), using line joining
  538.          characters as necessary.
  539.  
  540.  
  541.  
  542. 5-10                                                                User's Guide
  543.  
  544. --------------------------------------------------------------------------------
  545.  
  546.          SmartVertLine(X,Y1,Y2,Attr,Style:byte);
  547.  
  548.          Draws a vertical line between (X,Y1) and (X,Y2), using line joining
  549.          characters as necessary.
  550.  
  551.  
  552.  
  553.          Listed below is the demo program DEMBX3, followed by figure 5.4 illus-
  554.          trating the output.
  555.  
  556.          Program DemoBoxThree;
  557.          {DEMBX3}
  558.  
  559.          USES DOS,CRT, totFAST;
  560.  
  561.          begin
  562.             with Screen do
  563.             begin
  564.                TitledBox(1,1,80,25,27,31,30,1,' Smart Line Drawing ');
  565.                FillBox(30,7,50,18,27,2);
  566.                SmartVertLine(10,1,25,27,2);
  567.                SmartVertLine(70,1,25,27,1);
  568.                SmartVertLine(40,7,18,27,2);
  569.                SmartHorizLine(1,80,10,27,1);
  570.                SmartHorizLine(1,80,20,27,2);
  571.                SmartHorizLine(30,50,13,27,1);
  572.                GotoXY(1,25);
  573.             end;
  574.          end.
  575.  
  576.  
  577.  
  578.  
  579. Figure 5.4                                                              [SCREEN]
  580. Smart Line Drawing
  581.  
  582.  
  583.  
  584. Reading the Screen
  585.  
  586.          ScreenOBJ includes the following methods to help you read characters
  587.          and attributes directly from the screen:
  588.  
  589.  
  590.          ReadChar(X,Y:byte):char;
  591.  
  592.          This function method returns the character read from the screen at
  593.          location (X,Y).
  594.  
  595.  
  596.          ReadAttr(X,Y:byte):byte;
  597.  
  598.          This function method returns the display attribute at the screen loca-
  599.          tion (X,Y).
  600.  
  601.  
  602.  
  603. Writing to the Screen                                                       5-11
  604.  
  605. --------------------------------------------------------------------------------
  606.  
  607.          ReadWord(X,Y:byte; var Attr:byte; var Ch:char);
  608.  
  609.          This method is a combination of the ReadChar and ReadAttr functions. It
  610.          updates the passed parameters Attr and Ch with the attribute and char-
  611.          acter found at location (X,Y).
  612.  
  613.  
  614.          ReadStr(X1,X2,Y:byte):string;
  615.  
  616.          The ReadStr method function reads the characters from (X1,Y) to (X2,Y)
  617.          and returns the characters concatenated as a string.
  618.  
  619.  
  620.  
  621. Drawing Scroll Bars
  622.  
  623.          The totFAST unit includes a global instance pointer ScrollTOT^, which
  624.          defines the cosmetic appearance of all scroll bars used by the Toolkit.
  625.          Refer to page 3-14 for further information on how to change the Scroll-
  626.          TOT^ settings.
  627.  
  628.          The totWIN unit includes window objects which draw horizontal and ver-
  629.          tical scroll bars. However, the following two ScreenOBJ methods are
  630.          available if you need to draw independent scroll bars. In both methods,
  631.          two values must be passed which control the position of the elevator on
  632.          the slide bar.
  633.  
  634.  
  635.          WriteHScrollBar(X1,X2,Y,Attr:byte; Current,Max:longint);
  636.  
  637.          This method draws a horizontal scroll bar from (X1,Y) to (X2,Y) in the
  638.          specified attribute. The location of the elevator is controlled by the
  639.          percentage Current is of Max.
  640.  
  641.  
  642.          WriteVScrollBar(X,Y1,Y2,Attr:byte; Current,Max:longint);
  643.  
  644.          This method draws a vertical scroll bar from (X,Y1) to (X,Y2) in the
  645.          specified attribute. The location of the elevator is controlled by the
  646.          percentage Current is of Max.
  647.  
  648.  
  649.  
  650.          Listed below is the demo program DEMSC1.PAS which generates the output
  651.          shown in figure 5.5.
  652.  
  653.          Program DemoScrollOne;
  654.          {DEMSC1}
  655.  
  656.          USES DOS,CRT, totFAST;
  657.  
  658.          begin
  659.             Clrscr;
  660.             with Screen do
  661.             begin
  662.                WriteHScrollBar(1,80,1,31,1,1000);
  663.  
  664. 5-12                                                                User's Guide
  665.  
  666. --------------------------------------------------------------------------------
  667.  
  668.                WriteHScrollBar(1,80,3,31,950,1000);
  669.                WriteHScrollBar(1,39,5,31,500,1000);
  670.                WriteHScrollBar(41,80,5,31,25,100);
  671.                WriteVScrollBar(1,7,23,31,1,50);
  672.                WriteVScrollBar(3,7,23,31,50,50);
  673.                WriteVScrollBar(5,7,23,31,2,4);
  674.                ScrollTOT^.SetScrollChars(chr(30),chr(31),chr(17),
  675.                                          chr(16),chr(4),chr(219));
  676.                WriteHScrollBar(10,70,11,27,5,10);
  677.                WriteVScrollBar(50,13,23,27,8,10);
  678.                GotoXY(1,24);
  679.             end;
  680.          end.
  681.  
  682.  
  683.  
  684. Figure 5.5                                                              [SCREEN]
  685. Scroll Bars
  686.  
  687.  
  688.  
  689. Moving Screen Blocks
  690.  
  691.          ScreenOBJ includes the following three methods to help you manage rect-
  692.          angular areas of the screen:
  693.  
  694.  
  695.          Scroll(Way:tDirection; X1,Y1,X2,Y2:byte);
  696.  
  697.          The totFAST unit includes the declaration of an enumerated type tDirec-
  698.          tion, which has the members Up, Down, Left, Right, Vert, Horiz. The
  699.          Scroll method can be used to scroll a rectangular portion of the screen
  700.          in any of the first four directions, e.g. Up, Down, Left, or Right. The
  701.          area between the coordinates (X1,Y1) and (X2,Y2) is scrolled in the
  702.          direction specified. One line or column of the display area is removed
  703.          and the opposite line or column is replaced with blanks. For example,
  704.          if the text is scrolled Up, all the text is moved up one line; the
  705.          first line of the area is replaced by the second, and the gap vacated
  706.          by the last line is left blank.
  707.  
  708.  
  709.          CopyScreenBlock(X1,Y1,X2,Y2,X,Y:byte);
  710.  
  711.          This method takes a rectangular portion of the screen bounded by the
  712.          coordinates (X1,Y1) to (X2,Y2) and copies both the characters and the
  713.          attributes to another location on the screen. The top left coordinates
  714.          of the newly copied block are located at coordinates (X,Y).
  715.  
  716.  
  717.          MoveScreenBlock(X1,Y1,X2,Y2,X,Y:byte);
  718.  
  719.  
  720.  
  721. Writing to the Screen                                                       5-13
  722.  
  723. --------------------------------------------------------------------------------
  724.  
  725.          This method is similar to CopyScreenBlock, except that the text is
  726.          moved, i.e. it is removed from the original location and repositioned
  727.          so the new top left coordinate is (X,Y).
  728.  
  729. Controlling the Cursor
  730.  
  731.          The ScreenOBJ object includes a variety of methods for determining the
  732.          cursor location and style, as well as routines to re-position and re-
  733.          size it. Listed below are the public methods related to cursor control.
  734.  
  735.  
  736.          GotoXY(X,Y:byte);
  737.  
  738.          This method relocates the cursor to the position (X,Y).
  739.  
  740.  
  741.          WhereX:byte;
  742.  
  743.          This function method returns the X coordinate of the current cursor
  744.          location.
  745.  
  746.  
  747.          WhereY: byte;
  748.  
  749.          This function method returns the Y coordinate of the current cursor
  750.          location.
  751.  
  752.  
  753.          CursOff;
  754.  
  755.          This method makes the cursor invisible.
  756.  
  757.  
  758.          CursOn;
  759.  
  760.          This method makes the cursor visible and sets it to the DOS default
  761.          shape, i.e. a blinking line at the bottom of the character.
  762.  
  763.  
  764.          CursHalf;
  765.  
  766.          This method makes the cursor a block filling the lower half of the
  767.          character field.
  768.  
  769.  
  770.          CursFull;
  771.  
  772.          This method makes the cursor a full block filling the entire character
  773.          field.
  774.  
  775.  
  776.          CursReset;
  777.  
  778.          CursReset moves the cursor to the top left of the display and sets it
  779.          to the DOS default shape.
  780.  
  781. 5-14                                                                User's Guide
  782.  
  783. --------------------------------------------------------------------------------
  784.  
  785.          CharHeight:integer;
  786.  
  787.          In text mode, an individual character is comprised of a number of scan
  788.          lines. Usually, the cursor is located on one or two scan lines near the
  789.          bottom of the character. Different display systems use varying numbers
  790.          of scan lines. For example, a monochrome display usually has fourteen
  791.          scan lines, as does an EGA system, but a CGA has only eight. This
  792.          method, CharHeight, is a function which returns the actual number of
  793.          scan lines per character. You will need to use this function if you
  794.          want to manually set the cursor shape using CursSize (discussed next).
  795.  
  796.  
  797.          CursSize(T,B:byte);
  798.  
  799.          This method sets the cursor to the specified top and bottom scan lines.
  800.          The top scan line (e.g. the top bar of the letter "T") is scan line
  801.          zero. As an example, to set the cursor on an EGA system to a half block
  802.          filling the upper half of the character, call CursSize(0,7).
  803.  
  804.  
  805.          CursTop:byte;
  806.  
  807.          This function method returns the scan line of the uppermost part of the
  808.          cursor.
  809.  
  810.  
  811.          CursBot: byte;
  812.  
  813.          This function returns the scan line of the lowermost part of the cur-
  814.          sor.
  815.  
  816.  
  817.          The following program, DEMCU1.PAS, illustrates the main cursor control-
  818.          ling methods. Execute the program to see how the cursor shape changes.
  819.  
  820.          program DemoCursorOne;
  821.  
  822.          uses DOS,CRT,
  823.               totSYS, totFAST;
  824.  
  825.          var
  826.            Ch : char;
  827.            Temp: byte;
  828.  
  829.          procedure Msg;
  830.          {}
  831.          begin
  832.             writeln('Character height: ',Screen.CharHeight);
  833.             writeln('Press N-on O-off F-full H-half C-condensed S-25 lines Esc-
  834.          quit');
  835.          end; {Msg}
  836.  
  837.  
  838.  
  839. Writing to the Screen                                                       5-15
  840.  
  841. --------------------------------------------------------------------------------
  842.  
  843.          begin
  844.             Msg;
  845.             repeat
  846.                Ch := ReadKey;
  847.                case upcase(Ch) of
  848.                'N': Screen.CursOn;
  849.                'O': Screen.CursOff;
  850.                'F': Screen.CursFull;
  851.                'H': Screen.CursHalf;
  852.                'C': begin
  853.                         Temp := Monitor^.SetCondensed;
  854.                         Msg;
  855.                     end;
  856.                'S': begin
  857.                         Monitor^.Set25;
  858.                         Clrscr;
  859.                         Msg;
  860.                     end;
  861.                end; {case}
  862.             until Ch = #027;
  863.             Screen.CursOn;
  864.             Monitor^.Set25;
  865.          end.
  866.  
  867.  
  868.  
  869.  
  870. The Impact of Windows
  871.  
  872.          You may be familiar with the Turbo Pascal CRT Window command which
  873.          confines writing to a specific area of the screen. The Toolkit also
  874.          supports this basic windowing feature.
  875.  
  876.          Use the method SetWindow to confine screen writing to one area of the
  877.          screen. The method ResetWindow can be used to "remove" the window set-
  878.          tings, i.e. set the window back to the entire display. The method Win-
  879.          dowOFF can be used to temporarily disable the window confinement.
  880.          WindowON is used to reactivate the window settings. Alternatively, the
  881.          method SetWinIgnore will instruct all screen writing operations to
  882.          ignore the current window settings. The full syntax of the window
  883.          related methods are as follows:
  884.  
  885.  
  886.          SetWindow(X1,Y1,X2,Y2: byte);
  887.  
  888.          Restricts all screen writing to the area within the region (X1,Y1) and
  889.          (X2,Y2). The top left corner of the window area is set to coordinates
  890.          (1,1). Any attempt to write data outside of the window area is ignored,
  891.          and strings which are too long to fit are truncated, i.e. only the
  892.          element of the string which will fit within the window is written.
  893.  
  894.  
  895.  
  896. 5-16                                                                User's Guide
  897.  
  898. --------------------------------------------------------------------------------
  899.  
  900.          ResetWindow;
  901.  
  902.          Removes the window setting.
  903.  
  904.  
  905.          WindowActive: boolean;
  906.  
  907.          Returns true if the screen writing is currently restricted within a
  908.          window.
  909.  
  910.  
  911.          WindowOff: boolean;
  912.  
  913.          Temporarily disables the window settings, and returns true if a window
  914.          was active. This is useful if you want most of the screen writes to be
  915.          confined within a window, but you also want to briefly write some text
  916.          outside the window boundary. For example, the following code fragment
  917.          could be used to write the time at the lower right of the screen:
  918.  
  919.                   var
  920.                     WinWasActive: boolean;
  921.                   ....
  922.                   WinWasActive := WindowOff;
  923.                   WriteRight(1,25,white,CurrentTime);
  924.                   if WinWasActive then
  925.                      WindowOn;
  926.                   ...
  927.  
  928.  
  929.  
  930.          WindowOn;
  931.  
  932.          Reactivates the window settings. This method should only be used after
  933.          a call to WindowOff.
  934.  
  935.  
  936.          WindowCoords(var Coords: tByteCoords);
  937.  
  938.          The totFAST unit includes a type, tByteCoords, which is declared as
  939.          follows:
  940.  
  941.                   tByteCoords = record
  942.                      X1,Y1,X2,Y2: byte;
  943.                   end;
  944.  
  945.          This method will update the passed parameter Coords with the current
  946.          window settings.
  947.  
  948.  
  949.          SetWinIgnore(On:boolean);
  950.  
  951.          When passed a True parameter, this method instructs the Toolkit screen
  952.          writing methods to ignore the current window settings, and assume that
  953.          the coordinates (1,1) refer to the top left of the display. Passing a
  954.          False parameter instructs the Toolkit to adjust all screen writes rela-
  955.  
  956.  
  957. Writing to the Screen                                                       5-17
  958.  
  959. --------------------------------------------------------------------------------
  960.  
  961.          tive to the current method. This method is designed for use in hooked
  962.          procedures when the procedure wants to ignore any window settings which
  963.          may have been effective when it was invoked.
  964.  
  965.  
  966.          Listed below is the demo program DEMFS1.PAS, which illustrates the
  967.          impact of the window commands on screen writing. Figure 5.6 shows the
  968.          screen display generated by the program.
  969.  
  970.          Program DemoFastOne;
  971.          {DEMFS1}
  972.  
  973.          USES DOS,CRT, totFAST;
  974.  
  975.          var
  976.            WasOn: boolean;
  977.          begin
  978.             Clrscr;
  979.             with Screen do
  980.             begin
  981.                WriteAt(1,1,white,'* 1,1 (original)');
  982.                WriteAt(5,5,white,'* 5,5 (original)');
  983.                SetWindow(20,8,60,15);
  984.                Clear(31,' ');
  985.                WriteAt(1,1,lightcyan,'* 1,1 (in window)');
  986.                WriteAt(5,5,lightcyan,'* 5,5 (in window)');
  987.                WriteAt(20,7,Lightcyan,'This text is too long to fit!');
  988.                GotoXY(1,2);
  989.                TextColor(Lightcyan);
  990.                System.Writeln('Written with Turbo''s Writeln');
  991.                WasOn := WindowOff;   {disable the window}
  992.                WriteRight(80,23,white,'Written with WindowOff');
  993.                WindowOn;
  994.                WriteAt(1,8,lightcyan,'Window enabled again');
  995.                ResetWindow;
  996.                GotoXY(1,24);
  997.             end;
  998.          end.
  999.  
  1000.  
  1001.  
  1002.  
  1003. Figure 5.6                                                              [SCREEN]
  1004. ScreenOBJ Window
  1005. Commands
  1006.  
  1007.  
  1008.  
  1009.          Please note that the totWIN unit (discussed in chapter 7) provides
  1010.          formatted window support. The window features described in this section
  1011.  
  1012.  
  1013.  
  1014. 5-18                                                                User's Guide
  1015.  
  1016. --------------------------------------------------------------------------------
  1017.  
  1018.          simply influence the coordinates of where text is written. The rich
  1019.          windows implemented in totWIN save the underlying screen and restore
  1020.          the original contents when the window is removed.
  1021.  
  1022.  
  1023.  
  1024. Using Virtual Screens
  1025.  
  1026.          So far in this chapter, only the physical or visible screen has been
  1027.          discussed. Here we see that the totFAST unit also supports virtual
  1028.          screens.
  1029.  
  1030.          A virtual screen can be considered as an invisible screen - you may
  1031.          write to the virtual screen, but the changes are not visible on the
  1032.          display. A virtual screen can be copied (i.e. displayed) to the visible
  1033.          screen at any time.
  1034.  
  1035.          Virtual screens allow a programmer to build a number of "out of sight"
  1036.          screens which can be popped into view at a moment's notice. A good
  1037.          application is the preparation of help screens.
  1038.  
  1039.          After a virtual screen instance has been initialized with INIT, it must
  1040.          be created. A virtual screen can be created by one of two methods. A
  1041.          copy can be taken of the physical screen  using the method SAVE, or a
  1042.          new blank screen can be created with the method CREATE.
  1043.  
  1044.          Once you have created a virtual screen, you can write to it using the
  1045.          ScreenOBJ methods as described previously in this chapter. You can also
  1046.          set the screen windows and change the cursor location and shape. In
  1047.          fact, you can use all the ScreenOBJ methods described in the previous
  1048.          section - instead of affecting the visible screen, the virtual screen
  1049.          is updated. For example, the following code fragment creates a virtual
  1050.          screen, MyScreen, and writes to it:
  1051.  
  1052.                   with MyScreen do
  1053.                   begin
  1054.                      Init;
  1055.                      Create(80,25,' ');
  1056.                      WritePlain(1,1,'This is written to the virtual');
  1057.                      WritePlain(1,2,'screen, not the visible screen.');
  1058.                      GotoXY(20,20);
  1059.                      ....
  1060.                   end;
  1061.  
  1062.  
  1063.  
  1064. Saving the Visible Screen
  1065.  
  1066.          To create a screen which is a copy of the physical screen, initialize
  1067.          the instance and then call the Save method. For example:
  1068.  
  1069.  
  1070.  
  1071. Writing to the Screen                                                       5-19
  1072.  
  1073. --------------------------------------------------------------------------------
  1074.  
  1075.                   var Screen1: ScreenOBJ
  1076.  
  1077.                   begin
  1078.                      Screen1.Init;
  1079.                      Screen1.Save;
  1080.                      ....
  1081.                   end.
  1082.  
  1083.          All the text being displayed on the screen, together with the display
  1084.          attributes, is copied to the virtual screen. The virtual screen cursor
  1085.          is initially positioned in the same location as the real cursor.
  1086.  
  1087.  
  1088.  
  1089. Creating New Virtual Screens
  1090.  
  1091.          The Create method is used to create a new virtual screen without copy-
  1092.          ing the physical screen. The syntax of the Create method is as follows:
  1093.  
  1094.  
  1095.          Create(Width,Depth,Attr:byte);
  1096.  
  1097.          This method creates a virtual screen. The screen will be created Width
  1098.          characters wide and Depth lines deep. Any values in the range 1 to 255
  1099.          are acceptable. The screen is cleared or blanked, and the display
  1100.          attribute is set to Attr.
  1101.  
  1102.          The following code fragment shows how to create a virtual screen:
  1103.  
  1104.                   var Screen1: ScreenOBJ
  1105.  
  1106.                   begin
  1107.                      Screen1.Init;
  1108.                      Screen1.Create(100,150,white);
  1109.                      ....
  1110.                   end.
  1111.  
  1112.          Although normally you wouldn't need to call them, there are four func-
  1113.          tion methods which return information about the virtual screen. The
  1114.          syntax of these methods is as follows:
  1115.  
  1116.  
  1117.          ScreenPtr:pointer;
  1118.  
  1119.          Returns a pointer to the heap location of the virtual screen.
  1120.  
  1121.  
  1122.          Width:byte;
  1123.  
  1124.          Returns the width of the virtual screen in characters.
  1125.  
  1126.  
  1127.          Depth:byte;
  1128.  
  1129.          Returns how many lines deep the virtual screen is.
  1130.  
  1131.  
  1132. 5-20                                                                User's Guide
  1133.  
  1134. --------------------------------------------------------------------------------
  1135.  
  1136.          Exists: boolean;
  1137.  
  1138.          Only returns true when the virtual screen has been created.
  1139.  
  1140.  
  1141.  
  1142. Displaying a Virtual Screen
  1143.  
  1144.          The ScreenOBJ provides a number of methods for displaying all or part
  1145.          of a virtual screen, i.e. transferring the information from the virtual
  1146.          screen to the physical screen. A virtual screen can be instantly dis-
  1147.          played, or slid onto the display with interesting visual effects. Note
  1148.          that the coordinates specified in these methods are global coordinates,
  1149.          i.e. the methods ignore the current window settings.
  1150.  
  1151.          The syntax of the screen displaying methods is as follows:
  1152.  
  1153.  
  1154.          Display;
  1155.  
  1156.          This method instantly transfers the image stored on the virtual screen
  1157.          to the physical screen. If the virtual screen is smaller than the phys-
  1158.          ical screen, the virtual screen will be drawn at the top left of the
  1159.          display. If the virtual screen is larger than the physical screen, the
  1160.          upper-left portion of the virtual screen will be displayed.
  1161.  
  1162.  
  1163.          SlideDisplay(Way:tDirection);
  1164.  
  1165.          This method operates the same as Display, except the virtual screen
  1166.          sl i  d   e    s ... onto the screen -- just for the fun of it! The
  1167.          method is passed a single enumerated type parameter which may have one
  1168.          of the following values:
  1169.  
  1170.          Up         slides up onto the screen from the bottom
  1171.  
  1172.          Down       slides down onto the screen from the top
  1173.  
  1174.          Left       slides left onto the screen from the right
  1175.  
  1176.          Right      slides right onto the screen from the left
  1177.  
  1178.          Vert       slides inwards from the left and the right simultaneously
  1179.                     (like some drapes closing)
  1180.  
  1181.          Horiz      slides inwards from the top and the bottom simultaneously
  1182.                     (like teeth closing)
  1183.  
  1184.  
  1185.          PartDisplay(X1,Y1,X2,Y2,X,Y:byte);
  1186.  
  1187.          This method restores a rectangular portion of the virtual screen from
  1188.          virtual coordinates (X1,Y1) to (X2,Y2) and positions this information
  1189.          with the upper-left corner of the image position at physical coordi-
  1190.          nates (X,Y).
  1191.  
  1192.  
  1193. Writing to the Screen                                                       5-21
  1194.  
  1195. --------------------------------------------------------------------------------
  1196.  
  1197.          PartSlideDisplay(X1,Y1,X2,Y2:byte; Way:tDirection);
  1198.  
  1199.          This method is similar to PartDisplay, except that the image slides
  1200.          onto the display, and the image cannot be relocated, i.e. the image
  1201.          will be placed at coordinates (X1,Y1) on the physical screen.
  1202.  
  1203.  
  1204.  
  1205. Disposing of a Virtual Screen
  1206.  
  1207.          As with all Toolkit objects, the DONE method must be called when the
  1208.          virtual screen instance is no longer required. When Done is called, the
  1209.          memory reserved for the virtual screen is automatically released.
  1210.          Always call Done!
  1211.  
  1212.  
  1213.  
  1214. A Virtual Screen Example
  1215.  
  1216.          Listed below is an abbreviation of the demo program DEMVI1.PAS, which
  1217.          illustrates how to manage virtual screens and create interesting visual
  1218.          effects. We can't show the effects in a manual, so just run the pro-
  1219.          gram!
  1220.  
  1221.          Program DemoVirtualOne;
  1222.  
  1223.          Uses CRT, totFast;
  1224.  
  1225.          Var
  1226.            Screen1,
  1227.            Screen2,
  1228.            Screen3 : ScreenObj;   {screen objects}
  1229.            HeadCol,
  1230.            MsgCol,
  1231.            NormCol : byte;
  1232.  
  1233.          procedure Pause;
  1234.          {}
  1235.          var Ch : char;
  1236.          begin
  1237.             Ch := ReadKey;
  1238.          end; {of proc pause}
  1239.  
  1240.          procedure Initialize;
  1241.          {}
  1242.          begin
  1243.             Screen1.Init;
  1244.             Screen2.Init;
  1245.             Screen3.Init;
  1246.             HeadCol := Attr(yellow,blue);
  1247.             MsgCol  := Attr(yellow,red);
  1248.             NormCol := Attr(white,blue);
  1249.          end; {proc Initialize}
  1250.  
  1251.  
  1252.  
  1253.  
  1254. 5-22                                                                User's Guide
  1255.  
  1256. --------------------------------------------------------------------------------
  1257.  
  1258.          procedure IntroScreen;
  1259.          {}
  1260.          const
  1261.              Tab = 8;
  1262.          begin
  1263.             HeadCol := Attr(yellow,blue);
  1264.             MsgCol  := Attr(yellow,red);
  1265.             NormCol := Attr(white,blue);
  1266.             with Screen do {manipulate the visible screen}
  1267.             begin
  1268.                Clear(NormCol,' ');
  1269.                WriteCenter(1,HeadCol,'TechnoJock''s Object Toolkit');
  1270.                WritePlain(Tab,18,'the display.');
  1271.                WriteRight(80,25,MsgCol,'Press any key to continue ....');
  1272.             end;
  1273.          end; {of proc IntroScreen}
  1274.  
  1275.          procedure BuildScreen2;
  1276.          {}
  1277.          const
  1278.             Tab = 8; Tab1 = 10;
  1279.          begin
  1280.             HeadCol := Attr(yellow,red);
  1281.             MsgCol  := Attr(yellow,red);
  1282.             NormCol := Attr(white,red);
  1283.             with Screen2 do
  1284.             begin
  1285.                Create(80,25,NormCol);
  1286.                WriteCenter(1,HeadCol,'Screen Writing');
  1287.                WritePlain(Tab,6,'methods, including the following:');
  1288.                GotoXY(57,23);
  1289.             end;
  1290.          end; {of proc BuildScreen2}
  1291.  
  1292.          procedure BuildScreen3;
  1293.          {}
  1294.          const
  1295.             Tab = 8;
  1296.          begin
  1297.             HeadCol := Attr(yellow,blue);
  1298.             MsgCol  := Attr(yellow,red);
  1299.             NormCol := Attr(white,blue);
  1300.             with Screen3 do
  1301.             begin
  1302.                Create(80,25,NormCol);
  1303.                TitledBox(1,1,80,25,NormCol,HeadCol,NormCol,4,'|Box drawing');
  1304.                CursOff;
  1305.             end;
  1306.          end; {of proc BuildScreen3}
  1307.  
  1308.  
  1309.  
  1310. Writing to the Screen                                                       5-23
  1311.  
  1312. --------------------------------------------------------------------------------
  1313.  
  1314.          begin
  1315.             Initialize;
  1316.             IntroScreen;
  1317.             BuildScreen2;
  1318.             BuildScreen3;
  1319.             Pause;
  1320.             Screen1.Save;
  1321.             Screen2.SlideDisplay(horiz);
  1322.             Pause;
  1323.             Screen3.SlideDisplay(vert);
  1324.             Pause;
  1325.             with Screen do
  1326.             begin
  1327.                SmartHorizLine(1,80,14,white,1);
  1328.                SmartVertLine(35,8,19,white,2);
  1329.                SmartVertLine(64,10,19,white,2);
  1330.                WriteCenter(25,attr(black,white),'That''s all Folks!');
  1331.             end;
  1332.             Pause;
  1333.             Screen1.Done;
  1334.             Screen2.Done;
  1335.             Screen3.Done;
  1336.             ClrScr;
  1337.             Screen.CursOn;
  1338.          end.
  1339.