context.c 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. //*****************************************************************************
  2. //
  3. // context.c - Routines for handling drawing contexts.
  4. //
  5. // Copyright (c) 2007-2010 Texas Instruments Incorporated. All rights reserved.
  6. // Software License Agreement
  7. //
  8. // Texas Instruments (TI) is supplying this software for use solely and
  9. // exclusively on TI's microcontroller products. The software is owned by
  10. // TI and/or its suppliers, and is protected under applicable copyright
  11. // laws. You may not combine this software with "viral" open-source
  12. // software in order to form a larger program.
  13. //
  14. // THIS SOFTWARE IS PROVIDED "AS IS" AND WITH ALL FAULTS.
  15. // NO WARRANTIES, WHETHER EXPRESS, IMPLIED OR STATUTORY, INCLUDING, BUT
  16. // NOT LIMITED TO, IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  17. // A PARTICULAR PURPOSE APPLY TO THIS SOFTWARE. TI SHALL NOT, UNDER ANY
  18. // CIRCUMSTANCES, BE LIABLE FOR SPECIAL, INCIDENTAL, OR CONSEQUENTIAL
  19. // DAMAGES, FOR ANY REASON WHATSOEVER.
  20. //
  21. // This is part of revision 6288 of the Stellaris Graphics Library.
  22. //
  23. //*****************************************************************************
  24. #include "debug.h"
  25. #include "grlib.h"
  26. //*****************************************************************************
  27. //
  28. //! \addtogroup primitives_api
  29. //! @{
  30. //
  31. //*****************************************************************************
  32. //*****************************************************************************
  33. //
  34. //! Initializes a drawing context.
  35. //!
  36. //! \param pContext is a pointer to the drawing context to initialize.
  37. //! \param pDisplay is a pointer to the tDisplayInfo structure that describes
  38. //! the display driver to use.
  39. //!
  40. //! This function initializes a drawing context, preparing it for use. The
  41. //! provided display driver will be used for all subsequent graphics
  42. //! operations, and the default clipping region will be set to the extent of
  43. //! the screen.
  44. //!
  45. //! \return None.
  46. //
  47. //*****************************************************************************
  48. void
  49. GrContextInit(tContext *pContext, const tDisplay *pDisplay)
  50. {
  51. //
  52. // Check the arguments.
  53. //
  54. ASSERT(pContext);
  55. ASSERT(pDisplay);
  56. //
  57. // Set the size of the context.
  58. //
  59. pContext->lSize = sizeof(tContext);
  60. //
  61. // Save the pointer to the display.
  62. //
  63. pContext->pDisplay = pDisplay;
  64. //
  65. // Initialize the extent of the clipping region to the extents of the
  66. // screen.
  67. //
  68. pContext->sClipRegion.sXMin = 0;
  69. pContext->sClipRegion.sYMin = 0;
  70. pContext->sClipRegion.sXMax = pDisplay->usWidth - 1;
  71. pContext->sClipRegion.sYMax = pDisplay->usHeight - 1;
  72. //
  73. // Provide a default color and font.
  74. //
  75. pContext->ulForeground = 0;
  76. pContext->ulBackground = 0;
  77. pContext->pFont = 0;
  78. }
  79. //*****************************************************************************
  80. //
  81. //! Sets the extents of the clipping region.
  82. //!
  83. //! \param pContext is a pointer to the drawing context to use.
  84. //! \param pRect is a pointer to the structure containing the extents of the
  85. //! clipping region.
  86. //!
  87. //! This function sets the extents of the clipping region. The clipping region
  88. //! is not allowed to exceed the extents of the screen, but may be a portion of
  89. //! the screen.
  90. //!
  91. //! The supplied coordinate are inclusive; \e sXMin of 1 and \e sXMax of 1 will
  92. //! define a clipping region that will display only the pixels in the X = 1
  93. //! column. A consequence of this is that the clipping region must contain
  94. //! at least one row and one column.
  95. //!
  96. //! \return None.
  97. //
  98. //*****************************************************************************
  99. void
  100. GrContextClipRegionSet(tContext *pContext, tRectangle *pRect)
  101. {
  102. unsigned int ulW, ulH;
  103. //
  104. // Check the arguments.
  105. //
  106. ASSERT(pContext);
  107. ASSERT(pRect);
  108. //
  109. // Get the width and height of the display.
  110. //
  111. ulW = DpyWidthGet(pContext->pDisplay);
  112. ulH = DpyHeightGet(pContext->pDisplay);
  113. //
  114. // Set the extents of the clipping region, forcing them to reside within
  115. // the extents of the screen.
  116. //
  117. pContext->sClipRegion.sXMin = ((pRect->sXMin < 0) ? 0 :
  118. ((pRect->sXMin >= ulW) ? (ulW - 1) :
  119. pRect->sXMin));
  120. pContext->sClipRegion.sYMin = ((pRect->sYMin < 0) ? 0 :
  121. ((pRect->sYMin >= ulH) ? (ulH - 1) :
  122. pRect->sYMin));
  123. pContext->sClipRegion.sXMax = ((pRect->sXMax < 0) ? 0 :
  124. ((pRect->sXMax >= ulW) ? (ulW - 1) :
  125. pRect->sXMax));
  126. pContext->sClipRegion.sYMax = ((pRect->sYMax < 0) ? 0 :
  127. ((pRect->sYMax >= ulH) ? (ulH - 1) :
  128. pRect->sYMax));
  129. }
  130. //*****************************************************************************
  131. //
  132. // Close the Doxygen group.
  133. //! @}
  134. //
  135. //*****************************************************************************