home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD1.mdf / pascal / library / dos / wct / xcrt.doc < prev    next >
Encoding:
Text File  |  1992-01-18  |  11.3 KB  |  304 lines

  1. Here is a fairly more descriptive list of the procedures & functions in my
  2. XCRT unit.
  3.  
  4. --
  5.  
  6. procedure beep(hz,dur: word);
  7.  
  8. This procedure will play a note (in hertz) for a duration of dur
  9. milliseconds. Usually beep(1000,100) is a good high-pitched, error tone.
  10.  
  11. procedure disablespeaker;
  12. procedure enablespeaker;
  13.  
  14. I don't think you'll need to use these two.
  15.  
  16. --
  17.  
  18. function getch(x,y: byte):char;
  19.  
  20. Returns the character at position (x,y)
  21.  
  22. function getattr(x,y: byte):byte;
  23.  
  24. Returns the color attribute at (x,y). You will see a lot about color
  25. attributes in this unit, so I will explain them now. Background colors may
  26. be 0-7, foreground colors may be 0-15. Blinking is either 0 (off) or 1
  27. (on). The color attribute is set as follows:
  28.  
  29. blink*128+background*16+foreground
  30.  
  31. For example, if you wanted to extract the foreground color from a color
  32. attribute at (x,y), that's forecol:=getattr(x,y) div 16.
  33.  
  34. procedure putch(x,y: byte; c: char);
  35.  
  36. Puts character c at position x,y. You might wonder if it uses the current
  37. color settings or not. This depends on the unit variable PreserveAttr
  38. (preserve attribute). When PreserveAttr is TRUE, any routine that puts
  39. characters to the screen keeps the same color attribute that is already
  40. there. When PreserveAttr is FALSE, it uses the current color settings.
  41.  
  42. procedure putattr(x,y:byte; attr:byte);
  43.  
  44. This procedure sets the color attribute at (x,y). You might wonder why this
  45. is useful. See AttrBlock for a demonstration.
  46.  
  47. function shadowattr(attr:byte):byte;
  48.  
  49. This procedure returns the proper shadowing attribute for a color
  50. attribute. This is useful for making windows with shadows. See ShadowBlock
  51. for a demonstration.
  52.  
  53. --
  54.  
  55. procedure writexy(x,y: byte; s: writexystring);
  56.  
  57. This writes a string (s), right-justified, to (x,y). Much easier than
  58. gotoxy(x,y); write(s);
  59.  
  60. procedure rightjust(x,y: byte; s: writexystring);
  61.  
  62. This right-justifies a string s at (x,y)
  63.  
  64. procedure centerjust(x,y:byte; s:writexystring);
  65.  
  66. This centers a string s about (x,y)
  67.  
  68. --
  69.  
  70. procedure textbox(x1,y1,x2,y2: word; border:byte);
  71.  
  72. This procedure draws a textbox with the corners (x1,y1) and (x2,y2) with a
  73. bordertype of border. See the borders listed in the CONST section of XCRT.
  74. For example, if you wanted to put a box around the entire screen of double
  75. thickness, textbox(1,1,80,25,doubleborder) is what you want.
  76.  
  77. procedure textline(startat,endat,c:word; attr:byte);
  78.  
  79. This draws a line between two points. If the line is horizontal, startat
  80. and endat are the two x values and c is the constant y. If the line is
  81. vertical, startat and endat are the two y values and x is the constant x.
  82. Attr is the type of line - again, see the line types in the CONST section.
  83.  
  84. --
  85.  
  86. procedure colorblock(x1,y1,x2,y2: word; c:byte);
  87.  
  88. This procedure fills a block with a solid character of the current
  89. foreground color.
  90.  
  91. procedure fillblock(x1,y1,x2,y2:word; ch:char);
  92.  
  93. Fills a region with the specified character. This is useful step #1 in
  94. drawing windows. For example, if we wanted to draw a window with a box
  95. around it from (3,3) to (10,7), here is some code to do it:
  96.  
  97. textattr:=red*16+yellow; { another way of setting colors at same time }
  98. fillblock(3,3,10,7,' ');
  99. textbox(3,3,10,7,singleborder);
  100.  
  101. procedure shadowblock(x1,y1,x2,y2:word);
  102.  
  103. This procedure shadows a region. To extend the above example, if we want to
  104. shadow what's underneath it, you add the line shadowblock(4,4,10,8) before
  105. the FillBlock. Even better would be shadowblock(5,3,11,8) because the
  106. characters are much taller than they are wide. The function shadowattr is
  107. also available if you want to write your own shadowing routines in your
  108. programs.
  109.  
  110. procedure attrblock(x1,y1,x2,y2:word; attr:byte);
  111.  
  112. Sets the color attributes for an entire region of the screen. This can be
  113. incredibly useful when used in conjunction with PreserveAttr. For example,
  114. you are writing a program in which there are specific areas that always use
  115. the same color settings. The top line is always white on red. The left is
  116. always lightgray on black. The right is always cyan on blue, and the bottom
  117. line is always yellow on magneta. Admittedly, these may be horrible color
  118. settings, but it's only an example... You will also be constantly writing
  119. things all over the screen. It becomes a big pain in the butt to constantly
  120. keep setting textattr every time you are writing on the screen. Remember,
  121. though, that if PreserveAttr is set to TRUE, it ignores the current
  122. TextAttr setting and preserves the color attributes for where you are
  123. writing. You can take advantage of this fact by setting the color
  124. attributes for regions of the screen ONCE at the beginning of the program,
  125. set PreserveAttr to TRUE (it's defaulted to FALSE), and you're all set. For
  126. our example, that would accomplished as follows:
  127.  
  128. attrblock(1,1,80,1,red*16+white); { top line }
  129. attrblock(1,2,40,24,black*16+lightgray); { left }
  130. attrblock(41,2,80,24,blue*16+cyan); { right }
  131. attrblock(1,25,80,25,magenta*16+yellow); { bottom }
  132.  
  133. procedure scrollblockup(x1,y1,x2,y2,wakeattr:byte);
  134. procedure scrollblockdown(x1,y1,x2,y2,wakeattr:byte);
  135.  
  136. Scrolls a region of the screen up or down one row. When it scrolls, though,
  137. it loses a line from the end, and often you want that line replaced by
  138. something. You can set WakeAttr to tell it what color setting to leave in
  139. place of the last line that was scrolled.
  140.  
  141. procedure explodeblock(x1,y1,x2,y2:byte);
  142.  
  143. This draws a block just like fillblock(x1,y1,x2,y2,' ') except that it
  144. draws it so it looks like it's blowing up from the middle. It looks cool
  145. the first few times you use it, then it gets annoying.
  146.  
  147. --
  148.  
  149. function readallkeys:char;
  150.  
  151. This returns ANY key that you pressed. See the unit KEYDEF for the names of
  152. all the "special" keys, like F1, enter, esc, insert, delete, backspace,
  153. CTRL-F4, etc. Ch:=readallkeys will return the key that was pressed.
  154.  
  155. function yesorno:char;
  156.  
  157. Since so many programs use a repeat-until to answer this common question, I
  158. made it a function returning 'Y' or 'N'. It does not output or return lower
  159. case.
  160.  
  161. function getoneof(s:getoneofstring):char;
  162.  
  163. This extremely handy procedure is good for getting one or several specific
  164. keys but not accepting any others. For example, upcase(getoneof('YyNn')) is
  165. the same thing as YesOrNo. Or something more useful, say you want to wait
  166. for the user to push ENTER, ESC, F1, F2, or any number,
  167. getoneof(enter+esc+f1+f2+'0123456789') is the correct command. It simply
  168. gets characters until the character is contained in the string you sent in.
  169.  
  170. --
  171.  
  172. function getcursor:word;
  173.  
  174. Returns the current cursor setting.
  175.  
  176. procedure setcursor(curs:word);
  177.  
  178. Sets the cursor. Setcursor(cursorunderline) makes the cursor the normal
  179. underscore. Setcursor(cursorhalfblock) makes the cursor a sort of square.
  180. Setcursor(cursorblock) makes the cursor a large rectangle.
  181. Setcursor(cursoroff) turns the cursor off.
  182.  
  183. --
  184.  
  185. procedure writewindow(fn: string; var w: block);
  186.  
  187. Writes a "window" to disk.
  188.  
  189. procedure readwindow(fn: string; var w: block);
  190.  
  191. Reads a window from disk.
  192.  
  193. procedure savewindow(x1,y1,x2,y2: word; var w: block);
  194.  
  195. Saves a portion of the screen into what is known as a block. In the example
  196. about drawing windows with a shadow, we overlooked one very important
  197. detail. You lose whatever is underneath the window you draw. You need to
  198. save that region, draw over it, the restore it when you're done. So, first
  199. to save it... savewindow(3,3,11,8,w). Block is a type in the unit. A block
  200. is basically a rectangular region of a screen (in CRT mode). You usually do
  201. not access the fields of a block. A window is composed of a block, but it
  202. also contains the number of rows and columns. It is used only as a whole
  203. entity. Modifying the fields of a block can have fatal results. Now you are
  204. free to draw your window, and you recall it when necessary.
  205.  
  206. procedure killwindow(var w:block);
  207.  
  208. SaveWindow uses memory from the heap to store the block. A block should be
  209. disposed of when possible. So after you restore the screen underneath (see
  210. example after RecallWindow), you should kill the window with killwindow(w).
  211.  
  212. NOTE: DO NOT kill a window that 1. hasn't been created with a savewindow or
  213. 2. has been killed previously. It WILL crash your program.
  214.  
  215. procedure drawstrip(w:block; x1,y1:byte; row:byte; x2,x3:byte);
  216.  
  217. Draws a horizontal strip (at y-coorindate row, with x limits x2-x3) of a
  218. block (w) with upper-left hand corner x1,y1.  This is the basis for all of
  219. the other fancy ways of drawing a window.  For example, RecallWindow can
  220. be written as:
  221.  
  222. for i:=<y1> to <y1>+w.rows-1 do
  223.   drawstrip(w,<x1>,<y1>,i,<x1>,<x1>+w.cols-1)
  224.  
  225. The others are fairly more complicated.  With a little effort, you can
  226. create all sorts of ways to redraw windows.
  227.  
  228. procedure recallwindow(x1,y1:word; var w: block);
  229.  
  230. Recalls a block to the screen. It recalls it with the upper-left hand
  231. corner at (x1,y1). You can use this to make multiple copies of an image if
  232. you wish. Now let's put the entire example we've been compiling together.
  233.  
  234. { save screen }
  235. savewindow(3,3,12,8,w);
  236. { draw window }
  237. shadowblock(5,4,12,8);  { Draws "shadow" underneath window }
  238. textattr:=red*16+white; (* PreserveAttr is FALSE *)
  239. fillblock(3,3,10,7,' ');
  240. textbox(3,3,10,7,singleborder);
  241. (* Do whatever you need to do inside the window *)
  242. { restore screen }
  243. recallwindow(3,3,w);
  244. { deallocate memory used by w }
  245. killwindow(w);
  246.  
  247. procedure explodewindow(x1,y1: byte; w: block);
  248.  
  249. Very similar to RecallWindow, except that it explodes the window instead of
  250. simply drawing it.  It basically draws it from the inside-out.  It's best
  251. illustrated by trying it out.
  252.  
  253. procedure crunchwindow(x1,y1: byte; w: block);
  254.  
  255. The opposite of ExplodeWindow, CrunchWindow draws a window from the
  256. outside-in.
  257.  
  258. Here's how SaveWindow, WriteWindow, ReadWindow, ExplodeWindow, and
  259. CrunchWindow can all be used to make a software package look very
  260. professional.  Say you have a program with some complex pop-up windows.
  261. Here's what you do:
  262.  
  263. 1. In a separate program, design the pop-up window, capture it
  264.    (SaveWindow), and write it to disk (WriteWindow).
  265. 2. In the main program, read the window in (ReadWindow).  Now you can
  266.    display it at will.  Your program isn't bogged down with holding the
  267.    details of how the pop-up window was drawn.
  268. 3. When you are ready to display the pop-up, save the area where the pop-up
  269.    will be displayed into another block (SaveWindow).  Then display the
  270.    pop-up using ExplodeWindow.  When you are ready to restore the original
  271.    portion of the screen, draw the original portion using CrunchWindow.  I
  272.    think you'll be pleased with the results.  If it's too fast for you to
  273.    see, try setting ExplodeSteps higher before the entire process.  You can
  274.    reset it once you see the effect.
  275.  
  276. --
  277.  
  278. function getfont:byte;
  279. procedure setfont(font:byte);
  280.  
  281. Ignore these.
  282.  
  283. --
  284.  
  285. function getvideomode:byte; procedure setvideomode(mode:byte);
  286.  
  287. Ignore these too.
  288.  
  289. --
  290.  
  291. procedure xcrtinit;
  292.  
  293. While you're at it, ignore this as well. For some reason, I had to put this
  294. in the interface section. You shouldn't use in the program at all. It could
  295. likely screw things up.
  296.  
  297.  
  298. A few words from the author...
  299.  
  300. This unit can save you tremendous amounts of time by reducing what was
  301. before a tedious chore to a mere one or two lines. I would recommend highly
  302. to anyone who intends to do any more work with Pascal to keep this unit! It
  303. makes life infinitely simpler.
  304.