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.

154 lines
5.6 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. #include "grlib.h"
  33. //*****************************************************************************
  34. //
  35. //! \addtogroup context_api
  36. //! @{
  37. //
  38. //*****************************************************************************
  39. //*****************************************************************************
  40. //
  41. //! Initializes a drawing context.
  42. //!
  43. //! \param pContext is a pointer to the drawing context to initialize.
  44. //! \param pDisplay is a pointer to the tDisplayInfo structure that describes
  45. //! the display driver to use.
  46. //!
  47. //! This function initializes a drawing context, preparing it for use. The
  48. //! provided display driver will be used for all subsequent graphics
  49. //! operations, and the default clipping region will be set to the extent of
  50. //! the screen.
  51. //!
  52. //! \return None.
  53. //
  54. //*****************************************************************************
  55. void
  56. GrContextInit(tContext *pContext, const tDisplay *pDisplay)
  57. {
  58. //
  59. // Check the arguments.
  60. //
  61. assert(pContext);
  62. assert(pDisplay);
  63. //
  64. // Set the size of the context.
  65. //
  66. pContext->lSize = sizeof(tContext);
  67. //
  68. // Save the pointer to the display.
  69. //
  70. pContext->pDisplay = pDisplay;
  71. //
  72. // Initialize the extent of the clipping region to the extents of the
  73. // screen.
  74. //
  75. pContext->sClipRegion.sXMin = 0;
  76. pContext->sClipRegion.sYMin = 0;
  77. pContext->sClipRegion.sXMax = pDisplay->usWidth - 1;
  78. pContext->sClipRegion.sYMax = pDisplay->usHeight - 1;
  79. //
  80. // Provide a default color and font.
  81. //
  82. pContext->ulForeground = 0;
  83. pContext->ulBackground = 0;
  84. pContext->pFont = 0;
  85. }
  86. //*****************************************************************************
  87. //
  88. //! Sets the extents of the clipping region.
  89. //!
  90. //! \param pContext is a pointer to the drawing context to use.
  91. //! \param pRect is a pointer to the structure containing the extents of the
  92. //! clipping region.
  93. //!
  94. //! This function sets the extents of the clipping region. The clipping region
  95. //! is not allowed to exceed the extents of the screen, but may be a portion of
  96. //! the screen.
  97. //!
  98. //! The supplied coordinate are inclusive; \e sXMin of 1 and \e sXMax of 1 will
  99. //! define a clipping region that will display only the pixels in the X = 1
  100. //! column. A consequence of this is that the clipping region must contain
  101. //! at least one row and one column.
  102. //!
  103. //! \return None.
  104. //
  105. //*****************************************************************************
  106. void
  107. GrContextClipRegionSet(tContext *pContext, tRectangle *pRect)
  108. {
  109. unsigned long ulW, ulH;
  110. //
  111. // Check the arguments.
  112. //
  113. assert(pContext);
  114. assert(pRect);
  115. //
  116. // Get the width and height of the display.
  117. //
  118. ulW = DpyWidthGet(pContext->pDisplay);
  119. ulH = DpyHeightGet(pContext->pDisplay);
  120. //
  121. // Set the extents of the clipping region, forcing them to reside within
  122. // the extents of the screen.
  123. //
  124. pContext->sClipRegion.sXMin = ((pRect->sXMin < 0) ? 0 :
  125. ((pRect->sXMin >= ulW) ? (ulW - 1) :
  126. pRect->sXMin));
  127. pContext->sClipRegion.sYMin = ((pRect->sYMin < 0) ? 0 :
  128. ((pRect->sYMin >= ulH) ? (ulH - 1) :
  129. pRect->sYMin));
  130. pContext->sClipRegion.sXMax = ((pRect->sXMax < 0) ? 0 :
  131. ((pRect->sXMax >= ulW) ? (ulW - 1) :
  132. pRect->sXMax));
  133. pContext->sClipRegion.sYMax = ((pRect->sYMax < 0) ? 0 :
  134. ((pRect->sYMax >= ulH) ? (ulH - 1) :
  135. pRect->sYMax));
  136. }
  137. //*****************************************************************************
  138. //
  139. // Close the Doxygen group.
  140. //! @}
  141. //
  142. //*****************************************************************************