nxtool_register.c 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  1. /****************************************************************************
  2. * nuttx/graphics/nxconsole/nxtool_register.c
  3. *
  4. * Copyright (C) 2012 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 <nuttx/nx/nxtk.h>
  40. #include <nuttx/nx/nxconsole.h>
  41. #include "nxcon_internal.h"
  42. /****************************************************************************
  43. * Pre-processor Definitions
  44. ****************************************************************************/
  45. /****************************************************************************
  46. * Private Function Prototypes
  47. ****************************************************************************/
  48. static int nxtool_fill(FAR struct nxcon_state_s *priv,
  49. FAR const struct nxgl_rect_s *rect,
  50. nxgl_mxpixel_t wcolor[CONFIG_NX_NPLANES]);
  51. #ifndef CONFIG_NX_WRITEONLY
  52. static int nxtool_move(FAR struct nxcon_state_s *priv,
  53. FAR const struct nxgl_rect_s *rect,
  54. FAR const struct nxgl_point_s *offset);
  55. #endif
  56. static int nxtool_bitmap(FAR struct nxcon_state_s *priv,
  57. FAR const struct nxgl_rect_s *dest,
  58. FAR const void *src[CONFIG_NX_NPLANES],
  59. FAR const struct nxgl_point_s *origin,
  60. unsigned int stride);
  61. /****************************************************************************
  62. * Private Data
  63. ****************************************************************************/
  64. static const struct nxcon_operations_s g_nxtoolops =
  65. {
  66. nxtool_fill,
  67. #ifndef CONFIG_NX_WRITEONLY
  68. nxtool_move,
  69. #endif
  70. nxtool_bitmap
  71. };
  72. /****************************************************************************
  73. * Private Functions
  74. ****************************************************************************/
  75. /****************************************************************************
  76. * Name: nxtool_fill
  77. *
  78. * Description:
  79. * Fill the specified rectangle in the window with the specified color
  80. *
  81. * Input Parameters:
  82. * priv - The driver state structure.
  83. * rect - The location to be filled
  84. * color - The color to use in the fill
  85. *
  86. * Return:
  87. * OK on success; ERROR on failure with errno set appropriately
  88. *
  89. ****************************************************************************/
  90. static int nxtool_fill(FAR struct nxcon_state_s *priv,
  91. FAR const struct nxgl_rect_s *rect,
  92. nxgl_mxpixel_t wcolor[CONFIG_NX_NPLANES])
  93. {
  94. return nxtk_filltoolbar((NXTKWINDOW)priv->handle, rect, wcolor);
  95. }
  96. /****************************************************************************
  97. * Name: nxtool_move
  98. *
  99. * Description:
  100. * Move a rectangular region within the window
  101. *
  102. * Input Parameters:
  103. * priv - The driver state structure.
  104. * rect - Describes the rectangular region to move
  105. * offset - The offset to move the region. The rectangular region will be
  106. * moved so that the origin is translated by this amount.
  107. *
  108. * Return:
  109. * OK on success; ERROR on failure with errno set appropriately
  110. *
  111. ****************************************************************************/
  112. #ifndef CONFIG_NX_WRITEONLY
  113. static int nxtool_move(FAR struct nxcon_state_s *priv,
  114. FAR const struct nxgl_rect_s *rect,
  115. FAR const struct nxgl_point_s *offset)
  116. {
  117. return nxtk_movetoolbar((NXTKWINDOW)priv->handle, rect, offset);
  118. }
  119. #endif
  120. /****************************************************************************
  121. * Name: nxtool_bitmap
  122. *
  123. * Description:
  124. * Copy a rectangular region of a larger image into the rectangle in the
  125. * specified window.
  126. *
  127. * Input Parameters:
  128. * priv - The driver state structure.
  129. * dest - Describes the rectangular region on the display that will
  130. * receive the bit map.
  131. * src - The start of the source image. This is an array source
  132. * images of size CONFIG_NX_NPLANES.
  133. * origin - The origin of the upper, left-most corner of the full bitmap.
  134. * Both dest and origin are in window coordinates, however, origin
  135. * may lie outside of the display.
  136. * stride - The width of the full source image in bytes.
  137. *
  138. * Return:
  139. * OK on success; ERROR on failure with errno set appropriately
  140. *
  141. ****************************************************************************/
  142. static int nxtool_bitmap(FAR struct nxcon_state_s *priv,
  143. FAR const struct nxgl_rect_s *dest,
  144. FAR const void *src[CONFIG_NX_NPLANES],
  145. FAR const struct nxgl_point_s *origin,
  146. unsigned int stride)
  147. {
  148. return nxtk_bitmaptoolbar((NXTKWINDOW)priv->handle, dest, src, origin, stride);
  149. }
  150. /****************************************************************************
  151. * Public Functions
  152. ****************************************************************************/
  153. /****************************************************************************
  154. * Name: nxtool_register
  155. *
  156. * Description:
  157. * Register a console device on a toolbar of a framed NX window. The
  158. * device will be registered at /dev/nxtoolN where N is the provided minor
  159. * number.
  160. *
  161. * Input Parameters:
  162. * hfwnd - A handle that will be used to access the toolbar. The toolbar
  163. * must persist and this handle must be valid for the life of the NX
  164. * console.
  165. * wndo - Describes the window and font to be used
  166. * minor - The device minor number
  167. *
  168. * Return:
  169. * A non-NULL handle is returned on success.
  170. *
  171. ****************************************************************************/
  172. NXCONSOLE nxtool_register(NXTKWINDOW hfwnd, FAR struct nxcon_window_s *wndo, int minor)
  173. {
  174. return nxcon_register((NXCONSOLE)hfwnd, wndo, &g_nxtoolops, minor);
  175. }