You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1593 lines
62 KiB

5 years ago
  1. /* --COPYRIGHT--,BSD
  2. * Copyright (c) 2013, Texas Instruments Incorporated
  3. * All rights reserved.
  4. *
  5. * Redistribution and use in source and binary forms, with or without
  6. * modification, are permitted provided that the following conditions
  7. * are met:
  8. *
  9. * * Redistributions of source code must retain the above copyright
  10. * notice, this list of conditions and the following disclaimer.
  11. *
  12. * * Redistributions in binary form must reproduce the above copyright
  13. * notice, this list of conditions and the following disclaimer in the
  14. * documentation and/or other materials provided with the distribution.
  15. *
  16. * * Neither the name of Texas Instruments Incorporated nor the names of
  17. * its contributors may be used to endorse or promote products derived
  18. * from this software without specific prior written permission.
  19. *
  20. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  21. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  22. * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  23. * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  24. * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  25. * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  26. * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
  27. * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
  28. * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
  29. * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
  30. * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  31. * --/COPYRIGHT--*/
  32. #ifndef __GRLIB_H__
  33. #define __GRLIB_H__
  34. #define NDEBUG
  35. #include "assert.h"
  36. //*****************************************************************************
  37. //
  38. //! \addtogroup primitives_api
  39. //! @{
  40. //
  41. //*****************************************************************************
  42. //*****************************************************************************
  43. //
  44. // If building with a C++ compiler, make all of the definitions in this header
  45. // have a C binding.
  46. //
  47. //*****************************************************************************
  48. #ifdef __cplusplus
  49. extern "C"
  50. {
  51. #endif
  52. //*****************************************************************************
  53. //
  54. //! This structure defines the characteristics of a Bitmap Image
  55. //
  56. //*****************************************************************************
  57. typedef struct
  58. {
  59. //
  60. //! Bits per pixel and Compressed/Uncompressed
  61. //
  62. unsigned char BPP;
  63. //
  64. //! X size
  65. //
  66. unsigned int XSize;
  67. //
  68. //! Y size
  69. //
  70. unsigned int YSize;
  71. //
  72. //! Number of Colors in Palette
  73. //
  74. unsigned int NumColors;
  75. //
  76. //! Pointer to Palette
  77. //
  78. const unsigned long * pPalette;
  79. //
  80. //! Pointer to pixel data
  81. //
  82. const unsigned char * pPixel;
  83. }
  84. tImage;
  85. //*****************************************************************************
  86. //
  87. //! This structure defines the extents of a rectangle. All points greater than
  88. //! or equal to the minimum and less than or equal to the maximum are part of
  89. //! the rectangle.
  90. //
  91. //*****************************************************************************
  92. typedef struct
  93. {
  94. //
  95. //! The minimum X coordinate of the rectangle.
  96. //
  97. short sXMin;
  98. //
  99. //! The minimum Y coordinate of the rectangle.
  100. //
  101. short sYMin;
  102. //
  103. //! The maximum X coordinate of the rectangle.
  104. //
  105. short sXMax;
  106. //
  107. //! The maximum Y coordinate of the rectangle.
  108. //
  109. short sYMax;
  110. }
  111. tRectangle;
  112. //*****************************************************************************
  113. //
  114. //! This structure defines the characteristics of a display driver.
  115. //
  116. //*****************************************************************************
  117. typedef struct
  118. {
  119. //
  120. //! The size of this structure.
  121. //
  122. long lSize;
  123. //
  124. //! A pointer to display driver-specific data.
  125. //
  126. void *pvDisplayData;
  127. //
  128. //! The width of this display.
  129. //
  130. unsigned short usWidth;
  131. //
  132. //! The height of this display.
  133. //
  134. unsigned short usHeight;
  135. //
  136. //! A pointer to the function to draw a pixel on this display.
  137. //
  138. void (*pfnPixelDraw)(void *pvDisplayData, int lX, int lY,
  139. unsigned int ulValue);
  140. //
  141. //! A pointer to the function to draw multiple pixels on this display.
  142. //
  143. void (*pfnPixelDrawMultiple)(void *pvDisplayData, int lX, int lY,
  144. int lX0, int lCount, int lBPP,
  145. const unsigned char *pucData,
  146. const unsigned int *pucPalette);
  147. //
  148. //! A pointer to the function to draw a horizontal line on this display.
  149. //
  150. void (*pfnLineDrawH)(void *pvDisplayData, int lX1, int lX2, int lY,
  151. unsigned int ulValue);
  152. //
  153. //! A pointer to the function to draw a vertical line on this display.
  154. //
  155. void (*pfnLineDrawV)(void *pvDisplayData, int lX, int lY1, int lY2,
  156. unsigned int ulValue);
  157. //
  158. //! A pointer to the function to draw a filled rectangle on this display.
  159. //
  160. void (*pfnRectFill)(void *pvDisplayData, const tRectangle *pRect,
  161. unsigned int ulValue);
  162. //
  163. //! A pointer to the function to translate 24-bit RGB colors to
  164. //! display-specific colors.
  165. //
  166. unsigned int (*pfnColorTranslate)(void *pvDisplayData,
  167. unsigned long ulValue);
  168. //
  169. //! A pointer to the function to flush any cached drawing operations on
  170. //! this display.
  171. //
  172. void (*pfnFlush)(void *pvDisplayData);
  173. //
  174. //! A pointer to the function to clears Display. Contents of display buffer
  175. //! unmodified
  176. //
  177. void (*pfnClearDisplay)(void *pvDisplayData, unsigned int ulValue);
  178. }
  179. tDisplay;
  180. //*****************************************************************************
  181. //
  182. //! This structure describes a font used for drawing text onto the screen.
  183. //
  184. //*****************************************************************************
  185. typedef struct
  186. {
  187. //
  188. //! The format of the font. Can be one of FONT_FMT_UNCOMPRESSED or
  189. //! FONT_FMT_PIXEL_RLE.
  190. //
  191. unsigned char ucFormat;
  192. //
  193. //! The maximum width of a character; this is the width of the widest
  194. //! character in the font, though any individual character may be narrower
  195. //! than this width.
  196. //
  197. unsigned char ucMaxWidth;
  198. //
  199. //! The height of the character cell; this may be taller than the font data
  200. //! for the characters (to provide inter-line spacing).
  201. //
  202. unsigned char ucHeight;
  203. //
  204. //! The offset between the top of the character cell and the baseline of
  205. //! the glyph. The baseline is the bottom row of a capital letter, below
  206. //! which only the descenders of the lower case letters occur.
  207. //
  208. unsigned char ucBaseline;
  209. //
  210. //! The offset within pucData to the data for each character in the font.
  211. //
  212. unsigned short pusOffset[96];
  213. //
  214. //! A pointer to the data for the font.
  215. //
  216. const unsigned char *pucData;
  217. }
  218. tFont;
  219. //*****************************************************************************
  220. //
  221. //! This is a newer version of the structure which describes a font used
  222. //! for drawing text onto the screen. This variant allows a font to contain an
  223. //! arbitrary, contiguous block of codepoints from the 256 basic characters in
  224. //! an ISO8859-n font and allows support for accented characters in Western
  225. //! European languages and any left-to-right typeface supported by an ISO8859
  226. //! variant. Fonts encoded in this format may be used interchangeably with the
  227. //! original fonts merely by casting the structure pointer when calling any
  228. //! function or macro which expects a font pointer as a parameter.
  229. //
  230. //*****************************************************************************
  231. typedef struct
  232. {
  233. //
  234. //! The format of the font. Can be one of FONT_FMT_EX_UNCOMPRESSED or
  235. //! FONT_FMT_EX_PIXEL_RLE.
  236. //
  237. unsigned char ucFormat;
  238. //
  239. //! The maximum width of a character; this is the width of the widest
  240. //! character in the font, though any individual character may be narrower
  241. //! than this width.
  242. //
  243. unsigned char ucMaxWidth;
  244. //
  245. //! The height of the character cell; this may be taller than the font data
  246. //! for the characters (to provide inter-line spacing).
  247. //
  248. unsigned char ucHeight;
  249. //
  250. //! The offset between the top of the character cell and the baseline of
  251. //! the glyph. The baseline is the bottom row of a capital letter, below
  252. //! which only the descenders of the lower case letters occur.
  253. //
  254. unsigned char ucBaseline;
  255. //
  256. //! The codepoint number representing the first character encoded in the
  257. //! font.
  258. //
  259. unsigned char ucFirst;
  260. //
  261. //! The codepoint number representing the last character encoded in the
  262. //! font.
  263. //
  264. unsigned char ucLast;
  265. //
  266. //! A pointer to a table containing the offset within pucData to the data
  267. //! for each character in the font.
  268. //
  269. const unsigned short *pusOffset;
  270. //
  271. //! A pointer to the data for the font.
  272. //
  273. const unsigned char *pucData;
  274. }
  275. tFontEx;
  276. //*****************************************************************************
  277. //
  278. //! Indicates that the font data is stored in an uncompressed format.
  279. //
  280. //*****************************************************************************
  281. #define FONT_FMT_UNCOMPRESSED 0x00
  282. //*****************************************************************************
  283. //
  284. //! Indicates that the font data is stored using a pixel-based RLE format.
  285. //
  286. //*****************************************************************************
  287. #define FONT_FMT_PIXEL_RLE 0x01
  288. //*****************************************************************************
  289. //
  290. //! A marker used in the ucFormat field of a font to indicates that the font
  291. //! data is stored using the new tFontEx structure.
  292. //
  293. //*****************************************************************************
  294. #define FONT_EX_MARKER 0x80
  295. //*****************************************************************************
  296. //
  297. //! Indicates that the font data is stored in an uncompressed format and uses
  298. //! the tFontEx structure format.
  299. //
  300. //*****************************************************************************
  301. #define FONT_FMT_EX_UNCOMPRESSED (FONT_FMT_UNCOMPRESSED | FONT_EX_MARKER)
  302. //*****************************************************************************
  303. //
  304. //! Indicates that the font data is stored using a pixel-based RLE format and
  305. //! uses the tFontEx structure format.
  306. //
  307. //*****************************************************************************
  308. #define FONT_FMT_EX_PIXEL_RLE (FONT_FMT_PIXEL_RLE | FONT_EX_MARKER)
  309. //*****************************************************************************
  310. //
  311. //! Value to automatically draw the entire length of the string
  312. //! (subject to clipping)
  313. //
  314. //*****************************************************************************
  315. #define AUTO_STRING_LENGTH -1
  316. //*****************************************************************************
  317. //
  318. //! Value to draw text opaque
  319. //! The text foreground and background are drawn together
  320. //
  321. //*****************************************************************************
  322. #define OPAQUE_TEXT 1
  323. //*****************************************************************************
  324. //
  325. //! Value to draw text transparently
  326. //! The text only (no background) is drawn
  327. //
  328. //*****************************************************************************
  329. #define TRANSPARENT_TEXT 0
  330. //*****************************************************************************
  331. //
  332. //! Indicates that the image data is not compressed and represents each pixel
  333. //! with a single bit.
  334. //
  335. //*****************************************************************************
  336. #define IMAGE_FMT_1BPP_UNCOMP 0x01
  337. //*****************************************************************************
  338. //
  339. //! Indicates that the image data is not compressed and represents each pixel
  340. //! with two bits.
  341. //
  342. //*****************************************************************************
  343. #define IMAGE_FMT_2BPP_UNCOMP 0x02
  344. //*****************************************************************************
  345. //
  346. //! Indicates that the image data is not compressed and represents each pixel
  347. //! with four bits.
  348. //
  349. //*****************************************************************************
  350. #define IMAGE_FMT_4BPP_UNCOMP 0x04
  351. //*****************************************************************************
  352. //
  353. //! Indicates that the image data is not compressed and represents each pixel
  354. //! with eight bits.
  355. //
  356. //*****************************************************************************
  357. #define IMAGE_FMT_8BPP_UNCOMP 0x08
  358. //*****************************************************************************
  359. //
  360. //! Indicates that the image data is compressed with 4 bit Run Length Encoding
  361. //! and represents each pixel with a single bit.
  362. //
  363. //*****************************************************************************
  364. #define IMAGE_FMT_1BPP_COMP_RLE4 0x41
  365. //*****************************************************************************
  366. //
  367. //! Indicates that the image data is compressed with 4 bit Run Length Encoding
  368. //! and represents each pixel with two bits.
  369. //
  370. //*****************************************************************************
  371. #define IMAGE_FMT_2BPP_COMP_RLE4 0x42
  372. //*****************************************************************************
  373. //
  374. //! Indicates that the image data is compressed with 4 bit Run Length Encoding
  375. //! and represents each pixel with four bits.
  376. //
  377. //*****************************************************************************
  378. #define IMAGE_FMT_4BPP_COMP_RLE4 0x44
  379. //*****************************************************************************
  380. //
  381. //! Indicates that the image data is compressed with 8 bit Run Length Encoding
  382. //! and represents each pixel with a single bit.
  383. //
  384. //*****************************************************************************
  385. #define IMAGE_FMT_1BPP_COMP_RLE8 0x81
  386. //*****************************************************************************
  387. //
  388. //! Indicates that the image data is compressed with 8 bit Run Length Encoding
  389. //! and represents each pixel with two bits.
  390. //
  391. //*****************************************************************************
  392. #define IMAGE_FMT_2BPP_COMP_RLE8 0x82
  393. //*****************************************************************************
  394. //
  395. //! Indicates that the image data is compressed with 8 bit Run Length Encoding
  396. //! and represents each pixel with four bits.
  397. //
  398. //*****************************************************************************
  399. #define IMAGE_FMT_4BPP_COMP_RLE8 0x84
  400. //*****************************************************************************
  401. //
  402. //! Indicates that the image data is compressed with 8 bit Run Length Encoding
  403. //! and represents each pixel with eight bits.
  404. //
  405. //*****************************************************************************
  406. #define IMAGE_FMT_8BPP_COMP_RLE8 0x88
  407. //*****************************************************************************
  408. //
  409. //! Indicates that the image data is compressed and represents each pixel with
  410. //! info bits.
  411. //
  412. //*****************************************************************************
  413. #define IMAGE_FMT_8BPP_COMP_RLEBLEND 0x28
  414. //*****************************************************************************
  415. //
  416. //! This structure defines a drawing context to be used to draw onto the
  417. //! screen. Multiple drawing contexts may exist at any time.
  418. //
  419. //*****************************************************************************
  420. typedef struct
  421. {
  422. //
  423. //! The size of this structure.
  424. //
  425. long lSize;
  426. //
  427. //! The screen onto which drawing operations are performed.
  428. //
  429. const tDisplay *pDisplay;
  430. //
  431. //! The clipping region to be used when drawing onto the screen.
  432. //
  433. tRectangle sClipRegion;
  434. //
  435. //! The color used to draw primitives onto the screen.
  436. //
  437. unsigned long ulForeground;
  438. //
  439. //! The background color used to draw primitives onto the screen.
  440. //
  441. unsigned long ulBackground;
  442. //
  443. //! The font used to render text onto the screen.
  444. //
  445. const tFont *pFont;
  446. }
  447. tContext;
  448. //*****************************************************************************
  449. //
  450. //! Sets the background color to be used.
  451. //!
  452. //! \param pContext is a pointer to the drawing context to modify.
  453. //! \param ulValue is the 24-bit RGB color to be used.
  454. //!
  455. //! This function sets the background color to be used for drawing operations
  456. //! in the specified drawing context.
  457. //!
  458. //! \return None.
  459. //
  460. //*****************************************************************************
  461. #define GrContextBackgroundSet(pContext, ulValue) \
  462. do \
  463. { \
  464. tContext *pC = pContext; \
  465. pC->ulBackground = DpyColorTranslate(pC->pDisplay, ulValue); \
  466. } \
  467. while(0)
  468. //*****************************************************************************
  469. //
  470. //! Sets the background color to be used.
  471. //!
  472. //! \param pContext is a pointer to the drawing context to modify.
  473. //! \param ulValue is the display driver-specific color to be used.
  474. //!
  475. //! This function sets the background color to be used for drawing operations
  476. //! in the specified drawing context, using a color that has been previously
  477. //! translated to a driver-specific color (for example, via
  478. //! DpyColorTranslate()).
  479. //!
  480. //! \return None.
  481. //
  482. //*****************************************************************************
  483. #define GrContextBackgroundSetTranslated(pContext, ulValue) \
  484. do \
  485. { \
  486. tContext *pC = pContext; \
  487. pC->ulBackground = ulValue; \
  488. } \
  489. while(0)
  490. //*****************************************************************************
  491. //
  492. //! Gets the width of the display being used by this drawing context.
  493. //!
  494. //! \param pContext is a pointer to the drawing context to query.
  495. //!
  496. //! This function returns the width of the display that is being used by this
  497. //! drawing context.
  498. //!
  499. //! \return Returns the width of the display in pixels.
  500. //
  501. //*****************************************************************************
  502. #define GrContextDpyWidthGet(pContext) \
  503. (DpyWidthGet((pContext)->pDisplay))
  504. //*****************************************************************************
  505. //
  506. //! Gets the height of the display being used by this drawing context.
  507. //!
  508. //! \param pContext is a pointer to the drawing context to query.
  509. //!
  510. //! This function returns the height of the display that is being used by this
  511. //! drawing context.
  512. //!
  513. //! \return Returns the height of the display in pixels.
  514. //
  515. //*****************************************************************************
  516. #define GrContextDpyHeightGet(pContext) \
  517. (DpyHeightGet((pContext)->pDisplay))
  518. //*****************************************************************************
  519. //
  520. //! Sets the font to be used.
  521. //!
  522. //! \param pContext is a pointer to the drawing context to modify.
  523. //! \param pFnt is a pointer to the font to be used.
  524. //!
  525. //! This function sets the font to be used for string drawing operations in the
  526. //! specified drawing context. If a tFontEx type font is to be used, cast its
  527. //! pointer to a pFont pointer before passing it as the pFnt parameter.
  528. //!
  529. //! \return None.
  530. //
  531. //*****************************************************************************
  532. #define GrContextFontSet(pContext, pFnt) \
  533. do \
  534. { \
  535. tContext *pC = pContext; \
  536. const tFont *pF = pFnt; \
  537. pC->pFont = pF; \
  538. } \
  539. while(0)
  540. //*****************************************************************************
  541. //
  542. //! Sets the foreground color to be used.
  543. //!
  544. //! \param pContext is a pointer to the drawing context to modify.
  545. //! \param ulValue is the 24-bit RGB color to be used.
  546. //!
  547. //! This function sets the color to be used for drawing operations in the
  548. //! specified drawing context.
  549. //!
  550. //! \return None.
  551. //
  552. //*****************************************************************************
  553. #define GrContextForegroundSet(pContext, ulValue) \
  554. do \
  555. { \
  556. tContext *pC = pContext; \
  557. pC->ulForeground = DpyColorTranslate(pC->pDisplay, ulValue); \
  558. } \
  559. while(0)
  560. //*****************************************************************************
  561. //
  562. //! Sets the foreground color to be used.
  563. //!
  564. //! \param pContext is a pointer to the drawing context to modify.
  565. //! \param ulValue is the display driver-specific color to be used.
  566. //!
  567. //! This function sets the foreground color to be used for drawing operations
  568. //! in the specified drawing context, using a color that has been previously
  569. //! translated to a driver-specific color (for example, via
  570. //! DpyColorTranslate()).
  571. //!
  572. //! \return None.
  573. //
  574. //*****************************************************************************
  575. #define GrContextForegroundSetTranslated(pContext, ulValue) \
  576. do \
  577. { \
  578. tContext *pC = pContext; \
  579. pC->ulForeground = ulValue; \
  580. } \
  581. while(0)
  582. //*****************************************************************************
  583. //
  584. //! Flushes any cached drawing operations.
  585. //!
  586. //! \param pContext is a pointer to the drawing context to use.
  587. //!
  588. //! This function flushes any cached drawing operations. For display drivers
  589. //! that draw into a local frame buffer before writing to the actual display,
  590. //! calling this function will cause the display to be updated to match the
  591. //! contents of the local frame buffer.
  592. //!
  593. //! \return None.
  594. //
  595. //*****************************************************************************
  596. #define GrFlush(pContext) \
  597. do \
  598. { \
  599. const tContext *pC = pContext; \
  600. DpyFlush(pC->pDisplay); \
  601. } \
  602. while(0)
  603. //*****************************************************************************
  604. //
  605. //! Forces a clear screen. Contents of Display buffer unmodified
  606. //!
  607. //! \param pContext is a pointer to the drawing context to use.
  608. //!
  609. //! This function forces a clear screen.
  610. //!
  611. //! \return None.
  612. //
  613. //*****************************************************************************
  614. #define GrClearDisplay(pContext) \
  615. do \
  616. { \
  617. const tContext *pC = pContext; \
  618. DpyClearDisplay(pC->pDisplay,pC->ulBackground ); \
  619. } \
  620. while(0)
  621. //*****************************************************************************
  622. //
  623. //! Gets the baseline of a font.
  624. //!
  625. //! \param pFont is a pointer to the font to query.
  626. //!
  627. //! This function determines the baseline position of a font. The baseline is
  628. //! the offset between the top of the font and the bottom of the capital
  629. //! letters. The only font data that exists below the baseline are the
  630. //! descenders on some lower-case letters (such as ``y'').
  631. //!
  632. //! \return Returns the baseline of the font, in pixels.
  633. //
  634. //*****************************************************************************
  635. #define GrFontBaselineGet(pFont) \
  636. ((pFont)->ucBaseline)
  637. //*****************************************************************************
  638. //
  639. //! Gets the height of a font.
  640. //!
  641. //! \param pFont is a pointer to the font to query.
  642. //!
  643. //! This function determines the height of a font. The height is the offset
  644. //! between the top of the font and the bottom of the font, including any
  645. //! ascenders and descenders.
  646. //!
  647. //! \return Returns the height of the font, in pixels.
  648. //
  649. //*****************************************************************************
  650. #define GrFontHeightGet(pFont) \
  651. ((pFont)->ucHeight)
  652. //*****************************************************************************
  653. //
  654. //! Gets the maximum width of a font.
  655. //!
  656. //! \param pFont is a pointer to the font to query.
  657. //!
  658. //! This function determines the maximum width of a font. The maximum width is
  659. //! the width of the widest individual character in the font.
  660. //!
  661. //! \return Returns the maximum width of the font, in pixels.
  662. //
  663. //*****************************************************************************
  664. #define GrFontMaxWidthGet(pFont) \
  665. ((pFont)->ucMaxWidth)
  666. //*****************************************************************************
  667. //
  668. //! Gets the number of colors in an image.
  669. //!
  670. //! \param pImage is a tImage struct
  671. //!
  672. //! This function determines the number of colors in the palette of an image.
  673. //! This is only valid for 4bpp and 8bpp images; 1bpp images do not contain a
  674. //! palette.
  675. //!
  676. //! \return Returns the number of colors in the image.
  677. //
  678. //*****************************************************************************
  679. #define GrImageColorsGet(pImage) \
  680. pImage->NumColors
  681. //*****************************************************************************
  682. //
  683. //! Gets the height of an image.
  684. //!
  685. //! \param pImage is a tImage struct
  686. //!
  687. //! This function determines the height of an image in pixels.
  688. //!
  689. //! \return Returns the height of the image in pixels.
  690. //
  691. //*****************************************************************************
  692. #define GrImageHeightGet(pImage) \
  693. pImage->YSize
  694. //*****************************************************************************
  695. //
  696. //! Gets the width of an image.
  697. //!
  698. //! \param pImage is a tImage struct
  699. //!
  700. //! This function determines the width of an image in pixels.
  701. //!
  702. //! \return Returns the width of the image in pixels.
  703. //
  704. //*****************************************************************************
  705. #define GrImageWidthGet(pImage) \
  706. pImage->XSize
  707. //*****************************************************************************
  708. //
  709. //! Determines the size of the buffer for a 1 BPP off-screen image.
  710. //!
  711. //! \param lWidth is the width of the image in pixels.
  712. //! \param lHeight is the height of the image in pixels.
  713. //!
  714. //! This function determines the size of the memory buffer required to hold a
  715. //! 1 BPP off-screen image of the specified geometry.
  716. //!
  717. //! \return Returns the number of bytes required by the image.
  718. //
  719. //*****************************************************************************
  720. #define GrOffScreen1BPPSize(lWidth, lHeight) \
  721. (5 + (((lWidth + 7) / 8) * lHeight))
  722. //*****************************************************************************
  723. //
  724. //! Determines the size of the buffer for a 4 BPP off-screen image.
  725. //!
  726. //! \param lWidth is the width of the image in pixels.
  727. //! \param lHeight is the height of the image in pixels.
  728. //!
  729. //! This function determines the size of the memory buffer required to hold a
  730. //! 4 BPP off-screen image of the specified geometry.
  731. //!
  732. //! \return Returns the number of bytes required by the image.
  733. //
  734. //*****************************************************************************
  735. #define GrOffScreen4BPPSize(lWidth, lHeight) \
  736. (6 + (16 * 3) + (((lWidth + 1) / 2) * lHeight))
  737. //*****************************************************************************
  738. //
  739. //! Determines the size of the buffer for an 8 BPP off-screen image.
  740. //!
  741. //! \param lWidth is the width of the image in pixels.
  742. //! \param lHeight is the height of the image in pixels.
  743. //!
  744. //! This function determines the size of the memory buffer required to hold an
  745. //! 8 BPP off-screen image of the specified geometry.
  746. //!
  747. //! \return Returns the number of bytes required by the image.
  748. //
  749. //*****************************************************************************
  750. #define GrOffScreen8BPPSize(lWidth, lHeight) \
  751. (6 + (256 * 3) + (lWidth * lHeight))
  752. //*****************************************************************************
  753. //
  754. //! Draws a pixel.
  755. //!
  756. //! \param pContext is a pointer to the drawing context to use.
  757. //! \param lX is the X coordinate of the pixel.
  758. //! \param lY is the Y coordinate of the pixel.
  759. //!
  760. //! This function draws a pixel if it resides within the clipping region.
  761. //!
  762. //! \return None.
  763. //
  764. //*****************************************************************************
  765. #define GrPixelDraw(pContext, lX, lY) \
  766. do \
  767. { \
  768. const tContext *pC = pContext; \
  769. if((lX >= pC->sClipRegion.sXMin) && \
  770. (lX <= pC->sClipRegion.sXMax) && \
  771. (lY >= pC->sClipRegion.sYMin) && \
  772. (lY <= pC->sClipRegion.sYMax)) \
  773. { \
  774. DpyPixelDraw(pC->pDisplay, lX, lY, pC->ulForeground); \
  775. } \
  776. } \
  777. while(0)
  778. //*****************************************************************************
  779. //
  780. //! Gets the baseline of a string.
  781. //!
  782. //! \param pContext is a pointer to the drawing context to query.
  783. //!
  784. //! This function determines the baseline position of a string. The baseline
  785. //! is the offset between the top of the string and the bottom of the capital
  786. //! letters. The only string data that exists below the baseline are the
  787. //! descenders on some lower-case letters (such as ``y'').
  788. //!
  789. //! \return Returns the baseline of the string, in pixels.
  790. //
  791. //*****************************************************************************
  792. #define GrStringBaselineGet(pContext) \
  793. ((pContext)->pFont->ucBaseline)
  794. //*****************************************************************************
  795. //
  796. //! Draws a centered string.
  797. //!
  798. //! \param pContext is a pointer to the drawing context to use.
  799. //! \param pcString is a pointer to the string to be drawn.
  800. //! \param lLength is the number of characters from the string that should be
  801. //! drawn on the screen.
  802. //! \param lX is the X coordinate of the center of the string position on the
  803. //! screen.
  804. //! \param lY is the Y coordinate of the center of the string position on the
  805. //! screen.
  806. //! \param bOpaque is \b true if the background of each character should be
  807. //! drawn and \b false if it should not (leaving the background as is).
  808. //!
  809. //! This function draws a string of test on the screen centered upon the
  810. //! provided position. The \e lLength parameter allows a portion of the
  811. //! string to be examined without having to insert a NULL character at the
  812. //! stopping point (which would not be possible if the string was located in
  813. //! flash); specifying a length of -1 will cause the entire string to be
  814. //! rendered (subject to clipping).
  815. //!
  816. //! \return None.
  817. //
  818. //*****************************************************************************
  819. #define GrStringDrawCentered(pContext, pcString, lLength, lX, lY, bOpaque) \
  820. do \
  821. { \
  822. const tContext *pC = pContext; \
  823. const char *pcStr = pcString; \
  824. \
  825. GrStringDraw(pC, pcStr, lLength, \
  826. (lX) - (GrStringWidthGet(pC, pcStr, lLength) / 2), \
  827. (lY) - (pC->pFont->ucBaseline / 2), bOpaque); \
  828. } \
  829. while(0)
  830. //*****************************************************************************
  831. //
  832. //! Gets the height of a string.
  833. //!
  834. //! \param pContext is a pointer to the drawing context to query.
  835. //!
  836. //! This function determines the height of a string. The height is the offset
  837. //! between the top of the string and the bottom of the string, including any
  838. //! ascenders and descenders. Note that this will not account for the case
  839. //! where the string in question does not have any characters that use
  840. //! descenders but the font in the drawing context does contain characters with
  841. //! descenders.
  842. //!
  843. //! \return Returns the height of the string, in pixels.
  844. //
  845. //*****************************************************************************
  846. #define GrStringHeightGet(pContext) \
  847. ((pContext)->pFont->ucHeight)
  848. //*****************************************************************************
  849. //
  850. //! Gets the maximum width of a character in a string.
  851. //!
  852. //! \param pContext is a pointer to the drawing context to query.
  853. //!
  854. //! This function determines the maximum width of a character in a string. The
  855. //! maximum width is the width of the widest individual character in the font
  856. //! used to render the string, which may be wider than the widest character
  857. //! that is used to render a particular string.
  858. //!
  859. //! \return Returns the maximum width of a character in a string, in pixels.
  860. //
  861. //*****************************************************************************
  862. #define GrStringMaxWidthGet(pContext) \
  863. ((pContext)->pFont->ucMaxWidth)
  864. //*****************************************************************************
  865. //
  866. // A set of color definitions. This set is the subset of the X11 colors (from
  867. // rgb.txt) that are supported by typical web browsers.
  868. //
  869. //*****************************************************************************
  870. #define ClrAliceBlue 0x00F0F8FF
  871. #define ClrAntiqueWhite 0x00FAEBD7
  872. #define ClrAqua 0x0000FFFF
  873. #define ClrAquamarine 0x007FFFD4
  874. #define ClrAzure 0x00F0FFFF
  875. #define ClrBeige 0x00F5F5DC
  876. #define ClrBisque 0x00FFE4C4
  877. #define ClrBlack 0x00000000
  878. #define ClrBlanchedAlmond 0x00FFEBCD
  879. #define ClrBlue 0x000000FF
  880. #define ClrBlueViolet 0x008A2BE2
  881. #define ClrBrown 0x00A52A2A
  882. #define ClrBurlyWood 0x00DEB887
  883. #define ClrCadetBlue 0x005F9EA0
  884. #define ClrChartreuse 0x007FFF00
  885. #define ClrChocolate 0x00D2691E
  886. #define ClrCoral 0x00FF7F50
  887. #define ClrCornflowerBlue 0x006495ED
  888. #define ClrCornsilk 0x00FFF8DC
  889. #define ClrCrimson 0x00DC143C
  890. #define ClrCyan 0x0000FFFF
  891. #define ClrDarkBlue 0x0000008B
  892. #define ClrDarkCyan 0x00008B8B
  893. #define ClrDarkGoldenrod 0x00B8860B
  894. #define ClrDarkGray 0x00A9A9A9
  895. #define ClrDarkGreen 0x00006400
  896. #define ClrDarkKhaki 0x00BDB76B
  897. #define ClrDarkMagenta 0x008B008B
  898. #define ClrDarkOliveGreen 0x00556B2F
  899. #define ClrDarkOrange 0x00FF8C00
  900. #define ClrDarkOrchid 0x009932CC
  901. #define ClrDarkRed 0x008B0000
  902. #define ClrDarkSalmon 0x00E9967A
  903. #define ClrDarkSeaGreen 0x008FBC8F
  904. #define ClrDarkSlateBlue 0x00483D8B
  905. #define ClrDarkSlateGray 0x002F4F4F
  906. #define ClrDarkTurquoise 0x0000CED1
  907. #define ClrDarkViolet 0x009400D3
  908. #define ClrDeepPink 0x00FF1493
  909. #define ClrDeepSkyBlue 0x0000BFFF
  910. #define ClrDimGray 0x00696969
  911. #define ClrDodgerBlue 0x001E90FF
  912. #define ClrFireBrick 0x00B22222
  913. #define ClrFloralWhite 0x00FFFAF0
  914. #define ClrForestGreen 0x00228B22
  915. #define ClrFuchsia 0x00FF00FF
  916. #define ClrGainsboro 0x00DCDCDC
  917. #define ClrGhostWhite 0x00F8F8FF
  918. #define ClrGold 0x00FFD700
  919. #define ClrGoldenrod 0x00DAA520
  920. #define ClrGray 0x00808080
  921. #define ClrGreen 0x00008000
  922. #define ClrGreenYellow 0x00ADFF2F
  923. #define ClrHoneydew 0x00F0FFF0
  924. #define ClrHotPink 0x00FF69B4
  925. #define ClrIndianRed 0x00CD5C5C
  926. #define ClrIndigo 0x004B0082
  927. #define ClrIvory 0x00FFFFF0
  928. #define ClrKhaki 0x00F0E68C
  929. #define ClrLavender 0x00E6E6FA
  930. #define ClrLavenderBlush 0x00FFF0F5
  931. #define ClrLawnGreen 0x007CFC00
  932. #define ClrLemonChiffon 0x00FFFACD
  933. #define ClrLightBlue 0x00ADD8E6
  934. #define ClrLightCoral 0x00F08080
  935. #define ClrLightCyan 0x00E0FFFF
  936. #define ClrLightGoldenrodYellow 0x00FAFAD2
  937. #define ClrLightGreen 0x0090EE90
  938. #define ClrLightGrey 0x00D3D3D3
  939. #define ClrLightPink 0x00FFB6C1
  940. #define ClrLightSalmon 0x00FFA07A
  941. #define ClrLightSeaGreen 0x0020B2AA
  942. #define ClrLightSkyBlue 0x0087CEFA
  943. #define ClrLightSlateGray 0x00778899
  944. #define ClrLightSteelBlue 0x00B0C4DE
  945. #define ClrLightYellow 0x00FFFFE0
  946. #define ClrLime 0x0000FF00
  947. #define ClrLimeGreen 0x0032CD32
  948. #define ClrLinen 0x00FAF0E6
  949. #define ClrMagenta 0x00FF00FF
  950. #define ClrMaroon 0x00800000
  951. #define ClrMediumAquamarine 0x0066CDAA
  952. #define ClrMediumBlue 0x000000CD
  953. #define ClrMediumOrchid 0x00BA55D3
  954. #define ClrMediumPurple 0x009370DB
  955. #define ClrMediumSeaGreen 0x003CB371
  956. #define ClrMediumSlateBlue 0x007B68EE
  957. #define ClrMediumSpringGreen 0x0000FA9A
  958. #define ClrMediumTurquoise 0x0048D1CC
  959. #define ClrMediumVioletRed 0x00C71585
  960. #define ClrMidnightBlue 0x00191970
  961. #define ClrMintCream 0x00F5FFFA
  962. #define ClrMistyRose 0x00FFE4E1
  963. #define ClrMoccasin 0x00FFE4B5
  964. #define ClrNavajoWhite 0x00FFDEAD
  965. #define ClrNavy 0x00000080
  966. #define ClrOldLace 0x00FDF5E6
  967. #define ClrOlive 0x00808000
  968. #define ClrOliveDrab 0x006B8E23
  969. #define ClrOrange 0x00FFA500
  970. #define ClrOrangeRed 0x00FF4500
  971. #define ClrOrchid 0x00DA70D6
  972. #define ClrPaleGoldenrod 0x00EEE8AA
  973. #define ClrPaleGreen 0x0098FB98
  974. #define ClrPaleTurquoise 0x00AFEEEE
  975. #define ClrPaleVioletRed 0x00DB7093
  976. #define ClrPapayaWhip 0x00FFEFD5
  977. #define ClrPeachPuff 0x00FFDAB9
  978. #define ClrPeru 0x00CD853F
  979. #define ClrPink 0x00FFC0CB
  980. #define ClrPlum 0x00DDA0DD
  981. #define ClrPowderBlue 0x00B0E0E6
  982. #define ClrPurple 0x00800080
  983. #define ClrRed 0x00FF0000
  984. #define ClrRosyBrown 0x00BC8F8F
  985. #define ClrRoyalBlue 0x004169E1
  986. #define ClrSaddleBrown 0x008B4513
  987. #define ClrSalmon 0x00FA8072
  988. #define ClrSandyBrown 0x00F4A460
  989. #define ClrSeaGreen 0x002E8B57
  990. #define ClrSeashell 0x00FFF5EE
  991. #define ClrSienna 0x00A0522D
  992. #define ClrSilver 0x00C0C0C0
  993. #define ClrSkyBlue 0x0087CEEB
  994. #define ClrSlateBlue 0x006A5ACD
  995. #define ClrSlateGray 0x00708090
  996. #define ClrSnow 0x00FFFAFA
  997. #define ClrSpringGreen 0x0000FF7F
  998. #define ClrSteelBlue 0x004682B4
  999. #define ClrTan 0x00D2B48C
  1000. #define ClrTeal 0x00008080
  1001. #define ClrThistle 0x00D8BFD8
  1002. #define ClrTomato 0x00FF6347
  1003. #define ClrTurquoise 0x0040E0D0
  1004. #define ClrViolet 0x00EE82EE
  1005. #define ClrWheat 0x00F5DEB3
  1006. #define ClrWhite 0x00FFFFFF
  1007. #define ClrWhiteSmoke 0x00F5F5F5
  1008. #define ClrYellow 0x00FFFF00
  1009. #define ClrYellowGreen 0x009ACD32
  1010. #define ClrBlack 0x00000000
  1011. //*****************************************************************************
  1012. //
  1013. // Masks and shifts to aid in color format translation by drivers.
  1014. //
  1015. //*****************************************************************************
  1016. #define ClrRedMask 0x00FF0000
  1017. #define ClrRedShift 16
  1018. #define ClrGreenMask 0x0000FF00
  1019. #define ClrGreenShift 8
  1020. #define ClrBlueMask 0x000000FF
  1021. #define ClrBlueShift 0
  1022. //*****************************************************************************
  1023. //
  1024. // Prototypes for the predefined fonts in the graphics library. ..Cm.. is the
  1025. // computer modern font, which is a serif font. ..Cmsc.. is the computer
  1026. // modern small-caps font, which is also a serif font. ..Cmss.. is the
  1027. // computer modern sans-serif font.
  1028. //
  1029. //*****************************************************************************
  1030. extern const tFont g_sFontCm12;
  1031. extern const tFont g_sFontCm12b;
  1032. extern const tFont g_sFontCm12i;
  1033. extern const tFont g_sFontCm14;
  1034. extern const tFont g_sFontCm14b;
  1035. extern const tFont g_sFontCm14i;
  1036. extern const tFont g_sFontCm16;
  1037. extern const tFont g_sFontCm16b;
  1038. extern const tFont g_sFontCm16i;
  1039. extern const tFont g_sFontCm18;
  1040. extern const tFont g_sFontCm18b;
  1041. extern const tFont g_sFontCm18i;
  1042. extern const tFont g_sFontCm20;
  1043. extern const tFont g_sFontCm20b;
  1044. extern const tFont g_sFontCm20i;
  1045. extern const tFont g_sFontCm22;
  1046. extern const tFont g_sFontCm22b;
  1047. extern const tFont g_sFontCm22i;
  1048. extern const tFont g_sFontCm24;
  1049. extern const tFont g_sFontCm24b;
  1050. extern const tFont g_sFontCm24i;
  1051. extern const tFont g_sFontCm26;
  1052. extern const tFont g_sFontCm26b;
  1053. extern const tFont g_sFontCm26i;
  1054. extern const tFont g_sFontCm28;
  1055. extern const tFont g_sFontCm28b;
  1056. extern const tFont g_sFontCm28i;
  1057. extern const tFont g_sFontCm30;
  1058. extern const tFont g_sFontCm30b;
  1059. extern const tFont g_sFontCm30i;
  1060. extern const tFont g_sFontCm32;
  1061. extern const tFont g_sFontCm32b;
  1062. extern const tFont g_sFontCm32i;
  1063. extern const tFont g_sFontCm34;
  1064. extern const tFont g_sFontCm34b;
  1065. extern const tFont g_sFontCm34i;
  1066. extern const tFont g_sFontCm36;
  1067. extern const tFont g_sFontCm36b;
  1068. extern const tFont g_sFontCm36i;
  1069. extern const tFont g_sFontCm38;
  1070. extern const tFont g_sFontCm38b;
  1071. extern const tFont g_sFontCm38i;
  1072. extern const tFont g_sFontCm40;
  1073. extern const tFont g_sFontCm40b;
  1074. extern const tFont g_sFontCm40i;
  1075. extern const tFont g_sFontCm42;
  1076. extern const tFont g_sFontCm42b;
  1077. extern const tFont g_sFontCm42i;
  1078. extern const tFont g_sFontCm44;
  1079. extern const tFont g_sFontCm44b;
  1080. extern const tFont g_sFontCm44i;
  1081. extern const tFont g_sFontCm46;
  1082. extern const tFont g_sFontCm46b;
  1083. extern const tFont g_sFontCm46i;
  1084. extern const tFont g_sFontCm48;
  1085. extern const tFont g_sFontCm48b;
  1086. extern const tFont g_sFontCm48i;
  1087. extern const tFont g_sFontCmsc12;
  1088. extern const tFont g_sFontCmsc14;
  1089. extern const tFont g_sFontCmsc16;
  1090. extern const tFont g_sFontCmsc18;
  1091. extern const tFont g_sFontCmsc20;
  1092. extern const tFont g_sFontCmsc22;
  1093. extern const tFont g_sFontCmsc24;
  1094. extern const tFont g_sFontCmsc26;
  1095. extern const tFont g_sFontCmsc28;
  1096. extern const tFont g_sFontCmsc30;
  1097. extern const tFont g_sFontCmsc32;
  1098. extern const tFont g_sFontCmsc34;
  1099. extern const tFont g_sFontCmsc36;
  1100. extern const tFont g_sFontCmsc38;
  1101. extern const tFont g_sFontCmsc40;
  1102. extern const tFont g_sFontCmsc42;
  1103. extern const tFont g_sFontCmsc44;
  1104. extern const tFont g_sFontCmsc46;
  1105. extern const tFont g_sFontCmsc48;
  1106. extern const tFont g_sFontCmss12;
  1107. extern const tFont g_sFontCmss12b;
  1108. extern const tFont g_sFontCmss12i;
  1109. extern const tFont g_sFontCmss14;
  1110. extern const tFont g_sFontCmss14b;
  1111. extern const tFont g_sFontCmss14i;
  1112. extern const tFont g_sFontCmss16;
  1113. extern const tFont g_sFontCmss16b;
  1114. extern const tFont g_sFontCmss16i;
  1115. extern const tFont g_sFontCmss18;
  1116. extern const tFont g_sFontCmss18b;
  1117. extern const tFont g_sFontCmss18i;
  1118. extern const tFont g_sFontCmss20;
  1119. extern const tFont g_sFontCmss20b;
  1120. extern const tFont g_sFontCmss20i;
  1121. extern const tFont g_sFontCmss22;
  1122. extern const tFont g_sFontCmss22b;
  1123. extern const tFont g_sFontCmss22i;
  1124. extern const tFont g_sFontCmss24;
  1125. extern const tFont g_sFontCmss24b;
  1126. extern const tFont g_sFontCmss24i;
  1127. extern const tFont g_sFontCmss26;
  1128. extern const tFont g_sFontCmss26b;
  1129. extern const tFont g_sFontCmss26i;
  1130. extern const tFont g_sFontCmss28;
  1131. extern const tFont g_sFontCmss28b;
  1132. extern const tFont g_sFontCmss28i;
  1133. extern const tFont g_sFontCmss30;
  1134. extern const tFont g_sFontCmss30b;
  1135. extern const tFont g_sFontCmss30i;
  1136. extern const tFont g_sFontCmss32;
  1137. extern const tFont g_sFontCmss32b;
  1138. extern const tFont g_sFontCmss32i;
  1139. extern const tFont g_sFontCmss34;
  1140. extern const tFont g_sFontCmss34b;
  1141. extern const tFont g_sFontCmss34i;
  1142. extern const tFont g_sFontCmss36;
  1143. extern const tFont g_sFontCmss36b;
  1144. extern const tFont g_sFontCmss36i;
  1145. extern const tFont g_sFontCmss38;
  1146. extern const tFont g_sFontCmss38b;
  1147. extern const tFont g_sFontCmss38i;
  1148. extern const tFont g_sFontCmss40;
  1149. extern const tFont g_sFontCmss40b;
  1150. extern const tFont g_sFontCmss40i;
  1151. extern const tFont g_sFontCmss42;
  1152. extern const tFont g_sFontCmss42b;
  1153. extern const tFont g_sFontCmss42i;
  1154. extern const tFont g_sFontCmss44;
  1155. extern const tFont g_sFontCmss44b;
  1156. extern const tFont g_sFontCmss44i;
  1157. extern const tFont g_sFontCmss46;
  1158. extern const tFont g_sFontCmss46b;
  1159. extern const tFont g_sFontCmss46i;
  1160. extern const tFont g_sFontCmss48;
  1161. extern const tFont g_sFontCmss48b;
  1162. extern const tFont g_sFontCmss48i;
  1163. extern const tFont g_sFontCmtt12;
  1164. extern const tFont g_sFontCmtt14;
  1165. extern const tFont g_sFontCmtt16;
  1166. extern const tFont g_sFontCmtt18;
  1167. extern const tFont g_sFontCmtt20;
  1168. extern const tFont g_sFontCmtt22;
  1169. extern const tFont g_sFontCmtt24;
  1170. extern const tFont g_sFontCmtt26;
  1171. extern const tFont g_sFontCmtt28;
  1172. extern const tFont g_sFontCmtt30;
  1173. extern const tFont g_sFontCmtt32;
  1174. extern const tFont g_sFontCmtt34;
  1175. extern const tFont g_sFontCmtt36;
  1176. extern const tFont g_sFontCmtt38;
  1177. extern const tFont g_sFontCmtt40;
  1178. extern const tFont g_sFontCmtt42;
  1179. extern const tFont g_sFontCmtt44;
  1180. extern const tFont g_sFontCmtt46;
  1181. extern const tFont g_sFontCmtt48;
  1182. extern const tFont g_sFontFixed6x8;
  1183. //*****************************************************************************
  1184. //
  1185. // Language identifiers supported by the string table processing functions.
  1186. //
  1187. //*****************************************************************************
  1188. #define GrLangZhPRC 0x0804 // Chinese (PRC)
  1189. #define GrLangZhTW 0x0404 // Chinese (Taiwan)
  1190. #define GrLangEnUS 0x0409 // English (United States)
  1191. #define GrLangEnUK 0x0809 // English (United Kingdom)
  1192. #define GrLangEnAUS 0x0C09 // English (Australia)
  1193. #define GrLangEnCA 0x1009 // English (Canada)
  1194. #define GrLangEnNZ 0x1409 // English (New Zealand)
  1195. #define GrLangFr 0x040C // French (Standard)
  1196. #define GrLangDe 0x0407 // German (Standard)
  1197. #define GrLangHi 0x0439 // Hindi
  1198. #define GrLangIt 0x0410 // Italian (Standard)
  1199. #define GrLangJp 0x0411 // Japanese
  1200. #define GrLangKo 0x0412 // Korean
  1201. #define GrLangEsMX 0x080A // Spanish (Mexico)
  1202. #define GrLangEsSP 0x0C0A // Spanish (Spain)
  1203. #define GrLangSwKE 0x0441 // Swahili (Kenya)
  1204. #define GrLangUrIN 0x0820 // Urdu (India)
  1205. #define GrLangUrPK 0x0420 // Urdu (Pakistan)
  1206. //*****************************************************************************
  1207. //
  1208. //! Translates a 24-bit RGB color to a display driver-specific color.
  1209. //!
  1210. //! \param pDisplay is the pointer to the display driver structure for the
  1211. //! display to operate upon.
  1212. //! \param ulValue is the 24-bit RGB color. The least-significant byte is the
  1213. //! blue channel, the next byte is the green channel, and the third byte is the
  1214. //! red channel.
  1215. //!
  1216. //! This function translates a 24-bit RGB color into a value that can be
  1217. //! written into the display's frame buffer in order to reproduce that color,
  1218. //! or the closest possible approximation of that color.
  1219. //!
  1220. //! \return Returns the display-driver specific color.
  1221. //
  1222. //*****************************************************************************
  1223. #define DpyColorTranslate(pDisplay, ulValue) \
  1224. ((pDisplay)->pfnColorTranslate((pDisplay)->pvDisplayData, ulValue))
  1225. //*****************************************************************************
  1226. //
  1227. //! Flushes cached drawing operations.
  1228. //!
  1229. //! \param pDisplay is the pointer to the display driver structure for the
  1230. //! display to operate upon.
  1231. //!
  1232. //! This function flushes any cached drawing operations on a display.
  1233. //!
  1234. //! \return None.
  1235. //
  1236. //*****************************************************************************
  1237. #define DpyFlush(pDisplay) \
  1238. do \
  1239. { \
  1240. const tDisplay *pD = pDisplay; \
  1241. pD->pfnFlush(pD->pvDisplayData); \
  1242. } \
  1243. while(0)
  1244. //*****************************************************************************
  1245. //
  1246. //! Forces a clear Display.
  1247. //!
  1248. //! \param pDisplay is the pointer to the display driver structure for the
  1249. //! display to operate upon.
  1250. //! \param ulValue is the current background color to fill the screen with.
  1251. //!
  1252. //! This function clears the Display
  1253. //!
  1254. //! \return None.
  1255. //
  1256. //*****************************************************************************
  1257. #define DpyClearDisplay(pDisplay, ulValue) \
  1258. do \
  1259. { \
  1260. const tDisplay *pD = pDisplay; \
  1261. pD->pfnClearDisplay(pD->pvDisplayData, ulValue); \
  1262. } \
  1263. while(0)
  1264. //*****************************************************************************
  1265. //
  1266. //! Gets the height of the display.
  1267. //!
  1268. //! \param pDisplay is a pointer to the display driver structure for the
  1269. //! display to query.
  1270. //!
  1271. //! This function determines the height of the display.
  1272. //!
  1273. //! \return Returns the height of the display in pixels.
  1274. //
  1275. //*****************************************************************************
  1276. #define DpyHeightGet(pDisplay) \
  1277. ((pDisplay)->usHeight)
  1278. //*****************************************************************************
  1279. //
  1280. //! Draws a horizontal line on a display.
  1281. //!
  1282. //! \param pDisplay is the pointer to the display driver structure for the
  1283. //! display to operate upon.
  1284. //! \param lX1 is the starting X coordinate of the line.
  1285. //! \param lX2 is the ending X coordinate of the line.
  1286. //! \param lY is the Y coordinate of the line.
  1287. //! \param ulValue is the color to draw the line.
  1288. //!
  1289. //! This function draws a horizontal line on a display. This assumes that
  1290. //! clipping has already been performed, and that both end points of the line
  1291. //! are within the extents of the display.
  1292. //!
  1293. //! \return None.
  1294. //
  1295. //*****************************************************************************
  1296. #define DpyLineDrawH(pDisplay, lX1, lX2, lY, ulValue) \
  1297. do \
  1298. { \
  1299. const tDisplay *pD = pDisplay; \
  1300. pD->pfnLineDrawH(pD->pvDisplayData, lX1, lX2, lY, ulValue); \
  1301. } \
  1302. while(0)
  1303. //*****************************************************************************
  1304. //
  1305. //! Draws a vertical line on a display.
  1306. //!
  1307. //! \param pDisplay is the pointer to the display driver structure for the
  1308. //! display to operate upon.
  1309. //! \param lX is the X coordinate of the line.
  1310. //! \param lY1 is the starting Y coordinate of the line.
  1311. //! \param lY2 is the ending Y coordinate of the line.
  1312. //! \param ulValue is the color to draw the line.
  1313. //!
  1314. //! This function draws a vertical line on a display. This assumes that
  1315. //! clipping has already been performed, and that both end points of the line
  1316. //! are within the extents of the display.
  1317. //!
  1318. //! \return None.
  1319. //
  1320. //*****************************************************************************
  1321. #define DpyLineDrawV(pDisplay, lX, lY1, lY2, ulValue) \
  1322. do \
  1323. { \
  1324. const tDisplay *pD = pDisplay; \
  1325. pD->pfnLineDrawV(pD->pvDisplayData, lX, lY1, lY2, ulValue); \
  1326. } \
  1327. while(0)
  1328. //*****************************************************************************
  1329. //
  1330. //! Draws a pixel on a display.
  1331. //!
  1332. //! \param pDisplay is the pointer to the display driver structure for the
  1333. //! display to operate upon.
  1334. //! \param lX is the X coordinate of the pixel.
  1335. //! \param lY is the Y coordinate of the pixel.
  1336. //! \param ulValue is the color to draw the pixel.
  1337. //!
  1338. //! This function draws a pixel on a display. This assumes that clipping has
  1339. //! already been performed.
  1340. //!
  1341. //! \return None.
  1342. //
  1343. //*****************************************************************************
  1344. #define DpyPixelDraw(pDisplay, lX, lY, ulValue) \
  1345. do \
  1346. { \
  1347. const tDisplay *pD = pDisplay; \
  1348. pD->pfnPixelDraw(pD->pvDisplayData, lX, lY, ulValue); \
  1349. } \
  1350. while(0)
  1351. //*****************************************************************************
  1352. //
  1353. //! Draws a horizontal sequence of pixels on a display.
  1354. //!
  1355. //! \param pDisplay is the pointer to the display driver structure for the
  1356. //! display to operate upon.
  1357. //! \param lX is the X coordinate of the first pixel.
  1358. //! \param lY is the Y coordinate of the first pixel.
  1359. //! \param lX0 is sub-pixel offset within the pixel data, which is valid for 1
  1360. //! or 4 bit per pixel formats.
  1361. //! \param lCount is the number of pixels to draw.
  1362. //! \param lBPP is the number of bits per pixel; must be 1, 4, or 8.
  1363. //! \param pucData is a pointer to the pixel data. For 1 and 4 bit per pixel
  1364. //! formats, the most significant bit(s) represent the left-most pixel.
  1365. //! \param pucPalette is a pointer to the palette used to draw the pixels.
  1366. //!
  1367. //! This function draws a horizontal sequence of pixels on a display, using the
  1368. //! supplied palette. For 1 bit per pixel format, the palette contains
  1369. //! pre-translated colors; for 4 and 8 bit per pixel formats, the palette
  1370. //! contains 24-bit RGB values that must be translated before being written to
  1371. //! the display.
  1372. //!
  1373. //! \return None.
  1374. //
  1375. //*****************************************************************************
  1376. #define DpyPixelDrawMultiple(pDisplay, lX, lY, lX0, lCount, lBPP, pucData, \
  1377. pucPalette) \
  1378. do \
  1379. { \
  1380. const tDisplay *pD = pDisplay; \
  1381. pD->pfnPixelDrawMultiple(pD->pvDisplayData, lX, lY, lX0, lCount, \
  1382. lBPP, pucData, pucPalette); \
  1383. } \
  1384. while(0)
  1385. //*****************************************************************************
  1386. //
  1387. //! Fills a rectangle on a display.
  1388. //!
  1389. //! \param pDisplay is the pointer to the display driver structure for the
  1390. //! display to operate upon.
  1391. //! \param pRect is a pointer to the structure describing the rectangle to
  1392. //! fill.
  1393. //! \param ulValue is the color to fill the rectangle.
  1394. //!
  1395. //! This function fills a rectangle on the display. This assumes that clipping
  1396. //! has already been performed, and that all sides of the rectangle are within
  1397. //! the extents of the display.
  1398. //!
  1399. //! \return None.
  1400. //
  1401. //*****************************************************************************
  1402. #define DpyRectFill(pDisplay, pRect, ulValue) \
  1403. do \
  1404. { \
  1405. const tDisplay *pD = pDisplay; \
  1406. pD->pfnRectFill(pD->pvDisplayData, pRect, ulValue); \
  1407. } \
  1408. while(0)
  1409. //*****************************************************************************
  1410. //
  1411. //! Gets the width of the display.
  1412. //!
  1413. //! \param pDisplay is a pointer to the display driver structure for the
  1414. //! display to query.
  1415. //!
  1416. //! This function determines the width of the display.
  1417. //!
  1418. //! \return Returns the width of the display in pixels.
  1419. //
  1420. //*****************************************************************************
  1421. #define DpyWidthGet(pDisplay) \
  1422. ((pDisplay)->usWidth)
  1423. //*****************************************************************************
  1424. //
  1425. //! Determines if a point lies within a given rectangle.
  1426. //!
  1427. //! \param pRect is a pointer to the rectangle which the point is to be checked
  1428. //! against.
  1429. //! \param lX is the X coordinate of the point to be checked.
  1430. //! \param lY is the Y coordinate of the point to be checked.
  1431. //!
  1432. //! This function determines whether point (lX, lY) lies within the rectangle
  1433. //! described by \e pRect.
  1434. //!
  1435. //! \return Returns 1 if the point is within the rectangle or 0 otherwise.
  1436. //
  1437. //*****************************************************************************
  1438. #define GrRectContainsPoint(pRect, lX, lY) \
  1439. ((((lX) >= (pRect)->sXMin) && ((lX) <= (pRect)->sXMax) && \
  1440. ((lY) >= (pRect)->sYMin) && ((lY) <= (pRect)->sYMax)) ? 1 : 0)
  1441. //*****************************************************************************
  1442. //
  1443. // Prototypes for the graphics library functions.
  1444. //
  1445. //*****************************************************************************
  1446. extern void GrCircleDraw(const tContext *pContext, long lX, long lY,
  1447. long lRadius);
  1448. extern void GrCircleFill(const tContext *pContext, long lX, long lY,
  1449. long lRadius);
  1450. extern void GrContextClipRegionSet(tContext *pContext, tRectangle *pRect);
  1451. extern void GrContextInit(tContext *pContext, const tDisplay *pDisplay);
  1452. extern void GrImageDraw(const tContext *pContext,
  1453. const tImage *pBitmap, int lX, int lY);
  1454. extern void GrLineDraw(const tContext *pContext, long lX1, long lY1, long lX2,
  1455. long lY2);
  1456. extern void GrLineDrawH(const tContext *pContext, long lX1, long lX2, long lY);
  1457. extern void GrLineDrawV(const tContext *pContext, long lX, long lY1, long lY2);
  1458. extern void GrRectDraw(const tContext *pContext, const tRectangle *pRect);
  1459. extern void GrRectFill(const tContext *pContext, const tRectangle *pRect);
  1460. extern void GrStringDraw(const tContext *pContext, const char *pcString,
  1461. long lLength, long lX, long lY,
  1462. unsigned long bOpaque);
  1463. extern long GrStringWidthGet(const tContext *pContext, const char *pcString,
  1464. long lLength);
  1465. extern long GrRectOverlapCheck(tRectangle *psRect1, tRectangle *psRect2);
  1466. extern long GrRectIntersectGet(tRectangle *psRect1, tRectangle *psRect2,
  1467. tRectangle *psIntersect);
  1468. //*****************************************************************************
  1469. //
  1470. // Mark the end of the C bindings section for C++ compilers.
  1471. //
  1472. //*****************************************************************************
  1473. #ifdef __cplusplus
  1474. }
  1475. #endif
  1476. //*****************************************************************************
  1477. //
  1478. // Close the Doxygen group.
  1479. //! @}
  1480. //
  1481. //*****************************************************************************
  1482. #endif // __GRLIB_H__