nxterm_wndo.c 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  1. /****************************************************************************
  2. * apps/examples/nxterm/nxterm_wndo.c
  3. *
  4. * Licensed to the Apache Software Foundation (ASF) under one or more
  5. * contributor license agreements. See the NOTICE file distributed with
  6. * this work for additional information regarding copyright ownership. The
  7. * ASF licenses this file to you under the Apache License, Version 2.0 (the
  8. * "License"); you may not use this file except in compliance with the
  9. * License. You may obtain a copy of the License at
  10. *
  11. * http://www.apache.org/licenses/LICENSE-2.0
  12. *
  13. * Unless required by applicable law or agreed to in writing, software
  14. * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  15. * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
  16. * License for the specific language governing permissions and limitations
  17. * under the License.
  18. *
  19. ****************************************************************************/
  20. /****************************************************************************
  21. * Included Files
  22. ****************************************************************************/
  23. #include <nuttx/config.h>
  24. #include <sys/boardctl.h>
  25. #include <stdint.h>
  26. #include <stdbool.h>
  27. #include <stdio.h>
  28. #include <stdlib.h>
  29. #include <unistd.h>
  30. #include <string.h>
  31. #include <semaphore.h>
  32. #include <errno.h>
  33. #include <debug.h>
  34. #include <nuttx/nx/nx.h>
  35. #include <nuttx/nx/nxglib.h>
  36. #include <nuttx/nx/nxfonts.h>
  37. #include "nxterm_internal.h"
  38. /****************************************************************************
  39. * Private Function Prototypes
  40. ****************************************************************************/
  41. static void nxwndo_redraw(NXWINDOW hwnd, FAR const struct nxgl_rect_s *rect,
  42. bool morem, FAR void *arg);
  43. static void nxwndo_position(NXWINDOW hwnd, FAR const struct nxgl_size_s *size,
  44. FAR const struct nxgl_point_s *pos,
  45. FAR const struct nxgl_rect_s *bounds,
  46. FAR void *arg);
  47. #ifdef CONFIG_NX_XYINPUT
  48. static void nxwndo_mousein(NXWINDOW hwnd, FAR const struct nxgl_point_s *pos,
  49. uint8_t buttons, FAR void *arg);
  50. #endif
  51. #ifdef CONFIG_NX_KBD
  52. static void nxwndo_kbdin(NXWINDOW hwnd, uint8_t nch, FAR const uint8_t *ch,
  53. FAR void *arg);
  54. #endif
  55. /****************************************************************************
  56. * Public Data
  57. ****************************************************************************/
  58. /* Background window call table */
  59. const struct nx_callback_s g_nxtermcb =
  60. {
  61. nxwndo_redraw, /* redraw */
  62. nxwndo_position /* position */
  63. #ifdef CONFIG_NX_XYINPUT
  64. , nxwndo_mousein /* mousein */
  65. #endif
  66. #ifdef CONFIG_NX_KBD
  67. , nxwndo_kbdin /* kbdin */
  68. #endif
  69. , NULL /* event */
  70. };
  71. /****************************************************************************
  72. * Private Functions
  73. ****************************************************************************/
  74. /****************************************************************************
  75. * Name: nxwndo_redraw
  76. ****************************************************************************/
  77. static void nxwndo_redraw(NXWINDOW hwnd, FAR const struct nxgl_rect_s *rect,
  78. bool more, FAR void *arg)
  79. {
  80. nxgl_mxpixel_t wcolor[CONFIG_NX_NPLANES];
  81. ginfo("hwnd=%p rect={(%d,%d),(%d,%d)} more=%s\n",
  82. hwnd, rect->pt1.x, rect->pt1.y, rect->pt2.x, rect->pt2.y,
  83. more ? "true" : "false");
  84. /* Don't attempt to redraw if the driver has not yet been opened */
  85. if (g_nxterm_vars.hdrvr)
  86. {
  87. struct boardioc_nxterm_ioctl_s iocargs;
  88. struct nxtermioc_redraw_s redraw;
  89. /* Inform the NX console of the redraw request */
  90. redraw.handle = g_nxterm_vars.hdrvr;
  91. redraw.more = more;
  92. nxgl_rectcopy(&redraw.rect, rect);
  93. iocargs.cmd = NXTERMIOC_NXTERM_REDRAW;
  94. iocargs.arg = (uintptr_t)&redraw;
  95. boardctl(BOARDIOC_NXTERM_IOCTL, (uintptr_t)&iocargs);
  96. }
  97. else
  98. {
  99. /* If the driver has not been opened, then just redraw the window color */
  100. wcolor[0] = CONFIG_EXAMPLES_NXTERM_WCOLOR;
  101. nxtk_fillwindow(hwnd, rect, wcolor);
  102. }
  103. }
  104. /****************************************************************************
  105. * Name: nxwndo_position
  106. ****************************************************************************/
  107. static void nxwndo_position(NXWINDOW hwnd, FAR const struct nxgl_size_s *size,
  108. FAR const struct nxgl_point_s *pos,
  109. FAR const struct nxgl_rect_s *bounds,
  110. FAR void *arg)
  111. {
  112. /* Report the position */
  113. ginfo("hwnd=%p size=(%d,%d) pos=(%d,%d) bounds={(%d,%d),(%d,%d)}\n",
  114. hwnd, size->w, size->h, pos->x, pos->y,
  115. bounds->pt1.x, bounds->pt1.y, bounds->pt2.x, bounds->pt2.y);
  116. /* Have we picked off the window bounds yet? */
  117. if (!g_nxterm_vars.haveres)
  118. {
  119. /* Save the background window handle */
  120. g_nxterm_vars.hwnd = hwnd;
  121. /* Save the background window size */
  122. g_nxterm_vars.wndo.wsize.w = size->w;
  123. g_nxterm_vars.wndo.wsize.h = size->h;
  124. /* Save the window limits (these should be the same for all places and
  125. * all windows)
  126. */
  127. g_nxterm_vars.xres = bounds->pt2.x + 1;
  128. g_nxterm_vars.yres = bounds->pt2.y + 1;
  129. g_nxterm_vars.haveres = true;
  130. sem_post(&g_nxterm_vars.eventsem);
  131. ginfo("Have xres=%d yres=%d\n", g_nxterm_vars.xres, g_nxterm_vars.yres);
  132. }
  133. }
  134. /****************************************************************************
  135. * Name: nxwndo_mousein
  136. ****************************************************************************/
  137. #ifdef CONFIG_NX_XYINPUT
  138. static void nxwndo_mousein(NXWINDOW hwnd, FAR const struct nxgl_point_s *pos,
  139. uint8_t buttons, FAR void *arg)
  140. {
  141. ginfo("hwnd=%p pos=(%d,%d) button=%02x\n",
  142. hwnd, pos->x, pos->y, buttons);
  143. }
  144. #endif
  145. /****************************************************************************
  146. * Name: nxwndo_kbdin
  147. ****************************************************************************/
  148. #ifdef CONFIG_NX_KBD
  149. static void nxwndo_kbdin(NXWINDOW hwnd, uint8_t nch, FAR const uint8_t *ch,
  150. FAR void *arg)
  151. {
  152. ginfo("hwnd=%p nch=%d\n", hwnd, nch);
  153. write(1, ch, nch);
  154. }
  155. #endif
  156. /****************************************************************************
  157. * Public Functions
  158. ****************************************************************************/