nxtk_subwindowmove.c 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. /****************************************************************************
  2. * graphics/nxtk/nxtk_subwindowmove.c
  3. *
  4. * Copyright (C) 2008-2009 Gregory Nutt. All rights reserved.
  5. * Author: Gregory Nutt <gnutt@nuttx.org>
  6. *
  7. * Redistribution and use in source and binary forms, with or without
  8. * modification, are permitted provided that the following conditions
  9. * are met:
  10. *
  11. * 1. Redistributions of source code must retain the above copyright
  12. * notice, this list of conditions and the following disclaimer.
  13. * 2. Redistributions in binary form must reproduce the above copyright
  14. * notice, this list of conditions and the following disclaimer in
  15. * the documentation and/or other materials provided with the
  16. * distribution.
  17. * 3. Neither the name NuttX nor the names of its contributors may be
  18. * used to endorse or promote products derived from this software
  19. * without specific prior written permission.
  20. *
  21. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  22. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  23. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
  24. * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
  25. * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
  26. * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
  27. * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
  28. * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
  29. * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  30. * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
  31. * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  32. * POSSIBILITY OF SUCH DAMAGE.
  33. *
  34. ****************************************************************************/
  35. /****************************************************************************
  36. * Included Files
  37. ****************************************************************************/
  38. #include <nuttx/config.h>
  39. #include <stdlib.h>
  40. #include <errno.h>
  41. #include <debug.h>
  42. #include <nuttx/nx/nx.h>
  43. #include <nuttx/nx/nxtk.h>
  44. #include "nxfe.h"
  45. #include "nxtk_internal.h"
  46. /****************************************************************************
  47. * Pre-Processor Definitions
  48. ****************************************************************************/
  49. /****************************************************************************
  50. * Private Types
  51. ****************************************************************************/
  52. /****************************************************************************
  53. * Private Data
  54. ****************************************************************************/
  55. /****************************************************************************
  56. * Public Data
  57. ****************************************************************************/
  58. /****************************************************************************
  59. * Private Functions
  60. ****************************************************************************/
  61. /****************************************************************************
  62. * Public Functions
  63. ****************************************************************************/
  64. /****************************************************************************
  65. * Name: nxtk_subwindowmove
  66. *
  67. * Description:
  68. * Perform common clipping operations in preparatons for calling nx_move()
  69. *
  70. * Input Parameters:
  71. * fwnd - The framed window within which the move is to be done.
  72. * This must have been previously created by nxtk_openwindow().
  73. * destrect - The loccation to receive the clipped rectangle relative
  74. * to containing window
  75. * destoffset - The location to received the clipped offset.
  76. * srcrect - Describes the rectangular region relative to the client
  77. * sub-window to move relative to the sub-window
  78. * srcoffset - The offset to move the region
  79. * bounds - The subwindow bounds in absolute screen coordinates.
  80. *
  81. * Return:
  82. * OK on success; ERROR on failure with errno set appropriately
  83. *
  84. ****************************************************************************/
  85. void nxtk_subwindowmove(FAR struct nxtk_framedwindow_s *fwnd,
  86. FAR struct nxgl_rect_s *destrect,
  87. FAR struct nxgl_point_s *destoffset,
  88. FAR const struct nxgl_rect_s *srcrect,
  89. FAR const struct nxgl_point_s *srcoffset,
  90. FAR const struct nxgl_rect_s *bounds)
  91. {
  92. struct nxgl_rect_s abssrc;
  93. /* Temporarily, position the src rectangle in absolute screen coordinates */
  94. nxgl_rectoffset(&abssrc, srcrect, bounds->pt1.x, bounds->pt1.y);
  95. /* Clip the src rectangle to lie within the client window region */
  96. nxgl_rectintersect(&abssrc, &abssrc, &fwnd->fwrect);
  97. /* Clip the source rectangle so that destination area is within the window. */
  98. destoffset->x = srcoffset->x;
  99. if (destoffset->x < 0)
  100. {
  101. if (abssrc.pt1.x + destoffset->x < bounds->pt1.x)
  102. {
  103. abssrc.pt1.x = bounds->pt1.x - destoffset->x;
  104. }
  105. }
  106. else if (abssrc.pt2.x + destoffset->x > bounds->pt2.x)
  107. {
  108. abssrc.pt2.x = bounds->pt2.x - destoffset->x;
  109. }
  110. destoffset->y = srcoffset->y;
  111. if (destoffset->y < 0)
  112. {
  113. if (abssrc.pt1.y + destoffset->y < bounds->pt1.y)
  114. {
  115. abssrc.pt1.y = bounds->pt1.y - destoffset->y;
  116. }
  117. }
  118. else if (abssrc.pt2.y + destoffset->y > bounds->pt2.y)
  119. {
  120. abssrc.pt2.y = bounds->pt2.y - destoffset->y;
  121. }
  122. /* Then move the rectangle so that is relative to the containing window, not the
  123. * client subwindow
  124. */
  125. nxgl_rectoffset(destrect, &abssrc, -fwnd->wnd.bounds.pt1.x, -fwnd->wnd.bounds.pt1.y);
  126. }