home *** CD-ROM | disk | FTP | other *** search
/ ProfitPress Mega CDROM2 …eeware (MSDOS)(1992)(Eng) / ProfitPress-MegaCDROM2.B6I / PROG / DJGPP / DJDOC106.ZIP / DOCS / LIBGR.DOC < prev    next >
Encoding:
Text File  |  1991-04-18  |  11.3 KB  |  283 lines

  1. /* History:165,56 */
  2. This is file libgr.doc
  3.  
  4. Contents:
  5.  
  6. * General information
  7. * C functions
  8. * C++ objects
  9. * Mouse functions
  10.  
  11. All libgr.a functions are prototyped in <graphics.h> and <mouse.h>
  12.  
  13.  
  14.  
  15.  
  16.  
  17. General Information:
  18.  
  19. The DOS extender understands the paging methods used by Super VGA's, and
  20. liks that into the general paging mechanism it uses to provide virtual
  21. memory.  Most Super VGA's can present 64K of video memory at one time
  22. through the AT channel when in 256 color mode.  The extender uses the
  23. page table entries of the 386 to trap on accesses to pages that aren't
  24. mapped, while allowing accesses to memory corresponding to mapped memory.
  25. When an access is made to unmapped memory, the extender traps it, selects
  26. another graphics range to map, changes the present bits in the page
  27. table, and retries the instruction.  This makes the graphics memory
  28. appear to be a linear range of up to 1Mb of memory at 0xD0000000.
  29. Because swapping pages takes more time than not swapping (but not much;
  30. that swapping is done in protected mode without a mode switch), it follows
  31. that drawing horizontal lines is faster then vertical, and updating regions
  32. should be donw by rows, not columns, to minimize the number of swaps
  33. required.
  34.  
  35. Only 256 color modes are supported, 16 color modes are not.  All r,g,b
  36. values are in the range 0..255 (they wrap, so 256 == 0).  All color
  37. indexes are also in the range 0..255, but if bit 8 is set ("GrXOR"),
  38. then the color is XOR'd against the pixel already there.  All graphics
  39. operations support the XOR feature.  XORing the color zero is, in effect,
  40. a no-operation, as zero XOR anything is the same as before.
  41.  
  42. Some Super VGA's allow one range of memory to be mapped for reading and a
  43. different one for writing.  The extender uses this mode for quickly moving
  44. memory around on the screen by mapping the range 0xD0100000 to 0xD01FFFFF
  45. to be the "read-only" video memory, and 0xD0200000 to 0xD02FFFFF to be the
  46. "write-only" video memory, switching back to the primary range for normal
  47. read-write operation.  This mode is designed specifically for the Blit
  48. function (C++).  If a card does not support this mode, blit performance
  49. may suffer slightly.  It is recommended that a memory GrRegion (see below)
  50. be used for storage of images that are to be blitted around on the screen;
  51. they are much faster than screen-to-screen blits.
  52.  
  53. The following practices are recommended to maximize performance:
  54.  
  55. * Use screen-to-screen blits when the image will be blitted once, or when
  56.   the images are small.
  57. * Store images in memory GrRegions if they will be copied more than once.
  58. * Use memory GrRegions to create complex images, then blit them onto the
  59.   screen when needed. (see the C++ section for information about GrRegions).
  60. * Copy blits are faster than XOR blits, by a large margin.
  61.  
  62.  
  63.  
  64.  
  65.  
  66.  
  67. C Functions:
  68.  
  69. GrSetMode(m, w, h) puts the screen into a text or graphics mode.  See the
  70.   <graphics.h> file for a list of supported mode types.  Whenever you switch
  71.   to a graphics mode, the palette is configured according to allocated
  72.   colors.  When switching to a text mode, the palette is not initialized.
  73.   It is strongly recommended that you use the GR_default_graphics and
  74.   GR_default_text modes to switch to graphics and text.  This allows the
  75.   user to select a favorite resolution.  It is important that you do NOT
  76.   assume that you will get the mode you ask for!  You may ask for a mode
  77.   that the card does not support, and will be given a lower resolution mode.
  78.  
  79. GrSetColor(n, r, g, b) - Set the red, green, blue values of a specific
  80.   color index
  81.  
  82. GrAllocColor(r, g, b) - Allocate a color cell read-only.  Other calls to
  83.   this function with the same r,g,b will return the same pixel value.
  84.  
  85. GrAllocCell() - allocate a cell for read-write (write via GrSetColor()).
  86.  
  87. GrQueryColor(n, &r, &g, &b) - Query the r,g,b values of a given color cell.
  88.  
  89. GrFreeColor(n) - free a cell from a previous AllocColor or AllocCell call.
  90.   If the cell is allocated twice, two frees are required to free it.
  91.  
  92. GrBlack() - the value of a "black" pixel (set to 0 by libgr.a).
  93. GrWhite() - the value of a "white" pixel (set to 1 by libgr.a).
  94.  
  95. NOTE: The functions GrXxxx() below (C linkage) operate only on the
  96. graphics screen, with (0,0) at the upper left, and clip only at the edge.
  97.  
  98. GrPlot(x,y,c) - plot point (x,y) in color 'c' on the screen
  99. GrPixel(x,y) - return the pixel value at (x,y)
  100. GrMaxX() - maximum valid X value
  101. GrMaxY() - maximum valid Y value
  102. GrSizeX() - number of pixels across
  103. GrSizeY() - number of pixels up/down.
  104. GrLine(x1,y1,x2,y2,c) - draw a line.
  105. GrText(x,y,str,fg,bg) - draw text (8x16 font), upper left of text at (x,y)
  106.  
  107.  
  108.  
  109.  
  110.  
  111.  
  112. C++ functions:
  113.  
  114. The GrRegion class provides a much more robust interface to the screen by
  115. the use of screen and memory regions that the drawing primitives operate
  116. on.  Thus, you can create a memory region (new GrRegion(width,height)),
  117. draw an image on it, and blit it to the physical screen when needed.
  118. As far as the methods are concerned, there is no difference between a
  119. memory region and a visible region (except speed and visibility).
  120. GrRegions provide automatic coordinate translation and clipping and
  121. store constant information about the region to enhance performance.
  122.  
  123. Creating and destroying GrRegions are very quick operations, and the
  124. information they store makes programming very simple, so the use
  125. of GrRegions (versus doing clipping/translating yourself) is recommended.
  126. Even memory GrRegions are inexpensive.
  127.  
  128. GrScreenRegion() is a special function that returns a GrRegion encompassing
  129. the entire visible graphics screen.  Subregions off this GrRegion provide
  130. viewports onto the graphics screen.  You must call this function again if
  131. you use GrSetMode() to change the screen mode (all GrRegions are useless if
  132. you change screen modes).
  133.  
  134. To create a visible GrRegion, you must start with a visible GrRegion
  135. (hence the GrScreenRegion() function) and take a SubRegion() of it.
  136.  
  137. To create a memory GrRegion, simply instance a new GrRegion of the
  138. appropriate width and height, or take a SubRegion() of another
  139. memory GrRegion.
  140.  
  141. SubRegions are used to provide alternate clipping/translating sets for a
  142. given region.  SubRegions share data with all other GrRegions derived
  143. from the same top-level region.  The GrRegion methods DO NOT prevent
  144. one region from writing into the data of another.
  145.  
  146. To move data around in a region, or from one region to another, use the
  147. Blit functions.  They both take a source and destination GrRegion,
  148. an offset from (0,0) in the destination GrRegion, and a Blit function to
  149. perform.  Currently, the only BlitFuncs available are copy (BlitSrc),
  150. no operation (BlitDest), or XOR (BlitXor).  One of the Blit functions
  151. allows you to specify a subset of the source region as the actual source.
  152. Internally, Blit creates two new GrRegions that are the actual source
  153. and destination regions to perform the actual copy, then destroy them
  154. when the copy is done.
  155.  
  156.  
  157. GrRegion, the object:
  158.  
  159. NOTE: All methods work exactly the same, regardless of what type of
  160. region the object represents.
  161.  
  162.  
  163. flags - If set to 1, the destructor will free() the memory pointed to
  164.   by data.  The contructor normally handles this.
  165.  
  166. color - the default foreground color to use if unspecified.  The default
  167.   background color (for GrText()) is "transparent".
  168.  
  169. parent - NULL for new regions, else the region this was created from.
  170. rel_x, rel_y - coordinates of (0,0) relative to immediate parent.
  171. abs_x, abs_y - coordinates of (0,0) relative to topmost parent.
  172.  
  173. width - the width of the GrRegion.
  174. height - the height of the GrRegion.
  175. row_scale - the offset of the beginning of each row relative to the row
  176.   above it.  This is used for subregions and indexing the data pointers.
  177.  
  178. data - pointer to the data of the region.  (0,0) is at data[0], (1,0) at
  179.   data[1], (0,1) at data[row_scale].
  180. rdata - pointer used for the read half of a bcopy().  Same as data for
  181.   memory regions, but may be different for graphic regions.
  182. wdata - pointer used for the write half of a bcopy().  Same as data for
  183.   memory regions, but may be different for graphic regions.
  184.  
  185. GrRegion() - creates an "empty" region that can be attached to non-region
  186.   data, such as from a file.
  187. GrRegion(width, height) - returns a memory region.
  188. ~GrRegion() - destroys a region, freeing memory if needed.
  189.  
  190. SubRegion(x,y,width,height) - Creates a subregion of the given region.
  191.  
  192. MaxX() - maximum valid X coordinate before clipping happens.
  193. MaxY() - maximum valid Y coordinate before clipping happens.
  194. SizeX() - number of pixels across.
  195. SizeY() - number of pixels up/down.
  196.  
  197. Plot(x, y [,c]) - plot the given point in the given color, or the default color
  198.   if one is not given.
  199. Line(x1, y1, x2, y2 [,c]) - draw a line from (x1,y1) to (x2,y2).
  200. HLine(x1, x2, y [,c]) - optimized horizontal line.
  201. VLine(x, y1, y2 [,c]) - optimized vertical line.
  202. Rectangle(x1, y1, x2, y2 [,c]) - draw a retangle (unfilled).  Corners will
  203.   be drawn only once each (for XORing colors).
  204. Box(x, y, width, height [,c]) - filled box.
  205. Text(x, y, string [,fg [,bg]]) - Text.  Font is 8x16, (x,y) represents the
  206.   upper left corner.  if fg not given, color used.  If bg not given,
  207.   transparent used.
  208. Point(x,y) - return the pixel value at (x,y).
  209.  
  210.  
  211.  
  212.  
  213.  
  214.  
  215. Mouse Functions:
  216.  
  217.  
  218. MouseGetEvent(flags, event)
  219.   int flags;
  220.   MouseEvent *event;
  221.  
  222. The focal point of the mouse routines is the function MouseGetEvent().
  223. It takes a set of desired events, specified by manifest constants from
  224. <mouse.h> set in the "flags" parameter.  It returns a specific event in
  225. the structure passed as the second parameter.  The available events are:
  226.  
  227.  
  228. M_LEFT_DOWN    the left mouse button is pressed
  229. M_LEFT_UP    the left mouse button is released
  230. M_MIDDLE_DOWN    the middle mouse button is pressed
  231. M_MIDDLE_UP    the middle mouse button is released
  232. M_RIGHT_DOWN    the right mouse button is pressed
  233. M_RIGHT_UP    the right mouse button is released
  234. M_MOTION    the mouse moves
  235. M_KEYPRESS    a key is pressed
  236. M_BUTTON_DOWN    any button is pressed (the event says which)
  237. M_BUTTON_UP    any button is released (the event says which)
  238.  
  239. M_NOPAINT    don't paint the mouse, just return the event.  Useful for
  240.         developing an alternative mouse handler.
  241. M_POLL        return current mouse information without waiting.
  242.  
  243.  
  244. The "event" fields are:
  245.  
  246.   flags - specify the event that happened
  247.   x,y - where the mouse was when the event happened, relative to the
  248.     physical screen (no GrRegion support yet).
  249.   buttons - the mouse buttons that are depressed when the event happened
  250.       M_LEFT, M_MIDDLE, and M_RIGHT specify the bits in "buttons".
  251.   key - the key that was pressed, if flags & M_KEYPRESS.  For Alt'd or
  252.       function keys, returns 0x100 + scan code (bios INT 16h, AH ret).
  253.  
  254. Example:
  255.  
  256. draw()
  257. {
  258.   MouseEvent e;
  259.   while (1)
  260.   {
  261.     MouseGetEvent(M_MOTION|M_RIGHT_DOWN|M_KEYPRESS, &e);
  262.     if (e.flags & M_RIGHT_DOWN)
  263.       return -1;
  264.     if (e.flags & M_KEYPRESS)
  265.       return e.key;
  266.     GrPlot(e.x, e.y);
  267.   }
  268. }
  269.  
  270.  
  271. MouseSetColors(fg, bg) - set the foreground and background colors for
  272.   the mouse.  The current library does not allow the shape of the pointer
  273.   to be changed without recompiling the library.
  274.  
  275. MouseWarp(x, y) - instantly move the mouse to position (x,y).
  276.  
  277.  
  278.  
  279.  
  280. As a convenience, the libpc.a functions kbhit() and getkey() are included
  281. in libgr.a as well (the mouse functions use them).
  282.  
  283.