cnxwindow.hxx 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384
  1. /****************************************************************************
  2. * apps/include/graphics/nxwidgets/cnxwindow.hxx
  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. #ifndef __APPS_INCLUDE_GRAPHICS_NXWIDGETS_CNXWINDOW_HXX
  21. #define __APPS_INCLUDE_GRAPHICS_NXWIDGETS_CNXWINDOW_HXX
  22. /****************************************************************************
  23. * Included Files
  24. ****************************************************************************/
  25. #include <nuttx/config.h>
  26. #include <stdint.h>
  27. #include <stdbool.h>
  28. #include <nuttx/nx/nxglib.h>
  29. #include <nuttx/nx/nx.h>
  30. #include <nuttx/nx/nxtk.h>
  31. #include "graphics/nxwidgets/ccallback.hxx"
  32. #include "graphics/nxwidgets/inxwindow.hxx"
  33. /****************************************************************************
  34. * Implementation Classes
  35. ****************************************************************************/
  36. #if defined(__cplusplus)
  37. namespace NXWidgets
  38. {
  39. struct SBitmap;
  40. /**
  41. * This class defines operations on a basic "raw" NX window. These windows
  42. * are "raw" in the since that they are simply rectangular regions with
  43. * no framing or decoration of any kind
  44. *
  45. * There are three instances that represent an NX window from the
  46. * perspective of NXWidgets.
  47. *
  48. * - There is one widget control instance per NX window,
  49. * - One CCallback instance per window,
  50. * - One window instance.
  51. *
  52. * There a various kinds of of window instances, but each inherits
  53. * (1) CCallback and dispatches the Windows callbacks and (2) INxWindow
  54. * that describes the common window behavior.
  55. */
  56. class CNxWindow : protected CCallback, public INxWindow
  57. {
  58. private:
  59. NXHANDLE m_hNxServer; /**< Handle to the NX server. */
  60. NXWINDOW m_hNxWindow; /**< Handle to the NX raw window */
  61. CWidgetControl *m_widgetControl; /**< The controlling widget for the window */
  62. uint8_t m_flags; /**< Window properties */
  63. public:
  64. /**
  65. * Constructor. Creates an uninitialized instance of the CNxWindow
  66. * object. The open() method must be called to initialize the instance.
  67. *
  68. * The general steps to create any window include:
  69. * 1) Create a dumb CWigetControl instance
  70. * 2) Pass the dumb CWidgetControl instance to the window constructor
  71. * that inherits from INxWindow.
  72. * 3) The window constructor call CWidgetControl methods to "smarten"
  73. * the CWidgetControl instance with window-specific knowledge.
  74. * 4) Call the open() method on the window to display the window.
  75. * 5) After that, the fully smartend CWidgetControl instance can
  76. * be used to generate additional widgets.
  77. * 6) After that, the fully smartened CWidgetControl instance can
  78. * be used to generate additional widgets by passing it to the
  79. * widget constructor
  80. *
  81. * @param hNxServer Handle to the NX server.
  82. * @param widgetControl Controlling widget for this window.
  83. * @param flags Window properties
  84. */
  85. CNxWindow(NXHANDLE hNxServer, CWidgetControl *pWidgetControl,
  86. uint8_t flags = 0);
  87. /**
  88. * Destructor.
  89. */
  90. ~CNxWindow(void);
  91. /**
  92. * Creates a new window. Window creation is separate from
  93. * object instantiation so that failures can be reported.
  94. *
  95. * @return True if the window was successfully opened.
  96. */
  97. bool open(void);
  98. /**
  99. * Each implementation of INxWindow must provide a method to recover
  100. * the contained CWidgetControl instance.
  101. *
  102. * @return The contained CWidgetControl instance
  103. */
  104. CWidgetControl *getWidgetControl(void) const;
  105. /**
  106. * Synchronize the window with the NX server. This function will delay
  107. * until the the NX server has caught up with all of the queued requests.
  108. * When this function returns, the state of the NX server will be the
  109. * same as the state of the application.
  110. */
  111. inline void synchronize(void)
  112. {
  113. CCallback::synchronize(m_hNxWindow, CCallback::NX_RAWWINDOW);
  114. }
  115. /**
  116. * Request the position and size information of the window. The values
  117. * will be returned asynchronously through the client callback method.
  118. * The GetPosition() method may than be called to obtain the positional
  119. * data as provided by the callback.
  120. *
  121. * @return True on success, false on any failure.
  122. */
  123. bool requestPosition(void);
  124. /**
  125. * Get the position of the window (as reported by the NX callback).
  126. *
  127. * @return The position.
  128. */
  129. bool getPosition(FAR struct nxgl_point_s *pPos);
  130. /**
  131. * Get the size of the window (as reported by the NX callback).
  132. *
  133. * @return The size.
  134. */
  135. bool getSize(FAR struct nxgl_size_s *pSize);
  136. /**
  137. * Set the position and size of the window.
  138. *
  139. * @param pPos The new position of the window.
  140. * @return True on success, false on any failure.
  141. */
  142. bool setPosition(FAR const struct nxgl_point_s *pPos);
  143. /**
  144. * Set the size of the selected window.
  145. *
  146. * @param pSize The new size of the window.
  147. * @return True on success, false on any failure.
  148. */
  149. bool setSize(FAR const struct nxgl_size_s *pSize);
  150. /**
  151. * Bring the window to the top of the display.
  152. *
  153. * @return True on success, false on any failure.
  154. */
  155. inline bool raise(void)
  156. {
  157. return nx_raise(m_hNxWindow) == OK;
  158. }
  159. /**
  160. * Lower the window to the bottom of the display.
  161. *
  162. * @return True on success, false on any failure.
  163. */
  164. inline bool lower(void)
  165. {
  166. return nx_lower(m_hNxWindow) == OK;
  167. }
  168. /**
  169. * Return true if the window is currently being displayed
  170. *
  171. * @return True if the window is visible
  172. */
  173. inline bool isVisible(void)
  174. {
  175. return !nx_ishidden(m_hNxWindow);
  176. }
  177. /**
  178. * Show a hidden window
  179. *
  180. * @return True on success, false on any failure.
  181. */
  182. inline bool show(void)
  183. {
  184. return nx_setvisibility(m_hNxWindow, false) == OK;
  185. }
  186. /**
  187. * Hide a visible window
  188. *
  189. * @return True on success, false on any failure.
  190. */
  191. inline bool hide(void)
  192. {
  193. return nx_setvisibility(m_hNxWindow, true) == OK;
  194. }
  195. /**
  196. * May be used to either (1) raise a window to the top of the display and
  197. * select modal behavior, or (2) disable modal behavior.
  198. *
  199. * @param enable True: enter modal state; False: leave modal state
  200. * @return True on success, false on any failure.
  201. */
  202. bool modal(bool enable);
  203. /**
  204. * Each window implementation also inherits from CCallback. CCallback,
  205. * by default, forwards NX keyboard input to the various widgets residing
  206. * in the window. But NxTerm is a different usage model; In this case,
  207. * keyboard input needs to be directed to the NxTerm character driver.
  208. * This method can be used to enable (or disable) redirection of NX
  209. * keyboard input from the window widgets to the NxTerm
  210. *
  211. * @param handle. The NXTERM handle. If non-NULL, NX keyboard
  212. * input will be directed to the NxTerm driver using this
  213. * handle; If NULL (the default), NX keyboard input will be
  214. * directed to the widgets within the window.
  215. */
  216. #ifdef CONFIG_NXTERM_NXKBDIN
  217. inline void redirectNxTerm(NXTERM handle)
  218. {
  219. setNxTerm(handle);
  220. }
  221. #endif
  222. /**
  223. * Set an individual pixel in the window with the specified color.
  224. *
  225. * @param pPos The location of the pixel to be filled.
  226. * @param color The color to use in the fill.
  227. *
  228. * @return True on success; false on failure.
  229. */
  230. bool setPixel(FAR const struct nxgl_point_s *pPos,
  231. nxgl_mxpixel_t color);
  232. /**
  233. * Fill the specified rectangle in the window with the specified color.
  234. *
  235. * @param pRect The location to be filled.
  236. * @param color The color to use in the fill.
  237. *
  238. * @return True on success; false on failure.
  239. */
  240. bool fill(FAR const struct nxgl_rect_s *pRect,
  241. nxgl_mxpixel_t color);
  242. /**
  243. * Get the raw contents of graphic memory within a rectangular region. NOTE:
  244. * Since raw graphic memory is returned, the returned memory content may be
  245. * the memory of windows above this one and may not necessarily belong to
  246. * this window unless you assure that this is the top window.
  247. *
  248. * @param rect The location to be copied
  249. * @param dest - The describes the destination bitmap to receive the
  250. * graphics data.
  251. */
  252. void getRectangle(FAR const struct nxgl_rect_s *rect, struct SBitmap *dest);
  253. /**
  254. * Fill the specified trapezoidal region in the window with the specified
  255. * color.
  256. *
  257. * @param pClip Clipping rectangle relative to window (may be null).
  258. * @param pTrap The trapezoidal region to be filled.
  259. * @param color The color to use in the fill.
  260. *
  261. * @return True on success; false on failure.
  262. */
  263. bool fillTrapezoid(FAR const struct nxgl_rect_s *pClip,
  264. FAR const struct nxgl_trapezoid_s *pTrap,
  265. nxgl_mxpixel_t color);
  266. /**
  267. * Fill the specified line in the window with the specified color.
  268. *
  269. * @param vector - Describes the line to be drawn
  270. * @param width - The width of the line
  271. * @param color - The color to use to fill the line
  272. * @param caps - Draw a circular cap on the ends of the line to support
  273. * better line joins
  274. *
  275. * @return True on success; false on failure.
  276. */
  277. bool drawLine(FAR struct nxgl_vector_s *vector,
  278. nxgl_coord_t width, nxgl_mxpixel_t color,
  279. enum ELineCaps caps);
  280. /**
  281. * Draw a filled circle at the specified position, size, and color.
  282. *
  283. * @param center The window-relative coordinates of the circle center.
  284. * @param radius The radius of the rectangle in pixels.
  285. * @param color The color of the rectangle.
  286. */
  287. bool drawFilledCircle(struct nxgl_point_s *center, nxgl_coord_t radius,
  288. nxgl_mxpixel_t color);
  289. /**
  290. * Move a rectangular region within the window.
  291. *
  292. * @param pRect Describes the rectangular region to move.
  293. * @param pOffset The offset to move the region.
  294. *
  295. * @return True on success; false on failure.
  296. */
  297. bool move(FAR const struct nxgl_rect_s *pRect,
  298. FAR const struct nxgl_point_s *pOffset);
  299. /**
  300. * Copy a rectangular region of a larger image into the rectangle in the
  301. * specified window.
  302. *
  303. * @param pDest Describes the rectangular on the display that will receive
  304. * the bitmap.
  305. * @param pSrc The start of the source image.
  306. * @param pOrigin the pOrigin of the upper, left-most corner of the full
  307. * bitmap. Both pDest and pOrigin are in window coordinates, however,
  308. * pOrigin may lie outside of the display.
  309. * @param stride The width of the full source image in bytes.
  310. *
  311. * @return True on success; false on failure.
  312. */
  313. bool bitmap(FAR const struct nxgl_rect_s *pDest,
  314. FAR const void *pSrc,
  315. FAR const struct nxgl_point_s *pOrigin,
  316. unsigned int stride);
  317. };
  318. }
  319. #endif // __cplusplus
  320. #endif // __APPS_INCLUDE_GRAPHICS_NXWIDGETS_CNXWINDOW_HXX