nxterm_toolbar.c 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. /****************************************************************************
  2. * apps/examples/nxterm/nxterm_toolbar.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 <stdint.h>
  25. #include <stdbool.h>
  26. #include <stdio.h>
  27. #include <stdlib.h>
  28. #include <string.h>
  29. #include <semaphore.h>
  30. #include <errno.h>
  31. #include <debug.h>
  32. #include <nuttx/nx/nx.h>
  33. #include <nuttx/nx/nxfonts.h>
  34. #include "nxterm_internal.h"
  35. /****************************************************************************
  36. * Pre-processor Definitions
  37. ****************************************************************************/
  38. /****************************************************************************
  39. * Private Types
  40. ****************************************************************************/
  41. /****************************************************************************
  42. * Private Function Prototypes
  43. ****************************************************************************/
  44. static void nxtool_redraw(NXWINDOW hwnd, FAR const struct nxgl_rect_s *rect,
  45. bool morem, FAR void *arg);
  46. static void nxtool_position(NXWINDOW hwnd, FAR const struct nxgl_size_s *size,
  47. FAR const struct nxgl_point_s *pos,
  48. FAR const struct nxgl_rect_s *bounds,
  49. FAR void *arg);
  50. #ifdef CONFIG_NX_XYINPUT
  51. static void nxtool_mousein(NXWINDOW hwnd, FAR const struct nxgl_point_s *pos,
  52. uint8_t buttons, FAR void *arg);
  53. #endif
  54. #ifdef CONFIG_NX_KBD
  55. static void nxtool_kbdin(NXWINDOW hwnd, uint8_t nch, FAR const uint8_t *ch,
  56. FAR void *arg);
  57. #endif
  58. /****************************************************************************
  59. * Private Data
  60. ****************************************************************************/
  61. /****************************************************************************
  62. * Public Data
  63. ****************************************************************************/
  64. /* Background window call table */
  65. const struct nx_callback_s g_nxtoolcb =
  66. {
  67. nxtool_redraw, /* redraw */
  68. nxtool_position /* position */
  69. #ifdef CONFIG_NX_XYINPUT
  70. , nxtool_mousein /* mousein */
  71. #endif
  72. #ifdef CONFIG_NX_KBD
  73. , nxtool_kbdin /* kbdin */
  74. #endif
  75. , NULL /* event */
  76. };
  77. /****************************************************************************
  78. * Private Functions
  79. ****************************************************************************/
  80. /****************************************************************************
  81. * Name: nxtool_redraw
  82. ****************************************************************************/
  83. static void nxtool_redraw(NXWINDOW hwnd, FAR const struct nxgl_rect_s *rect,
  84. bool more, FAR void *arg)
  85. {
  86. nxgl_mxpixel_t color[CONFIG_NX_NPLANES];
  87. int ret;
  88. ginfo("hwnd=%p rect={(%d,%d),(%d,%d)} more=%s\n",
  89. hwnd, rect->pt1.x, rect->pt1.y, rect->pt2.x, rect->pt2.y,
  90. more ? "true" : "false");
  91. color[0] = CONFIG_EXAMPLES_NXTERM_TBCOLOR;
  92. ret = nxtk_filltoolbar(hwnd, rect, color);
  93. if (ret < 0)
  94. {
  95. gerr("ERROR: nxtk_filltoolbar failed: %d\n", errno);
  96. }
  97. }
  98. /****************************************************************************
  99. * Name: nxtool_position
  100. ****************************************************************************/
  101. static void nxtool_position(NXWINDOW hwnd, FAR const struct nxgl_size_s *size,
  102. FAR const struct nxgl_point_s *pos,
  103. FAR const struct nxgl_rect_s *bounds,
  104. FAR void *arg)
  105. {
  106. ginfo("hwnd=%p size=(%d,%d) pos=(%d,%d) bounds={(%d,%d),(%d,%d)}\n",
  107. hwnd, size->w, size->h, pos->x, pos->y,
  108. bounds->pt1.x, bounds->pt1.y, bounds->pt2.x, bounds->pt2.y);
  109. }
  110. /****************************************************************************
  111. * Name: nxtool_mousein
  112. ****************************************************************************/
  113. #ifdef CONFIG_NX_XYINPUT
  114. static void nxtool_mousein(NXWINDOW hwnd, FAR const struct nxgl_point_s *pos,
  115. uint8_t buttons, FAR void *arg)
  116. {
  117. ginfo("hwnd=%p pos=(%d,%d) button=%02x\n", hwnd, pos->x, pos->y, buttons);
  118. }
  119. #endif
  120. /****************************************************************************
  121. * Name: nxtool_kbdin
  122. ****************************************************************************/
  123. #ifdef CONFIG_NX_KBD
  124. static void nxtool_kbdin(NXWINDOW hwnd, uint8_t nch, FAR const uint8_t *ch,
  125. FAR void *arg)
  126. {
  127. ginfo("hwnd=%p nch=%d\n", hwnd, nch);
  128. }
  129. #endif
  130. /****************************************************************************
  131. * Public Functions
  132. ****************************************************************************/